Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies to 0.3 #9

Open
wants to merge 4 commits into
base: r1cs-nark-pcd
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@ edition = "2018"
################################# Dependencies ################################

[dependencies]
ark-serialize = { version = "^0.2.0", default-features = false, features = [ "derive" ] }
ark-ff = { version = "^0.2.0", default-features = false }
ark-ec = { version = "^0.2.0", default-features = false }
ark-poly = { version = "^0.2.0", default-features = false }
ark-serialize = { version = "^0.3.0", default-features = false, features = [ "derive" ] }
ark-ff = { version = "^0.3.0", default-features = false }
ark-ec = { version = "^0.3.0", default-features = false }
ark-poly = { version = "^0.3.0", default-features = false }

ark-std = { version = "^0.2.0", default-features = false }
ark-std = { version = "^0.3.0", default-features = false }

ark-relations = { version = "^0.2.0", default-features = false }
ark-crypto-primitives = { version = "^0.2.0", default-features = false, features = [ "r1cs" ] }
ark-relations = { version = "^0.3.0", default-features = false }
ark-crypto-primitives = { version = "^0.3.0", default-features = false, features = [ "r1cs" ] }

ark-r1cs-std = { version = "^0.2.0", default-features = false }
ark-r1cs-std = { version = "^0.3.0", default-features = false }

ark-nonnative-field = { git = "https://github.com/arkworks-rs/nonnative", default-features = false }
ark-snark = { version = "^0.2.0", default-features = false }
ark-snark = { version = "^0.3.0", default-features = false }

ark-accumulation = { git = "https://github.com/arkworks-rs/accumulation/", branch = "main", default-features = false, features = [ "r1cs-nark-as", "r1cs" ] }
ark-sponge = { git = "https://github.com/arkworks-rs/sponge/", branch = "accumulation-experimental", default-features = false, features = [ "r1cs" ] }
ark-accumulation = { git = "https://github.com/arkworks-rs/accumulation/", branch = "upgrade-to-0.3", default-features = false, features = [ "r1cs-nark-as", "r1cs" ] }
ark-sponge = { version = "^0.3.0", default-features = false, features = [ "r1cs" ] }

ark-ed-on-mnt4-298 = { version = "^0.2.0", default-features = false }
ark-ed-on-bls12-381 = { version = "^0.2.0", default-features = false }
ark-mnt4-298 = { version = "^0.2.0", default-features = false, features = [ "curve", "r1cs" ] }
ark-mnt6-298 = { version = "^0.2.0", default-features = false, features = [ "r1cs" ] }
ark-ed-on-mnt4-298 = { version = "^0.3.0", default-features = false }
ark-ed-on-bls12-381 = { version = "^0.3.0", default-features = false }
ark-mnt4-298 = { version = "^0.3.0", default-features = false, features = [ "curve", "r1cs" ] }
ark-mnt6-298 = { version = "^0.3.0", default-features = false, features = [ "r1cs" ] }

rand_chacha = { version = "0.2.1", default-features = false }
rand_chacha = { version = "0.3.1", default-features = false }
derivative = { version = "2.0", features = ["use_core"] }

ark-groth16 = { version = "^0.2.0", features = [ "r1cs" ], default-features = false }
ark-gm17 = { version = "^0.2.0", features = [ "r1cs" ], default-features = false }
ark-marlin = { git = "https://github.com/arkworks-rs/marlin", branch = "constraints", default-features = false }
ark-groth16 = { version = "^0.3.0", features = [ "r1cs" ], default-features = false }
ark-gm17 = { version = "^0.3.0", features = [ "r1cs" ], default-features = false }
ark-marlin = { git = "https://github.com/arkworks-rs/marlin", branch = "vlopes11/constraints-sponge-rate", default-features = false }
ark-poly-commit = { git = "https://github.com/arkworks-rs/poly-commit", branch = "constraints", default-features = false, features = [ "r1cs" ] }

tracing = { version = "0.1", default-features = false, features = [ "attributes" ] }
Expand Down
12 changes: 6 additions & 6 deletions src/ec_cycle_pcd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use ark_r1cs_std::{
use ark_relations::r1cs::{
ConstraintSynthesizer, ConstraintSystem, ConstraintSystemRef, OptimizationGoal, SynthesisError,
};
use ark_sponge::Absorbable;
use ark_sponge::Absorb;
use ark_std::rand::{CryptoRng, Rng, RngCore};
use ark_std::{boxed::Box, marker::PhantomData, vec::Vec};

Expand Down Expand Up @@ -255,14 +255,14 @@ where
}

