diff --git a/Cargo.lock b/Cargo.lock index 36e2539b098..66dffa03c9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,21 +4,22 @@ version = 3 [[package]] name = "acir" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "084577e67b44c72d1cdfabe286d48adac6f5e0ad441ef134c5c467f4b6eee291" +checksum = "c831802bad8d6810bfdb57cd00913157dfe710a185dc360c9a94eecd043bbf12" dependencies = [ "acir_field", "flate2", "rmp-serde", "serde", + "thiserror", ] [[package]] name = "acir_field" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a267ef529f4b132293199ecdf8c232ade817f01d916039f2d34562cab39e75e9" +checksum = "d455746f51b4421548e42d34e2ce46b6db637cb048095d78766612d26bf526db" dependencies = [ "ark-bn254", "ark-ff", @@ -30,49 +31,48 @@ dependencies = [ [[package]] name = "acvm" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e1d6795105b50b13fa0dd1779b5191c4d8e9cd98b357b0b9a0b04a847baacf0" +checksum = "fd8e75cf737b52195a8c109e0ee776e468e1c2ec42f0f88aa4465cd76a09b4ed" dependencies = [ "acir", "acvm_stdlib", + "async-trait", "blake2", - "crc32fast", "indexmap", "k256", "num-bigint", "num-traits", - "sha2 0.9.9", + "sha2 0.10.6", "sha3", "thiserror", ] [[package]] name = "acvm-backend-barretenberg" -version = "0.1.2" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85bf493c97da8c528c21353452aa10f7972f4870a3aab90919bcc08ba56a8cd8" +checksum = "fa434008757491ec90e630796056de6f76114a04f533dd03c1a748c204503a31" dependencies = [ "acvm", "barretenberg-sys", - "blake2", - "dirs 3.0.2", - "futures-util", + "bincode", + "bytesize", "getrandom", - "indicatif", "pkg-config", "reqwest", "rust-embed", + "serde", + "serde-big-array", "thiserror", - "tokio", "wasmer", ] [[package]] name = "acvm_stdlib" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3131af53d17ac12340c0ff50f8555d8e040321f8078b8ee3cd8846560b6a44a9" +checksum = "a2e87549b987593eeb1902990006443f2fe5817db927035f081008e4b8a46a49" dependencies = [ "acir", ] @@ -200,7 +200,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d6873aaba7959593d89babed381d33e2329453368f1bf3c67e07686a1c1056f" dependencies = [ "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -213,7 +213,7 @@ dependencies = [ "num-traits", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -249,7 +249,7 @@ checksum = "fd34f0920d995d2c932f38861c416f70de89a6de9875876b012557079603e6cc" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -292,6 +292,17 @@ dependencies = [ "tempfile", ] +[[package]] +name = "async-trait" +version = "0.1.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.12", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -333,6 +344,15 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bindgen" version = "0.64.0" @@ -351,7 +371,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn", + "syn 1.0.109", "which", ] @@ -374,13 +394,11 @@ dependencies = [ [[package]] name = "blake2" -version = "0.9.2" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a4e37d16930f5459780f5621038b6382b9bb37c19016f39fb6b5808d831f174" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" dependencies = [ - "crypto-mac 0.8.0", - "digest 0.9.0", - "opaque-debug", + "digest 0.10.6", ] [[package]] @@ -389,7 +407,6 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "block-padding", "generic-array", ] @@ -402,12 +419,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "block-padding" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" - [[package]] name = "bstr" version = "1.4.0" @@ -456,7 +467,7 @@ checksum = "e31225543cb46f81a7e224762764f4a6a0f097b1db0b175f69e8065efaa42de5" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -471,6 +482,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +[[package]] +name = "bytesize" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38fcc2979eff34a4b84e1cf9a1e3da42a7d44b3b690a40cdcb23e3d556cfb2e5" + [[package]] name = "cc" version = "1.0.79" @@ -558,7 +575,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -626,19 +643,6 @@ dependencies = [ "tracing-error", ] -[[package]] -name = "console" -version = "0.15.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d79fbe8970a77e3e34151cc13d3b3e248aa0faaecb9f6091fa07ebefe5ad60" -dependencies = [ - "encode_unicode", - "lazy_static", - "libc", - "unicode-width", - "windows-sys 0.42.0", -] - [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -824,16 +828,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "crypto-mac" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" -dependencies = [ - "generic-array", - "subtle", -] - [[package]] name = "crypto-mac" version = "0.10.1" @@ -868,7 +862,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn", + "syn 1.0.109", ] [[package]] @@ -885,7 +879,7 @@ checksum = "0b75aed41bb2e6367cae39e6326ef817a851db13c13e4f3263714ca3cfb8de56" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -908,7 +902,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -919,7 +913,7 @@ checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" dependencies = [ "darling_core", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -939,7 +933,7 @@ checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -965,15 +959,7 @@ checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ "block-buffer 0.10.4", "crypto-common", -] - -[[package]] -name = "dirs" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30baa043103c9d0c2a57cf537cc2f35623889dc0d405e6c3cccfadbc81c71309" -dependencies = [ - "dirs-sys", + "subtle", ] [[package]] @@ -1037,12 +1023,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "encode_unicode" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" - [[package]] name = "encoding_rs" version = "0.8.32" @@ -1069,7 +1049,7 @@ checksum = "c134c37760b27a871ba422106eedbb8247da973a09e82558bf26d619c882b159" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1090,7 +1070,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1222,23 +1202,6 @@ version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd" -[[package]] -name = "futures-io" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d422fa3cbe3b40dca574ab087abb5bc98258ea57eea3fd6f1fa7162c778b91" - -[[package]] -name = "futures-macro" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "futures-sink" version = "0.3.27" @@ -1258,14 +1221,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" dependencies = [ "futures-core", - "futures-io", - "futures-macro", - "futures-sink", "futures-task", - "memchr", "pin-project-lite", "pin-utils", - "slab", ] [[package]] @@ -1448,7 +1406,7 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" dependencies = [ - "crypto-mac 0.10.1", + "crypto-mac", "digest 0.9.0", ] @@ -1597,18 +1555,6 @@ dependencies = [ "serde", ] -[[package]] -name = "indicatif" -version = "0.17.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cef509aa9bc73864d6756f0d34d35504af3cf0844373afe9b8669a5b8005a729" -dependencies = [ - "console", - "number_prefix", - "portable-atomic", - "unicode-width", -] - [[package]] name = "instant" version = "0.1.12" @@ -1771,7 +1717,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0fbfc88337168279f2e9ae06e157cfed4efd3316e14dc96ed074d4f2e6c5952" dependencies = [ "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1860,7 +1806,6 @@ name = "nargo" version = "0.6.0" dependencies = [ "acvm", - "iter-extended", "noirc_abi", "noirc_driver", "rustc_version", @@ -1882,7 +1827,7 @@ dependencies = [ "clap", "color-eyre", "const_format", - "dirs 4.0.0", + "dirs", "hex", "iter-extended", "nargo", @@ -1896,6 +1841,7 @@ dependencies = [ "tempdir", "termcolor", "thiserror", + "tokio", "toml", "url", ] @@ -2048,12 +1994,6 @@ dependencies = [ "libc", ] -[[package]] -name = "number_prefix" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" - [[package]] name = "object" version = "0.28.4" @@ -2144,12 +2084,6 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" -[[package]] -name = "portable-atomic" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26f6a7b87c2e435a3241addceeeff740ff8b7e76b74c13bf9acb17fa454ea00b" - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2207,7 +2141,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "version_check", ] @@ -2257,7 +2191,7 @@ checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2484,12 +2418,10 @@ dependencies = [ "serde_urlencoded", "tokio", "tokio-rustls", - "tokio-util", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", - "wasm-streams", "web-sys", "webpki-roots", "winreg", @@ -2532,7 +2464,7 @@ checksum = "ff26ed6c7c4dfc2aa9480b86a60e3c7233543a270a680e10758a507c5a4ce476" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2578,7 +2510,7 @@ dependencies = [ "quote", "rust-embed-utils", "shellexpand", - "syn", + "syn 1.0.109", "walkdir", ] @@ -2766,6 +2698,15 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-big-array" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11fc7cc2c76d73e0f27ee52abbd64eec84d46f370c88371120433196934e4b7f" +dependencies = [ + "serde", +] + [[package]] name = "serde_bytes" version = "0.11.9" @@ -2783,7 +2724,7 @@ checksum = "d071a94a3fac4aff69d023a7f411e33f40f3483f8c5190b1953822b6b76d7630" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2844,14 +2785,12 @@ dependencies = [ [[package]] name = "sha3" -version = "0.9.1" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" dependencies = [ - "block-buffer 0.9.0", - "digest 0.9.0", + "digest 0.10.6", "keccak", - "opaque-debug", ] [[package]] @@ -2869,7 +2808,7 @@ version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4" dependencies = [ - "dirs 4.0.0", + "dirs", ] [[package]] @@ -2984,7 +2923,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn", + "syn 1.0.109", ] [[package]] @@ -3004,6 +2943,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79d9531f94112cfc3e4c8f5f02cb2b58f72c97b7efd85f70203cc6d8efda5927" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "synstructure" version = "0.12.6" @@ -3012,7 +2962,7 @@ checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "unicode-xid", ] @@ -3077,7 +3027,7 @@ checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3218,7 +3168,7 @@ checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3391,7 +3341,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-shared", ] @@ -3425,7 +3375,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3456,19 +3406,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "wasm-streams" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bbae3363c08332cadccd13b67db371814cd214c2524020932f0804b8cf7c078" -dependencies = [ - "futures-util", - "js-sys", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", -] - [[package]] name = "wasmer" version = "2.3.0" @@ -3556,7 +3493,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3963,6 +3900,6 @@ checksum = "44bf07cb3e50ea2003396695d58bf46bc9887a1f362260446fad6bc4e79bd36c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "synstructure", -] +] \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 1b9b9d61f90..fea173505b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ edition = "2021" rust-version = "1.66" [workspace.dependencies] -acvm = "0.11.0" +acvm = "0.12.0" arena = { path = "crates/arena" } fm = { path = "crates/fm" } iter-extended = { path = "crates/iter-extended" } diff --git a/crates/nargo/Cargo.toml b/crates/nargo/Cargo.toml index 8d3c9fbd3cd..77c881835dc 100644 --- a/crates/nargo/Cargo.toml +++ b/crates/nargo/Cargo.toml @@ -14,7 +14,6 @@ rustc_version = "0.4.0" acvm.workspace = true noirc_abi.workspace = true noirc_driver.workspace = true -iter-extended.workspace = true toml.workspace = true serde.workspace = true thiserror.workspace = true diff --git a/crates/nargo/src/ops/codegen_verifier.rs b/crates/nargo/src/ops/codegen_verifier.rs index 2a0b54df865..4db3d53f7aa 100644 --- a/crates/nargo/src/ops/codegen_verifier.rs +++ b/crates/nargo/src/ops/codegen_verifier.rs @@ -2,7 +2,8 @@ use acvm::SmartContract; pub fn codegen_verifier( backend: &B, + common_reference_string: &[u8], verification_key: &[u8], ) -> Result { - backend.eth_contract_from_vk(verification_key) + backend.eth_contract_from_vk(common_reference_string, verification_key) } diff --git a/crates/nargo/src/ops/execute.rs b/crates/nargo/src/ops/execute.rs index e4c8a5afbb5..a46c440c76c 100644 --- a/crates/nargo/src/ops/execute.rs +++ b/crates/nargo/src/ops/execute.rs @@ -1,6 +1,6 @@ -use acvm::{acir::circuit::Circuit, pwg::block::Blocks}; -use acvm::{PartialWitnessGenerator, PartialWitnessGeneratorStatus}; -use noirc_abi::WitnessMap; +use acvm::pwg::{solve, PartialWitnessGeneratorStatus}; +use acvm::PartialWitnessGenerator; +use acvm::{acir::circuit::Circuit, acir::native_types::WitnessMap, pwg::block::Blocks}; use crate::NargoError; @@ -10,7 +10,7 @@ pub fn execute_circuit( mut initial_witness: WitnessMap, ) -> Result { let mut blocks = Blocks::default(); - let solver_status = backend.solve(&mut initial_witness, &mut blocks, circuit.opcodes)?; + let solver_status = solve(backend, &mut initial_witness, &mut blocks, circuit.opcodes)?; if matches!(solver_status, PartialWitnessGeneratorStatus::RequiresOracleData { .. }) { todo!("Add oracle support to nargo execute") } diff --git a/crates/nargo/src/ops/mod.rs b/crates/nargo/src/ops/mod.rs index 5d1f096ecf4..8a0cce4b8c5 100644 --- a/crates/nargo/src/ops/mod.rs +++ b/crates/nargo/src/ops/mod.rs @@ -1,6 +1,6 @@ pub use self::codegen_verifier::codegen_verifier; pub use self::execute::execute_circuit; -pub use self::preprocess::{preprocess_contract, preprocess_program}; +pub use self::preprocess::{preprocess_contract_function, preprocess_program}; pub use self::prove::prove_execution; pub use self::verify::verify_proof; diff --git a/crates/nargo/src/ops/preprocess.rs b/crates/nargo/src/ops/preprocess.rs index 3be8151f9c9..b545980b963 100644 --- a/crates/nargo/src/ops/preprocess.rs +++ b/crates/nargo/src/ops/preprocess.rs @@ -1,23 +1,21 @@ use acvm::ProofSystemCompiler; -use iter_extended::try_vecmap; -use noirc_driver::{CompiledContract, CompiledProgram}; +use noirc_driver::{CompiledProgram, ContractFunction}; -use crate::artifacts::{ - contract::{PreprocessedContract, PreprocessedContractFunction}, - program::PreprocessedProgram, -}; +use crate::artifacts::{contract::PreprocessedContractFunction, program::PreprocessedProgram}; -// TODO: pull this from backend. +// TODO(#1388): pull this from backend. const BACKEND_IDENTIFIER: &str = "acvm-backend-barretenberg"; pub fn preprocess_program( backend: &B, + common_reference_string: &[u8], compiled_program: CompiledProgram, ) -> Result { // TODO: currently `compiled_program`'s bytecode is already optimized for the backend. // In future we'll need to apply those optimizations here. let optimized_bytecode = compiled_program.circuit; - let (proving_key, verification_key) = backend.preprocess(&optimized_bytecode)?; + let (proving_key, verification_key) = + backend.preprocess(common_reference_string, &optimized_bytecode)?; Ok(PreprocessedProgram { backend: String::from(BACKEND_IDENTIFIER), @@ -28,30 +26,24 @@ pub fn preprocess_program( }) } -pub fn preprocess_contract( +pub fn preprocess_contract_function( backend: &B, - compiled_contract: CompiledContract, -) -> Result { - let preprocessed_contract_functions = try_vecmap(compiled_contract.functions, |func| { - // TODO: currently `func`'s bytecode is already optimized for the backend. - // In future we'll need to apply those optimizations here. - let optimized_bytecode = func.bytecode; - let (proving_key, verification_key) = backend.preprocess(&optimized_bytecode)?; - - Ok(PreprocessedContractFunction { - name: func.name, - function_type: func.function_type, - abi: func.abi, + common_reference_string: &[u8], + func: ContractFunction, +) -> Result { + // TODO: currently `func`'s bytecode is already optimized for the backend. + // In future we'll need to apply those optimizations here. + let optimized_bytecode = func.bytecode; + let (proving_key, verification_key) = + backend.preprocess(common_reference_string, &optimized_bytecode)?; - bytecode: optimized_bytecode, - proving_key, - verification_key, - }) - })?; + Ok(PreprocessedContractFunction { + name: func.name, + function_type: func.function_type, + abi: func.abi, - Ok(PreprocessedContract { - name: compiled_contract.name, - backend: String::from(BACKEND_IDENTIFIER), - functions: preprocessed_contract_functions, + bytecode: optimized_bytecode, + proving_key, + verification_key, }) } diff --git a/crates/nargo/src/ops/prove.rs b/crates/nargo/src/ops/prove.rs index 80771bc9cb7..e2c70739a35 100644 --- a/crates/nargo/src/ops/prove.rs +++ b/crates/nargo/src/ops/prove.rs @@ -1,12 +1,12 @@ -use acvm::acir::circuit::Circuit; +use acvm::acir::{circuit::Circuit, native_types::WitnessMap}; use acvm::ProofSystemCompiler; -use noirc_abi::WitnessMap; pub fn prove_execution( backend: &B, + common_reference_string: &[u8], circuit: &Circuit, solved_witness: WitnessMap, proving_key: &[u8], ) -> Result, B::Error> { - backend.prove_with_pk(circuit, solved_witness, proving_key) + backend.prove_with_pk(common_reference_string, circuit, solved_witness, proving_key) } diff --git a/crates/nargo/src/ops/verify.rs b/crates/nargo/src/ops/verify.rs index cd76fbd430e..1d2d3bbbd6f 100644 --- a/crates/nargo/src/ops/verify.rs +++ b/crates/nargo/src/ops/verify.rs @@ -1,13 +1,13 @@ -use acvm::acir::circuit::Circuit; +use acvm::acir::{circuit::Circuit, native_types::WitnessMap}; use acvm::ProofSystemCompiler; -use noirc_abi::WitnessMap; pub fn verify_proof( backend: &B, + common_reference_string: &[u8], circuit: &Circuit, proof: &[u8], public_inputs: WitnessMap, verification_key: &[u8], ) -> Result { - backend.verify_with_vk(proof, public_inputs, circuit, verification_key) + backend.verify_with_vk(common_reference_string, proof, public_inputs, circuit, verification_key) } diff --git a/crates/nargo_cli/Cargo.toml b/crates/nargo_cli/Cargo.toml index 74db54c8ef7..829f6498f99 100644 --- a/crates/nargo_cli/Cargo.toml +++ b/crates/nargo_cli/Cargo.toml @@ -35,9 +35,10 @@ hex = "0.4.2" serde_json = "1.0" termcolor = "1.1.2" color-eyre = "0.6.2" +tokio = "1.0" # Backends -acvm-backend-barretenberg = { version = "0.1.2", default-features = false } +acvm-backend-barretenberg = { version = "0.2.0", default-features = false } [dev-dependencies] tempdir = "0.3.7" diff --git a/crates/nargo_cli/src/cli/check_cmd.rs b/crates/nargo_cli/src/cli/check_cmd.rs index 4453616f32f..af56766cc56 100644 --- a/crates/nargo_cli/src/cli/check_cmd.rs +++ b/crates/nargo_cli/src/cli/check_cmd.rs @@ -1,4 +1,4 @@ -use crate::{errors::CliError, resolver::Resolver}; +use crate::errors::CliError; use acvm::Backend; use clap::Args; use iter_extended::btree_map; @@ -6,8 +6,8 @@ use noirc_abi::{AbiParameter, AbiType, MAIN_RETURN_NAME}; use noirc_driver::CompileOptions; use std::path::{Path, PathBuf}; -use super::fs::write_to_file; use super::NargoConfig; +use super::{compile_cmd::setup_driver, fs::write_to_file}; use crate::constants::{PROVER_INPUT_FILE, VERIFIER_INPUT_FILE}; /// Checks the constraint system for errors @@ -29,15 +29,10 @@ pub(crate) fn run( fn check_from_path>( backend: &B, - p: P, + program_dir: P, compile_options: &CompileOptions, ) -> Result<(), CliError> { - let mut driver = Resolver::resolve_root_manifest( - p.as_ref(), - backend.np_language(), - #[allow(deprecated)] - Box::new(acvm::default_is_opcode_supported(backend.np_language())), - )?; + let mut driver = setup_driver(backend, program_dir.as_ref())?; driver.check_crate(compile_options).map_err(|_| CliError::CompilationError)?; @@ -47,7 +42,7 @@ fn check_from_path>( // For now it is hard-coded to be toml. // // Check for input.toml and verifier.toml - let path_to_root = PathBuf::from(p.as_ref()); + let path_to_root = PathBuf::from(program_dir.as_ref()); let path_to_prover_input = path_to_root.join(format!("{PROVER_INPUT_FILE}.toml")); let path_to_verifier_input = path_to_root.join(format!("{VERIFIER_INPUT_FILE}.toml")); diff --git a/crates/nargo_cli/src/cli/codegen_verifier_cmd.rs b/crates/nargo_cli/src/cli/codegen_verifier_cmd.rs index d38433e2d1c..b65d64bb917 100644 --- a/crates/nargo_cli/src/cli/codegen_verifier_cmd.rs +++ b/crates/nargo_cli/src/cli/codegen_verifier_cmd.rs @@ -1,4 +1,12 @@ -use super::fs::{create_named_dir, program::read_program_from_file, write_to_file}; +use super::fs::{ + common_reference_string::{ + read_cached_common_reference_string, update_common_reference_string, + write_cached_common_reference_string, + }, + create_named_dir, + program::read_program_from_file, + write_to_file, +}; use super::NargoConfig; use crate::{ cli::compile_cmd::compile_circuit, constants::CONTRACT_DIR, constants::TARGET_DIR, @@ -29,18 +37,36 @@ pub(crate) fn run( .circuit_name .map(|circuit_name| config.program_dir.join(TARGET_DIR).join(circuit_name)); - let preprocessed_program = match circuit_build_path { - Some(circuit_build_path) => read_program_from_file(circuit_build_path)?, + let common_reference_string = read_cached_common_reference_string(); + + let (common_reference_string, preprocessed_program) = match circuit_build_path { + Some(circuit_build_path) => { + let program = read_program_from_file(circuit_build_path)?; + let common_reference_string = update_common_reference_string( + backend, + &common_reference_string, + &program.bytecode, + ) + .map_err(CliError::CommonReferenceStringError)?; + (common_reference_string, program) + } None => { - let compiled_program = + let program = compile_circuit(backend, config.program_dir.as_ref(), &args.compile_options)?; - preprocess_program(backend, compiled_program) - .map_err(CliError::ProofSystemCompilerError)? + let common_reference_string = + update_common_reference_string(backend, &common_reference_string, &program.circuit) + .map_err(CliError::CommonReferenceStringError)?; + let program = preprocess_program(backend, &common_reference_string, program) + .map_err(CliError::ProofSystemCompilerError)?; + (common_reference_string, program) } }; - let smart_contract_string = codegen_verifier(backend, &preprocessed_program.verification_key) - .map_err(CliError::SmartContractError)?; + let smart_contract_string = + codegen_verifier(backend, &common_reference_string, &preprocessed_program.verification_key) + .map_err(CliError::SmartContractError)?; + + write_cached_common_reference_string(&common_reference_string); let contract_dir = config.program_dir.join(CONTRACT_DIR); create_named_dir(&contract_dir, "contract"); diff --git a/crates/nargo_cli/src/cli/compile_cmd.rs b/crates/nargo_cli/src/cli/compile_cmd.rs index fbdc9330da8..d2b5532cf24 100644 --- a/crates/nargo_cli/src/cli/compile_cmd.rs +++ b/crates/nargo_cli/src/cli/compile_cmd.rs @@ -1,18 +1,28 @@ use acvm::Backend; use iter_extended::try_vecmap; +use nargo::artifacts::contract::PreprocessedContract; use noirc_driver::{CompileOptions, CompiledProgram, Driver}; use std::path::Path; use clap::Args; -use nargo::ops::{preprocess_contract, preprocess_program}; +use nargo::ops::{preprocess_contract_function, preprocess_program}; use crate::resolver::DependencyResolutionError; use crate::{constants::TARGET_DIR, errors::CliError, resolver::Resolver}; -use super::fs::program::{save_contract_to_file, save_program_to_file}; +use super::fs::{ + common_reference_string::{ + read_cached_common_reference_string, update_common_reference_string, + write_cached_common_reference_string, + }, + program::{save_contract_to_file, save_program_to_file}, +}; use super::NargoConfig; +// TODO(#1388): pull this from backend. +const BACKEND_IDENTIFIER: &str = "acvm-backend-barretenberg"; + /// Compile the program and its secret execution trace into ACIR format #[derive(Debug, Clone, Args)] pub(crate) struct CompileCommand { @@ -34,16 +44,40 @@ pub(crate) fn run( ) -> Result<(), CliError> { let circuit_dir = config.program_dir.join(TARGET_DIR); + let mut common_reference_string = read_cached_common_reference_string(); + // If contracts is set we're compiling every function in a 'contract' rather than just 'main'. if args.contracts { let mut driver = setup_driver(backend, &config.program_dir)?; let compiled_contracts = driver .compile_contracts(&args.compile_options) .map_err(|_| CliError::CompilationError)?; - let preprocessed_contracts = try_vecmap(compiled_contracts, |contract| { - preprocess_contract(backend, contract).map_err(CliError::ProofSystemCompilerError) - })?; - for contract in preprocessed_contracts { + + // TODO(#1389): I wonder if it is incorrect for nargo-core to know anything about contracts. + // As can be seen here, It seems like a leaky abstraction where ContractFunctions (essentially CompiledPrograms) + // are compiled via nargo-core and then the PreprocessedContract is constructed here. + // This is due to EACH function needing it's own CRS, PKey, and VKey from the backend. + let preprocessed_contracts: Result, CliError> = + try_vecmap(compiled_contracts, |contract| { + let preprocessed_contract_functions = try_vecmap(contract.functions, |func| { + common_reference_string = update_common_reference_string( + backend, + &common_reference_string, + &func.bytecode, + ) + .map_err(CliError::CommonReferenceStringError)?; + + preprocess_contract_function(backend, &common_reference_string, func) + .map_err(CliError::ProofSystemCompilerError) + })?; + + Ok(PreprocessedContract { + name: contract.name, + backend: String::from(BACKEND_IDENTIFIER), + functions: preprocessed_contract_functions, + }) + }); + for contract in preprocessed_contracts? { save_contract_to_file( &contract, &format!("{}-{}", &args.circuit_name, contract.name), @@ -52,22 +86,29 @@ pub(crate) fn run( } } else { let program = compile_circuit(backend, &config.program_dir, &args.compile_options)?; - let preprocessed_program = - preprocess_program(backend, program).map_err(CliError::ProofSystemCompilerError)?; + common_reference_string = + update_common_reference_string(backend, &common_reference_string, &program.circuit) + .map_err(CliError::CommonReferenceStringError)?; + + let preprocessed_program = preprocess_program(backend, &common_reference_string, program) + .map_err(CliError::ProofSystemCompilerError)?; save_program_to_file(&preprocessed_program, &args.circuit_name, circuit_dir); } + + write_cached_common_reference_string(&common_reference_string); + Ok(()) } -fn setup_driver( +pub(super) fn setup_driver( backend: &B, program_dir: &Path, ) -> Result { Resolver::resolve_root_manifest( program_dir, backend.np_language(), - #[allow(deprecated)] - Box::new(acvm::default_is_opcode_supported(backend.np_language())), + // TODO(#1102): Remove need for driver to be aware of backend. + Box::new(|op| B::default().supports_opcode(op)), ) } diff --git a/crates/nargo_cli/src/cli/execute_cmd.rs b/crates/nargo_cli/src/cli/execute_cmd.rs index 855fea04cb3..61e709ce500 100644 --- a/crates/nargo_cli/src/cli/execute_cmd.rs +++ b/crates/nargo_cli/src/cli/execute_cmd.rs @@ -1,10 +1,10 @@ use std::path::Path; -use acvm::acir::circuit::Circuit; +use acvm::acir::{circuit::Circuit, native_types::WitnessMap}; use acvm::Backend; use clap::Args; use noirc_abi::input_parser::{Format, InputValue}; -use noirc_abi::{Abi, InputMap, WitnessMap}; +use noirc_abi::{Abi, InputMap}; use noirc_driver::{CompileOptions, CompiledProgram}; use super::fs::{inputs::read_inputs_from_file, witness::save_witness_to_dir}; diff --git a/crates/nargo_cli/src/cli/fs/common_reference_string.rs b/crates/nargo_cli/src/cli/fs/common_reference_string.rs new file mode 100644 index 00000000000..a22c819d402 --- /dev/null +++ b/crates/nargo_cli/src/cli/fs/common_reference_string.rs @@ -0,0 +1,55 @@ +use std::{env, path::PathBuf}; + +use acvm::{acir::circuit::Circuit, CommonReferenceString}; + +use super::{create_named_dir, write_to_file}; + +// TODO(#1388): pull this from backend. +const BACKEND_IDENTIFIER: &str = "acvm-backend-barretenberg"; +const TRANSCRIPT_NAME: &str = "common-reference-string.bin"; + +fn common_reference_string_location() -> PathBuf { + let cache_dir = match env::var("NARGO_BACKEND_CACHE_DIR") { + Ok(cache_dir) => PathBuf::from(cache_dir), + Err(_) => dirs::home_dir().unwrap().join(".nargo").join("backends"), + }; + cache_dir.join(BACKEND_IDENTIFIER).join(TRANSCRIPT_NAME) +} + +pub(crate) fn read_cached_common_reference_string() -> Vec { + let crs_path = common_reference_string_location(); + + // TODO(#1390): Implement checksum + match std::fs::read(crs_path) { + Ok(common_reference_string) => common_reference_string, + Err(_) => vec![], + } +} + +pub(crate) fn update_common_reference_string( + backend: &B, + common_reference_string: &[u8], + circuit: &Circuit, +) -> Result, B::Error> { + use tokio::runtime::Builder; + + let runtime = Builder::new_current_thread().enable_all().build().unwrap(); + + // TODO(#1391): Implement retries + // If the read data is empty, we don't have a CRS and need to generate one + let fut = if common_reference_string.is_empty() { + backend.generate_common_reference_string(circuit) + } else { + backend.update_common_reference_string(common_reference_string.to_vec(), circuit) + }; + + runtime.block_on(fut) +} + +pub(crate) fn write_cached_common_reference_string(common_reference_string: &[u8]) { + let crs_path = common_reference_string_location(); + + create_named_dir(crs_path.parent().unwrap(), "crs"); + + write_to_file(common_reference_string, &crs_path); +} diff --git a/crates/nargo_cli/src/cli/fs/mod.rs b/crates/nargo_cli/src/cli/fs/mod.rs index 4ebce3b3325..73229e0476c 100644 --- a/crates/nargo_cli/src/cli/fs/mod.rs +++ b/crates/nargo_cli/src/cli/fs/mod.rs @@ -6,6 +6,7 @@ use std::{ use crate::errors::FilesystemError; +pub(super) mod common_reference_string; pub(super) mod inputs; pub(super) mod program; pub(super) mod proof; diff --git a/crates/nargo_cli/src/cli/fs/witness.rs b/crates/nargo_cli/src/cli/fs/witness.rs index d41123e74fa..3b2ca2aab9f 100644 --- a/crates/nargo_cli/src/cli/fs/witness.rs +++ b/crates/nargo_cli/src/cli/fs/witness.rs @@ -1,7 +1,6 @@ use std::path::{Path, PathBuf}; -use acvm::acir::native_types::Witness; -use noirc_abi::WitnessMap; +use acvm::acir::native_types::WitnessMap; use super::{create_named_dir, write_to_file}; use crate::{constants::WITNESS_EXT, errors::FilesystemError}; @@ -14,7 +13,7 @@ pub(crate) fn save_witness_to_dir>( create_named_dir(witness_dir.as_ref(), "witness"); let witness_path = witness_dir.as_ref().join(witness_name).with_extension(WITNESS_EXT); - let buf = Witness::to_bytes(&witness); + let buf: Vec = witness.try_into()?; write_to_file(buf.as_slice(), &witness_path); diff --git a/crates/nargo_cli/src/cli/prove_cmd.rs b/crates/nargo_cli/src/cli/prove_cmd.rs index d2adc8d4af1..1238dbd9f8e 100644 --- a/crates/nargo_cli/src/cli/prove_cmd.rs +++ b/crates/nargo_cli/src/cli/prove_cmd.rs @@ -11,6 +11,10 @@ use super::NargoConfig; use super::{ compile_cmd::compile_circuit, fs::{ + common_reference_string::{ + read_cached_common_reference_string, update_common_reference_string, + write_cached_common_reference_string, + }, inputs::{read_inputs_from_file, write_inputs_to_file}, program::read_program_from_file, proof::save_proof_to_dir, @@ -72,15 +76,32 @@ pub(crate) fn prove_with_path>( check_proof: bool, compile_options: &CompileOptions, ) -> Result, CliError> { - let preprocessed_program = match circuit_build_path { - Some(circuit_build_path) => read_program_from_file(circuit_build_path)?, + let common_reference_string = read_cached_common_reference_string(); + + let (common_reference_string, preprocessed_program) = match circuit_build_path { + Some(circuit_build_path) => { + let program = read_program_from_file(circuit_build_path)?; + let common_reference_string = update_common_reference_string( + backend, + &common_reference_string, + &program.bytecode, + ) + .map_err(CliError::CommonReferenceStringError)?; + (common_reference_string, program) + } None => { - let compiled_program = compile_circuit(backend, program_dir.as_ref(), compile_options)?; - preprocess_program(backend, compiled_program) - .map_err(CliError::ProofSystemCompilerError)? + let program = compile_circuit(backend, program_dir.as_ref(), compile_options)?; + let common_reference_string = + update_common_reference_string(backend, &common_reference_string, &program.circuit) + .map_err(CliError::CommonReferenceStringError)?; + let program = preprocess_program(backend, &common_reference_string, program) + .map_err(CliError::ProofSystemCompilerError)?; + (common_reference_string, program) } }; + write_cached_common_reference_string(&common_reference_string); + let PreprocessedProgram { abi, bytecode, proving_key, verification_key, .. } = preprocessed_program; @@ -102,14 +123,21 @@ pub(crate) fn prove_with_path>( Format::Toml, )?; - let proof = prove_execution(backend, &bytecode, solved_witness, &proving_key) - .map_err(CliError::ProofSystemCompilerError)?; + let proof = + prove_execution(backend, &common_reference_string, &bytecode, solved_witness, &proving_key) + .map_err(CliError::ProofSystemCompilerError)?; if check_proof { let public_inputs = public_abi.encode(&public_inputs, return_value)?; - let valid_proof = - verify_proof(backend, &bytecode, &proof, public_inputs, &verification_key) - .map_err(CliError::ProofSystemCompilerError)?; + let valid_proof = verify_proof( + backend, + &common_reference_string, + &bytecode, + &proof, + public_inputs, + &verification_key, + ) + .map_err(CliError::ProofSystemCompilerError)?; if !valid_proof { return Err(CliError::InvalidProof("".into())); diff --git a/crates/nargo_cli/src/cli/test_cmd.rs b/crates/nargo_cli/src/cli/test_cmd.rs index 024eaa20600..e4fadfa41c5 100644 --- a/crates/nargo_cli/src/cli/test_cmd.rs +++ b/crates/nargo_cli/src/cli/test_cmd.rs @@ -1,13 +1,13 @@ -use std::{collections::BTreeMap, io::Write, path::Path}; +use std::{io::Write, path::Path}; -use acvm::Backend; +use acvm::{acir::native_types::WitnessMap, Backend}; use clap::Args; use nargo::ops::execute_circuit; use noirc_driver::{CompileOptions, Driver}; use noirc_frontend::node_interner::FuncId; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; -use crate::{errors::CliError, resolver::Resolver}; +use crate::{cli::compile_cmd::setup_driver, errors::CliError}; use super::NargoConfig; @@ -37,12 +37,7 @@ fn run_tests( test_name: &str, compile_options: &CompileOptions, ) -> Result<(), CliError> { - let mut driver = Resolver::resolve_root_manifest( - program_dir, - backend.np_language(), - #[allow(deprecated)] - Box::new(acvm::default_is_opcode_supported(backend.np_language())), - )?; + let mut driver = setup_driver(backend, program_dir)?; driver.check_crate(compile_options).map_err(|_| CliError::CompilationError)?; @@ -94,7 +89,7 @@ fn run_test( // Run the backend to ensure the PWG evaluates functions like std::hash::pedersen, // otherwise constraints involving these expressions will not error. - match execute_circuit(backend, program.circuit, BTreeMap::new()) { + match execute_circuit(backend, program.circuit, WitnessMap::new()) { Ok(_) => Ok(()), Err(error) => { let writer = StandardStream::stderr(ColorChoice::Always); diff --git a/crates/nargo_cli/src/cli/verify_cmd.rs b/crates/nargo_cli/src/cli/verify_cmd.rs index 07ba12d3899..26eb39f3f81 100644 --- a/crates/nargo_cli/src/cli/verify_cmd.rs +++ b/crates/nargo_cli/src/cli/verify_cmd.rs @@ -1,5 +1,13 @@ use super::compile_cmd::compile_circuit; -use super::fs::{inputs::read_inputs_from_file, load_hex_data, program::read_program_from_file}; +use super::fs::{ + common_reference_string::{ + read_cached_common_reference_string, update_common_reference_string, + write_cached_common_reference_string, + }, + inputs::read_inputs_from_file, + load_hex_data, + program::read_program_from_file, +}; use super::NargoConfig; use crate::{ constants::{PROOFS_DIR, PROOF_EXT, TARGET_DIR, VERIFIER_INPUT_FILE}, @@ -9,7 +17,7 @@ use crate::{ use acvm::Backend; use clap::Args; use nargo::artifacts::program::PreprocessedProgram; -use nargo::ops::preprocess_program; +use nargo::ops::{preprocess_program, verify_proof}; use noirc_abi::input_parser::Format; use noirc_driver::CompileOptions; use std::path::{Path, PathBuf}; @@ -44,7 +52,7 @@ pub(crate) fn run( &config.program_dir, proof_path, circuit_build_path.as_ref(), - args.compile_options, + &args.compile_options, ) } @@ -53,18 +61,34 @@ fn verify_with_path>( program_dir: P, proof_path: PathBuf, circuit_build_path: Option

