From ffc451b7963b5aa6cd9bcda02e6f4e95e87e7485 Mon Sep 17 00:00:00 2001 From: Victor Lopez Date: Mon, 16 May 2022 16:29:09 +0200 Subject: [PATCH 1/4] Update dependencies to 0.3 --- Cargo.toml | 38 ++++++++--------- src/ec_cycle_pcd/mod.rs | 12 +++--- src/lib.rs | 8 ++-- src/r1cs_nark_pcd/help_circuit.rs | 34 ++++++++------- src/r1cs_nark_pcd/main_circuit.rs | 33 ++++++++------- src/r1cs_nark_pcd/mod.rs | 69 ++++++++++++++++++------------- 6 files changed, 107 insertions(+), 87 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 12132b1..29b8c9a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", 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" ] } diff --git a/src/ec_cycle_pcd/mod.rs b/src/ec_cycle_pcd/mod.rs index 528ee23..2f636af 100644 --- a/src/ec_cycle_pcd/mod.rs +++ b/src/ec_cycle_pcd/mod.rs @@ -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}; @@ -255,14 +255,14 @@ where } pub struct BoundTestingPredicate< - F: PrimeField + Absorbable, + F: PrimeField + Absorb, BoundCircuit: ConstraintSynthesizer + Clone, > { pub bound_circuit: BoundCircuit, pub field_phantom: PhantomData, } -impl, BoundCircuit: ConstraintSynthesizer + Clone> Clone +impl + Clone> Clone for BoundTestingPredicate { fn clone(&self) -> Self { @@ -273,7 +273,7 @@ impl, BoundCircuit: ConstraintSynthesizer + Clo } } -impl, BoundCircuit: ConstraintSynthesizer + Clone> PCDPredicate +impl + Clone> PCDPredicate for BoundTestingPredicate { type Message = F; @@ -307,8 +307,8 @@ impl, BoundCircuit: ConstraintSynthesizer + Clo impl UniversalSetupPCD for ECCyclePCD where - MainField: PrimeField + Absorbable, - HelpField: PrimeField + Absorbable, + MainField: PrimeField + Absorb, + HelpField: PrimeField + Absorb, IC: ECCyclePCDConfig, IC::MainSNARK: UniversalSetupSNARK, IC::HelpSNARK: UniversalSetupSNARK, diff --git a/src/lib.rs b/src/lib.rs index 0ffdd6b..8412838 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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}; @@ -18,8 +18,8 @@ extern crate derivative; pub type Error = Box; pub trait PCDPredicate: Clone { - type Message: Absorbable + ToBytes + Sized + Clone + Default; - type MessageVar: AbsorbableGadget + ToBytesGadget + AllocVar; + type Message: Absorb + ToBytes + Sized + Clone + Default; + type MessageVar: AbsorbGadget + ToBytesGadget + AllocVar; type LocalWitness: Sized + Clone + Default; type LocalWitnessVar: AllocVar; diff --git a/src/r1cs_nark_pcd/help_circuit.rs b/src/r1cs_nark_pcd/help_circuit.rs index a184b0e..46003af 100644 --- a/src/r1cs_nark_pcd/help_circuit.rs +++ b/src/r1cs_nark_pcd/help_circuit.rs @@ -10,6 +10,8 @@ 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::ahp::CryptographicSpongeVarNonNative; +use ark_marlin::ahp::CryptographicSpongeWithDefault; use ark_r1cs_std::alloc::AllocVar; use ark_r1cs_std::bits::boolean::Boolean; use ark_r1cs_std::eq::EqGadget; @@ -19,7 +21,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 @@ -29,10 +31,10 @@ use ark_std::marker::PhantomData; pub(crate) struct HelpCircuit where E: CurveCycle, - MainField: PrimeField + Absorbable>, - HelpField: PrimeField + Absorbable>, - MainAffine: Absorbable>, - HelpAffine: Absorbable>, + MainField: PrimeField + Absorb, + HelpField: PrimeField + Absorb, + MainAffine: Absorb, + HelpAffine: Absorb, PC: R1CSNarkPCDConfig, P: PCDPredicate>, { @@ -65,10 +67,10 @@ where impl HelpCircuit where E: CurveCycle, - MainField: PrimeField + Absorbable>, - HelpField: PrimeField + Absorbable>, - MainAffine: Absorbable>, - HelpAffine: Absorbable>, + MainField: PrimeField + Absorb, + HelpField: PrimeField + Absorb, + MainAffine: Absorb, + HelpAffine: Absorb, PC: R1CSNarkPCDConfig, P: PCDPredicate>, { @@ -84,7 +86,8 @@ where main_avk: &r1cs_nark_as::VerifierKey, main_accumulator_instance: &AccumulatorInstance>, ) -> HelpField { - let mut sponge = PC::HelpSponge::new(); + let params = PC::HelpSponge::default_params(); + let mut sponge = PC::HelpSponge::new(¶ms); absorb!(&mut sponge, main_avk, main_accumulator_instance); sponge.squeeze_field_elements(1).pop().unwrap() } @@ -95,7 +98,8 @@ where main_avk_var: &r1cs_nark_as::constraints::VerifierKeyVar>, main_accumulator_instance_var: &AccumulatorInstanceVar, PC::MainCurveVar>, ) -> Result>, SynthesisError> { - let mut sponge = PC::HelpSpongeVar::new(cs); + let params = PC::HelpSpongeVar::default_params(); + let mut sponge = PC::HelpSpongeVar::new(cs, ¶ms); absorb_gadget!(&mut sponge, main_avk_var, main_accumulator_instance_var); Ok(sponge.squeeze_field_elements(1)?.pop().unwrap()) } @@ -119,10 +123,10 @@ where impl ConstraintSynthesizer> for HelpCircuit where E: CurveCycle, - MainField: PrimeField + Absorbable>, - HelpField: PrimeField + Absorbable>, - MainAffine: Absorbable>, - HelpAffine: Absorbable>, + MainField: PrimeField + Absorb, + HelpField: PrimeField + Absorb, + MainAffine: Absorb, + HelpAffine: Absorb, PC: R1CSNarkPCDConfig, P: PCDPredicate>, { diff --git a/src/r1cs_nark_pcd/main_circuit.rs b/src/r1cs_nark_pcd/main_circuit.rs index 5c47bbd..f29558c 100644 --- a/src/r1cs_nark_pcd/main_circuit.rs +++ b/src/r1cs_nark_pcd/main_circuit.rs @@ -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::ahp::{CryptographicSpongeVarNonNative, CryptographicSpongeWithDefault}; use ark_r1cs_std::alloc::AllocVar; use ark_r1cs_std::bits::boolean::Boolean; use ark_r1cs_std::eq::EqGadget; @@ -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 help circuit was computed @@ -29,10 +30,10 @@ use ark_std::marker::PhantomData; pub(crate) struct MainCircuit where E: CurveCycle, - MainField: PrimeField + Absorbable>, - HelpField: PrimeField + Absorbable>, - MainAffine: Absorbable>, - HelpAffine: Absorbable>, + MainField: PrimeField + Absorb, + HelpField: PrimeField + Absorb, + MainAffine: Absorb, + HelpAffine: Absorb, PC: R1CSNarkPCDConfig, P: PCDPredicate>, { @@ -74,10 +75,10 @@ where impl MainCircuit where E: CurveCycle, - MainField: PrimeField + Absorbable>, - HelpField: PrimeField + Absorbable>, - MainAffine: Absorbable>, - HelpAffine: Absorbable>, + MainField: PrimeField + Absorb, + HelpField: PrimeField + Absorb, + MainAffine: Absorb, + HelpAffine: Absorb, PC: R1CSNarkPCDConfig, P: PCDPredicate>, { @@ -94,7 +95,8 @@ where help_accumulator_instance: &AccumulatorInstance>, msg: &P::Message, ) -> MainField { - let mut sponge = PC::MainSponge::new(); + let params = PC::MainSponge::default_params(); + let mut sponge = PC::MainSponge::new(¶ms); absorb!(&mut sponge, help_avk, help_accumulator_instance, msg); sponge.squeeze_field_elements(1).pop().unwrap() } @@ -106,7 +108,8 @@ where help_accumulator_instance_var: &AccumulatorInstanceVar, PC::HelpCurveVar>, msg_var: &P::MessageVar, ) -> Result>, SynthesisError> { - let mut sponge = PC::MainSpongeVar::new(cs); + let params = PC::MainSpongeVar::default_params(); + let mut sponge = PC::MainSpongeVar::new(cs, ¶ms); absorb_gadget!( &mut sponge, help_avk_var, @@ -136,10 +139,10 @@ where impl ConstraintSynthesizer> for MainCircuit where E: CurveCycle, - MainField: PrimeField + Absorbable>, - HelpField: PrimeField + Absorbable>, - MainAffine: Absorbable>, - HelpAffine: Absorbable>, + MainField: PrimeField + Absorb, + HelpField: PrimeField + Absorb, + MainAffine: Absorb, + HelpAffine: Absorb, PC: R1CSNarkPCDConfig, P: PCDPredicate>, { diff --git a/src/r1cs_nark_pcd/mod.rs b/src/r1cs_nark_pcd/mod.rs index 89524be..4cbc734 100644 --- a/src/r1cs_nark_pcd/mod.rs +++ b/src/r1cs_nark_pcd/mod.rs @@ -7,9 +7,10 @@ use ark_accumulation::{ }; use ark_ec::CurveCycle; use ark_ff::PrimeField; +use ark_marlin::ahp::{CryptographicSpongeVarNonNative, CryptographicSpongeWithDefault}; use ark_r1cs_std::groups::CurveVar; -use ark_sponge::constraints::{AbsorbableGadget, CryptographicSpongeVar}; -use ark_sponge::{Absorbable, CryptographicSponge}; +use ark_sponge::constraints::AbsorbGadget; +use ark_sponge::{Absorb, CryptographicSponge}; use ark_std::marker::PhantomData; use ark_std::rand::{CryptoRng, Rng}; use help_circuit::HelpCircuit; @@ -33,28 +34,36 @@ pub(crate) const MAKE_ZK: bool = true; pub trait R1CSNarkPCDConfig where E: CurveCycle, - MainField: PrimeField + Absorbable>, - HelpField: PrimeField + Absorbable>, - MainAffine: Absorbable>, - HelpAffine: Absorbable>, + MainField: PrimeField + Absorb, + HelpField: PrimeField + Absorb, + MainAffine: Absorb, + HelpAffine: Absorb, { /// The curve var for the main affine. - type MainCurveVar: CurveVar, HelpField> + AbsorbableGadget>; + type MainCurveVar: CurveVar, HelpField> + AbsorbGadget>; /// The curve var for the help affine. - type HelpCurveVar: CurveVar, MainField> + AbsorbableGadget>; + type HelpCurveVar: CurveVar, MainField> + AbsorbGadget>; /// The sponge that the main circuit uses. - type MainSponge: CryptographicSponge>; + type MainSponge: CryptographicSpongeWithDefault; /// The sponge var that the main circuit uses. - type MainSpongeVar: CryptographicSpongeVar, Self::MainSponge>; + type MainSpongeVar: CryptographicSpongeVarNonNative< + HelpField, + MainField, + Self::MainSponge, + >; /// The sponge that the help circuit uses. - type HelpSponge: CryptographicSponge>; + type HelpSponge: CryptographicSpongeWithDefault; /// The sponge var that the help circuit uses. - type HelpSpongeVar: CryptographicSpongeVar, Self::HelpSponge>; + type HelpSpongeVar: CryptographicSpongeVarNonNative< + MainField, + HelpField, + Self::HelpSponge, + >; } /// A PCD that does not rely on SNARKs but instead builds on an R1CS NARK construction and its @@ -107,10 +116,10 @@ where pub struct R1CSNarkPCD where E: CurveCycle, - MainField: PrimeField + Absorbable>, - HelpField: PrimeField + Absorbable>, - MainAffine: Absorbable>, - HelpAffine: Absorbable>, + MainField: PrimeField + Absorb, + HelpField: PrimeField + Absorb, + MainAffine: Absorb, + HelpAffine: Absorb, PC: R1CSNarkPCDConfig, { _curve_cycle_phantom: PhantomData, @@ -120,10 +129,10 @@ where impl PCD> for R1CSNarkPCD where E: CurveCycle, - MainField: PrimeField + Absorbable>, - HelpField: PrimeField + Absorbable>, - MainAffine: Absorbable>, - HelpAffine: Absorbable>, + MainField: PrimeField + Absorb, + HelpField: PrimeField + Absorb, + MainAffine: Absorb, + HelpAffine: Absorb, PC: R1CSNarkPCDConfig, { type ProvingKey = ProvingKey; @@ -348,7 +357,8 @@ where _config_phantom: PhantomData, }; - let help_sponge = PC::HelpSponge::new(); + let params = PC::HelpSponge::default_params(); + let help_sponge = PC::HelpSponge::new(¶ms); let main_nark_sponge = ASForR1CSNark::, PC::HelpSponge>::nark_sponge(&help_sponge); @@ -436,7 +446,8 @@ where _predicate_phantom: PhantomData, }; - let main_sponge = PC::MainSponge::new(); + let params = PC::MainSponge::default_params(); + let main_sponge = PC::MainSponge::new(¶ms); let help_nark_sponge = ASForR1CSNark::, PC::MainSponge>::nark_sponge(&main_sponge); @@ -480,7 +491,8 @@ where proof: &Self::Proof, ) -> Result { let main_nark_verify = { - let help_sponge = PC::HelpSponge::new(); + let params = PC::HelpSponge::default_params(); + let help_sponge = PC::HelpSponge::new(¶ms); let main_nark_sponge = ASForR1CSNark::, PC::HelpSponge>::nark_sponge(&help_sponge); @@ -497,7 +509,8 @@ where }; let help_nark_verify = { - let main_sponge = PC::MainSponge::new(); + let params = PC::MainSponge::default_params(); + let main_sponge = PC::MainSponge::new(¶ms); let help_nark_sponge = ASForR1CSNark::, PC::MainSponge>::nark_sponge(&main_sponge); @@ -556,10 +569,10 @@ where impl CircuitSpecificSetupPCD> for R1CSNarkPCD where E: CurveCycle, - MainField: PrimeField + Absorbable>, - HelpField: PrimeField + Absorbable>, - MainAffine: Absorbable>, - HelpAffine: Absorbable>, + MainField: PrimeField + Absorb, + HelpField: PrimeField + Absorb, + MainAffine: Absorb, + HelpAffine: Absorb, PC: R1CSNarkPCDConfig, { } From 5c081598dc84020eff0a02e470a7bc7141c918bb Mon Sep 17 00:00:00 2001 From: weikengchen Date: Sat, 21 May 2022 13:03:17 -0700 Subject: [PATCH 2/4] some changes to fix the tests --- src/lib.rs | 20 ++++++++++---------- tests/mnt4_gm17.rs | 4 ++-- tests/mnt4_groth16.rs | 4 ++-- tests/mnt4_marlin.rs | 4 ++-- tests/mnt4_mix_gm17groth16.rs | 4 ++-- tests/mnt4_mix_groth16gm17.rs | 4 ++-- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8412838..6442369 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -102,15 +102,15 @@ 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> { + pub struct TestIVCPredicate { pub field_phantom: PhantomData, } - impl> TestIVCPredicate { + impl TestIVCPredicate { fn new() -> Self { Self { field_phantom: PhantomData, @@ -118,7 +118,7 @@ pub mod tests { } } - impl> PCDPredicate for TestIVCPredicate { + impl PCDPredicate for TestIVCPredicate { type Message = F; type MessageVar = FpVar; type LocalWitness = F; @@ -142,11 +142,11 @@ pub mod tests { } #[derive(Clone)] - pub struct TestPCDPredicate> { + pub struct TestPCDPredicate { pub field_phantom: PhantomData, } - impl> TestPCDPredicate { + impl TestPCDPredicate { fn new() -> Self { Self { field_phantom: PhantomData, @@ -154,7 +154,7 @@ pub mod tests { } } - impl> PCDPredicate for TestPCDPredicate { + impl PCDPredicate for TestPCDPredicate { type Message = F; type MessageVar = FpVar; type LocalWitness = F; @@ -177,7 +177,7 @@ pub mod tests { } } - pub fn test_ivc_base_case, TestPCD: PCD>() { + pub fn test_ivc_base_case>() { let mut rng = ark_std::test_rng(); let witness = F::one(); @@ -190,7 +190,7 @@ pub mod tests { assert!(TestPCD::verify::>(&vk, &msg_0, &proof_0).unwrap()); } - pub fn test_ivc, TestPCD: PCD>() { + pub fn test_ivc>() { let mut rng = ark_std::test_rng(); let witness = F::one(); @@ -229,7 +229,7 @@ pub mod tests { assert!(TestPCD::verify::>(&vk, &msg_2, &proof_2).unwrap()); } - pub fn test_pcd, TestPCD: PCD>() { + pub fn test_pcd>() { let mut rng = ark_std::test_rng(); let witness = F::one(); diff --git a/tests/mnt4_gm17.rs b/tests/mnt4_gm17.rs index 4a89f29..d5ab944 100644 --- a/tests/mnt4_gm17.rs +++ b/tests/mnt4_gm17.rs @@ -17,7 +17,7 @@ use ark_r1cs_std::eq::EqGadget; use ark_r1cs_std::fields::fp::FpVar; use ark_relations::r1cs::ConstraintSystemRef; use ark_relations::r1cs::SynthesisError; -use ark_sponge::Absorbable; +use ark_sponge::Absorb; use core::marker::PhantomData; use rand_chacha::ChaChaRng; @@ -51,7 +51,7 @@ impl Clone for TestPredicate { } } -impl> PCDPredicate for TestPredicate { +impl PCDPredicate for TestPredicate { type Message = F; type MessageVar = FpVar; type LocalWitness = F; diff --git a/tests/mnt4_groth16.rs b/tests/mnt4_groth16.rs index e82d3b4..7eabed0 100644 --- a/tests/mnt4_groth16.rs +++ b/tests/mnt4_groth16.rs @@ -16,7 +16,7 @@ use ark_r1cs_std::eq::EqGadget; use ark_r1cs_std::fields::fp::FpVar; use ark_relations::r1cs::ConstraintSystemRef; use ark_relations::r1cs::SynthesisError; -use ark_sponge::Absorbable; +use ark_sponge::Absorb; use core::marker::PhantomData; use rand_chacha::ChaChaRng; @@ -50,7 +50,7 @@ impl Clone for TestPredicate { } } -impl> PCDPredicate for TestPredicate { +impl PCDPredicate for TestPredicate { type Message = F; type MessageVar = FpVar; type LocalWitness = F; diff --git a/tests/mnt4_marlin.rs b/tests/mnt4_marlin.rs index 9f1e130..3b9d9bb 100644 --- a/tests/mnt4_marlin.rs +++ b/tests/mnt4_marlin.rs @@ -25,7 +25,7 @@ use ark_r1cs_std::eq::EqGadget; use ark_r1cs_std::fields::fp::FpVar; use ark_relations::r1cs::ConstraintSystemRef; use ark_relations::r1cs::SynthesisError; -use ark_sponge::Absorbable; +use ark_sponge::Absorb; use core::marker::PhantomData; use rand_chacha::ChaChaRng; @@ -114,7 +114,7 @@ impl Clone for TestPredicate { } } -impl> PCDPredicate for TestPredicate { +impl PCDPredicate for TestPredicate { type Message = F; type MessageVar = FpVar; type LocalWitness = F; diff --git a/tests/mnt4_mix_gm17groth16.rs b/tests/mnt4_mix_gm17groth16.rs index c3b8c8b..e3c1e60 100644 --- a/tests/mnt4_mix_gm17groth16.rs +++ b/tests/mnt4_mix_gm17groth16.rs @@ -18,7 +18,7 @@ use ark_r1cs_std::eq::EqGadget; use ark_r1cs_std::fields::fp::FpVar; use ark_relations::r1cs::ConstraintSystemRef; use ark_relations::r1cs::SynthesisError; -use ark_sponge::Absorbable; +use ark_sponge::Absorb; use core::marker::PhantomData; use rand_chacha::ChaChaRng; @@ -52,7 +52,7 @@ impl Clone for TestPredicate { } } -impl> PCDPredicate for TestPredicate { +impl PCDPredicate for TestPredicate { type Message = F; type MessageVar = FpVar; type LocalWitness = F; diff --git a/tests/mnt4_mix_groth16gm17.rs b/tests/mnt4_mix_groth16gm17.rs index ec6323d..b1a9cf7 100644 --- a/tests/mnt4_mix_groth16gm17.rs +++ b/tests/mnt4_mix_groth16gm17.rs @@ -18,7 +18,7 @@ use ark_r1cs_std::eq::EqGadget; use ark_r1cs_std::fields::fp::FpVar; use ark_relations::r1cs::ConstraintSystemRef; use ark_relations::r1cs::SynthesisError; -use ark_sponge::Absorbable; +use ark_sponge::Absorb; use core::marker::PhantomData; use rand_chacha::ChaChaRng; @@ -52,7 +52,7 @@ impl Clone for TestPredicate { } } -impl> PCDPredicate for TestPredicate { +impl PCDPredicate for TestPredicate { type Message = F; type MessageVar = FpVar; type LocalWitness = F; From b4a9fc6eb493cc5ff6ba9701989e060fb6446d7c Mon Sep 17 00:00:00 2001 From: Deevashwer Rathee Date: Sat, 4 Jun 2022 19:06:55 -0700 Subject: [PATCH 3/4] all tests compiling but mnt4_marlin --- Cargo.toml | 2 +- src/r1cs_nark_pcd/data_structures.rs | 3 ++ src/r1cs_nark_pcd/help_circuit.rs | 18 +++++++----- src/r1cs_nark_pcd/main_circuit.rs | 17 +++++++---- src/r1cs_nark_pcd/mod.rs | 44 +++++++++++++--------------- tests/mnt4_marlin.rs | 6 ++-- 6 files changed, 50 insertions(+), 40 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 29b8c9a..15827d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ derivative = { version = "2.0", features = ["use_core"] } 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", 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" ] } diff --git a/src/r1cs_nark_pcd/data_structures.rs b/src/r1cs_nark_pcd/data_structures.rs index a0f3e94..f07a3e7 100644 --- a/src/r1cs_nark_pcd/data_structures.rs +++ b/src/r1cs_nark_pcd/data_structures.rs @@ -11,6 +11,9 @@ pub(crate) type HelpField = <::E2 as AffineCurve>::ScalarFie pub(crate) type MainProjective = as AffineCurve>::Projective; pub(crate) type HelpProjective = 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 diff --git a/src/r1cs_nark_pcd/help_circuit.rs b/src/r1cs_nark_pcd/help_circuit.rs index 46003af..af2b197 100644 --- a/src/r1cs_nark_pcd/help_circuit.rs +++ b/src/r1cs_nark_pcd/help_circuit.rs @@ -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; @@ -10,8 +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::ahp::CryptographicSpongeVarNonNative; -use ark_marlin::ahp::CryptographicSpongeWithDefault; +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; @@ -37,6 +36,8 @@ where HelpAffine: Absorb, PC: R1CSNarkPCDConfig, P: PCDPredicate>, + ::Parameters: CryptographicSpongeParameters, + ::Parameters: CryptographicSpongeParameters, { /// The key for verifying the accumulation of arguments about the main circuit. pub(crate) main_avk: r1cs_nark_as::VerifierKey, @@ -73,6 +74,8 @@ where HelpAffine: Absorb, PC: R1CSNarkPCDConfig, P: PCDPredicate>, + ::Parameters: CryptographicSpongeParameters, + ::Parameters: CryptographicSpongeParameters, { /// Returns the public input size of the help circuit. pub(crate) fn public_input_size() -> usize { @@ -86,8 +89,7 @@ where main_avk: &r1cs_nark_as::VerifierKey, main_accumulator_instance: &AccumulatorInstance>, ) -> HelpField { - let params = PC::HelpSponge::default_params(); - let mut sponge = PC::HelpSponge::new(¶ms); + let mut sponge = PC::HelpSponge::from_rate(SPONGE_RATE); absorb!(&mut sponge, main_avk, main_accumulator_instance); sponge.squeeze_field_elements(1).pop().unwrap() } @@ -98,8 +100,8 @@ where main_avk_var: &r1cs_nark_as::constraints::VerifierKeyVar>, main_accumulator_instance_var: &AccumulatorInstanceVar, PC::MainCurveVar>, ) -> Result>, SynthesisError> { - let params = PC::HelpSpongeVar::default_params(); - let mut sponge = PC::HelpSpongeVar::new(cs, ¶ms); + let sponge_params = ::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()) } @@ -129,6 +131,8 @@ where HelpAffine: Absorb, PC: R1CSNarkPCDConfig, P: PCDPredicate>, + ::Parameters: CryptographicSpongeParameters, + ::Parameters: CryptographicSpongeParameters, { fn generate_constraints( self, diff --git a/src/r1cs_nark_pcd/main_circuit.rs b/src/r1cs_nark_pcd/main_circuit.rs index f29558c..0d8e22b 100644 --- a/src/r1cs_nark_pcd/main_circuit.rs +++ b/src/r1cs_nark_pcd/main_circuit.rs @@ -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::help_circuit::HelpCircuit; use crate::r1cs_nark_pcd::{R1CSNarkPCDConfig, MAKE_ZK}; use crate::PCDPredicate; @@ -10,7 +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::ahp::{CryptographicSpongeVarNonNative, CryptographicSpongeWithDefault}; +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; @@ -36,6 +36,8 @@ where HelpAffine: Absorb, PC: R1CSNarkPCDConfig, P: PCDPredicate>, + ::Parameters: CryptographicSpongeParameters, + ::Parameters: CryptographicSpongeParameters, { /// The PCD predicate. pub(crate) predicate: P, @@ -81,6 +83,8 @@ where HelpAffine: Absorb, PC: R1CSNarkPCDConfig, P: PCDPredicate>, + ::Parameters: CryptographicSpongeParameters, + ::Parameters: CryptographicSpongeParameters, { /// Returns the public input size of the main circuit. pub(crate) fn public_input_size() -> usize { @@ -95,8 +99,7 @@ where help_accumulator_instance: &AccumulatorInstance>, msg: &P::Message, ) -> MainField { - let params = PC::MainSponge::default_params(); - let mut sponge = PC::MainSponge::new(¶ms); + let mut sponge = PC::MainSponge::from_rate(SPONGE_RATE); absorb!(&mut sponge, help_avk, help_accumulator_instance, msg); sponge.squeeze_field_elements(1).pop().unwrap() } @@ -108,8 +111,8 @@ where help_accumulator_instance_var: &AccumulatorInstanceVar, PC::HelpCurveVar>, msg_var: &P::MessageVar, ) -> Result>, SynthesisError> { - let params = PC::MainSpongeVar::default_params(); - let mut sponge = PC::MainSpongeVar::new(cs, ¶ms); + let sponge_params = ::Parameters::from_rate(SPONGE_RATE); + let mut sponge = PC::MainSpongeVar::new(cs, &sponge_params); absorb_gadget!( &mut sponge, help_avk_var, @@ -145,6 +148,8 @@ where HelpAffine: Absorb, PC: R1CSNarkPCDConfig, P: PCDPredicate>, + ::Parameters: CryptographicSpongeParameters, + ::Parameters: CryptographicSpongeParameters, { fn generate_constraints( self, diff --git a/src/r1cs_nark_pcd/mod.rs b/src/r1cs_nark_pcd/mod.rs index 4cbc734..6a68aa4 100644 --- a/src/r1cs_nark_pcd/mod.rs +++ b/src/r1cs_nark_pcd/mod.rs @@ -7,10 +7,11 @@ use ark_accumulation::{ }; use ark_ec::CurveCycle; use ark_ff::PrimeField; -use ark_marlin::ahp::{CryptographicSpongeVarNonNative, CryptographicSpongeWithDefault}; +use ark_marlin::CryptographicSpongeParameters; +use ark_marlin::sponge::{CryptographicSpongeWithRate}; use ark_r1cs_std::groups::CurveVar; use ark_sponge::constraints::AbsorbGadget; -use ark_sponge::{Absorb, CryptographicSponge}; +use ark_sponge::{Absorb, CryptographicSponge, constraints::CryptographicSpongeVar}; use ark_std::marker::PhantomData; use ark_std::rand::{CryptoRng, Rng}; use help_circuit::HelpCircuit; @@ -38,6 +39,8 @@ where HelpField: PrimeField + Absorb, MainAffine: Absorb, HelpAffine: Absorb, + ::Parameters: CryptographicSpongeParameters, + ::Parameters: CryptographicSpongeParameters, { /// The curve var for the main affine. type MainCurveVar: CurveVar, HelpField> + AbsorbGadget>; @@ -46,24 +49,16 @@ where type HelpCurveVar: CurveVar, MainField> + AbsorbGadget>; /// The sponge that the main circuit uses. - type MainSponge: CryptographicSpongeWithDefault; + type MainSponge: CryptographicSpongeWithRate; /// The sponge var that the main circuit uses. - type MainSpongeVar: CryptographicSpongeVarNonNative< - HelpField, - MainField, - Self::MainSponge, - >; + type MainSpongeVar: CryptographicSpongeVar, Self::MainSponge, Parameters = ::Parameters>; /// The sponge that the help circuit uses. - type HelpSponge: CryptographicSpongeWithDefault; + type HelpSponge: CryptographicSpongeWithRate; /// The sponge var that the help circuit uses. - type HelpSpongeVar: CryptographicSpongeVarNonNative< - MainField, - HelpField, - Self::HelpSponge, - >; + type HelpSpongeVar: CryptographicSpongeVar, Self::HelpSponge, Parameters = ::Parameters>; } /// A PCD that does not rely on SNARKs but instead builds on an R1CS NARK construction and its @@ -121,6 +116,8 @@ where MainAffine: Absorb, HelpAffine: Absorb, PC: R1CSNarkPCDConfig, + ::Parameters: CryptographicSpongeParameters, + ::Parameters: CryptographicSpongeParameters, { _curve_cycle_phantom: PhantomData, _config_phantom: PhantomData, @@ -134,6 +131,8 @@ where MainAffine: Absorb, HelpAffine: Absorb, PC: R1CSNarkPCDConfig, + ::Parameters: CryptographicSpongeParameters, + ::Parameters: CryptographicSpongeParameters, { type ProvingKey = ProvingKey; type VerifyingKey = VerifyingKey; @@ -357,8 +356,7 @@ where _config_phantom: PhantomData, }; - let params = PC::HelpSponge::default_params(); - let help_sponge = PC::HelpSponge::new(¶ms); + let help_sponge = PC::HelpSponge::from_rate(SPONGE_RATE); let main_nark_sponge = ASForR1CSNark::, PC::HelpSponge>::nark_sponge(&help_sponge); @@ -446,8 +444,7 @@ where _predicate_phantom: PhantomData, }; - let params = PC::MainSponge::default_params(); - let main_sponge = PC::MainSponge::new(¶ms); + let main_sponge = PC::MainSponge::from_rate(SPONGE_RATE); let help_nark_sponge = ASForR1CSNark::, PC::MainSponge>::nark_sponge(&main_sponge); @@ -491,8 +488,7 @@ where proof: &Self::Proof, ) -> Result { let main_nark_verify = { - let params = PC::HelpSponge::default_params(); - let help_sponge = PC::HelpSponge::new(¶ms); + let help_sponge = PC::HelpSponge::from_rate(SPONGE_RATE); let main_nark_sponge = ASForR1CSNark::, PC::HelpSponge>::nark_sponge(&help_sponge); @@ -509,8 +505,7 @@ where }; let help_nark_verify = { - let params = PC::MainSponge::default_params(); - let main_sponge = PC::MainSponge::new(¶ms); + let main_sponge = PC::MainSponge::from_rate(SPONGE_RATE); let help_nark_sponge = ASForR1CSNark::, PC::MainSponge>::nark_sponge(&main_sponge); @@ -574,6 +569,8 @@ where MainAffine: Absorb, HelpAffine: Absorb, PC: R1CSNarkPCDConfig, + ::Parameters: CryptographicSpongeParameters, + ::Parameters: CryptographicSpongeParameters, { } @@ -603,7 +600,8 @@ pub mod tests { } pub struct TestConfig {} - impl R1CSNarkPCDConfig for TestConfig { + impl R1CSNarkPCDConfig for TestConfig + { type MainCurveVar = MainCurveVar; type HelpCurveVar = HelpCurveVar; type MainSponge = MainSponge; diff --git a/tests/mnt4_marlin.rs b/tests/mnt4_marlin.rs index 3b9d9bb..1c1a7ec 100644 --- a/tests/mnt4_marlin.rs +++ b/tests/mnt4_marlin.rs @@ -5,10 +5,10 @@ use ark_ec::{CurveCycle, PairingEngine, PairingFriendlyCycle}; use ark_ed_on_mnt4_298::EdwardsParameters; use ark_ff::{One, PrimeField}; use ark_marlin::constraints::snark::{MarlinSNARK, MarlinSNARKGadget}; +use ark_sponge::poseidon::constraints::PoseidonSpongeVar; +use ark_sponge::poseidon::PoseidonSponge; use ark_marlin::fiat_shamir::constraints::FiatShamirAlgebraicSpongeRngVar; -use ark_marlin::fiat_shamir::poseidon::constraints::PoseidonSpongeVar; -use ark_marlin::fiat_shamir::poseidon::PoseidonSponge; -use ark_marlin::fiat_shamir::FiatShamirAlgebraicSpongeRng; +use ark_marlin::fiat_shamir::FiatShamirRng; use ark_marlin::MarlinConfig; use ark_mnt4_298::constraints::PairingVar as MNT4PairingVar; use ark_mnt4_298::{Fq, Fr, MNT4_298}; From ee5ebaff60bd2064cb1e3dfe88328564f48bd186 Mon Sep 17 00:00:00 2001 From: Deevashwer Rathee Date: Sat, 4 Jun 2022 20:28:18 -0700 Subject: [PATCH 4/4] passing sponge instead of None to accumulation --- src/r1cs_nark_pcd/help_circuit.rs | 4 +++- src/r1cs_nark_pcd/main_circuit.rs | 4 +++- src/r1cs_nark_pcd/mod.rs | 12 ++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/r1cs_nark_pcd/help_circuit.rs b/src/r1cs_nark_pcd/help_circuit.rs index af2b197..ea52705 100644 --- a/src/r1cs_nark_pcd/help_circuit.rs +++ b/src/r1cs_nark_pcd/help_circuit.rs @@ -251,6 +251,8 @@ where input_hash_var.enforce_equal(&claimed_input_hash_var)?; + let sponge_params = ::Parameters::from_rate(SPONGE_RATE); + let help_sponge = PC::HelpSpongeVar::new(cs.clone(), &sponge_params); let as_verify = ASForR1CSNarkVerifierGadget::< MainAffine, PC::MainCurveVar, @@ -263,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 diff --git a/src/r1cs_nark_pcd/main_circuit.rs b/src/r1cs_nark_pcd/main_circuit.rs index 0d8e22b..80f700e 100644 --- a/src/r1cs_nark_pcd/main_circuit.rs +++ b/src/r1cs_nark_pcd/main_circuit.rs @@ -299,6 +299,8 @@ where input_hash_var.enforce_equal(&claimed_input_hash_var)?; + let sponge_params = ::Parameters::from_rate(SPONGE_RATE); + let main_sponge = PC::MainSpongeVar::new(cs.clone(), &sponge_params); let as_verify = ASForR1CSNarkVerifierGadget::< HelpAffine, PC::HelpCurveVar, @@ -311,7 +313,7 @@ where &help_old_accumulator_instance_vars, &help_new_accumulator_instance_var, &help_accumulation_proof_var, - None, + Some(main_sponge), )?; base_case_var diff --git a/src/r1cs_nark_pcd/mod.rs b/src/r1cs_nark_pcd/mod.rs index 6a68aa4..19f374b 100644 --- a/src/r1cs_nark_pcd/mod.rs +++ b/src/r1cs_nark_pcd/mod.rs @@ -317,6 +317,7 @@ where witness: &proof.help_accumulator.1, }); + let main_sponge = PC::MainSponge::from_rate(SPONGE_RATE); ASForR1CSNark::, PC::MainSponge>::prove( &pk.help_apk, help_accumulation_input_refs, @@ -326,7 +327,7 @@ where } else { MakeZK::Disabled }, - None, + Some(main_sponge), )? }; @@ -409,6 +410,7 @@ where witness: &proof.main_accumulator.1, }); + let help_sponge = PC::HelpSponge::from_rate(SPONGE_RATE); ASForR1CSNark::, PC::HelpSponge>::prove( &pk.main_apk, main_accumulation_input_refs, @@ -418,7 +420,7 @@ where } else { MakeZK::Disabled }, - None, + Some(help_sponge), )? }; @@ -530,10 +532,11 @@ where witness: &proof.main_accumulator.1, }; + let help_sponge = PC::HelpSponge::from_rate(SPONGE_RATE); ASForR1CSNark::, PC::HelpSponge>::decide( &vk.main_ivk, main_accumulator_ref, - None, + Some(help_sponge), )? }; @@ -547,10 +550,11 @@ where witness: &proof.help_accumulator.1, }; + let main_sponge = PC::MainSponge::from_rate(SPONGE_RATE); ASForR1CSNark::, PC::MainSponge>::decide( &vk.help_ivk, help_accumulator_ref, - None, + Some(main_sponge), )? };