From 285182771c5dda79b0879452f0307ac02b37f8a0 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Mon, 10 Jul 2023 14:56:33 +0700 Subject: [PATCH] chore: update to `acvm-backend-barretenberg` 0.7.0 (#1897) * feat: update to `acvm-backend-barretenberg` 0.7.0 * chore: update cspell --- Cargo.lock | 38 +++++++++++++------ Cargo.toml | 3 +- crates/nargo_cli/Cargo.toml | 2 +- crates/nargo_cli/src/cli/check_cmd.rs | 6 ++- crates/nargo_cli/src/cli/test_cmd.rs | 6 ++- .../src/brillig/brillig_ir/debug_show.rs | 16 ++++++++ crates/noirc_evaluator/src/ssa/builtin.rs | 10 +++-- .../acir_gen/acir_ir/generated_acir.rs | 18 ++++++++- cspell.json | 1 + flake.lock | 6 +-- 10 files changed, 80 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 76c32c310f8..1b0f46d761e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "acir" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bed559b3e6e10a04b2a1af7a8b0f23d4bbaf4a87a6c8ac9946583f8945c53ce5" +checksum = "502a9126627ae67868515031c2283e64f3e1fef5ff93850009ed89a8a24fac60" dependencies = [ "acir_field", "brillig_vm", @@ -18,9 +18,9 @@ dependencies = [ [[package]] name = "acir_field" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29adbffe34f7ae42e080833364f66ea0e933ca4aa3880e12444780538e1f6767" +checksum = "4a98fe4e3f9156f5551c8c9686e8f720a990d000e1e666e08a86e938a36ac8be" dependencies = [ "ark-bn254", "ark-ff", @@ -32,9 +32,9 @@ dependencies = [ [[package]] name = "acvm" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4808764cc92ba018210ec2f276f6d90908263af33f9a8abea6ae4139ba49aa0" +checksum = "95315759a51115860af49a492791ae5155c3d2c0555eec1358faa5d74c763391" dependencies = [ "acir", "acvm_stdlib", @@ -44,6 +44,7 @@ dependencies = [ "k256", "num-bigint", "num-traits", + "p256", "sha2", "sha3", "thiserror", @@ -51,8 +52,9 @@ dependencies = [ [[package]] name = "acvm-backend-barretenberg" -version = "0.6.0" -source = "git+https://github.com/noir-lang/acvm-backend-barretenberg.git?rev=0842911beed6c54b7efcd721372fb73431c95bbf#0842911beed6c54b7efcd721372fb73431c95bbf" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e23bca54647ad1e9e89c24ca62f813427cea990177aebd68139081649b96e3b" dependencies = [ "acvm", "barretenberg-sys", @@ -70,9 +72,9 @@ dependencies = [ [[package]] name = "acvm_stdlib" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57b0fea96f9ddc8866782636f1317aa0ac958ab7bc628fa9620a4915cc667edc" +checksum = "0f7d2d8407e55ac26078af1d783408525e7f906e531cb04adcc47650d7994f62" dependencies = [ "acir", ] @@ -512,13 +514,14 @@ dependencies = [ [[package]] name = "brillig_vm" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9400d1493af661cba05923a5b4a78e3aeaeb4210b321831fc0461b01203191e" +checksum = "36821ba87dd1807784d679bca54d753665014b109f6acfe38516eec7f3d71941" dependencies = [ "acir_field", "blake2", "k256", + "p256", "serde", "sha2", "sha3", @@ -2195,6 +2198,17 @@ version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" +[[package]] +name = "p256" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51f44edd08f51e2ade572f141051021c5af22677e42b7dd28a88155151c33594" +dependencies = [ + "ecdsa", + "elliptic-curve", + "sha2", +] + [[package]] name = "paste" version = "1.0.12" diff --git a/Cargo.toml b/Cargo.toml index 81bce683b36..f1d1e53e5d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ edition = "2021" rust-version = "1.66" [workspace.dependencies] -acvm = "0.16.0" +acvm = "0.17.0" arena = { path = "crates/arena" } fm = { path = "crates/fm" } iter-extended = { path = "crates/iter-extended" } @@ -58,4 +58,3 @@ wasm-bindgen-test = "0.3.33" [patch.crates-io] async-lsp = { git = "https://github.com/oxalica/async-lsp", rev = "09dbcc11046f7a188a80137f8d36484d86c78c78" } -acvm-backend-barretenberg = { git = "https://github.com/noir-lang/acvm-backend-barretenberg.git", rev = "0842911beed6c54b7efcd721372fb73431c95bbf" } \ No newline at end of file diff --git a/crates/nargo_cli/Cargo.toml b/crates/nargo_cli/Cargo.toml index 9550d0f978c..62328b42de8 100644 --- a/crates/nargo_cli/Cargo.toml +++ b/crates/nargo_cli/Cargo.toml @@ -43,7 +43,7 @@ color-eyre = "0.6.2" tokio = { version = "1.0", features = ["io-std"] } # Backends -acvm-backend-barretenberg = { version = "0.6.0", default-features = false } +acvm-backend-barretenberg = { version = "0.7.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 02ac3c024c0..5abef7bfb2a 100644 --- a/crates/nargo_cli/src/cli/check_cmd.rs +++ b/crates/nargo_cli/src/cli/check_cmd.rs @@ -37,7 +37,11 @@ fn check_from_path( compile_options: &CompileOptions, ) -> Result<(), CliError> { let mut context = resolve_root_manifest(program_dir)?; - check_crate_and_report_errors(&mut context, compile_options.deny_warnings, compile_options.experimental_ssa)?; + check_crate_and_report_errors( + &mut context, + compile_options.deny_warnings, + compile_options.experimental_ssa, + )?; // XXX: We can have a --overwrite flag to determine if you want to overwrite the Prover/Verifier.toml files if let Some((parameters, return_type)) = compute_function_signature(&context) { diff --git a/crates/nargo_cli/src/cli/test_cmd.rs b/crates/nargo_cli/src/cli/test_cmd.rs index 5b51efe1add..19a30858d21 100644 --- a/crates/nargo_cli/src/cli/test_cmd.rs +++ b/crates/nargo_cli/src/cli/test_cmd.rs @@ -41,7 +41,11 @@ fn run_tests( compile_options: &CompileOptions, ) -> Result<(), CliError> { let mut context = resolve_root_manifest(program_dir)?; - check_crate_and_report_errors(&mut context, compile_options.deny_warnings, compile_options.experimental_ssa)?; + check_crate_and_report_errors( + &mut context, + compile_options.deny_warnings, + compile_options.experimental_ssa, + )?; let test_functions = context.get_all_test_functions_in_crate_matching(&LOCAL_CRATE, test_name); println!("Running {} test functions...", test_functions.len()); diff --git a/crates/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs b/crates/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs index 01c04ffab3d..37c0f4006f3 100644 --- a/crates/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs +++ b/crates/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs @@ -296,6 +296,22 @@ pub(crate) fn black_box_op_instruction(op: BlackBoxOp) { result ); } + BlackBoxOp::EcdsaSecp256r1 { + hashed_msg, + public_key_x, + public_key_y, + signature, + result, + } => { + debug_println!( + " ECDSA_SECP256R1 {} {} {} {} -> {}", + hashed_msg, + public_key_x, + public_key_y, + signature, + result + ); + } } } diff --git a/crates/noirc_evaluator/src/ssa/builtin.rs b/crates/noirc_evaluator/src/ssa/builtin.rs index 7cda3ad7290..ec4cb764534 100644 --- a/crates/noirc_evaluator/src/ssa/builtin.rs +++ b/crates/noirc_evaluator/src/ssa/builtin.rs @@ -79,7 +79,9 @@ impl Opcode { | BlackBoxFunc::FixedBaseScalarMul | BlackBoxFunc::RecursiveAggregation => BigUint::zero(), // Verify returns zero or one - BlackBoxFunc::SchnorrVerify | BlackBoxFunc::EcdsaSecp256k1 => BigUint::one(), + BlackBoxFunc::SchnorrVerify + | BlackBoxFunc::EcdsaSecp256k1 + | BlackBoxFunc::EcdsaSecp256r1 => BigUint::one(), BlackBoxFunc::HashToField128Security => ObjectType::native_field().max_size(), BlackBoxFunc::RANGE | BlackBoxFunc::AND | BlackBoxFunc::XOR => { unimplemented!("ICE: these opcodes do not have Noir builtin functions") @@ -103,9 +105,9 @@ impl Opcode { } BlackBoxFunc::HashToField128Security => (1, ObjectType::native_field()), // See issue #775 on changing this to return a boolean - BlackBoxFunc::SchnorrVerify | BlackBoxFunc::EcdsaSecp256k1 => { - (1, ObjectType::native_field()) - } + BlackBoxFunc::SchnorrVerify + | BlackBoxFunc::EcdsaSecp256k1 + | BlackBoxFunc::EcdsaSecp256r1 => (1, ObjectType::native_field()), BlackBoxFunc::Pedersen => (2, ObjectType::native_field()), BlackBoxFunc::FixedBaseScalarMul => (2, ObjectType::native_field()), BlackBoxFunc::RecursiveAggregation => { diff --git a/crates/noirc_evaluator/src/ssa_refactor/acir_gen/acir_ir/generated_acir.rs b/crates/noirc_evaluator/src/ssa_refactor/acir_gen/acir_ir/generated_acir.rs index 174475bb5eb..d8ed0f42d40 100644 --- a/crates/noirc_evaluator/src/ssa_refactor/acir_gen/acir_ir/generated_acir.rs +++ b/crates/noirc_evaluator/src/ssa_refactor/acir_gen/acir_ir/generated_acir.rs @@ -244,6 +244,16 @@ impl GeneratedAcir { hashed_message: inputs[128..].to_vec(), output: outputs[0], }, + BlackBoxFunc::EcdsaSecp256r1 => BlackBoxFuncCall::EcdsaSecp256r1 { + // 32 bytes for each public key co-ordinate + public_key_x: inputs[0..32].to_vec(), + public_key_y: inputs[32..64].to_vec(), + // (r,s) are both 32 bytes each, so signature + // takes up 64 bytes + signature: inputs[64..128].to_vec(), + hashed_message: inputs[128..].to_vec(), + output: outputs[0], + }, BlackBoxFunc::FixedBaseScalarMul => BlackBoxFuncCall::FixedBaseScalarMul { input: inputs[0], outputs: (outputs[0], outputs[1]), @@ -806,7 +816,9 @@ fn black_box_func_expected_input_size(name: BlackBoxFunc) -> Option { // Signature verification algorithms will take in a variable // number of inputs, since the message/hashed-message can vary in size. - BlackBoxFunc::SchnorrVerify | BlackBoxFunc::EcdsaSecp256k1 => None, + BlackBoxFunc::SchnorrVerify + | BlackBoxFunc::EcdsaSecp256k1 + | BlackBoxFunc::EcdsaSecp256r1 => None, // Inputs for fixed based scalar multiplication // is just a scalar BlackBoxFunc::FixedBaseScalarMul => Some(1), @@ -836,7 +848,9 @@ fn black_box_expected_output_size(name: BlackBoxFunc) -> u32 { // witness at a time. BlackBoxFunc::RANGE => 0, // Signature verification algorithms will return a boolean - BlackBoxFunc::SchnorrVerify | BlackBoxFunc::EcdsaSecp256k1 => 1, + BlackBoxFunc::SchnorrVerify + | BlackBoxFunc::EcdsaSecp256k1 + | BlackBoxFunc::EcdsaSecp256r1 => 1, // Output of fixed based scalar mul over the embedded curve // will be 2 field elements representing the point. BlackBoxFunc::FixedBaseScalarMul => 2, diff --git a/cspell.json b/cspell.json index 92c3154f2b3..0bd24be47e4 100644 --- a/cspell.json +++ b/cspell.json @@ -90,6 +90,7 @@ "rustc", "rustup", "secp256k1", + "secp256r1", "smol", "tempdir", "tempfile", diff --git a/flake.lock b/flake.lock index c9047f7d52a..659daec5d3a 100644 --- a/flake.lock +++ b/flake.lock @@ -10,11 +10,11 @@ ] }, "locked": { - "lastModified": 1686677483, - "narHash": "sha256-mpsCXzHMaqSveQcD/SA9k3NH4pF167KqR5/oYJJjKE8=", + "lastModified": 1688820427, + "narHash": "sha256-w7yMeYp50KrlTn23TTKfYmLOQL4uIgw0wSX67v2tvvc=", "owner": "AztecProtocol", "repo": "barretenberg", - "rev": "65e651d04c6092cb5ca079cd9e12ed9b5846fa3a", + "rev": "fdd46f77531a6fcc9d9b24a698c56590d54d487e", "type": "github" }, "original": {