Skip to content

Added the support for GR1CS and added rescue hash function #161

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

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
toolchain: ${{ matrix.rust }}
override: true

- uses: actions/cache@v2
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
target: aarch64-unknown-none
override: true

- uses: actions/cache@v2
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
Expand Down
24 changes: 4 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
[workspace]
members = [
"crypto-primitives",
"macros",
]
members = ["crypto-primitives", "macros"]
resolver = "2"

[workspace.package]
version = "0.4.0"
authors = [ "arkworks contributors" ]
version = "0.5.0"
authors = ["arkworks contributors"]
description = "A library of useful cryptographic primitives"
homepage = "https://arkworks.rs"
repository = "https://github.com/arkworks-rs/crypto-primitives"
documentation = "https://docs.rs/ark-crypto-primitives/"
keywords = [ "r1cs", "pedersen", "blake2s", "snark", "schnorr" ]
keywords = ["gr1cs", "pedersen", "blake2s", "snark", "schnorr"]
categories = ["cryptography"]
include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
license = "MIT/Apache-2.0"
Expand Down Expand Up @@ -43,16 +40,3 @@ incremental = true
debug-assertions = true
debug = true

[patch.crates-io]
ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std/" }
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/" }
ark-bls12-377 = { git = "https://github.com/arkworks-rs/algebra/" }
ark-mnt4-298 = { git = "https://github.com/arkworks-rs/algebra/" }
ark-mnt6-298 = { git = "https://github.com/arkworks-rs/algebra/" }
79 changes: 50 additions & 29 deletions crypto-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,75 @@ edition.workspace = true
################################# Dependencies ################################

[dependencies]
ark-crypto-primitives-macros = { version = "^0.4.0", path = "../macros" }
ark-crypto-primitives-macros = { version = "^0.5.0", path = "../macros" }

ark-ff = { version = "^0.4.0", default-features = false }
ark-ec = { version = "^0.4.0", default-features = false }
ark-std = { version = "^0.4.0", default-features = false }
ark-relations = { version = "^0.4.0", default-features = false }
ark-serialize = { version = "^0.4.0", default-features = false, features = [ "derive" ] }
ark-ff = { version = "^0.5.0", default-features = false }
ark-ec = { version = "^0.5.0", default-features = false }
ark-std = { version = "^0.5.0", default-features = false }
ark-relations = { git = "https://github.com/arkworks-rs/snark", default-features = true }
ark-serialize = { version = "^0.5.0", default-features = false, features = [
"derive",
] }

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 }
num-bigint = "0.4.4"
ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std", default-features = true, optional = true }
ark-snark = { git = "https://github.com/arkworks-rs/snark", default-features = true }

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, features = ["inline-more", "allocator-api2"], optional = true }
tracing = { version = "0.1", default-features = false, features = [
"attributes",
], optional = true }
hashbrown = { version = "0.14", default-features = false, features = [
"inline-more",
"allocator-api2",
], optional = true }

[features]
default = ["std"]
std = [ "ark-ff/std", "ark-ec/std", "ark-std/std", "ark-relations/std" ]
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 = [ "merlin" ]
commitment = [ "crh" ]
std = ["ark-ff/std", "ark-ec/std", "ark-std/std", "ark-relations/std"]
print-trace = ["ark-std/print-trace"]
parallel = [
"std",
"rayon",
"ark-ec/parallel",
"ark-std/parallel",
"ark-ff/parallel",
]
r1cs = ["ark-r1cs-std", "tracing"]
gr1cs = ["ark-r1cs-std", "tracing"]
crh = ["sponge"]
sponge = ["merlin"]
commitment = ["crh"]
merkle_tree = ["crh", "hashbrown"]
encryption = []
prf = []
snark = []
signature = []

[target.'cfg(all(target_has_atomic = "8", target_has_atomic = "16", target_has_atomic = "32", target_has_atomic = "64", target_has_atomic = "ptr"))'.dependencies]
ahash = { version = "0.8", default-features = false}
ahash = { version = "0.8", default-features = false }

[target.'cfg(not(all(target_has_atomic = "8", target_has_atomic = "16", target_has_atomic = "32", target_has_atomic = "64", target_has_atomic = "ptr")))'.dependencies]
fnv = { version = "1.0", default-features = false }

[dev-dependencies]
ark-ed-on-bls12-377 = { version = "^0.4.0", default-features = false }
ark-ed-on-bls12-381 = { version = "^0.4.0", default-features = false, features = [ "r1cs" ] }
ark-bls12-377 = { version = "^0.4.0", default-features = false, features = [ "curve", "r1cs" ] }
ark-mnt4-298 = { version = "^0.4.0", default-features = false, features = [ "curve", "r1cs" ] }
ark-mnt6-298 = { version = "^0.4.0", default-features = false, features = [ "r1cs" ] }
ark-ed-on-bls12-377 = { git = "https://github.com/arkworks-rs/algebra", default-features = false }
ark-ed-on-bls12-381 = { git = "https://github.com/arkworks-rs/algebra", default-features = false }
ark-bls12-377 = { git = "https://github.com/arkworks-rs/algebra", default-features = false, features = [
"curve",
] }
ark-bls12-381 = { git = "https://github.com/arkworks-rs/algebra", default-features = false, features = [
"curve",
] }
ark-mnt4-298 = { git = "https://github.com/arkworks-rs/algebra", default-features = false, features = [
"curve",
] }
ark-mnt6-298 = { git = "https://github.com/arkworks-rs/algebra", default-features = false }
criterion = { version = "0.4" }

