From c7cf27ad2085b782605001de069219e773aeb8e8 Mon Sep 17 00:00:00 2001 From: Hossein Moghaddas Date: Wed, 3 Jan 2024 12:31:34 +0100 Subject: [PATCH 1/4] Rename nonnative to emulated, as in `r1cs-std` --- poly-commit/src/constraints.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/poly-commit/src/constraints.rs b/poly-commit/src/constraints.rs index e6fb5d4f..dcd9cdd4 100644 --- a/poly-commit/src/constraints.rs +++ b/poly-commit/src/constraints.rs @@ -5,7 +5,7 @@ use crate::{ use ark_crypto_primitives::sponge::CryptographicSponge; use ark_ff::PrimeField; use ark_poly::Polynomial; -use ark_r1cs_std::fields::nonnative::NonNativeFieldVar; +use ark_r1cs_std::fields::emulated_fp::EmulatedFpVar; use ark_r1cs_std::{fields::fp::FpVar, prelude::*}; use ark_relations::r1cs::{ConstraintSystemRef, Namespace, Result as R1CSResult, SynthesisError}; use ark_std::{borrow::Borrow, cmp::Eq, cmp::PartialEq, hash::Hash, marker::Sized}; @@ -24,8 +24,8 @@ pub enum LinearCombinationCoeffVar), + /// Other coefficient, represented as a "emulated" field element. + Var(EmulatedFpVar), } /// An allocated version of `LinearCombination`. @@ -60,7 +60,7 @@ impl let (f, lc_term) = term; let fg = - NonNativeFieldVar::new_variable(ark_relations::ns!(cs, "term"), || Ok(f), mode) + EmulatedFpVar::new_variable(ark_relations::ns!(cs, "term"), || Ok(f), mode) .unwrap(); (LinearCombinationCoeffVar::Var(fg), lc_term.clone()) @@ -79,12 +79,12 @@ impl pub struct PCCheckRandomDataVar { /// Opening challenges. /// The prover and the verifier MUST use the same opening challenges. - pub opening_challenges: Vec>, + pub opening_challenges: Vec>, /// Bit representations of the opening challenges. pub opening_challenges_bits: Vec>>, /// Batching random numbers. /// The verifier can choose these numbers freely, as long as they are random. - pub batching_rands: Vec>, + pub batching_rands: Vec>, /// Bit representations of the batching random numbers. pub batching_rands_bits: Vec>>, } @@ -172,7 +172,7 @@ pub struct LabeledPointVar { /// MUST be a unique identifier in a query set. pub name: String, /// The point value. - pub value: NonNativeFieldVar, + pub value: EmulatedFpVar, } /// An allocated version of `QuerySet`. @@ -184,7 +184,7 @@ pub struct QuerySetVar( /// An allocated version of `Evaluations`. #[derive(Clone)] pub struct EvaluationsVar( - pub HashMap, NonNativeFieldVar>, + pub HashMap, EmulatedFpVar>, ); impl EvaluationsVar { @@ -192,8 +192,8 @@ impl EvaluationsVar, - ) -> Result, SynthesisError> { + point: &EmulatedFpVar, + ) -> Result, SynthesisError> { let key = LabeledPointVar:: { name: String::from(lc_string), value: point.clone(), From 3a2f4113ea6d0f6634b706febcf3ac5a3f941419 Mon Sep 17 00:00:00 2001 From: Hossein Moghaddas Date: Thu, 4 Jan 2024 11:47:29 +0100 Subject: [PATCH 2/4] Rename `ChallengeGenerator` enum items --- bench-templates/src/lib.rs | 8 ++++---- poly-commit/src/challenge.rs | 40 ++++++++++++++++++------------------ poly-commit/src/lib.rs | 12 +++++------ 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/bench-templates/src/lib.rs b/bench-templates/src/lib.rs index 1594ee7c..1386a1e0 100644 --- a/bench-templates/src/lib.rs +++ b/bench-templates/src/lib.rs @@ -123,7 +123,7 @@ where [&labeled_poly], &coms, &point, - &mut ChallengeGenerator::new_univariate(&mut test_sponge()), + &mut ChallengeGenerator::new_correlated(&mut test_sponge()), &randomness, Some(rng), ) @@ -156,7 +156,7 @@ where [&labeled_poly], &coms, &point, - &mut ChallengeGenerator::new_univariate(&mut test_sponge()), + &mut ChallengeGenerator::new_correlated(&mut test_sponge()), &randomness, Some(rng), ) @@ -193,7 +193,7 @@ where [&labeled_poly], &coms, &point, - &mut ChallengeGenerator::new_univariate(&mut test_sponge()), + &mut ChallengeGenerator::new_correlated(&mut test_sponge()), &randomness, Some(rng), ) @@ -206,7 +206,7 @@ where &point, [claimed_eval], &proof, - &mut ChallengeGenerator::new_univariate(&mut test_sponge()), + &mut ChallengeGenerator::new_correlated(&mut test_sponge()), None, ) .unwrap(); diff --git a/poly-commit/src/challenge.rs b/poly-commit/src/challenge.rs index 23b3c9d1..88823dbf 100644 --- a/poly-commit/src/challenge.rs +++ b/poly-commit/src/challenge.rs @@ -1,45 +1,45 @@ use ark_crypto_primitives::sponge::{CryptographicSponge, FieldElementSize}; use ark_ff::PrimeField; -/// `ChallengeGenerator` generates opening challenges using multivariate or univariate strategy. -/// For multivariate strategy, each challenge is freshly squeezed from a sponge. -/// For univariate strategy, each challenge is a power of one squeezed element from sponge. +/// `ChallengeGenerator` generates opening challenges using independent or correlated strategy. +/// For independent strategy, each challenge is freshly squeezed from a sponge. +/// For correlated strategy, each challenge is a power of one squeezed element from sponge. /// /// Note that mutable reference cannot be cloned. #[derive(Clone)] pub enum ChallengeGenerator { /// Each challenge is freshly squeezed from a sponge. - Multivariate(S), + Independent(S), /// Each challenge is a power of one squeezed element from sponge. /// - /// `Univariate(generator, next_element)` - Univariate(F, F), + /// `Correlated(generator, next_element)` + Correlated(F, F), } impl ChallengeGenerator { - /// Returns a challenge generator with multivariate strategy. Each challenge is freshly squeezed + /// Returns a challenge generator with independent strategy. Each challenge is freshly squeezed /// from a sponge. - pub fn new_multivariate(sponge: S) -> Self { - Self::Multivariate(sponge) + pub fn new_independent(sponge: S) -> Self { + Self::Independent(sponge) } - /// Returns a challenge generator with univariate strategy. Each challenge is a power of one + /// Returns a challenge generator with correlated strategy. Each challenge is a power of one /// squeezed element from sponge. - pub fn new_univariate(sponge: &mut S) -> Self { + pub fn new_correlated(sponge: &mut S) -> Self { let gen = sponge.squeeze_field_elements(1)[0]; - Self::Univariate(gen, gen) + Self::Correlated(gen, gen) } /// Returns a challenge of size `size`. - /// * If `self == Self::Multivariate(...)`, then this squeezes out a challenge of size `size`. - /// * If `self == Self::Univariate(...)`, then this ignores the `size` argument and simply squeezes out + /// * If `self == Self::Independent(...)`, then this squeezes out a challenge of size `size`. + /// * If `self == Self::Correlated(...)`, then this ignores the `size` argument and simply squeezes out /// the next field element. pub fn try_next_challenge_of_size(&mut self, size: FieldElementSize) -> F { match self { - // multivariate (full) - Self::Multivariate(sponge) => sponge.squeeze_field_elements_with_sizes(&[size])[0], - // univariate - Self::Univariate(gen, next) => { + // independent (full) + Self::Independent(sponge) => sponge.squeeze_field_elements_with_sizes(&[size])[0], + // correlated + Self::Correlated(gen, next) => { let result = next.clone(); *next *= *gen; result @@ -51,10 +51,10 @@ impl ChallengeGenerator { self.try_next_challenge_of_size(FieldElementSize::Full) } - /// Returns the sponge state if `self` is multivariate. Returns `None` otherwise. + /// Returns the sponge state if `self` is independent. Returns `None` otherwise. pub fn into_sponge(self) -> Option { match self { - Self::Multivariate(s) => Some(s), + Self::Independent(s) => Some(s), _ => None, } } diff --git a/poly-commit/src/lib.rs b/poly-commit/src/lib.rs index 8413a1af..efdd6c47 100644 --- a/poly-commit/src/lib.rs +++ b/poly-commit/src/lib.rs @@ -666,8 +666,8 @@ pub mod tests { S: CryptographicSponge, { let challenge_generators = vec![ - ChallengeGenerator::new_multivariate(sponge()), - ChallengeGenerator::new_univariate(&mut sponge()), + ChallengeGenerator::new_independent(sponge()), + ChallengeGenerator::new_correlated(&mut sponge()), ]; for challenge_gen in challenge_generators { @@ -774,8 +774,8 @@ pub mod tests { } = info; let challenge_gens = vec![ - ChallengeGenerator::new_multivariate(sponge()), - ChallengeGenerator::new_univariate(&mut sponge()), + ChallengeGenerator::new_independent(sponge()), + ChallengeGenerator::new_correlated(&mut sponge()), ]; for challenge_gen in challenge_gens { @@ -919,8 +919,8 @@ pub mod tests { } = info; let challenge_gens = vec![ - ChallengeGenerator::new_multivariate(sponge()), - ChallengeGenerator::new_univariate(&mut sponge()), + ChallengeGenerator::new_independent(sponge()), + ChallengeGenerator::new_correlated(&mut sponge()), ]; for challenge_gen in challenge_gens { From 33b708676249159e90f4760bc0b72be278688d05 Mon Sep 17 00:00:00 2001 From: Hossein Moghaddas Date: Thu, 4 Jan 2024 11:49:17 +0100 Subject: [PATCH 3/4] Run `fmt` --- poly-commit/src/constraints.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poly-commit/src/constraints.rs b/poly-commit/src/constraints.rs index dcd9cdd4..1300509a 100644 --- a/poly-commit/src/constraints.rs +++ b/poly-commit/src/constraints.rs @@ -60,7 +60,7 @@ impl let (f, lc_term) = term; let fg = - EmulatedFpVar::new_variable(ark_relations::ns!(cs, "term"), || Ok(f), mode) + EmulatedFpVar::new_variable(ark_relations::ns!(cs, "term"), || Ok(f), mode) .unwrap(); (LinearCombinationCoeffVar::Var(fg), lc_term.clone()) From 80a273d064eebf30b9f9262425b0f44d2ca0ad87 Mon Sep 17 00:00:00 2001 From: Hossein Moghaddas Date: Thu, 4 Jan 2024 11:49:51 +0100 Subject: [PATCH 4/4] Temporarily change `Cargo.toml` --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bc7f3243..1cbef84d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,8 +31,8 @@ debug = true ark-ff = { git = "https://github.com/arkworks-rs/algebra/" } ark-ec = { git = "https://github.com/arkworks-rs/algebra/" } ark-serialize = { git = "https://github.com/arkworks-rs/algebra/" } -ark-crypto-primitives = { git = "https://github.com/arkworks-rs/crypto-primitives" } -ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std/" } +ark-crypto-primitives = { git = "https://github.com/autquis/crypto-primitives" } +ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std/", branch = "add-convert-traits-to-prelude" } ark-bls12-377 = { git = "https://github.com/arkworks-rs/curves/" } ark-bls12-381 = { git = "https://github.com/arkworks-rs/curves/" }