diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b7ef464e..aa46edac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,9 +61,9 @@ jobs: curl -sSfL https://github.com/ethereum/solidity/releases/download/v0.8.4/solc-static-linux -o /usr/local/bin/solc chmod +x /usr/local/bin/solc - name: Execute compile.sh to generate .r1cs and .wasm from .circom - run: ./folding-schemes/src/frontend/circom/test_folder/compile.sh + run: ./frontends/src/circom/test_folder/compile.sh - name: Execute compile.sh to generate .json from noir - run: ./folding-schemes/src/frontend/noir/test_folder/compile.sh + run: ./frontends/src/noir/test_folder/compile.sh - name: Run tests uses: actions-rs/cargo@v1 with: @@ -127,7 +127,7 @@ jobs: curl -sSfL https://github.com/ethereum/solidity/releases/download/v0.8.4/solc-static-linux -o /usr/local/bin/solc chmod +x /usr/local/bin/solc - name: Execute compile.sh to generate .r1cs and .wasm from .circom - run: ./folding-schemes/src/frontend/circom/test_folder/compile.sh + run: ./frontends/src/circom/test_folder/compile.sh - name: Execute compile.sh to generate .json from noir run: ./folding-schemes/src/frontend/noir/test_folder/compile.sh - name: Run examples tests diff --git a/.gitignore b/.gitignore index d3067b1d..e2e3afdc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,14 +2,14 @@ Cargo.lock # Circom generated files -folding-schemes/src/frontend/circom/test_folder/*_js/ +frontends/src/circom/test_folder/*_js/ *.r1cs *.sym # Noir generated files -folding-schemes/src/frontend/noir/test_folder/*/target/* +frontends/src/noir/test_folder/*/target/* -# generated contracts at test time +# generated contracts data solidity-verifiers/generated examples/*.sol examples/*.calldata diff --git a/Cargo.toml b/Cargo.toml index 8445a188..ab6063d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,8 @@ members = [ "folding-schemes", "solidity-verifiers", - "cli" + "cli", + "frontends" ] resolver = "2" diff --git a/README.md b/README.md index 5b742968..3bfb3129 100644 --- a/README.md +++ b/README.md @@ -27,14 +27,6 @@ Work in progress: - [ProtoGalaxy: Efficient ProtoStar-style folding of multiple instances](https://eprint.iacr.org/2023/1106.pdf), Liam Eagen, Ariel Gabizon. 2023 -## Available frontends - -Available frontends to define the folded circuit: - -- [arkworks](https://github.com/arkworks-rs), arkworks contributors -- [Circom](https://github.com/iden3/circom), iden3, 0Kims Association -- [Noname](https://github.com/zksecurity/noname), zkSecurity - ## Usage ### Build & test diff --git a/examples/circom_full_flow.rs b/examples/circom_full_flow.rs index dccf0d8e..bd6427ee 100644 --- a/examples/circom_full_flow.rs +++ b/examples/circom_full_flow.rs @@ -23,10 +23,11 @@ use folding_schemes::{ decider_eth::{prepare_calldata, Decider as DeciderEth}, Nova, PreprocessorParam, }, - frontend::{circom::CircomFCircuit, FCircuit}, + frontend::FCircuit, transcript::poseidon::poseidon_canonical_config, Decider, FoldingScheme, }; +use frontends::circom::CircomFCircuit; use solidity_verifiers::{ evm::{compile_solidity, Evm}, utils::get_function_selector_for_nova_cyclefold_verifier, diff --git a/examples/noir_full_flow.rs b/examples/noir_full_flow.rs index 64531098..d0984f40 100644 --- a/examples/noir_full_flow.rs +++ b/examples/noir_full_flow.rs @@ -20,13 +20,11 @@ use folding_schemes::{ decider_eth::{prepare_calldata, Decider as DeciderEth}, Nova, PreprocessorParam, }, - frontend::{ - noir::{load_noir_circuit, NoirFCircuit}, - FCircuit, - }, + frontend::FCircuit, transcript::poseidon::poseidon_canonical_config, Decider, FoldingScheme, }; +use frontends::noir::{load_noir_circuit, NoirFCircuit}; use std::{env, time::Instant}; use solidity_verifiers::{ diff --git a/examples/noname_full_flow.rs b/examples/noname_full_flow.rs index 00dccbfb..6831a2e5 100644 --- a/examples/noname_full_flow.rs +++ b/examples/noname_full_flow.rs @@ -21,10 +21,11 @@ use folding_schemes::{ decider_eth::{prepare_calldata, Decider as DeciderEth}, Nova, PreprocessorParam, }, - frontend::{noname::NonameFCircuit, FCircuit}, + frontend::FCircuit, transcript::poseidon::poseidon_canonical_config, Decider, FoldingScheme, }; +use frontends::noname::NonameFCircuit; use std::time::Instant; use solidity_verifiers::{ diff --git a/folding-schemes/Cargo.toml b/folding-schemes/Cargo.toml index d7c45482..22b074de 100644 --- a/folding-schemes/Cargo.toml +++ b/folding-schemes/Cargo.toml @@ -9,28 +9,20 @@ ark-ff = { version = "^0.4.0", default-features = false, features = ["parallel", ark-poly = { version = "^0.4.0", default-features = false, features = ["parallel"] } ark-std = { version = "^0.4.0", default-features = false, features = ["parallel"] } ark-crypto-primitives = { version = "^0.4.0", default-features = false, features = ["r1cs", "sponge", "crh", "parallel"] } -ark-grumpkin = { version = "0.4.0", default-features = false } ark-poly-commit = { version = "^0.4.0", default-features = false, features = ["parallel"] } ark-relations = { version = "^0.4.0", default-features = false } -# this is patched at the workspace level +# ark-r1cs-std is patched at the workspace level ark-r1cs-std = { version = "0.4.0", default-features = false, features = ["parallel"] } ark-snark = { version = "^0.4.0", default-features = false } ark-serialize = { version = "^0.4.0", default-features = false } -ark-circom = { git = "https://github.com/arnaucube/circom-compat", default-features = false } ark-groth16 = { version = "^0.4.0", default-features = false, features = ["parallel"]} ark-bn254 = { version = "^0.4.0", default-features = false } +ark-grumpkin = { version = "0.4.0", default-features = false } thiserror = "1.0" rayon = "1" num-bigint = "0.4" num-integer = "0.1" -color-eyre = "=0.6.2" sha3 = "0.10" -ark-noname = { git = "https://github.com/dmpierre/ark-noname", branch = "feat/sonobe-integration" } -noname = { git = "https://github.com/dmpierre/noname" } -serde_json = "1.0.85" # to (de)serialize JSON -serde = "1.0.203" -acvm = { git = "https://github.com/noir-lang/noir", rev="2b4853e", default-features = false } -noir_arkworks_backend = { package="arkworks_backend", git = "https://github.com/dmpierre/arkworks_backend", branch = "feat/sonobe-integration" } log = "0.4" # tmp import for espresso's sumcheck @@ -46,6 +38,7 @@ ark-grumpkin = {version="0.4.0", features=["r1cs"]} ark-mnt4-298 = {version="0.4.0", features=["r1cs"]} ark-mnt6-298 = {version="0.4.0", features=["r1cs"]} rand = "0.8.5" +num-bigint = {version = "0.4", features = ["rand"]} tracing = { version = "0.1", default-features = false, features = [ "attributes" ] } tracing-subscriber = { version = "0.2" } @@ -55,9 +48,8 @@ tracing-subscriber = { version = "0.2" } getrandom = { version = "0.2", features = ["js"] } [features] -default = ["ark-circom/default", "parallel"] +default = ["parallel"] parallel = [] -wasm = ["ark-circom/wasm"] light-test = [] diff --git a/folding-schemes/src/frontend/circom/test_folder/compile.sh b/folding-schemes/src/frontend/circom/test_folder/compile.sh deleted file mode 100755 index 6eae30ed..00000000 --- a/folding-schemes/src/frontend/circom/test_folder/compile.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -circom ./folding-schemes/src/frontend/circom/test_folder/cubic_circuit.circom --r1cs --sym --wasm --prime bn128 --output ./folding-schemes/src/frontend/circom/test_folder/ -circom ./folding-schemes/src/frontend/circom/test_folder/with_external_inputs.circom --r1cs --sym --wasm --prime bn128 --output ./folding-schemes/src/frontend/circom/test_folder/ -circom ./folding-schemes/src/frontend/circom/test_folder/no_external_inputs.circom --r1cs --sym --wasm --prime bn128 --output ./folding-schemes/src/frontend/circom/test_folder/ diff --git a/folding-schemes/src/frontend/mod.rs b/folding-schemes/src/frontend/mod.rs index 7cf9e432..8570c818 100644 --- a/folding-schemes/src/frontend/mod.rs +++ b/folding-schemes/src/frontend/mod.rs @@ -4,9 +4,6 @@ use ark_r1cs_std::fields::fp::FpVar; use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError}; use ark_std::fmt::Debug; -pub mod circom; -pub mod noir; -pub mod noname; pub mod utils; /// FCircuit defines the trait of the circuit of the F function, which is the one being folded (ie. diff --git a/folding-schemes/src/frontend/utils.rs b/folding-schemes/src/frontend/utils.rs index 64d8847c..0abb040f 100644 --- a/folding-schemes/src/frontend/utils.rs +++ b/folding-schemes/src/frontend/utils.rs @@ -152,14 +152,14 @@ impl FCircuit for CustomFCircuit { /// than the one done in the `AugmentedFCircuit`, but without adding all the extra constraints /// of the AugmentedF circuit logic, in order to run lighter tests when we're not interested in /// the the AugmentedF logic but in the wrapping of the circuits. -#[cfg(test)] +// #[cfg(test)] pub struct WrapperCircuit> { pub FC: FC, // F circuit pub z_i: Option>, pub z_i1: Option>, } -#[cfg(test)] +// #[cfg(test)] impl ark_relations::r1cs::ConstraintSynthesizer for WrapperCircuit where F: PrimeField, diff --git a/frontends/Cargo.toml b/frontends/Cargo.toml new file mode 100644 index 00000000..d3c56e04 --- /dev/null +++ b/frontends/Cargo.toml @@ -0,0 +1,41 @@ +[package] +name = "frontends" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +ark-ec = { version = "^0.4.0", default-features = false, features = ["parallel"] } +ark-ff = { version = "^0.4.0", default-features = false, features = ["parallel", "asm"] } +ark-poly = { version = "^0.4.0", default-features = false, features = ["parallel"] } +ark-std = { version = "^0.4.0", default-features = false, features = ["parallel"] } +ark-relations = { version = "^0.4.0", default-features = false } +# this is patched at the workspace level +ark-r1cs-std = { version = "0.4.0", default-features = false, features = ["parallel"] } +ark-serialize = { version = "^0.4.0", default-features = false } +ark-circom = { git = "https://github.com/arnaucube/circom-compat", default-features = false } +num-bigint = "0.4" +color-eyre = "=0.6.2" +ark-noname = { git = "https://github.com/dmpierre/ark-noname", branch = "feat/sonobe-integration" } +noname = { git = "https://github.com/dmpierre/noname" } +serde_json = "1.0.85" # to (de)serialize JSON +acvm = { git = "https://github.com/noir-lang/noir", rev="2b4853e", default-features = false } +noir_arkworks_backend = { package="arkworks_backend", git = "https://github.com/dmpierre/arkworks_backend", branch = "feat/sonobe-integration" } +folding-schemes = { path = "../folding-schemes/"} + +# tmp import for espresso's sumcheck +espresso_subroutines = {git="https://github.com/EspressoSystems/hyperplonk", package="subroutines"} + +[dev-dependencies] +ark-bn254 = {version="0.4.0", features=["r1cs"]} + +# This allows the crate to be built when targeting WASM. +# See more at: https://docs.rs/getrandom/#webassembly-support +[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies] +getrandom = { version = "0.2", features = ["js"] } + +[features] +default = ["ark-circom/default", "parallel"] +parallel = [] +wasm = ["ark-circom/wasm"] diff --git a/frontends/README.md b/frontends/README.md new file mode 100644 index 00000000..43391011 --- /dev/null +++ b/frontends/README.md @@ -0,0 +1,14 @@ +# frontends + +Experimental frontends for Sonobe. +The recommended frontend is to directly use [arkworks](https://github.com/arkworks-rs) to define the FCircuit, just following the [`FCircuit` trait](https://github.com/privacy-scaling-explorations/sonobe/blob/main/folding-schemes/src/frontend/mod.rs). + +## Experimental frontends +> Warning: the following frontends are experimental and some computational and time overhead is expected when using them compared to directly using the [arkworks frontend](https://github.com/privacy-scaling-explorations/sonobe/blob/main/folding-schemes/src/frontend/mod.rs). + +- [Circom](https://github.com/iden3/circom), iden3, 0Kims Association (supported v2.1.9) +- [Noir](https://github.com/noir-lang/noir), Aztec +- [Noname](https://github.com/zksecurity/noname), zkSecurity + + +More details about frontends: https://privacy-scaling-explorations.github.io/sonobe-docs/usage/frontend.html diff --git a/folding-schemes/src/frontend/circom/mod.rs b/frontends/src/circom/mod.rs similarity index 89% rename from folding-schemes/src/frontend/circom/mod.rs rename to frontends/src/circom/mod.rs index a261f722..88a9da5b 100644 --- a/folding-schemes/src/frontend/circom/mod.rs +++ b/frontends/src/circom/mod.rs @@ -1,14 +1,12 @@ -use crate::frontend::FCircuit; -use crate::frontend::FpVar::Var; -use crate::utils::PathOrBin; -use crate::Error; use ark_circom::circom::{CircomCircuit, R1CS as CircomR1CS}; use ark_ff::PrimeField; use ark_r1cs_std::alloc::AllocVar; use ark_r1cs_std::fields::fp::FpVar; +use ark_r1cs_std::fields::fp::FpVar::Var; use ark_r1cs_std::R1CSVar; use ark_relations::r1cs::{ConstraintSynthesizer, ConstraintSystemRef, SynthesisError}; use ark_std::fmt::Debug; +use folding_schemes::{frontend::FCircuit, utils::PathOrBin, Error}; use num_bigint::BigInt; use std::rc::Rc; use std::{fmt, usize}; @@ -187,10 +185,10 @@ impl FCircuit for CircomFCircuit { } impl CircomFCircuit { - fn fpvars_to_bigints(&self, fpVars: &[FpVar]) -> Result, SynthesisError> { + fn fpvars_to_bigints(&self, fpvars: &[FpVar]) -> Result, SynthesisError> { let mut input_values = Vec::new(); // converts each FpVar to PrimeField value, then to num_bigint::BigInt. - for fp_var in fpVars.iter() { + for fp_var in fpvars.iter() { // extracts the PrimeField value from FpVar. let primefield_value = fp_var.value()?; // converts the PrimeField value to num_bigint::BigInt. @@ -213,9 +211,9 @@ pub mod tests { // Tests the step_native function of CircomFCircuit. #[test] fn test_circom_step_native() { - let r1cs_path = PathBuf::from("./src/frontend/circom/test_folder/cubic_circuit.r1cs"); + let r1cs_path = PathBuf::from("./src/circom/test_folder/cubic_circuit.r1cs"); let wasm_path = - PathBuf::from("./src/frontend/circom/test_folder/cubic_circuit_js/cubic_circuit.wasm"); + PathBuf::from("./src/circom/test_folder/cubic_circuit_js/cubic_circuit.wasm"); let circom_fcircuit = CircomFCircuit::::new((r1cs_path.into(), wasm_path.into(), 1, 0)).unwrap(); // state_len:1, external_inputs_len:0 @@ -228,9 +226,9 @@ pub mod tests { // Tests the generate_step_constraints function of CircomFCircuit. #[test] fn test_circom_step_constraints() { - let r1cs_path = PathBuf::from("./src/frontend/circom/test_folder/cubic_circuit.r1cs"); + let r1cs_path = PathBuf::from("./src/circom/test_folder/cubic_circuit.r1cs"); let wasm_path = - PathBuf::from("./src/frontend/circom/test_folder/cubic_circuit_js/cubic_circuit.wasm"); + PathBuf::from("./src/circom/test_folder/cubic_circuit_js/cubic_circuit.wasm"); let circom_fcircuit = CircomFCircuit::::new((r1cs_path.into(), wasm_path.into(), 1, 0)).unwrap(); // state_len:1, external_inputs_len:0 @@ -249,16 +247,16 @@ pub mod tests { // Tests the WrapperCircuit with CircomFCircuit. #[test] fn test_wrapper_circomtofcircuit() { - let r1cs_path = PathBuf::from("./src/frontend/circom/test_folder/cubic_circuit.r1cs"); + let r1cs_path = PathBuf::from("./src/circom/test_folder/cubic_circuit.r1cs"); let wasm_path = - PathBuf::from("./src/frontend/circom/test_folder/cubic_circuit_js/cubic_circuit.wasm"); + PathBuf::from("./src/circom/test_folder/cubic_circuit_js/cubic_circuit.wasm"); let circom_fcircuit = CircomFCircuit::::new((r1cs_path.into(), wasm_path.into(), 1, 0)).unwrap(); // state_len:1, external_inputs_len:0 // Allocates z_i1 by using step_native function. let z_i = vec![Fr::from(3_u32)]; - let wrapper_circuit = crate::frontend::utils::WrapperCircuit { + let wrapper_circuit = folding_schemes::frontend::utils::WrapperCircuit { FC: circom_fcircuit.clone(), z_i: Some(z_i.clone()), z_i1: Some(circom_fcircuit.step_native(0, z_i.clone(), vec![]).unwrap()), @@ -275,10 +273,9 @@ pub mod tests { #[test] fn test_circom_external_inputs() { - let r1cs_path = - PathBuf::from("./src/frontend/circom/test_folder/with_external_inputs.r1cs"); + let r1cs_path = PathBuf::from("./src/circom/test_folder/with_external_inputs.r1cs"); let wasm_path = PathBuf::from( - "./src/frontend/circom/test_folder/with_external_inputs_js/with_external_inputs.wasm", + "./src/circom/test_folder/with_external_inputs_js/with_external_inputs.wasm", ); let circom_fcircuit = CircomFCircuit::::new((r1cs_path.into(), wasm_path.into(), 1, 2)).unwrap(); // state_len:1, external_inputs_len:2 @@ -320,10 +317,9 @@ pub mod tests { #[test] fn test_circom_no_external_inputs() { - let r1cs_path = PathBuf::from("./src/frontend/circom/test_folder/no_external_inputs.r1cs"); - let wasm_path = PathBuf::from( - "./src/frontend/circom/test_folder/no_external_inputs_js/no_external_inputs.wasm", - ); + let r1cs_path = PathBuf::from("./src/circom/test_folder/no_external_inputs.r1cs"); + let wasm_path = + PathBuf::from("./src/circom/test_folder/no_external_inputs_js/no_external_inputs.wasm"); let circom_fcircuit = CircomFCircuit::::new((r1cs_path.into(), wasm_path.into(), 3, 0)).unwrap(); let cs = ConstraintSystem::::new_ref(); @@ -353,9 +349,9 @@ pub mod tests { #[test] fn test_custom_code() { - let r1cs_path = PathBuf::from("./src/frontend/circom/test_folder/cubic_circuit.r1cs"); + let r1cs_path = PathBuf::from("./src/circom/test_folder/cubic_circuit.r1cs"); let wasm_path = - PathBuf::from("./src/frontend/circom/test_folder/cubic_circuit_js/cubic_circuit.wasm"); + PathBuf::from("./src/circom/test_folder/cubic_circuit_js/cubic_circuit.wasm"); let mut circom_fcircuit = CircomFCircuit::::new((r1cs_path.into(), wasm_path.into(), 1, 0)).unwrap(); // state_len:1, external_inputs_len:0 @@ -367,7 +363,7 @@ pub mod tests { // Allocates z_i1 by using step_native function. let z_i = vec![Fr::from(3_u32)]; - let wrapper_circuit = crate::frontend::utils::WrapperCircuit { + let wrapper_circuit = folding_schemes::frontend::utils::WrapperCircuit { FC: circom_fcircuit.clone(), z_i: Some(z_i.clone()), z_i1: Some(circom_fcircuit.step_native(0, z_i.clone(), vec![]).unwrap()), diff --git a/folding-schemes/src/frontend/circom/test_folder/circuits/is_zero.circom b/frontends/src/circom/test_folder/circuits/is_zero.circom similarity index 100% rename from folding-schemes/src/frontend/circom/test_folder/circuits/is_zero.circom rename to frontends/src/circom/test_folder/circuits/is_zero.circom diff --git a/frontends/src/circom/test_folder/compile.sh b/frontends/src/circom/test_folder/compile.sh new file mode 100755 index 00000000..736c06c1 --- /dev/null +++ b/frontends/src/circom/test_folder/compile.sh @@ -0,0 +1,4 @@ +#!/bin/bash +circom ./frontends/src/circom/test_folder/cubic_circuit.circom --r1cs --sym --wasm --prime bn128 --output ./frontends/src/circom/test_folder/ +circom ./frontends/src/circom/test_folder/with_external_inputs.circom --r1cs --sym --wasm --prime bn128 --output ./frontends/src/circom/test_folder/ +circom ./frontends/src/circom/test_folder/no_external_inputs.circom --r1cs --sym --wasm --prime bn128 --output ./frontends/src/circom/test_folder/ diff --git a/folding-schemes/src/frontend/circom/test_folder/cubic_circuit.circom b/frontends/src/circom/test_folder/cubic_circuit.circom similarity index 100% rename from folding-schemes/src/frontend/circom/test_folder/cubic_circuit.circom rename to frontends/src/circom/test_folder/cubic_circuit.circom diff --git a/folding-schemes/src/frontend/circom/test_folder/no_external_inputs.circom b/frontends/src/circom/test_folder/no_external_inputs.circom similarity index 100% rename from folding-schemes/src/frontend/circom/test_folder/no_external_inputs.circom rename to frontends/src/circom/test_folder/no_external_inputs.circom diff --git a/folding-schemes/src/frontend/circom/test_folder/with_external_inputs.circom b/frontends/src/circom/test_folder/with_external_inputs.circom similarity index 100% rename from folding-schemes/src/frontend/circom/test_folder/with_external_inputs.circom rename to frontends/src/circom/test_folder/with_external_inputs.circom diff --git a/folding-schemes/src/frontend/circom/utils.rs b/frontends/src/circom/utils.rs similarity index 93% rename from folding-schemes/src/frontend/circom/utils.rs rename to frontends/src/circom/utils.rs index f2c89199..19f3ea2d 100644 --- a/folding-schemes/src/frontend/circom/utils.rs +++ b/frontends/src/circom/utils.rs @@ -8,7 +8,7 @@ use color_eyre::Result; use num_bigint::{BigInt, Sign}; use std::{fs::File, io::Cursor, marker::PhantomData, path::PathBuf}; -use crate::{utils::PathOrBin, Error}; +use folding_schemes::{utils::PathOrBin, Error}; // A struct that wraps Circom functionalities, allowing for extraction of R1CS and witnesses // based on file paths to Circom's .r1cs and .wasm. @@ -134,14 +134,14 @@ mod tests { use ark_relations::r1cs::{ConstraintSynthesizer, ConstraintSystem}; //To generate .r1cs and .wasm files, run the below command in the terminal. - //bash ./folding-schemes/src/frontend/circom/test_folder/compile.sh + //bash ./frontends/src/circom/test_folder/compile.sh // Test the satisfication by using the CircomBuilder of circom-compat #[test] fn test_circombuilder_satisfied() { let cfg = CircomConfig::::new( - "./src/frontend/circom/test_folder/cubic_circuit_js/cubic_circuit.wasm", - "./src/frontend/circom/test_folder/cubic_circuit.r1cs", + "./src/circom/test_folder/cubic_circuit_js/cubic_circuit.wasm", + "./src/circom/test_folder/cubic_circuit.r1cs", ) .unwrap(); let mut builder = CircomBuilder::new(cfg); @@ -156,9 +156,9 @@ mod tests { // Test the satisfication by using the CircomWrapper #[test] fn test_extract_r1cs_and_witness() { - let r1cs_path = PathBuf::from("./src/frontend/circom/test_folder/cubic_circuit.r1cs"); + let r1cs_path = PathBuf::from("./src/circom/test_folder/cubic_circuit.r1cs"); let wasm_path = - PathBuf::from("./src/frontend/circom/test_folder/cubic_circuit_js/cubic_circuit.wasm"); + PathBuf::from("./src/circom/test_folder/cubic_circuit_js/cubic_circuit.wasm"); let inputs = vec![("ivc_input".to_string(), vec![BigInt::from(3)])]; let wrapper = CircomWrapper::::new(r1cs_path.into(), wasm_path.into()).unwrap(); diff --git a/frontends/src/lib.rs b/frontends/src/lib.rs new file mode 100644 index 00000000..f6b56f35 --- /dev/null +++ b/frontends/src/lib.rs @@ -0,0 +1,3 @@ +pub mod circom; +pub mod noir; +pub mod noname; diff --git a/folding-schemes/src/frontend/noir/mod.rs b/frontends/src/noir/mod.rs similarity index 94% rename from folding-schemes/src/frontend/noir/mod.rs rename to frontends/src/noir/mod.rs index b0910910..22d95776 100644 --- a/folding-schemes/src/frontend/noir/mod.rs +++ b/frontends/src/noir/mod.rs @@ -1,8 +1,5 @@ use std::collections::HashMap; -use crate::{utils::PathOrBin, Error}; - -use super::FCircuit; use acvm::{ acir::{ acir_field::GenericFieldElement, @@ -16,6 +13,7 @@ use ark_ff::PrimeField; use ark_r1cs_std::{alloc::AllocVar, fields::fp::FpVar, R1CSVar}; use ark_relations::r1cs::ConstraintSynthesizer; use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError}; +use folding_schemes::{frontend::FCircuit, utils::PathOrBin, Error}; use noir_arkworks_backend::{ read_program_from_binary, read_program_from_file, sonobe_bridge::AcirCircuitSonobe, }; @@ -30,7 +28,7 @@ pub struct NoirFCircuit { impl FCircuit for NoirFCircuit { type Params = (PathOrBin, usize, usize); - fn new(params: Self::Params) -> Result { + fn new(params: Self::Params) -> Result { let (source, state_len, external_inputs_len) = params; let program = match source { PathOrBin::Path(path) => read_program_from_file(path), @@ -70,7 +68,7 @@ impl FCircuit for NoirFCircuit { _i: usize, z_i: Vec, external_inputs: Vec, // inputs that are not part of the state - ) -> Result, crate::Error> { + ) -> Result, Error> { let mut acvm = ACVM::new( &StubbedBlackBoxSolver, &self.circuit.opcodes, @@ -226,20 +224,21 @@ pub fn load_noir_circuit(path: String) -> Circuit::new_ref(); let cur_path = env::current_dir().unwrap(); let circuit_path = format!( - "{}/src/frontend/noir/test_folder/test_circuit/target/test_circuit.json", + "{}/src/noir/test_folder/test_circuit/target/test_circuit.json", cur_path.to_str().unwrap() ); let circuit = load_noir_circuit(circuit_path); @@ -283,7 +282,7 @@ mod tests { let cs = ConstraintSystem::::new_ref(); let cur_path = env::current_dir().unwrap(); let circuit_path = format!( - "{}/src/frontend/noir/test_folder/test_no_external_inputs/target/test_no_external_inputs.json", + "{}/src/noir/test_folder/test_no_external_inputs/target/test_no_external_inputs.json", cur_path.to_str().unwrap() ); let circuit = load_noir_circuit(circuit_path); diff --git a/folding-schemes/src/frontend/noir/test_folder/compile.sh b/frontends/src/noir/test_folder/compile.sh similarity index 100% rename from folding-schemes/src/frontend/noir/test_folder/compile.sh rename to frontends/src/noir/test_folder/compile.sh diff --git a/folding-schemes/src/frontend/noir/test_folder/test_circuit/Nargo.toml b/frontends/src/noir/test_folder/test_circuit/Nargo.toml similarity index 100% rename from folding-schemes/src/frontend/noir/test_folder/test_circuit/Nargo.toml rename to frontends/src/noir/test_folder/test_circuit/Nargo.toml diff --git a/folding-schemes/src/frontend/noir/test_folder/test_circuit/src/main.nr b/frontends/src/noir/test_folder/test_circuit/src/main.nr similarity index 100% rename from folding-schemes/src/frontend/noir/test_folder/test_circuit/src/main.nr rename to frontends/src/noir/test_folder/test_circuit/src/main.nr diff --git a/folding-schemes/src/frontend/noir/test_folder/test_mimc/Nargo.toml b/frontends/src/noir/test_folder/test_mimc/Nargo.toml similarity index 100% rename from folding-schemes/src/frontend/noir/test_folder/test_mimc/Nargo.toml rename to frontends/src/noir/test_folder/test_mimc/Nargo.toml diff --git a/folding-schemes/src/frontend/noir/test_folder/test_mimc/src/main.nr b/frontends/src/noir/test_folder/test_mimc/src/main.nr similarity index 100% rename from folding-schemes/src/frontend/noir/test_folder/test_mimc/src/main.nr rename to frontends/src/noir/test_folder/test_mimc/src/main.nr diff --git a/folding-schemes/src/frontend/noir/test_folder/test_no_external_inputs/Nargo.toml b/frontends/src/noir/test_folder/test_no_external_inputs/Nargo.toml similarity index 100% rename from folding-schemes/src/frontend/noir/test_folder/test_no_external_inputs/Nargo.toml rename to frontends/src/noir/test_folder/test_no_external_inputs/Nargo.toml diff --git a/folding-schemes/src/frontend/noir/test_folder/test_no_external_inputs/src/main.nr b/frontends/src/noir/test_folder/test_no_external_inputs/src/main.nr similarity index 100% rename from folding-schemes/src/frontend/noir/test_folder/test_no_external_inputs/src/main.nr rename to frontends/src/noir/test_folder/test_no_external_inputs/src/main.nr diff --git a/folding-schemes/src/frontend/noname/mod.rs b/frontends/src/noname/mod.rs similarity index 97% rename from folding-schemes/src/frontend/noname/mod.rs rename to frontends/src/noname/mod.rs index 61ac1e7a..0de41ebf 100644 --- a/folding-schemes/src/frontend/noname/mod.rs +++ b/frontends/src/noname/mod.rs @@ -1,4 +1,3 @@ -use crate::Error; use ark_noname::sonobe::NonameSonobeCircuit; use ark_r1cs_std::alloc::AllocVar; use ark_r1cs_std::fields::fp::FpVar; @@ -8,9 +7,9 @@ use std::marker::PhantomData; use self::utils::NonameInputs; -use super::FCircuit; use ark_ff::PrimeField; use ark_noname::utils::compile_source_code; +use folding_schemes::{frontend::FCircuit, Error}; use noname::backends::{r1cs::R1CS as R1CSNoname, BackendField}; use noname::witness::CompiledCircuit; pub mod utils; @@ -25,7 +24,7 @@ pub struct NonameFCircuit { impl FCircuit for NonameFCircuit { type Params = (String, usize, usize); - fn new(params: Self::Params) -> Result { + fn new(params: Self::Params) -> Result { let (code, state_len, external_inputs_len) = params; let compiled_circuit = compile_source_code::(&code).map_err(|_| { Error::Other("Encountered an error while compiling a noname circuit".to_owned()) @@ -51,7 +50,7 @@ impl FCircuit for NonameFCircuit { _i: usize, z_i: Vec, external_inputs: Vec, - ) -> Result, crate::Error> { + ) -> Result, Error> { let wtns_external_inputs = NonameInputs::from((&external_inputs, "external_inputs".to_string())); let wtns_ivc_inputs = NonameInputs::from((&z_i, "ivc_inputs".to_string())); @@ -119,7 +118,7 @@ mod tests { use ark_r1cs_std::{alloc::AllocVar, fields::fp::FpVar, R1CSVar}; use noname::backends::r1cs::R1csBn254Field; - use crate::frontend::FCircuit; + use folding_schemes::frontend::FCircuit; use super::NonameFCircuit; use ark_relations::r1cs::ConstraintSystem; diff --git a/folding-schemes/src/frontend/noname/utils.rs b/frontends/src/noname/utils.rs similarity index 100% rename from folding-schemes/src/frontend/noname/utils.rs rename to frontends/src/noname/utils.rs diff --git a/solidity-verifiers/Cargo.toml b/solidity-verifiers/Cargo.toml index 907f93bf..e165016b 100644 --- a/solidity-verifiers/Cargo.toml +++ b/solidity-verifiers/Cargo.toml @@ -29,6 +29,7 @@ ark-bn254 = {version="0.4.0", features=["r1cs"]} ark-grumpkin = {version="0.4.0", features=["r1cs"]} rand = "0.8.5" folding-schemes = { path = "../folding-schemes/", features=["light-test"]} +frontends = { path = "../frontends/"} noname = { git = "https://github.com/dmpierre/noname" } [features]