From 407d23cf78d693c446facd5249f62f4943d102e3 Mon Sep 17 00:00:00 2001 From: sirasistant <sirasistant@gmail.com> Date: Wed, 9 Oct 2024 16:23:20 +0000 Subject: [PATCH 01/10] hell --- .../src/core/libraries/ConstantsGen.sol | 3 +- .../aztec/src/context/public_context.nr | 2 +- noir-projects/mega_honk_circuits.json | 3 +- .../parity-lib/src/root/root_parity_input.nr | 4 +- .../src/root/root_rollup_parity_input.nr | 4 +- .../src/private_kernel_empty.nr | 4 +- .../src/abis/previous_rollup_block_data.nr | 4 +- .../src/abis/previous_rollup_data.nr | 4 +- .../crates/types/src/abis/kernel_data.nr | 6 +-- .../abis/private_kernel/private_call_data.nr | 6 +-- .../types/src/abis/private_kernel_data.nr | 6 +-- .../types/src/abis/public_kernel_data.nr | 6 +-- .../src/abis/public_kernel_inner_data.nr | 5 ++- .../crates/types/src/constants.nr | 4 +- .../crates/types/src/hash.nr | 2 +- .../types/src/recursion/verification_key.nr | 37 ++++++++--------- .../crates/types/src/tests/fixture_builder.nr | 19 +++++---- noir-projects/scripts/generate_vk_json.js | 8 ++-- .../bb-prover/src/test/test_circuit_prover.ts | 5 ++- yarn-project/circuits.js/src/constants.gen.ts | 3 +- .../src/structs/kernel/kernel_data.ts | 4 +- .../src/structs/kernel/private_kernel_data.ts | 4 +- .../src/structs/kernel/public_kernel_data.ts | 8 +++- .../kernel/public_kernel_inner_data.ts | 4 +- .../src/structs/verification_key.test.ts | 5 ++- .../src/structs/verification_key.ts | 17 ++++---- .../circuits.js/src/tests/factories.ts | 15 +++---- .../noir-protocol-circuits-types/package.json | 6 ++- .../src/scripts/generate_declaration_files.ts | 2 +- .../src/scripts/generate_ts_from_abi.ts | 2 +- .../src/scripts/generate_vk_hashes.ts | 40 +++++++++++++++++++ .../src/type_conversion.ts | 34 +++++++++------- .../src/utils/vk_json.ts | 19 +++------ .../src/orchestrator/orchestrator.ts | 8 +++- .../prover-agent/memory-proving-queue.test.ts | 5 ++- .../src/prover-agent/prover-agent.test.ts | 5 ++- .../src/test/bb_prover_parity.test.ts | 3 +- .../prover-client/src/test/mock_prover.ts | 25 ++++++------ .../src/kernel_prover/kernel_prover.test.ts | 7 ++-- .../pxe/src/kernel_prover/kernel_prover.ts | 3 +- .../kernel_prover/test/test_circuit_prover.ts | 3 +- .../src/block_builder/light.test.ts | 3 +- .../src/block_builder/light.ts | 3 +- .../src/public/enqueued_calls_processor.ts | 4 +- 44 files changed, 216 insertions(+), 148 deletions(-) create mode 100644 yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index c7773668730e..7c60e37758d2 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -226,7 +226,8 @@ library Constants { uint256 internal constant RECURSIVE_PROOF_LENGTH = 463; uint256 internal constant NESTED_RECURSIVE_PROOF_LENGTH = 463; uint256 internal constant TUBE_PROOF_LENGTH = 463; - uint256 internal constant VERIFICATION_KEY_LENGTH_IN_FIELDS = 128; + uint256 internal constant HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS = 128; + uint256 internal constant CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS = 145; uint256 internal constant MEM_TAG_U1 = 1; uint256 internal constant MEM_TAG_U8 = 2; uint256 internal constant MEM_TAG_U16 = 3; diff --git a/noir-projects/aztec-nr/aztec/src/context/public_context.nr b/noir-projects/aztec-nr/aztec/src/context/public_context.nr index 98188c3bf966..329ca04beb2f 100644 --- a/noir-projects/aztec-nr/aztec/src/context/public_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/public_context.nr @@ -259,7 +259,7 @@ unconstrained fn note_hash_exists(note_hash: Field, leaf_index: Field) -> u8 { unconstrained fn emit_note_hash(note_hash: Field) { emit_note_hash_opcode(note_hash) } -unconstrained fn nullifier_exists(nullifier: Field, address: Field) -> u8 { +unconstrained fn nullifier_exists(nullifier: Field, address: Field) -> u1 { nullifier_exists_opcode(nullifier, address) } unconstrained fn emit_nullifier(nullifier: Field) { diff --git a/noir-projects/mega_honk_circuits.json b/noir-projects/mega_honk_circuits.json index 812e1aba8b59..c1dd653f4de2 100644 --- a/noir-projects/mega_honk_circuits.json +++ b/noir-projects/mega_honk_circuits.json @@ -1,4 +1,3 @@ [ - "private_kernel.*", - "empty_nested" + "private_kernel.*" ] \ No newline at end of file diff --git a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_parity_input.nr b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_parity_input.nr index 61c896981912..c84e6436f19f 100644 --- a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_parity_input.nr +++ b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_parity_input.nr @@ -1,13 +1,13 @@ use dep::types::{ traits::Empty, - recursion::{verification_key::VerificationKey, proof::RecursiveProof, traits::Verifiable}, + recursion::{verification_key::{VerificationKey, HonkVerificationKey}, proof::RecursiveProof, traits::Verifiable}, constants::{BASE_PARITY_INDEX, VK_TREE_HEIGHT}, merkle_tree::membership::assert_check_membership }; use crate::parity_public_inputs::ParityPublicInputs; pub struct RootParityInput { proof: RecursiveProof, - verification_key: VerificationKey, + verification_key: HonkVerificationKey, vk_path: [Field; VK_TREE_HEIGHT], public_inputs: ParityPublicInputs, } diff --git a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_rollup_parity_input.nr b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_rollup_parity_input.nr index b41567543782..d2686645431e 100644 --- a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_rollup_parity_input.nr +++ b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_rollup_parity_input.nr @@ -1,13 +1,13 @@ use dep::types::{ traits::Empty, - recursion::{verification_key::VerificationKey, proof::NestedRecursiveProof, traits::Verifiable}, + recursion::{verification_key::{VerificationKey, HonkVerificationKey}, proof::NestedRecursiveProof, traits::Verifiable}, constants::{ROOT_PARITY_INDEX, VK_TREE_HEIGHT}, merkle_tree::membership::assert_check_membership }; use crate::parity_public_inputs::ParityPublicInputs; pub struct RootRollupParityInput { proof: NestedRecursiveProof, - verification_key: VerificationKey, + verification_key: HonkVerificationKey, vk_path: [Field; VK_TREE_HEIGHT], public_inputs: ParityPublicInputs, } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_empty.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_empty.nr index a46cae38e692..2456ea790627 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_empty.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_empty.nr @@ -1,11 +1,11 @@ use dep::types::{ header::Header, KernelCircuitPublicInputs, traits::Empty, - recursion::{verification_key::VerificationKey, proof::RecursiveProof, traits::Verifiable} + recursion::{verification_key::{VerificationKey, HonkVerificationKey}, proof::RecursiveProof, traits::Verifiable} }; pub struct EmptyNestedCircuitPublicInputs { proof: RecursiveProof, - vk: VerificationKey, + vk: HonkVerificationKey, } impl Verifiable for EmptyNestedCircuitPublicInputs { diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr index b235ce5de9a5..eb6ea141b037 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr @@ -1,7 +1,7 @@ use crate::abis::block_root_or_block_merge_public_inputs::BlockRootOrBlockMergePublicInputs; use dep::types::{ constants::VK_TREE_HEIGHT, - recursion::{proof::NestedRecursiveProof, verification_key::VerificationKey, traits::Verifiable}, + recursion::{proof::NestedRecursiveProof, verification_key::{HonkVerificationKey, VerificationKey}, traits::Verifiable}, traits::Empty, merkle_tree::MembershipWitness, merkle_tree::membership::assert_check_membership, utils::arrays::find_index_hint }; @@ -9,7 +9,7 @@ use dep::types::{ pub struct PreviousRollupBlockData { block_root_or_block_merge_public_inputs: BlockRootOrBlockMergePublicInputs, proof: NestedRecursiveProof, - vk: VerificationKey, + vk: HonkVerificationKey, vk_witness: MembershipWitness<VK_TREE_HEIGHT>, } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr index e2d3be7dc419..8a71fe201c5c 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr @@ -1,7 +1,7 @@ use crate::abis::base_or_merge_rollup_public_inputs::BaseOrMergeRollupPublicInputs; use dep::types::{ constants::VK_TREE_HEIGHT, - recursion::{proof::NestedRecursiveProof, verification_key::VerificationKey, traits::Verifiable}, + recursion::{proof::NestedRecursiveProof, verification_key::{VerificationKey, HonkVerificationKey}, traits::Verifiable}, traits::Empty, merkle_tree::MembershipWitness, merkle_tree::membership::assert_check_membership, utils::arrays::find_index_hint }; @@ -9,7 +9,7 @@ use dep::types::{ pub struct PreviousRollupData{ base_or_merge_rollup_public_inputs : BaseOrMergeRollupPublicInputs, proof : NestedRecursiveProof, - vk : VerificationKey, + vk : HonkVerificationKey, vk_witness : MembershipWitness<VK_TREE_HEIGHT>, } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr index 82934bf83600..059d68b8742f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr @@ -1,14 +1,14 @@ use crate::{ - abis::kernel_circuit_public_inputs::KernelCircuitPublicInputs, constants::VK_TREE_HEIGHT, + abis::kernel_circuit_public_inputs::KernelCircuitPublicInputs, constants::{VK_TREE_HEIGHT}, merkle_tree::membership::assert_check_membership, - recursion::{proof::NestedRecursiveProof, verification_key::VerificationKey, traits::Verifiable}, + recursion::{proof::NestedRecursiveProof, verification_key::HonkVerificationKey, traits::Verifiable}, utils::arrays::find_index_hint }; pub struct KernelData { public_inputs: KernelCircuitPublicInputs, proof: NestedRecursiveProof, - vk: VerificationKey, + vk: HonkVerificationKey, vk_index: u32, vk_path: [Field; VK_TREE_HEIGHT], } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr index d42e3f55fa17..618607ea8b1e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr @@ -5,13 +5,13 @@ use crate::{ }, address::{SaltedInitializationHash, PublicKeysHash}, constants::{FUNCTION_TREE_HEIGHT, PROTOCOL_CONTRACT_TREE_HEIGHT}, - merkle_tree::membership::MembershipWitness, recursion::{verification_key::VerificationKey} + merkle_tree::membership::MembershipWitness, recursion::{verification_key::ClientIVCVerificationKey} }; pub struct PrivateCallData { call_stack_item: PrivateCallStackItem, - vk: VerificationKey, + vk: ClientIVCVerificationKey, salted_initialization_hash: SaltedInitializationHash, public_keys_hash: PublicKeysHash, @@ -26,7 +26,7 @@ pub struct PrivateCallData { pub struct PrivateCallDataWithoutPublicInputs { call_stack_item: PrivateCallStackItemWithoutPublicInputs, - vk: VerificationKey, + vk: ClientIVCVerificationKey, salted_initialization_hash: SaltedInitializationHash, public_keys_hash: PublicKeysHash, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr index 1fe3479fd803..6ea5cbbb435d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr @@ -1,13 +1,13 @@ use crate::{ abis::kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs, constants::{PRIVATE_KERNEL_RESET_INDEX, VK_TREE_HEIGHT}, - merkle_tree::membership::assert_check_membership, recursion::{verification_key::VerificationKey}, + merkle_tree::membership::assert_check_membership, recursion::{verification_key::ClientIVCVerificationKey}, utils::arrays::find_index_hint }; pub struct PrivateKernelData { public_inputs: PrivateKernelCircuitPublicInputs, - vk: VerificationKey, + vk: ClientIVCVerificationKey, vk_index: u32, vk_path: [Field; VK_TREE_HEIGHT], } @@ -35,7 +35,7 @@ impl PrivateKernelData { } pub struct PrivateKernelDataWithoutPublicInputs { - vk: VerificationKey, + vk: ClientIVCVerificationKey, vk_index: u32, vk_path: [Field; VK_TREE_HEIGHT], } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr index 050a092d29e4..dbf9da3519f0 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr @@ -1,14 +1,14 @@ use crate::{ - abis::kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs, constants::VK_TREE_HEIGHT, + abis::kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs, constants::{VK_TREE_HEIGHT}, merkle_tree::membership::assert_check_membership, - recursion::{proof::NestedRecursiveProof, verification_key::VerificationKey, traits::Verifiable}, + recursion::{proof::NestedRecursiveProof, verification_key::HonkVerificationKey, traits::Verifiable}, utils::arrays::find_index_hint }; pub struct PublicKernelData { public_inputs: PublicKernelCircuitPublicInputs, proof: NestedRecursiveProof, - vk: VerificationKey, + vk: HonkVerificationKey, vk_index: u32, vk_path: [Field; VK_TREE_HEIGHT], } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_inner_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_inner_data.nr index 7986b55cbc14..48c0aa0560eb 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_inner_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_inner_data.nr @@ -1,12 +1,13 @@ use crate::{ abis::kernel_circuit_public_inputs::VMCircuitPublicInputs, - recursion::{proof::NestedRecursiveProof, verification_key::VerificationKey, traits::Verifiable} + recursion::{proof::NestedRecursiveProof, verification_key::HonkVerificationKey, traits::Verifiable}, + }; pub struct PublicKernelInnerData { public_inputs: VMCircuitPublicInputs, proof: NestedRecursiveProof, - vk: VerificationKey, + vk: HonkVerificationKey, } impl Verifiable for PublicKernelInnerData { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index d071be58d086..7710ed1a33b4 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -316,7 +316,9 @@ global RECURSIVE_PROOF_LENGTH: u32= 463; global NESTED_RECURSIVE_PROOF_LENGTH: u32= 463; global TUBE_PROOF_LENGTH: u32 = RECURSIVE_PROOF_LENGTH; // in the future these can differ -global VERIFICATION_KEY_LENGTH_IN_FIELDS: u32 = 128; +global HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS: u32 = 128; + +global CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS: u32 = 145; // VK is composed of // - circuit size encoded as a fr field element (32 bytes) // - num of inputs encoded as a fr field element (32 bytes) diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr index ec4ca57fc12a..3b6e5de23127 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr @@ -131,7 +131,7 @@ pub fn merkle_hash(left: Field, right: Field) -> Field { poseidon2_hash([left, right]) } -pub fn stdlib_recursion_verification_key_compress_native_vk(_vk: VerificationKey) -> Field { +pub fn stdlib_recursion_verification_key_compress_native_vk<let N: u32>(_vk: VerificationKey<N>) -> Field { // Original cpp code // stdlib::recursion::verification_key<CT::bn254>::compress_native(private_call.vk, GeneratorIndex::VK); // The above cpp method is only ever called on verification key, so it has been special cased here diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr b/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr index e2b21da3bb34..49c00b4cf566 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr @@ -1,49 +1,50 @@ -use crate::{traits::{Serialize, Deserialize, Empty}, constants::VERIFICATION_KEY_LENGTH_IN_FIELDS}; +use crate::{traits::{Serialize, Deserialize, Empty}, constants::{HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS}}; -global SERIALIZED_VERIFICATION_KEY_LENGTH: u32 = VERIFICATION_KEY_LENGTH_IN_FIELDS + 1; - -pub struct VerificationKey { - key: [Field; VERIFICATION_KEY_LENGTH_IN_FIELDS], +pub struct VerificationKey<let N: u32> { + key: [Field; N], hash: Field, } -impl Serialize<SERIALIZED_VERIFICATION_KEY_LENGTH> for VerificationKey { - fn serialize(self) -> [Field; SERIALIZED_VERIFICATION_KEY_LENGTH] { - let mut fields = [0; SERIALIZED_VERIFICATION_KEY_LENGTH]; - for i in 0..VERIFICATION_KEY_LENGTH_IN_FIELDS { +impl<let N: u32> Serialize<N + 1> for VerificationKey<N> { + fn serialize(self) -> [Field; N + 1] { + let mut fields = [0; N+1]; + for i in 0..N { fields[i] = self.key[i]; } - fields[VERIFICATION_KEY_LENGTH_IN_FIELDS] = self.hash; + fields[N] = self.hash; fields } } -impl Deserialize<SERIALIZED_VERIFICATION_KEY_LENGTH> for VerificationKey { - fn deserialize(fields: [Field; SERIALIZED_VERIFICATION_KEY_LENGTH]) -> Self { +impl<let N: u32> Deserialize<N + 1> for VerificationKey<N> { + fn deserialize(fields: [Field; N+1]) -> Self { let mut key = VerificationKey::empty(); - for i in 0..VERIFICATION_KEY_LENGTH_IN_FIELDS { + for i in 0..N { key.key[i] = fields[i]; } - key.hash = fields[VERIFICATION_KEY_LENGTH_IN_FIELDS]; + key.hash = fields[N]; key } } -impl Empty for VerificationKey { +impl<let N: u32> Empty for VerificationKey<N> { fn empty() -> Self { - VerificationKey { hash: 0, key: [0; VERIFICATION_KEY_LENGTH_IN_FIELDS] } + VerificationKey { hash: 0, key: [0; N] } } } -impl Eq for VerificationKey { +impl<let N: u32> Eq for VerificationKey<N> { fn eq(self, other: Self) -> bool { (self.hash == other.hash) & (self.key == other.key) } } +type HonkVerificationKey = VerificationKey<HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS>; +type ClientIVCVerificationKey = VerificationKey<CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS>; + #[test] fn serialization_of_empty() { - let key = VerificationKey::empty(); + let key: VerificationKey<20> = VerificationKey::empty(); let serialized = key.serialize(); let deserialized = VerificationKey::deserialize(serialized); assert(key.eq(deserialized)); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr index 254d36795b39..e8e3a1111a0d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr @@ -52,7 +52,7 @@ use crate::{ partial_state_reference::PartialStateReference, tests::{fixtures, fixtures::{contracts::ContractData, contract_functions::ContractFunction}}, transaction::{tx_context::TxContext, tx_request::TxRequest}, traits::Empty, - recursion::{verification_key::VerificationKey, proof::NestedRecursiveProof}, point::Point + recursion::{verification_key::{HonkVerificationKey, ClientIVCVerificationKey, VerificationKey}, proof::NestedRecursiveProof}, point::Point }; fn subarray<T, let N: u32, let M: u32>(arr: [T; N]) -> [T; M] { @@ -147,7 +147,8 @@ pub struct FixtureBuilder { // Proof. proof: NestedRecursiveProof, - vk: VerificationKey, + honk_vk: HonkVerificationKey, + client_ivc_vk: ClientIVCVerificationKey, vk_index: u32, vk_path: [Field; VK_TREE_HEIGHT], vk_tree_root: Field, @@ -199,7 +200,8 @@ impl FixtureBuilder { let vk_tree = fixtures::vk_tree::get_vk_merkle_tree(); let vk_hash = vk_tree.leaves[vk_index]; - self.vk.hash = vk_hash; + self.honk_vk.hash = vk_hash; + self.client_ivc_vk.hash = vk_hash; self.vk_path = vk_tree.get_sibling_path(vk_index); @@ -352,7 +354,7 @@ impl FixtureBuilder { pub fn to_private_call_data(self) -> PrivateCallData { PrivateCallData { call_stack_item: self.to_private_call_stack_item(), - vk: self.vk, + vk: self.client_ivc_vk, function_leaf_membership_witness: self.function_leaf_membership_witness, salted_initialization_hash: self.salted_initialization_hash, public_keys_hash: self.public_keys_hash, @@ -477,7 +479,7 @@ impl FixtureBuilder { pub fn to_private_kernel_data(self) -> PrivateKernelData { let public_inputs = self.to_private_kernel_circuit_public_inputs(); - PrivateKernelData { public_inputs, vk: self.vk, vk_index: self.vk_index, vk_path: self.vk_path } + PrivateKernelData { public_inputs, vk: self.client_ivc_vk, vk_index: self.vk_index, vk_path: self.vk_path } } pub fn to_public_circuit_public_inputs(self) -> PublicCircuitPublicInputs { @@ -586,7 +588,7 @@ impl FixtureBuilder { pub fn to_public_kernel_data(self, revertible: bool) -> PublicKernelData { let public_inputs = self.to_public_kernel_circuit_public_inputs(revertible); - PublicKernelData { public_inputs, proof: self.proof, vk: self.vk, vk_index: self.vk_index, vk_path: self.vk_path } + PublicKernelData { public_inputs, proof: self.proof, vk: self.honk_vk, vk_index: self.vk_index, vk_path: self.vk_path } } pub fn to_rollup_validation_requests(self) -> RollupValidationRequests { @@ -613,7 +615,7 @@ impl FixtureBuilder { KernelData { public_inputs, proof: NestedRecursiveProof::empty(), - vk: self.vk, + vk: self.honk_vk, vk_index: self.vk_index, vk_path: self.vk_path } @@ -1264,7 +1266,8 @@ impl Empty for FixtureBuilder { bytecode_hash: 0, prover_address: AztecAddress::zero(), proof: NestedRecursiveProof::empty(), - vk: VerificationKey::empty(), + honk_vk: VerificationKey::empty(), + client_ivc_vk: VerificationKey::empty(), vk_index: 0, vk_path: [0; VK_TREE_HEIGHT], vk_tree_root: FixtureBuilder::vk_tree_root(), diff --git a/noir-projects/scripts/generate_vk_json.js b/noir-projects/scripts/generate_vk_json.js index 6f4c6a3da88d..07778e0ccc79 100644 --- a/noir-projects/scripts/generate_vk_json.js +++ b/noir-projects/scripts/generate_vk_json.js @@ -110,11 +110,9 @@ async function hasArtifactHashChanged(artifactHash, vkDataPath) { } function isMegaHonkCircuit(artifactName) { - // TODO Uncomment when mega honk vks are supported in the protocol - // return megaHonkPatterns.some((pattern) => - // artifactName.match(new RegExp(pattern)) - // ); - return false; + return megaHonkPatterns.some((pattern) => + artifactName.match(new RegExp(pattern)) + ); } async function processArtifact( diff --git a/yarn-project/bb-prover/src/test/test_circuit_prover.ts b/yarn-project/bb-prover/src/test/test_circuit_prover.ts index 2bae23f7f633..d7a619849a73 100644 --- a/yarn-project/bb-prover/src/test/test_circuit_prover.ts +++ b/yarn-project/bb-prover/src/test/test_circuit_prover.ts @@ -15,6 +15,7 @@ import { type BlockRootRollupInputs, type EmptyBlockRootRollupInputs, EmptyNestedData, + HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, type KernelCircuitPublicInputs, type MergeRollupInputs, NESTED_RECURSIVE_PROOF_LENGTH, @@ -155,7 +156,7 @@ export class TestCircuitProver implements ServerCircuitProver { return makePublicInputsAndRecursiveProof( result, makeRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), ); } @@ -276,7 +277,7 @@ export class TestCircuitProver implements ServerCircuitProver { ): Promise<{ tubeVK: VerificationKeyData; tubeProof: RecursiveProof<typeof TUBE_PROOF_LENGTH> }> { await this.delay(); return { - tubeVK: VerificationKeyData.makeFake(), + tubeVK: VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), tubeProof: makeEmptyRecursiveProof(TUBE_PROOF_LENGTH), }; } diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index f4e52e52580a..6f2080bd6ff2 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -211,7 +211,8 @@ export const NUM_BASE_PARITY_PER_ROOT_PARITY = 4; export const RECURSIVE_PROOF_LENGTH = 463; export const NESTED_RECURSIVE_PROOF_LENGTH = 463; export const TUBE_PROOF_LENGTH = 463; -export const VERIFICATION_KEY_LENGTH_IN_FIELDS = 128; +export const HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS = 128; +export const CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS = 145; export const AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS = 66; export const AVM_PROOF_LENGTH_IN_FIELDS = 3822; export const AVM_PUBLIC_COLUMN_MAX_SIZE = 1024; diff --git a/yarn-project/circuits.js/src/structs/kernel/kernel_data.ts b/yarn-project/circuits.js/src/structs/kernel/kernel_data.ts index 855ad7f8866a..b914f37e7e8d 100644 --- a/yarn-project/circuits.js/src/structs/kernel/kernel_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/kernel_data.ts @@ -2,7 +2,7 @@ import { makeTuple } from '@aztec/foundation/array'; import { Fr } from '@aztec/foundation/fields'; import { BufferReader, type Tuple, serializeToBuffer } from '@aztec/foundation/serialize'; -import { RECURSIVE_PROOF_LENGTH, VK_TREE_HEIGHT } from '../../constants.gen.js'; +import { HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, RECURSIVE_PROOF_LENGTH, VK_TREE_HEIGHT } from '../../constants.gen.js'; import { RecursiveProof, makeEmptyRecursiveProof } from '../recursive_proof.js'; import { type UInt32 } from '../shared.js'; import { VerificationKeyData } from '../verification_key.js'; @@ -37,7 +37,7 @@ export class KernelData { return new this( KernelCircuitPublicInputs.empty(), makeEmptyRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), 0, makeTuple(VK_TREE_HEIGHT, Fr.zero), ); diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_data.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_data.ts index 33bced5e4d54..049d51c84332 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_data.ts @@ -2,7 +2,7 @@ import { makeTuple } from '@aztec/foundation/array'; import { Fr } from '@aztec/foundation/fields'; import { BufferReader, type Tuple, serializeToBuffer } from '@aztec/foundation/serialize'; -import { VK_TREE_HEIGHT } from '../../constants.gen.js'; +import { CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS, VK_TREE_HEIGHT } from '../../constants.gen.js'; import { type UInt32 } from '../shared.js'; import { VerificationKeyAsFields } from '../verification_key.js'; import { PrivateKernelCircuitPublicInputs } from './private_kernel_circuit_public_inputs.js'; @@ -53,7 +53,7 @@ export class PrivateKernelData { static empty(): PrivateKernelData { return new PrivateKernelData( PrivateKernelCircuitPublicInputs.empty(), - VerificationKeyAsFields.makeFake(), + VerificationKeyAsFields.makeFake(CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS), 0, makeTuple(VK_TREE_HEIGHT, Fr.zero), ); diff --git a/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts b/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts index 7a1608f9a8e2..55acb8a7c7fd 100644 --- a/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts @@ -2,7 +2,11 @@ import { makeTuple } from '@aztec/foundation/array'; import { Fr } from '@aztec/foundation/fields'; import { BufferReader, type Tuple, serializeToBuffer } from '@aztec/foundation/serialize'; -import { NESTED_RECURSIVE_PROOF_LENGTH, VK_TREE_HEIGHT } from '../../constants.gen.js'; +import { + HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, + NESTED_RECURSIVE_PROOF_LENGTH, + VK_TREE_HEIGHT, +} from '../../constants.gen.js'; import { ClientIvcProof } from '../client_ivc_proof.js'; import { RecursiveProof, makeEmptyRecursiveProof } from '../recursive_proof.js'; import { type UInt32 } from '../shared.js'; @@ -57,7 +61,7 @@ export class PublicKernelData { return new this( PublicKernelCircuitPublicInputs.empty(), makeEmptyRecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>(NESTED_RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), 0, makeTuple(VK_TREE_HEIGHT, Fr.zero), ClientIvcProof.empty(), diff --git a/yarn-project/circuits.js/src/structs/kernel/public_kernel_inner_data.ts b/yarn-project/circuits.js/src/structs/kernel/public_kernel_inner_data.ts index 59bc665ea667..754516841016 100644 --- a/yarn-project/circuits.js/src/structs/kernel/public_kernel_inner_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/public_kernel_inner_data.ts @@ -1,6 +1,6 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; -import { NESTED_RECURSIVE_PROOF_LENGTH } from '../../constants.gen.js'; +import { HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, NESTED_RECURSIVE_PROOF_LENGTH } from '../../constants.gen.js'; import { RecursiveProof, makeEmptyRecursiveProof } from '../recursive_proof.js'; import { VerificationKeyData } from '../verification_key.js'; import { VMCircuitPublicInputs } from './vm_circuit_public_inputs.js'; @@ -37,7 +37,7 @@ export class PublicKernelInnerData { return new this( VMCircuitPublicInputs.empty(), makeEmptyRecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>(NESTED_RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), ); } diff --git a/yarn-project/circuits.js/src/structs/verification_key.test.ts b/yarn-project/circuits.js/src/structs/verification_key.test.ts index d96c07a4e34b..6b73b08e7773 100644 --- a/yarn-project/circuits.js/src/structs/verification_key.test.ts +++ b/yarn-project/circuits.js/src/structs/verification_key.test.ts @@ -1,8 +1,9 @@ +import { HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS } from '../constants.gen.js'; import { VerificationKey, VerificationKeyAsFields, VerificationKeyData } from './verification_key.js'; describe('structs/verification_key_as_fields', () => { it(`can serialise and deserialise a verification key as fields`, () => { - const vk = VerificationKeyAsFields.makeFake(); + const vk = VerificationKeyAsFields.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS); const serialised = vk.toBuffer(); const deserialised = VerificationKeyAsFields.fromBuffer(serialised); expect(vk).toEqual(deserialised); @@ -20,7 +21,7 @@ describe('structs/verification_key', () => { describe('structs/verification_key_data', () => { it(`can serialise and deserialise a verification key data`, () => { - const vk = VerificationKeyData.makeFake(); + const vk = VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS); const serialised = vk.toBuffer(); const deserialised = VerificationKeyData.fromBuffer(serialised); expect(vk).toEqual(deserialised); diff --git a/yarn-project/circuits.js/src/structs/verification_key.ts b/yarn-project/circuits.js/src/structs/verification_key.ts index 9b927bc834df..a85d02716672 100644 --- a/yarn-project/circuits.js/src/structs/verification_key.ts +++ b/yarn-project/circuits.js/src/structs/verification_key.ts @@ -5,7 +5,7 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { strict as assert } from 'assert'; -import { AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS, VERIFICATION_KEY_LENGTH_IN_FIELDS } from '../constants.gen.js'; +import { AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS } from '../constants.gen.js'; import { CircuitType } from './shared.js'; /** @@ -124,16 +124,16 @@ export class VerificationKeyAsFields { * Builds a fake verification key that should be accepted by circuits. * @returns A fake verification key. */ - static makeFake(seed = 1): VerificationKeyAsFields { - return new VerificationKeyAsFields(makeTuple(VERIFICATION_KEY_LENGTH_IN_FIELDS, Fr.random, seed), Fr.random()); + static makeFake(size: number, seed = 1): VerificationKeyAsFields { + return new VerificationKeyAsFields(makeTuple(size, Fr.random, seed), Fr.random()); } /** * Builds an 'empty' verification key * @returns An 'empty' verification key */ - static makeEmpty(): VerificationKeyAsFields { - return new VerificationKeyAsFields(makeTuple(VERIFICATION_KEY_LENGTH_IN_FIELDS, Fr.zero), Fr.zero()); + static makeEmpty(size: number): VerificationKeyAsFields { + return new VerificationKeyAsFields(makeTuple(size, Fr.zero), Fr.zero()); } } @@ -292,8 +292,11 @@ export class VerificationKeyData { return this.keyAsFields.isRecursive; } - static makeFake(): VerificationKeyData { - return new VerificationKeyData(VerificationKeyAsFields.makeFake(), VerificationKey.makeFake().toBuffer()); + static makeFake(sizeInFields: number): VerificationKeyData { + return new VerificationKeyData( + VerificationKeyAsFields.makeFake(sizeInFields), + VerificationKey.makeFake().toBuffer(), + ); } /** diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 9b39e39720b7..96763dd1704e 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -36,6 +36,7 @@ import { FunctionData, FunctionSelector, GrumpkinScalar, + HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, KeyValidationRequest, KeyValidationRequestAndGenerator, L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, @@ -600,8 +601,8 @@ export function makeMembershipWitness<N extends number>(size: N, start: number): * Creates arbitrary/mocked verification key in fields format. * @returns A verification key as fields object */ -export function makeVerificationKeyAsFields(): VerificationKeyAsFields { - return VerificationKeyAsFields.makeFake(); +export function makeVerificationKeyAsFields(size: number): VerificationKeyAsFields { + return VerificationKeyAsFields.makeFake(size); } /** @@ -640,7 +641,7 @@ export function makePublicKernelData(seed = 1, kernelPublicInputs?: PublicKernel return new PublicKernelData( kernelPublicInputs ?? makePublicKernelCircuitPublicInputs(seed, true), makeRecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>(NESTED_RECURSIVE_PROOF_LENGTH, seed + 0x80), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), 0x42, makeTuple(VK_TREE_HEIGHT, fr, 0x1000), ); @@ -656,7 +657,7 @@ export function makeRollupKernelData(seed = 1, kernelPublicInputs?: KernelCircui return new KernelData( kernelPublicInputs ?? makeKernelCircuitPublicInputs(seed, true), makeRecursiveProof<typeof TUBE_PROOF_LENGTH>(TUBE_PROOF_LENGTH, seed + 0x80), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), 0x42, makeTuple(VK_TREE_HEIGHT, fr, 0x1000), ); @@ -735,7 +736,7 @@ function makePublicKernelInnerData(seed = 1) { return new PublicKernelInnerData( makeVMCircuitPublicInputs(seed), makeRecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>(NESTED_RECURSIVE_PROOF_LENGTH, seed + 0x100), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), ); } @@ -994,7 +995,7 @@ export function makePreviousRollupData( return new PreviousRollupData( makeBaseOrMergeRollupPublicInputs(seed, globalVariables), makeRecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>(NESTED_RECURSIVE_PROOF_LENGTH, seed + 0x50), - VerificationKeyAsFields.makeFake(), + VerificationKeyAsFields.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), makeMembershipWitness(VK_TREE_HEIGHT, seed + 0x120), ); } @@ -1012,7 +1013,7 @@ export function makePreviousRollupBlockData( return new PreviousRollupBlockData( makeBlockRootOrBlockMergeRollupPublicInputs(seed, globalVariables), makeRecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>(NESTED_RECURSIVE_PROOF_LENGTH, seed + 0x50), - VerificationKeyAsFields.makeFake(), + VerificationKeyAsFields.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), makeMembershipWitness(VK_TREE_HEIGHT, seed + 0x120), ); } diff --git a/yarn-project/noir-protocol-circuits-types/package.json b/yarn-project/noir-protocol-circuits-types/package.json index 909ce8f37bfc..9f5c57ee8c7c 100644 --- a/yarn-project/noir-protocol-circuits-types/package.json +++ b/yarn-project/noir-protocol-circuits-types/package.json @@ -16,8 +16,10 @@ "formatting": "run -T prettier --check ./src && run -T eslint ./src", "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src", "formatting:fix:types": "NODE_OPTIONS='--max-old-space-size=8096' run -T eslint --fix ./src/types && run -T prettier -w ./src/types", - "generate": "yarn generate:noir-circuits && yarn generate:reset-data", - "generate:noir-circuits": "mkdir -p ./artifacts && cp -r ../../noir-projects/noir-protocol-circuits/target/* ./artifacts && node --no-warnings --loader ts-node/esm src/scripts/generate_declaration_files.ts && node --no-warnings --loader ts-node/esm src/scripts/generate_ts_from_abi.ts && run -T prettier -w ./src/types", + "generate": "yarn generate:copy-artifacts && yarn generate:vk-hashes && yarn generate:noir-circuits && yarn generate:reset-data", + "generate:copy-artifacts": "mkdir -p ./artifacts && cp -r ../../noir-projects/noir-protocol-circuits/target/* ./artifacts && node --no-warnings --loader ts-node/esm src/scripts/generate_declaration_files.ts ", + "generate:vk-hashes": "node --no-warnings --loader ts-node/esm src/scripts/generate_vk_hashes.ts", + "generate:noir-circuits": "node --no-warnings --loader ts-node/esm src/scripts/generate_ts_from_abi.ts && run -T prettier -w ./src/types", "generate:reset-data": "node --no-warnings --loader ts-node/esm src/scripts/generate_private_kernel_reset_data.ts && run -T prettier -w src/private_kernel_reset_data.ts", "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests", "codegen": "yarn noir-codegen", diff --git a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_declaration_files.ts b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_declaration_files.ts index 5a3cd7557fd9..2b6a9ed14426 100644 --- a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_declaration_files.ts +++ b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_declaration_files.ts @@ -10,7 +10,7 @@ export = circuit; `; const vk = `\ -const vk: { keyAsBytes: string; keyAsFields: string[] }; +const vk: { keyAsBytes: string; keyAsFields: string[], vkHash: string }; export = vk; `; diff --git a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_ts_from_abi.ts b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_ts_from_abi.ts index 7cf03712bd1b..7d437c85ff76 100644 --- a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_ts_from_abi.ts +++ b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_ts_from_abi.ts @@ -5,7 +5,7 @@ import { type CompiledCircuit } from '@noir-lang/types'; import { pascalCase } from 'change-case'; import fs from 'fs/promises'; -const log = createConsoleLogger('aztec:noir-contracts'); +const log = createConsoleLogger('aztec:autogenerate'); const circuits = [ 'parity_base', diff --git a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts new file mode 100644 index 000000000000..0dccc3e62dd6 --- /dev/null +++ b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts @@ -0,0 +1,40 @@ +import { Fr } from '@aztec/circuits.js'; +import { poseidon2Hash } from '@aztec/foundation/crypto'; +import { createConsoleLogger } from '@aztec/foundation/log'; +import { fileURLToPath } from '@aztec/foundation/url'; + +import fs from 'fs/promises'; +import { join } from 'path'; + +const log = createConsoleLogger('aztec:autogenerate'); + +function resolveRelativePath(relativePath: string) { + return fileURLToPath(new URL(relativePath, import.meta.url).href); +} + +function hashVk(keyAsFields: string[]): string { + const keyAsFrs = keyAsFields.map((str: string) => Fr.fromString(str)); + return poseidon2Hash(keyAsFrs).toString(); +} + +const main = async () => { + const files = await fs.readdir(resolveRelativePath('../../artifacts/keys')); + for (const fileName of files) { + if (fileName.endsWith('.vk.data.json')) { + const keyPath = join(resolveRelativePath(`../../artifacts/keys`), fileName); + const content = JSON.parse(await fs.readFile(keyPath, 'utf-8')); + if (!content.vkHash) { + const { keyAsFields } = content; + content.vkHash = hashVk(keyAsFields); + await fs.writeFile(keyPath, JSON.stringify(content, null, 2)); + } + } + } +}; + +try { + await main(); +} catch (err: unknown) { + log(`Error generating types ${err}`); + process.exit(1); +} diff --git a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts index 9f03cc2fc5fd..31a9b2e53886 100644 --- a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts +++ b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts @@ -8,6 +8,7 @@ import { type BlockMergeRollupInputs, BlockRootOrBlockMergePublicInputs, type BlockRootRollupInputs, + CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS, CallContext, CombinedAccumulatedData, CombinedConstantData, @@ -29,6 +30,7 @@ import { GasSettings, GlobalVariables, GrumpkinScalar, + HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, Header, KernelCircuitPublicInputs, type KernelData, @@ -136,7 +138,6 @@ import { type TreeLeafReadRequestHint, TxContext, type TxRequest, - VERIFICATION_KEY_LENGTH_IN_FIELDS, VMCircuitPublicInputs, type VerificationKeyAsFields, } from '@aztec/circuits.js'; @@ -1006,7 +1007,7 @@ export function mapPrivateCallStackItemToNoir( export function mapPrivateCallDataToNoir(privateCallData: PrivateCallData): PrivateCallDataWithoutPublicInputsNoir { return { call_stack_item: mapPrivateCallStackItemToNoir(privateCallData.callStackItem), - vk: mapVerificationKeyToNoir(privateCallData.vk), + vk: mapVerificationKeyToNoir(privateCallData.vk, CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS), function_leaf_membership_witness: mapMembershipWitnessToNoir(privateCallData.functionLeafMembershipWitness), contract_class_artifact_hash: mapFieldToNoir(privateCallData.contractClassArtifactHash), contract_class_public_bytecode_commitment: mapFieldToNoir(privateCallData.contractClassPublicBytecodeCommitment), @@ -1642,7 +1643,7 @@ function mapPublicKernelDataToNoir(publicKernelData: PublicKernelData): PublicKe return { public_inputs: mapPublicKernelCircuitPublicInputsToNoir(publicKernelData.publicInputs), proof: mapRecursiveProofToNoir<typeof NESTED_RECURSIVE_PROOF_LENGTH>(publicKernelData.proof), - vk: mapVerificationKeyToNoir(publicKernelData.vk.keyAsFields), + vk: mapVerificationKeyToNoir(publicKernelData.vk.keyAsFields, HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), vk_index: mapFieldToNoir(new Fr(publicKernelData.vkIndex)), vk_path: mapTuple(publicKernelData.vkPath, mapFieldToNoir), }; @@ -1652,7 +1653,7 @@ function mapPublicKernelInnerDataToNoir(publicKernelData: PublicKernelInnerData) return { public_inputs: mapVMCircuitPublicInputsToNoir(publicKernelData.publicInputs), proof: mapRecursiveProofToNoir<typeof NESTED_RECURSIVE_PROOF_LENGTH>(publicKernelData.proof), - vk: mapVerificationKeyToNoir(publicKernelData.vk.keyAsFields), + vk: mapVerificationKeyToNoir(publicKernelData.vk.keyAsFields, HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), }; } @@ -1660,18 +1661,21 @@ function mapKernelDataToNoir(kernelData: KernelData): KernelDataNoir { return { public_inputs: mapKernelCircuitPublicInputsToNoir(kernelData.publicInputs), proof: mapRecursiveProofToNoir<typeof NESTED_RECURSIVE_PROOF_LENGTH>(kernelData.proof), - vk: mapVerificationKeyToNoir(kernelData.vk.keyAsFields), + vk: mapVerificationKeyToNoir(kernelData.vk.keyAsFields, HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), vk_index: mapFieldToNoir(new Fr(kernelData.vkIndex)), vk_path: mapTuple(kernelData.vkPath, mapFieldToNoir), }; } -export function mapVerificationKeyToNoir(key: VerificationKeyAsFields): VerificationKeyNoir { - if (key.key.length !== VERIFICATION_KEY_LENGTH_IN_FIELDS) { - throw new Error(`Expected ${VERIFICATION_KEY_LENGTH_IN_FIELDS} fields, got ${key.key.length}`); +export function mapVerificationKeyToNoir<N extends number>( + key: VerificationKeyAsFields, + length: N, +): VerificationKeyNoir<N> { + if (key.key.length !== length) { + throw new Error(`Expected ${length} fields, got ${key.key.length}`); } return { - key: mapTuple(key.key as Tuple<Fr, typeof VERIFICATION_KEY_LENGTH_IN_FIELDS>, mapFieldToNoir), + key: key.key.map(mapFieldToNoir) as FixedLengthArray<NoirField, N>, hash: mapFieldToNoir(key.hash), }; } @@ -1711,7 +1715,7 @@ export function mapPrivateKernelDataToNoir( privateKernelInnerData: PrivateKernelData, ): PrivateKernelDataWithoutPublicInputsNoir { return { - vk: mapVerificationKeyToNoir(privateKernelInnerData.vk), + vk: mapVerificationKeyToNoir(privateKernelInnerData.vk, CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS), vk_index: mapFieldToNoir(new Fr(privateKernelInnerData.vkIndex)), vk_path: mapTuple(privateKernelInnerData.vkPath, mapFieldToNoir), }; @@ -2168,7 +2172,7 @@ export function mapPreviousRollupDataToNoir(previousRollupData: PreviousRollupDa previousRollupData.baseOrMergeRollupPublicInputs, ), proof: mapRecursiveProofToNoir(previousRollupData.proof), - vk: mapVerificationKeyToNoir(previousRollupData.vk), + vk: mapVerificationKeyToNoir(previousRollupData.vk, HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), vk_witness: { leaf_index: mapFieldToNoir(new Fr(previousRollupData.vkWitness.leafIndex)), sibling_path: mapTuple(previousRollupData.vkWitness.siblingPath, mapFieldToNoir), @@ -2189,7 +2193,7 @@ export function mapPreviousRollupBlockDataToNoir( previousRollupData.blockRootOrBlockMergePublicInputs, ), proof: mapRecursiveProofToNoir(previousRollupData.proof), - vk: mapVerificationKeyToNoir(previousRollupData.vk), + vk: mapVerificationKeyToNoir(previousRollupData.vk, HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), vk_witness: { leaf_index: mapFieldToNoir(new Fr(previousRollupData.vkWitness.leafIndex)), sibling_path: mapTuple(previousRollupData.vkWitness.siblingPath, mapFieldToNoir), @@ -2226,7 +2230,7 @@ export function mapRootRollupParityInputToNoir( ): RootRollupParityInputNoir { return { proof: mapRecursiveProofToNoir(rootParityInput.proof), - verification_key: mapVerificationKeyToNoir(rootParityInput.verificationKey), + verification_key: mapVerificationKeyToNoir(rootParityInput.verificationKey, HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), vk_path: mapTuple(rootParityInput.vkPath, mapFieldToNoir), public_inputs: mapParityPublicInputsToNoir(rootParityInput.publicInputs), }; @@ -2297,7 +2301,7 @@ export function mapRootParityInputToNoir( ): ParityRootParityInputNoir { return { proof: mapRecursiveProofToNoir(rootParityInput.proof), - verification_key: mapVerificationKeyToNoir(rootParityInput.verificationKey), + verification_key: mapVerificationKeyToNoir(rootParityInput.verificationKey, HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), vk_path: mapTuple(rootParityInput.vkPath, mapFieldToNoir), public_inputs: mapParityPublicInputsToNoir(rootParityInput.publicInputs), }; @@ -2615,6 +2619,6 @@ export function mapEmptyKernelInputsToNoir(inputs: PrivateKernelEmptyInputs): Pr function mapEmptyNestedDataToNoir(inputs: EmptyNestedData): EmptyNestedDataNoir { return { proof: mapRecursiveProofToNoir(inputs.proof), - vk: mapVerificationKeyToNoir(inputs.vk), + vk: mapVerificationKeyToNoir(inputs.vk, HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), }; } diff --git a/yarn-project/noir-protocol-circuits-types/src/utils/vk_json.ts b/yarn-project/noir-protocol-circuits-types/src/utils/vk_json.ts index 52f0facc72e5..2640a9e5cbb5 100644 --- a/yarn-project/noir-protocol-circuits-types/src/utils/vk_json.ts +++ b/yarn-project/noir-protocol-circuits-types/src/utils/vk_json.ts @@ -1,26 +1,17 @@ -import { - Fr, - VERIFICATION_KEY_LENGTH_IN_FIELDS, - VerificationKeyAsFields, - VerificationKeyData, -} from '@aztec/circuits.js'; -import { assertLength } from '@aztec/foundation/serialize'; +import { Fr, VerificationKeyAsFields, VerificationKeyData } from '@aztec/circuits.js'; interface VkJson { keyAsBytes: string; keyAsFields: string[]; + vkHash: string; } export function keyJsonToVKData(json: VkJson): VerificationKeyData { - const { keyAsBytes, keyAsFields } = json; + const { keyAsBytes, keyAsFields, vkHash } = json; return new VerificationKeyData( new VerificationKeyAsFields( - assertLength( - keyAsFields.map((str: string) => new Fr(Buffer.from(str.slice(2), 'hex'))), - VERIFICATION_KEY_LENGTH_IN_FIELDS, - ), - // TODO(#7410) what should be the vk hash here? - new Fr(Buffer.from(keyAsFields[0].slice(2), 'hex')), + keyAsFields.map((str: string) => Fr.fromString(str)), + Fr.fromString(vkHash), ), Buffer.from(keyAsBytes, 'hex'), ); diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator.ts b/yarn-project/prover-client/src/orchestrator/orchestrator.ts index f7e345c63a8e..d36219e6a148 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator.ts @@ -28,6 +28,7 @@ import { EmptyBlockRootRollupInputs, Fr, type GlobalVariables, + HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, type KernelCircuitPublicInputs, L1_TO_L2_MSG_SUBTREE_HEIGHT, L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, @@ -708,7 +709,7 @@ export class ProvingOrchestrator implements EpochProver { makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH), provingState.globalVariables, this.db, - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), ), ); @@ -1225,7 +1226,10 @@ export class ProvingOrchestrator implements EpochProver { logger.warn( `Error thrown when proving AVM circuit, but AVM_PROVING_STRICT is off, so faking AVM proof and carrying on. Error: ${err}.`, ); - return { proof: makeEmptyProof(), verificationKey: VerificationKeyData.makeFake() }; + return { + proof: makeEmptyProof(), + verificationKey: VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + }; } } }, diff --git a/yarn-project/prover-client/src/prover-agent/memory-proving-queue.test.ts b/yarn-project/prover-client/src/prover-agent/memory-proving-queue.test.ts index a581c4012d05..6107f89c2270 100644 --- a/yarn-project/prover-client/src/prover-agent/memory-proving-queue.test.ts +++ b/yarn-project/prover-client/src/prover-agent/memory-proving-queue.test.ts @@ -1,6 +1,7 @@ import { ProvingRequestType } from '@aztec/circuit-types'; import { Fr, + HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, RECURSIVE_PROOF_LENGTH, RootParityInput, VK_TREE_HEIGHT, @@ -86,7 +87,7 @@ describe('MemoryProvingQueue', () => { const publicInputs = makeParityPublicInputs(); const proof = makeRecursiveProof<typeof RECURSIVE_PROOF_LENGTH>(RECURSIVE_PROOF_LENGTH); - const vk = VerificationKeyAsFields.makeFake(); + const vk = VerificationKeyAsFields.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS); const vkPath = makeTuple(VK_TREE_HEIGHT, Fr.zero); await queue.resolveProvingJob(job!.id, new RootParityInput(proof, vk, vkPath, publicInputs)); await expect(promise).resolves.toEqual(new RootParityInput(proof, vk, vkPath, publicInputs)); @@ -144,7 +145,7 @@ describe('MemoryProvingQueue', () => { const output = new RootParityInput( makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyAsFields.makeFake(), + VerificationKeyAsFields.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), makeTuple(VK_TREE_HEIGHT, Fr.zero), makeParityPublicInputs(), ); diff --git a/yarn-project/prover-client/src/prover-agent/prover-agent.test.ts b/yarn-project/prover-client/src/prover-agent/prover-agent.test.ts index b892dff31d56..8bcac1c5a6f5 100644 --- a/yarn-project/prover-client/src/prover-agent/prover-agent.test.ts +++ b/yarn-project/prover-client/src/prover-agent/prover-agent.test.ts @@ -1,6 +1,7 @@ import { type ServerCircuitProver } from '@aztec/circuit-types'; import { Fr, + HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, RECURSIVE_PROOF_LENGTH, RootParityInput, VK_TREE_HEIGHT, @@ -40,7 +41,7 @@ describe('ProverAgent', () => { it('takes jobs from the queue', async () => { const publicInputs = makeParityPublicInputs(); const proof = makeRecursiveProof<typeof RECURSIVE_PROOF_LENGTH>(RECURSIVE_PROOF_LENGTH); - const vk = VerificationKeyAsFields.makeFake(); + const vk = VerificationKeyAsFields.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS); prover.getBaseParityProof.mockResolvedValue( new RootParityInput<typeof RECURSIVE_PROOF_LENGTH>(proof, vk, makeTuple(VK_TREE_HEIGHT, Fr.zero), publicInputs), ); @@ -69,7 +70,7 @@ describe('ProverAgent', () => { it('continues to process jobs', async () => { const publicInputs = makeParityPublicInputs(); const proof = makeRecursiveProof<typeof RECURSIVE_PROOF_LENGTH>(RECURSIVE_PROOF_LENGTH); - const vk = VerificationKeyAsFields.makeFake(); + const vk = VerificationKeyAsFields.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS); prover.getBaseParityProof.mockResolvedValue( new RootParityInput<typeof RECURSIVE_PROOF_LENGTH>(proof, vk, makeTuple(VK_TREE_HEIGHT, Fr.zero), publicInputs), ); diff --git a/yarn-project/prover-client/src/test/bb_prover_parity.test.ts b/yarn-project/prover-client/src/test/bb_prover_parity.test.ts index 00562614ea20..ad7f5e943878 100644 --- a/yarn-project/prover-client/src/test/bb_prover_parity.test.ts +++ b/yarn-project/prover-client/src/test/bb_prover_parity.test.ts @@ -2,6 +2,7 @@ import { BBNativeRollupProver, type BBProverConfig } from '@aztec/bb-prover'; import { BaseParityInputs, Fr, + HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, NUM_BASE_PARITY_PER_ROOT_PARITY, ParityPublicInputs, @@ -97,7 +98,7 @@ describe('prover/bb_prover/parity', () => { const defectiveVerificationKey = new RootParityInput( validProof, - VerificationKeyAsFields.makeFake(), + VerificationKeyAsFields.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), baseParityVkPath, validPublicInputs, ); diff --git a/yarn-project/prover-client/src/test/mock_prover.ts b/yarn-project/prover-client/src/test/mock_prover.ts index 0564d0bfd442..d0d0486b01c3 100644 --- a/yarn-project/prover-client/src/test/mock_prover.ts +++ b/yarn-project/prover-client/src/test/mock_prover.ts @@ -8,6 +8,7 @@ import { AvmVerificationKeyData, type BaseOrMergeRollupPublicInputs, type BlockRootOrBlockMergePublicInputs, + HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, type KernelCircuitPublicInputs, type PublicKernelCircuitPublicInputs, RECURSIVE_PROOF_LENGTH, @@ -53,7 +54,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeBaseOrMergeRollupPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), ), ); } @@ -63,7 +64,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeBaseOrMergeRollupPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), ), ); } @@ -73,7 +74,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeBlockRootOrBlockMergeRollupPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), ), ); } @@ -83,7 +84,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeBlockRootOrBlockMergeRollupPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), ), ); } @@ -93,7 +94,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeBlockRootOrBlockMergeRollupPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), ), ); } @@ -103,7 +104,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeKernelCircuitPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), ), ); } @@ -113,7 +114,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeKernelCircuitPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), ), ); } @@ -123,7 +124,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeVMCircuitPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), ), ); } @@ -133,7 +134,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makePublicKernelCircuitPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), ), ); } @@ -143,7 +144,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeKernelCircuitPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), ), ); } @@ -153,7 +154,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeRootRollupPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), ), ); } @@ -163,7 +164,7 @@ export class MockProver implements ServerCircuitProver { tubeProof: RecursiveProof<typeof RECURSIVE_PROOF_LENGTH>; }> { return Promise.resolve({ - tubeVK: VerificationKeyData.makeFake(), + tubeVK: VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), tubeProof: makeRecursiveProof(RECURSIVE_PROOF_LENGTH), }); } diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts index e2f7e1689e04..d6b0dc1385f5 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts @@ -6,6 +6,7 @@ import { PublicExecutionRequest, } from '@aztec/circuit-types'; import { + CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS, FunctionData, FunctionSelector, MAX_NOTE_HASHES_PER_CALL, @@ -92,7 +93,7 @@ describe('Kernel Prover', () => { publicInputs.end.noteHashes = noteHashes; return { publicInputs, - verificationKey: VerificationKeyAsFields.makeEmpty(), + verificationKey: VerificationKeyAsFields.makeEmpty(CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS), outputWitness: new Map(), bytecode: Buffer.from([]), }; @@ -109,14 +110,14 @@ describe('Kernel Prover', () => { return { publicInputs, outputWitness: new Map(), - verificationKey: VerificationKeyAsFields.makeEmpty(), + verificationKey: VerificationKeyAsFields.makeEmpty(CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS), bytecode: Buffer.from([]), }; }; const computeAppCircuitVerificationKeyOutput = () => { return { - verificationKey: VerificationKeyAsFields.makeEmpty(), + verificationKey: VerificationKeyAsFields.makeEmpty(CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS), }; }; diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts index fec9dc2dddc7..9101803cadfc 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts @@ -9,6 +9,7 @@ import { getFinalMinRevertibleSideEffectCounter, } from '@aztec/circuit-types'; import { + CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS, Fr, PROTOCOL_CONTRACT_TREE_HEIGHT, PrivateCallData, @@ -40,7 +41,7 @@ import { type ProvingDataOracle } from './proving_data_oracle.js'; const NULL_PROVE_OUTPUT: PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs> = { publicInputs: PrivateKernelCircuitPublicInputs.empty(), - verificationKey: VerificationKeyAsFields.makeEmpty(), + verificationKey: VerificationKeyAsFields.makeEmpty(CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS), outputWitness: new Map(), bytecode: Buffer.from([]), }; diff --git a/yarn-project/pxe/src/kernel_prover/test/test_circuit_prover.ts b/yarn-project/pxe/src/kernel_prover/test/test_circuit_prover.ts index 4798a40c5c84..710312768cca 100644 --- a/yarn-project/pxe/src/kernel_prover/test/test_circuit_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/test/test_circuit_prover.ts @@ -5,6 +5,7 @@ import { } from '@aztec/circuit-types'; import type { CircuitSimulationStats } from '@aztec/circuit-types/stats'; import { + CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS, ClientIvcProof, type PrivateKernelCircuitPublicInputs, type PrivateKernelInitCircuitPrivateInputs, @@ -111,7 +112,7 @@ export class TestPrivateKernelProver implements PrivateKernelProver { _appCircuitName?: string | undefined, ): Promise<AppCircuitSimulateOutput> { const appCircuitProofOutput: AppCircuitSimulateOutput = { - verificationKey: VerificationKeyAsFields.makeEmpty(), + verificationKey: VerificationKeyAsFields.makeEmpty(CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS), }; return Promise.resolve(appCircuitProofOutput); } diff --git a/yarn-project/sequencer-client/src/block_builder/light.test.ts b/yarn-project/sequencer-client/src/block_builder/light.test.ts index abe8ff8a4326..4f7470d5ca4f 100644 --- a/yarn-project/sequencer-client/src/block_builder/light.test.ts +++ b/yarn-project/sequencer-client/src/block_builder/light.test.ts @@ -14,6 +14,7 @@ import { BlockRootRollupInputs, Fr, type GlobalVariables, + HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, L1_TO_L2_MSG_SUBTREE_HEIGHT, L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, type MembershipWitness, @@ -74,7 +75,7 @@ describe('LightBlockBuilder', () => { simulator = new TestCircuitProver(new NoopTelemetryClient()); vkRoot = getVKTreeRoot(); emptyProof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH); - emptyVk = VerificationKeyData.makeFake(); + emptyVk = VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS); emptyVkWitness = makeEmptyMembershipWitness(VK_TREE_HEIGHT); db = await NativeWorldStateService.tmp(); }); diff --git a/yarn-project/sequencer-client/src/block_builder/light.ts b/yarn-project/sequencer-client/src/block_builder/light.ts index bbca758c3505..db59f17a19bf 100644 --- a/yarn-project/sequencer-client/src/block_builder/light.ts +++ b/yarn-project/sequencer-client/src/block_builder/light.ts @@ -13,6 +13,7 @@ import { import { Fr, type GlobalVariables, + HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, NESTED_RECURSIVE_PROOF_LENGTH, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, VerificationKeyData, @@ -57,7 +58,7 @@ export class LightweightBlockBuilder implements BlockBuilder { makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH), this.globalVariables!, this.db, - VerificationKeyData.makeFake(), + VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), ); } diff --git a/yarn-project/simulator/src/public/enqueued_calls_processor.ts b/yarn-project/simulator/src/public/enqueued_calls_processor.ts index a83cc36d29b0..77702909d324 100644 --- a/yarn-project/simulator/src/public/enqueued_calls_processor.ts +++ b/yarn-project/simulator/src/public/enqueued_calls_processor.ts @@ -15,6 +15,7 @@ import { Fr, Gas, type GlobalVariables, + HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, type Header, type KernelCircuitPublicInputs, NESTED_RECURSIVE_PROOF_LENGTH, @@ -23,6 +24,7 @@ import { type PublicKernelCircuitPublicInputs, PublicKernelData, type VMCircuitPublicInputs, + VerificationKeyData, makeEmptyProof, makeEmptyRecursiveProof, } from '@aztec/circuits.js'; @@ -378,7 +380,7 @@ export class EnqueuedCallsProcessor { const proof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH); const vk = isFromPrivate - ? ProtocolCircuitVks.PrivateKernelTailToPublicArtifact + ? VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS) // TODO(Alvaro) tube VK here : ProtocolCircuitVks.PublicKernelMergeArtifact; const vkIndex = getVKIndex(vk); const siblingPath = getVKSiblingPath(vkIndex); From 3804642778663d5ccedf1e974677173d29c24871 Mon Sep 17 00:00:00 2001 From: sirasistant <sirasistant@gmail.com> Date: Thu, 10 Oct 2024 13:36:24 +0000 Subject: [PATCH 02/10] restore moar checks --- l1-contracts/src/core/libraries/ConstantsGen.sol | 1 + .../aztec-nr/aztec/src/context/public_context.nr | 2 +- .../crates/parity-lib/src/root/root_parity_inputs.nr | 3 +-- .../src/components/previous_kernel_validator.nr | 5 ++--- .../src/components/previous_kernel_validator.nr | 5 ++--- .../public-kernel-lib/src/public_kernel_merge.nr | 4 ++-- .../crates/rollup-lib/src/base/base_rollup_inputs.nr | 7 +++---- .../src/block_merge/block_merge_rollup_inputs.nr | 6 ++---- .../src/block_root/block_root_rollup_inputs.nr | 9 +++------ .../crates/rollup-lib/src/merge/merge_rollup_inputs.nr | 6 ++---- .../crates/rollup-lib/src/root/root_rollup_inputs.nr | 6 ++---- .../crates/types/src/abis/kernel_data.nr | 10 +++++++--- .../crates/types/src/abis/public_kernel_data.nr | 10 +++++++--- .../crates/types/src/constants.nr | 1 + yarn-project/circuits.js/src/constants.gen.ts | 1 + yarn-project/end-to-end/src/e2e_card_game.test.ts | 2 ++ .../simulator/src/public/enqueued_calls_processor.ts | 5 +++-- 17 files changed, 42 insertions(+), 41 deletions(-) diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index 7c60e37758d2..06a17f5d8833 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -89,6 +89,7 @@ library Constants { uint256 internal constant BLOCK_MERGE_ROLLUP_INDEX = 15; uint256 internal constant ROOT_ROLLUP_INDEX = 16; uint256 internal constant BLOCK_ROOT_ROLLUP_EMPTY_INDEX = 17; + uint256 internal constant TUBE_INDEX = 18; uint256 internal constant PRIVATE_KERNEL_RESET_INDEX = 20; uint256 internal constant FUNCTION_SELECTOR_NUM_BYTES = 4; uint256 internal constant INITIALIZATION_SLOT_SEPARATOR = 1000000000; diff --git a/noir-projects/aztec-nr/aztec/src/context/public_context.nr b/noir-projects/aztec-nr/aztec/src/context/public_context.nr index 329ca04beb2f..98188c3bf966 100644 --- a/noir-projects/aztec-nr/aztec/src/context/public_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/public_context.nr @@ -259,7 +259,7 @@ unconstrained fn note_hash_exists(note_hash: Field, leaf_index: Field) -> u8 { unconstrained fn emit_note_hash(note_hash: Field) { emit_note_hash_opcode(note_hash) } -unconstrained fn nullifier_exists(nullifier: Field, address: Field) -> u1 { +unconstrained fn nullifier_exists(nullifier: Field, address: Field) -> u8 { nullifier_exists_opcode(nullifier, address) } unconstrained fn emit_nullifier(nullifier: Field) { diff --git a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_parity_inputs.nr b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_parity_inputs.nr index 4473cb2a6ba4..9f7a818df053 100644 --- a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_parity_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_parity_inputs.nr @@ -44,8 +44,7 @@ impl RootParityInputs { //TODO: Do we need to validate this following hash //assert(hash(self.children[i].verification_key) == self.children[i].verification_key.hash); self.children[i].verify(); - // TODO(#7410) we need the tube vk to reinstate this - // self.children[i].validate_in_vk_tree(); + self.children[i].validate_in_vk_tree(); } } } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/previous_kernel_validator.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/previous_kernel_validator.nr index 5173f4f03b7d..67489e713a97 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/previous_kernel_validator.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/previous_kernel_validator.nr @@ -19,10 +19,9 @@ impl PreviousKernelValidator { PreviousKernelValidator { previous_kernel, hints } } - pub fn validate_proof<let N: u32>(_self: Self, _allowed_indices: [u32; N]) { + pub fn validate_proof<let N: u32>(self: Self, allowed_indices: [u32; N]) { if !dep::std::runtime::is_unconstrained() { - // TODO(#7410) currently stubbed out until tube vk handled - // self.previous_kernel.validate_in_vk_tree(allowed_indices); + self.previous_kernel.validate_in_vk_tree(allowed_indices); } } diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/previous_kernel_validator.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/previous_kernel_validator.nr index 3a53b0febcdf..3859b81383e4 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/previous_kernel_validator.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/components/previous_kernel_validator.nr @@ -10,12 +10,11 @@ impl PreviousKernelValidator { PreviousKernelValidator { previous_kernel } } - pub fn validate_proof<let N: u32>(self, _allowed_indices: [u32; N]) { + pub fn validate_proof<let N: u32>(self, allowed_indices: [u32; N]) { if !dep::std::runtime::is_unconstrained() { // Recursively verify the tube proof or a previous public kernel proof self.previous_kernel.verify(); - // TODO(#7410) currently stubbed out until tube vk handled - // self.previous_kernel.validate_in_vk_tree(allowed_indices); + self.previous_kernel.validate_in_vk_tree(allowed_indices); } } diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_merge.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_merge.nr index ebfd605cee7c..65073adf19de 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_merge.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_merge.nr @@ -12,11 +12,11 @@ use dep::types::{ enqueued_call_data::EnqueuedCallData, kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs, public_kernel_data::PublicKernelData }, - constants::{PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX, PUBLIC_KERNEL_MERGE_INDEX} + constants::{TUBE_INDEX, PUBLIC_KERNEL_MERGE_INDEX} }; global ALLOWED_PREVIOUS_CIRCUITS = [ - PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX, + TUBE_INDEX, PUBLIC_KERNEL_MERGE_INDEX, ]; diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr index ce963e76bc8d..f4c953e3eca6 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -23,7 +23,7 @@ use dep::types::{ MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, NULLIFIER_SUBTREE_HEIGHT, NULLIFIER_TREE_HEIGHT, PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH, PUBLIC_DATA_SUBTREE_HEIGHT, ARCHIVE_HEIGHT, FEE_JUICE_ADDRESS, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PUBLIC_KERNEL_TAIL_INDEX, - PRIVATE_KERNEL_EMPTY_INDEX, PRIVATE_KERNEL_TAIL_INDEX + PRIVATE_KERNEL_EMPTY_INDEX, TUBE_INDEX }, merkle_tree::{ append_only_tree, assert_check_membership, calculate_empty_tree_root, calculate_subtree_root, @@ -36,7 +36,7 @@ use dep::types::{ global ALLOWED_PREVIOUS_CIRCUITS = [ PRIVATE_KERNEL_EMPTY_INDEX, - PRIVATE_KERNEL_TAIL_INDEX, + TUBE_INDEX, PUBLIC_KERNEL_TAIL_INDEX, ]; @@ -64,8 +64,7 @@ impl BaseRollupInputs { if !dep::std::runtime::is_unconstrained() { // Recursively verify the tube proof if straight from private, or the public kernel tail self.kernel_data.verify(); - // TODO(#7410) we need the tube vk to reinstate this - // self.kernel_data.validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); + self.kernel_data.validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); } // Verify the kernel chain_id and versions assert( diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_merge/block_merge_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_merge/block_merge_rollup_inputs.nr index cd8215c1e094..e856b50588e2 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_merge/block_merge_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_merge/block_merge_rollup_inputs.nr @@ -26,12 +26,10 @@ impl BlockMergeRollupInputs { // Verify the previous rollup proofs if !dep::std::runtime::is_unconstrained() { self.previous_rollup_data[0].verify(); - // TODO(#7410) we need the tube vk to reinstate this - // self.previous_rollup_data[0].validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); + self.previous_rollup_data[0].validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); self.previous_rollup_data[1].verify(); - // TODO(#7410) we need the tube vk to reinstate this - // self.previous_rollup_data[1].validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); + self.previous_rollup_data[1].validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); } let left = self.previous_rollup_data[0].block_root_or_block_merge_public_inputs; diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/block_root_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/block_root_rollup_inputs.nr index ecad76313ebf..1342f39f7890 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/block_root_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/block_root_rollup_inputs.nr @@ -52,17 +52,14 @@ impl BlockRootRollupInputs { // Verify the previous rollup proofs if !dep::std::runtime::is_unconstrained() { self.previous_rollup_data[0].verify(); - // TODO(#7410) we need the tube vk to reinstate this - // self.previous_rollup_data[0].validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); + self.previous_rollup_data[0].validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); self.previous_rollup_data[1].verify(); - // TODO(#7410) we need the tube vk to reinstate this - // self.previous_rollup_data[1].validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); + self.previous_rollup_data[1].validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); // verify the root parity self.l1_to_l2_roots.verify(); - // TODO(#7410) we need the tube vk to reinstate this - // self.l1_to_l2_roots.validate_in_vk_tree(); + self.l1_to_l2_roots.validate_in_vk_tree(); } let left = self.previous_rollup_data[0].base_or_merge_rollup_public_inputs; diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/merge/merge_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/merge/merge_rollup_inputs.nr index ee10a70d852a..098f5f448f00 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/merge/merge_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/merge/merge_rollup_inputs.nr @@ -27,12 +27,10 @@ impl MergeRollupInputs { // Verify the previous rollup proofs if !dep::std::runtime::is_unconstrained() { self.previous_rollup_data[0].verify(); - // TODO(#7410) we need the tube vk to reinstate this - // self.previous_rollup_data[0].validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); + self.previous_rollup_data[0].validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); self.previous_rollup_data[1].verify(); - // TODO(#7410) we need the tube vk to reinstate this - // self.previous_rollup_data[1].validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); + self.previous_rollup_data[1].validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); } let left = self.previous_rollup_data[0].base_or_merge_rollup_public_inputs; diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_inputs.nr index 24fcb0f9f9ef..43972f54394a 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_inputs.nr @@ -25,12 +25,10 @@ impl RootRollupInputs { // Verify the previous rollup proofs if !dep::std::runtime::is_unconstrained() { self.previous_rollup_data[0].verify(); - // TODO(#7410) we need the tube vk to reinstate this - // self.previous_rollup_data[0].validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); + self.previous_rollup_data[0].validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); self.previous_rollup_data[1].verify(); - // TODO(#7410) we need the tube vk to reinstate this - // self.previous_rollup_data[1].validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); + self.previous_rollup_data[1].validate_in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS); } let left = self.previous_rollup_data[0].block_root_or_block_merge_public_inputs; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr index 059d68b8742f..fec3be35ecf7 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr @@ -1,6 +1,6 @@ use crate::{ - abis::kernel_circuit_public_inputs::KernelCircuitPublicInputs, constants::{VK_TREE_HEIGHT}, - merkle_tree::membership::assert_check_membership, + abis::kernel_circuit_public_inputs::KernelCircuitPublicInputs, + constants::{VK_TREE_HEIGHT, TUBE_INDEX}, merkle_tree::membership::check_membership, recursion::{proof::NestedRecursiveProof, verification_key::HonkVerificationKey, traits::Verifiable}, utils::arrays::find_index_hint }; @@ -27,11 +27,15 @@ impl KernelData { }; assert_eq(allowed_indices[index_hint], self.vk_index, "Invalid vk index"); - assert_check_membership( + // TODO(#7410) Remove the exception for the tube index + assert( + check_membership( self.vk.hash, self.vk_index as Field, self.vk_path, self.public_inputs.constants.vk_tree_root + ) + | (self.vk_index == TUBE_INDEX) ); } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr index dbf9da3519f0..fb34aec4bfdb 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr @@ -1,6 +1,6 @@ use crate::{ - abis::kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs, constants::{VK_TREE_HEIGHT}, - merkle_tree::membership::assert_check_membership, + abis::kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs, + constants::{VK_TREE_HEIGHT, TUBE_INDEX}, merkle_tree::membership::check_membership, recursion::{proof::NestedRecursiveProof, verification_key::HonkVerificationKey, traits::Verifiable}, utils::arrays::find_index_hint }; @@ -27,11 +27,15 @@ impl PublicKernelData { }; assert_eq(allowed_indices[index_hint], self.vk_index, "Invalid vk index"); - assert_check_membership( + // TODO(#7410) Remove the exception for the tube index + assert( + check_membership( self.vk.hash, self.vk_index as Field, self.vk_path, self.public_inputs.constants.vk_tree_root + ) + | (self.vk_index == TUBE_INDEX) ); } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index 7710ed1a33b4..d3f64ddbccd9 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -115,6 +115,7 @@ global BLOCK_ROOT_ROLLUP_INDEX: u32 = 14; global BLOCK_MERGE_ROLLUP_INDEX: u32 = 15; global ROOT_ROLLUP_INDEX: u32 = 16; global BLOCK_ROOT_ROLLUP_EMPTY_INDEX: u32 = 17; +global TUBE_INDEX: u32 = 18; global PRIVATE_KERNEL_RESET_INDEX: u32 = 20; // Important: Do not define indexes after the PRIVATE_KERNEL_RESET_INDEX. They are allocated for the variants of private kernel reset. diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 6f2080bd6ff2..465e41b6a540 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -75,6 +75,7 @@ export const BLOCK_ROOT_ROLLUP_INDEX = 14; export const BLOCK_MERGE_ROLLUP_INDEX = 15; export const ROOT_ROLLUP_INDEX = 16; export const BLOCK_ROOT_ROLLUP_EMPTY_INDEX = 17; +export const TUBE_INDEX = 18; export const PRIVATE_KERNEL_RESET_INDEX = 20; export const FUNCTION_SELECTOR_NUM_BYTES = 4; export const INITIALIZATION_SLOT_SEPARATOR = 1000000000; diff --git a/yarn-project/end-to-end/src/e2e_card_game.test.ts b/yarn-project/end-to-end/src/e2e_card_game.test.ts index d845ec81ff0d..80ac5d8af742 100644 --- a/yarn-project/end-to-end/src/e2e_card_game.test.ts +++ b/yarn-project/end-to-end/src/e2e_card_game.test.ts @@ -151,7 +151,9 @@ describe('e2e_card_game', () => { it('should be able to buy packs', async () => { const seed = 27n; // docs:start:send_tx + console.log('Buying pack...'); await contract.methods.buy_pack(seed).send().wait(); + console.log('Pack bought'); // docs:end:send_tx const collection = await contract.methods.view_collection_cards(firstPlayer, 0).simulate({ from: firstPlayer }); const expected = getPackedCards(0, seed); diff --git a/yarn-project/simulator/src/public/enqueued_calls_processor.ts b/yarn-project/simulator/src/public/enqueued_calls_processor.ts index 77702909d324..10383a2fb35c 100644 --- a/yarn-project/simulator/src/public/enqueued_calls_processor.ts +++ b/yarn-project/simulator/src/public/enqueued_calls_processor.ts @@ -23,6 +23,7 @@ import { PublicKernelCircuitPrivateInputs, type PublicKernelCircuitPublicInputs, PublicKernelData, + TUBE_INDEX, type VMCircuitPublicInputs, VerificationKeyData, makeEmptyProof, @@ -380,9 +381,9 @@ export class EnqueuedCallsProcessor { const proof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH); const vk = isFromPrivate - ? VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS) // TODO(Alvaro) tube VK here + ? VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS) // TODO(#7410) tube VK goes here : ProtocolCircuitVks.PublicKernelMergeArtifact; - const vkIndex = getVKIndex(vk); + const vkIndex = isFromPrivate ? TUBE_INDEX : getVKIndex(vk); const siblingPath = getVKSiblingPath(vkIndex); return new PublicKernelData(previousOutput, proof, vk, vkIndex, siblingPath); From 3a93b165857335f106aef8c536b0080a48df84fd Mon Sep 17 00:00:00 2001 From: sirasistant <sirasistant@gmail.com> Date: Thu, 10 Oct 2024 18:16:52 +0000 Subject: [PATCH 03/10] fixes --- noir-projects/mega_honk_circuits.json | 5 +++- yarn-project/bb-prover/src/bb/execute.ts | 2 +- .../src/prover/bb_private_kernel_prover.ts | 2 +- .../bb-prover/src/prover/bb_prover.ts | 3 ++- .../verification_key/verification_key_data.ts | 5 ++-- .../noir-protocol-circuits-types/src/index.ts | 1 + .../src/scripts/generate_vk_hashes.ts | 24 ++++++++++++------- .../src/utils/vk_json.ts | 5 ++++ .../noir-protocol-circuits-types/src/vks.ts | 10 ++++++-- .../src/orchestrator/orchestrator.ts | 12 +++++++--- .../src/block_builder/light.ts | 6 ++--- .../src/public/enqueued_calls_processor.ts | 8 ++----- 12 files changed, 54 insertions(+), 29 deletions(-) diff --git a/noir-projects/mega_honk_circuits.json b/noir-projects/mega_honk_circuits.json index c1dd653f4de2..37b25115596a 100644 --- a/noir-projects/mega_honk_circuits.json +++ b/noir-projects/mega_honk_circuits.json @@ -1,3 +1,6 @@ [ - "private_kernel.*" + "private_kernel_init", + "private_kernel_inner", + "private_kernel_reset.*", + "private_kernel_tail.*" ] \ No newline at end of file diff --git a/yarn-project/bb-prover/src/bb/execute.ts b/yarn-project/bb-prover/src/bb/execute.ts index 22c4b5e9393f..d5fbcb06d76c 100644 --- a/yarn-project/bb-prover/src/bb/execute.ts +++ b/yarn-project/bb-prover/src/bb/execute.ts @@ -263,7 +263,7 @@ export async function computeVerificationKey( workingDirectory: string, circuitName: string, bytecode: Buffer, - flavor: UltraHonkFlavor, + flavor: UltraHonkFlavor | 'mega_honk', log: LogFn, ): Promise<BBFailure | BBSuccess> { // Check that the working directory exists diff --git a/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts b/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts index ee9e8f03e4c7..94b096545724 100644 --- a/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts +++ b/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts @@ -308,7 +308,7 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver { directory, circuitType, bytecode, - circuitType === 'App' ? 'ultra_honk' : getUltraHonkFlavorForCircuit(circuitType), + circuitType === 'App' ? 'mega_honk' : getUltraHonkFlavorForCircuit(circuitType), this.log.debug, ); diff --git a/yarn-project/bb-prover/src/prover/bb_prover.ts b/yarn-project/bb-prover/src/prover/bb_prover.ts index b99dff1748de..fd585faef67f 100644 --- a/yarn-project/bb-prover/src/prover/bb_prover.ts +++ b/yarn-project/bb-prover/src/prover/bb_prover.ts @@ -48,6 +48,7 @@ import { createDebugLogger } from '@aztec/foundation/log'; import { Timer } from '@aztec/foundation/timer'; import { ProtocolCircuitVkIndexes, + ProtocolCircuitVks, ServerCircuitArtifacts, type ServerProtocolArtifact, convertBaseParityInputsToWitnessMap, @@ -529,7 +530,7 @@ export class BBNativeRollupProver implements ServerCircuitProver { convertPrivateKernelEmptyOutputsFromWitnessMap, ); //info(`proof: ${proof.proof}`); - const verificationKey = await this.getVerificationKeyDataForCircuit('PrivateKernelEmptyArtifact'); + const verificationKey = ProtocolCircuitVks['PrivateKernelEmptyArtifact']; await this.verifyProof('PrivateKernelEmptyArtifact', proof.binaryProof); return makePublicInputsAndRecursiveProof(circuitOutput, proof, verificationKey); diff --git a/yarn-project/bb-prover/src/verification_key/verification_key_data.ts b/yarn-project/bb-prover/src/verification_key/verification_key_data.ts index 908e49b5aee1..0b33cf86e1b8 100644 --- a/yarn-project/bb-prover/src/verification_key/verification_key_data.ts +++ b/yarn-project/bb-prover/src/verification_key/verification_key_data.ts @@ -6,6 +6,7 @@ import { VerificationKeyAsFields, VerificationKeyData, } from '@aztec/circuits.js'; +import { hashVk } from '@aztec/noir-protocol-circuits-types'; import { strict as assert } from 'assert'; import * as fs from 'fs/promises'; @@ -25,8 +26,8 @@ export async function extractVkData(vkDirectoryPath: string): Promise<Verificati ]); const fieldsJson = JSON.parse(rawFields); const fields = fieldsJson.map(Fr.fromString); - // The first item is the hash, this is not part of the actual VK - const vkHash = fields[0]; + // The hash is not included in the BB response + const vkHash = hashVk(fields); const vkAsFields = new VerificationKeyAsFields(fields, vkHash); return new VerificationKeyData(vkAsFields, rawBinary); } diff --git a/yarn-project/noir-protocol-circuits-types/src/index.ts b/yarn-project/noir-protocol-circuits-types/src/index.ts index 176cefe5a96d..cda46fac68fb 100644 --- a/yarn-project/noir-protocol-circuits-types/src/index.ts +++ b/yarn-project/noir-protocol-circuits-types/src/index.ts @@ -100,6 +100,7 @@ export * from './artifacts.js'; export { maxPrivateKernelResetDimensions, privateKernelResetDimensionsConfig } from './private_kernel_reset_data.js'; export * from './utils/private_kernel_reset.js'; export * from './vks.js'; +export { hashVk } from './utils/vk_json.js'; /* eslint-disable camelcase */ diff --git a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts index 0dccc3e62dd6..129780c8ee12 100644 --- a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts +++ b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts @@ -1,23 +1,30 @@ -import { Fr } from '@aztec/circuits.js'; -import { poseidon2Hash } from '@aztec/foundation/crypto'; +import { Fr, HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, VerificationKeyData } from '@aztec/circuits.js'; import { createConsoleLogger } from '@aztec/foundation/log'; import { fileURLToPath } from '@aztec/foundation/url'; import fs from 'fs/promises'; import { join } from 'path'; +import { hashVk } from '../utils/vk_json.js'; + const log = createConsoleLogger('aztec:autogenerate'); function resolveRelativePath(relativePath: string) { return fileURLToPath(new URL(relativePath, import.meta.url).href); } -function hashVk(keyAsFields: string[]): string { - const keyAsFrs = keyAsFields.map((str: string) => Fr.fromString(str)); - return poseidon2Hash(keyAsFrs).toString(); -} - const main = async () => { + // TODO(#7410) tube VK should have been generated previously, this is just faking it + const tubeVK = VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS); + const tubeVKPath = resolveRelativePath('../../artifacts/keys/tube.vk.data.json'); + await fs.writeFile( + tubeVKPath, + JSON.stringify({ + keyAsBytes: tubeVK.keyAsBytes.toString('hex'), + keyAsFields: tubeVK.keyAsFields.key.map((field: Fr) => field.toString()), + }), + ); + const files = await fs.readdir(resolveRelativePath('../../artifacts/keys')); for (const fileName of files) { if (fileName.endsWith('.vk.data.json')) { @@ -25,7 +32,8 @@ const main = async () => { const content = JSON.parse(await fs.readFile(keyPath, 'utf-8')); if (!content.vkHash) { const { keyAsFields } = content; - content.vkHash = hashVk(keyAsFields); + + content.vkHash = hashVk(keyAsFields.map((str: string) => Fr.fromString(str))).toString(); await fs.writeFile(keyPath, JSON.stringify(content, null, 2)); } } diff --git a/yarn-project/noir-protocol-circuits-types/src/utils/vk_json.ts b/yarn-project/noir-protocol-circuits-types/src/utils/vk_json.ts index 2640a9e5cbb5..6176bcbb68f9 100644 --- a/yarn-project/noir-protocol-circuits-types/src/utils/vk_json.ts +++ b/yarn-project/noir-protocol-circuits-types/src/utils/vk_json.ts @@ -1,4 +1,5 @@ import { Fr, VerificationKeyAsFields, VerificationKeyData } from '@aztec/circuits.js'; +import { poseidon2Hash } from '@aztec/foundation/crypto'; interface VkJson { keyAsBytes: string; @@ -16,3 +17,7 @@ export function keyJsonToVKData(json: VkJson): VerificationKeyData { Buffer.from(keyAsBytes, 'hex'), ); } + +export function hashVk(keyAsFields: Fr[]): Fr { + return poseidon2Hash(keyAsFields); +} diff --git a/yarn-project/noir-protocol-circuits-types/src/vks.ts b/yarn-project/noir-protocol-circuits-types/src/vks.ts index e7e070f26593..bd8e0dbbf4ca 100644 --- a/yarn-project/noir-protocol-circuits-types/src/vks.ts +++ b/yarn-project/noir-protocol-circuits-types/src/vks.ts @@ -19,6 +19,7 @@ import { PUBLIC_KERNEL_TAIL_INDEX, ROOT_PARITY_INDEX, ROOT_ROLLUP_INDEX, + TUBE_INDEX, VK_TREE_HEIGHT, VerificationKeyAsFields, VerificationKeyData, @@ -43,10 +44,14 @@ import BlockRootRollupVkJson from '../artifacts/keys/rollup_block_root.vk.data.j import EmptyBlockRootRollupVkJson from '../artifacts/keys/rollup_block_root_empty.vk.data.json' assert { type: 'json' }; import MergeRollupVkJson from '../artifacts/keys/rollup_merge.vk.data.json' assert { type: 'json' }; import RootRollupVkJson from '../artifacts/keys/rollup_root.vk.data.json' assert { type: 'json' }; +import TubeVkJson from '../artifacts/keys/tube.vk.data.json' assert { type: 'json' }; import { type ClientProtocolArtifact, type ProtocolArtifact, type ServerProtocolArtifact } from './artifacts.js'; import { PrivateKernelResetVkIndexes, PrivateKernelResetVks } from './private_kernel_reset_data.js'; import { keyJsonToVKData } from './utils/vk_json.js'; +// TODO Include this in the normal maps when the tube is implemented in noir +export const TubeVk = keyJsonToVKData(TubeVkJson); + export const ServerCircuitVks: Record<ServerProtocolArtifact, VerificationKeyData> = { EmptyNestedArtifact: keyJsonToVKData(EmptyNestedVkJson), PrivateKernelEmptyArtifact: keyJsonToVKData(PrivateKernelEmptyVkJson), @@ -108,6 +113,8 @@ function buildVKTree() { vkHashes[index] = value.keyAsFields.hash.toBuffer(); } + vkHashes[TUBE_INDEX] = TubeVk.keyAsFields.hash.toBuffer(); + return calculator.computeTree(vkHashes); } @@ -136,8 +143,7 @@ export function getVKIndex(vk: VerificationKeyData | VerificationKeyAsFields | F const index = getVKTree().getIndex(hash.toBuffer()); if (index < 0) { - //throw new Error(`VK index for ${hash.toString()} not found in VK tree`); - return 0; // faked for now + throw new Error(`VK index for ${hash.toString()} not found in VK tree`); } return index; } diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator.ts b/yarn-project/prover-client/src/orchestrator/orchestrator.ts index d36219e6a148..f869c286ec2e 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator.ts @@ -42,6 +42,7 @@ import { type RecursiveProof, type RootParityInput, RootParityInputs, + TUBE_INDEX, type TUBE_PROOF_LENGTH, TubeInputs, type VMCircuitPublicInputs, @@ -58,7 +59,7 @@ import { promiseWithResolvers } from '@aztec/foundation/promise'; import { type Tuple } from '@aztec/foundation/serialize'; import { pushTestData } from '@aztec/foundation/testing'; import { elapsed } from '@aztec/foundation/timer'; -import { getVKIndex, getVKSiblingPath, getVKTreeRoot } from '@aztec/noir-protocol-circuits-types'; +import { TubeVk, getVKIndex, getVKSiblingPath, getVKTreeRoot } from '@aztec/noir-protocol-circuits-types'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { Attributes, type TelemetryClient, type Tracer, trackSpan, wrapCallbackInSpan } from '@aztec/telemetry-client'; @@ -709,7 +710,7 @@ export class ProvingOrchestrator implements EpochProver { makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH), provingState.globalVariables, this.db, - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + TubeVk, ), ); @@ -1282,7 +1283,12 @@ export class ProvingOrchestrator implements EpochProver { // Take the final proof and assign it to the base rollup inputs txProvingState.baseRollupInputs.kernelData.proof = proof; txProvingState.baseRollupInputs.kernelData.vk = verificationKey; - txProvingState.baseRollupInputs.kernelData.vkIndex = getVKIndex(verificationKey); + try { + txProvingState.baseRollupInputs.kernelData.vkIndex = getVKIndex(verificationKey); + } catch (_ignored) { + // TODO(#7410) The VK for the tube won't be in the tree, so we manually set it to the tube vk index + txProvingState.baseRollupInputs.kernelData.vkIndex = TUBE_INDEX; + } txProvingState.baseRollupInputs.kernelData.vkPath = getVKSiblingPath( txProvingState.baseRollupInputs.kernelData.vkIndex, ); diff --git a/yarn-project/sequencer-client/src/block_builder/light.ts b/yarn-project/sequencer-client/src/block_builder/light.ts index db59f17a19bf..158f846a62ca 100644 --- a/yarn-project/sequencer-client/src/block_builder/light.ts +++ b/yarn-project/sequencer-client/src/block_builder/light.ts @@ -13,14 +13,12 @@ import { import { Fr, type GlobalVariables, - HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, NESTED_RECURSIVE_PROOF_LENGTH, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, - VerificationKeyData, makeEmptyRecursiveProof, } from '@aztec/circuits.js'; import { padArrayEnd } from '@aztec/foundation/collection'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types'; +import { TubeVk, getVKTreeRoot } from '@aztec/noir-protocol-circuits-types'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { buildBaseRollupInput, buildHeaderFromTxEffects, getTreeSnapshot } from '@aztec/prover-client/helpers'; import { type TelemetryClient } from '@aztec/telemetry-client'; @@ -58,7 +56,7 @@ export class LightweightBlockBuilder implements BlockBuilder { makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH), this.globalVariables!, this.db, - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + TubeVk, ); } diff --git a/yarn-project/simulator/src/public/enqueued_calls_processor.ts b/yarn-project/simulator/src/public/enqueued_calls_processor.ts index 10383a2fb35c..4977546962c9 100644 --- a/yarn-project/simulator/src/public/enqueued_calls_processor.ts +++ b/yarn-project/simulator/src/public/enqueued_calls_processor.ts @@ -15,7 +15,6 @@ import { Fr, Gas, type GlobalVariables, - HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, type Header, type KernelCircuitPublicInputs, NESTED_RECURSIVE_PROOF_LENGTH, @@ -25,13 +24,12 @@ import { PublicKernelData, TUBE_INDEX, type VMCircuitPublicInputs, - VerificationKeyData, makeEmptyProof, makeEmptyRecursiveProof, } from '@aztec/circuits.js'; import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log'; import { Timer } from '@aztec/foundation/timer'; -import { ProtocolCircuitVks, getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types'; +import { ProtocolCircuitVks, TubeVk, getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types'; import { inspect } from 'util'; @@ -380,9 +378,7 @@ export class EnqueuedCallsProcessor { // The proof is not used in simulation. const proof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH); - const vk = isFromPrivate - ? VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS) // TODO(#7410) tube VK goes here - : ProtocolCircuitVks.PublicKernelMergeArtifact; + const vk = isFromPrivate ? TubeVk : ProtocolCircuitVks.PublicKernelMergeArtifact; const vkIndex = isFromPrivate ? TUBE_INDEX : getVKIndex(vk); const siblingPath = getVKSiblingPath(vkIndex); From 104b595830d3981f2e90169cb22272ff0f31f7da Mon Sep 17 00:00:00 2001 From: sirasistant <sirasistant@gmail.com> Date: Fri, 11 Oct 2024 10:05:13 +0000 Subject: [PATCH 04/10] fmt --- .../crates/parity-lib/src/root/root_rollup_parity_input.nr | 5 ++++- .../rollup-lib/src/abis/previous_rollup_block_data.nr | 5 ++++- .../crates/rollup-lib/src/abis/previous_rollup_data.nr | 5 ++++- .../crates/types/src/abis/private_kernel_data.nr | 4 ++-- .../crates/types/src/abis/public_kernel_inner_data.nr | 3 +-- .../crates/types/src/recursion/verification_key.nr | 7 +++++-- .../crates/types/src/tests/fixture_builder.nr | 6 +++++- 7 files changed, 25 insertions(+), 10 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_rollup_parity_input.nr b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_rollup_parity_input.nr index d2686645431e..3fb976cbc139 100644 --- a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_rollup_parity_input.nr +++ b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_rollup_parity_input.nr @@ -1,6 +1,9 @@ use dep::types::{ traits::Empty, - recursion::{verification_key::{VerificationKey, HonkVerificationKey}, proof::NestedRecursiveProof, traits::Verifiable}, + recursion::{ + verification_key::{VerificationKey, HonkVerificationKey}, proof::NestedRecursiveProof, + traits::Verifiable +}, constants::{ROOT_PARITY_INDEX, VK_TREE_HEIGHT}, merkle_tree::membership::assert_check_membership }; use crate::parity_public_inputs::ParityPublicInputs; diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr index eb6ea141b037..19e2b3ec1dce 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr @@ -1,7 +1,10 @@ use crate::abis::block_root_or_block_merge_public_inputs::BlockRootOrBlockMergePublicInputs; use dep::types::{ constants::VK_TREE_HEIGHT, - recursion::{proof::NestedRecursiveProof, verification_key::{HonkVerificationKey, VerificationKey}, traits::Verifiable}, + recursion::{ + proof::NestedRecursiveProof, verification_key::{HonkVerificationKey, VerificationKey}, + traits::Verifiable +}, traits::Empty, merkle_tree::MembershipWitness, merkle_tree::membership::assert_check_membership, utils::arrays::find_index_hint }; diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr index 8a71fe201c5c..1c35ba5c6408 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr @@ -1,7 +1,10 @@ use crate::abis::base_or_merge_rollup_public_inputs::BaseOrMergeRollupPublicInputs; use dep::types::{ constants::VK_TREE_HEIGHT, - recursion::{proof::NestedRecursiveProof, verification_key::{VerificationKey, HonkVerificationKey}, traits::Verifiable}, + recursion::{ + proof::NestedRecursiveProof, verification_key::{VerificationKey, HonkVerificationKey}, + traits::Verifiable +}, traits::Empty, merkle_tree::MembershipWitness, merkle_tree::membership::assert_check_membership, utils::arrays::find_index_hint }; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr index 6ea5cbbb435d..bac68405b728 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr @@ -1,8 +1,8 @@ use crate::{ abis::kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs, constants::{PRIVATE_KERNEL_RESET_INDEX, VK_TREE_HEIGHT}, - merkle_tree::membership::assert_check_membership, recursion::{verification_key::ClientIVCVerificationKey}, - utils::arrays::find_index_hint + merkle_tree::membership::assert_check_membership, + recursion::{verification_key::ClientIVCVerificationKey}, utils::arrays::find_index_hint }; pub struct PrivateKernelData { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_inner_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_inner_data.nr index 48c0aa0560eb..d1979110ba59 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_inner_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_inner_data.nr @@ -1,7 +1,6 @@ use crate::{ abis::kernel_circuit_public_inputs::VMCircuitPublicInputs, - recursion::{proof::NestedRecursiveProof, verification_key::HonkVerificationKey, traits::Verifiable}, - + recursion::{proof::NestedRecursiveProof, verification_key::HonkVerificationKey, traits::Verifiable} }; pub struct PublicKernelInnerData { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr b/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr index 49c00b4cf566..f4f5b9762c93 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr @@ -1,4 +1,7 @@ -use crate::{traits::{Serialize, Deserialize, Empty}, constants::{HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS}}; +use crate::{ + traits::{Serialize, Deserialize, Empty}, + constants::{HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS} +}; pub struct VerificationKey<let N: u32> { key: [Field; N], @@ -7,7 +10,7 @@ pub struct VerificationKey<let N: u32> { impl<let N: u32> Serialize<N + 1> for VerificationKey<N> { fn serialize(self) -> [Field; N + 1] { - let mut fields = [0; N+1]; + let mut fields = [0; N + 1]; for i in 0..N { fields[i] = self.key[i]; } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr index e8e3a1111a0d..e5df48c41080 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr @@ -52,7 +52,11 @@ use crate::{ partial_state_reference::PartialStateReference, tests::{fixtures, fixtures::{contracts::ContractData, contract_functions::ContractFunction}}, transaction::{tx_context::TxContext, tx_request::TxRequest}, traits::Empty, - recursion::{verification_key::{HonkVerificationKey, ClientIVCVerificationKey, VerificationKey}, proof::NestedRecursiveProof}, point::Point + recursion::{ + verification_key::{HonkVerificationKey, ClientIVCVerificationKey, VerificationKey}, + proof::NestedRecursiveProof +}, + point::Point }; fn subarray<T, let N: u32, let M: u32>(arr: [T; N]) -> [T; M] { From efe42f97709a925834231da3fac046619ab3d3f8 Mon Sep 17 00:00:00 2001 From: sirasistant <sirasistant@gmail.com> Date: Fri, 11 Oct 2024 11:36:52 +0000 Subject: [PATCH 05/10] fix tests --- .../src/private_kernel_inner.nr | 16 +- .../src/private_kernel_reset.nr | 16 +- .../src/private_kernel_tail.nr | 16 +- .../src/public_kernel_app_logic.nr | 523 ------------------ .../src/public_kernel_merge.nr | 16 +- .../src/public_kernel_setup.nr | 512 ----------------- .../src/public_kernel_tail.nr | 17 +- .../src/public_kernel_teardown.nr | 434 --------------- .../src/abis/previous_rollup_block_data.nr | 1 + .../src/abis/previous_rollup_data.nr | 1 + .../rollup-lib/src/base/base_rollup_inputs.nr | 21 +- .../block_merge/block_merge_rollup_inputs.nr | 22 +- .../src/merge/merge_rollup_inputs.nr | 22 +- .../crates/types/src/abis/kernel_data.nr | 1 + .../types/src/abis/private_kernel_data.nr | 1 + .../types/src/abis/public_kernel_data.nr | 1 + .../src/scripts/generate_vk_hashes.ts | 3 +- .../src/orchestrator/orchestrator.ts | 2 +- 18 files changed, 82 insertions(+), 1543 deletions(-) delete mode 100644 noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr index 4ccf8f61c3be..5ad472b7a244 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr @@ -85,7 +85,7 @@ mod tests { use crate::private_kernel_inner::{PrivateKernelInnerCircuitPrivateInputs, ALLOWED_PREVIOUS_CIRCUITS}; use dep::types::{ abis::{kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs}, - constants::PRIVATE_KERNEL_INIT_INDEX, + constants::{PRIVATE_KERNEL_INIT_INDEX, BASE_ROLLUP_INDEX}, tests::{fixture_builder::FixtureBuilder, utils::assert_array_eq} }; @@ -155,11 +155,11 @@ mod tests { let _res = builder.execute(); } } - // TODO(#7410) we need the tube vk to reinstate this - // #[test(should_fail_with="Invalid vk index")] - // fn invalid_previous_kernel() { - // let mut builder = PrivateKernelInnerInputsBuilder::new(); - // builder.previous_kernel = builder.previous_kernel.in_vk_tree(BASE_ROLLUP_INDEX); - // let _res = builder.execute(); - // } + + #[test(should_fail_with="Invalid vk index")] + fn invalid_previous_kernel() { + let mut builder = PrivateKernelInnerInputsBuilder::new(); + builder.previous_kernel = builder.previous_kernel.in_vk_tree(BASE_ROLLUP_INDEX); + let _res = builder.execute(); + } } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr index 2317649881a4..54b602117b3b 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr @@ -132,7 +132,7 @@ mod tests { }; use dep::types::constants::{ MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_KEY_VALIDATION_REQUESTS_PER_TX, - GENERATOR_INDEX__OVSK_M, PRIVATE_KERNEL_INNER_INDEX + GENERATOR_INDEX__OVSK_M, PRIVATE_KERNEL_INNER_INDEX, BASE_ROLLUP_INDEX }; use dep::types::{ abis::{ @@ -609,11 +609,11 @@ mod tests { // The 2nd nullifier has been siloed assert(output_nullifiers[2].value() != nullifiers[2].value()); } - // TODO(#7410) we need the tube vk to reinstate this - // #[test(should_fail_with="Invalid vk index")] - // fn invalid_previous_kernel() { - // let mut builder = PrivateKernelResetInputsBuilder::new(); - // builder.previous_kernel = builder.previous_kernel.in_vk_tree(BASE_ROLLUP_INDEX); - // let _res = builder.execute(); - // } + + #[test(should_fail_with="Invalid vk index")] + fn invalid_previous_kernel() { + let mut builder = PrivateKernelResetInputsBuilder::new(); + builder.previous_kernel = builder.previous_kernel.in_vk_tree(BASE_ROLLUP_INDEX); + let _res = builder.execute(); + } } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr index 26b48c38174e..809f02e1634d 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr @@ -57,7 +57,7 @@ mod tests { use crate::private_kernel_tail::{PrivateKernelTailCircuitPrivateInputs, ALLOWED_PREVIOUS_CIRCUITS}; use dep::types::constants::{ DA_BYTES_PER_FIELD, DA_GAS_PER_BYTE, GENERATOR_INDEX__IVSK_M, L2_GAS_PER_LOG_BYTE, - L2_GAS_PER_NULLIFIER, PRIVATE_KERNEL_INNER_INDEX + L2_GAS_PER_NULLIFIER, PRIVATE_KERNEL_INNER_INDEX, BASE_ROLLUP_INDEX }; use dep::types::{ abis::{ @@ -310,11 +310,11 @@ mod tests { let _res = builder.execute(); } } - // TODO(#7410) we need the tube vk to reinstate this - // #[test(should_fail_with="Invalid vk index")] - // fn invalid_previous_kernel() { - // let mut builder = PrivateKernelTailInputsBuilder::new(); - // builder.previous_kernel = builder.previous_kernel.in_vk_tree(BASE_ROLLUP_INDEX); - // let _res = builder.execute(); - // } + + #[test(should_fail_with="Invalid vk index")] + fn invalid_previous_kernel() { + let mut builder = PrivateKernelTailInputsBuilder::new(); + builder.previous_kernel = builder.previous_kernel.in_vk_tree(BASE_ROLLUP_INDEX); + let _res = builder.execute(); + } } diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr deleted file mode 100644 index 4bcb3ad9d9d6..000000000000 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr +++ /dev/null @@ -1,523 +0,0 @@ -use crate::{ - components::{ - previous_kernel_validator::PreviousKernelValidator, - public_call_data_validator::PublicCallDataValidator, - public_kernel_output_composer::PublicKernelOutputComposer -}, - public_kernel_phase::PublicKernelPhase -}; -use dep::types::{ - abis::{ - kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs, public_kernel_data::PublicKernelData, - public_call_data::PublicCallData -}, - constants::{PUBLIC_KERNEL_SETUP_INDEX, PUBLIC_KERNEL_APP_LOGIC_INDEX, PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX} -}; - -global ALLOWED_PREVIOUS_CIRCUITS = [ - PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX, - PUBLIC_KERNEL_SETUP_INDEX, - PUBLIC_KERNEL_APP_LOGIC_INDEX, -]; - -pub struct PublicKernelAppLogicCircuitPrivateInputs { - previous_kernel: PublicKernelData, - public_call: PublicCallData, -} - -impl PublicKernelAppLogicCircuitPrivateInputs { - fn execute(self) -> PublicKernelCircuitPublicInputs { - let phase = PublicKernelPhase.APP_LOGIC; - - let previous_kernel_validator = PreviousKernelValidator::new(self.previous_kernel); - previous_kernel_validator.validate_phase(phase); - previous_kernel_validator.validate_proof(ALLOWED_PREVIOUS_CIRCUITS); - - let call_data_validator = PublicCallDataValidator::new(self.public_call, PublicKernelPhase.APP_LOGIC); - call_data_validator.validate(); - call_data_validator.validate_against_previous_kernel(self.previous_kernel.public_inputs); - - // noir-fmt:ignore - PublicKernelOutputComposer::new_from_previous_kernel(self.previous_kernel.public_inputs) - .remove_top_call_request(phase) - .propagate_from_public_call(self.public_call.call_stack_item.public_inputs, phase) - .finish() - } -} - -mod tests { - use crate::{public_kernel_app_logic::{PublicKernelAppLogicCircuitPrivateInputs, ALLOWED_PREVIOUS_CIRCUITS}}; - use dep::types::{ - abis::{ - gas::Gas, kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs, - nullifier::{Nullifier, ScopedNullifier}, - public_call_stack_item_compressed::PublicCallStackItemCompressed, - public_data_read::PublicDataRead, public_data_update_request::PublicDataUpdateRequest - }, - constants::{PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX, PUBLIC_KERNEL_APP_LOGIC_INDEX}, - contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest}, - address::AztecAddress, hash::compute_siloed_nullifier, - tests::{fixture_builder::FixtureBuilder, utils::assert_array_eq}, traits::is_empty - }; - - struct PublicKernelAppLogicCircuitPrivateInputsBuilder { - previous_kernel: FixtureBuilder, - previous_non_revertible: FixtureBuilder, - public_call: FixtureBuilder, - } - - impl PublicKernelAppLogicCircuitPrivateInputsBuilder { - pub fn new() -> Self { - let previous_kernel = FixtureBuilder::new().as_parent_contract().in_vk_tree(PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX); - let previous_non_revertible = FixtureBuilder::new().as_parent_contract(); - let mut public_call = FixtureBuilder::new().is_public_function(); - public_call.value_offset = 9999; // Add an offset so that the mock data won't be the same as the values in previous_kernel. - - PublicKernelAppLogicCircuitPrivateInputsBuilder { previous_kernel, previous_non_revertible, public_call } - } - - pub fn is_delegate_call(&mut self) -> Self { - let _ = self.public_call.is_delegate_call(); - *self - } - - pub fn to_public_data_reads<let N: u32>(self, contract_storage_reads: [StorageRead; N]) -> [PublicDataRead; N] { - let storage_contract_address = self.public_call.storage_contract_address; - contract_storage_reads.map(|r: StorageRead| PublicDataRead::from_contract_storage_read(storage_contract_address, r)) - } - - pub fn to_public_data_update_requests<let N: u32>( - self, - storage_update_requests: [StorageUpdateRequest; N] - ) -> [PublicDataUpdateRequest; N] { - let storage_contract_address = self.public_call.storage_contract_address; - storage_update_requests.map( - |r: StorageUpdateRequest| - PublicDataUpdateRequest::from_contract_storage_update_request(storage_contract_address, r) - ) - } - - pub fn to_siloed_nullifiers<let N: u32>(self, nullifiers: [ScopedNullifier; N]) -> [Nullifier; N] { - let storage_contract_address = self.public_call.storage_contract_address; - nullifiers.map( - |n: ScopedNullifier| Nullifier { - value: compute_siloed_nullifier(storage_contract_address, n.value()), - note_hash: n.nullifier.note_hash, - counter: n.counter() - } - ) - } - - pub fn execute(&mut self) -> PublicKernelCircuitPublicInputs { - let public_call = self.public_call.to_public_call_data(); - // Adjust the call stack item hash for the current call in the previous iteration. - let compressed = public_call.call_stack_item.get_compressed(); - self.previous_kernel.push_public_call_request(compressed); - let mut previous_kernel = self.previous_kernel.to_public_kernel_data(true); - previous_kernel.public_inputs.end_non_revertible = self.previous_non_revertible.to_public_accumulated_data(); - - let kernel = PublicKernelAppLogicCircuitPrivateInputs { previous_kernel, public_call }; - - kernel.execute() - } - - pub fn get_call_request_item(self) -> PublicCallStackItemCompressed { - self.public_call.to_public_call_stack_item().get_compressed() - } - - pub fn failed_with_call_request_item(&mut self, item: PublicCallStackItemCompressed) { - let public_call = self.public_call.to_public_call_data(); - self.previous_kernel.push_public_call_request(item); - let previous_kernel = self.previous_kernel.to_public_kernel_data(true); - let kernel = PublicKernelAppLogicCircuitPrivateInputs { previous_kernel, public_call }; - let _ = kernel.execute(); - } - - pub fn succeeded(&mut self) { - let _ = self.execute(); - } - - pub fn failed(&mut self) { - let _ = self.execute(); - } - } - - #[test] - fn public_kernel_circuit_with_public_previous_kernel_should_succeed() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - builder.succeeded(); - } - - #[test(should_fail_with="Cannot run unnecessary app logic circuit")] - fn public_previous_kernel_private_previous_kernel_should_fail() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - builder.previous_kernel = FixtureBuilder::new().in_vk_tree(PUBLIC_KERNEL_APP_LOGIC_INDEX); - let public_call = builder.public_call.to_public_call_data(); - - // the key difference in this test versus those that use builder.execute() - // is that we do not add a public call request to the previous kernel. - // this means that when we call `to_public_kernel_data` below, - // it will say needs_app_logic is false - - let previous_kernel = builder.previous_kernel.to_public_kernel_data(true); - - let kernel = PublicKernelAppLogicCircuitPrivateInputs { previous_kernel, public_call }; - - let _ = kernel.execute(); - } - - #[test] - fn circuit_outputs_should_be_correctly_populated_with_previous_commitments() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - - // Setup 1 non-revertible note hash and log on the previous kernel. - builder.previous_non_revertible.append_note_hashes_with_logs(1); - let prev_non_rev_notes = builder.previous_non_revertible.note_hashes.storage; - let prev_non_rev_logs = builder.previous_non_revertible.to_public_accumulated_data().note_encrypted_logs_hashes; - - // Setup 2 revertible note hashes and logs on the previous kernel. - builder.previous_kernel.append_note_hashes_with_logs(2); - let prev_notes = builder.previous_kernel.note_hashes.storage; - let prev_logs = builder.previous_kernel.to_public_accumulated_data().note_encrypted_logs_hashes; - - // Setup 2 note hashes and logs on the current public call. - builder.public_call.append_note_hashes(2); - let curr_notes = builder.public_call.note_hashes.storage; - - let public_inputs = builder.execute(); - - assert_array_eq( - public_inputs.end_non_revertible.note_hashes, - [prev_non_rev_notes[0]] - ); - assert_array_eq( - public_inputs.end.note_hashes, - [prev_notes[0], prev_notes[1], curr_notes[0], curr_notes[1]] - ); - assert_array_eq( - public_inputs.end_non_revertible.note_encrypted_logs_hashes, - [prev_non_rev_logs[0]] - ); - assert_array_eq( - public_inputs.end.note_encrypted_logs_hashes, - [prev_logs[0], prev_logs[1]] - ); - } - - #[test] - fn circuit_outputs_should_be_correctly_populated_with_previous_update_requests() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - - // Setup 2 data writes on the previous kernel. - builder.previous_kernel.append_public_data_update_requests(2); - let previous = builder.previous_kernel.public_data_update_requests.storage; - // Setup 2 data writes on the current public inputs. - builder.public_call.append_contract_storage_update_requests(2); - let current = builder.to_public_data_update_requests(builder.public_call.contract_storage_update_requests.storage); - - let public_inputs = builder.execute(); - - assert_array_eq( - public_inputs.end.public_data_update_requests, - [previous[0], previous[1], current[0], current[1]] - ); - } - - #[test] - fn circuit_outputs_should_be_correctly_populated_with_previous_read_requests() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - - // Setup 2 data reads on the previous kernel. - builder.previous_kernel.append_public_data_read_requests(2); - let previous = builder.previous_kernel.public_data_reads.storage; - // Setup 2 data reads on the current public inputs. - builder.public_call.append_contract_storage_read_requests(2); - let current = builder.to_public_data_reads(builder.public_call.contract_storage_reads.storage); - - let public_inputs = builder.execute(); - - assert_array_eq( - public_inputs.validation_requests.public_data_reads, - [previous[0], previous[1], current[0], current[1]] - ); - } - - #[test] - fn circuit_outputs_should_be_correctly_populated_with_previous_nullifiers() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - - // Setup 2 new nullifiers on the previous kernel. - builder.previous_kernel.append_nullifiers(2); - let previous = builder.previous_kernel.nullifiers.storage.map(|n: ScopedNullifier| n.nullifier); - // Setup 2 new nullifiers on the current public call. - builder.public_call.append_nullifiers(2); - let siloed = builder.to_siloed_nullifiers(builder.public_call.nullifiers.storage); - - let public_inputs = builder.execute(); - - assert_array_eq( - public_inputs.end.nullifiers, - [previous[0], previous[1], siloed[0], siloed[1]] - ); - } - - #[test] - fn circuit_outputs_should_be_correctly_populated_with_previous_l2_to_l1_msg() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - - builder.previous_kernel.append_l2_to_l1_msgs(1); - let previous = builder.previous_kernel.l2_to_l1_msgs.storage; - // Setup 1 new l2 to l1 message on the current public inputs. - builder.public_call.append_l2_to_l1_msgs(1); - let current = builder.public_call.l2_to_l1_msgs.storage; - - let public_inputs = builder.execute(); - - assert_array_eq(public_inputs.end.l2_to_l1_msgs, [previous[0], current[0]]); - } - // TODO: Break up this test into smaller tests. - #[test] - fn circuit_outputs_should_be_correctly_populated_with_previous_public_kernel_logs() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - // Logs for the current call stack. - builder.public_call.append_unencrypted_log_hashes(1); - let curr_data = builder.public_call.to_public_accumulated_data(); - - // Logs for the previous call stack. - builder.previous_kernel.append_encrypted_log_hashes(1); - builder.previous_kernel.append_unencrypted_log_hashes(1); - let prev_data = builder.previous_kernel.to_public_accumulated_data(); - let expected_unencrypted_logs = [prev_data.unencrypted_logs_hashes[0], curr_data.unencrypted_logs_hashes[0]]; - // we assume the encrypted log is already siloed from private kernels - let expected_encrypted_logs = [prev_data.encrypted_logs_hashes[0]]; - - let public_inputs = builder.execute(); - - assert_array_eq( - public_inputs.end.encrypted_logs_hashes, - expected_encrypted_logs - ); - assert_array_eq( - public_inputs.end.unencrypted_logs_hashes, - expected_unencrypted_logs - ); - } - - #[test(should_fail_with="No contract storage update requests are allowed for static calls")] - fn previous_public_kernel_fails_if_contract_storage_update_requests_on_static_call() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - builder.public_call.is_static_call = true; - builder.public_call.append_contract_storage_update_requests(1); - - builder.failed(); - } - - #[test(should_fail_with="curent contract address must not match storage contract address for delegate calls")] - fn previous_public_kernel_fails_if_incorrect_storage_contract_on_delegate_call() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new().is_delegate_call(); - - builder.public_call.contract_address = builder.public_call.storage_contract_address; - - builder.failed(); - } - - #[test(should_fail_with="note_hashes must be empty for static calls")] - fn public_kernel_fails_creating_note_hashes_on_static_call() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - builder.public_call.is_static_call = true; - builder.public_call.append_note_hashes(1); - - builder.failed(); - } - - #[test(should_fail_with="nullifiers must be empty for static calls")] - fn public_kernel_fails_creating_nullifiers_on_static_call() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - builder.public_call.is_static_call = true; - builder.public_call.append_nullifiers(1); - - builder.failed(); - } - - #[test(should_fail_with="call stack item does not match item at the top of the call stack")] - fn public_kernel_circuit_fails_on_incorrect_storage_contract_in_delegate_call() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new().is_delegate_call(); - - let mut item = builder.get_call_request_item(); - // Set the storage contract address to be the contract address. - item.call_context.storage_contract_address = builder.public_call.contract_address; - - builder.failed_with_call_request_item(item); - } - - #[test] - fn circuit_outputs_should_be_correctly_populated_with_public_call_requests() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - - builder.previous_kernel.append_public_call_requests(2); - let prev_calls = builder.previous_kernel.public_call_requests.storage; - - builder.public_call.append_public_call_requests(2); - let curr_calls = builder.public_call.public_call_requests.storage; - - let public_inputs = builder.execute(); - - assert_array_eq( - public_inputs.end.public_call_stack, - [prev_calls[0], prev_calls[1], curr_calls[0], curr_calls[1]] - ); - } - - #[test(should_fail_with="Cannot run app logic circuit before setup circuit")] - fn previous_kernel_non_empty_non_revertible_public_call_requests_should_fail() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - - builder.previous_non_revertible.append_public_call_requests(1); - builder.public_call.append_public_call_requests(1); - - builder.failed(); - } - - #[test] - fn propagate_nullifier_non_existent_read_requests() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - - builder.public_call.append_nullifier_non_existent_read_requests(2); - let requests = builder.public_call.nullifier_non_existent_read_requests.storage; - - let public_inputs = builder.execute(); - - let end_requests = public_inputs.validation_requests.nullifier_non_existent_read_requests; - assert_array_eq(end_requests, [requests[0], requests[1]]); - } - - #[test] - fn updates_revertible_gas_used() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - - // Transaction gas limit is 1k - builder.previous_kernel.tx_context.gas_settings.gas_limits = Gas::new(1000, 1000); - - // Revertible has already used 300 - builder.previous_kernel.gas_used = Gas::new(300, 300); - - // This call starts with 700 gas left - builder.public_call.start_gas_left = Gas::new(700, 700); - - // And uses 200, ending with 500 left - builder.public_call.end_gas_left = Gas::new(500, 500); - - // So the updated gas used by revertible must go up by 200, and non-revertible must stay the same - let output = builder.execute(); - assert_eq(output.end.gas_used, Gas::new(500, 500)); - assert_eq(output.end_non_revertible.gas_used, Gas::new(0, 0)); - } - - #[test(should_fail_with="Start gas for public phase does not match transaction gas left")] - fn validates_start_gas() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - - builder.public_call.is_execution_request = true; // don't need to check start gas for nested calls - builder.public_call.start_gas_left = Gas::new(100, 100); - - builder.failed(); - } - - #[test(should_fail_with="Transaction fee must be zero on setup and app phases")] - fn validates_transaction_fee() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - - builder.public_call.transaction_fee = 10; - - builder.failed(); - } - - #[test] - fn propagates_global_variables_if_empty() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - - builder.public_call.global_variables.block_number = 11; - - let public_inputs = builder.execute(); - - assert_eq(public_inputs.constants.global_variables.block_number, 11); - } - - #[test(should_fail_with="Global variables injected into the public call do not match constants")] - fn validates_global_variables() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - - builder.previous_kernel.global_variables.block_number = 10; - builder.public_call.global_variables.block_number = 11; - - builder.failed(); - } - - #[test] - unconstrained fn propagate_fee_payer() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - let fee_payer = AztecAddress::from_field(123); - builder.previous_kernel.set_fee_payer(fee_payer); - let public_inputs = builder.execute(); - assert_eq(public_inputs.fee_payer, fee_payer); - - // Check that the fee payer is not set if is_fee_payer is false - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - assert_eq(is_empty(builder.previous_kernel.fee_payer), true); - let public_inputs = builder.execute(); - assert_eq(public_inputs.fee_payer, AztecAddress::empty()); - } - - #[test] - unconstrained fn correctly_updates_revert_code() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - let public_inputs = builder.execute(); - assert_eq(public_inputs.revert_code, 0); - - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - builder.public_call.revert_code = 1; - let public_inputs = builder.execute(); - assert_eq(public_inputs.revert_code, 1); - - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - builder.previous_kernel.revert_code = 1; - let public_inputs = builder.execute(); - assert_eq(public_inputs.revert_code, 1); - } - - #[test] - fn clears_stack_if_current_call_revert_code_is_set() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - builder.public_call.revert_code = 1; - - builder.previous_kernel.append_public_call_requests(2); - - builder.previous_kernel.append_public_teardown_call_requests(2); - let teardown_calls = builder.previous_kernel.public_teardown_call_stack.storage; - - let public_inputs = builder.execute(); - - assert_array_eq(public_inputs.end.public_call_stack, []); - assert_array_eq( - public_inputs.public_teardown_call_stack, - [teardown_calls[0], teardown_calls[1]] - ); - } - - #[test] - fn valid_previous_kernel() { - for i in 0..ALLOWED_PREVIOUS_CIRCUITS.len() { - let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - builder.previous_kernel = builder.previous_kernel.in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS[i]); - - let _res = builder.execute(); - } - } - // TODO(#7410) we need the tube vk to reinstate this - // #[test(should_fail_with="Invalid vk index")] - // fn invalid_previous_kernel() { - // let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); - // builder.previous_kernel = builder.previous_kernel.in_vk_tree(BASE_ROLLUP_INDEX); - // let _res = builder.execute(); - // } -} diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_merge.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_merge.nr index 65073adf19de..08ed1cc6039f 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_merge.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_merge.nr @@ -90,7 +90,7 @@ mod tests { kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs, max_block_number::MaxBlockNumber, validation_requests::PublicValidationRequestArrayLengths }, - constants::PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX, + constants::{PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX, BASE_ROLLUP_INDEX}, tests::{fixture_builder::FixtureBuilder, utils::assert_array_eq} }; @@ -246,11 +246,11 @@ mod tests { builder.succeeded(); } } - // TODO(#7410) we need the tube vk to reinstate this - // #[test(should_fail_with="Invalid vk index")] - // fn invalid_previous_kernel() { - // let mut builder = PublicKernelMergeCircuitPrivateInputsBuilder::new(); - // builder.previous_kernel = builder.previous_kernel.in_vk_tree(BASE_ROLLUP_INDEX); - // let _res = builder.execute(); - // } + + #[test(should_fail_with="Invalid vk index")] + fn invalid_previous_kernel() { + let mut builder = PublicKernelMergeCircuitPrivateInputsBuilder::new(); + builder.previous_kernel = builder.previous_kernel.in_vk_tree(BASE_ROLLUP_INDEX); + let _res = builder.execute(); + } } diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr deleted file mode 100644 index 04a1fdbe9dac..000000000000 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr +++ /dev/null @@ -1,512 +0,0 @@ -use crate::{ - components::{ - previous_kernel_validator::PreviousKernelValidator, - public_call_data_validator::PublicCallDataValidator, - public_kernel_output_composer::PublicKernelOutputComposer -}, - public_kernel_phase::PublicKernelPhase -}; -use dep::types::{ - abis::{ - kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs, public_kernel_data::PublicKernelData, - public_call_data::PublicCallData -}, - constants::{PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX, PUBLIC_KERNEL_SETUP_INDEX} -}; - -global ALLOWED_PREVIOUS_CIRCUITS = [ - PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX, - PUBLIC_KERNEL_SETUP_INDEX, -]; - -pub struct PublicKernelSetupCircuitPrivateInputs { - // Note: One might think that our previous_kernel ought to be - // a PrivateKernelTailData. However, we instead supply a PublicKernelData. - // This is because PrivateKernelTailData is a subset of PublicKernelData. - // And we just initialize the missing values to zero in TS before passing it to the circuit, - // except for the constants.global_variables which we populate with the current block values. - // This is a bit of a hack, but it allows us to reuse the setup circuit until - // the setup phase of the public kernel is complete. Maybe in a perfect world we would - // have a SetupInit, SetupInner, etc, but this will change anyway once the public VM is able to - // consume entire enqueued public calls. - previous_kernel: PublicKernelData, - public_call: PublicCallData, -} - -impl PublicKernelSetupCircuitPrivateInputs { - fn execute(self) -> PublicKernelCircuitPublicInputs { - let phase = PublicKernelPhase.SETUP; - - let previous_kernel_validator = PreviousKernelValidator::new(self.previous_kernel); - previous_kernel_validator.validate_phase(phase); - previous_kernel_validator.validate_proof(ALLOWED_PREVIOUS_CIRCUITS); - - let call_data_validator = PublicCallDataValidator::new(self.public_call, phase); - call_data_validator.validate(); - call_data_validator.validate_against_previous_kernel(self.previous_kernel.public_inputs); - - // noir-fmt:ignore - PublicKernelOutputComposer::new_from_previous_kernel(self.previous_kernel.public_inputs) - .remove_top_call_request(phase) - .propagate_from_public_call(self.public_call.call_stack_item.public_inputs, phase) - .finish() - } -} - -mod tests { - use crate::{public_kernel_setup::{PublicKernelSetupCircuitPrivateInputs, ALLOWED_PREVIOUS_CIRCUITS}}; - use dep::types::{ - abis::{ - function_selector::FunctionSelector, gas::Gas, - kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs, max_block_number::MaxBlockNumber, - public_call_stack_item_compressed::PublicCallStackItemCompressed, - public_data_read::PublicDataRead, public_data_update_request::PublicDataUpdateRequest, - read_request::ReadRequest - }, - address::AztecAddress, constants::PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX, - contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest}, - tests::{fixture_builder::FixtureBuilder, utils::assert_array_eq}, traits::is_empty - }; - - struct PublicKernelSetupCircuitPrivateInputsBuilder { - previous_kernel: FixtureBuilder, - previous_revertible: FixtureBuilder, - public_call: FixtureBuilder, - } - - impl PublicKernelSetupCircuitPrivateInputsBuilder { - pub fn new() -> Self { - let previous_kernel = FixtureBuilder::new().as_parent_contract().in_vk_tree(PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX); - let previous_revertible = FixtureBuilder::new(); - let mut public_call = FixtureBuilder::new().is_public_function(); - public_call.value_offset = 9999; // Add an offset so that the mock data won't be the same as the values in previous_kernel. - - PublicKernelSetupCircuitPrivateInputsBuilder { previous_kernel, previous_revertible, public_call } - } - - pub fn is_delegate_call(&mut self) -> Self { - let _ = self.public_call.is_delegate_call(); - *self - } - - pub fn to_public_data_reads<let N: u32>(self, contract_storage_reads: [StorageRead; N]) -> [PublicDataRead; N] { - let storage_contract_address = self.public_call.storage_contract_address; - contract_storage_reads.map(|r: StorageRead| PublicDataRead::from_contract_storage_read(storage_contract_address, r)) - } - - pub fn to_public_data_update_requests<let N: u32>( - self, - storage_update_requests: [StorageUpdateRequest; N] - ) -> [PublicDataUpdateRequest; N] { - let storage_contract_address = self.public_call.storage_contract_address; - storage_update_requests.map( - |r: StorageUpdateRequest| - PublicDataUpdateRequest::from_contract_storage_update_request(storage_contract_address, r) - ) - } - - pub fn execute(&mut self) -> PublicKernelCircuitPublicInputs { - let public_call = self.public_call.to_public_call_data(); - - // In order to run the setup circuit, we must have an enqueued public call for setup. - let compressed_item = public_call.call_stack_item.get_compressed(); - self.previous_kernel.push_public_call_request(compressed_item); - - let mut previous_kernel = self.previous_kernel.to_public_kernel_data(false); - - previous_kernel.public_inputs.end = self.previous_revertible.to_public_accumulated_data(); - - // Run the kernel on the setup call - let kernel = PublicKernelSetupCircuitPrivateInputs { previous_kernel, public_call }; - kernel.execute() - } - - pub fn get_call_request_item(self) -> PublicCallStackItemCompressed { - self.public_call.to_public_call_stack_item().get_compressed() - } - - pub fn failed_with_call_request_item(&mut self, item: PublicCallStackItemCompressed) { - let public_call = self.public_call.to_public_call_data(); - self.previous_kernel.push_public_call_request(item); - let previous_kernel = self.previous_kernel.to_public_kernel_data(false); - - let kernel = PublicKernelSetupCircuitPrivateInputs { previous_kernel, public_call }; - let _ = kernel.execute(); - } - - pub fn succeeded(&mut self) { - let _ = self.execute(); - } - - pub fn failed(&mut self) { - let _ = self.execute(); - } - } - - #[test(should_fail_with="Bytecode hash cannot be zero")] - fn no_bytecode_hash_should_fail() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - builder.public_call.bytecode_hash = 0; - - builder.failed(); - } - - #[test(should_fail_with="Contract address cannot be zero")] - fn contract_address_must_be_valid() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - - builder.previous_kernel.append_public_call_requests(1); - builder.public_call.contract_address = AztecAddress::zero(); - - builder.failed(); - } - - #[test(should_fail_with="Function signature cannot be zero")] - fn function_selector_must_be_valid() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - builder.public_call.function_data.selector = FunctionSelector::zero(); - - builder.failed(); - } - - #[test(should_fail_with="Cannot execute a private function with the public kernel circuit")] - fn private_call_should_fail() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - builder.public_call.function_data.is_private = true; - - builder.failed(); - } - - #[test(should_fail_with="call stack item does not match item at the top of the call stack")] - fn inconsistent_call_request_item_should_fail() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - - let mut item = builder.get_call_request_item(); - // Tweak the call stack item. - item.args_hash += 1; - - builder.failed_with_call_request_item(item); - } - - #[test(should_fail_with="call stack item does not match item at the top of the call stack")] - fn incorrect_msg_sender_fails_for_regular_calls() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - - let mut item = builder.get_call_request_item(); - // Set the msg_sender to a wrong value. - item.call_context.msg_sender.inner += 1; - - builder.failed_with_call_request_item(item); - } - - #[test(should_fail_with="call stack storage address does not match expected contract address")] - fn incorrect_storage_contract_address_fails_for_regular_calls() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - - // Set the storage contract address to a wrong value. - builder.public_call.storage_contract_address.inner += 1; - - builder.failed(); - } - - #[test] - fn delegate_call_succeeds() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new().is_delegate_call(); - builder.succeeded(); - } - - #[test(should_fail_with="call stack item does not match item at the top of the call stack")] - fn incorrect_msg_sender_for_delegate_calls_fails() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new().is_delegate_call(); - - let mut item = builder.get_call_request_item(); - // Set the msg_sender to be the caller contract. - item.call_context.msg_sender = builder.previous_kernel.contract_address; - - builder.failed_with_call_request_item(item); - } - - #[test(should_fail_with="curent contract address must not match storage contract address for delegate calls")] - fn previous_private_kernel_fails_if_incorrect_storage_contract_on_delegate_call() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new().is_delegate_call(); - - builder.public_call.contract_address = builder.public_call.storage_contract_address; - - builder.failed(); - } - - #[test(should_fail_with = "incorrect storage_contract_address for call request")] - fn incorrect_storage_contract_address_for_call_request_fails() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - - builder.public_call.append_public_call_requests(1); - let mut call_request = builder.public_call.public_call_requests.pop(); - // Change the caller contract address to be a different value. - call_request.item.call_context.storage_contract_address.inner += 1; - builder.public_call.public_call_requests.push(call_request); - - builder.failed(); - } - - #[test(should_fail_with="incorrect storage_contract_address for delegate call request")] - fn incorrect_call_context_for_delegate_call_request_fails() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - - builder.public_call.append_public_call_requests_delegate(1); - let mut call_request = builder.public_call.public_call_requests.pop(); - // Change the storage contract address to be the contract address. - call_request.item.call_context.storage_contract_address = call_request.item.contract_address; - builder.public_call.public_call_requests.push(call_request); - - builder.failed(); - } - - #[test] - fn public_kernel_circuit_with_private_previous_kernel_should_succeed() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - builder.succeeded(); - } - - #[test] - fn circuit_outputs_should_be_correctly_populated_with_previous_private_kernel() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - - builder.previous_kernel.max_block_number = MaxBlockNumber::new(13); - - builder.public_call.append_public_call_requests(2); - let curr_calls = builder.public_call.public_call_requests.storage; - - builder.previous_kernel.append_public_call_requests(1); - let prev_calls = builder.previous_kernel.public_call_requests.storage; - - builder.public_call.append_contract_storage_update_requests(2); - let update_requests = builder.public_call.contract_storage_update_requests.storage; - - builder.public_call.append_contract_storage_read_requests(3); - let read_requests = builder.public_call.contract_storage_reads.storage; - - let public_inputs = builder.execute(); - - assert_eq(public_inputs.validation_requests.for_rollup.max_block_number.unwrap(), 13); - assert_array_eq( - public_inputs.end_non_revertible.public_call_stack, - [prev_calls[0], curr_calls[0], curr_calls[1]] - ); - assert_array_eq( - public_inputs.end_non_revertible.public_data_update_requests, - builder.to_public_data_update_requests([update_requests[0], update_requests[1]]) - ); - assert_array_eq( - public_inputs.validation_requests.public_data_reads, - builder.to_public_data_reads([read_requests[0], read_requests[1], read_requests[2]]) - ); - } - - #[test(should_fail_with="Cannot run unnecessary setup circuit")] - fn previous_kernel_empty_public_call_stack_should_fail() { - let builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - let previous_kernel = builder.previous_kernel.to_public_kernel_data(false); - let public_call = builder.public_call.to_public_call_data(); - let kernel = PublicKernelSetupCircuitPrivateInputs { previous_kernel, public_call }; - let _ = kernel.execute(); - } - - #[test(should_fail_with="No contract storage update requests are allowed for static calls")] - fn previous_private_kernel_fails_if_contract_storage_update_requests_on_static_call() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - builder.public_call.is_static_call = true; - builder.public_call.append_contract_storage_update_requests(1); - - builder.failed(); - } - - #[test] - fn logs_are_handled_as_expected() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - - // Logs for the current call stack. - let unencrypted_logs_hash = 26; - let unencrypted_log_preimages_length = 50; - builder.public_call.add_unencrypted_log_hash(unencrypted_logs_hash, unencrypted_log_preimages_length); - - // Logs for the previous call stack. - let prev_encrypted_logs_hash = 80; - let prev_encrypted_log_preimages_length = 13; - let prev_unencrypted_logs_hash = 956; - let prev_unencrypted_log_preimages_length = 24; - builder.previous_kernel.add_encrypted_log_hash(prev_encrypted_logs_hash, prev_encrypted_log_preimages_length); - builder.previous_kernel.add_unencrypted_log_hash( - prev_unencrypted_logs_hash, - prev_unencrypted_log_preimages_length - ); - let prev_data = builder.previous_kernel.to_public_accumulated_data(); - - let expected_unencrypted_logs = [prev_data.unencrypted_logs_hashes[0], builder.public_call.unencrypted_logs_hashes.storage[0]]; - // we assume the encrypted log is already siloed from private kernels - let expected_encrypted_logs = [prev_data.encrypted_logs_hashes[0]]; - - let public_inputs = builder.execute(); - - assert_array_eq( - public_inputs.end_non_revertible.encrypted_logs_hashes, - expected_encrypted_logs - ); - assert_array_eq( - public_inputs.end_non_revertible.unencrypted_logs_hashes, - expected_unencrypted_logs - ); - } - - #[test] - fn propagate_nullifier_non_existent_read_requests() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - let storage_contract_address = builder.public_call.storage_contract_address; - - let request_0 = ReadRequest { value: 123, counter: 4567 }.scope(storage_contract_address); - builder.public_call.nullifier_non_existent_read_requests.push(request_0); - let request_1 = ReadRequest { value: 777888, counter: 90 }.scope(storage_contract_address); - builder.public_call.nullifier_non_existent_read_requests.push(request_1); - - let public_inputs = builder.execute(); - - let end_requests = public_inputs.validation_requests.nullifier_non_existent_read_requests; - assert_array_eq(end_requests, [request_0, request_1]); - } - - #[test(should_fail_with="Public call cannot be reverted")] - fn fails_if_public_call_reverted() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - builder.public_call.revert_code = 1; - - builder.failed(); - } - - #[test] - fn updates_non_revertible_gas_used() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - - // Transaction gas limit is 1k - builder.previous_kernel.tx_context.gas_settings.gas_limits = Gas::new(1000, 1000); - - // Revertible has already used 100 - builder.previous_revertible.gas_used = Gas::new(100, 100); - - // And non-revertible has used another 200 - builder.previous_kernel.gas_used = Gas::new(200, 200); - - // So this call starts with 700 gas left - builder.public_call.start_gas_left = Gas::new(700, 700); - - // And uses 300, ending with 400 left - builder.public_call.end_gas_left = Gas::new(400, 400); - - // So the updated gas used by non-revertible must go up by 300, and revertible must stay the same - let output = builder.execute(); - assert_eq(output.end_non_revertible.gas_used, Gas::new(500, 500)); - assert_eq(output.end.gas_used, Gas::new(100, 100)); - } - - #[test(should_fail_with="Start gas for public phase does not match transaction gas left")] - fn validates_start_gas() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - - builder.public_call.is_execution_request = true; // don't need to check start gas for nested calls - builder.public_call.start_gas_left = Gas::new(100, 100); - - builder.failed(); - } - - #[test(should_fail_with="Transaction fee must be zero on setup and app phases")] - fn validates_transaction_fee() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - - builder.public_call.transaction_fee = 10; - - builder.failed(); - } - - #[test] - fn propagates_global_variables_if_empty() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - - builder.public_call.global_variables.block_number = 11; - - let public_inputs = builder.execute(); - - assert_eq(public_inputs.constants.global_variables.block_number, 11); - } - - #[test(should_fail_with="Global variables injected into the public call do not match constants")] - fn validates_global_variables() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - - builder.previous_kernel.global_variables.block_number = 10; - builder.public_call.global_variables.block_number = 11; - - builder.failed(); - } - - #[test] - unconstrained fn propagate_fee_payer() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - let fee_payer = AztecAddress::from_field(123); - builder.previous_kernel.set_fee_payer(fee_payer); - let public_inputs = builder.execute(); - assert_eq(public_inputs.fee_payer, fee_payer); - - // Check that the fee payer is not set if is_fee_payer is false - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - assert_eq(is_empty(builder.previous_kernel.fee_payer), true); - let public_inputs = builder.execute(); - assert_eq(public_inputs.fee_payer, AztecAddress::empty()); - } - - #[test] - fn propagate_call_stacks_on_success() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - - builder.previous_kernel.append_public_call_requests(1); - let prev_non_rev_calls = builder.previous_kernel.public_call_requests.storage; - - builder.previous_revertible.append_public_call_requests(2); - let prev_rev_calls = builder.previous_revertible.public_call_requests.storage; - - builder.previous_kernel.append_public_teardown_call_requests(1); - let prev_teardoen_calls = builder.previous_kernel.public_teardown_call_stack.storage; - - builder.public_call.append_public_call_requests(2); - let curr_calls = builder.public_call.public_call_requests.storage; - - let public_inputs = builder.execute(); - - assert_array_eq( - public_inputs.end_non_revertible.public_call_stack, - [prev_non_rev_calls[0], curr_calls[0], curr_calls[1]] - ); - assert_array_eq( - public_inputs.end.public_call_stack, - [prev_rev_calls[0], prev_rev_calls[1]] - ); - assert_array_eq( - public_inputs.public_teardown_call_stack, - [prev_teardoen_calls[0]] - ); - } - - #[test] - fn valid_previous_kernel() { - for i in 0..ALLOWED_PREVIOUS_CIRCUITS.len() { - let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - builder.previous_kernel = builder.previous_kernel.in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS[i]); - - let _res = builder.execute(); - } - } - // TODO(#7410) we need the tube vk to reinstate this - // #[test(should_fail_with="Invalid vk index")] - // fn invalid_previous_kernel() { - // let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - // builder.previous_kernel = builder.previous_kernel.in_vk_tree(BASE_ROLLUP_INDEX); - // let _res = builder.execute(); - // } -} diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr index 6dc88bee1c0d..b13d51729f68 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr @@ -108,7 +108,8 @@ mod tests { MAX_PUBLIC_DATA_HINTS, NOTE_HASH_SUBTREE_HEIGHT, NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH, NULLIFIER_TREE_HEIGHT, NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH, NULLIFIER_SUBTREE_HEIGHT, PUBLIC_DATA_SUBTREE_HEIGHT, PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH, PUBLIC_DATA_TREE_HEIGHT, - MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, NOTE_HASH_TREE_HEIGHT, PUBLIC_KERNEL_MERGE_INDEX + MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, NOTE_HASH_TREE_HEIGHT, PUBLIC_KERNEL_MERGE_INDEX, + BASE_ROLLUP_INDEX }, data::{PublicDataLeafHint, PublicDataTreeLeafPreimage}, hash::{compute_siloed_nullifier, silo_note_hash}, @@ -633,11 +634,11 @@ mod tests { let _res = builder.execute(); } - // TODO(#7410) we need the tube vk to reinstate this - // #[test(should_fail_with="Invalid vk index")] - // fn invalid_previous_kernel() { - // let mut builder = PublicKernelTailCircuitPrivateInputsBuilder::new(); - // builder.previous_kernel = builder.previous_kernel.in_vk_tree(BASE_ROLLUP_INDEX); - // let _res = builder.execute(); - // } + + #[test(should_fail_with="Invalid vk index")] + fn invalid_previous_kernel() { + let mut builder = PublicKernelTailCircuitPrivateInputsBuilder::new(); + builder.previous_kernel = builder.previous_kernel.in_vk_tree(BASE_ROLLUP_INDEX); + let _res = builder.execute(); + } } diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr deleted file mode 100644 index 23150b260906..000000000000 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr +++ /dev/null @@ -1,434 +0,0 @@ -use crate::{ - components::{ - previous_kernel_validator::PreviousKernelValidator, - public_call_data_validator::PublicCallDataValidator, - public_kernel_output_composer::PublicKernelOutputComposer -}, - public_kernel_phase::PublicKernelPhase -}; -use dep::types::{ - abis::{ - kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs, public_kernel_data::PublicKernelData, - public_call_data::PublicCallData -}, - constants::{ - PUBLIC_KERNEL_SETUP_INDEX, PUBLIC_KERNEL_APP_LOGIC_INDEX, PUBLIC_KERNEL_TEARDOWN_INDEX, - PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX -} -}; - -pub struct PublicKernelTeardownCircuitPrivateInputs { - previous_kernel: PublicKernelData, - public_call: PublicCallData, -} - -global ALLOWED_PREVIOUS_CIRCUITS = [ - PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX, - PUBLIC_KERNEL_SETUP_INDEX, - PUBLIC_KERNEL_APP_LOGIC_INDEX, - PUBLIC_KERNEL_TEARDOWN_INDEX, -]; - -impl PublicKernelTeardownCircuitPrivateInputs { - fn execute(self) -> PublicKernelCircuitPublicInputs { - let phase = PublicKernelPhase.TEARDOWN; - - let previous_kernel_validator = PreviousKernelValidator::new(self.previous_kernel); - previous_kernel_validator.validate_phase(phase); - previous_kernel_validator.validate_proof(ALLOWED_PREVIOUS_CIRCUITS); - - let call_data_validator = PublicCallDataValidator::new(self.public_call, phase); - call_data_validator.validate(); - call_data_validator.validate_against_previous_kernel(self.previous_kernel.public_inputs); - - // noir-fmt:ignore - PublicKernelOutputComposer::new_from_previous_kernel(self.previous_kernel.public_inputs) - .remove_top_call_request(phase) - .propagate_from_public_call(self.public_call.call_stack_item.public_inputs, phase) - .finish() - } -} - -mod tests { - use crate::{public_kernel_teardown::{ALLOWED_PREVIOUS_CIRCUITS, PublicKernelTeardownCircuitPrivateInputs}}; - use dep::types::{ - abis::{ - function_selector::FunctionSelector, gas::Gas, - kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs, - public_call_stack_item_compressed::PublicCallStackItemCompressed - }, - address::AztecAddress, constants::PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX, - tests::{fixture_builder::FixtureBuilder, utils::assert_array_eq}, traits::is_empty - }; - - struct PublicKernelTeardownCircuitPrivateInputsBuilder { - previous_kernel: FixtureBuilder, - public_call: FixtureBuilder, - } - - impl PublicKernelTeardownCircuitPrivateInputsBuilder { - pub fn new() -> Self { - let previous_kernel = FixtureBuilder::new().as_parent_contract().in_vk_tree(PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX); - let mut public_call = FixtureBuilder::new().is_public_function(); - public_call.value_offset = 9999; // Add an offset so that the mock data won't be the same as the values in previous_kernel. - - PublicKernelTeardownCircuitPrivateInputsBuilder { previous_kernel, public_call } - } - - pub fn is_delegate_call(&mut self) -> Self { - let _ = self.public_call.is_delegate_call(); - *self - } - - pub fn execute(&mut self) -> PublicKernelCircuitPublicInputs { - let public_call = self.public_call.to_public_call_data(); - // Adjust the call stack item hash for the current call in the previous iteration. - let compressed = public_call.call_stack_item.get_compressed(); - self.previous_kernel.push_public_teardown_call_request(compressed); - let mut previous_kernel = self.previous_kernel.to_public_kernel_data(true); - - let kernel = PublicKernelTeardownCircuitPrivateInputs { previous_kernel, public_call }; - - kernel.execute() - } - - pub fn get_call_request_item(self) -> PublicCallStackItemCompressed { - self.public_call.to_public_call_stack_item().get_compressed() - } - - pub fn failed_with_call_request_item(&mut self, item: PublicCallStackItemCompressed) { - let public_call = self.public_call.to_public_call_data(); - self.previous_kernel.push_public_teardown_call_request(item); - let previous_kernel = self.previous_kernel.to_public_kernel_data(true); - let kernel = PublicKernelTeardownCircuitPrivateInputs { previous_kernel, public_call }; - let _ = kernel.execute(); - } - - pub fn succeeded(&mut self) { - let _ = self.execute(); - } - - pub fn failed(&mut self) { - let _ = self.execute(); - } - } - - #[test(should_fail_with="Bytecode hash cannot be zero")] - fn no_bytecode_hash_should_fail() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - builder.public_call.bytecode_hash = 0; - - builder.failed(); - } - - #[test(should_fail_with="Contract address cannot be zero")] - fn contract_address_must_be_valid() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - - builder.previous_kernel.append_public_teardown_call_requests(1); - builder.public_call.contract_address = AztecAddress::zero(); - - builder.failed(); - } - - #[test(should_fail_with="Function signature cannot be zero")] - fn function_selector_must_be_valid() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - builder.public_call.function_data.selector = FunctionSelector::zero(); - - builder.failed(); - } - - #[test(should_fail_with="Cannot execute a private function with the public kernel circuit")] - fn private_call_should_fail() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - builder.public_call.function_data.is_private = true; - - builder.failed(); - } - - #[test(should_fail_with="call stack item does not match item at the top of the call stack")] - fn inconsistent_call_request_item_should_fail() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - - let mut item = builder.get_call_request_item(); - // Tweak the call stack item. - item.args_hash += 1; - - builder.failed_with_call_request_item(item); - } - - #[test(should_fail_with="call stack item does not match item at the top of the call stack")] - fn incorrect_msg_sender_fails_for_regular_calls() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - - let mut item = builder.get_call_request_item(); - // Set the msg_sender to a wrong value. - item.call_context.msg_sender.inner += 1; - - builder.failed_with_call_request_item(item); - } - - #[test(should_fail_with="call stack storage address does not match expected contract address")] - fn incorrect_storage_contract_address_fails_for_regular_calls() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - - // Set the storage contract address to a wrong value. - builder.public_call.storage_contract_address.inner += 1; - - builder.failed(); - } - - #[test] - fn delegate_call_succeeds() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new().is_delegate_call(); - builder.succeeded(); - } - - #[test(should_fail_with="call stack item does not match item at the top of the call stack")] - fn incorrect_msg_sender_for_delegate_calls_fails() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new().is_delegate_call(); - - let mut item = builder.get_call_request_item(); - // Set the msg_sender to be the caller contract. - item.call_context.msg_sender = builder.previous_kernel.contract_address; - - builder.failed_with_call_request_item(item); - } - - #[test(should_fail_with="call stack item does not match item at the top of the call stack")] - fn public_kernel_circuit_fails_on_incorrect_storage_contract_in_delegate_call() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new().is_delegate_call(); - - let mut item = builder.get_call_request_item(); - // Set the storage contract address to be the contract address. - item.call_context.storage_contract_address = builder.public_call.contract_address; - - builder.failed_with_call_request_item(item); - } - - #[test(should_fail_with="curent contract address must not match storage contract address for delegate calls")] - fn previous_private_kernel_fails_if_incorrect_storage_contract_on_delegate_call() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new().is_delegate_call(); - - builder.public_call.contract_address = builder.public_call.storage_contract_address; - - builder.failed(); - } - - #[test(should_fail_with="incorrect storage_contract_address for call request")] - fn incorrect_storage_contract_address_for_call_request_fails() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - - builder.public_call.append_public_call_requests(1); - let mut call_request = builder.public_call.public_call_requests.pop(); - // Change the caller contract address to be a different value. - call_request.item.call_context.storage_contract_address.inner += 1; - builder.public_call.public_call_requests.push(call_request); - - builder.failed(); - } - - #[test(should_fail_with="incorrect storage_contract_address for delegate call request")] - fn incorrect_call_context_for_delegate_call_request_fails() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - - builder.public_call.append_public_call_requests_delegate(1); - let mut call_request = builder.public_call.public_call_requests.pop(); - // Change the storage contract address to be the target contract address. - call_request.item.call_context.storage_contract_address = call_request.item.contract_address; - builder.public_call.public_call_requests.push(call_request); - - builder.failed(); - } - - #[test] - fn public_kernel_circuit_teardown_with_no_setup_and_no_app_logic_succeeds() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - builder.succeeded(); - } - - #[test(should_fail_with="Cannot run unnecessary teardown circuit")] - fn private_previous_kernel_non_empty_private_call_stack_should_fail() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - - let public_call = builder.public_call.to_public_call_data(); - // Don't push a call for teardown - let previous_kernel = builder.previous_kernel.to_public_kernel_data(true); - - let kernel = PublicKernelTeardownCircuitPrivateInputs { previous_kernel, public_call }; - - let _ = kernel.execute(); - } - - #[test(should_fail_with="No contract storage update requests are allowed for static calls")] - fn previous_private_kernel_fails_if_contract_storage_update_requests_on_static_call() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - builder.public_call.is_static_call = true; - builder.public_call.append_contract_storage_update_requests(1); - - builder.failed(); - } - - #[test] - fn logs_are_handled_as_expected() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - - // Logs for the current call stack. - builder.public_call.append_unencrypted_log_hashes(1); - let curr_data = builder.public_call.to_public_accumulated_data(); - - // Logs for the previous call stack. - builder.previous_kernel.append_encrypted_log_hashes(1); - builder.previous_kernel.append_unencrypted_log_hashes(1); - let prev_data = builder.previous_kernel.to_public_accumulated_data(); - - let expected_unencrypted_logs = [prev_data.unencrypted_logs_hashes[0], curr_data.unencrypted_logs_hashes[0]]; - // we assume the encrypted log is already siloed from private kernels - let expected_encrypted_logs = [prev_data.encrypted_logs_hashes[0]]; - - let public_inputs = builder.execute(); - - assert_array_eq( - public_inputs.end.encrypted_logs_hashes, - expected_encrypted_logs - ); - assert_array_eq( - public_inputs.end.unencrypted_logs_hashes, - expected_unencrypted_logs - ); - } - - #[test(should_fail_with="Start gas for teardown phase does not match teardown gas allocation")] - fn validates_start_gas() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - - builder.public_call.is_execution_request = true; // don't need to check start gas for nested calls - builder.public_call.start_gas_left = Gas::new(10, 30); - - builder.failed(); - } - - #[test(should_fail_with="Transaction fee on teardown phase does not match expected value")] - fn validates_transaction_fee() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - builder.public_call.transaction_fee = 1234; - - builder.failed(); - } - - #[test] - fn propagates_global_variables_if_empty() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - - builder.public_call.global_variables.block_number = 11; - - let public_inputs = builder.execute(); - - assert_eq(public_inputs.constants.global_variables.block_number, 11); - } - - #[test(should_fail_with="Global variables injected into the public call do not match constants")] - fn validates_global_variables() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - - builder.previous_kernel.global_variables.block_number = 10; - builder.public_call.global_variables.block_number = 11; - - builder.failed(); - } - - #[test] - unconstrained fn propagate_fee_payer() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - let fee_payer = AztecAddress::from_field(123); - builder.previous_kernel.set_fee_payer(fee_payer); - let public_inputs = builder.execute(); - assert_eq(public_inputs.fee_payer, fee_payer); - - // Check that the fee payer is not set if is_fee_payer is false - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - assert_eq(is_empty(builder.previous_kernel.fee_payer), true); - let public_inputs = builder.execute(); - assert_eq(public_inputs.fee_payer, AztecAddress::empty()); - } - - #[test] - fn clears_stack_if_current_call_revert_code_is_set() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - builder.public_call.revert_code = 1; - - builder.previous_kernel.append_public_teardown_call_requests(2); - - let public_inputs = builder.execute(); - - assert_array_eq(public_inputs.public_teardown_call_stack, []); - } - - #[test] - fn retains_stack_if_fail_in_app_logic() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - builder.previous_kernel.revert_code = 1; - - builder.previous_kernel.append_public_teardown_call_requests(2); - let teardown_calls = builder.previous_kernel.public_teardown_call_stack.storage; - - let public_inputs = builder.execute(); - - assert_array_eq( - public_inputs.public_teardown_call_stack, - [teardown_calls[0], teardown_calls[1]] - ); - } - - #[test] - unconstrained fn correctly_updates_revert_code_0() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - let public_inputs = builder.execute(); - assert_eq(public_inputs.revert_code, 0); - } - - #[test] - unconstrained fn correctly_updates_revert_code_1() { - // Case where we carry forward a revert code from app logic - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - builder.previous_kernel.revert_code = 1; - let public_inputs = builder.execute(); - assert_eq(public_inputs.revert_code, 1); - } - - #[test] - unconstrained fn correctly_updates_revert_code_2() { - // Case where there is a new error in teardown - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - builder.public_call.revert_code = 1; - let public_inputs = builder.execute(); - assert_eq(public_inputs.revert_code, 2); - } - - #[test] - unconstrained fn correctly_updates_revert_code_3() { - // Case where there is an error in both app logic and teardown - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - builder.previous_kernel.revert_code = 1; - builder.public_call.revert_code = 1; - let public_inputs = builder.execute(); - assert_eq(public_inputs.revert_code, 3); - } - - #[test] - fn valid_previous_kernel() { - for i in 0..ALLOWED_PREVIOUS_CIRCUITS.len() { - let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - builder.previous_kernel = builder.previous_kernel.in_vk_tree(ALLOWED_PREVIOUS_CIRCUITS[i]); - - let _res = builder.execute(); - } - } - // #[test(should_fail_with="Invalid vk index")] - // fn invalid_previous_kernel() { - // let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - // builder.previous_kernel = builder.previous_kernel.in_vk_tree(BASE_ROLLUP_INDEX); - // let _res = builder.execute(); - // } -} diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr index 19e2b3ec1dce..a11a39605c51 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr @@ -40,6 +40,7 @@ impl PreviousRollupBlockData { let index_hint = unsafe { find_index_hint(allowed_indices, |index: u32| index == leaf_index) }; + assert(index_hint < N, "Invalid vk index"); assert_eq(allowed_indices[index_hint], leaf_index, "Invalid vk index"); assert_check_membership( diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr index 1c35ba5c6408..13e4599fdb0b 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr @@ -40,6 +40,7 @@ impl PreviousRollupData { let index_hint = unsafe { find_index_hint(allowed_indices, |index: u32| index == leaf_index) }; + assert(index_hint < N, "Invalid vk index"); assert_eq(allowed_indices[index_hint], leaf_index, "Invalid vk index"); assert_check_membership( diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr index f4c953e3eca6..64e585c1ed68 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -481,7 +481,8 @@ mod tests { NULLIFIER_SUBTREE_HEIGHT, PUBLIC_DATA_TREE_HEIGHT, PUBLIC_DATA_SUBTREE_HEIGHT, PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH, MAX_L2_TO_L1_MSGS_PER_TX, PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, - PRIVATE_KERNEL_EMPTY_INDEX, PRIVATE_KERNEL_TAIL_INDEX, PUBLIC_KERNEL_TAIL_INDEX + PRIVATE_KERNEL_EMPTY_INDEX, PRIVATE_KERNEL_TAIL_INDEX, PUBLIC_KERNEL_TAIL_INDEX, + BASE_ROLLUP_INDEX, TUBE_INDEX }, partial_state_reference::PartialStateReference, data::{PublicDataTreeLeaf, PublicDataTreeLeafPreimage}, @@ -1444,9 +1445,9 @@ mod tests { } #[test] - fn valid_previous_kernel_tail() { + fn valid_previous_kernel_tube() { let builder = unsafe { - BaseRollupInputsBuilder::new_with_previous_kernel(PRIVATE_KERNEL_TAIL_INDEX) + BaseRollupInputsBuilder::new_with_previous_kernel(TUBE_INDEX) }; let _res = builder.execute(); @@ -1460,11 +1461,11 @@ mod tests { let _res = builder.execute(); } - // TODO(#7410) we need the tube vk to reinstate this - // #[test(should_fail_with="Invalid vk index")] - // fn invalid_previous_kernel() { - // let mut builder = BaseRollupInputsBuilder::new(); - // builder.kernel_data = builder.kernel_data.in_vk_tree(BASE_ROLLUP_INDEX); - // let _res = builder.execute(); - // } + + #[test(should_fail_with="Invalid vk index")] + fn invalid_previous_kernel() { + let mut builder = BaseRollupInputsBuilder::new(); + builder.kernel_data = builder.kernel_data.in_vk_tree(BASE_ROLLUP_INDEX); + let _res = builder.execute(); + } } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_merge/block_merge_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_merge/block_merge_rollup_inputs.nr index e856b50588e2..b9ee75b1f17e 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_merge/block_merge_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_merge/block_merge_rollup_inputs.nr @@ -68,7 +68,7 @@ impl BlockMergeRollupInputs { mod tests { use crate::{tests::block_merge_rollup_inputs::default_block_merge_rollup_inputs}; use dep::types::{hash::accumulate_sha256}; - use dep::types::constants::{BLOCK_ROOT_ROLLUP_INDEX, BLOCK_MERGE_ROLLUP_INDEX}; + use dep::types::constants::{BLOCK_ROOT_ROLLUP_INDEX, BLOCK_MERGE_ROLLUP_INDEX, ROOT_PARITY_INDEX}; #[test(should_fail_with="input blocks have different chain id")] fn constants_different_chain_id_fails() { @@ -161,14 +161,14 @@ mod tests { inputs.previous_rollup_data[0].vk_witness.sibling_path = vk_tree.get_sibling_path(BLOCK_MERGE_ROLLUP_INDEX); let _outputs = inputs.block_merge_rollup_circuit(); } - // TODO(#7410) we need the tube vk to reinstate this - // #[test(should_fail_with="Invalid vk index")] - // fn invalid_previous_circuit() { - // let mut inputs = default_block_merge_rollup_inputs(); - // let vk_tree = dep::types::tests::fixtures::vk_tree::get_vk_merkle_tree(); - // inputs.previous_rollup_data[0].vk.hash = vk_tree.leaves[ROOT_PARITY_INDEX]; - // inputs.previous_rollup_data[0].vk_witness.leaf_index = ROOT_PARITY_INDEX as Field; - // inputs.previous_rollup_data[0].vk_witness.sibling_path = vk_tree.get_sibling_path(ROOT_PARITY_INDEX); - // let _outputs = inputs.block_merge_rollup_circuit(); - // } + + #[test(should_fail_with="Invalid vk index")] + fn invalid_previous_circuit() { + let mut inputs = default_block_merge_rollup_inputs(); + let vk_tree = dep::types::tests::fixtures::vk_tree::get_vk_merkle_tree(); + inputs.previous_rollup_data[0].vk.hash = vk_tree.leaves[ROOT_PARITY_INDEX]; + inputs.previous_rollup_data[0].vk_witness.leaf_index = ROOT_PARITY_INDEX as Field; + inputs.previous_rollup_data[0].vk_witness.sibling_path = vk_tree.get_sibling_path(ROOT_PARITY_INDEX); + let _outputs = inputs.block_merge_rollup_circuit(); + } } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/merge/merge_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/merge/merge_rollup_inputs.nr index 098f5f448f00..b61343fc287a 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/merge/merge_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/merge/merge_rollup_inputs.nr @@ -64,7 +64,7 @@ impl MergeRollupInputs { mod tests { use crate::{tests::merge_rollup_inputs::default_merge_rollup_inputs}; use dep::types::hash::accumulate_sha256; - use dep::types::constants::{MERGE_ROLLUP_INDEX, BASE_ROLLUP_INDEX}; + use dep::types::constants::{MERGE_ROLLUP_INDEX, BASE_ROLLUP_INDEX, ROOT_PARITY_INDEX}; #[test(should_fail_with="The rollup should be filled greedily from L to R, but received a L base and R merge")] fn different_rollup_type_fails() { @@ -199,14 +199,14 @@ mod tests { let _outputs = inputs.merge_rollup_circuit(); } - // TODO(#7410) we need the tube vk to reinstate this - // #[test(should_fail_with="Invalid vk index")] - // fn invalid_previous_circuit() { - // let mut inputs = default_merge_rollup_inputs(); - // let vk_tree = dep::types::tests::fixtures::vk_tree::get_vk_merkle_tree(); - // inputs.previous_rollup_data[0].vk.hash = vk_tree.leaves[ROOT_PARITY_INDEX]; - // inputs.previous_rollup_data[0].vk_witness.leaf_index = ROOT_PARITY_INDEX as Field; - // inputs.previous_rollup_data[0].vk_witness.sibling_path = vk_tree.get_sibling_path(ROOT_PARITY_INDEX); - // let _outputs = inputs.merge_rollup_circuit(); - // } + + #[test(should_fail_with="Invalid vk index")] + fn invalid_previous_circuit() { + let mut inputs = default_merge_rollup_inputs(); + let vk_tree = dep::types::tests::fixtures::vk_tree::get_vk_merkle_tree(); + inputs.previous_rollup_data[0].vk.hash = vk_tree.leaves[ROOT_PARITY_INDEX]; + inputs.previous_rollup_data[0].vk_witness.leaf_index = ROOT_PARITY_INDEX as Field; + inputs.previous_rollup_data[0].vk_witness.sibling_path = vk_tree.get_sibling_path(ROOT_PARITY_INDEX); + let _outputs = inputs.merge_rollup_circuit(); + } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr index fec3be35ecf7..cf3149dbf3b2 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr @@ -25,6 +25,7 @@ impl KernelData { let index_hint = unsafe { find_index_hint(allowed_indices, |index: u32| index == self.vk_index) }; + assert(index_hint < N, "Invalid vk index"); assert_eq(allowed_indices[index_hint], self.vk_index, "Invalid vk index"); // TODO(#7410) Remove the exception for the tube index diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr index bac68405b728..ee1b86c7b5e8 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr @@ -23,6 +23,7 @@ impl PrivateKernelData { let index_hint = unsafe { find_index_hint(allowed_indices, |index: u32| index == index_in_allowed_list) }; + assert(index_hint < N, "Invalid vk index"); assert_eq(allowed_indices[index_hint], index_in_allowed_list, "Invalid vk index"); assert_check_membership( diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr index fb34aec4bfdb..46f9a8262936 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr @@ -25,6 +25,7 @@ impl PublicKernelData { let index_hint = unsafe { find_index_hint(allowed_indices, |index: u32| index == self.vk_index) }; + assert(index_hint < N, "Invalid vk index"); assert_eq(allowed_indices[index_hint], self.vk_index, "Invalid vk index"); // TODO(#7410) Remove the exception for the tube index diff --git a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts index 129780c8ee12..a299ea1bd6bf 100644 --- a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts +++ b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts @@ -14,7 +14,8 @@ function resolveRelativePath(relativePath: string) { } const main = async () => { - // TODO(#7410) tube VK should have been generated previously, this is just faking it + // TODO(#7410) tube VK should have been generated in noir-projects, but since we don't have a limited set of tubes + // we fake it here. const tubeVK = VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS); const tubeVKPath = resolveRelativePath('../../artifacts/keys/tube.vk.data.json'); await fs.writeFile( diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator.ts b/yarn-project/prover-client/src/orchestrator/orchestrator.ts index f869c286ec2e..710bba92dae7 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator.ts @@ -1286,7 +1286,7 @@ export class ProvingOrchestrator implements EpochProver { try { txProvingState.baseRollupInputs.kernelData.vkIndex = getVKIndex(verificationKey); } catch (_ignored) { - // TODO(#7410) The VK for the tube won't be in the tree, so we manually set it to the tube vk index + // TODO(#7410) The VK for the tube won't be in the tree for now, so we manually set it to the tube vk index txProvingState.baseRollupInputs.kernelData.vkIndex = TUBE_INDEX; } txProvingState.baseRollupInputs.kernelData.vkPath = getVKSiblingPath( From f0592de9756f1fb4057f0fce634149c88b0fb4b2 Mon Sep 17 00:00:00 2001 From: sirasistant <sirasistant@gmail.com> Date: Fri, 11 Oct 2024 14:31:06 +0000 Subject: [PATCH 06/10] fix: unit tests --- .../src/block_builder/light.test.ts | 50 +++++++++++++------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/yarn-project/sequencer-client/src/block_builder/light.test.ts b/yarn-project/sequencer-client/src/block_builder/light.test.ts index 4f7470d5ca4f..26f78656ce58 100644 --- a/yarn-project/sequencer-client/src/block_builder/light.test.ts +++ b/yarn-project/sequencer-client/src/block_builder/light.test.ts @@ -14,10 +14,9 @@ import { BlockRootRollupInputs, Fr, type GlobalVariables, - HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, L1_TO_L2_MSG_SUBTREE_HEIGHT, L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, - type MembershipWitness, + MembershipWitness, MergeRollupInputs, NESTED_RECURSIVE_PROOF_LENGTH, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, @@ -28,14 +27,22 @@ import { RootParityInput, RootParityInputs, VK_TREE_HEIGHT, - VerificationKeyData, + type VerificationKeyAsFields, + type VerificationKeyData, makeEmptyRecursiveProof, } from '@aztec/circuits.js'; import { makeGlobalVariables } from '@aztec/circuits.js/testing'; +import { makeTuple } from '@aztec/foundation/array'; import { padArrayEnd, times } from '@aztec/foundation/collection'; import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log'; import { type Tuple, assertLength } from '@aztec/foundation/serialize'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types'; +import { + ProtocolCircuitVks, + TubeVk, + getVKIndex, + getVKSiblingPath, + getVKTreeRoot, +} from '@aztec/noir-protocol-circuits-types'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { buildBaseRollupInput, @@ -67,16 +74,12 @@ describe('LightBlockBuilder', () => { let builder: LightweightBlockBuilder; let emptyProof: RecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>; - let emptyVk: VerificationKeyData; - let emptyVkWitness: MembershipWitness<typeof VK_TREE_HEIGHT>; beforeAll(async () => { logger = createDebugLogger('aztec:sequencer-client:test:block-builder'); simulator = new TestCircuitProver(new NoopTelemetryClient()); vkRoot = getVKTreeRoot(); emptyProof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH); - emptyVk = VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS); - emptyVkWitness = makeEmptyMembershipWitness(VK_TREE_HEIGHT); db = await NativeWorldStateService.tmp(); }); @@ -253,7 +256,7 @@ describe('LightBlockBuilder', () => { const getRollupOutputs = async (txs: ProcessedTx[]) => { const rollupOutputs = []; for (const tx of txs) { - const inputs = await buildBaseRollupInput(tx, emptyProof, globals, expectsFork, emptyVk); + const inputs = await buildBaseRollupInput(tx, emptyProof, globals, expectsFork, TubeVk); const result = await simulator.getBaseRollupProof(inputs); rollupOutputs.push(result.inputs); } @@ -261,8 +264,10 @@ describe('LightBlockBuilder', () => { }; const getMergeOutput = async (left: BaseOrMergeRollupPublicInputs, right: BaseOrMergeRollupPublicInputs) => { - const leftInput = new PreviousRollupData(left, emptyProof, emptyVk.keyAsFields, emptyVkWitness); - const rightInput = new PreviousRollupData(right, emptyProof, emptyVk.keyAsFields, emptyVkWitness); + const baseRollupVk = ProtocolCircuitVks['BaseRollupArtifact'].keyAsFields; + const baseRollupVkWitness = getVkMembershipWitness(baseRollupVk); + const leftInput = new PreviousRollupData(left, emptyProof, baseRollupVk, baseRollupVkWitness); + const rightInput = new PreviousRollupData(right, emptyProof, baseRollupVk, baseRollupVkWitness); const inputs = new MergeRollupInputs([leftInput, rightInput]); const result = await simulator.getMergeRollupProof(inputs); return result.inputs; @@ -273,10 +278,12 @@ describe('LightBlockBuilder', () => { await expectsFork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2Messages); const rootParityInputs: RootParityInput<typeof NESTED_RECURSIVE_PROOF_LENGTH>[] = []; + const baseParityVk = ProtocolCircuitVks['BaseParityArtifact'].keyAsFields; + const baseParityVkWitness = getVkMembershipWitness(baseParityVk); for (let i = 0; i < NUM_BASE_PARITY_PER_ROOT_PARITY; i++) { const input = BaseParityInputs.fromSlice(l1ToL2Messages, i, vkRoot); const { publicInputs } = await simulator.getBaseParityProof(input); - const rootInput = new RootParityInput(emptyProof, emptyVk.keyAsFields, emptyVkWitness.siblingPath, publicInputs); + const rootInput = new RootParityInput(emptyProof, baseParityVk, baseParityVkWitness.siblingPath, publicInputs); rootParityInputs.push(rootInput); } @@ -295,17 +302,23 @@ describe('LightBlockBuilder', () => { messageTreeSnapshot: AppendOnlyTreeSnapshot; }, ) => { - const rollupLeft = new PreviousRollupData(left, emptyProof, emptyVk.keyAsFields, emptyVkWitness); - const rollupRight = new PreviousRollupData(right, emptyProof, emptyVk.keyAsFields, emptyVkWitness); + const mergeRollupVk = ProtocolCircuitVks['MergeRollupArtifact'].keyAsFields; + const mergeRollupVkWitness = getVkMembershipWitness(mergeRollupVk); + + const rollupLeft = new PreviousRollupData(left, emptyProof, mergeRollupVk, mergeRollupVkWitness); + const rollupRight = new PreviousRollupData(right, emptyProof, mergeRollupVk, mergeRollupVkWitness); const startArchiveSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, expectsFork); const newArchiveSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.ARCHIVE, expectsFork); const previousBlockHashLeafIndex = BigInt(startArchiveSnapshot.nextAvailableLeafIndex - 1); const previousBlockHash = (await expectsFork.getLeafValue(MerkleTreeId.ARCHIVE, previousBlockHashLeafIndex))!; + const rootParityVk = ProtocolCircuitVks['RootParityArtifact'].keyAsFields; + const rootParityVkWitness = getVkMembershipWitness(rootParityVk); + const rootParityInput = new RootParityInput( emptyProof, - emptyVk.keyAsFields, - emptyVkWitness.siblingPath, + rootParityVk, + rootParityVkWitness.siblingPath, parityOutput, ); @@ -324,4 +337,9 @@ describe('LightBlockBuilder', () => { const result = await simulator.getBlockRootRollupProof(inputs); return result.inputs; }; + + function getVkMembershipWitness(vk: VerificationKeyAsFields) { + const leafIndex = getVKIndex(vk); + return new MembershipWitness(VK_TREE_HEIGHT, BigInt(leafIndex), getVKSiblingPath(leafIndex)); + } }); From 197c83eb807fb5c7450a0a7a6512bb5d8aa52309 Mon Sep 17 00:00:00 2001 From: sirasistant <sirasistant@gmail.com> Date: Fri, 11 Oct 2024 14:58:47 +0000 Subject: [PATCH 07/10] fix root rollup --- .../crates/rollup-lib/src/root/root_rollup_inputs.nr | 6 +++++- .../sequencer-client/src/block_builder/light.test.ts | 3 --- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_inputs.nr index 43972f54394a..ff01e0012c7b 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_inputs.nr @@ -2,11 +2,15 @@ use crate::{ abis::previous_rollup_block_data::PreviousRollupBlockData, components, root::root_rollup_public_inputs::RootRollupPublicInputs }; -use types::{traits::Empty, constants::{BLOCK_ROOT_ROLLUP_INDEX, BLOCK_MERGE_ROLLUP_INDEX}}; +use types::{ + traits::Empty, + constants::{BLOCK_ROOT_ROLLUP_INDEX, BLOCK_MERGE_ROLLUP_INDEX, BLOCK_ROOT_ROLLUP_EMPTY_INDEX} +}; // TODO(#7346): Currently unused! Will be used when batch rollup circuits are integrated. global ALLOWED_PREVIOUS_CIRCUITS = [ BLOCK_ROOT_ROLLUP_INDEX, BLOCK_MERGE_ROLLUP_INDEX, + BLOCK_ROOT_ROLLUP_EMPTY_INDEX ]; pub struct RootRollupInputs { diff --git a/yarn-project/sequencer-client/src/block_builder/light.test.ts b/yarn-project/sequencer-client/src/block_builder/light.test.ts index 26f78656ce58..25372470b9cb 100644 --- a/yarn-project/sequencer-client/src/block_builder/light.test.ts +++ b/yarn-project/sequencer-client/src/block_builder/light.test.ts @@ -28,11 +28,9 @@ import { RootParityInputs, VK_TREE_HEIGHT, type VerificationKeyAsFields, - type VerificationKeyData, makeEmptyRecursiveProof, } from '@aztec/circuits.js'; import { makeGlobalVariables } from '@aztec/circuits.js/testing'; -import { makeTuple } from '@aztec/foundation/array'; import { padArrayEnd, times } from '@aztec/foundation/collection'; import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log'; import { type Tuple, assertLength } from '@aztec/foundation/serialize'; @@ -50,7 +48,6 @@ import { getRootTreeSiblingPath, getSubtreeSiblingPath, getTreeSnapshot, - makeEmptyMembershipWitness, } from '@aztec/prover-client/helpers'; import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { type MerkleTreeAdminDatabase, NativeWorldStateService } from '@aztec/world-state'; From 67845a2aad8dacc4c17810b1d9dca426e516086c Mon Sep 17 00:00:00 2001 From: sirasistant <sirasistant@gmail.com> Date: Fri, 11 Oct 2024 15:14:53 +0000 Subject: [PATCH 08/10] remove console.log --- yarn-project/end-to-end/src/e2e_card_game.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_card_game.test.ts b/yarn-project/end-to-end/src/e2e_card_game.test.ts index 80ac5d8af742..d845ec81ff0d 100644 --- a/yarn-project/end-to-end/src/e2e_card_game.test.ts +++ b/yarn-project/end-to-end/src/e2e_card_game.test.ts @@ -151,9 +151,7 @@ describe('e2e_card_game', () => { it('should be able to buy packs', async () => { const seed = 27n; // docs:start:send_tx - console.log('Buying pack...'); await contract.methods.buy_pack(seed).send().wait(); - console.log('Pack bought'); // docs:end:send_tx const collection = await contract.methods.view_collection_cards(firstPlayer, 0).simulate({ from: firstPlayer }); const expected = getPackedCards(0, seed); From 0d4d007a455c688b15b0344ecb05099b1ccb7cc9 Mon Sep 17 00:00:00 2001 From: sirasistant <sirasistant@gmail.com> Date: Fri, 11 Oct 2024 15:18:48 +0000 Subject: [PATCH 09/10] refactor --- yarn-project/simulator/src/public/enqueued_calls_processor.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/yarn-project/simulator/src/public/enqueued_calls_processor.ts b/yarn-project/simulator/src/public/enqueued_calls_processor.ts index 4977546962c9..f4741d0eb8e6 100644 --- a/yarn-project/simulator/src/public/enqueued_calls_processor.ts +++ b/yarn-project/simulator/src/public/enqueued_calls_processor.ts @@ -22,7 +22,6 @@ import { PublicKernelCircuitPrivateInputs, type PublicKernelCircuitPublicInputs, PublicKernelData, - TUBE_INDEX, type VMCircuitPublicInputs, makeEmptyProof, makeEmptyRecursiveProof, @@ -379,7 +378,7 @@ export class EnqueuedCallsProcessor { const proof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH); const vk = isFromPrivate ? TubeVk : ProtocolCircuitVks.PublicKernelMergeArtifact; - const vkIndex = isFromPrivate ? TUBE_INDEX : getVKIndex(vk); + const vkIndex = getVKIndex(vk); const siblingPath = getVKSiblingPath(vkIndex); return new PublicKernelData(previousOutput, proof, vk, vkIndex, siblingPath); From a98c14e34e617f1fbf1d3a284c5bc208ecb82cbc Mon Sep 17 00:00:00 2001 From: sirasistant <sirasistant@gmail.com> Date: Fri, 11 Oct 2024 15:29:31 +0000 Subject: [PATCH 10/10] refactor --- .../bb-prover/src/test/test_circuit_prover.ts | 5 ++-- .../src/structs/kernel/kernel_data.ts | 4 +-- .../src/structs/kernel/public_kernel_data.ts | 8 ++---- .../kernel/public_kernel_inner_data.ts | 4 +-- .../src/structs/verification_key.test.ts | 5 ++-- .../src/structs/verification_key.ts | 13 +++++----- .../circuits.js/src/tests/factories.ts | 11 ++++---- .../src/scripts/generate_vk_hashes.ts | 4 +-- .../src/orchestrator/orchestrator.ts | 3 +-- .../prover-agent/memory-proving-queue.test.ts | 5 ++-- .../src/prover-agent/prover-agent.test.ts | 5 ++-- .../src/test/bb_prover_parity.test.ts | 3 +-- .../prover-client/src/test/mock_prover.ts | 25 +++++++++---------- 13 files changed, 42 insertions(+), 53 deletions(-) diff --git a/yarn-project/bb-prover/src/test/test_circuit_prover.ts b/yarn-project/bb-prover/src/test/test_circuit_prover.ts index d7a619849a73..0fd121ca6f99 100644 --- a/yarn-project/bb-prover/src/test/test_circuit_prover.ts +++ b/yarn-project/bb-prover/src/test/test_circuit_prover.ts @@ -15,7 +15,6 @@ import { type BlockRootRollupInputs, type EmptyBlockRootRollupInputs, EmptyNestedData, - HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, type KernelCircuitPublicInputs, type MergeRollupInputs, NESTED_RECURSIVE_PROOF_LENGTH, @@ -156,7 +155,7 @@ export class TestCircuitProver implements ServerCircuitProver { return makePublicInputsAndRecursiveProof( result, makeRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), ); } @@ -277,7 +276,7 @@ export class TestCircuitProver implements ServerCircuitProver { ): Promise<{ tubeVK: VerificationKeyData; tubeProof: RecursiveProof<typeof TUBE_PROOF_LENGTH> }> { await this.delay(); return { - tubeVK: VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + tubeVK: VerificationKeyData.makeFakeHonk(), tubeProof: makeEmptyRecursiveProof(TUBE_PROOF_LENGTH), }; } diff --git a/yarn-project/circuits.js/src/structs/kernel/kernel_data.ts b/yarn-project/circuits.js/src/structs/kernel/kernel_data.ts index b914f37e7e8d..234b949acf7c 100644 --- a/yarn-project/circuits.js/src/structs/kernel/kernel_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/kernel_data.ts @@ -2,7 +2,7 @@ import { makeTuple } from '@aztec/foundation/array'; import { Fr } from '@aztec/foundation/fields'; import { BufferReader, type Tuple, serializeToBuffer } from '@aztec/foundation/serialize'; -import { HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, RECURSIVE_PROOF_LENGTH, VK_TREE_HEIGHT } from '../../constants.gen.js'; +import { RECURSIVE_PROOF_LENGTH, VK_TREE_HEIGHT } from '../../constants.gen.js'; import { RecursiveProof, makeEmptyRecursiveProof } from '../recursive_proof.js'; import { type UInt32 } from '../shared.js'; import { VerificationKeyData } from '../verification_key.js'; @@ -37,7 +37,7 @@ export class KernelData { return new this( KernelCircuitPublicInputs.empty(), makeEmptyRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), 0, makeTuple(VK_TREE_HEIGHT, Fr.zero), ); diff --git a/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts b/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts index 55acb8a7c7fd..f771cc2207cf 100644 --- a/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts @@ -2,11 +2,7 @@ import { makeTuple } from '@aztec/foundation/array'; import { Fr } from '@aztec/foundation/fields'; import { BufferReader, type Tuple, serializeToBuffer } from '@aztec/foundation/serialize'; -import { - HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, - NESTED_RECURSIVE_PROOF_LENGTH, - VK_TREE_HEIGHT, -} from '../../constants.gen.js'; +import { NESTED_RECURSIVE_PROOF_LENGTH, VK_TREE_HEIGHT } from '../../constants.gen.js'; import { ClientIvcProof } from '../client_ivc_proof.js'; import { RecursiveProof, makeEmptyRecursiveProof } from '../recursive_proof.js'; import { type UInt32 } from '../shared.js'; @@ -61,7 +57,7 @@ export class PublicKernelData { return new this( PublicKernelCircuitPublicInputs.empty(), makeEmptyRecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>(NESTED_RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), 0, makeTuple(VK_TREE_HEIGHT, Fr.zero), ClientIvcProof.empty(), diff --git a/yarn-project/circuits.js/src/structs/kernel/public_kernel_inner_data.ts b/yarn-project/circuits.js/src/structs/kernel/public_kernel_inner_data.ts index 754516841016..5108818ae346 100644 --- a/yarn-project/circuits.js/src/structs/kernel/public_kernel_inner_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/public_kernel_inner_data.ts @@ -1,6 +1,6 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; -import { HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, NESTED_RECURSIVE_PROOF_LENGTH } from '../../constants.gen.js'; +import { NESTED_RECURSIVE_PROOF_LENGTH } from '../../constants.gen.js'; import { RecursiveProof, makeEmptyRecursiveProof } from '../recursive_proof.js'; import { VerificationKeyData } from '../verification_key.js'; import { VMCircuitPublicInputs } from './vm_circuit_public_inputs.js'; @@ -37,7 +37,7 @@ export class PublicKernelInnerData { return new this( VMCircuitPublicInputs.empty(), makeEmptyRecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>(NESTED_RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), ); } diff --git a/yarn-project/circuits.js/src/structs/verification_key.test.ts b/yarn-project/circuits.js/src/structs/verification_key.test.ts index 6b73b08e7773..281ca48e0523 100644 --- a/yarn-project/circuits.js/src/structs/verification_key.test.ts +++ b/yarn-project/circuits.js/src/structs/verification_key.test.ts @@ -1,9 +1,8 @@ -import { HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS } from '../constants.gen.js'; import { VerificationKey, VerificationKeyAsFields, VerificationKeyData } from './verification_key.js'; describe('structs/verification_key_as_fields', () => { it(`can serialise and deserialise a verification key as fields`, () => { - const vk = VerificationKeyAsFields.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS); + const vk = VerificationKeyAsFields.makeFakeHonk(); const serialised = vk.toBuffer(); const deserialised = VerificationKeyAsFields.fromBuffer(serialised); expect(vk).toEqual(deserialised); @@ -21,7 +20,7 @@ describe('structs/verification_key', () => { describe('structs/verification_key_data', () => { it(`can serialise and deserialise a verification key data`, () => { - const vk = VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS); + const vk = VerificationKeyData.makeFakeHonk(); const serialised = vk.toBuffer(); const deserialised = VerificationKeyData.fromBuffer(serialised); expect(vk).toEqual(deserialised); diff --git a/yarn-project/circuits.js/src/structs/verification_key.ts b/yarn-project/circuits.js/src/structs/verification_key.ts index a85d02716672..178048183e96 100644 --- a/yarn-project/circuits.js/src/structs/verification_key.ts +++ b/yarn-project/circuits.js/src/structs/verification_key.ts @@ -5,7 +5,7 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { strict as assert } from 'assert'; -import { AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS } from '../constants.gen.js'; +import { AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS, HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS } from '../constants.gen.js'; import { CircuitType } from './shared.js'; /** @@ -128,6 +128,10 @@ export class VerificationKeyAsFields { return new VerificationKeyAsFields(makeTuple(size, Fr.random, seed), Fr.random()); } + static makeFakeHonk(seed = 1): VerificationKeyAsFields { + return new VerificationKeyAsFields(makeTuple(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, Fr.random, seed), Fr.random()); + } + /** * Builds an 'empty' verification key * @returns An 'empty' verification key @@ -292,11 +296,8 @@ export class VerificationKeyData { return this.keyAsFields.isRecursive; } - static makeFake(sizeInFields: number): VerificationKeyData { - return new VerificationKeyData( - VerificationKeyAsFields.makeFake(sizeInFields), - VerificationKey.makeFake().toBuffer(), - ); + static makeFakeHonk(): VerificationKeyData { + return new VerificationKeyData(VerificationKeyAsFields.makeFakeHonk(), VerificationKey.makeFake().toBuffer()); } /** diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 96763dd1704e..c2e10912de6d 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -36,7 +36,6 @@ import { FunctionData, FunctionSelector, GrumpkinScalar, - HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, KeyValidationRequest, KeyValidationRequestAndGenerator, L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, @@ -641,7 +640,7 @@ export function makePublicKernelData(seed = 1, kernelPublicInputs?: PublicKernel return new PublicKernelData( kernelPublicInputs ?? makePublicKernelCircuitPublicInputs(seed, true), makeRecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>(NESTED_RECURSIVE_PROOF_LENGTH, seed + 0x80), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), 0x42, makeTuple(VK_TREE_HEIGHT, fr, 0x1000), ); @@ -657,7 +656,7 @@ export function makeRollupKernelData(seed = 1, kernelPublicInputs?: KernelCircui return new KernelData( kernelPublicInputs ?? makeKernelCircuitPublicInputs(seed, true), makeRecursiveProof<typeof TUBE_PROOF_LENGTH>(TUBE_PROOF_LENGTH, seed + 0x80), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), 0x42, makeTuple(VK_TREE_HEIGHT, fr, 0x1000), ); @@ -736,7 +735,7 @@ function makePublicKernelInnerData(seed = 1) { return new PublicKernelInnerData( makeVMCircuitPublicInputs(seed), makeRecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>(NESTED_RECURSIVE_PROOF_LENGTH, seed + 0x100), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), ); } @@ -995,7 +994,7 @@ export function makePreviousRollupData( return new PreviousRollupData( makeBaseOrMergeRollupPublicInputs(seed, globalVariables), makeRecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>(NESTED_RECURSIVE_PROOF_LENGTH, seed + 0x50), - VerificationKeyAsFields.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyAsFields.makeFakeHonk(), makeMembershipWitness(VK_TREE_HEIGHT, seed + 0x120), ); } @@ -1013,7 +1012,7 @@ export function makePreviousRollupBlockData( return new PreviousRollupBlockData( makeBlockRootOrBlockMergeRollupPublicInputs(seed, globalVariables), makeRecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>(NESTED_RECURSIVE_PROOF_LENGTH, seed + 0x50), - VerificationKeyAsFields.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyAsFields.makeFakeHonk(), makeMembershipWitness(VK_TREE_HEIGHT, seed + 0x120), ); } diff --git a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts index a299ea1bd6bf..d8bc6e0ac969 100644 --- a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts +++ b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts @@ -1,4 +1,4 @@ -import { Fr, HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, VerificationKeyData } from '@aztec/circuits.js'; +import { Fr, VerificationKeyData } from '@aztec/circuits.js'; import { createConsoleLogger } from '@aztec/foundation/log'; import { fileURLToPath } from '@aztec/foundation/url'; @@ -16,7 +16,7 @@ function resolveRelativePath(relativePath: string) { const main = async () => { // TODO(#7410) tube VK should have been generated in noir-projects, but since we don't have a limited set of tubes // we fake it here. - const tubeVK = VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS); + const tubeVK = VerificationKeyData.makeFakeHonk(); const tubeVKPath = resolveRelativePath('../../artifacts/keys/tube.vk.data.json'); await fs.writeFile( tubeVKPath, diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator.ts b/yarn-project/prover-client/src/orchestrator/orchestrator.ts index 212c201e5cbb..53eadebef486 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator.ts @@ -28,7 +28,6 @@ import { EmptyBlockRootRollupInputs, Fr, type GlobalVariables, - HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, type Header, type KernelCircuitPublicInputs, L1_TO_L2_MSG_SUBTREE_HEIGHT, @@ -1235,7 +1234,7 @@ export class ProvingOrchestrator implements EpochProver { ); return { proof: makeEmptyProof(), - verificationKey: VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + verificationKey: VerificationKeyData.makeFakeHonk(), }; } } diff --git a/yarn-project/prover-client/src/prover-agent/memory-proving-queue.test.ts b/yarn-project/prover-client/src/prover-agent/memory-proving-queue.test.ts index 6107f89c2270..f552880a31ed 100644 --- a/yarn-project/prover-client/src/prover-agent/memory-proving-queue.test.ts +++ b/yarn-project/prover-client/src/prover-agent/memory-proving-queue.test.ts @@ -1,7 +1,6 @@ import { ProvingRequestType } from '@aztec/circuit-types'; import { Fr, - HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, RECURSIVE_PROOF_LENGTH, RootParityInput, VK_TREE_HEIGHT, @@ -87,7 +86,7 @@ describe('MemoryProvingQueue', () => { const publicInputs = makeParityPublicInputs(); const proof = makeRecursiveProof<typeof RECURSIVE_PROOF_LENGTH>(RECURSIVE_PROOF_LENGTH); - const vk = VerificationKeyAsFields.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS); + const vk = VerificationKeyAsFields.makeFakeHonk(); const vkPath = makeTuple(VK_TREE_HEIGHT, Fr.zero); await queue.resolveProvingJob(job!.id, new RootParityInput(proof, vk, vkPath, publicInputs)); await expect(promise).resolves.toEqual(new RootParityInput(proof, vk, vkPath, publicInputs)); @@ -145,7 +144,7 @@ describe('MemoryProvingQueue', () => { const output = new RootParityInput( makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyAsFields.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyAsFields.makeFakeHonk(), makeTuple(VK_TREE_HEIGHT, Fr.zero), makeParityPublicInputs(), ); diff --git a/yarn-project/prover-client/src/prover-agent/prover-agent.test.ts b/yarn-project/prover-client/src/prover-agent/prover-agent.test.ts index 8bcac1c5a6f5..1582ca6e2ad3 100644 --- a/yarn-project/prover-client/src/prover-agent/prover-agent.test.ts +++ b/yarn-project/prover-client/src/prover-agent/prover-agent.test.ts @@ -1,7 +1,6 @@ import { type ServerCircuitProver } from '@aztec/circuit-types'; import { Fr, - HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, RECURSIVE_PROOF_LENGTH, RootParityInput, VK_TREE_HEIGHT, @@ -41,7 +40,7 @@ describe('ProverAgent', () => { it('takes jobs from the queue', async () => { const publicInputs = makeParityPublicInputs(); const proof = makeRecursiveProof<typeof RECURSIVE_PROOF_LENGTH>(RECURSIVE_PROOF_LENGTH); - const vk = VerificationKeyAsFields.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS); + const vk = VerificationKeyAsFields.makeFakeHonk(); prover.getBaseParityProof.mockResolvedValue( new RootParityInput<typeof RECURSIVE_PROOF_LENGTH>(proof, vk, makeTuple(VK_TREE_HEIGHT, Fr.zero), publicInputs), ); @@ -70,7 +69,7 @@ describe('ProverAgent', () => { it('continues to process jobs', async () => { const publicInputs = makeParityPublicInputs(); const proof = makeRecursiveProof<typeof RECURSIVE_PROOF_LENGTH>(RECURSIVE_PROOF_LENGTH); - const vk = VerificationKeyAsFields.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS); + const vk = VerificationKeyAsFields.makeFakeHonk(); prover.getBaseParityProof.mockResolvedValue( new RootParityInput<typeof RECURSIVE_PROOF_LENGTH>(proof, vk, makeTuple(VK_TREE_HEIGHT, Fr.zero), publicInputs), ); diff --git a/yarn-project/prover-client/src/test/bb_prover_parity.test.ts b/yarn-project/prover-client/src/test/bb_prover_parity.test.ts index ad7f5e943878..4c0026ca986e 100644 --- a/yarn-project/prover-client/src/test/bb_prover_parity.test.ts +++ b/yarn-project/prover-client/src/test/bb_prover_parity.test.ts @@ -2,7 +2,6 @@ import { BBNativeRollupProver, type BBProverConfig } from '@aztec/bb-prover'; import { BaseParityInputs, Fr, - HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, NUM_BASE_PARITY_PER_ROOT_PARITY, ParityPublicInputs, @@ -98,7 +97,7 @@ describe('prover/bb_prover/parity', () => { const defectiveVerificationKey = new RootParityInput( validProof, - VerificationKeyAsFields.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyAsFields.makeFakeHonk(), baseParityVkPath, validPublicInputs, ); diff --git a/yarn-project/prover-client/src/test/mock_prover.ts b/yarn-project/prover-client/src/test/mock_prover.ts index d0d0486b01c3..5fa366edc26f 100644 --- a/yarn-project/prover-client/src/test/mock_prover.ts +++ b/yarn-project/prover-client/src/test/mock_prover.ts @@ -8,7 +8,6 @@ import { AvmVerificationKeyData, type BaseOrMergeRollupPublicInputs, type BlockRootOrBlockMergePublicInputs, - HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, type KernelCircuitPublicInputs, type PublicKernelCircuitPublicInputs, RECURSIVE_PROOF_LENGTH, @@ -54,7 +53,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeBaseOrMergeRollupPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), ), ); } @@ -64,7 +63,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeBaseOrMergeRollupPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), ), ); } @@ -74,7 +73,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeBlockRootOrBlockMergeRollupPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), ), ); } @@ -84,7 +83,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeBlockRootOrBlockMergeRollupPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), ), ); } @@ -94,7 +93,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeBlockRootOrBlockMergeRollupPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), ), ); } @@ -104,7 +103,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeKernelCircuitPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), ), ); } @@ -114,7 +113,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeKernelCircuitPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), ), ); } @@ -124,7 +123,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeVMCircuitPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), ), ); } @@ -134,7 +133,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makePublicKernelCircuitPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), ), ); } @@ -144,7 +143,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeKernelCircuitPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), ), ); } @@ -154,7 +153,7 @@ export class MockProver implements ServerCircuitProver { makePublicInputsAndRecursiveProof( makeRootRollupPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), - VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + VerificationKeyData.makeFakeHonk(), ), ); } @@ -164,7 +163,7 @@ export class MockProver implements ServerCircuitProver { tubeProof: RecursiveProof<typeof RECURSIVE_PROOF_LENGTH>; }> { return Promise.resolve({ - tubeVK: VerificationKeyData.makeFake(HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS), + tubeVK: VerificationKeyData.makeFakeHonk(), tubeProof: makeRecursiveProof(RECURSIVE_PROOF_LENGTH), }); }