diff --git a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/common.nr b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/common.nr index 44f36ddbee94..ee040f22f9e5 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/common.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/common.nr @@ -360,7 +360,7 @@ pub fn contract_logic( private_call.contract_leaf_membership_witness.sibling_path ); - let purported_contract_tree_root = private_call.call_stack_item.public_inputs.block_header.contract_tree_root(); + let purported_contract_tree_root = private_call.call_stack_item.public_inputs.block_header.state.partial.contract_tree.root; assert_eq( computed_contract_tree_root, purported_contract_tree_root, "computed_contract_tree_root does not match purported_contract_tree_root" ); diff --git a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_init.nr b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_init.nr index 5b215d829718..0fdc32b1b94e 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_init.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_init.nr @@ -91,7 +91,7 @@ impl PrivateKernelInputsInit { self.validate_this_private_call_against_tx_request(); common::validate_read_requests( - public_inputs.constants.block_header.note_hash_tree_root(), + public_inputs.constants.block_header.state.partial.note_hash_tree.root, self.private_call.call_stack_item.public_inputs.read_requests, self.private_call.read_request_membership_witnesses ); diff --git a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr index 98cbe5ff2ae1..39d3c7df13a7 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr @@ -22,8 +22,8 @@ impl PrivateKernelInputsInner { } fn validate_contract_tree_root(self) { - let purported_contract_tree_root = self.private_call.call_stack_item.public_inputs.block_header.contract_tree_root(); - let previous_kernel_contract_tree_root = self.previous_kernel.public_inputs.constants.block_header.contract_tree_root(); + let purported_contract_tree_root = self.private_call.call_stack_item.public_inputs.block_header.state.partial.contract_tree.root; + let previous_kernel_contract_tree_root = self.previous_kernel.public_inputs.constants.block_header.state.partial.contract_tree.root; assert(purported_contract_tree_root == previous_kernel_contract_tree_root, "purported_contract_tree_root does not match previous_kernel_contract_tree_root"); } @@ -52,7 +52,7 @@ impl PrivateKernelInputsInner { self.pop_and_validate_this_private_call_hash(&mut public_inputs); common::validate_read_requests( - public_inputs.constants.block_header.note_hash_tree_root(), + public_inputs.constants.block_header.state.partial.note_hash_tree.root, self.private_call.call_stack_item.public_inputs.read_requests, // read requests from private call self.private_call.read_request_membership_witnesses); @@ -171,8 +171,8 @@ mod tests { let mut builder = PrivateKernelInnerInputsBuilder::new(); // Set historical_tree_root to a wrong value (the correct value + 1). - let contract_tree_root = builder.previous_kernel.block_header.contract_tree_root; - builder.previous_kernel.block_header.contract_tree_root = contract_tree_root + 1; + let contract_tree_root = builder.previous_kernel.block_header.state.partial.contract_tree.root; + builder.previous_kernel.block_header.state.partial.contract_tree.root = contract_tree_root + 1; builder.failed(); } @@ -610,8 +610,8 @@ mod tests { builder.private_call.append_read_requests(1); // Set the root to be a different root so the above read request is not under this root. - let old_root = builder.previous_kernel.block_header.note_hash_tree_root; - builder.previous_kernel.block_header.note_hash_tree_root = old_root + 1; + let old_root = builder.previous_kernel.block_header.state.partial.note_hash_tree.root; + builder.previous_kernel.block_header.state.partial.note_hash_tree.root = old_root + 1; builder.failed(); } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/append_only_tree_snapshot.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/append_only_tree_snapshot.nr index 9b1ca92f4322..e0f2485a92a7 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/append_only_tree_snapshot.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/append_only_tree_snapshot.nr @@ -1,4 +1,5 @@ use dep::std::cmp::Eq; +use crate::traits::Empty; struct AppendOnlyTreeSnapshot { root : Field, @@ -25,3 +26,12 @@ impl Eq for AppendOnlyTreeSnapshot { (self.root == other.root) & (self.next_available_leaf_index == other.next_available_leaf_index) } } + +impl Empty for AppendOnlyTreeSnapshot { + fn empty() -> Self { + Self { + root: 0, + next_available_leaf_index: 0 + } + } +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr index 85b208776d36..f4be50a14ac2 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr @@ -1,13 +1,13 @@ use crate::{ abis::{ call_context::CallContext, - block_header::BlockHeader, side_effect::{SideEffect, SideEffectLinkedToNoteHash}, }, contrakt::deployment_data::ContractDeploymentData, hash::{ pedersen_hash, }, + header::Header, utils::bounded_vec::BoundedVec, }; use crate::constants::{ @@ -48,7 +48,7 @@ struct PrivateCircuitPublicInputs { encrypted_log_preimages_length: Field, unencrypted_log_preimages_length: Field, - block_header: BlockHeader, + block_header: Header, contract_deployment_data: ContractDeploymentData, diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/constants.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/constants.nr index 549763a070c6..219fcf9769ca 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/constants.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/constants.nr @@ -102,7 +102,8 @@ global CONTRACT_DEPLOYMENT_DATA_LENGTH: Field = 6; // Change this ONLY if you have changed the PrivateCircuitPublicInputs structure. // In other words, if the structure/size of the public inputs of a function call changes then we // should change this constant as well as the offsets in private_call_stack_item.nr -global PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH: Field = 189; +// TODO(benesjan): Didn't find any offsets in call_stack_item.nr is this ^ still relevant +global PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH: Field = 200; global CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH: Field = 3; global CONTRACT_STORAGE_READ_LENGTH: Field = 2; // Change this ONLY if you have changed the PublicCircuitPublicInputs structure. diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures.nr index 39f729e70329..7c5f916c66f4 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures.nr @@ -4,21 +4,46 @@ mod contracts; mod note_hash_tree; mod read_requests; -use crate::address::AztecAddress; -use crate::abis::block_header::BlockHeader; -use crate::grumpkin_point::GrumpkinPoint; -use crate::tests::fixtures; +use crate::{ + abis::{ + append_only_tree_snapshot::AppendOnlyTreeSnapshot, + global_variables::GlobalVariables, + }, + address::AztecAddress, + constants::NUM_FIELDS_PER_SHA256, + grumpkin_point::GrumpkinPoint, + header::Header, + partial_state_reference::PartialStateReference, + state_reference::StateReference, + tests::fixtures +}; global MSG_SENDER = AztecAddress { inner: 27 }; global DEPLOYER_PUBLIC_KEY = GrumpkinPoint { x: 123456789, y: 123456789 }; -global BLOCK_HEADER = BlockHeader { - note_hash_tree_root: fixtures::note_hash_tree::ROOT, - nullifier_tree_root: 0, - contract_tree_root: fixtures::contract_tree::ROOT, - l1_to_l2_message_tree_root: 0, - archive_root: 0, - public_data_tree_root: 0, - global_variables_hash: 0, +global BLOCK_HEADER = Header { + last_archive: AppendOnlyTreeSnapshot::empty(), + body_hash: [0; NUM_FIELDS_PER_SHA256], + state: StateReference { + l1_to_l2_message_tree: AppendOnlyTreeSnapshot::empty(), + partial: PartialStateReference { + note_hash_tree: AppendOnlyTreeSnapshot { + root: fixtures::note_hash_tree::ROOT, + next_available_leaf_index: 0, // TODO: should this be populated? + }, + nullifier_tree: AppendOnlyTreeSnapshot::empty(), + contract_tree: AppendOnlyTreeSnapshot { + root: fixtures::contract_tree::ROOT, + next_available_leaf_index: 0, // TODO: should this be populated? + }, + public_data_tree: AppendOnlyTreeSnapshot::empty() + } + }, + global_variables: GlobalVariables { + chain_id: 0, + version: 0, + block_number: 0, + timestamp: 0 + } }; diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/previous_kernel_data_builder.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/previous_kernel_data_builder.nr index 3a587aefbff7..2ad570e702e6 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/previous_kernel_data_builder.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/previous_kernel_data_builder.nr @@ -4,7 +4,6 @@ use crate::{ call_request::{CallerContext, CallRequest}, combined_constant_data::CombinedConstantData, combined_accumulated_data::CombinedAccumulatedDataBuilder, - block_header::BlockHeader, kernel_circuit_public_inputs::KernelCircuitPublicInputs, previous_kernel_data::PreviousKernelData, public_data_read::PublicDataRead, @@ -12,6 +11,7 @@ use crate::{ side_effect::{SideEffect, SideEffectLinkedToNoteHash}, }, address::{AztecAddress, EthAddress}, + header::Header, mocked::{Proof, VerificationKey}, tests::{ fixtures, @@ -32,7 +32,7 @@ struct PreviousKernelDataBuilder { contract_address: AztecAddress, portal_contract_address: EthAddress, end: CombinedAccumulatedDataBuilder, - block_header: BlockHeader, + block_header: Header, tx_context: TxContext, is_private: bool, proof: Proof, diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/private_circuit_public_inputs_builder.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/private_circuit_public_inputs_builder.nr index 2d09777ef071..302cbe022bdb 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/private_circuit_public_inputs_builder.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/private_circuit_public_inputs_builder.nr @@ -2,12 +2,12 @@ use crate::{ abis::{ call_context::CallContext, complete_address::CompleteAddress, - block_header::BlockHeader, private_circuit_public_inputs::PrivateCircuitPublicInputs, side_effect::{SideEffect, SideEffectLinkedToNoteHash}, }, contrakt::deployment_data::ContractDeploymentData, hash::{compute_constructor_hash, hash_args}, + header::Header, tests::{ fixtures, testing_harness::build_contract_deployment_data, @@ -46,7 +46,7 @@ struct PrivateCircuitPublicInputsBuilder { encrypted_log_preimages_length: Field, unencrypted_log_preimages_length: Field, - block_header: BlockHeader, + block_header: Header, contract_deployment_data: ContractDeploymentData, diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_circuit_public_inputs_builder.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_circuit_public_inputs_builder.nr index 134640b691b1..e14e05f77f8e 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_circuit_public_inputs_builder.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_circuit_public_inputs_builder.nr @@ -1,7 +1,6 @@ use crate::{ abis::{ call_context::CallContext, - block_header::BlockHeader, public_circuit_public_inputs::PublicCircuitPublicInputs, side_effect::{SideEffect, SideEffectLinkedToNoteHash}, }, @@ -10,6 +9,7 @@ use crate::{ storage_read::StorageRead, storage_update_request::StorageUpdateRequest, }, + header::Header, tests::fixtures, utils::bounded_vec::BoundedVec, }; @@ -36,7 +36,7 @@ struct PublicCircuitPublicInputsBuilder { new_l2_to_l1_msgs: BoundedVec, unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], unencrypted_log_preimages_length: Field, - block_header: BlockHeader, + block_header: Header, prover_address: AztecAddress, }