From a1e5966ffe98351d848bfa47608a2f22c381acfb Mon Sep 17 00:00:00 2001 From: Jean M <132435771+jeanmon@users.noreply.github.com> Date: Wed, 4 Dec 2024 15:14:40 +0100 Subject: [PATCH] chore(avm): Fake verification routine for avm recursion in public base rollup (#10382) Resolves #10243 --- .../vm/avm/tests/recursive_verifier.test.cpp | 4 +-- .../rollup-lib/src/base/public_base_rollup.nr | 5 +++ .../src/abis/avm_circuit_public_inputs.nr | 33 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/tests/recursive_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/tests/recursive_verifier.test.cpp index 7397d26196b..0d9920ad09b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/tests/recursive_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/tests/recursive_verifier.test.cpp @@ -109,8 +109,6 @@ TEST_F(AvmRecursiveTests, recursion) verification_key->pcs_verification_key->pairing_check(agg_output.P0.get_value(), agg_output.P1.get_value()); ASSERT_TRUE(agg_output_valid) << "Pairing points (aggregation state) are not valid."; - - vinfo("Recursive verifier: num gates = ", outer_circuit.num_gates); ASSERT_FALSE(outer_circuit.failed()) << "Outer circuit has failed."; bool outer_circuit_checked = CircuitChecker::check(outer_circuit); @@ -139,6 +137,8 @@ TEST_F(AvmRecursiveTests, recursion) auto ultra_verification_key = std::make_shared(ultra_instance->proving_key); OuterVerifier ultra_verifier(ultra_verification_key); + vinfo("Recursive verifier: finalized num gates = ", outer_circuit.num_gates); + auto recursion_proof = ultra_prover.construct_proof(); bool recursion_verified = ultra_verifier.verify_proof(recursion_proof); EXPECT_TRUE(recursion_verified) << "recursion proof verification failed"; diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/public_base_rollup.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/public_base_rollup.nr index c994027d7ec..ce7add25489 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/public_base_rollup.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/public_base_rollup.nr @@ -97,6 +97,11 @@ impl PublicBaseRollupInputs { // self.tube_data.vk_data.validate_in_vk_tree([TUBE_VK_INDEX]); } + // Warning: Fake verification! TODO(#8470) + if !dep::std::runtime::is_unconstrained() { + self.avm_proof_data.fake_verify(); + } + // TODO(#8470) // if !dep::std::runtime::is_unconstrained() { // self.avm_proof_data.verify(); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/avm_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/avm_circuit_public_inputs.nr index 7affd9031c9..b88a123a1fd 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/avm_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/avm_circuit_public_inputs.nr @@ -21,6 +21,8 @@ use crate::{ utils::reader::Reader, }; +use std::hash::{poseidon2, poseidon2_permutation}; + pub struct AvmCircuitPublicInputs { /////////////////////////////////// // Inputs. @@ -180,6 +182,37 @@ pub struct AvmProofData { pub vk_data: VkData, } +// The number of columns for the AVM recursive verifier we want to fake, i.e., the resulting +// verify() routine below will create a similar number of gates as a real AVM recursive verifier +// with the number of columns set by this constant. +pub global DUMMY_AVM_VERIFIER_NUM_COLUMNS: u32 = 2200; + +// Current AVM recursive verifier has 9500 gates per column. +// Note that the addition of a single column in AVM recursive verifier incurs 8500 gates. +// (some additional costs are due to lookups, relations, ...). +// 78 gates per Poseidon permutation +// 9500/78 = 121.8 +pub global DUMMY_AVM_VERIFIER_NUM_ITERATIONS: u32 = DUMMY_AVM_VERIFIER_NUM_COLUMNS * 122; + +// Warning: This is a fake avm recursive verification whose sole goal is to reproduce a similar +// computational effort (number of gates) as the real recursive verifier. +// TODO(#8470): Replace with the real AVM recursive verifier +impl AvmProofData { + pub fn fake_verify(self) { + let mut input_hash = poseidon2::Poseidon2::hash( + [self.public_inputs.transaction_fee, self.proof.fields[0], self.vk_data.vk.key[0]], + 3, + ); + + let mut result: [Field; 4] = [input_hash, 0, 0, 0]; + for i in 0..DUMMY_AVM_VERIFIER_NUM_ITERATIONS { + result = poseidon2_permutation(result, 4); + } + + assert(!result[0].lt(1)); + } +} + impl Verifiable for AvmProofData { fn verify(self) { // TODO(#8470)