From 7fc117bb2629b4e7560327c233efc1853b59f554 Mon Sep 17 00:00:00 2001 From: Hossein Moghaddas Date: Tue, 23 Jan 2024 03:44:53 +0100 Subject: [PATCH 01/10] Add Merlin, `squeeze_bits` does not work --- crypto-primitives/src/sponge/mod.rs | 5 +++++ src/sponge/merlin/mod.rs | 31 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/sponge/merlin/mod.rs diff --git a/crypto-primitives/src/sponge/mod.rs b/crypto-primitives/src/sponge/mod.rs index bd8a1d92..19baba85 100644 --- a/crypto-primitives/src/sponge/mod.rs +++ b/crypto-primitives/src/sponge/mod.rs @@ -17,6 +17,11 @@ pub use absorb::*; /// [cos]: https://eprint.iacr.org/2019/1076 pub mod poseidon; +/// The sponge for Merlin +/// +/// +pub mod merlin; + #[cfg(test)] mod test; diff --git a/src/sponge/merlin/mod.rs b/src/sponge/merlin/mod.rs new file mode 100644 index 00000000..cb873df7 --- /dev/null +++ b/src/sponge/merlin/mod.rs @@ -0,0 +1,31 @@ +use crate::sponge::{Absorb, CryptographicSponge}; +use merlin::Transcript; + +impl CryptographicSponge for Transcript { + type Config = &'static [u8]; + + fn new(params: &Self::Config) -> Self { + Transcript::new(*params) + } + + fn absorb(&mut self, input: &impl Absorb) { + self.append_message(b"", &input.to_sponge_bytes_as_vec()); + } + + fn squeeze_bytes(&mut self, num_bytes: usize) -> Vec { + let mut dest = Vec::with_capacity(num_bytes); + self.challenge_bytes(b"", &mut dest); + dest + } + + fn squeeze_bits(&mut self, num_bits: usize) -> Vec { + let num_bytes = (num_bits + 7) / 8; + let mut tmp = Vec::with_capacity(num_bytes); + self.challenge_bytes(b"", &mut tmp); + let dest = tmp + .iter() + .flat_map(|byte| (0..8u32).rev().map(move |i| (byte >> i) & 1 == 1)) + .collect::>(); + dest[..num_bits].to_vec() + } +} From 183758060102f938989d39c906d3cf39463c102c Mon Sep 17 00:00:00 2001 From: Hossein Moghaddas Date: Tue, 23 Jan 2024 15:55:27 +0100 Subject: [PATCH 02/10] Fix bug --- src/sponge/merlin/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sponge/merlin/mod.rs b/src/sponge/merlin/mod.rs index cb873df7..fd2de54c 100644 --- a/src/sponge/merlin/mod.rs +++ b/src/sponge/merlin/mod.rs @@ -13,14 +13,14 @@ impl CryptographicSponge for Transcript { } fn squeeze_bytes(&mut self, num_bytes: usize) -> Vec { - let mut dest = Vec::with_capacity(num_bytes); + let mut dest = vec![0; num_bytes]; self.challenge_bytes(b"", &mut dest); dest } fn squeeze_bits(&mut self, num_bits: usize) -> Vec { let num_bytes = (num_bits + 7) / 8; - let mut tmp = Vec::with_capacity(num_bytes); + let mut tmp = vec![0; num_bytes]; self.challenge_bytes(b"", &mut tmp); let dest = tmp .iter() From 746e62e38c2f80b7fff52349070292d08a1c7937 Mon Sep 17 00:00:00 2001 From: Marcin Date: Mon, 29 Jan 2024 18:53:23 +0100 Subject: [PATCH 03/10] Apply suggestions from code review --- src/sponge/merlin/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sponge/merlin/mod.rs b/src/sponge/merlin/mod.rs index fd2de54c..b0e95847 100644 --- a/src/sponge/merlin/mod.rs +++ b/src/sponge/merlin/mod.rs @@ -1,5 +1,6 @@ use crate::sponge::{Absorb, CryptographicSponge}; -use merlin::Transcript; +use crate::Vec; +pub use merlin::Transcript; impl CryptographicSponge for Transcript { type Config = &'static [u8]; From 551578773817969e9dcb7e71fada747b53317145 Mon Sep 17 00:00:00 2001 From: autquis Date: Tue, 13 Feb 2024 23:53:52 +0100 Subject: [PATCH 04/10] Rename the merlin directory --- {src => crypto-primitives/src}/sponge/merlin/mod.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {src => crypto-primitives/src}/sponge/merlin/mod.rs (100%) diff --git a/src/sponge/merlin/mod.rs b/crypto-primitives/src/sponge/merlin/mod.rs similarity index 100% rename from src/sponge/merlin/mod.rs rename to crypto-primitives/src/sponge/merlin/mod.rs From 7e798f6a0761b6e7f3e95967a206e2b2996cc254 Mon Sep 17 00:00:00 2001 From: autquis Date: Wed, 14 Feb 2024 00:03:57 +0100 Subject: [PATCH 05/10] Fix `Cargo.toml` --- crypto-primitives/Cargo.toml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crypto-primitives/Cargo.toml b/crypto-primitives/Cargo.toml index 3dc2baf5..92e48f2d 100644 --- a/crypto-primitives/Cargo.toml +++ b/crypto-primitives/Cargo.toml @@ -26,6 +26,7 @@ ark-serialize = { version = "^0.4.0", default-features = false, features = [ "de blake2 = { version = "0.10", default-features = false } sha2 = { version = "0.10", default-features = false } digest = { version = "0.10", default-features = false } +merlin = { version = "3.0.0", default-features = false, optional = true } ark-r1cs-std = { version = "^0.4.0", optional = true, default-features = false } ark-snark = { version = "^0.4.0", default-features = false } @@ -41,9 +42,9 @@ print-trace = [ "ark-std/print-trace" ] parallel = [ "std", "rayon", "ark-ec/parallel", "ark-std/parallel", "ark-ff/parallel" ] r1cs = [ "ark-r1cs-std", "tracing" ] crh = [ "sponge" ] -sponge = [] -commitment = ["crh"] -merkle_tree = ["crh"] +sponge = [ "merlin" ] +commitment = [ "crh" ] +merkle_tree = [ "crh" ] encryption = [] prf = [] snark = [] From c899a535dc638e9fb1d86bc1a83b3ed23490e3b5 Mon Sep 17 00:00:00 2001 From: autquis Date: Mon, 11 Mar 2024 15:32:40 +0100 Subject: [PATCH 06/10] Add link to Merlin page --- crypto-primitives/src/sponge/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto-primitives/src/sponge/mod.rs b/crypto-primitives/src/sponge/mod.rs index 19baba85..b3e270be 100644 --- a/crypto-primitives/src/sponge/mod.rs +++ b/crypto-primitives/src/sponge/mod.rs @@ -17,9 +17,9 @@ pub use absorb::*; /// [cos]: https://eprint.iacr.org/2019/1076 pub mod poseidon; -/// The sponge for Merlin -/// +/// The sponge for [Merlin][merlin] /// +/// [merlin]: https://merlin.cool/ pub mod merlin; #[cfg(test)] From 6cbaad73542c62e85ce9b50223ff6bb85ad6702b Mon Sep 17 00:00:00 2001 From: autquis Date: Mon, 11 Mar 2024 15:57:42 +0100 Subject: [PATCH 07/10] Remove redundant imports, nightly check --- .../src/commitment/blake2s/constraints.rs | 1 - .../src/commitment/pedersen/constraints.rs | 1 - .../src/commitment/pedersen/mod.rs | 2 +- .../src/crh/bowe_hopwood/constraints.rs | 16 +++++--------- crypto-primitives/src/crh/bowe_hopwood/mod.rs | 2 +- .../src/crh/injective_map/constraints.rs | 4 +--- .../src/crh/injective_map/mod.rs | 1 - .../src/crh/pedersen/constraints.rs | 9 +++----- crypto-primitives/src/crh/pedersen/mod.rs | 2 +- .../src/crh/poseidon/constraints.rs | 2 +- .../src/crh/sha256/constraints.rs | 12 ++-------- crypto-primitives/src/crh/sha256/mod.rs | 2 +- .../src/encryption/elgamal/constraints.rs | 2 +- .../src/merkle_tree/constraints.rs | 1 - crypto-primitives/src/merkle_tree/mod.rs | 1 - .../src/merkle_tree/tests/mod.rs | 7 ++---- .../src/prf/blake2s/constraints.rs | 2 +- crypto-primitives/src/prf/blake2s/mod.rs | 1 - crypto-primitives/src/prf/constraints.rs | 2 +- crypto-primitives/src/signature/mod.rs | 4 ++-- .../src/signature/schnorr/constraints.rs | 1 - .../src/signature/schnorr/mod.rs | 2 +- crypto-primitives/src/snark/constraints.rs | 22 ++++++------------- crypto-primitives/src/sponge/absorb.rs | 4 +--- .../src/sponge/constraints/absorb.rs | 3 +-- .../src/sponge/constraints/mod.rs | 2 -- crypto-primitives/src/sponge/merlin/mod.rs | 1 - crypto-primitives/src/sponge/mod.rs | 1 - .../src/sponge/poseidon/constraints.rs | 2 -- .../src/sponge/poseidon/grain_lfsr.rs | 1 - crypto-primitives/src/sponge/poseidon/mod.rs | 2 -- .../src/sponge/poseidon/traits.rs | 3 +-- 32 files changed, 34 insertions(+), 84 deletions(-) diff --git a/crypto-primitives/src/commitment/blake2s/constraints.rs b/crypto-primitives/src/commitment/blake2s/constraints.rs index f38b7378..07f28ca8 100644 --- a/crypto-primitives/src/commitment/blake2s/constraints.rs +++ b/crypto-primitives/src/commitment/blake2s/constraints.rs @@ -3,7 +3,6 @@ use ark_relations::r1cs::{Namespace, SynthesisError}; use crate::{ commitment::{blake2s, CommitmentGadget}, prf::blake2s::constraints::{evaluate_blake2s, OutputVar}, - Vec, }; use ark_ff::{Field, PrimeField}; use ark_r1cs_std::prelude::*; diff --git a/crypto-primitives/src/commitment/pedersen/constraints.rs b/crypto-primitives/src/commitment/pedersen/constraints.rs index f077e295..8386815d 100644 --- a/crypto-primitives/src/commitment/pedersen/constraints.rs +++ b/crypto-primitives/src/commitment/pedersen/constraints.rs @@ -1,7 +1,6 @@ use crate::{ commitment::pedersen::{Commitment, Parameters, Randomness}, crh::pedersen::Window, - Vec, }; use ark_ec::CurveGroup; use ark_ff::{ diff --git a/crypto-primitives/src/commitment/pedersen/mod.rs b/crypto-primitives/src/commitment/pedersen/mod.rs index 6782e9c6..cfcdab74 100644 --- a/crypto-primitives/src/commitment/pedersen/mod.rs +++ b/crypto-primitives/src/commitment/pedersen/mod.rs @@ -1,4 +1,4 @@ -use crate::{crh::CRHScheme, Error, Vec}; +use crate::{crh::CRHScheme, Error}; use ark_ec::CurveGroup; use ark_ff::{BitIteratorLE, Field, PrimeField, ToConstraintField}; use ark_serialize::CanonicalSerialize; diff --git a/crypto-primitives/src/crh/bowe_hopwood/constraints.rs b/crypto-primitives/src/crh/bowe_hopwood/constraints.rs index e1f6f487..e5eef789 100644 --- a/crypto-primitives/src/crh/bowe_hopwood/constraints.rs +++ b/crypto-primitives/src/crh/bowe_hopwood/constraints.rs @@ -2,22 +2,16 @@ use ark_ec::twisted_edwards::{Projective as TEProjective, TECurveConfig}; use ark_ec::CurveConfig; use core::{borrow::Borrow, iter, marker::PhantomData}; -use crate::{ - crh::{ - bowe_hopwood::{Parameters, CHUNK_SIZE}, - pedersen::{self, Window}, - CRHSchemeGadget, TwoToOneCRHSchemeGadget, - }, - Vec, +use crate::crh::{ + bowe_hopwood::{Parameters, CHUNK_SIZE}, + pedersen::{self, Window}, + CRHSchemeGadget, TwoToOneCRHSchemeGadget, }; use ark_ff::Field; -use ark_r1cs_std::{ - alloc::AllocVar, groups::curves::twisted_edwards::AffineVar, prelude::*, uint8::UInt8, -}; +use ark_r1cs_std::{groups::curves::twisted_edwards::AffineVar, prelude::*}; use ark_relations::r1cs::{Namespace, SynthesisError}; use crate::crh::bowe_hopwood::{TwoToOneCRH, CRH}; -use ark_r1cs_std::boolean::Boolean; type ConstraintF