, - compile_options: CompileOptions, + compile_options: &CompileOptions, ) -> Result<(), CliError> { - let preprocessed_program = match circuit_build_path { - Some(circuit_build_path) => read_program_from_file(circuit_build_path)?, + let common_reference_string = read_cached_common_reference_string(); + + let (common_reference_string, preprocessed_program) = match circuit_build_path { + Some(circuit_build_path) => { + let program = read_program_from_file(circuit_build_path)?; + let common_reference_string = update_common_reference_string( + backend, + &common_reference_string, + &program.bytecode, + ) + .map_err(CliError::CommonReferenceStringError)?; + (common_reference_string, program) + } None => { - let compiled_program = - compile_circuit(backend, program_dir.as_ref(), &compile_options)?; - preprocess_program(backend, compiled_program) - .map_err(CliError::ProofSystemCompilerError)? + let program = compile_circuit(backend, program_dir.as_ref(), compile_options)?; + let common_reference_string = + update_common_reference_string(backend, &common_reference_string, &program.circuit) + .map_err(CliError::CommonReferenceStringError)?; + let program = preprocess_program(backend, &common_reference_string, program) + .map_err(CliError::ProofSystemCompilerError)?; + (common_reference_string, program) } }; + write_cached_common_reference_string(&common_reference_string); + let PreprocessedProgram { abi, bytecode, verification_key, .. } = preprocessed_program; // Load public inputs (if any) from `VERIFIER_INPUT_FILE`. @@ -75,9 +99,15 @@ fn verify_with_path>( let public_inputs = public_abi.encode(&public_inputs_map, return_value)?; let proof = load_hex_data(&proof_path)?; - let valid_proof = - nargo::ops::verify_proof(backend, &bytecode, &proof, public_inputs, &verification_key) - .map_err(CliError::ProofSystemCompilerError)?; + let valid_proof = verify_proof( + backend, + &common_reference_string, + &bytecode, + &proof, + public_inputs, + &verification_key, + ) + .map_err(CliError::ProofSystemCompilerError)?; if valid_proof { Ok(()) diff --git a/crates/nargo_cli/src/errors.rs b/crates/nargo_cli/src/errors.rs index 15d1917a5d6..02bc5b031a9 100644 --- a/crates/nargo_cli/src/errors.rs +++ b/crates/nargo_cli/src/errors.rs @@ -1,4 +1,7 @@ -use acvm::{Backend, ProofSystemCompiler, SmartContract}; +use acvm::{ + acir::native_types::WitnessMapError, Backend, CommonReferenceString, ProofSystemCompiler, + SmartContract, +}; use hex::FromHexError; use nargo::NargoError; use noirc_abi::errors::{AbiError, InputParserError}; @@ -21,6 +24,10 @@ pub(crate) enum FilesystemError { /// Input parsing error #[error(transparent)] InputParserError(#[from] InputParserError), + + /// WitnessMap serialization error + #[error(transparent)] + WitnessMapSerialization(#[from] WitnessMapError), } #[derive(Debug, Error)] @@ -59,4 +66,8 @@ pub(crate) enum CliError { /// Backend error caused by a function on the ProofSystemCompiler trait #[error(transparent)] ProofSystemCompilerError(::Error), // Unfortunately, Rust won't let us `impl From` over an Associated Type on a generic + + /// Backend error caused by a function on the CommonReferenceString trait + #[error(transparent)] + CommonReferenceStringError(::Error), // Unfortunately, Rust won't let us `impl From` over an Associated Type on a generic } diff --git a/crates/noirc_abi/src/lib.rs b/crates/noirc_abi/src/lib.rs index 191128b9407..56ed3728527 100644 --- a/crates/noirc_abi/src/lib.rs +++ b/crates/noirc_abi/src/lib.rs @@ -5,7 +5,10 @@ use std::{collections::BTreeMap, str}; -use acvm::{acir::native_types::Witness, FieldElement}; +use acvm::{ + acir::native_types::{Witness, WitnessMap}, + FieldElement, +}; use errors::AbiError; use input_parser::InputValue; use iter_extended::{try_btree_map, try_vecmap, vecmap}; @@ -22,9 +25,6 @@ mod serialization; /// A map from the fields in an TOML/JSON file which correspond to some ABI to their values pub type InputMap = BTreeMap; -/// A map from the witnesses in a constraint system to the field element values -pub type WitnessMap = BTreeMap; - /// A tuple of the arguments to a function along with its return value. pub type FunctionSignature = (Vec, Option); @@ -254,7 +254,7 @@ impl Abi { .collect::>()?; // Write input field elements into witness indices specified in `self.param_witnesses`. - let mut witness_map: WitnessMap = encoded_input_map + let mut witness_map: BTreeMap = encoded_input_map .iter() .flat_map(|(param_name, encoded_param_fields)| { let param_witness_indices = &self.param_witnesses[param_name]; @@ -297,7 +297,7 @@ impl Abi { (_, None) => {} } - Ok(witness_map) + Ok(witness_map.into()) } fn encode_value(value: InputValue) -> Result, AbiError> { diff --git a/crates/noirc_driver/src/lib.rs b/crates/noirc_driver/src/lib.rs index 6adf8d64f0c..86fea37c5fc 100644 --- a/crates/noirc_driver/src/lib.rs +++ b/crates/noirc_driver/src/lib.rs @@ -6,7 +6,6 @@ use acvm::acir::circuit::Opcode; use acvm::Language; use clap::Args; -use contract::ContractFunction; use fm::FileType; use iter_extended::try_vecmap; use noirc_abi::FunctionSignature; @@ -23,14 +22,12 @@ use std::path::{Path, PathBuf}; mod contract; mod program; -pub use contract::{CompiledContract, ContractFunctionType}; +pub use contract::{CompiledContract, ContractFunction, ContractFunctionType}; pub use program::CompiledProgram; pub struct Driver { context: Context, language: Language, - // We retain this as we need to pass this into `create_circuit` once signature is updated to allow. - #[allow(dead_code)] is_opcode_supported: Box bool>, } @@ -287,14 +284,12 @@ impl Driver { let program = monomorphize(main_function, &self.context.def_interner); let np_language = self.language.clone(); - // TODO: use proper `is_opcode_supported` implementation. - let is_opcode_supported = acvm::default_is_opcode_supported(np_language.clone()); let circuit_abi = if options.experimental_ssa { experimental_create_circuit( program, np_language, - is_opcode_supported, + &self.is_opcode_supported, options.show_ssa, options.show_output, ) @@ -302,7 +297,7 @@ impl Driver { create_circuit( program, np_language, - is_opcode_supported, + &self.is_opcode_supported, options.show_ssa, options.show_output, ) diff --git a/crates/noirc_evaluator/src/lib.rs b/crates/noirc_evaluator/src/lib.rs index 533adce4325..506b0c2ceba 100644 --- a/crates/noirc_evaluator/src/lib.rs +++ b/crates/noirc_evaluator/src/lib.rs @@ -13,7 +13,7 @@ pub mod ssa_refactor; use acvm::{ acir::circuit::{opcodes::Opcode as AcirOpcode, Circuit, PublicInputs}, acir::native_types::{Expression, Witness}, - compiler::transformers::IsOpcodeSupported, + compiler::optimizers::simplify::CircuitSimplifier, Language, }; use errors::{RuntimeError, RuntimeErrorKind}; @@ -66,7 +66,7 @@ pub struct Evaluator { pub fn create_circuit( program: Program, np_language: Language, - is_opcode_supported: IsOpcodeSupported, + is_opcode_supported: &impl Fn(&AcirOpcode) -> bool, enable_logging: bool, show_output: bool, ) -> Result<(Circuit, Abi), RuntimeError> { @@ -83,6 +83,7 @@ pub fn create_circuit( opcodes, .. } = evaluator; + let simplifier = CircuitSimplifier::new(current_witness_index); let optimized_circuit = acvm::compiler::compile( Circuit { current_witness_index, @@ -92,6 +93,7 @@ pub fn create_circuit( }, np_language, is_opcode_supported, + &simplifier, ) .map_err(|_| RuntimeErrorKind::Spanless(String::from("produced an acvm compile error")))?; diff --git a/crates/noirc_evaluator/src/ssa/acir_gen/constraints.rs b/crates/noirc_evaluator/src/ssa/acir_gen/constraints.rs index 0f8ad42620d..0900c34ce36 100644 --- a/crates/noirc_evaluator/src/ssa/acir_gen/constraints.rs +++ b/crates/noirc_evaluator/src/ssa/acir_gen/constraints.rs @@ -6,7 +6,7 @@ use crate::{ use acvm::{ acir::{ circuit::{ - directives::Directive, + directives::{Directive, QuotientDirective}, opcodes::{BlackBoxFuncCall, FunctionInput, Opcode as AcirOpcode}, }, native_types::{Expression, Witness}, @@ -265,13 +265,13 @@ pub(crate) fn range_constraint( let b_witness = evaluator.add_witness_to_cs(); let exp_big = BigUint::from(2_u128).pow(num_bits - 1); let exp = FieldElement::from_be_bytes_reduce(&exp_big.to_bytes_be()); - evaluator.push_opcode(AcirOpcode::Directive(Directive::Quotient { + evaluator.push_opcode(AcirOpcode::Directive(Directive::Quotient(QuotientDirective { a: Expression::from(witness), b: Expression::from_field(exp), q: b_witness, r: r_witness, predicate: None, - })); + }))); try_range_constraint(r_witness, num_bits - 1, evaluator); try_range_constraint(b_witness, 1, evaluator); @@ -283,10 +283,8 @@ pub(crate) fn range_constraint( let my_constraint = add(&res, -FieldElement::one(), &witness.into()); evaluator.push_opcode(AcirOpcode::Arithmetic(my_constraint)); } else { - let gate = AcirOpcode::BlackBoxFuncCall(BlackBoxFuncCall { - name: acvm::acir::BlackBoxFunc::RANGE, - inputs: vec![FunctionInput { witness, num_bits }], - outputs: vec![], + let gate = AcirOpcode::BlackBoxFuncCall(BlackBoxFuncCall::RANGE { + input: FunctionInput { witness, num_bits }, }); evaluator.push_opcode(gate); } @@ -311,13 +309,13 @@ pub(crate) fn bound_check( //2^s+a-b=q*2^s +r let expr = add(&r_witness.into(), two_s, &q_witness.into()); evaluator.push_opcode(AcirOpcode::Arithmetic(subtract(&sub, FieldElement::one(), &expr))); - evaluator.push_opcode(AcirOpcode::Directive(Directive::Quotient { + evaluator.push_opcode(AcirOpcode::Directive(Directive::Quotient(QuotientDirective { a: sub, b: Expression::from_field(two_s), q: q_witness, r: r_witness, predicate: None, - })); + }))); try_range_constraint(r_witness, max_bits, evaluator); evaluator.push_opcode(AcirOpcode::Arithmetic(boolean(q_witness))); q_witness @@ -522,13 +520,13 @@ pub(crate) fn evaluate_truncate( //1. Generate witnesses a,b,c let b_witness = evaluator.add_witness_to_cs(); let c_witness = evaluator.add_witness_to_cs(); - evaluator.push_opcode(AcirOpcode::Directive(Directive::Quotient { + evaluator.push_opcode(AcirOpcode::Directive(Directive::Quotient(QuotientDirective { a: lhs.clone(), b: Expression::from_field(exp), q: c_witness, r: b_witness, predicate: None, - })); + }))); try_range_constraint(b_witness, rhs, evaluator); //TODO propagate the error using ? try_range_constraint(c_witness, max_bits - rhs, evaluator); @@ -567,13 +565,13 @@ pub(crate) fn evaluate_constant_modulo( //1. Generate witnesses b,c let b_witness = evaluator.add_witness_to_cs(); let c_witness = evaluator.add_witness_to_cs(); - evaluator.push_opcode(AcirOpcode::Directive(Directive::Quotient { + evaluator.push_opcode(AcirOpcode::Directive(Directive::Quotient(QuotientDirective { a: lhs.clone(), b: modulus_exp.clone(), q: c_witness, r: b_witness, predicate: None, - })); + }))); bound_constraint_with_offset( &Expression::from(b_witness), &modulus_exp, @@ -608,13 +606,13 @@ pub(crate) fn evaluate_udiv( let q_witness = evaluator.add_witness_to_cs(); let r_witness = evaluator.add_witness_to_cs(); let pa = mul_with_witness(evaluator, lhs, predicate); - evaluator.push_opcode(AcirOpcode::Directive(Directive::Quotient { + evaluator.push_opcode(AcirOpcode::Directive(Directive::Quotient(QuotientDirective { a: lhs.clone(), b: rhs.clone(), q: q_witness, r: r_witness, predicate: Some(predicate.clone()), - })); + }))); //r acvm::acir::BlackBoxFunc::AND, - BinaryOp::Xor => acvm::acir::BlackBoxFunc::XOR, + let gate = match opcode { + BinaryOp::And => AcirOpcode::BlackBoxFuncCall(BlackBoxFuncCall::AND { + lhs: FunctionInput { witness: a_witness, num_bits: bit_size }, + rhs: FunctionInput { witness: b_witness, num_bits: bit_size }, + output: result, + }), + BinaryOp::Xor => AcirOpcode::BlackBoxFuncCall(BlackBoxFuncCall::XOR { + lhs: FunctionInput { witness: a_witness, num_bits: bit_size }, + rhs: FunctionInput { witness: b_witness, num_bits: bit_size }, + output: result, + }), BinaryOp::Or => { a_witness = evaluator.create_intermediate_variable(constraints::subtract( &Expression::from_field(max), @@ -136,19 +144,15 @@ pub(super) fn evaluate_bitwise( &Expression::from(b_witness), )); // We do not have an OR gate yet, so we use the AND gate - acvm::acir::BlackBoxFunc::AND + AcirOpcode::BlackBoxFuncCall(BlackBoxFuncCall::AND { + lhs: FunctionInput { witness: a_witness, num_bits: bit_size }, + rhs: FunctionInput { witness: b_witness, num_bits: bit_size }, + output: result, + }) } _ => unreachable!("ICE: expected a bitwise operation"), }; - let gate = AcirOpcode::BlackBoxFuncCall(BlackBoxFuncCall { - name: bit_gate, - inputs: vec![ - FunctionInput { witness: a_witness, num_bits: bit_size }, - FunctionInput { witness: b_witness, num_bits: bit_size }, - ], - outputs: vec![result], - }); evaluator.opcodes.push(gate); if opcode == BinaryOp::Or { diff --git a/crates/noirc_evaluator/src/ssa/acir_gen/operations/intrinsics.rs b/crates/noirc_evaluator/src/ssa/acir_gen/operations/intrinsics.rs index ea7d3d9c6c0..01d5fecc897 100644 --- a/crates/noirc_evaluator/src/ssa/acir_gen/operations/intrinsics.rs +++ b/crates/noirc_evaluator/src/ssa/acir_gen/operations/intrinsics.rs @@ -7,7 +7,7 @@ use crate::{ }, builtin, context::SsaContext, - mem::{ArrayId, Memory}, + mem::Memory, node::{self, Instruction, Node, NodeId, ObjectType}, }, Evaluator, @@ -19,6 +19,7 @@ use acvm::{ opcodes::{BlackBoxFuncCall, FunctionInput, Opcode as AcirOpcode}, }, native_types::{Expression, Witness}, + BlackBoxFunc, }, FieldElement, }; @@ -79,15 +80,70 @@ pub(crate) fn evaluate( } } Opcode::LowLevel(op) => { - let inputs = prepare_inputs(acir_gen, args, ctx, evaluator); - let output_count = op.definition().output_size.0 as u32; - outputs = - prepare_outputs(&mut acir_gen.memory, instruction_id, output_count, ctx, evaluator); - - let func_call = BlackBoxFuncCall { - name: op, - inputs, //witness + bit size - outputs: outputs.clone(), //witness + outputs = match op { + BlackBoxFunc::SHA256 | BlackBoxFunc::Blake2s => { + prepare_outputs(&mut acir_gen.memory, instruction_id, 32, ctx, evaluator) + } + BlackBoxFunc::Keccak256 => { + prepare_outputs(&mut acir_gen.memory, instruction_id, 32, ctx, evaluator) + } + BlackBoxFunc::Pedersen | BlackBoxFunc::FixedBaseScalarMul => { + prepare_outputs(&mut acir_gen.memory, instruction_id, 2, ctx, evaluator) + } + BlackBoxFunc::SchnorrVerify + | BlackBoxFunc::EcdsaSecp256k1 + | BlackBoxFunc::ComputeMerkleRoot + | BlackBoxFunc::HashToField128Security => { + prepare_outputs(&mut acir_gen.memory, instruction_id, 1, ctx, evaluator) + } + _ => panic!("Unsupported low level function {:?}", op), + }; + let func_call = match op { + BlackBoxFunc::SHA256 => BlackBoxFuncCall::SHA256 { + inputs: resolve_array(&args[0], acir_gen, ctx, evaluator), + outputs: outputs.to_vec(), + }, + BlackBoxFunc::Blake2s => BlackBoxFuncCall::Blake2s { + inputs: resolve_array(&args[0], acir_gen, ctx, evaluator), + outputs: outputs.to_vec(), + }, + BlackBoxFunc::Keccak256 => BlackBoxFuncCall::Keccak256 { + inputs: resolve_array(&args[0], acir_gen, ctx, evaluator), + outputs: outputs.to_vec(), + }, + BlackBoxFunc::Pedersen => BlackBoxFuncCall::Pedersen { + inputs: resolve_array(&args[0], acir_gen, ctx, evaluator), + outputs: outputs.to_vec(), + }, + BlackBoxFunc::FixedBaseScalarMul => BlackBoxFuncCall::FixedBaseScalarMul { + input: resolve_variable(&args[0], acir_gen, ctx, evaluator).unwrap(), + outputs: outputs.to_vec(), + }, + BlackBoxFunc::SchnorrVerify => BlackBoxFuncCall::SchnorrVerify { + public_key_x: resolve_variable(&args[0], acir_gen, ctx, evaluator).unwrap(), + public_key_y: resolve_variable(&args[1], acir_gen, ctx, evaluator).unwrap(), + signature: resolve_array(&args[2], acir_gen, ctx, evaluator), + message: resolve_array(&args[3], acir_gen, ctx, evaluator), + output: outputs[0], + }, + BlackBoxFunc::EcdsaSecp256k1 => BlackBoxFuncCall::EcdsaSecp256k1 { + public_key_x: resolve_array(&args[0], acir_gen, ctx, evaluator), + public_key_y: resolve_array(&args[1], acir_gen, ctx, evaluator), + signature: resolve_array(&args[2], acir_gen, ctx, evaluator), + hashed_message: resolve_array(&args[3], acir_gen, ctx, evaluator), + output: outputs[0], + }, + BlackBoxFunc::ComputeMerkleRoot => BlackBoxFuncCall::ComputeMerkleRoot { + leaf: resolve_variable(&args[0], acir_gen, ctx, evaluator).unwrap(), + index: resolve_variable(&args[1], acir_gen, ctx, evaluator).unwrap(), + hash_path: resolve_array(&args[2], acir_gen, ctx, evaluator), + output: outputs[0], + }, + BlackBoxFunc::HashToField128Security => BlackBoxFuncCall::HashToField128Security { + inputs: resolve_array(&args[0], acir_gen, ctx, evaluator), + output: outputs[0], + }, + _ => panic!("Unsupported low level function {:?}", op), }; evaluator.opcodes.push(AcirOpcode::BlackBoxFuncCall(func_call)); } @@ -139,64 +195,45 @@ pub(crate) fn evaluate( (outputs.len() == 1).then(|| InternalVar::from(outputs[0])) } -// Transform the arguments of intrinsic functions into witnesses -fn prepare_inputs( - acir_gen: &mut Acir, - arguments: &[NodeId], - cfg: &SsaContext, - evaluator: &mut Evaluator, -) -> Vec { - let mut inputs: Vec = Vec::new(); - - for argument in arguments { - inputs.extend(resolve_node_id(argument, acir_gen, cfg, evaluator)); - } - inputs -} - -fn resolve_node_id( +fn resolve_variable( node_id: &NodeId, acir_gen: &mut Acir, cfg: &SsaContext, evaluator: &mut Evaluator, -) -> Vec { +) -> Option { let node_object = cfg.try_get_node(*node_id).expect("could not find node for {node_id}"); match node_object { node::NodeObject::Variable(v) => { - let node_obj_type = node_object.get_type(); - match node_obj_type { - // If the `Variable` represents a Pointer - // Then we know that it is an `Array` - node::ObjectType::ArrayPointer(a) => resolve_array(a, acir_gen, cfg, evaluator), - // If it is not a pointer, we attempt to fetch the witness associated with it - _ => match v.witness { - Some(w) => { - vec![FunctionInput { witness: w, num_bits: v.size_in_bits() }] - } - None => todo!("generate a witness"), - }, - } + Some(FunctionInput { witness: v.witness?, num_bits: v.size_in_bits() }) } _ => { // Upon the case that the `NodeObject` is not a `Variable`, // we attempt to fetch an associated `InternalVar`. // Otherwise, this is a internal compiler error. let internal_var = acir_gen.var_cache.get(node_id).expect("invalid input").clone(); - let witness = acir_gen - .var_cache - .get_or_compute_witness(internal_var, evaluator) - .expect("unexpected constant expression"); - vec![FunctionInput { witness, num_bits: node_object.size_in_bits() }] + let witness = acir_gen.var_cache.get_or_compute_witness(internal_var, evaluator)?; + Some(FunctionInput { witness, num_bits: node_object.size_in_bits() }) } } } fn resolve_array( - array_id: ArrayId, + node_id: &NodeId, acir_gen: &mut Acir, cfg: &SsaContext, evaluator: &mut Evaluator, ) -> Vec { + let node_object = cfg.try_get_node(*node_id).expect("could not find node for {node_id}"); + let array_id = match node_object { + node::NodeObject::Variable(_) => { + let node_obj_type = node_object.get_type(); + match node_obj_type { + node::ObjectType::ArrayPointer(a) => a, + _ => unreachable!(), + } + } + _ => todo!("generate a witness"), + }; let mut inputs = Vec::new(); let array = &cfg.mem[array_id]; diff --git a/crates/noirc_evaluator/src/ssa/acir_gen/operations/sort.rs b/crates/noirc_evaluator/src/ssa/acir_gen/operations/sort.rs index 9566252b2be..ccea9caac4c 100644 --- a/crates/noirc_evaluator/src/ssa/acir_gen/operations/sort.rs +++ b/crates/noirc_evaluator/src/ssa/acir_gen/operations/sort.rs @@ -113,13 +113,10 @@ fn permutation_layer( #[cfg(test)] mod test { - use std::collections::BTreeMap; - use acvm::{ - acir::{circuit::opcodes::BlackBoxFuncCall, native_types::Witness}, - pwg::block::Blocks, - FieldElement, OpcodeResolution, OpcodeResolutionError, PartialWitnessGenerator, - PartialWitnessGeneratorStatus, + acir::{circuit::opcodes::FunctionInput, native_types::Witness, native_types::WitnessMap}, + pwg::{block::Blocks, solve, OpcodeResolution, PartialWitnessGeneratorStatus}, + FieldElement, OpcodeResolutionError, PartialWitnessGenerator, }; use crate::{ @@ -130,12 +127,118 @@ mod test { struct MockBackend {} impl PartialWitnessGenerator for MockBackend { - fn solve_black_box_function_call( + fn aes( + &self, + _initial_witness: &mut WitnessMap, + _inputs: &[FunctionInput], + _outputs: &[Witness], + ) -> Result { + panic!("Path not trodden by this test") + } + fn and( + &self, + _initial_witness: &mut WitnessMap, + _lhs: &FunctionInput, + _rhs: &FunctionInput, + _output: &Witness, + ) -> Result { + panic!("Path not trodden by this test") + } + fn xor( + &self, + _initial_witness: &mut WitnessMap, + _lhs: &FunctionInput, + _rhs: &FunctionInput, + _output: &Witness, + ) -> Result { + panic!("Path not trodden by this test") + } + fn range( + &self, + _initial_witness: &mut WitnessMap, + _input: &FunctionInput, + ) -> Result { + panic!("Path not trodden by this test") + } + fn sha256( + &self, + _initial_witness: &mut WitnessMap, + _inputs: &[FunctionInput], + _outputs: &[Witness], + ) -> Result { + panic!("Path not trodden by this test") + } + fn blake2s( + &self, + _initial_witness: &mut WitnessMap, + _inputs: &[FunctionInput], + _outputs: &[Witness], + ) -> Result { + panic!("Path not trodden by this test") + } + fn compute_merkle_root( + &self, + _initial_witness: &mut WitnessMap, + _leaf: &FunctionInput, + _index: &FunctionInput, + _hash_path: &[FunctionInput], + _output: &Witness, + ) -> Result { + panic!("Path not trodden by this test") + } + fn schnorr_verify( + &self, + _initial_witness: &mut WitnessMap, + _public_key_x: &FunctionInput, + _public_key_y: &FunctionInput, + _signature: &[FunctionInput], + _message: &[FunctionInput], + _output: &Witness, + ) -> Result { + panic!("Path not trodden by this test") + } + fn pedersen( + &self, + _initial_witness: &mut WitnessMap, + _inputs: &[FunctionInput], + _outputs: &[Witness], + ) -> Result { + panic!("Path not trodden by this test") + } + fn hash_to_field_128_security( + &self, + _initial_witness: &mut WitnessMap, + _inputs: &[FunctionInput], + _output: &Witness, + ) -> Result { + panic!("Path not trodden by this test") + } + fn ecdsa_secp256k1( + &self, + _initial_witness: &mut WitnessMap, + _public_key_x: &[FunctionInput], + _public_key_y: &[FunctionInput], + _signature: &[FunctionInput], + _message: &[FunctionInput], + _output: &Witness, + ) -> Result { + panic!("Path not trodden by this test") + } + fn fixed_base_scalar_mul( + &self, + _initial_witness: &mut WitnessMap, + _input: &FunctionInput, + _outputs: &[Witness], + ) -> Result { + panic!("Path not trodden by this test") + } + fn keccak256( &self, - _initial_witness: &mut BTreeMap, - _func_call: &BlackBoxFuncCall, + _initial_witness: &mut WitnessMap, + _inputs: &[FunctionInput], + _outputs: &[Witness], ) -> Result { - unreachable!(); + panic!("Path not trodden by this test") } } @@ -150,7 +253,7 @@ mod test { let mut input = Vec::new(); let mut a_val = Vec::new(); let mut b_wit = Vec::new(); - let mut solved_witness: BTreeMap = BTreeMap::new(); + let mut solved_witness = WitnessMap::new(); for i in 0..n { let w = eval.add_witness_to_cs(); input.push(w.into()); @@ -181,9 +284,9 @@ mod test { // compute the network output by solving the constraints let backend = MockBackend {}; let mut blocks = Blocks::default(); - let solver_status = backend - .solve(&mut solved_witness, &mut blocks, eval.opcodes.clone()) - .expect("Could not solve permutation constraints"); + let solver_status = + solve(&backend, &mut solved_witness, &mut blocks, eval.opcodes.clone()) + .expect("Could not solve permutation constraints"); assert_eq!(solver_status, PartialWitnessGeneratorStatus::Solved, "Incomplete solution"); let mut b_val = Vec::new(); for i in 0..output.len() { diff --git a/crates/noirc_evaluator/src/ssa_refactor.rs b/crates/noirc_evaluator/src/ssa_refactor.rs index 8330931a4b4..af5f89bc122 100644 --- a/crates/noirc_evaluator/src/ssa_refactor.rs +++ b/crates/noirc_evaluator/src/ssa_refactor.rs @@ -8,7 +8,10 @@ #![allow(dead_code)] use crate::errors::{RuntimeError, RuntimeErrorKind}; -use acvm::{acir::circuit::Circuit, compiler::transformers::IsOpcodeSupported, Language}; +use acvm::{ + acir::circuit::{Circuit, Opcode as AcirOpcode}, + Language, +}; use noirc_abi::Abi; use noirc_frontend::monomorphization::ast::Program; @@ -39,7 +42,7 @@ pub fn optimize_into_acir(program: Program) { pub fn experimental_create_circuit( _program: Program, _np_language: Language, - _is_opcode_supported: IsOpcodeSupported, + _is_opcode_supported: &impl Fn(&AcirOpcode) -> bool, _enable_logging: bool, _show_output: bool, ) -> Result<(Circuit, Abi), RuntimeError> { diff --git a/flake.lock b/flake.lock index 62abdb4a42e..53b65eb4b4f 100644 --- a/flake.lock +++ b/flake.lock @@ -10,11 +10,11 @@ ] }, "locked": { - "lastModified": 1683839119, - "narHash": "sha256-pVoW3C5Ek9/878PBzvXqnt51KpIDrxPt5HVtNwdErnE=", + "lastModified": 1683909802, + "narHash": "sha256-2CL8NYKLYwwy6n0RyldvH86ULgrSvfzHrgq2Qf0ZUkE=", "owner": "AztecProtocol", "repo": "barretenberg", - "rev": "223b9dee2542145d67126cc8a5aa0e9b9d82c244", + "rev": "97c9bc72aebab850b4a647d6e6cc50085226eafb", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index c15a1e51061..696c38623ed 100644 --- a/flake.nix +++ b/flake.nix @@ -84,10 +84,6 @@ # We set the environment variable because barretenberg must be compiled in a special way for wasm BARRETENBERG_BIN_DIR = "${pkgs.barretenberg-wasm}/bin"; - - # We provide `barretenberg-transcript00` from the overlay to the build. - # This is necessary because the Nix sandbox disables the $HOME so downloading during tests would fail - BARRETENBERG_TRANSCRIPT = pkgs.barretenberg-transcript00; }; # The `self.rev` property is only available when the working tree is not dirty @@ -138,6 +134,31 @@ inherit GIT_DIRTY; }; + # The `port` is parameterized to support parallel test runs without colliding static servers + testArgs = port: { + # We provide `barretenberg-transcript00` from the overlay to the tests as a URL hosted via a static server + # This is necessary because the Nix sandbox has no network access and downloading during tests would fail + TRANSCRIPT_URL = "http://0.0.0.0:${toString port}/${builtins.baseNameOf pkgs.barretenberg-transcript00}"; + + # This copies the `barretenberg-transcript00` from the Nix store into this sandbox + # which avoids exposing the entire Nix store to the static server it starts + # The static server is moved to the background and killed after checks are completed + # + # We also set the NARGO_BACKEND_CACHE_DIR environment variable to the $TMP directory so we can successfully cache + # the transcript; which isn't possible with the default path because the Nix sandbox disabled $HOME + preCheck = '' + export NARGO_BACKEND_CACHE_DIR=$TMP + cp ${pkgs.barretenberg-transcript00} . + echo "Starting simple static server" + ${pkgs.simple-http-server}/bin/simple-http-server --port ${toString port} --silent & + HTTP_SERVER_PID=$! + ''; + + postCheck = '' + kill $HTTP_SERVER_PID + ''; + }; + # Build *just* the cargo dependencies, so we can reuse all of that work between runs cargoArtifacts = craneLib.buildDepsOnly commonArgs; @@ -152,16 +173,15 @@ # TODO(#1198): It'd be nice to include these flags when running `cargo clippy` in a devShell. cargoClippyExtraArgs = "--all-targets -- -D warnings"; - - doCheck = true; }); - cargo-test = craneLib.cargoTest (commonArgs // { + cargo-test = craneLib.cargoTest (commonArgs // (testArgs 8000) // { inherit cargoArtifacts; # TODO(#1198): It'd be nice to include this flag when running `cargo test` in a devShell. cargoTestExtraArgs = "--workspace"; + # It's unclear why doCheck needs to be enabled for tests to run but not clippy doCheck = true; }); };