From 32a3de074398bcd7825d29791d7cd3fa8ed50381 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Wed, 7 Jun 2023 14:14:53 +0000 Subject: [PATCH 1/4] acvm 0.14.0 dep and respective backend change --- Cargo.lock | 24 ++++++++++++------------ Cargo.toml | 2 +- crates/nargo_cli/Cargo.toml | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1fa151a51f0..ec0273de002 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "acir" -version = "0.13.3" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e011212158b81a8bbe6c9f7f4713fbf8b9542076a49ba916769436833b5d738f" +checksum = "a686d2e9e57b6ab9a6e4fb9b8ae16f589dd6002597f9c18990213f2627e4656e" dependencies = [ "acir_field", "brillig_vm", @@ -18,9 +18,9 @@ dependencies = [ [[package]] name = "acir_field" -version = "0.13.3" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08e3bbb98412bdcb65b7b688269cbc04db0710e25f3c32e99cf3923026ea3941" +checksum = "f7cef2443400feb687cc3c9ac710c81e45dda495a7d4b33acf51ccb39d64fb27" dependencies = [ "ark-bn254", "ark-ff", @@ -32,9 +32,9 @@ dependencies = [ [[package]] name = "acvm" -version = "0.13.3" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5b5a910c6dcbea83195107368805911a02b2ed3453a1516e15fa2bc89e4d1c2" +checksum = "31a21697700d8b47eab9cd1fb24a5465aab6b50c30dece17f08ebad077ec3c08" dependencies = [ "acir", "acvm_stdlib", @@ -51,9 +51,9 @@ dependencies = [ [[package]] name = "acvm-backend-barretenberg" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e792521ba83064509ce23763d11a9134773f90c325d7a418cb650b139f02afa6" +checksum = "4c9fd4e49aa0498725c79202e308cb7e2690d0faafbf22f5de4c8f0e704451c1" dependencies = [ "acvm", "barretenberg-sys", @@ -71,9 +71,9 @@ dependencies = [ [[package]] name = "acvm_stdlib" -version = "0.13.3" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe3837b19bcbf11cecd61083e088a49c2d7911abedd0585cc62bf77bb47a384" +checksum = "218b068da8e83af7dba9dbc0881013b034f7a24257b5dd86c4390d95cde067ea" dependencies = [ "acir", ] @@ -505,9 +505,9 @@ dependencies = [ [[package]] name = "brillig_vm" -version = "0.13.3" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b690fd9d34b8653edf286c03982433e80e6e3878a8fc6289b680997c3e80925b" +checksum = "22c4384c6e10aa275904f66b5243d604990ef6fcc693fd9a03596c6c7a51c759" dependencies = [ "acir_field", "num-bigint", diff --git a/Cargo.toml b/Cargo.toml index bdcd158ff04..6639005ba2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ edition = "2021" rust-version = "1.66" [workspace.dependencies] -acvm = "=0.13.3" +acvm = "=0.14.0" arena = { path = "crates/arena" } fm = { path = "crates/fm" } iter-extended = { path = "crates/iter-extended" } diff --git a/crates/nargo_cli/Cargo.toml b/crates/nargo_cli/Cargo.toml index 840232a64c6..47113b160a3 100644 --- a/crates/nargo_cli/Cargo.toml +++ b/crates/nargo_cli/Cargo.toml @@ -42,7 +42,7 @@ color-eyre = "0.6.2" tokio = "1.0" # Backends -acvm-backend-barretenberg = { version = "0.3.0", default-features = false } +acvm-backend-barretenberg = { version = "0.4.0", default-features = false } [dev-dependencies] tempdir = "0.3.7" From 885e0d44cf6f16e40aa15773965966fd7c8b83bb Mon Sep 17 00:00:00 2001 From: vezenovm Date: Wed, 7 Jun 2023 18:23:43 +0000 Subject: [PATCH 2/4] updates inside noir for acvm 0.14.0 --- crates/nargo/src/ops/prove.rs | 3 +- crates/nargo/src/ops/verify.rs | 3 +- .../src/ssa/acir_gen/operations/intrinsics.rs | 49 +++++++++++++++++++ crates/noirc_evaluator/src/ssa/builtin.rs | 7 ++- .../acir_gen/acir_ir/generated_acir.rs | 14 ++++++ flake.lock | 6 +-- 6 files changed, 76 insertions(+), 6 deletions(-) diff --git a/crates/nargo/src/ops/prove.rs b/crates/nargo/src/ops/prove.rs index e2c70739a35..16839a1b060 100644 --- a/crates/nargo/src/ops/prove.rs +++ b/crates/nargo/src/ops/prove.rs @@ -8,5 +8,6 @@ pub fn prove_execution( solved_witness: WitnessMap, proving_key: &[u8], ) -> Result, B::Error> { - backend.prove_with_pk(common_reference_string, circuit, solved_witness, proving_key) + // TODO(#1569): update from not just accepting `false` once we get nargo to interop with dynamic backend + backend.prove_with_pk(common_reference_string, circuit, solved_witness, proving_key, false) } diff --git a/crates/nargo/src/ops/verify.rs b/crates/nargo/src/ops/verify.rs index 1d2d3bbbd6f..7e93b5ec26f 100644 --- a/crates/nargo/src/ops/verify.rs +++ b/crates/nargo/src/ops/verify.rs @@ -9,5 +9,6 @@ pub fn verify_proof( public_inputs: WitnessMap, verification_key: &[u8], ) -> Result { - backend.verify_with_vk(common_reference_string, proof, public_inputs, circuit, verification_key) + // TODO(#1569): update from not just accepting `false` once we get nargo to interop with dynamic backend + backend.verify_with_vk(common_reference_string, proof, public_inputs, circuit, verification_key, false) } 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 02179b17bca..03a2988509b 100644 --- a/crates/noirc_evaluator/src/ssa/acir_gen/operations/intrinsics.rs +++ b/crates/noirc_evaluator/src/ssa/acir_gen/operations/intrinsics.rs @@ -95,6 +95,11 @@ pub(crate) fn evaluate( | BlackBoxFunc::HashToField128Security => { prepare_outputs(&mut acir_gen.memory, instruction_id, 1, ctx, evaluator) } + // There are some low level functions that have variable outputs and + // should not have a set output count in Noir + BlackBoxFunc::RecursiveAggregation => { + prepare_outputs_no_count(&mut acir_gen.memory, instruction_id, ctx, evaluator) + } _ => panic!("Unsupported low level function {:?}", op), }; let func_call = match op { @@ -151,6 +156,31 @@ pub(crate) fn evaluate( inputs: resolve_array(&args[0], acir_gen, ctx, evaluator), output: outputs[0], }, + BlackBoxFunc::RecursiveAggregation => { + let has_previous_aggregation = evaluator.opcodes.iter().any(|op| { + matches!( + op, + AcirOpcode::BlackBoxFuncCall( + BlackBoxFuncCall::RecursiveAggregation { .. } + ) + ) + }); + + let input_aggregation_object = if !has_previous_aggregation { + None + } else { + Some(resolve_array(&args[4], acir_gen, ctx, evaluator)) + }; + + BlackBoxFuncCall::RecursiveAggregation { + verification_key: resolve_array(&args[0], acir_gen, ctx, evaluator), + proof: resolve_array(&args[1], acir_gen, ctx, evaluator), + public_inputs: resolve_array(&args[2], acir_gen, ctx, evaluator), + key_hash: resolve_variable(&args[3], acir_gen, ctx, evaluator).unwrap(), + input_aggregation_object, + output_aggregation_object: outputs.to_vec(), + } + } _ => panic!("Unsupported low level function {:?}", op), }; evaluator.opcodes.push(AcirOpcode::BlackBoxFuncCall(func_call)); @@ -280,6 +310,25 @@ fn prepare_outputs( outputs } +fn prepare_outputs_no_count( + memory_map: &mut AcirMem, + pointer: NodeId, + ctx: &SsaContext, + evaluator: &mut Evaluator, +) -> Vec { + // Create fresh variables that will link to the output + let l_obj = ctx.try_get_node(pointer).unwrap(); + if let node::ObjectType::ArrayPointer(a) = l_obj.get_type() { + let mem_array = &ctx.mem[a]; + let output_nb = mem_array.len; + let outputs = vecmap(0..output_nb, |_| evaluator.add_witness_to_cs()); + memory_map.map_array(a, &outputs, ctx); + outputs + } else { + vec![evaluator.add_witness_to_cs()] + } +} + fn evaluate_println( var_cache: &mut InternalVarCache, memory_map: &mut AcirMem, diff --git a/crates/noirc_evaluator/src/ssa/builtin.rs b/crates/noirc_evaluator/src/ssa/builtin.rs index 6ef55f76b5f..7cda3ad7290 100644 --- a/crates/noirc_evaluator/src/ssa/builtin.rs +++ b/crates/noirc_evaluator/src/ssa/builtin.rs @@ -76,7 +76,8 @@ impl Opcode { | BlackBoxFunc::Keccak256 | BlackBoxFunc::Blake2s | BlackBoxFunc::Pedersen - | BlackBoxFunc::FixedBaseScalarMul => BigUint::zero(), + | BlackBoxFunc::FixedBaseScalarMul + | BlackBoxFunc::RecursiveAggregation => BigUint::zero(), // Verify returns zero or one BlackBoxFunc::SchnorrVerify | BlackBoxFunc::EcdsaSecp256k1 => BigUint::one(), BlackBoxFunc::HashToField128Security => ObjectType::native_field().max_size(), @@ -107,6 +108,10 @@ impl Opcode { } BlackBoxFunc::Pedersen => (2, ObjectType::native_field()), BlackBoxFunc::FixedBaseScalarMul => (2, ObjectType::native_field()), + BlackBoxFunc::RecursiveAggregation => { + let a = super::mem::Memory::deref(ctx, args[4]).unwrap(); + (ctx.mem[a].len, ctx.mem[a].element_type) + } BlackBoxFunc::RANGE | BlackBoxFunc::AND | BlackBoxFunc::XOR => { unreachable!("ICE: these opcodes do not have Noir builtin functions") } 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 640fff829d1..5b7963b5f06 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 @@ -207,6 +207,10 @@ impl GeneratedAcir { let var_message_size = inputs.pop().expect("ICE: Missing message_size arg"); BlackBoxFuncCall::Keccak256VariableLength { inputs, var_message_size, outputs } } + // TODO(#1570): Generate ACIR for recursive aggregation + BlackBoxFunc::RecursiveAggregation => { + panic!("ICE: Cannot generate ACIR for recursive aggregation") + } }; self.opcodes.push(AcirOpcode::BlackBoxFuncCall(black_box_func_call)); @@ -635,6 +639,12 @@ fn black_box_func_expected_input_size(name: BlackBoxFunc) -> Option { // Inputs for fixed based scalar multiplication // is just a scalar BlackBoxFunc::FixedBaseScalarMul => Some(1), + // TODO(#1570): Generate ACIR for recursive aggregation + // RecursiveAggregation has variable inputs and we could return `None` here, + // but as it is not fully implemented we panic for now + BlackBoxFunc::RecursiveAggregation => { + panic!("ICE: Cannot generate ACIR for recursive aggregation") + } } } @@ -659,6 +669,10 @@ fn black_box_expected_output_size(name: BlackBoxFunc) -> u32 { // Output of fixed based scalar mul over the embedded curve // will be 2 field elements representing the point. BlackBoxFunc::FixedBaseScalarMul => 2, + // TODO(#1570): Generate ACIR for recursive aggregation + BlackBoxFunc::RecursiveAggregation => { + panic!("ICE: Cannot generate ACIR for recursive aggregation") + } } } diff --git a/flake.lock b/flake.lock index 6bfc9462b60..10839befbc2 100644 --- a/flake.lock +++ b/flake.lock @@ -10,11 +10,11 @@ ] }, "locked": { - "lastModified": 1685544246, - "narHash": "sha256-OECUSjN/pqJgS2TjOHwv02qH4NkHKk3BghD3XbEHUKw=", + "lastModified": 1685812470, + "narHash": "sha256-sJYVipq1EthnjSxVIZnZF15wy9LDMHNPfIJKRHyZrws=", "owner": "AztecProtocol", "repo": "barretenberg", - "rev": "aebfe95c547b0022a9baed3901e945bb386503be", + "rev": "193ce1a45ef5eab6a8522178cf918e45320f3de8", "type": "github" }, "original": { From b546314059d6fd0d4752037ea247fbada60a9f2a Mon Sep 17 00:00:00 2001 From: vezenovm Date: Wed, 7 Jun 2023 18:26:57 +0000 Subject: [PATCH 3/4] cargo fmt --- crates/nargo/src/ops/verify.rs | 9 ++++++++- .../src/ssa/acir_gen/operations/intrinsics.rs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/nargo/src/ops/verify.rs b/crates/nargo/src/ops/verify.rs index 7e93b5ec26f..4cc6c9ce34b 100644 --- a/crates/nargo/src/ops/verify.rs +++ b/crates/nargo/src/ops/verify.rs @@ -10,5 +10,12 @@ pub fn verify_proof( verification_key: &[u8], ) -> Result { // TODO(#1569): update from not just accepting `false` once we get nargo to interop with dynamic backend - backend.verify_with_vk(common_reference_string, proof, public_inputs, circuit, verification_key, false) + backend.verify_with_vk( + common_reference_string, + proof, + public_inputs, + circuit, + verification_key, + false, + ) } 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 03a2988509b..829a48fef9d 100644 --- a/crates/noirc_evaluator/src/ssa/acir_gen/operations/intrinsics.rs +++ b/crates/noirc_evaluator/src/ssa/acir_gen/operations/intrinsics.rs @@ -95,7 +95,7 @@ pub(crate) fn evaluate( | BlackBoxFunc::HashToField128Security => { prepare_outputs(&mut acir_gen.memory, instruction_id, 1, ctx, evaluator) } - // There are some low level functions that have variable outputs and + // There are some low level functions that have variable outputs and // should not have a set output count in Noir BlackBoxFunc::RecursiveAggregation => { prepare_outputs_no_count(&mut acir_gen.memory, instruction_id, ctx, evaluator) From 45894e2ed1d36d015275da2f798325303a0ca594 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Wed, 7 Jun 2023 18:55:54 +0000 Subject: [PATCH 4/4] add verify_proof to stdlib --- noir_stdlib/src/lib.nr | 3 +++ 1 file changed, 3 insertions(+) diff --git a/noir_stdlib/src/lib.nr b/noir_stdlib/src/lib.nr index f6a60a6dee7..b010eb31be3 100644 --- a/noir_stdlib/src/lib.nr +++ b/noir_stdlib/src/lib.nr @@ -15,3 +15,6 @@ mod compat; #[builtin(println)] fn println(_input : T) {} + +#[foreign(recursive_aggregation)] +fn verify_proof(_verification_key : [Field], _proof : [Field], _public_inputs : [Field], _key_hash : Field, _input_aggregation_object : [Field]) -> [Field] {}