Skip to content

Commit

Permalink
Fix CI and build for each feature (#142)
Browse files Browse the repository at this point in the history
* Fix build for different features with `no-std`

* Fix for constraints of each feature

* Fix CI

* Do a `cargo fmt`

* patch std

needed after arkworks-rs/algebra#811

Need to add Sync trait bounds on a few types

---------

Co-authored-by: mmagician <[email protected]>
  • Loading branch information
autquis and mmagician authored Apr 9, 2024
1 parent fc1c949 commit 9ef1753
Show file tree
Hide file tree
Showing 30 changed files with 66 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,5 @@ jobs:

- name: crypto-primitives
run: |
cargo build --no-default-features --features=r1cs --target aarch64-unknown-none
cargo check --examples --no-default-features --features=r1cs --target aarch64-unknown-none
cargo build --no-default-features --features=r1cs,merkle_tree,prf,encryption,signature,snark --target aarch64-unknown-none
cargo check --all --no-default-features --features=r1cs,merkle_tree,prf,encryption,signature,snark --target aarch64-unknown-none
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ ark-ff = { git = "https://github.com/arkworks-rs/algebra/" }
ark-ec = { git = "https://github.com/arkworks-rs/algebra/" }
ark-poly = { git = "https://github.com/arkworks-rs/algebra/" }
ark-serialize = { git = "https://github.com/arkworks-rs/algebra/" }
ark-std = { git = "https://github.com/arkworks-rs/std/" }

ark-ed-on-bls12-377 = { git = "https://github.com/arkworks-rs/algebra/" }
ark-ed-on-bls12-381 = { git = "https://github.com/arkworks-rs/algebra/" }
Expand Down
3 changes: 2 additions & 1 deletion crypto-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ark-snark = { version = "^0.4.0", default-features = false }
rayon = { version = "1.0", optional = true }
derivative = { version = "2.0", features = ["use_core"] }
tracing = { version = "0.1", default-features = false, features = [ "attributes" ], optional = true }
hashbrown = { version = "^0.14", default-features = false, optional = true }

[features]
default = ["std"]
Expand All @@ -43,7 +44,7 @@ r1cs = [ "ark-r1cs-std", "tracing" ]
crh = [ "sponge" ]
sponge = []
commitment = ["crh"]
merkle_tree = ["crh"]
merkle_tree = ["crh", "hashbrown"]
encryption = []
prf = []
snark = []
Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/commitment/pedersen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use ark_ff::{BitIteratorLE, Field, PrimeField, ToConstraintField};
use ark_serialize::CanonicalSerialize;
use ark_std::marker::PhantomData;
use ark_std::rand::Rng;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
use ark_std::UniformRand;

use super::CommitmentScheme;
Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/crh/bowe_hopwood/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use crate::crh::{
use ark_ff::Field;
use ark_r1cs_std::{groups::curves::twisted_edwards::AffineVar, prelude::*};
use ark_relations::r1cs::{Namespace, SynthesisError};
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

use crate::crh::bowe_hopwood::{TwoToOneCRH, CRH};

Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/crh/bowe_hopwood/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use ark_ff::fields::PrimeField;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::borrow::Borrow;
use ark_std::cfg_chunks;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
use ark_std::UniformRand;

#[cfg(feature = "r1cs")]
Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/crh/injective_map/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::Error;
use ark_std::rand::Rng;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
use ark_std::{fmt::Debug, hash::Hash, marker::PhantomData};

use super::{pedersen, CRHScheme, TwoToOneCRHScheme};
Expand Down
4 changes: 2 additions & 2 deletions crypto-primitives/src/crh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub trait CRHScheme {
+ Default
+ CanonicalSerialize
+ CanonicalDeserialize;
type Parameters: Clone + CanonicalSerialize + CanonicalDeserialize;
type Parameters: Clone + CanonicalSerialize + CanonicalDeserialize + Sync;

fn setup<R: Rng>(r: &mut R) -> Result<Self::Parameters, Error>;
fn evaluate<T: Borrow<Self::Input>>(
Expand All @@ -50,7 +50,7 @@ pub trait TwoToOneCRHScheme {
+ Default
+ CanonicalSerialize
+ CanonicalDeserialize;
type Parameters: Clone + CanonicalSerialize + CanonicalDeserialize;
type Parameters: Clone + CanonicalSerialize + CanonicalDeserialize + Sync;

fn setup<R: Rng>(r: &mut R) -> Result<Self::Parameters, Error>;

Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/crh/pedersen/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use ark_ec::CurveGroup;
use ark_ff::Field;
use ark_r1cs_std::prelude::*;
use ark_relations::r1cs::{Namespace, SynthesisError};
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

use crate::crh::pedersen::{TwoToOneCRH, CRH};
use crate::crh::{CRHSchemeGadget, TwoToOneCRHSchemeGadget};
Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/crh/pedersen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use ark_ff::{Field, ToConstraintField};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::borrow::Borrow;
use ark_std::cfg_chunks;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

#[cfg(feature = "r1cs")]
pub mod constraints;
Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/crh/poseidon/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use ark_r1cs_std::R1CSVar;
use ark_relations::r1cs::{Namespace, SynthesisError};
use ark_std::borrow::Borrow;
use ark_std::marker::PhantomData;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

#[derive(Clone)]
pub struct CRHParametersVar<F: PrimeField + Absorb> {
Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/crh/sha256/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use ark_r1cs_std::{
R1CSVar,
};
use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError};
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

const STATE_LEN: usize = 8;

Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/crh/sha256/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use crate::crh::{CRHScheme, TwoToOneCRHScheme};
use crate::Error;

use ark_std::rand::Rng;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

// Re-export the RustCrypto Sha256 type and its associated traits
pub use sha2::{digest, Sha256};
Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/encryption/elgamal/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use ark_ff::{
Zero,
};
use ark_serialize::CanonicalSerialize;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
use ark_std::{borrow::Borrow, marker::PhantomData};

pub type ConstraintF<C> = <<C as CurveGroup>::BaseField as Field>::BasePrimeField;
Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/merkle_tree/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use ark_r1cs_std::prelude::*;
use ark_relations::r1cs::{Namespace, SynthesisError};
use ark_std::borrow::Borrow;
use ark_std::fmt::Debug;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

pub trait DigestVarConverter<From, To: ?Sized> {
type TargetType: Borrow<To>;
Expand Down
10 changes: 8 additions & 2 deletions crypto-primitives/src/merkle_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ use crate::sponge::Absorb;
use crate::{crh::CRHScheme, Error};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::borrow::Borrow;
use ark_std::collections::{BTreeSet, HashMap};
use ark_std::collections::BTreeSet;
use ark_std::hash::Hash;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
use hashbrown::HashMap;

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -65,7 +68,9 @@ pub trait Config {
+ Default
+ CanonicalSerialize
+ CanonicalDeserialize
+ Send;
+ Send
+ Sync;

// transition between leaf layer to inner layer
type LeafInnerDigestConverter: DigestConverter<
Self::LeafDigest,
Expand All @@ -80,6 +85,7 @@ pub trait Config {
+ CanonicalSerialize
+ CanonicalDeserialize
+ Send
+ Sync
+ Absorb;

// Tom's Note: in the future, if we want different hash function, we can simply add more
Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/prf/blake2s/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError};

use crate::prf::PRFGadget;
use ark_r1cs_std::prelude::*;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

use core::borrow::Borrow;

Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/prf/blake2s/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
use blake2::{Blake2s256 as B2s, Blake2sMac};
use digest::Digest;

Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/prf/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use crate::prf::PRF;
use ark_relations::r1cs::{Namespace, SynthesisError};

use ark_r1cs_std::prelude::*;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

pub trait PRFGadget<P: PRF, F: Field> {
type OutputVar: EqGadget<F>
Expand Down
4 changes: 3 additions & 1 deletion crypto-primitives/src/signature/schnorr/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use ark_relations::r1cs::{Namespace, SynthesisError};

use crate::signature::SigRandomizePkGadget;

use core::{borrow::Borrow, marker::PhantomData};
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
use ark_std::{borrow::Borrow, marker::PhantomData};

use crate::signature::schnorr::{Parameters, PublicKey, Schnorr};
use digest::Digest;
Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/signature/schnorr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use ark_ff::{
use ark_serialize::CanonicalSerialize;
use ark_std::ops::Mul;
use ark_std::rand::Rng;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
use ark_std::{hash::Hash, marker::PhantomData};
use digest::Digest;

Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/snark/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use ark_relations::{
},
};
use ark_snark::{CircuitSpecificSetupSNARK, UniversalSetupSNARK, SNARK};
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
use ark_std::{borrow::Borrow, fmt, marker::PhantomData, vec::IntoIter};

/// This implements constraints for SNARK verifiers.
Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/sponge/absorb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use ark_ec::{
use ark_ff::models::{Fp, FpConfig};
use ark_ff::{BigInteger, Field, PrimeField, ToConstraintField};
use ark_serialize::CanonicalSerialize;
#[cfg(not(feature = "std"))]
use ark_std::{string::String, vec::Vec};

pub use ark_crypto_primitives_macros::*;

Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/sponge/constraints/absorb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ 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;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

/// An interface for objects that can be absorbed by a `CryptographicSpongeVar` whose constraint field
/// is `CF`.
Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/sponge/constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use ark_r1cs_std::uint8::UInt8;
use ark_r1cs_std::R1CSVar;
use ark_relations::lc;
use ark_relations::r1cs::{ConstraintSystemRef, LinearCombination, SynthesisError};
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

mod absorb;
pub use absorb::*;
Expand Down
3 changes: 2 additions & 1 deletion crypto-primitives/src/sponge/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use ark_ff::PrimeField;
use ark_std::vec;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

/// Infrastructure for the constraints counterparts.
#[cfg(feature = "r1cs")]
Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/sponge/poseidon/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use ark_ff::PrimeField;
use ark_r1cs_std::fields::fp::FpVar;
use ark_r1cs_std::prelude::*;
use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

#[derive(Clone)]
/// the gadget for Poseidon sponge
Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/sponge/poseidon/grain_lfsr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![allow(dead_code)]

use ark_ff::{BigInteger, PrimeField};
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

pub struct PoseidonGrainLFSR {
pub prime_num_bits: u64,
Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/sponge/poseidon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use crate::sponge::{
use ark_ff::{BigInteger, PrimeField};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::any::TypeId;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

/// constraints for Poseidon
#[cfg(feature = "r1cs")]
Expand Down
2 changes: 2 additions & 0 deletions crypto-primitives/src/sponge/poseidon/traits.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::sponge::poseidon::grain_lfsr::PoseidonGrainLFSR;
use crate::sponge::poseidon::PoseidonConfig;
use ark_ff::{fields::models::*, PrimeField};
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

/// An entry in the default Poseidon parameters
pub struct PoseidonDefaultConfigEntry {
Expand Down

0 comments on commit 9ef1753

Please sign in to comment.