Skip to content

Commit b3b4a15

Browse files
Update the latest arkworks dependencies (#84)
Co-authored-by: Pratyush Mishra <pratyush795@gmail.com>
1 parent d570ee5 commit b3b4a15

11 files changed

Lines changed: 206 additions & 200 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
steps:
1515

1616
- name: Checkout
17-
uses: actions/checkout@v1
17+
uses: actions/checkout@v4
1818
- name: Install Rust
1919
uses: actions-rs/toolchain@v1
2020
with:
@@ -41,7 +41,7 @@ jobs:
4141
- nightly
4242
steps:
4343
- name: Checkout
44-
uses: actions/checkout@v2
44+
uses: actions/checkout@v4
4545

4646
- name: Install Rust (${{ matrix.rust }})
4747
uses: actions-rs/toolchain@v1
@@ -89,7 +89,7 @@ jobs:
8989
runs-on: ubuntu-latest
9090
steps:
9191
- name: Checkout
92-
uses: actions/checkout@v2
92+
uses: actions/checkout@v4
9393

9494
- name: Install Rust
9595
uses: actions-rs/toolchain@v1

Cargo.toml

Lines changed: 62 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,72 @@ description = "An implementation of the Groth 2016 zkSNARK proof system"
66
homepage = "https://arkworks.rs"
77
repository = "https://github.com/arkworks-rs/groth16"
88
documentation = "https://docs.rs/ark-groth16/"
9-
keywords = [ "zero-knowledge", "cryptography", "zkSNARK", "SNARK", "Groth-Maller" ]
10-
categories = [ "cryptography" ]
9+
keywords = [
10+
"zero-knowledge",
11+
"cryptography",
12+
"zkSNARK",
13+
"SNARK",
14+
"Groth-Maller",
15+
]
16+
categories = ["cryptography"]
1117
include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
1218
license = "MIT/Apache-2.0"
1319
edition = "2021"
1420

1521
################################# Dependencies ################################
1622

1723
[dependencies]
18-
ark-ff = { version = "0.5.0", default-features = false }
19-
ark-ec = { version = "0.5.0", default-features = false }
20-
ark-serialize = { version = "0.5.0", default-features = false, features = [ "derive" ] }
21-
ark-poly = { version = "0.5.0", default-features = false }
24+
ark-ff = { git = "https://github.com/arkworks-rs/algebra.git", default-features = false }
25+
ark-ec = { git = "https://github.com/arkworks-rs/algebra.git", default-features = false }
26+
ark-serialize = { git = "https://github.com/arkworks-rs/algebra.git", default-features = false, features = [ "derive" ] }
27+
ark-poly = { git = "https://github.com/arkworks-rs/algebra.git", default-features = false }
2228
ark-std = { version = "0.5.0", default-features = false }
23-
ark-relations = { version = "0.5.0", default-features = false }
24-
ark-crypto-primitives = { version = "0.5.0", default-features = false, features = ["snark", "sponge"] }
25-
ark-r1cs-std = { version = "0.5.0", default-features = false, optional = true }
2629

27-
tracing = { version = "0.1", default-features = false, features = [ "attributes" ], optional = true }
28-
derivative = { version = "2.0", features = ["use_core"], optional = true}
30+
ark-relations = { git = "https://github.com/arkworks-rs/snark.git", default-features = false }
31+
ark-snark = { git = "https://github.com/arkworks-rs/snark.git", default-features = false }
32+
33+
ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std.git", default-features = false, optional = true }
34+
ark-crypto-primitives = { git = "https://github.com/arkworks-rs/crypto-primitives.git", default-features = false, features = [ "snark", "sponge" ] }
35+
tracing = { version = "0.1", default-features = false, features = ["attributes" ], optional = true }
36+
educe = { version = "0.6.0", default-features = false, features = [ "Clone" ], optional = true }
2937

3038
rayon = { version = "1", optional = true }
3139

3240
[dev-dependencies]
33-
csv = { version = "1" }
34-
ark-bls12-381 = { version = "0.5.0", default-features = false, features = ["curve"] }
35-
ark-bls12-377 = { version = "0.5.0", default-features = false, features = ["curve"] }
36-
ark-bw6-761 = { version = "0.5.0", default-features = false }
37-
ark-mnt4-298 = { version = "0.5.0", default-features = false, features = ["r1cs", "curve"] }
38-
ark-mnt6-298 = { version = "0.5.0", default-features = false, features = ["r1cs"] }
39-
ark-mnt4-753 = { version = "0.5.0", default-features = false, features = ["r1cs", "curve"] }
40-
ark-mnt6-753 = { version = "0.5.0", default-features = false, features = ["r1cs"] }
41-
ark-r1cs-std = { version = "0.5.0", default-features = false }
42-
ark-bn254 = { version = "0.5.0", default-features = false, features = ["curve"] }
41+
ark-bls12-381 = { git = "https://github.com/arkworks-rs/algebra.git", default-features = false, features = [ "curve" ] }
42+
ark-bls12-377 = { git = "https://github.com/arkworks-rs/algebra.git", default-features = false, features = [ "curve" ] }
43+
ark-bn254 = { git = "https://github.com/arkworks-rs/algebra.git", default-features = false, features = [ "curve" ] }
44+
ark-bw6-761 = { git = "https://github.com/arkworks-rs/algebra.git", default-features = false }
45+
ark-mnt4-298 = { git = "https://github.com/arkworks-rs/algebra.git", default-features = false, features = [ "curve", "r1cs" ] }
46+
ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std.git", default-features = true }
47+
4348

4449
[features]
4550
default = ["parallel"]
46-
std = ["ark-ff/std", "ark-ec/std", "ark-poly/std", "ark-relations/std", "ark-crypto-primitives/std", "ark-std/std" ]
47-
parallel = ["std", "ark-ff/parallel", "ark-poly/parallel", "ark-ec/parallel", "ark-crypto-primitives/parallel", "ark-std/parallel", "rayon"]
48-
r1cs = [ "ark-crypto-primitives/r1cs", "ark-r1cs-std", "tracing", "derivative" ]
49-
print-trace = [ "ark-std/print-trace" ]
51+
std = [
52+
"ark-ff/std",
53+
"ark-ec/std",
54+
"ark-poly/std",
55+
"ark-relations/std",
56+
"ark-crypto-primitives/std",
57+
"ark-std/std",
58+
]
59+
parallel = [
60+
"std",
61+
"ark-ff/parallel",
62+
"ark-poly/parallel",
63+
"ark-ec/parallel",
64+
"ark-crypto-primitives/parallel",
65+
"ark-std/parallel",
66+
"rayon",
67+
]
68+
r1cs = [
69+
"ark-crypto-primitives/constraints",
70+
"ark-r1cs-std",
71+
"tracing",
72+
"educe",
73+
]
74+
print-trace = ["ark-std/print-trace"]
5075

5176
[[bench]]
5277
name = "groth16-benches"
@@ -74,27 +99,19 @@ panic = 'abort'
7499

75100
[profile.test]
76101
opt-level = 3
77-
lto = "thin"
78102
incremental = true
79103
debug-assertions = true
80104
debug = true
81105

82-
83-
# [patch.crates-io]
84-
# ark-ff = { git = "https://github.com/arkworks-rs/algebra/" }
85-
# ark-ec = { git = "https://github.com/arkworks-rs/algebra/" }
86-
# ark-poly = { git = "https://github.com/arkworks-rs/algebra/" }
87-
# ark-serialize = { git = "https://github.com/arkworks-rs/algebra/" }
88-
# ark-bls12-381 = { git = "https://github.com/arkworks-rs/algebra/" }
89-
# ark-mnt4-298 = { git = "https://github.com/arkworks-rs/algebra/" }
90-
# ark-mnt6-298 = { git = "https://github.com/arkworks-rs/algebra/" }
91-
# ark-mnt4-753 = { git = "https://github.com/arkworks-rs/algebra/" }
92-
# ark-mnt6-753 = { git = "https://github.com/arkworks-rs/algebra/" }
93-
# ark-bls12-377 = { git = "https://github.com/arkworks-rs/algebra/" }
94-
# ark-bw6-761 = { git = "https://github.com/arkworks-rs/algebra/" }
95-
96-
# ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std/" }
97-
# ark-crypto-primitives = { git = "https://github.com/arkworks-rs/crypto-primitives/" }
98-
99-
# ark-relations = { git = "https://github.com/arkworks-rs/snark/" }
100-
# ark-snark = { git = "https://github.com/arkworks-rs/snark/" }
106+
[patch.crates-io]
107+
ark-relations = { git = "https://github.com/arkworks-rs/snark.git" }
108+
ark-ff = { git = "https://github.com/arkworks-rs/algebra.git" }
109+
ark-ec = { git = "https://github.com/arkworks-rs/algebra.git" }
110+
ark-poly = { git = "https://github.com/arkworks-rs/algebra.git" }
111+
ark-serialize = { git = "https://github.com/arkworks-rs/algebra.git" }
112+
ark-bls12-381 = { git = "https://github.com/arkworks-rs/algebra.git" }
113+
ark-bls12-377 = { git = "https://github.com/arkworks-rs/algebra.git" }
114+
ark-bn254 = { git = "https://github.com/arkworks-rs/algebra.git" }
115+
ark-bw6-761 = { git = "https://github.com/arkworks-rs/algebra.git" }
116+
ark-mnt4-298 = { git = "https://github.com/arkworks-rs/algebra.git" }
117+
ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std.git" }

benches/bench.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// For benchmark, run:
2-
// RAYON_NUM_THREADS=N cargo bench --no-default-features --features "std parallel" -- --nocapture
3-
// where N is the number of threads you want to use (N = 1 for single-thread).
2+
// RAYON_NUM_THREADS=N cargo bench --no-default-features --features "std
3+
// parallel" -- --nocapture where N is the number of threads you want to use (N
4+
// = 1 for single-thread).
45

56
use ark_bls12_381::{Bls12_381, Fr as BlsFr};
67
use ark_crypto_primitives::snark::SNARK;
78
use ark_ff::{PrimeField, UniformRand};
89
use ark_groth16::{r1cs_to_qap::evaluate_constraint, Groth16};
910
use ark_mnt4_298::{Fr as MNT4Fr, MNT4_298};
10-
use ark_mnt6_298::{Fr as MNT6Fr, MNT6_298};
1111
use ark_relations::{
12+
gr1cs::{ConstraintSynthesizer, ConstraintSystemRef, SynthesisError},
1213
lc,
13-
r1cs::{ConstraintSynthesizer, ConstraintSystemRef, SynthesisError},
1414
};
1515
use ark_std::rand::{Rng, SeedableRng};
1616

@@ -54,10 +54,10 @@ impl<F: PrimeField> ConstraintSynthesizer<F> for DummyCircuit<F> {
5454
}
5555

5656
for _ in 0..self.num_constraints - 1 {
57-
cs.enforce_constraint(lc!() + a, lc!() + b, lc!() + c)?;
57+
cs.enforce_r1cs_constraint(|| lc!() + a, || lc!() + b, || lc!() + c)?;
5858
}
5959

60-
cs.enforce_constraint(lc!(), lc!(), lc!())?;
60+
cs.enforce_r1cs_constraint(|| lc!(), || lc!(), || lc!())?;
6161

6262
Ok(())
6363
}
@@ -152,13 +152,11 @@ fn bench_evaluate_constraint() {
152152
fn bench_prove() {
153153
groth16_prove_bench!(bls, BlsFr, Bls12_381);
154154
groth16_prove_bench!(mnt4, MNT4Fr, MNT4_298);
155-
groth16_prove_bench!(mnt6, MNT6Fr, MNT6_298);
156155
}
157156

158157
fn bench_verify() {
159158
groth16_verify_bench!(bls, BlsFr, Bls12_381);
160159
groth16_verify_bench!(mnt4, MNT4Fr, MNT4_298);
161-
groth16_verify_bench!(mnt6, MNT6Fr, MNT6_298);
162160
}
163161

164162
fn main() {

src/constraints.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ use ark_r1cs_std::{
2121
pairing::PairingVar,
2222
uint8::UInt8,
2323
};
24-
use ark_relations::r1cs::{Namespace, SynthesisError};
24+
use ark_relations::gr1cs::{Namespace, SynthesisError};
2525
use ark_std::{borrow::Borrow, marker::PhantomData, vec::Vec};
2626

2727
type BasePrimeField<E> = <<E as Pairing>::BaseField as Field>::BasePrimeField;
2828

2929
/// The proof variable for the Groth16 construction
30-
#[derive(Derivative)]
31-
#[derivative(Clone(bound = "P::G1Var: Clone, P::G2Var: Clone"))]
30+
#[derive(educe::Educe)]
31+
#[educe(Clone(bound = "P::G1Var: Clone, P::G2Var: Clone"))]
3232
pub struct ProofVar<E: Pairing, P: PairingVar<E>> {
3333
/// The `A` element in `G1`.
3434
pub a: P::G1Var,
@@ -39,8 +39,8 @@ pub struct ProofVar<E: Pairing, P: PairingVar<E>> {
3939
}
4040

4141
/// A variable representing the Groth16 verifying key in the constraint system.
42-
#[derive(Derivative)]
43-
#[derivative(Clone(
42+
#[derive(educe::Educe)]
43+
#[educe(Clone(
4444
bound = "P::G1Var: Clone, P::GTVar: Clone, P::G1PreparedVar: Clone, P::G2PreparedVar: Clone"
4545
))]
4646
pub struct VerifyingKeyVar<E: Pairing, P: PairingVar<E>> {
@@ -111,8 +111,8 @@ where
111111

112112
/// Preprocessed verification key parameters variable for the Groth16
113113
/// construction
114-
#[derive(Derivative)]
115-
#[derivative(
114+
#[derive(educe::Educe)]
115+
#[educe(
116116
Clone(bound = "P::G1Var: Clone, P::GTVar: Clone, P::G1PreparedVar: Clone, \
117117
P::G2PreparedVar: Clone, ")
118118
)]
@@ -455,12 +455,13 @@ mod test {
455455
use ark_crypto_primitives::snark::{constraints::SNARKGadget, SNARK};
456456
use ark_ec::pairing::Pairing;
457457
use ark_ff::{Field, UniformRand};
458-
use ark_mnt4_298::{constraints::PairingVar as MNT4PairingVar, Fr as MNT4Fr, MNT4_298 as MNT4};
459-
use ark_mnt6_298::Fr as MNT6Fr;
458+
use ark_mnt4_298::{
459+
constraints::PairingVar as MNT4PairingVar, Fq as MNT6Fr, Fr as MNT4Fr, MNT4_298 as MNT4,
460+
};
460461
use ark_r1cs_std::{alloc::AllocVar, boolean::Boolean, eq::EqGadget};
461462
use ark_relations::{
463+
gr1cs::{ConstraintSynthesizer, ConstraintSystem, ConstraintSystemRef, SynthesisError},
462464
lc, ns,
463-
r1cs::{ConstraintSynthesizer, ConstraintSystem, ConstraintSystemRef, SynthesisError},
464465
};
465466
use ark_std::{
466467
ops::MulAssign,
@@ -492,11 +493,12 @@ mod test {
492493
})?;
493494

494495
for _ in 0..(self.num_variables - 3) {
495-
cs.new_witness_variable(|| self.a.ok_or(SynthesisError::AssignmentMissing))?;
496+
let _ =
497+
cs.new_witness_variable(|| self.a.ok_or(SynthesisError::AssignmentMissing))?;
496498
}
497499

498500
for _ in 0..self.num_constraints {
499-
cs.enforce_constraint(lc!() + a, lc!() + b, lc!() + c)
501+
cs.enforce_r1cs_constraint(|| lc!() + a, || lc!() + b, || lc!() + c)
500502
.unwrap();
501503
}
502504
Ok(())

src/generator.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ use crate::{r1cs_to_qap::R1CSToQAP, Groth16, ProvingKey, Vec, VerifyingKey};
22
use ark_ec::{pairing::Pairing, scalar_mul::BatchMulPreprocessing, CurveGroup};
33
use ark_ff::{Field, UniformRand, Zero};
44
use ark_poly::{EvaluationDomain, GeneralEvaluationDomain};
5-
use ark_relations::r1cs::{
5+
use ark_relations::gr1cs::{
66
ConstraintSynthesizer, ConstraintSystem, OptimizationGoal, Result as R1CSResult,
77
SynthesisError, SynthesisMode,
88
};
9-
use ark_std::rand::Rng;
10-
use ark_std::{cfg_into_iter, cfg_iter};
9+
use ark_std::{cfg_into_iter, cfg_iter, rand::Rng};
1110

1211
#[cfg(feature = "parallel")]
1312
use rayon::prelude::*;
@@ -43,7 +42,8 @@ impl<E: Pairing, QAP: R1CSToQAP> Groth16<E, QAP> {
4342
)
4443
}
4544

46-
/// Create parameters for a circuit, given some toxic waste, R1CS to QAP calculator and group generators
45+
/// Create parameters for a circuit, given some toxic waste, R1CS to QAP
46+
/// calculator and group generators
4747
pub fn generate_parameters_with_qap<C>(
4848
circuit: C,
4949
alpha: E::ScalarField,
@@ -73,8 +73,8 @@ impl<E: Pairing, QAP: R1CSToQAP> Groth16<E, QAP> {
7373
cs.finalize();
7474
end_timer!(lc_time);
7575

76-
// Following is the mapping of symbols from the Groth16 paper to this implementation
77-
// l -> num_instance_variables
76+
// Following is the mapping of symbols from the Groth16 paper to this
77+
// implementation l -> num_instance_variables
7878
// m -> qap_num_variables
7979
// x -> t
8080
// t(x) - zt
@@ -107,8 +107,8 @@ impl<E: Pairing, QAP: R1CSToQAP> Groth16<E, QAP> {
107107
.map(|i| usize::from(!b[i].is_zero()))
108108
.sum();
109109

110-
let gamma_inverse = gamma.inverse().ok_or(SynthesisError::UnexpectedIdentity)?;
111-
let delta_inverse = delta.inverse().ok_or(SynthesisError::UnexpectedIdentity)?;
110+
let gamma_inverse = gamma.inverse().unwrap();
111+
let delta_inverse = delta.inverse().unwrap();
112112

113113
let gamma_abc = cfg_iter!(a[..num_instance_variables])
114114
.zip(&b[..num_instance_variables])

src/lib.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
#[macro_use]
1616
extern crate ark_std;
1717

18-
#[cfg(feature = "r1cs")]
19-
#[macro_use]
20-
extern crate derivative;
21-
2218
/// Reduce an R1CS instance to a *Quadratic Arithmetic Program* instance.
2319
pub mod r1cs_to_qap;
2420

@@ -41,14 +37,12 @@ pub mod constraints;
4137
#[cfg(test)]
4238
mod test;
4339

44-
pub use self::data_structures::*;
45-
pub use self::verifier::*;
40+
pub use self::{data_structures::*, verifier::*};
4641

47-
use ark_crypto_primitives::snark::*;
4842
use ark_ec::pairing::Pairing;
49-
use ark_relations::r1cs::{ConstraintSynthesizer, SynthesisError};
50-
use ark_std::rand::RngCore;
51-
use ark_std::{marker::PhantomData, vec::Vec};
43+
use ark_relations::gr1cs::{ConstraintSynthesizer, SynthesisError};
44+
use ark_snark::*;
45+
use ark_std::{marker::PhantomData, rand::RngCore, vec::Vec};
5246
use r1cs_to_qap::{LibsnarkReduction, R1CSToQAP};
5347

5448
/// The SNARK of [[Groth16]](https://eprint.iacr.org/2016/260.pdf).
@@ -66,7 +60,11 @@ impl<E: Pairing, QAP: R1CSToQAP> SNARK<E::ScalarField> for Groth16<E, QAP> {
6660
fn circuit_specific_setup<C: ConstraintSynthesizer<E::ScalarField>, R: RngCore>(
6761
circuit: C,
6862
rng: &mut R,
69-
) -> Result<(Self::ProvingKey, Self::VerifyingKey), Self::Error> {
63+
) -> Result<(Self::ProvingKey, Self::VerifyingKey), Self::Error>
64+
where
65+
C: ConstraintSynthesizer<E::ScalarField>,
66+
R: RngCore,
67+
{
7068
let pk = Self::generate_random_parameters_with_reduction(circuit, rng)?;
7169
let vk = pk.vk.clone();
7270

0 commit comments

Comments
 (0)