= <

::BaseField as Field>::BasePrimeField; diff --git a/crypto-primitives/src/crh/bowe_hopwood/mod.rs b/crypto-primitives/src/crh/bowe_hopwood/mod.rs index 820727a0..fb2bf0ac 100644 --- a/crypto-primitives/src/crh/bowe_hopwood/mod.rs +++ b/crypto-primitives/src/crh/bowe_hopwood/mod.rs @@ -2,7 +2,7 @@ //! specific Twisted Edwards (TE) curves. See [Section 5.4.17 of the Zcash protocol specification](https://raw.githubusercontent.com/zcash/zips/master/protocol/protocol.pdf#concretepedersenhash) for a formal description of this hash function, specialized for the Jubjub curve. //! The implementation in this repository is generic across choice of TE curves. -use crate::{Error, Vec}; +use crate::Error; use ark_std::rand::Rng; use ark_std::{ fmt::{Debug, Formatter, Result as FmtResult}, diff --git a/crypto-primitives/src/crh/injective_map/constraints.rs b/crypto-primitives/src/crh/injective_map/constraints.rs index 8e9cd703..1a60c842 100644 --- a/crypto-primitives/src/crh/injective_map/constraints.rs +++ b/crypto-primitives/src/crh/injective_map/constraints.rs @@ -14,9 +14,7 @@ use ark_ec::{ }; use ark_ff::fields::{Field, PrimeField}; use ark_r1cs_std::{ - fields::fp::FpVar, - groups::{curves::twisted_edwards::AffineVar as TEVar, CurveVar}, - prelude::*, + fields::fp::FpVar, groups::curves::twisted_edwards::AffineVar as TEVar, prelude::*, }; use ark_relations::r1cs::SynthesisError; diff --git a/crypto-primitives/src/crh/injective_map/mod.rs b/crypto-primitives/src/crh/injective_map/mod.rs index fbd99fd1..4927852a 100644 --- a/crypto-primitives/src/crh/injective_map/mod.rs +++ b/crypto-primitives/src/crh/injective_map/mod.rs @@ -9,7 +9,6 @@ use ark_ec::{ }; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use ark_std::borrow::Borrow; -use ark_std::vec::Vec; #[cfg(feature = "r1cs")] pub mod constraints; diff --git a/crypto-primitives/src/crh/pedersen/constraints.rs b/crypto-primitives/src/crh/pedersen/constraints.rs index fdf2340a..3f64e755 100644 --- a/crypto-primitives/src/crh/pedersen/constraints.rs +++ b/crypto-primitives/src/crh/pedersen/constraints.rs @@ -1,9 +1,6 @@ -use crate::{ - crh::{ - pedersen::{Parameters, Window}, - CRHSchemeGadget as CRHGadgetTrait, - }, - Vec, +use crate::crh::{ + pedersen::{Parameters, Window}, + CRHSchemeGadget as CRHGadgetTrait, }; use ark_ec::CurveGroup; use ark_ff::Field; diff --git a/crypto-primitives/src/crh/pedersen/mod.rs b/crypto-primitives/src/crh/pedersen/mod.rs index eec86e36..97850b86 100644 --- a/crypto-primitives/src/crh/pedersen/mod.rs +++ b/crypto-primitives/src/crh/pedersen/mod.rs @@ -1,4 +1,4 @@ -use crate::{Error, Vec}; +use crate::Error; use ark_std::rand::Rng; use ark_std::{ fmt::{Debug, Formatter, Result as FmtResult}, diff --git a/crypto-primitives/src/crh/poseidon/constraints.rs b/crypto-primitives/src/crh/poseidon/constraints.rs index 9684624c..a0ad5001 100644 --- a/crypto-primitives/src/crh/poseidon/constraints.rs +++ b/crypto-primitives/src/crh/poseidon/constraints.rs @@ -1,11 +1,11 @@ use crate::crh::poseidon::{TwoToOneCRH, CRH}; +use crate::crh::CRHScheme; use crate::crh::{ CRHSchemeGadget as CRHGadgetTrait, TwoToOneCRHSchemeGadget as TwoToOneCRHGadgetTrait, }; use crate::sponge::constraints::CryptographicSpongeVar; use crate::sponge::poseidon::constraints::PoseidonSpongeVar; use crate::sponge::poseidon::PoseidonConfig; -use crate::{crh::CRHScheme, Vec}; use crate::sponge::Absorb; use ark_ff::PrimeField; diff --git a/crypto-primitives/src/crh/sha256/constraints.rs b/crypto-primitives/src/crh/sha256/constraints.rs index c7080809..bf40c945 100644 --- a/crypto-primitives/src/crh/sha256/constraints.rs +++ b/crypto-primitives/src/crh/sha256/constraints.rs @@ -19,7 +19,6 @@ use ark_r1cs_std::{ R1CSVar, }; use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; -use ark_std::{vec, vec::Vec}; const STATE_LEN: usize = 8; @@ -383,17 +382,10 @@ where #[cfg(test)] mod test { use super::*; - use crate::crh::{ - sha256::{digest::Digest, Sha256}, - CRHScheme, CRHSchemeGadget, TwoToOneCRHScheme, TwoToOneCRHSchemeGadget, - }; + use crate::crh::{sha256::digest::Digest, CRHScheme, TwoToOneCRHScheme}; use ark_bls12_377::Fr; - use ark_r1cs_std::R1CSVar; - use ark_relations::{ - ns, - r1cs::{ConstraintSystem, Namespace}, - }; + use ark_relations::{ns, r1cs::ConstraintSystem}; use ark_std::rand::RngCore; const TEST_LENGTHS: &[usize] = &[ diff --git a/crypto-primitives/src/crh/sha256/mod.rs b/crypto-primitives/src/crh/sha256/mod.rs index 6010be32..8a2cb1d4 100644 --- a/crypto-primitives/src/crh/sha256/mod.rs +++ b/crypto-primitives/src/crh/sha256/mod.rs @@ -1,5 +1,5 @@ use crate::crh::{CRHScheme, TwoToOneCRHScheme}; -use crate::{Error, Vec}; +use crate::Error; use ark_std::rand::Rng; diff --git a/crypto-primitives/src/encryption/elgamal/constraints.rs b/crypto-primitives/src/encryption/elgamal/constraints.rs index 7527352a..290492d2 100644 --- a/crypto-primitives/src/encryption/elgamal/constraints.rs +++ b/crypto-primitives/src/encryption/elgamal/constraints.rs @@ -11,7 +11,7 @@ use ark_ff::{ Zero, }; use ark_serialize::CanonicalSerialize; -use ark_std::{borrow::Borrow, marker::PhantomData, vec::Vec}; +use ark_std::{borrow::Borrow, marker::PhantomData}; pub type ConstraintF = <::BaseField as Field>::BasePrimeField; diff --git a/crypto-primitives/src/merkle_tree/constraints.rs b/crypto-primitives/src/merkle_tree/constraints.rs index e243079c..4cb764a3 100644 --- a/crypto-primitives/src/merkle_tree/constraints.rs +++ b/crypto-primitives/src/merkle_tree/constraints.rs @@ -6,7 +6,6 @@ use ark_r1cs_std::prelude::*; use ark_relations::r1cs::{Namespace, SynthesisError}; use ark_std::borrow::Borrow; use ark_std::fmt::Debug; -use ark_std::vec::Vec; pub trait DigestVarConverter { type TargetType: Borrow; diff --git a/crypto-primitives/src/merkle_tree/mod.rs b/crypto-primitives/src/merkle_tree/mod.rs index 4a0a4a19..cc8c290c 100644 --- a/crypto-primitives/src/merkle_tree/mod.rs +++ b/crypto-primitives/src/merkle_tree/mod.rs @@ -7,7 +7,6 @@ use crate::{crh::CRHScheme, Error}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use ark_std::borrow::Borrow; use ark_std::hash::Hash; -use ark_std::vec::Vec; #[cfg(test)] mod tests; diff --git a/crypto-primitives/src/merkle_tree/tests/mod.rs b/crypto-primitives/src/merkle_tree/tests/mod.rs index a4968917..8db57449 100644 --- a/crypto-primitives/src/merkle_tree/tests/mod.rs +++ b/crypto-primitives/src/merkle_tree/tests/mod.rs @@ -4,10 +4,7 @@ mod test_utils; mod bytes_mt_tests { - use crate::{ - crh::{pedersen, *}, - merkle_tree::*, - }; + use crate::{crh::*, merkle_tree::*}; use ark_ed_on_bls12_381::EdwardsProjective as JubJub; use ark_ff::BigInteger256; use ark_std::{test_rng, UniformRand}; @@ -120,7 +117,7 @@ mod field_mt_tests { use crate::crh::poseidon; use crate::merkle_tree::tests::test_utils::poseidon_parameters; use crate::merkle_tree::{Config, IdentityDigestConverter, MerkleTree}; - use ark_std::{test_rng, vec::Vec, One, UniformRand}; + use ark_std::{test_rng, One, UniformRand}; type F = ark_ed_on_bls12_381::Fr; type H = poseidon::CRH; diff --git a/crypto-primitives/src/prf/blake2s/constraints.rs b/crypto-primitives/src/prf/blake2s/constraints.rs index cd52cf69..fdfd99d7 100644 --- a/crypto-primitives/src/prf/blake2s/constraints.rs +++ b/crypto-primitives/src/prf/blake2s/constraints.rs @@ -1,7 +1,7 @@ use ark_ff::PrimeField; use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; -use crate::{prf::PRFGadget, Vec}; +use crate::prf::PRFGadget; use ark_r1cs_std::prelude::*; use core::borrow::Borrow; diff --git a/crypto-primitives/src/prf/blake2s/mod.rs b/crypto-primitives/src/prf/blake2s/mod.rs index 7455e18a..b2696c19 100644 --- a/crypto-primitives/src/prf/blake2s/mod.rs +++ b/crypto-primitives/src/prf/blake2s/mod.rs @@ -1,4 +1,3 @@ -use crate::Vec; use blake2::{Blake2s256 as B2s, Blake2sMac}; use digest::Digest; diff --git a/crypto-primitives/src/prf/constraints.rs b/crypto-primitives/src/prf/constraints.rs index bbca88c7..1e09571d 100644 --- a/crypto-primitives/src/prf/constraints.rs +++ b/crypto-primitives/src/prf/constraints.rs @@ -1,7 +1,7 @@ use ark_ff::Field; use core::fmt::Debug; -use crate::{prf::PRF, Vec}; +use crate::prf::PRF; use ark_relations::r1cs::{Namespace, SynthesisError}; use ark_r1cs_std::prelude::*; diff --git a/crypto-primitives/src/signature/mod.rs b/crypto-primitives/src/signature/mod.rs index c7cbddca..1f7cf219 100644 --- a/crypto-primitives/src/signature/mod.rs +++ b/crypto-primitives/src/signature/mod.rs @@ -52,10 +52,10 @@ pub trait SignatureScheme { #[cfg(test)] mod test { - use crate::signature::{schnorr, *}; + use crate::signature::*; use ark_ec::AdditiveGroup; use ark_ed_on_bls12_381::EdwardsProjective as JubJub; - use ark_std::{test_rng, vec::Vec, UniformRand}; + use ark_std::{test_rng, UniformRand}; use blake2::Blake2s256 as Blake2s; fn sign_and_verify(message: &[u8]) { diff --git a/crypto-primitives/src/signature/schnorr/constraints.rs b/crypto-primitives/src/signature/schnorr/constraints.rs index 0f663825..7d19ecc1 100644 --- a/crypto-primitives/src/signature/schnorr/constraints.rs +++ b/crypto-primitives/src/signature/schnorr/constraints.rs @@ -1,4 +1,3 @@ -use crate::Vec; use ark_ec::CurveGroup; use ark_ff::Field; use ark_r1cs_std::prelude::*; diff --git a/crypto-primitives/src/signature/schnorr/mod.rs b/crypto-primitives/src/signature/schnorr/mod.rs index e0584c44..c8c3cf75 100644 --- a/crypto-primitives/src/signature/schnorr/mod.rs +++ b/crypto-primitives/src/signature/schnorr/mod.rs @@ -1,4 +1,4 @@ -use crate::{signature::SignatureScheme, Error, Vec}; +use crate::{signature::SignatureScheme, Error}; use ark_ec::{AffineRepr, CurveGroup}; use ark_ff::{ fields::{Field, PrimeField}, diff --git a/crypto-primitives/src/snark/constraints.rs b/crypto-primitives/src/snark/constraints.rs index 66419198..ba1ef909 100644 --- a/crypto-primitives/src/snark/constraints.rs +++ b/crypto-primitives/src/snark/constraints.rs @@ -1,15 +1,12 @@ use ark_ff::{BigInteger, PrimeField}; -use ark_r1cs_std::prelude::*; -use ark_r1cs_std::{ - fields::{ - emulated_fp::{ - params::{get_params, OptimizationType}, - AllocatedEmulatedFpVar, EmulatedFpVar, - }, - fp::{AllocatedFp, FpVar}, +use ark_r1cs_std::fields::{ + emulated_fp::{ + params::{get_params, OptimizationType}, + AllocatedEmulatedFpVar, EmulatedFpVar, }, - R1CSVar, + fp::{AllocatedFp, FpVar}, }; +use ark_r1cs_std::prelude::*; use ark_relations::r1cs::OptimizationGoal; use ark_relations::{ lc, ns, @@ -18,12 +15,7 @@ use ark_relations::{ }, }; use ark_snark::{CircuitSpecificSetupSNARK, UniversalSetupSNARK, SNARK}; -use ark_std::{ - borrow::Borrow, - fmt, - marker::PhantomData, - vec::{IntoIter, Vec}, -}; +use ark_std::{borrow::Borrow, fmt, marker::PhantomData, vec::IntoIter}; /// This implements constraints for SNARK verifiers. pub trait SNARKGadget> { diff --git a/crypto-primitives/src/sponge/absorb.rs b/crypto-primitives/src/sponge/absorb.rs index ed98bf1d..eb154515 100644 --- a/crypto-primitives/src/sponge/absorb.rs +++ b/crypto-primitives/src/sponge/absorb.rs @@ -7,8 +7,6 @@ use ark_ec::{ use ark_ff::models::{Fp, FpConfig}; use ark_ff::{BigInteger, Field, PrimeField, ToConstraintField}; use ark_serialize::CanonicalSerialize; -use ark_std::string::String; -use ark_std::vec::Vec; pub use ark_crypto_primitives_macros::*; @@ -389,7 +387,7 @@ mod tests { use crate::sponge::Absorb; use crate::sponge::{field_cast, CryptographicSponge}; use ark_ff::PrimeField; - use ark_std::{test_rng, vec::Vec, UniformRand}; + use ark_std::{test_rng, UniformRand}; #[test] fn test_cast() { diff --git a/crypto-primitives/src/sponge/constraints/absorb.rs b/crypto-primitives/src/sponge/constraints/absorb.rs index 58779a02..fa943cdf 100644 --- a/crypto-primitives/src/sponge/constraints/absorb.rs +++ b/crypto-primitives/src/sponge/constraints/absorb.rs @@ -13,8 +13,7 @@ use ark_r1cs_std::groups::curves::short_weierstrass::{ use ark_r1cs_std::groups::curves::twisted_edwards::AffineVar as TEAffineVar; use ark_r1cs_std::uint8::UInt8; use ark_relations::r1cs::SynthesisError; -use ark_std::vec; -use ark_std::vec::Vec; + /// An interface for objects that can be absorbed by a `CryptographicSpongeVar` whose constraint field /// is `CF`. pub trait AbsorbGadget { diff --git a/crypto-primitives/src/sponge/constraints/mod.rs b/crypto-primitives/src/sponge/constraints/mod.rs index 0d29efe9..889f733f 100644 --- a/crypto-primitives/src/sponge/constraints/mod.rs +++ b/crypto-primitives/src/sponge/constraints/mod.rs @@ -9,8 +9,6 @@ use ark_r1cs_std::uint8::UInt8; use ark_r1cs_std::R1CSVar; use ark_relations::lc; use ark_relations::r1cs::{ConstraintSystemRef, LinearCombination, SynthesisError}; -use ark_std::vec; -use ark_std::vec::Vec; mod absorb; pub use absorb::*; diff --git a/crypto-primitives/src/sponge/merlin/mod.rs b/crypto-primitives/src/sponge/merlin/mod.rs index b0e95847..fa054e25 100644 --- a/crypto-primitives/src/sponge/merlin/mod.rs +++ b/crypto-primitives/src/sponge/merlin/mod.rs @@ -1,5 +1,4 @@ use crate::sponge::{Absorb, CryptographicSponge}; -use crate::Vec; pub use merlin::Transcript; impl CryptographicSponge for Transcript { diff --git a/crypto-primitives/src/sponge/mod.rs b/crypto-primitives/src/sponge/mod.rs index b3e270be..a73e5cc5 100644 --- a/crypto-primitives/src/sponge/mod.rs +++ b/crypto-primitives/src/sponge/mod.rs @@ -1,6 +1,5 @@ use ark_ff::PrimeField; use ark_std::vec; -use ark_std::vec::Vec; /// Infrastructure for the constraints counterparts. #[cfg(feature = "r1cs")] diff --git a/crypto-primitives/src/sponge/poseidon/constraints.rs b/crypto-primitives/src/sponge/poseidon/constraints.rs index 8cbec6d2..276ed0e0 100644 --- a/crypto-primitives/src/sponge/poseidon/constraints.rs +++ b/crypto-primitives/src/sponge/poseidon/constraints.rs @@ -7,8 +7,6 @@ use ark_ff::PrimeField; use ark_r1cs_std::fields::fp::FpVar; use ark_r1cs_std::prelude::*; use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError}; -use ark_std::vec; -use ark_std::vec::Vec; #[derive(Clone)] /// the gadget for Poseidon sponge diff --git a/crypto-primitives/src/sponge/poseidon/grain_lfsr.rs b/crypto-primitives/src/sponge/poseidon/grain_lfsr.rs index 41b83c65..1cda4f71 100644 --- a/crypto-primitives/src/sponge/poseidon/grain_lfsr.rs +++ b/crypto-primitives/src/sponge/poseidon/grain_lfsr.rs @@ -1,7 +1,6 @@ #![allow(dead_code)] use ark_ff::{BigInteger, PrimeField}; -use ark_std::vec::Vec; pub struct PoseidonGrainLFSR { pub prime_num_bits: u64, diff --git a/crypto-primitives/src/sponge/poseidon/mod.rs b/crypto-primitives/src/sponge/poseidon/mod.rs index 69dd01ff..26349b0b 100644 --- a/crypto-primitives/src/sponge/poseidon/mod.rs +++ b/crypto-primitives/src/sponge/poseidon/mod.rs @@ -5,8 +5,6 @@ use crate::sponge::{ use ark_ff::{BigInteger, PrimeField}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use ark_std::any::TypeId; -use ark_std::vec; -use ark_std::vec::Vec; /// constraints for Poseidon #[cfg(feature = "r1cs")] diff --git a/crypto-primitives/src/sponge/poseidon/traits.rs b/crypto-primitives/src/sponge/poseidon/traits.rs index 1e85214c..237f8732 100644 --- a/crypto-primitives/src/sponge/poseidon/traits.rs +++ b/crypto-primitives/src/sponge/poseidon/traits.rs @@ -1,7 +1,6 @@ use crate::sponge::poseidon::grain_lfsr::PoseidonGrainLFSR; use crate::sponge::poseidon::PoseidonConfig; -use ark_ff::{fields::models::*, FpConfig, PrimeField}; -use ark_std::{vec, vec::Vec}; +use ark_ff::{fields::models::*, PrimeField}; /// An entry in the default Poseidon parameters pub struct PoseidonDefaultConfigEntry { From e1a54f6a3d778abb9347925adf9795fef7e87618 Mon Sep 17 00:00:00 2001 From: autquis Date: Tue, 16 Apr 2024 17:38:56 +0200 Subject: [PATCH 08/10] Undo a mistake --- crypto-primitives/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/crypto-primitives/Cargo.toml b/crypto-primitives/Cargo.toml index efff91e5..c738399e 100644 --- a/crypto-primitives/Cargo.toml +++ b/crypto-primitives/Cargo.toml @@ -44,6 +44,7 @@ parallel = [ "std", "rayon", "ark-ec/parallel", "ark-std/parallel", "ark-ff/para r1cs = [ "ark-r1cs-std", "tracing" ] crh = [ "sponge" ] sponge = [ "merlin" ] +commitment = [ "crh" ] merkle_tree = ["crh", "hashbrown"] encryption = [] prf = [] From 705a9389b3c74a1b1b0e5c9b10cc8c0b9bb7670a Mon Sep 17 00:00:00 2001 From: autquis Date: Tue, 16 Apr 2024 17:42:49 +0200 Subject: [PATCH 09/10] Fix Merlin sponge --- crypto-primitives/src/sponge/merlin/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crypto-primitives/src/sponge/merlin/mod.rs b/crypto-primitives/src/sponge/merlin/mod.rs index fa054e25..47906dee 100644 --- a/crypto-primitives/src/sponge/merlin/mod.rs +++ b/crypto-primitives/src/sponge/merlin/mod.rs @@ -1,4 +1,6 @@ use crate::sponge::{Absorb, CryptographicSponge}; +#[cfg(not(feature = "std"))] +use ark_std::vec::Vec; pub use merlin::Transcript; impl CryptographicSponge for Transcript { From 09603008bd97f8a09926c5f160125d1a26badf30 Mon Sep 17 00:00:00 2001 From: Cesar199999 Date: Fri, 28 Jun 2024 15:05:30 +0200 Subject: [PATCH 10/10] Fix nightly check errors --- crypto-primitives/src/merkle_tree/constraints.rs | 6 +++++- crypto-primitives/src/merkle_tree/mod.rs | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/crypto-primitives/src/merkle_tree/constraints.rs b/crypto-primitives/src/merkle_tree/constraints.rs index aa9fbb87..ccad3a93 100644 --- a/crypto-primitives/src/merkle_tree/constraints.rs +++ b/crypto-primitives/src/merkle_tree/constraints.rs @@ -1,5 +1,5 @@ use crate::crh::TwoToOneCRHSchemeGadget; -use crate::merkle_tree::{Config, IdentityDigestConverter}; +use crate::merkle_tree::Config; use crate::{crh::CRHSchemeGadget, merkle_tree::Path}; use ark_ff::PrimeField; use ark_r1cs_std::prelude::*; @@ -9,11 +9,15 @@ use ark_std::fmt::Debug; #[cfg(not(feature = "std"))] use ark_std::vec::Vec; +#[cfg(test)] +use crate::merkle_tree::IdentityDigestConverter; + pub trait DigestVarConverter { type TargetType: Borrow; fn convert(from: From) -> Result; } +#[cfg(test)] impl DigestVarConverter for IdentityDigestConverter { type TargetType = T; diff --git a/crypto-primitives/src/merkle_tree/mod.rs b/crypto-primitives/src/merkle_tree/mod.rs index 5a7e4934..14b9671f 100644 --- a/crypto-primitives/src/merkle_tree/mod.rs +++ b/crypto-primitives/src/merkle_tree/mod.rs @@ -49,10 +49,12 @@ pub trait DigestConverter { } /// A trivial converter where digest of previous layer's hash is the same as next layer's input. +#[cfg(test)] pub struct IdentityDigestConverter { _prev_layer_digest: T, } +#[cfg(test)] impl DigestConverter for IdentityDigestConverter { type TargetType = T; fn convert(item: T) -> Result {