################################# Benchmarks ##################################
Expand All @@ -71,28 +92,28 @@ criterion = { version = "0.4" }
name = "pedersen_crh"
path = "benches/crh.rs"
harness = false
required-features = [ "crh" ]
required-features = ["crh"]

[[bench]]
name = "pedersen_comm"
path = "benches/comm.rs"
harness = false
required-features = [ "commitment" ]
required-features = ["commitment"]

[[bench]]
name = "blake2s_prf"
path = "benches/prf.rs"
harness = false
required-features = [ "prf" ]
required-features = ["prf"]

[[bench]]
name = "schnorr_sig"
path = "benches/signature.rs"
harness = false
required-features = [ "signature" ]
required-features = ["signature"]

[[bench]]
name = "merkle_tree"
path = "benches/merkle_tree.rs"
harness = false
required-features = [ "merkle_tree" ]
required-features = ["merkle_tree"]
10 changes: 5 additions & 5 deletions crypto-primitives/src/commitment/blake2s/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};
use ark_ff::{Field, PrimeField};
use ark_r1cs_std::prelude::*;
use ark_relations::r1cs::{Namespace, SynthesisError};
use ark_relations::gr1cs::{Namespace, SynthesisError};
use ark_std::borrow::Borrow;

#[derive(Clone)]
Expand All @@ -20,7 +20,7 @@ impl<F: PrimeField> CommitmentGadget<blake2s::Commitment, F> for CommGadget {
type ParametersVar = ParametersVar;
type RandomnessVar = RandomnessVar<F>;

#[tracing::instrument(target = "r1cs", skip(input, r))]
#[tracing::instrument(target = "gr1cs", skip(input, r))]
fn commit(
_: &Self::ParametersVar,
input: &[UInt8<F>],
Expand All @@ -40,7 +40,7 @@ impl<F: PrimeField> CommitmentGadget<blake2s::Commitment, F> for CommGadget {
}

impl<ConstraintF: Field> AllocVar<(), ConstraintF> for ParametersVar {
#[tracing::instrument(target = "r1cs", skip(_cs, _f))]
#[tracing::instrument(target = "gr1cs", skip(_cs, _f))]
fn new_variable<T: Borrow<()>>(
_cs: impl Into<Namespace<ConstraintF>>,
_f: impl FnOnce() -> Result<T, SynthesisError>,
Expand All @@ -51,7 +51,7 @@ impl<ConstraintF: Field> AllocVar<(), ConstraintF> for ParametersVar {
}

impl<ConstraintF: PrimeField> AllocVar<[u8; 32], ConstraintF> for RandomnessVar<ConstraintF> {
#[tracing::instrument(target = "r1cs", skip(cs, f))]
#[tracing::instrument(target = "gr1cs", skip(cs, f))]
fn new_variable<T: Borrow<[u8; 32]>>(
cs: impl Into<Namespace<ConstraintF>>,
f: impl FnOnce() -> Result<T, SynthesisError>,
Expand All @@ -77,7 +77,7 @@ mod test {
};
use ark_ed_on_bls12_381::Fq as Fr;
use ark_r1cs_std::prelude::*;
use ark_relations::r1cs::ConstraintSystem;
use ark_relations::gr1cs::ConstraintSystem;
use ark_std::rand::Rng;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crypto-primitives/src/commitment/blake2s/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use digest::Digest;

pub struct Commitment;

#[cfg(feature = "r1cs")]
#[cfg(any(feature = "r1cs", feature = "gr1cs"))]
pub mod constraints;

impl CommitmentScheme for Commitment {
Expand Down
4 changes: 2 additions & 2 deletions crypto-primitives/src/commitment/constraints.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::commitment::CommitmentScheme;
use ark_ff::Field;
use ark_r1cs_std::prelude::*;
use ark_relations::r1cs::SynthesisError;
use ark_relations::gr1cs::SynthesisError;
use ark_std::fmt::Debug;

pub trait CommitmentGadget<C: CommitmentScheme, ConstraintF: Field> {
type OutputVar: EqGadget<ConstraintF>
+ ToBytesGadget<ConstraintF>
+ AllocVar<C::Output, ConstraintF>
+ R1CSVar<ConstraintF>
+ GR1CSVar<ConstraintF>
+ Clone
+ Sized
+ Debug;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use ark_r1cs_std::{
groups::{CurveVar, GroupOpsBounds},
uint8::UInt8,
};
use ark_relations::r1cs::SynthesisError;
use ark_relations::gr1cs::SynthesisError;
use ark_std::marker::PhantomData;

type ConstraintF<C> = <<C as CurveGroup>::BaseField as Field>::BasePrimeField;
Expand Down
2 changes: 1 addition & 1 deletion crypto-primitives/src/commitment/injective_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
use ark_ec::CurveGroup;
use ark_std::{marker::PhantomData, rand::Rng};

#[cfg(feature = "r1cs")]
#[cfg(any(feature = "r1cs", feature = "gr1cs"))]
pub mod constraints;

pub struct PedersenCommCompressor<C: CurveGroup, I: InjectiveMap<C>, W: pedersen::Window> {
Expand Down
4 changes: 2 additions & 2 deletions crypto-primitives/src/commitment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ pub mod blake2s;
pub mod injective_map;
pub mod pedersen;

#[cfg(feature = "r1cs")]
#[cfg(any(feature = "r1cs", feature = "gr1cs"))]
pub mod constraints;
#[cfg(feature = "r1cs")]
#[cfg(any(feature = "r1cs", feature = "gr1cs"))]
pub use constraints::*;

pub trait CommitmentScheme {
Expand Down
Loading