pub struct BoundTestingPredicate<
F: PrimeField + Absorbable<F>,
F: PrimeField + Absorb,
BoundCircuit: ConstraintSynthesizer<F> + Clone,
> {
pub bound_circuit: BoundCircuit,
pub field_phantom: PhantomData<F>,
}

impl<F: PrimeField + Absorbable<F>, BoundCircuit: ConstraintSynthesizer<F> + Clone> Clone
impl<F: PrimeField + Absorb, BoundCircuit: ConstraintSynthesizer<F> + Clone> Clone
for BoundTestingPredicate<F, BoundCircuit>
{
fn clone(&self) -> Self {
Expand All @@ -273,7 +273,7 @@ impl<F: PrimeField + Absorbable<F>, BoundCircuit: ConstraintSynthesizer<F> + Clo
}
}

impl<F: PrimeField + Absorbable<F>, BoundCircuit: ConstraintSynthesizer<F> + Clone> PCDPredicate<F>
impl<F: PrimeField + Absorb, BoundCircuit: ConstraintSynthesizer<F> + Clone> PCDPredicate<F>
for BoundTestingPredicate<F, BoundCircuit>
{
type Message = F;
Expand Down Expand Up @@ -307,8 +307,8 @@ impl<F: PrimeField + Absorbable<F>, BoundCircuit: ConstraintSynthesizer<F> + Clo

impl<MainField, HelpField, IC> UniversalSetupPCD<MainField> for ECCyclePCD<MainField, HelpField, IC>
where
MainField: PrimeField + Absorbable<MainField>,
HelpField: PrimeField + Absorbable<HelpField>,
MainField: PrimeField + Absorb,
HelpField: PrimeField + Absorb,
IC: ECCyclePCDConfig<MainField, HelpField>,
IC::MainSNARK: UniversalSetupSNARK<MainField>,
IC::HelpSNARK: UniversalSetupSNARK<HelpField>,
Expand Down
28 changes: 14 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use ark_r1cs_std::alloc::AllocVar;
use ark_r1cs_std::bits::boolean::Boolean;
use ark_r1cs_std::ToBytesGadget;
use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
use ark_sponge::constraints::AbsorbableGadget;
use ark_sponge::Absorbable;
use ark_sponge::constraints::AbsorbGadget;
use ark_sponge::Absorb;
use ark_std::rand::{CryptoRng, RngCore};
use ark_std::{boxed::Box, fmt::Debug};

Expand All @@ -18,8 +18,8 @@ extern crate derivative;
pub type Error = Box<dyn ark_std::error::Error + 'static>;

pub trait PCDPredicate<F: PrimeField>: Clone {
type Message: Absorbable<F> + ToBytes + Sized + Clone + Default;
type MessageVar: AbsorbableGadget<F> + ToBytesGadget<F> + AllocVar<Self::Message, F>;
type Message: Absorb + ToBytes + Sized + Clone + Default;
type MessageVar: AbsorbGadget<F> + ToBytesGadget<F> + AllocVar<Self::Message, F>;

type LocalWitness: Sized + Clone + Default;
type LocalWitnessVar: AllocVar<Self::LocalWitness, F>;
Expand Down Expand Up @@ -102,23 +102,23 @@ pub mod tests {
use ark_r1cs_std::eq::EqGadget;
use ark_r1cs_std::fields::fp::FpVar;
use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
use ark_sponge::Absorbable;
use ark_sponge::Absorb;
use ark_std::marker::PhantomData;

#[derive(Clone)]
pub struct TestIVCPredicate<F: PrimeField + Absorbable<F>> {
pub struct TestIVCPredicate<F: PrimeField + Absorb> {
pub field_phantom: PhantomData<F>,
}

impl<F: PrimeField + Absorbable<F>> TestIVCPredicate<F> {
impl<F: PrimeField + Absorb> TestIVCPredicate<F> {
fn new() -> Self {
Self {
field_phantom: PhantomData,
}
}
}

impl<F: PrimeField + Absorbable<F>> PCDPredicate<F> for TestIVCPredicate<F> {
impl<F: PrimeField + Absorb> PCDPredicate<F> for TestIVCPredicate<F> {
type Message = F;
type MessageVar = FpVar<F>;
type LocalWitness = F;
Expand All @@ -142,19 +142,19 @@ pub mod tests {
}

#[derive(Clone)]
pub struct TestPCDPredicate<F: PrimeField + Absorbable<F>> {
pub struct TestPCDPredicate<F: PrimeField + Absorb> {
pub field_phantom: PhantomData<F>,
}

impl<F: PrimeField + Absorbable<F>> TestPCDPredicate<F> {
impl<F: PrimeField + Absorb> TestPCDPredicate<F> {
fn new() -> Self {
Self {
field_phantom: PhantomData,
}
}
}

impl<F: PrimeField + Absorbable<F>> PCDPredicate<F> for TestPCDPredicate<F> {
impl<F: PrimeField + Absorb> PCDPredicate<F> for TestPCDPredicate<F> {
type Message = F;
type MessageVar = FpVar<F>;
type LocalWitness = F;
Expand All @@ -177,7 +177,7 @@ pub mod tests {
}
}

pub fn test_ivc_base_case<F: PrimeField + Absorbable<F>, TestPCD: PCD<F>>() {
pub fn test_ivc_base_case<F: PrimeField + Absorb, TestPCD: PCD<F>>() {
let mut rng = ark_std::test_rng();

let witness = F::one();
Expand All @@ -190,7 +190,7 @@ pub mod tests {
assert!(TestPCD::verify::<TestIVCPredicate<F>>(&vk, &msg_0, &proof_0).unwrap());
}

pub fn test_ivc<F: PrimeField + Absorbable<F>, TestPCD: PCD<F>>() {
pub fn test_ivc<F: PrimeField + Absorb, TestPCD: PCD<F>>() {
let mut rng = ark_std::test_rng();

let witness = F::one();
Expand Down Expand Up @@ -229,7 +229,7 @@ pub mod tests {
assert!(TestPCD::verify::<TestIVCPredicate<F>>(&vk, &msg_2, &proof_2).unwrap());
}

pub fn test_pcd<F: PrimeField + Absorbable<F>, TestPCD: PCD<F>>() {
pub fn test_pcd<F: PrimeField + Absorb, TestPCD: PCD<F>>() {
let mut rng = ark_std::test_rng();

let witness = F::one();
Expand Down
3 changes: 3 additions & 0 deletions src/r1cs_nark_pcd/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub(crate) type HelpField<E> = <<E as CurveCycle>::E2 as AffineCurve>::ScalarFie
pub(crate) type MainProjective<E> = <MainAffine<E> as AffineCurve>::Projective;
pub(crate) type HelpProjective<E> = <HelpAffine<E> as AffineCurve>::Projective;

// TODO: fix
pub(crate) const SPONGE_RATE: usize = 4;

/// The proving key of [`R1CSNarkPCD`][nark_pcd].
///
/// [nark_pcd]: crate::r1cs_nark_pcd::R1CSNarkPCD
Expand Down
44 changes: 27 additions & 17 deletions src/r1cs_nark_pcd/help_circuit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::r1cs_nark_pcd::data_structures::{HelpAffine, HelpField, MainAffine, MainField};
use crate::r1cs_nark_pcd::data_structures::{HelpAffine, HelpField, MainAffine, MainField, SPONGE_RATE};
use crate::r1cs_nark_pcd::main_circuit::MainCircuit;
use crate::r1cs_nark_pcd::{R1CSNarkPCDConfig, MAKE_ZK};
use crate::PCDPredicate;
Expand All @@ -10,6 +10,7 @@ use ark_accumulation::r1cs_nark_as::constraints::{
use ark_accumulation::r1cs_nark_as::{AccumulatorInstance, InputInstance};
use ark_ec::CurveCycle;
use ark_ff::{PrimeField, Zero};
use ark_marlin::sponge::{CryptographicSpongeParameters, CryptographicSpongeWithRate};
use ark_r1cs_std::alloc::AllocVar;
use ark_r1cs_std::bits::boolean::Boolean;
use ark_r1cs_std::eq::EqGadget;
Expand All @@ -19,7 +20,7 @@ use ark_relations::r1cs::{
ConstraintSynthesizer, ConstraintSystem, ConstraintSystemRef, SynthesisError,
};
use ark_sponge::constraints::CryptographicSpongeVar;
use ark_sponge::{absorb, absorb_gadget, Absorbable, CryptographicSponge};
use ark_sponge::{absorb, absorb_gadget, Absorb, CryptographicSponge};
use ark_std::marker::PhantomData;

/// A circuit used to verify that the accumulation of arguments about the main circuit was computed
Expand All @@ -29,12 +30,14 @@ use ark_std::marker::PhantomData;
pub(crate) struct HelpCircuit<E, PC, P>
where
E: CurveCycle,
MainField<E>: PrimeField + Absorbable<MainField<E>>,
HelpField<E>: PrimeField + Absorbable<HelpField<E>>,
MainAffine<E>: Absorbable<HelpField<E>>,
HelpAffine<E>: Absorbable<MainField<E>>,
MainField<E>: PrimeField + Absorb,
HelpField<E>: PrimeField + Absorb,
MainAffine<E>: Absorb,
HelpAffine<E>: Absorb,
PC: R1CSNarkPCDConfig<E>,
P: PCDPredicate<MainField<E>>,
<PC::MainSponge as CryptographicSponge>::Parameters: CryptographicSpongeParameters,
<PC::HelpSponge as CryptographicSponge>::Parameters: CryptographicSpongeParameters,
{
/// The key for verifying the accumulation of arguments about the main circuit.
pub(crate) main_avk: r1cs_nark_as::VerifierKey,
Expand Down Expand Up @@ -65,12 +68,14 @@ where
impl<E, PC, P> HelpCircuit<E, PC, P>
where
E: CurveCycle,
MainField<E>: PrimeField + Absorbable<MainField<E>>,
HelpField<E>: PrimeField + Absorbable<HelpField<E>>,
MainAffine<E>: Absorbable<HelpField<E>>,
HelpAffine<E>: Absorbable<MainField<E>>,
MainField<E>: PrimeField + Absorb,
HelpField<E>: PrimeField + Absorb,
MainAffine<E>: Absorb,
HelpAffine<E>: Absorb,
PC: R1CSNarkPCDConfig<E>,
P: PCDPredicate<MainField<E>>,
<PC::MainSponge as CryptographicSponge>::Parameters: CryptographicSpongeParameters,
<PC::HelpSponge as CryptographicSponge>::Parameters: CryptographicSpongeParameters,
{
/// Returns the public input size of the help circuit.
pub(crate) fn public_input_size() -> usize {
Expand All @@ -84,7 +89,7 @@ where
main_avk: &r1cs_nark_as::VerifierKey,
main_accumulator_instance: &AccumulatorInstance<MainAffine<E>>,
) -> HelpField<E> {
let mut sponge = PC::HelpSponge::new();
let mut sponge = PC::HelpSponge::from_rate(SPONGE_RATE);
absorb!(&mut sponge, main_avk, main_accumulator_instance);
sponge.squeeze_field_elements(1).pop().unwrap()
}
Expand All @@ -95,7 +100,8 @@ where
main_avk_var: &r1cs_nark_as::constraints::VerifierKeyVar<HelpField<E>>,
main_accumulator_instance_var: &AccumulatorInstanceVar<MainAffine<E>, PC::MainCurveVar>,
) -> Result<FpVar<HelpField<E>>, SynthesisError> {
let mut sponge = PC::HelpSpongeVar::new(cs);
let sponge_params = <PC::HelpSponge as CryptographicSponge>::Parameters::from_rate(SPONGE_RATE);
let mut sponge = PC::HelpSpongeVar::new(cs, &sponge_params);
absorb_gadget!(&mut sponge, main_avk_var, main_accumulator_instance_var);
Ok(sponge.squeeze_field_elements(1)?.pop().unwrap())
}
Expand All @@ -119,12 +125,14 @@ where
impl<E, PC, P> ConstraintSynthesizer<HelpField<E>> for HelpCircuit<E, PC, P>
where
E: CurveCycle,
MainField<E>: PrimeField + Absorbable<MainField<E>>,
HelpField<E>: PrimeField + Absorbable<HelpField<E>>,
MainAffine<E>: Absorbable<HelpField<E>>,
HelpAffine<E>: Absorbable<MainField<E>>,
MainField<E>: PrimeField + Absorb,
HelpField<E>: PrimeField + Absorb,
MainAffine<E>: Absorb,
HelpAffine<E>: Absorb,
PC: R1CSNarkPCDConfig<E>,
P: PCDPredicate<MainField<E>>,
<PC::MainSponge as CryptographicSponge>::Parameters: CryptographicSpongeParameters,
<PC::HelpSponge as CryptographicSponge>::Parameters: CryptographicSpongeParameters,
{
fn generate_constraints(
self,
Expand Down Expand Up @@ -243,6 +251,8 @@ where

input_hash_var.enforce_equal(&claimed_input_hash_var)?;

let sponge_params = <PC::HelpSponge as CryptographicSponge>::Parameters::from_rate(SPONGE_RATE);
let help_sponge = PC::HelpSpongeVar::new(cs.clone(), &sponge_params);
let as_verify = ASForR1CSNarkVerifierGadget::<
MainAffine<E>,
PC::MainCurveVar,
Expand All @@ -255,7 +265,7 @@ where
&main_old_accumulator_instance_vars,
&main_new_accumulator_instance_var,
&main_accumulation_proof_var,
None,
Some(help_sponge),
)?;

base_case_var
Expand Down
Loading