Skip to content

Commit 9b7dd34

Browse files
flyingnobitawindericadmpierre
authored
feat: Update arkworks to latest git versions with GR1CS migration (#228)
* Fix Pedersen circuit with inputs of odd length * Bump rust version * Fix performance regression of Pedersen circuit * Attempt to fix wasm target * Fix features for `getrandom` * Fix wasmer stuff * Fix CI * Add `CycleFoldCommittedInstanceVar::new_incoming_from_components` to simplify the construction of incoming CF instances * RLC for ProtoGalaxy can now be computed using a single `CycleFoldCircuit` * Absorb `pp_hash` when initializing sponge or transcript so we no longer need to absorb it later * Clarify comments and remove redundant code * feat: Update arkworks to latest git versions with GR1CS migration Dependencies Updated: - arkworks libraries: Updated to latest git versions via patch.crates-io - Note: Pinning to specific revisions caused version conflicts across the arkworks ecosystem - ark-r1cs-std: Using fork flyingnobita/r1cs-std_yelhousni (rev: b4bab0c) for GR1CS compatibility - ark-crypto-primitives: Using fork flyingnobita/crypto-primitives (rev: f559264) for GR1CS compatibility - wasmer: Updated to 6.1.0-rc.2 with sys feature for ark-circom compatibility - Rust toolchain: Updated to 1.85.0 (required by transitive dependency base64ct v1.8.0 via acvm/noir) Major API Changes: - Migrated from R1CS to GR1CS throughout the codebase - Changed all R1CSVar imports to GR1CSVar - Updated ark_relations::r1cs to ark_relations::gr1cs - Updated constraint enforcement API - Changed enforce_constraint to enforce_r1cs_constraint in experimental-frontends - Wrapped linear combinations in closures - Fixed instance_assignment from field access to method call Known Issue: - wasmer 6.1.0-rc.2 has linking issues on macOS ARM64 (undefined libunwind symbols) - Workarounds: - Exclude experimental-frontends from tests on macOS - Run tests in Linux/Intel environment - Note: wasmer 6.0.1 works but would require forking ark-circom * feat: Complete GR1CS migration and rebase onto dev branch - Migrate all constraint systems from R1CS to GR1CS across all folding schemes * refactor: Fix cargo fmt * fix: Update examples to use GR1CS instead of R1CS - Replace R1CSVar with GR1CSVar in test modules - Update ConstraintSystem imports from r1cs to gr1cs - Fix formatting in experimental-frontends witness calculator * chore: Remove unnecessary features from wasmer dependency to be inline with ark-circom dependency * fix: Update ark-circom dependency to resolve wasm target compilation Replace custom ark-circom fork with dmpierre's fork to fix compilation issues when building experimental-frontends for wasm targets. * ci: trigger * fix: Fix cargo fmt --------- Co-authored-by: winderica <[email protected]> Co-authored-by: dmpierre <[email protected]>
1 parent 9414c45 commit 9b7dd34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1257
-1292
lines changed

.github/scripts/wasm-target-test-build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ cd foobar
1212
cp "${GIT_ROOT}/rust-toolchain" .
1313

1414
# add wasm32-* targets
15-
rustup target add wasm32-unknown-unknown wasm32-wasi
15+
rustup target add wasm32-unknown-unknown wasm32-wasip1
1616

1717
# add dependencies
1818
cargo add --path "${GIT_ROOT}/frontends" --features wasm, parallel
1919
cargo add --path "${GIT_ROOT}/folding-schemes" --features parallel
20-
cargo add getrandom --features js --target wasm32-unknown-unknown
20+
cargo add getrandom --features wasm_js --target wasm32-unknown-unknown
2121

2222
# test build for wasm32-* targets
2323
cargo build --release --target wasm32-unknown-unknown
24-
cargo build --release --target wasm32-wasi
24+
cargo build --release --target wasm32-wasip1
2525
# Emscripten would require to fetch the `emcc` tooling. Hence we don't build the lib as a dep for it.
2626
# cargo build --release --target wasm32-unknown-emscripten
2727

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
matrix:
8484
target:
8585
- wasm32-unknown-unknown
86-
- wasm32-wasi
86+
- wasm32-wasip1
8787
# Ignoring until clear usage is required
8888
# - wasm32-unknown-emscripten
8989

Cargo.toml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,38 @@ members = [
33
"folding-schemes",
44
"solidity-verifiers",
55
"cli",
6-
"experimental-frontends"
6+
"experimental-frontends",
77
]
88
resolver = "2"
99

1010

1111
[patch.crates-io]
12-
ark-r1cs-std = { git = "https://github.com/yelhousni/r1cs-std", rev = "440ca3" } # "perf/sw" branch
12+
# Update ark-groth16 to latest git version
13+
ark-groth16 = { git = "https://github.com/arkworks-rs/groth16", rev = "b3b4a15" }
14+
15+
# Required dependencies for latest ark-groth16
16+
ark-ff = { git = "https://github.com/arkworks-rs/algebra" }
17+
ark-ec = { git = "https://github.com/arkworks-rs/algebra" }
18+
ark-serialize = { git = "https://github.com/arkworks-rs/algebra" }
19+
ark-poly = { git = "https://github.com/arkworks-rs/algebra" }
20+
ark-relations = { git = "https://github.com/arkworks-rs/snark" }
21+
ark-snark = { git = "https://github.com/arkworks-rs/snark" }
22+
ark-crypto-primitives = { git = "https://github.com/flyingnobita/crypto-primitives", rev = "f559264" }
23+
ark-r1cs-std = { git = "https://github.com/flyingnobita/r1cs-std_yelhousni", rev = "b4bab0c" } # "perf/sw-updated" branch
24+
ark-std = { git = "https://github.com/arkworks-rs/std" }
25+
ark-poly-commit = { git = "https://github.com/arkworks-rs/poly-commit" }
26+
27+
28+
# Curve crates also need git versions
29+
ark-bn254 = { git = "https://github.com/arkworks-rs/algebra" }
30+
ark-grumpkin = { git = "https://github.com/arkworks-rs/algebra" }
31+
ark-pallas = { git = "https://github.com/arkworks-rs/algebra" }
32+
ark-vesta = { git = "https://github.com/arkworks-rs/algebra" }
33+
ark-mnt4-298 = { git = "https://github.com/arkworks-rs/algebra" }
34+
ark-mnt6-298 = { git = "https://github.com/arkworks-rs/algebra" }
35+
36+
[patch."https://github.com/arkworks-rs/circom-compat"]
37+
ark-circom = { git = "https://github.com/dmpierre/circom-compat", rev = "0dfd773c" }
1338

1439
[workspace.package]
1540
edition = "2021"
@@ -38,11 +63,11 @@ revm = { version = "19.5.0", default-features = false }
3863
rust-crypto = { version = "0.2" }
3964
thiserror = { version = "1.0" }
4065
tokio = "1.44.1"
41-
wasmer = { version = "4.4.0", default-features = false }
66+
wasmer = { version = "6.1.0-rc.2", default-features = false }
4267

4368
# Arkworks family
4469
ark-bn254 = { version = "^0.5.0", default-features = false }
45-
ark-circom = { version = "^0.5.0", default-features = false }
70+
ark-circom = { git = "https://github.com/arkworks-rs/circom-compat", default-features = false }
4671
ark-crypto-primitives = { version = "^0.5.0", default-features = false }
4772
ark-ec = { version = "^0.5.0", default-features = false }
4873
ark-ff = { version = "^0.5.0", default-features = false }

cli/src/settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub(crate) enum Protocol {
2020

2121
impl Display for Protocol {
2222
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23-
write!(f, "{:?}", self)
23+
write!(f, "{self:?}")
2424
}
2525
}
2626

examples/external_inputs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use ark_ff::PrimeField;
1515
use ark_grumpkin::Projective as Projective2;
1616
use ark_r1cs_std::alloc::AllocVar;
1717
use ark_r1cs_std::fields::fp::FpVar;
18-
use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
18+
use ark_relations::gr1cs::{ConstraintSystemRef, SynthesisError};
1919
use core::marker::PhantomData;
2020
use std::time::Instant;
2121

@@ -108,8 +108,8 @@ where
108108
pub mod tests {
109109
use super::*;
110110
use ark_crypto_primitives::crh::{poseidon::CRH, CRHScheme};
111-
use ark_r1cs_std::R1CSVar;
112-
use ark_relations::r1cs::ConstraintSystem;
111+
use ark_r1cs_std::GR1CSVar;
112+
use ark_relations::gr1cs::ConstraintSystem;
113113

114114
fn external_inputs_step_native<F: PrimeField + Absorb>(
115115
z_i: Vec<F>,

examples/full_flow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use ark_groth16::Groth16;
1515
use ark_grumpkin::Projective as G2;
1616
use ark_r1cs_std::alloc::AllocVar;
1717
use ark_r1cs_std::fields::fp::FpVar;
18-
use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
18+
use ark_relations::gr1cs::{ConstraintSystemRef, SynthesisError};
1919
use std::marker::PhantomData;
2020
use std::time::Instant;
2121

examples/multi_inputs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use ark_ff::PrimeField;
77
use ark_r1cs_std::alloc::AllocVar;
88
use ark_r1cs_std::fields::fp::FpVar;
9-
use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
9+
use ark_relations::gr1cs::{ConstraintSystemRef, SynthesisError};
1010
use core::marker::PhantomData;
1111
use std::time::Instant;
1212

@@ -64,8 +64,8 @@ impl<F: PrimeField> FCircuit<F> for MultiInputsFCircuit<F> {
6464
#[cfg(test)]
6565
pub mod tests {
6666
use super::*;
67-
use ark_r1cs_std::{alloc::AllocVar, R1CSVar};
68-
use ark_relations::r1cs::ConstraintSystem;
67+
use ark_r1cs_std::{alloc::AllocVar, GR1CSVar};
68+
use ark_relations::gr1cs::ConstraintSystem;
6969

7070
fn multi_inputs_step_native<F: PrimeField>(z_i: Vec<F>) -> Vec<F> {
7171
let a = z_i[0] + F::from(4_u32);

examples/sha256.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use ark_r1cs_std::{
1212
convert::{ToBytesGadget, ToConstraintFieldGadget},
1313
fields::fp::FpVar,
1414
};
15-
use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
15+
use ark_relations::gr1cs::{ConstraintSystemRef, SynthesisError};
1616
use core::marker::PhantomData;
1717
use std::time::Instant;
1818

@@ -66,8 +66,8 @@ pub mod tests {
6666
use super::*;
6767
use ark_crypto_primitives::crh::{sha256::Sha256, CRHScheme};
6868
use ark_ff::{BigInteger, ToConstraintField};
69-
use ark_r1cs_std::{alloc::AllocVar, R1CSVar};
70-
use ark_relations::r1cs::ConstraintSystem;
69+
use ark_r1cs_std::{alloc::AllocVar, GR1CSVar};
70+
use ark_relations::gr1cs::ConstraintSystem;
7171

7272
fn sha256_step_native<F: PrimeField>(z_i: Vec<F>) -> Vec<F> {
7373
let out_bytes = Sha256::evaluate(&(), z_i[0].into_bigint().to_bytes_le()).unwrap();

experimental-frontends/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ acvm = { workspace = true }
1818
folding-schemes = { workspace = true }
1919
serde = { workspace = true, features = ["derive"] }
2020
serde_json = { workspace = true }
21-
tokio = { workspace = true }
2221
wasmer = { workspace = true }
2322

2423
[dev-dependencies]

experimental-frontends/src/circom/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use ark_circom::circom::R1CS as CircomR1CS;
22
use ark_ff::PrimeField;
33
use ark_r1cs_std::{
44
fields::fp::{AllocatedFp, FpVar},
5-
R1CSVar,
5+
GR1CSVar,
66
};
77
use ark_relations::{
8+
gr1cs::{ConstraintSystemRef, SynthesisError, Variable},
89
lc,
9-
r1cs::{ConstraintSystemRef, SynthesisError, Variable},
1010
};
1111
use ark_std::fmt::Debug;
1212
use folding_schemes::{frontend::FCircuit, utils::PathOrBin, Error};
@@ -124,10 +124,10 @@ impl<F: PrimeField, const SL: usize, const EIL: usize> FCircuit<F> for CircomFCi
124124

125125
// Generates the constraints for the circom_circuit.
126126
for (a, b, c) in &self.r1cs.constraints {
127-
cs.enforce_constraint(
128-
a.iter().fold(lc!(), fold_lc),
129-
b.iter().fold(lc!(), fold_lc),
130-
c.iter().fold(lc!(), fold_lc),
127+
cs.enforce_r1cs_constraint(
128+
|| a.iter().fold(lc!(), fold_lc),
129+
|| b.iter().fold(lc!(), fold_lc),
130+
|| c.iter().fold(lc!(), fold_lc),
131131
)?;
132132
}
133133

@@ -157,7 +157,7 @@ pub mod tests {
157157
use super::*;
158158
use ark_bn254::Fr;
159159
use ark_r1cs_std::alloc::AllocVar;
160-
use ark_relations::r1cs::{ConstraintSynthesizer, ConstraintSystem};
160+
use ark_relations::gr1cs::{ConstraintSynthesizer, ConstraintSystem};
161161
use std::path::PathBuf;
162162

163163
/// Native implementation of `src/circom/test_folder/cubic_circuit.r1cs`

0 commit comments

Comments
 (0)