diff --git a/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp b/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp index acc05883409..c3a7b265564 100644 --- a/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp @@ -38,7 +38,6 @@ #define PUBLIC_INNER_CALL_REQUEST_LENGTH 13 #define STATE_REFERENCE_LENGTH 8 #define TOTAL_FEES_LENGTH 1 -#define HEADER_LENGTH 25 #define PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH 867 #define AVM_ACCUMULATED_DATA_LENGTH 318 #define AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH 1006 diff --git a/docs/docs/aztec/smart_contracts/functions/context.md b/docs/docs/aztec/smart_contracts/functions/context.md index 6929153a1f7..f8b0eae3c16 100644 --- a/docs/docs/aztec/smart_contracts/functions/context.md +++ b/docs/docs/aztec/smart_contracts/functions/context.md @@ -66,13 +66,11 @@ The call context contains information about the current call being made: - is_delegate_call: Denotes whether the current call is a delegate call. If true, then the storage contract address will be the address of the sender. - is_static_call: This will be set if and only if the current call is a static call. In a static call, state changing altering operations are not allowed. -### Header +### Block Header -Another structure that is contained within the context is the Header object. -In the private context this is a header of a block which used to generate proofs against. -In the public context this header is set by sequencer (sequencer executes public calls) and it is set to 1 block before the block in which the transaction is included. +Another structure that is contained within the context is the `BlockHeader` object, which is the header of the block used to generate proofs against. -#include_code header /noir-projects/noir-protocol-circuits/crates/types/src/header.nr rust +#include_code block-header /noir-projects/noir-protocol-circuits/crates/types/src/block_header.nr rust ### Transaction Context diff --git a/docs/docs/migration_notes.md b/docs/docs/migration_notes.md index ec28ac22ecc..03c70c7934b 100644 --- a/docs/docs/migration_notes.md +++ b/docs/docs/migration_notes.md @@ -6,6 +6,17 @@ keywords: [sandbox, aztec, notes, migration, updating, upgrading] Aztec is in full-speed development. Literally every version breaks compatibility with the previous ones. This page attempts to target errors and difficulties you might encounter when upgrading, and how to resolve them. +## TBD + +### [aztec.nr] Renamed `Header` and associated helpers + +The `Header` struct has been renamed to `BlockHeader`, and the `get_header()` family of functions have been similarly renamed to `get_block_header()`. + +```diff +- let header = context.get_header_at(block_number); ++ let header = context.get_block_header_at(block_number); +``` + ## 0.66 ### DEBUG env var is removed diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index eef7eeb48a1..79803ccb63b 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -199,7 +199,7 @@ library Constants { uint256 internal constant TX_REQUEST_LENGTH = 12; uint256 internal constant TOTAL_FEES_LENGTH = 1; uint256 internal constant TOTAL_MANA_USED_LENGTH = 1; - uint256 internal constant HEADER_LENGTH = 25; + uint256 internal constant BLOCK_HEADER_LENGTH = 25; uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 739; uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 867; uint256 internal constant PRIVATE_CONTEXT_INPUTS_LENGTH = 38; diff --git a/l1-contracts/src/core/libraries/RollupLibs/HeaderLib.sol b/l1-contracts/src/core/libraries/RollupLibs/HeaderLib.sol index 15d26b46e74..29021febbc3 100644 --- a/l1-contracts/src/core/libraries/RollupLibs/HeaderLib.sol +++ b/l1-contracts/src/core/libraries/RollupLibs/HeaderLib.sol @@ -203,8 +203,8 @@ library HeaderLib { fields[24] = bytes32(_header.totalManaUsed); // fail if the header structure has changed without updating this function require( - fields.length == Constants.HEADER_LENGTH, - Errors.HeaderLib__InvalidHeaderSize(Constants.HEADER_LENGTH, fields.length) + fields.length == Constants.BLOCK_HEADER_LENGTH, + Errors.HeaderLib__InvalidHeaderSize(Constants.BLOCK_HEADER_LENGTH, fields.length) ); return fields; @@ -234,7 +234,7 @@ library HeaderLib { // When we verify root proofs, this method can be removed => no need for separate named error require( fields.length == Constants.GLOBAL_VARIABLES_LENGTH, - Errors.HeaderLib__InvalidHeaderSize(Constants.HEADER_LENGTH, fields.length) + Errors.HeaderLib__InvalidHeaderSize(Constants.BLOCK_HEADER_LENGTH, fields.length) ); return fields; diff --git a/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr b/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr index 232972417cf..afbd1970bc0 100644 --- a/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr +++ b/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr @@ -1,5 +1,5 @@ use dep::protocol_types::{ - abis::call_context::CallContext, header::Header, traits::Empty, + abis::call_context::CallContext, block_header::BlockHeader, traits::Empty, transaction::tx_context::TxContext, }; @@ -7,7 +7,7 @@ use dep::protocol_types::{ // docs:start:private-context-inputs pub struct PrivateContextInputs { pub call_context: CallContext, - pub historical_header: Header, + pub historical_header: BlockHeader, pub tx_context: TxContext, pub start_side_effect_counter: u32, } @@ -17,7 +17,7 @@ impl Empty for PrivateContextInputs { fn empty() -> Self { PrivateContextInputs { call_context: CallContext::empty(), - historical_header: Header::empty(), + historical_header: BlockHeader::empty(), tx_context: TxContext::empty(), start_side_effect_counter: 0 as u32, } diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index 8284ebc74df..b2c94e61427 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -5,12 +5,12 @@ use crate::{ messaging::process_l1_to_l2_message, oracle::{ arguments, + block_header::get_block_header_at, call_private_function::call_private_function_internal, enqueue_public_function_call::{ enqueue_public_function_call_internal, notify_set_min_revertible_side_effect_counter, set_public_teardown_function_call_internal, }, - header::get_header_at, key_validation_request::get_key_validation_request, returns::pack_returns, }, @@ -33,6 +33,7 @@ use dep::protocol_types::{ validation_requests::{KeyValidationRequest, KeyValidationRequestAndGenerator}, }, address::{AztecAddress, EthAddress}, + block_header::BlockHeader, constants::{ MAX_CONTRACT_CLASS_LOGS_PER_CALL, MAX_ENQUEUED_CALLS_PER_CALL, MAX_KEY_VALIDATION_REQUESTS_PER_CALL, MAX_L2_TO_L1_MSGS_PER_CALL, @@ -41,7 +42,6 @@ use dep::protocol_types::{ MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, MAX_PRIVATE_LOGS_PER_CALL, PRIVATE_LOG_SIZE_IN_FIELDS, PUBLIC_DISPATCH_SELECTOR, }, - header::Header, messaging::l2_to_l1_message::L2ToL1Message, traits::Empty, }; @@ -74,7 +74,7 @@ pub struct PrivateContext { // docs:end:private-context // Header of a block whose state is used during private execution (not the block the transaction is included in). - pub historical_header: Header, + pub historical_header: BlockHeader, pub private_logs: BoundedVec, pub contract_class_logs_hashes: BoundedVec, @@ -157,14 +157,14 @@ impl PrivateContext { // Returns the header of a block whose state is used during private execution (not the block the transaction is // included in). - pub fn get_header(self) -> Header { + pub fn get_block_header(self) -> BlockHeader { self.historical_header } // Returns the header of an arbitrary block whose block number is less than or equal to the block number // of historical header. - pub fn get_header_at(self, block_number: u32) -> Header { - get_header_at(block_number, self) + pub fn get_block_header_at(self, block_number: u32) -> BlockHeader { + get_block_header_at(block_number, self) } pub fn set_return_hash(&mut self, returns_hasher: ArgsHasher) { @@ -585,7 +585,7 @@ impl Empty for PrivateContext { public_call_requests: BoundedVec::new(), public_teardown_call_request: PublicCallRequest::empty(), l2_to_l1_msgs: BoundedVec::new(), - historical_header: Header::empty(), + historical_header: BlockHeader::empty(), private_logs: BoundedVec::new(), contract_class_logs_hashes: BoundedVec::new(), last_key_validation_requests: [Option::none(); NUM_KEY_TYPES], diff --git a/noir-projects/aztec-nr/aztec/src/history/contract_inclusion.nr b/noir-projects/aztec-nr/aztec/src/history/contract_inclusion.nr index 342be3c0522..0fcd5ec920e 100644 --- a/noir-projects/aztec-nr/aztec/src/history/contract_inclusion.nr +++ b/noir-projects/aztec-nr/aztec/src/history/contract_inclusion.nr @@ -1,13 +1,13 @@ use dep::protocol_types::{ - address::AztecAddress, constants::DEPLOYER_CONTRACT_ADDRESS, hash::compute_siloed_nullifier, - header::Header, + address::AztecAddress, block_header::BlockHeader, constants::DEPLOYER_CONTRACT_ADDRESS, + hash::compute_siloed_nullifier, }; trait ProveContractDeployment { - fn prove_contract_deployment(header: Header, contract_address: AztecAddress); + fn prove_contract_deployment(header: BlockHeader, contract_address: AztecAddress); } -impl ProveContractDeployment for Header { +impl ProveContractDeployment for BlockHeader { fn prove_contract_deployment(self, contract_address: AztecAddress) { // Compute deployment nullifier let nullifier = @@ -18,10 +18,10 @@ impl ProveContractDeployment for Header { } trait ProveContractNonDeployment { - fn prove_contract_non_deployment(header: Header, contract_address: AztecAddress); + fn prove_contract_non_deployment(header: BlockHeader, contract_address: AztecAddress); } -impl ProveContractNonDeployment for Header { +impl ProveContractNonDeployment for BlockHeader { fn prove_contract_non_deployment(self, contract_address: AztecAddress) { // Compute deployment nullifier let nullifier = @@ -34,10 +34,10 @@ impl ProveContractNonDeployment for Header { } trait ProveContractInitialization { - fn prove_contract_initialization(header: Header, contract_address: AztecAddress); + fn prove_contract_initialization(header: BlockHeader, contract_address: AztecAddress); } -impl ProveContractInitialization for Header { +impl ProveContractInitialization for BlockHeader { fn prove_contract_initialization(self, contract_address: AztecAddress) { // Compute initialization nullifier let nullifier = compute_siloed_nullifier(contract_address, contract_address.to_field()); @@ -47,10 +47,10 @@ impl ProveContractInitialization for Header { } trait ProveContractNonInitialization { - fn prove_contract_non_initialization(header: Header, contract_address: AztecAddress); + fn prove_contract_non_initialization(header: BlockHeader, contract_address: AztecAddress); } -impl ProveContractNonInitialization for Header { +impl ProveContractNonInitialization for BlockHeader { fn prove_contract_non_initialization(self, contract_address: AztecAddress) { // Compute initialization nullifier let nullifier = compute_siloed_nullifier(contract_address, contract_address.to_field()); diff --git a/noir-projects/aztec-nr/aztec/src/history/note_inclusion.nr b/noir-projects/aztec-nr/aztec/src/history/note_inclusion.nr index 0876b824a07..886801dea6f 100644 --- a/noir-projects/aztec-nr/aztec/src/history/note_inclusion.nr +++ b/noir-projects/aztec-nr/aztec/src/history/note_inclusion.nr @@ -1,4 +1,4 @@ -use dep::protocol_types::header::Header; +use dep::protocol_types::block_header::BlockHeader; use dep::protocol_types::merkle_tree::root::root_from_sibling_path; use crate::{ @@ -7,12 +7,12 @@ use crate::{ }; trait ProveNoteInclusion { - fn prove_note_inclusion(header: Header, note: Note) + fn prove_note_inclusion(header: BlockHeader, note: Note) where Note: NoteInterface + NullifiableNote; } -impl ProveNoteInclusion for Header { +impl ProveNoteInclusion for BlockHeader { fn prove_note_inclusion(self, note: Note) where Note: NoteInterface + NullifiableNote, diff --git a/noir-projects/aztec-nr/aztec/src/history/note_validity.nr b/noir-projects/aztec-nr/aztec/src/history/note_validity.nr index 3efac1fc1aa..1eb5981024b 100644 --- a/noir-projects/aztec-nr/aztec/src/history/note_validity.nr +++ b/noir-projects/aztec-nr/aztec/src/history/note_validity.nr @@ -1,10 +1,10 @@ use crate::{context::PrivateContext, note::note_interface::{NoteInterface, NullifiableNote}}; -use dep::protocol_types::header::Header; +use dep::protocol_types::block_header::BlockHeader; trait ProveNoteValidity { fn prove_note_validity( - header: Header, + header: BlockHeader, note: Note, context: &mut PrivateContext, ) @@ -12,7 +12,7 @@ trait ProveNoteValidity { Note: NoteInterface + NullifiableNote; } -impl ProveNoteValidity for Header { +impl ProveNoteValidity for BlockHeader { fn prove_note_validity(self, note: Note, context: &mut PrivateContext) where Note: NoteInterface + NullifiableNote, diff --git a/noir-projects/aztec-nr/aztec/src/history/nullifier_inclusion.nr b/noir-projects/aztec-nr/aztec/src/history/nullifier_inclusion.nr index bd0f508d485..f1278658b89 100644 --- a/noir-projects/aztec-nr/aztec/src/history/nullifier_inclusion.nr +++ b/noir-projects/aztec-nr/aztec/src/history/nullifier_inclusion.nr @@ -1,4 +1,4 @@ -use dep::protocol_types::header::Header; +use dep::protocol_types::block_header::BlockHeader; use dep::protocol_types::merkle_tree::root::root_from_sibling_path; use crate::{ @@ -8,10 +8,10 @@ use crate::{ }; trait ProveNullifierInclusion { - fn prove_nullifier_inclusion(header: Header, nullifier: Field); + fn prove_nullifier_inclusion(header: BlockHeader, nullifier: Field); } -impl ProveNullifierInclusion for Header { +impl ProveNullifierInclusion for BlockHeader { fn prove_nullifier_inclusion(self, nullifier: Field) { // 1) Get the membership witness of the nullifier let witness = unsafe { @@ -39,7 +39,7 @@ impl ProveNullifierInclusion for Header { trait ProveNoteIsNullified { fn prove_note_is_nullified( - header: Header, + header: BlockHeader, note: Note, context: &mut PrivateContext, ) @@ -47,7 +47,7 @@ trait ProveNoteIsNullified { Note: NoteInterface + NullifiableNote; } -impl ProveNoteIsNullified for Header { +impl ProveNoteIsNullified for BlockHeader { // docs:start:prove_note_is_nullified fn prove_note_is_nullified(self, note: Note, context: &mut PrivateContext) where diff --git a/noir-projects/aztec-nr/aztec/src/history/nullifier_non_inclusion.nr b/noir-projects/aztec-nr/aztec/src/history/nullifier_non_inclusion.nr index 95a43086b2b..e40c199ea7d 100644 --- a/noir-projects/aztec-nr/aztec/src/history/nullifier_non_inclusion.nr +++ b/noir-projects/aztec-nr/aztec/src/history/nullifier_non_inclusion.nr @@ -4,16 +4,16 @@ use crate::{ oracle::get_nullifier_membership_witness::get_low_nullifier_membership_witness, }; use dep::protocol_types::{ - header::Header, + block_header::BlockHeader, utils::field::{full_field_greater_than, full_field_less_than}, }; use dep::protocol_types::merkle_tree::root::root_from_sibling_path; trait ProveNullifierNonInclusion { - fn prove_nullifier_non_inclusion(header: Header, nullifier: Field); + fn prove_nullifier_non_inclusion(header: BlockHeader, nullifier: Field); } -impl ProveNullifierNonInclusion for Header { +impl ProveNullifierNonInclusion for BlockHeader { fn prove_nullifier_non_inclusion(self, nullifier: Field) { // 1) Get the membership witness of a low nullifier of the nullifier let witness = unsafe { @@ -52,7 +52,7 @@ impl ProveNullifierNonInclusion for Header { trait ProveNoteNotNullified { fn prove_note_not_nullified( - header: Header, + header: BlockHeader, note: Note, context: &mut PrivateContext, ) @@ -60,7 +60,7 @@ trait ProveNoteNotNullified { Note: NoteInterface + NullifiableNote; } -impl ProveNoteNotNullified for Header { +impl ProveNoteNotNullified for BlockHeader { // docs:start:prove_note_not_nullified fn prove_note_not_nullified(self, note: Note, context: &mut PrivateContext) where diff --git a/noir-projects/aztec-nr/aztec/src/history/public_storage.nr b/noir-projects/aztec-nr/aztec/src/history/public_storage.nr index d26397d1314..37cf287cde4 100644 --- a/noir-projects/aztec-nr/aztec/src/history/public_storage.nr +++ b/noir-projects/aztec-nr/aztec/src/history/public_storage.nr @@ -1,6 +1,6 @@ use dep::protocol_types::{ - address::AztecAddress, constants::GENERATOR_INDEX__PUBLIC_LEAF_INDEX, - hash::poseidon2_hash_with_separator, header::Header, utils::field::full_field_less_than, + address::AztecAddress, block_header::BlockHeader, constants::GENERATOR_INDEX__PUBLIC_LEAF_INDEX, + hash::poseidon2_hash_with_separator, utils::field::full_field_less_than, }; use dep::protocol_types::merkle_tree::root::root_from_sibling_path; @@ -8,13 +8,13 @@ use crate::oracle::get_public_data_witness::get_public_data_witness; trait PublicStorageHistoricalRead { fn public_storage_historical_read( - header: Header, + header: BlockHeader, storage_slot: Field, contract_address: AztecAddress, ) -> Field; } -impl PublicStorageHistoricalRead for Header { +impl PublicStorageHistoricalRead for BlockHeader { fn public_storage_historical_read( self, storage_slot: Field, diff --git a/noir-projects/aztec-nr/aztec/src/oracle/header.nr b/noir-projects/aztec-nr/aztec/src/oracle/block_header.nr similarity index 54% rename from noir-projects/aztec-nr/aztec/src/oracle/header.nr rename to noir-projects/aztec-nr/aztec/src/oracle/block_header.nr index 9ce477aac1a..3139b6d85a6 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/header.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/block_header.nr @@ -1,32 +1,30 @@ -use dep::protocol_types::{constants::HEADER_LENGTH, header::Header}; +use dep::protocol_types::{block_header::BlockHeader, constants::BLOCK_HEADER_LENGTH}; use dep::protocol_types::merkle_tree::root::root_from_sibling_path; use crate::{ context::PrivateContext, oracle::get_membership_witness::get_archive_membership_witness, }; -use crate::test::helpers::test_environment::TestEnvironment; +#[oracle(getBlockHeader)] +unconstrained fn get_block_header_at_oracle(_block_number: u32) -> [Field; BLOCK_HEADER_LENGTH] {} -#[oracle(getHeader)] -unconstrained fn get_header_at_oracle(_block_number: u32) -> [Field; HEADER_LENGTH] {} - -pub unconstrained fn get_header_at_internal(block_number: u32) -> Header { - let header = get_header_at_oracle(block_number); - Header::deserialize(header) +unconstrained fn get_block_header_at_internal(block_number: u32) -> BlockHeader { + let header = get_block_header_at_oracle(block_number); + BlockHeader::deserialize(header) } -pub fn get_header_at(block_number: u32, context: PrivateContext) -> Header { - let header = context.historical_header; - let current_block_number = header.global_variables.block_number as u32; +pub fn get_block_header_at(block_number: u32, context: PrivateContext) -> BlockHeader { + let historical_header = context.historical_header; + let historical_block_number = historical_header.global_variables.block_number as u32; - if (block_number == current_block_number) { + if (block_number == historical_block_number) { // If the block number we want to prove against is the same as the block number in the historical header we // skip the inclusion proofs and just return the historical header from context. - header + historical_header } else { // 1) Get block number corresponding to the last_archive root in the header // Note: We subtract 1 because the last_archive root is the root of the archive after applying the previous block - let last_archive_block_number = current_block_number - 1; + let last_archive_block_number = historical_block_number - 1; // 2) Check that the last archive block number is more than or equal to the block number we want to prove against // We could not perform the proof otherwise because the last archive root from the header would not "contain" @@ -37,24 +35,24 @@ pub fn get_header_at(block_number: u32, context: PrivateContext) -> Header { ); // 3) Get the header hint of a given block from an oracle - let historical = unsafe { get_header_at_internal(block_number) }; + let header = unsafe { get_block_header_at_internal(block_number) }; // 4) We make sure that the header hint we received from the oracle exists in the state tree and is the actual header // at the desired block number - constrain_get_header_at_internal( - historical, + constrain_get_block_header_at_internal( + header, block_number, last_archive_block_number, - header.last_archive.root, + historical_header.last_archive.root, ); // 5) Return the block header - historical + header } } -fn constrain_get_header_at_internal( - header_hint: Header, +fn constrain_get_block_header_at_internal( + header_hint: BlockHeader, block_number: u32, last_archive_block_number: u32, last_archive_root: Field, @@ -78,23 +76,28 @@ fn constrain_get_header_at_internal( ); } -#[test(should_fail_with = "Block number provided is not the same as the block number from the header hint")] -unconstrained fn fetching_a_valid_but_different_header_should_fail() { - let mut env = TestEnvironment::new(); +mod test { + use crate::test::helpers::test_environment::TestEnvironment; + use super::{constrain_get_block_header_at_internal, get_block_header_at_internal}; - env.advance_block_to(3); + #[test(should_fail_with = "Block number provided is not the same as the block number from the header hint")] + unconstrained fn fetching_a_valid_but_different_header_should_fail() { + let mut env = TestEnvironment::new(); - // We get our current header for the last archive values. - let current_header = env.private().historical_header; + env.advance_block_to(3); - let target_block_number = 2; - let bad_header = get_header_at_internal(target_block_number - 1); + // We get our current header for the last archive values. + let current_header = env.private().historical_header; - // We pass in a different block number than the header received - constrain_get_header_at_internal( - bad_header, - 2, - current_header.global_variables.block_number as u32 - 1, - current_header.last_archive.root, - ); + let target_block_number = 2; + let bad_header = get_block_header_at_internal(target_block_number - 1); + + // We pass in a different block number than the header received + constrain_get_block_header_at_internal( + bad_header, + 2, + current_header.global_variables.block_number as u32 - 1, + current_header.last_archive.root, + ); + } } diff --git a/noir-projects/aztec-nr/aztec/src/oracle/mod.nr b/noir-projects/aztec-nr/aztec/src/oracle/mod.nr index b6d74a57c69..7fbf9f64b8b 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/mod.nr @@ -15,7 +15,7 @@ pub mod key_validation_request; pub mod get_sibling_path; pub mod random; pub mod enqueue_public_function_call; -pub mod header; +pub mod block_header; pub mod notes; pub mod storage; pub mod logs; diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/public_immutable.nr b/noir-projects/aztec-nr/aztec/src/state_vars/public_immutable.nr index a3e5df8b9c8..4ed4f2bbb4d 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/public_immutable.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/public_immutable.nr @@ -73,7 +73,7 @@ where T: Serialize + Deserialize, { pub fn read(self) -> T { - let header = self.context.get_header(); + let header = self.context.get_block_header(); let mut fields = [0; T_SERIALIZED_LEN]; for i in 0..fields.len() { diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable.nr b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable.nr index a56f06c7f66..3d940d3d492 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable.nr @@ -191,7 +191,7 @@ where fn historical_read_from_public_storage( self, ) -> (ScheduledValueChange, ScheduledDelayChange, u32) { - let header = self.context.get_header(); + let header = self.context.get_block_header(); let address = self.context.this_address(); let historical_block_number = header.global_variables.block_number as u32; diff --git a/noir-projects/noir-contracts/contracts/claim_contract/src/main.nr b/noir-projects/noir-contracts/contracts/claim_contract/src/main.nr index 1318e17f192..e2a9e487756 100644 --- a/noir-projects/noir-contracts/contracts/claim_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/claim_contract/src/main.nr @@ -36,7 +36,7 @@ contract Claim { ); // 2) Prove that the note hash exists in the note hash tree - let header = context.get_header(); + let header = context.get_block_header(); header.prove_note_inclusion(proof_note); // 3) Compute and emit a nullifier which is unique to the note and this contract to ensure the reward can be diff --git a/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr b/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr index 8be4ea12343..65dafc9a93f 100644 --- a/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr @@ -65,9 +65,9 @@ contract InclusionProofs { // docs:start:prove_note_inclusion // 2) Prove the note inclusion let header = if (use_block_number) { - context.get_header_at(block_number) + context.get_block_header_at(block_number) } else { - context.get_header() + context.get_block_header() }; header.prove_note_inclusion(note); @@ -80,13 +80,13 @@ contract InclusionProofs { use_block_number: bool, block_number: u32, // The block at which we'll prove that the note exists ) { - let header = context.get_header(); + let header = context.get_block_header(); let mut note = ValueNote::new(1, owner); let header = if (use_block_number) { - context.get_header_at(block_number) + context.get_block_header_at(block_number) } else { - context.get_header() + context.get_block_header() }; header.prove_note_inclusion(note); @@ -113,9 +113,9 @@ contract InclusionProofs { let note = private_values.get_notes(options).get(0); let header = if (use_block_number) { - context.get_header_at(block_number) + context.get_block_header_at(block_number) } else { - context.get_header() + context.get_block_header() }; // docs:start:prove_note_not_nullified header.prove_note_not_nullified(note, &mut context); @@ -140,9 +140,9 @@ contract InclusionProofs { // 2) Prove the note validity let header = if (use_block_number) { - context.get_header_at(block_number) + context.get_block_header_at(block_number) } else { - context.get_header() + context.get_block_header() }; // docs:start:prove_note_validity header.prove_note_validity(note, &mut context); @@ -170,9 +170,9 @@ contract InclusionProofs { block_number: u32, // The block at which we'll prove that the nullifier exists in the nullifier tree ) { let header = if (use_block_number) { - context.get_header_at(block_number) + context.get_block_header_at(block_number) } else { - context.get_header() + context.get_block_header() }; // docs:start:prove_nullifier_inclusion header.prove_nullifier_inclusion(nullifier); @@ -194,7 +194,7 @@ contract InclusionProofs { fn test_storage_historical_read_unset_slot( block_number: u32, // The block at which we'll read the public storage value ) { - let header = context.get_header_at(block_number); + let header = context.get_block_header_at(block_number); // docs:start:public_storage_historical_read assert_eq( header.public_storage_historical_read( @@ -213,9 +213,9 @@ contract InclusionProofs { block_number: u32, // The block at which we'll read the public storage value ) { let header = if (use_block_number) { - context.get_header_at(block_number) + context.get_block_header_at(block_number) } else { - context.get_header() + context.get_block_header() }; let actual = header.public_storage_historical_read( @@ -234,7 +234,7 @@ contract InclusionProofs { test_deployment: bool, test_initialization: bool, ) { - let header = context.get_header_at(block_number); + let header = context.get_block_header_at(block_number); if test_deployment { // docs:start:prove_contract_deployment @@ -256,7 +256,7 @@ contract InclusionProofs { test_deployment: bool, test_initialization: bool, ) { - let header = context.get_header_at(block_number); + let header = context.get_block_header_at(block_number); if test_deployment { // docs:start:prove_contract_non_deployment 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 76ac505ad72..fa8a054d0e6 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,5 +1,5 @@ use dep::types::{ - header::Header, + block_header::BlockHeader, KernelCircuitPublicInputs, proof::{ recursive_proof::RecursiveProof, @@ -28,7 +28,7 @@ impl Empty for EmptyNestedCircuitPublicInputs { pub struct PrivateKernelEmptyPrivateInputs { empty_nested: EmptyNestedCircuitPublicInputs, - historical_header: Header, + historical_header: BlockHeader, chain_id: Field, version: Field, vk_tree_root: Field, @@ -54,7 +54,7 @@ impl Empty for PrivateKernelEmptyPrivateInputs { fn empty() -> Self { PrivateKernelEmptyPrivateInputs { empty_nested: EmptyNestedCircuitPublicInputs::empty(), - historical_header: Header::empty(), + historical_header: BlockHeader::empty(), chain_id: 0, version: 0, vk_tree_root: 0, @@ -67,13 +67,13 @@ mod tests { use crate::private_kernel_empty::{ EmptyNestedCircuitPublicInputs, PrivateKernelEmptyPrivateInputs, }; - use dep::types::header::Header; + use dep::types::block_header::BlockHeader; #[test] unconstrained fn works() { let private_inputs = PrivateKernelEmptyPrivateInputs { empty_nested: EmptyNestedCircuitPublicInputs::empty(), - historical_header: Header::empty(), + historical_header: BlockHeader::empty(), chain_id: 1, version: 2, vk_tree_root: 3, diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/archive.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/archive.nr index e97541be158..075676c4846 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/archive.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/archive.nr @@ -1,6 +1,6 @@ use types::{ + block_header::BlockHeader, constants::ARCHIVE_HEIGHT, - header::Header, merkle_tree::membership::{assert_check_membership, MembershipWitness}, }; @@ -9,7 +9,7 @@ use types::{ pub(crate) fn perform_archive_membership_check( archive_root: Field, previous_block_hash_witness: MembershipWitness, - header: Header, + header: BlockHeader, ) { // Rebuild the block hash let previous_block_hash = header.hash(); 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 751dc299204..ea137243a54 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 @@ -8,6 +8,7 @@ use crate::{ use parity_lib::root::root_rollup_parity_input::RootRollupParityInput; use types::{ abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot, + block_header::BlockHeader, constants::{ ARCHIVE_HEIGHT, AZTEC_MAX_EPOCH_DURATION, L1_TO_L2_MSG_SUBTREE_HEIGHT, L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, MERGE_ROLLUP_INDEX, @@ -15,7 +16,6 @@ use types::{ PUBLIC_BASE_ROLLUP_VK_INDEX, }, content_commitment::ContentCommitment, - header::Header, merkle_tree::{append_only_tree, calculate_empty_tree_root}, state_reference::StateReference, traits::Empty, @@ -116,7 +116,7 @@ impl BlockRootRollupInputs { // debug_log_format("header.total_fees={0}", [total_fees]); // debug_log_format("header.total_mana_used={0}", [total_mana_used]); // } - let header = Header { + let header = BlockHeader { last_archive: left.constants.last_archive, content_commitment, state, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr index 03e9863016b..48d0f7be170 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr @@ -1,12 +1,12 @@ use crate::abis::{global_variables::GlobalVariables, tx_constant_data::TxConstantData}; +use crate::block_header::BlockHeader; use crate::constants::COMBINED_CONSTANT_DATA_LENGTH; -use crate::header::Header; use crate::traits::{Deserialize, Empty, Serialize}; use crate::transaction::tx_context::TxContext; use crate::utils::reader::Reader; pub struct CombinedConstantData { - pub historical_header: Header, + pub historical_header: BlockHeader, // Note: `chain_id` and `version` in tx_context are not redundant to the values in // self.historical_header.global_variables because they can be different in case of a protocol upgrade. In such // a situation we could be using header from a block before the upgrade took place but be using the updated @@ -37,7 +37,7 @@ impl CombinedConstantData { impl Empty for CombinedConstantData { fn empty() -> Self { CombinedConstantData { - historical_header: Header::empty(), + historical_header: BlockHeader::empty(), tx_context: TxContext::empty(), vk_tree_root: 0, protocol_contract_tree_root: 0, @@ -67,7 +67,7 @@ impl Deserialize for CombinedConstantData { let mut reader = Reader::new(fields); let item = CombinedConstantData { - historical_header: reader.read_struct(Header::deserialize), + historical_header: reader.read_struct(BlockHeader::deserialize), tx_context: reader.read_struct(TxContext::deserialize), vk_tree_root: reader.read(), protocol_contract_tree_root: reader.read(), diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr index c4e9a850257..217d97ddffc 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr @@ -6,6 +6,7 @@ use crate::{ read_request::ReadRequest, side_effect::Counted, validation_requests::KeyValidationRequestAndGenerator, }, + block_header::BlockHeader, constants::{ MAX_CONTRACT_CLASS_LOGS_PER_CALL, MAX_ENQUEUED_CALLS_PER_CALL, MAX_KEY_VALIDATION_REQUESTS_PER_CALL, MAX_L2_TO_L1_MSGS_PER_CALL, @@ -14,7 +15,6 @@ use crate::{ MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, MAX_PRIVATE_LOGS_PER_CALL, PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH, }, - header::Header, messaging::l2_to_l1_message::L2ToL1Message, traits::{Deserialize, Empty, Serialize}, transaction::tx_context::TxContext, @@ -82,7 +82,7 @@ pub struct PrivateCircuitPublicInputs { pub end_side_effect_counter: u32, // Header of a block whose state is used during private execution (not the block the transaction is included in). - pub historical_header: Header, + pub historical_header: BlockHeader, // Note: The chain_id and version here are not redundant to the values in self.historical_header.global_variables because // they can be different in case of a protocol upgrade. In such a situation we could be using header from a block @@ -226,7 +226,7 @@ impl Deserialize for PrivateCircuitPublicI ), start_side_effect_counter: reader.read() as u32, end_side_effect_counter: reader.read() as u32, - historical_header: reader.read_struct(Header::deserialize), + historical_header: reader.read_struct(BlockHeader::deserialize), tx_context: reader.read_struct(TxContext::deserialize), }; @@ -261,7 +261,7 @@ impl Empty for PrivateCircuitPublicInputs { contract_class_logs_hashes: [LogHash::empty(); MAX_CONTRACT_CLASS_LOGS_PER_CALL], start_side_effect_counter: 0 as u32, end_side_effect_counter: 0 as u32, - historical_header: Header::empty(), + historical_header: BlockHeader::empty(), tx_context: TxContext::empty(), } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/tx_constant_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/tx_constant_data.nr index be7c8151d70..e23d05cca9d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/tx_constant_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/tx_constant_data.nr @@ -1,6 +1,6 @@ use crate::{ + block_header::BlockHeader, constants::TX_CONSTANT_DATA_LENGTH, - header::Header, traits::{Deserialize, Empty, Serialize}, transaction::tx_context::TxContext, utils::reader::Reader, @@ -8,7 +8,7 @@ use crate::{ // Constants used throughout the executions of both private and public. pub struct TxConstantData { - pub historical_header: Header, + pub historical_header: BlockHeader, // Note: `chain_id` and `version` in tx_context are not redundant to the values in // self.historical_header.global_variables because they can be different in case of a protocol upgrade. In such // a situation we could be using header from a block before the upgrade took place but be using the updated @@ -21,7 +21,7 @@ pub struct TxConstantData { impl Empty for TxConstantData { fn empty() -> Self { TxConstantData { - historical_header: Header::empty(), + historical_header: BlockHeader::empty(), tx_context: TxContext::empty(), vk_tree_root: 0, protocol_contract_tree_root: 0, @@ -58,7 +58,7 @@ impl Deserialize for TxConstantData { let mut reader = Reader::new(fields); let item = TxConstantData { - historical_header: reader.read_struct(Header::deserialize), + historical_header: reader.read_struct(BlockHeader::deserialize), tx_context: reader.read_struct(TxContext::deserialize), vk_tree_root: reader.read(), protocol_contract_tree_root: reader.read(), diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr b/noir-projects/noir-protocol-circuits/crates/types/src/block_header.nr similarity index 81% rename from noir-projects/noir-protocol-circuits/crates/types/src/header.nr rename to noir-projects/noir-protocol-circuits/crates/types/src/block_header.nr index 5817cdb7e18..842a7eaa308 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/block_header.nr @@ -4,8 +4,8 @@ use crate::{ global_variables::GlobalVariables, }, constants::{ - CONTENT_COMMITMENT_LENGTH, GENERATOR_INDEX__BLOCK_HASH, GLOBAL_VARIABLES_LENGTH, - HEADER_LENGTH, STATE_REFERENCE_LENGTH, + BLOCK_HEADER_LENGTH, CONTENT_COMMITMENT_LENGTH, GENERATOR_INDEX__BLOCK_HASH, + GLOBAL_VARIABLES_LENGTH, STATE_REFERENCE_LENGTH, }, content_commitment::ContentCommitment, hash::poseidon2_hash_with_separator, @@ -14,8 +14,8 @@ use crate::{ utils::arr_copy_slice, }; -// docs:start:header -pub struct Header { +// docs:start:block-header +pub struct BlockHeader { pub last_archive: AppendOnlyTreeSnapshot, pub content_commitment: ContentCommitment, pub state: StateReference, @@ -23,9 +23,9 @@ pub struct Header { pub total_fees: Field, pub total_mana_used: Field, } -// docs:end:header +// docs:end:block-header -impl Eq for Header { +impl Eq for BlockHeader { fn eq(self, other: Self) -> bool { self.last_archive.eq(other.last_archive) & self.content_commitment.eq(other.content_commitment) @@ -36,9 +36,9 @@ impl Eq for Header { } } -impl Serialize for Header { - fn serialize(self) -> [Field; HEADER_LENGTH] { - let mut fields: BoundedVec = BoundedVec::new(); +impl Serialize for BlockHeader { + fn serialize(self) -> [Field; BLOCK_HEADER_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); fields.extend_from_array(self.last_archive.serialize()); fields.extend_from_array(self.content_commitment.serialize()); @@ -50,8 +50,8 @@ impl Serialize for Header { } } -impl Deserialize for Header { - fn deserialize(serialized: [Field; HEADER_LENGTH]) -> Self { +impl Deserialize for BlockHeader { + fn deserialize(serialized: [Field; BLOCK_HEADER_LENGTH]) -> Self { let mut offset = 0; let last_archive_fields = @@ -74,7 +74,7 @@ impl Deserialize for Header { let total_mana_used = serialized[offset]; - Header { + BlockHeader { last_archive: AppendOnlyTreeSnapshot::deserialize(last_archive_fields), content_commitment: ContentCommitment::deserialize(content_commitment_fields), state: StateReference::deserialize(state_fields), @@ -85,7 +85,7 @@ impl Deserialize for Header { } } -impl Empty for Header { +impl Empty for BlockHeader { fn empty() -> Self { Self { last_archive: AppendOnlyTreeSnapshot::zero(), @@ -98,7 +98,7 @@ impl Empty for Header { } } -impl Hash for Header { +impl Hash for BlockHeader { fn hash(self) -> Field { poseidon2_hash_with_separator(self.serialize(), GENERATOR_INDEX__BLOCK_HASH) } @@ -106,21 +106,21 @@ impl Hash for Header { #[test] fn serialization_of_empty() { - let header = Header::empty(); + let header = BlockHeader::empty(); let serialized = header.serialize(); - let deserialized = Header::deserialize(serialized); + let deserialized = BlockHeader::deserialize(serialized); assert(header.eq(deserialized)); } #[test] fn hash_smoke() { - let header = Header::empty(); + let header = BlockHeader::empty(); let _hashed = header.hash(); } #[test] fn empty_hash_is_zero() { - let header = Header::empty(); + let header = BlockHeader::empty(); let hash = header.hash(); // Value from new_contract_data.test.ts "computes empty hash" test 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 488d22b26c9..9311559e90b 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -307,7 +307,7 @@ pub global TX_CONTEXT_LENGTH: u32 = 2 + GAS_SETTINGS_LENGTH; pub global TX_REQUEST_LENGTH: u32 = 2 + TX_CONTEXT_LENGTH + FUNCTION_DATA_LENGTH; pub global TOTAL_FEES_LENGTH: u32 = 1; pub global TOTAL_MANA_USED_LENGTH: u32 = 1; -pub global HEADER_LENGTH: u32 = APPEND_ONLY_TREE_SNAPSHOT_LENGTH +pub global BLOCK_HEADER_LENGTH: u32 = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + CONTENT_COMMITMENT_LENGTH + STATE_REFERENCE_LENGTH + GLOBAL_VARIABLES_LENGTH @@ -328,7 +328,7 @@ pub global PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH: u32 = CALL_CONTEXT_LENGTH + 2 + (PRIVATE_LOG_DATA_LENGTH * MAX_PRIVATE_LOGS_PER_CALL) + (LOG_HASH_LENGTH * MAX_CONTRACT_CLASS_LOGS_PER_CALL) - + HEADER_LENGTH + + BLOCK_HEADER_LENGTH + TX_CONTEXT_LENGTH; pub global PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH: u32 = CALL_CONTEXT_LENGTH + /*argsHash + returnsHash*/ 2 @@ -344,14 +344,14 @@ pub global PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH: u32 = CALL_CONTEXT_LENGTH + (L2_TO_L1_MESSAGE_LENGTH * MAX_L2_TO_L1_MSGS_PER_CALL) + 2 + (LOG_HASH_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) - + HEADER_LENGTH + + BLOCK_HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + AZTEC_ADDRESS_LENGTH + /* revert_code */ 1 + 2 * GAS_LENGTH + /* transaction_fee */ 1; pub global PRIVATE_CONTEXT_INPUTS_LENGTH: u32 = - CALL_CONTEXT_LENGTH + HEADER_LENGTH + TX_CONTEXT_LENGTH + 1; + CALL_CONTEXT_LENGTH + BLOCK_HEADER_LENGTH + TX_CONTEXT_LENGTH + 1; pub global FEE_RECIPIENT_LENGTH: u32 = 2; pub global AGGREGATION_OBJECT_LENGTH: u32 = 16; @@ -373,7 +373,7 @@ pub global COMBINED_ACCUMULATED_DATA_LENGTH: u32 = MAX_NOTE_HASHES_PER_TX + (SCOPED_LOG_HASH_LENGTH * MAX_CONTRACT_CLASS_LOGS_PER_TX) + 1 /* contract_class_log_preimages_length */ + (MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * PUBLIC_DATA_WRITE_LENGTH); -pub global TX_CONSTANT_DATA_LENGTH: u32 = HEADER_LENGTH +pub global TX_CONSTANT_DATA_LENGTH: u32 = BLOCK_HEADER_LENGTH + TX_CONTEXT_LENGTH + 1 /* vk_tree_root */ + 1 /* protocol_contract_tree_root */; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr b/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr index d5ead85a57f..e4e638b113d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr @@ -17,7 +17,7 @@ pub mod traits; pub mod type_serialization; pub mod content_commitment; -pub mod header; +pub mod block_header; mod tests; 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 2780ca84cb0..34274967dcd 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 @@ -37,6 +37,7 @@ use crate::{ }, }, address::{AztecAddress, EthAddress, SaltedInitializationHash}, + block_header::BlockHeader, constants::{ CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS, FUNCTION_TREE_HEIGHT, MAX_CONTRACT_CLASS_LOGS_PER_TX, MAX_ENQUEUED_CALLS_PER_TX, MAX_FIELD_VALUE, @@ -52,7 +53,6 @@ use crate::{ compute_l2_to_l1_hash, compute_siloed_nullifier, compute_siloed_private_log_field, silo_note_hash, }, - header::Header, merkle_tree::{membership::MembershipWitness, MerkleTree}, messaging::l2_to_l1_message::{L2ToL1Message, ScopedL2ToL1Message}, partial_state_reference::PartialStateReference, @@ -101,7 +101,7 @@ pub struct FixtureBuilder { pub end_gas_left: Gas, // Constant data. - pub historical_header: Header, + pub historical_header: BlockHeader, pub tx_context: TxContext, pub global_variables: GlobalVariables, @@ -1059,7 +1059,7 @@ impl Empty for FixtureBuilder { is_fee_payer: false, fee_payer: AztecAddress::zero(), public_teardown_call_request: PublicCallRequest::empty(), - historical_header: Header::empty(), + historical_header: BlockHeader::empty(), tx_context: TxContext::empty(), global_variables: GlobalVariables::empty(), note_hashes: BoundedVec::new(), diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index f3b25d266b4..849b36df3aa 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -22,12 +22,12 @@ import { getTimestampRangeForEpoch, } from '@aztec/circuit-types'; import { + type BlockHeader, type ContractClassPublic, type ContractDataSource, type ContractInstanceWithAddress, type ExecutablePrivateFunctionWithMembershipProof, type FunctionSelector, - type Header, type PrivateLog, type PublicFunction, type UnconstrainedFunctionWithMembershipProof, @@ -617,7 +617,7 @@ export class Archiver implements ArchiveSource { return blocks.length === 0 ? undefined : blocks[0].data; } - public async getBlockHeader(number: number | 'latest'): Promise
{ + public async getBlockHeader(number: number | 'latest'): Promise { if (number === 'latest') { number = await this.store.getSynchedL2BlockNumber(); } @@ -1014,7 +1014,7 @@ class ArchiverStoreHelper getBlocks(from: number, limit: number): Promise[]> { return this.store.getBlocks(from, limit); } - getBlockHeaders(from: number, limit: number): Promise { + getBlockHeaders(from: number, limit: number): Promise { return this.store.getBlockHeaders(from, limit); } getTxEffect(txHash: TxHash): Promise | undefined> { diff --git a/yarn-project/archiver/src/archiver/archiver_store.ts b/yarn-project/archiver/src/archiver/archiver_store.ts index 281fb80c41d..11d0abd7c35 100644 --- a/yarn-project/archiver/src/archiver/archiver_store.ts +++ b/yarn-project/archiver/src/archiver/archiver_store.ts @@ -10,11 +10,11 @@ import { type TxScopedL2Log, } from '@aztec/circuit-types'; import { + type BlockHeader, type ContractClassPublic, type ContractInstanceWithAddress, type ExecutablePrivateFunctionWithMembershipProof, type Fr, - type Header, type PrivateLog, type UnconstrainedFunctionWithMembershipProof, } from '@aztec/circuits.js'; @@ -71,7 +71,7 @@ export interface ArchiverDataStore { * @param limit - The number of blocks to return. * @returns The requested L2 block headers. */ - getBlockHeaders(from: number, limit: number): Promise; + getBlockHeaders(from: number, limit: number): Promise; /** * Gets a tx effect. diff --git a/yarn-project/archiver/src/archiver/data_retrieval.ts b/yarn-project/archiver/src/archiver/data_retrieval.ts index de09a98ac23..7cc84ab185c 100644 --- a/yarn-project/archiver/src/archiver/data_retrieval.ts +++ b/yarn-project/archiver/src/archiver/data_retrieval.ts @@ -1,5 +1,5 @@ import { Body, InboxLeaf, L2Block } from '@aztec/circuit-types'; -import { AppendOnlyTreeSnapshot, Fr, Header, Proof } from '@aztec/circuits.js'; +import { AppendOnlyTreeSnapshot, BlockHeader, Fr, Proof } from '@aztec/circuits.js'; import { asyncPool } from '@aztec/foundation/async-pool'; import { type EthAddress } from '@aztec/foundation/eth-address'; import { type ViemSignature } from '@aztec/foundation/eth-signature'; @@ -150,7 +150,7 @@ async function getBlockFromRollupTx( Hex, ]; - const header = Header.fromBuffer(Buffer.from(hexToBytes(decodedArgs.header))); + const header = BlockHeader.fromBuffer(Buffer.from(hexToBytes(decodedArgs.header))); const blockBody = Body.fromBuffer(Buffer.from(hexToBytes(bodyHex))); const blockNumberFromHeader = header.globalVariables.blockNumber.toBigInt(); diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts index 3d15de3fbbb..458ab231778 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts @@ -1,5 +1,5 @@ import { Body, type InBlock, L2Block, L2BlockHash, type TxEffect, type TxHash, TxReceipt } from '@aztec/circuit-types'; -import { AppendOnlyTreeSnapshot, type AztecAddress, Header, INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js'; +import { AppendOnlyTreeSnapshot, type AztecAddress, BlockHeader, INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js'; import { createDebugLogger } from '@aztec/foundation/log'; import { type AztecKVStore, type AztecMap, type AztecSingleton, type Range } from '@aztec/kv-store'; @@ -147,14 +147,14 @@ export class BlockStore { * @param limit - The number of blocks to return. * @returns The requested L2 block headers */ - *getBlockHeaders(start: number, limit: number): IterableIterator
{ + *getBlockHeaders(start: number, limit: number): IterableIterator { for (const blockStorage of this.#blocks.values(this.#computeBlockRange(start, limit))) { - yield Header.fromBuffer(blockStorage.header); + yield BlockHeader.fromBuffer(blockStorage.header); } } private getBlockFromBlockStorage(blockStorage: BlockStorage) { - const header = Header.fromBuffer(blockStorage.header); + const header = BlockHeader.fromBuffer(blockStorage.header); const archive = AppendOnlyTreeSnapshot.fromBuffer(blockStorage.archive); const blockHash = header.hash().toString(); const blockBodyBuffer = this.#blockBodies.get(blockHash); diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts index 618abf9cbfd..804f2caa03e 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts @@ -9,11 +9,11 @@ import { type TxScopedL2Log, } from '@aztec/circuit-types'; import { + type BlockHeader, type ContractClassPublic, type ContractInstanceWithAddress, type ExecutablePrivateFunctionWithMembershipProof, type Fr, - type Header, type PrivateLog, type UnconstrainedFunctionWithMembershipProof, } from '@aztec/circuits.js'; @@ -171,7 +171,7 @@ export class KVArchiverDataStore implements ArchiverDataStore { * @param limit - The number of blocks to return. * @returns The requested L2 blocks */ - getBlockHeaders(start: number, limit: number): Promise { + getBlockHeaders(start: number, limit: number): Promise { try { return Promise.resolve(Array.from(this.#blockStore.getBlockHeaders(start, limit))); } catch (err) { diff --git a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts index 5a0c7085c61..74480bc8007 100644 --- a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts @@ -16,12 +16,12 @@ import { wrapInBlock, } from '@aztec/circuit-types'; import { + type BlockHeader, type ContractClassPublic, type ContractClassPublicWithBlockNumber, type ContractInstanceWithAddress, type ExecutablePrivateFunctionWithMembershipProof, Fr, - type Header, INITIAL_L2_BLOCK_NUM, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, @@ -427,7 +427,7 @@ export class MemoryArchiverStore implements ArchiverDataStore { return Promise.resolve(this.l2Blocks.slice(fromIndex, toIndex)); } - public async getBlockHeaders(from: number, limit: number): Promise { + public async getBlockHeaders(from: number, limit: number): Promise { const blocks = await this.getBlocks(from, limit); return blocks.map(block => block.data.header); } diff --git a/yarn-project/archiver/src/test/mock_l2_block_source.ts b/yarn-project/archiver/src/test/mock_l2_block_source.ts index 86c120fcb2e..6dd2c43a8b6 100644 --- a/yarn-project/archiver/src/test/mock_l2_block_source.ts +++ b/yarn-project/archiver/src/test/mock_l2_block_source.ts @@ -8,7 +8,7 @@ import { TxStatus, } from '@aztec/circuit-types'; import { getSlotRangeForEpoch } from '@aztec/circuit-types'; -import { EthAddress, type Header } from '@aztec/circuits.js'; +import { type BlockHeader, EthAddress } from '@aztec/circuits.js'; import { DefaultL1ContractsConfig } from '@aztec/ethereum'; import { createDebugLogger } from '@aztec/foundation/log'; @@ -106,7 +106,7 @@ export class MockL2BlockSource implements L2BlockSource { ); } - getBlockHeader(number: number | 'latest'): Promise
{ + getBlockHeader(number: number | 'latest'): Promise { return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.header); } diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 87d74936a4a..9a244b42e16 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -34,13 +34,13 @@ import { } from '@aztec/circuit-types'; import { type ARCHIVE_HEIGHT, + type BlockHeader, type ContractClassPublic, type ContractDataSource, type ContractInstanceWithAddress, EthAddress, Fr, type GasFees, - type Header, INITIAL_L2_BLOCK_NUM, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT, @@ -767,7 +767,7 @@ export class AztecNodeService implements AztecNode { * Returns the currently committed block header, or the initial header if no blocks have been produced. * @returns The current committed block header. */ - public async getBlockHeader(blockNumber: L2BlockNumber = 'latest'): Promise
{ + public async getBlockHeader(blockNumber: L2BlockNumber = 'latest'): Promise { return ( (await this.getBlock(blockNumber === 'latest' ? -1 : blockNumber))?.header ?? this.worldStateSynchronizer.getCommitted().getInitialHeader() diff --git a/yarn-project/bb-prover/src/test/test_avm.ts b/yarn-project/bb-prover/src/test/test_avm.ts new file mode 100644 index 00000000000..7dd0954dfe6 --- /dev/null +++ b/yarn-project/bb-prover/src/test/test_avm.ts @@ -0,0 +1,85 @@ +import { + AztecAddress, + BlockHeader, + ContractStorageRead, + ContractStorageUpdateRequest, + Gas, + GlobalVariables, + L2ToL1Message, + LogHash, + MAX_ENQUEUED_CALLS_PER_CALL, + MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL, + MAX_L2_TO_L1_MSGS_PER_CALL, + MAX_NOTE_HASHES_PER_CALL, + MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, + MAX_NULLIFIERS_PER_CALL, + MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, + MAX_NULLIFIER_READ_REQUESTS_PER_CALL, + MAX_PUBLIC_DATA_READS_PER_CALL, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, + MAX_UNENCRYPTED_LOGS_PER_CALL, + NoteHash, + Nullifier, + PublicCircuitPublicInputs, + PublicInnerCallRequest, + ReadRequest, + RevertCode, + TreeLeafReadRequest, +} from '@aztec/circuits.js'; +import { computeVarArgsHash } from '@aztec/circuits.js/hash'; +import { padArrayEnd } from '@aztec/foundation/collection'; +import { type PublicFunctionCallResult } from '@aztec/simulator'; + +// TODO: pub somewhere more usable - copied from abstract phase manager +export function getPublicInputs(result: PublicFunctionCallResult): PublicCircuitPublicInputs { + return PublicCircuitPublicInputs.from({ + callContext: result.executionRequest.callContext, + proverAddress: AztecAddress.ZERO, + argsHash: computeVarArgsHash(result.executionRequest.args), + noteHashes: padArrayEnd(result.noteHashes, NoteHash.empty(), MAX_NOTE_HASHES_PER_CALL), + nullifiers: padArrayEnd(result.nullifiers, Nullifier.empty(), MAX_NULLIFIERS_PER_CALL), + l2ToL1Msgs: padArrayEnd(result.l2ToL1Messages, L2ToL1Message.empty(), MAX_L2_TO_L1_MSGS_PER_CALL), + startSideEffectCounter: result.startSideEffectCounter, + endSideEffectCounter: result.endSideEffectCounter, + returnsHash: computeVarArgsHash(result.returnValues), + noteHashReadRequests: padArrayEnd( + result.noteHashReadRequests, + TreeLeafReadRequest.empty(), + MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, + ), + nullifierReadRequests: padArrayEnd( + result.nullifierReadRequests, + ReadRequest.empty(), + MAX_NULLIFIER_READ_REQUESTS_PER_CALL, + ), + nullifierNonExistentReadRequests: padArrayEnd( + result.nullifierNonExistentReadRequests, + ReadRequest.empty(), + MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, + ), + l1ToL2MsgReadRequests: padArrayEnd( + result.l1ToL2MsgReadRequests, + TreeLeafReadRequest.empty(), + MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL, + ), + contractStorageReads: padArrayEnd( + result.contractStorageReads, + ContractStorageRead.empty(), + MAX_PUBLIC_DATA_READS_PER_CALL, + ), + contractStorageUpdateRequests: padArrayEnd( + result.contractStorageUpdateRequests, + ContractStorageUpdateRequest.empty(), + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, + ), + publicCallRequests: padArrayEnd([], PublicInnerCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_CALL), + unencryptedLogsHashes: padArrayEnd(result.unencryptedLogsHashes, LogHash.empty(), MAX_UNENCRYPTED_LOGS_PER_CALL), + historicalHeader: BlockHeader.empty(), + globalVariables: GlobalVariables.empty(), + startGasLeft: Gas.from(result.startGasLeft), + endGasLeft: Gas.from(result.endGasLeft), + transactionFee: result.transactionFee, + // TODO(@just-mitch): need better mapping from simulator to revert code. + revertCode: result.reverted ? RevertCode.APP_LOGIC_REVERTED : RevertCode.OK, + }); +} diff --git a/yarn-project/circuit-types/src/interfaces/archiver.test.ts b/yarn-project/circuit-types/src/interfaces/archiver.test.ts index c97893fc897..04aa0e0341d 100644 --- a/yarn-project/circuit-types/src/interfaces/archiver.test.ts +++ b/yarn-project/circuit-types/src/interfaces/archiver.test.ts @@ -1,11 +1,11 @@ import { AztecAddress, + BlockHeader, type ContractClassPublic, type ContractInstanceWithAddress, EthAddress, Fr, FunctionSelector, - Header, PrivateLog, type PublicFunction, PublicKeys, @@ -92,7 +92,7 @@ describe('ArchiverApiSchema', () => { it('getBlockHeader', async () => { const result = await context.client.getBlockHeader(1); - expect(result).toBeInstanceOf(Header); + expect(result).toBeInstanceOf(BlockHeader); }); it('getBlocks', async () => { @@ -277,8 +277,8 @@ class MockArchiver implements ArchiverApi { getBlock(number: number): Promise { return Promise.resolve(L2Block.random(number)); } - getBlockHeader(_number: number | 'latest'): Promise
{ - return Promise.resolve(Header.empty()); + getBlockHeader(_number: number | 'latest'): Promise { + return Promise.resolve(BlockHeader.empty()); } getBlocks(from: number, _limit: number, _proven?: boolean | undefined): Promise { return Promise.resolve([L2Block.random(from)]); diff --git a/yarn-project/circuit-types/src/interfaces/archiver.ts b/yarn-project/circuit-types/src/interfaces/archiver.ts index b032efc6174..bf8ace98b60 100644 --- a/yarn-project/circuit-types/src/interfaces/archiver.ts +++ b/yarn-project/circuit-types/src/interfaces/archiver.ts @@ -1,8 +1,8 @@ import { + BlockHeader, ContractClassPublicSchema, type ContractDataSource, ContractInstanceWithAddressSchema, - Header, PrivateLog, PublicFunctionSchema, } from '@aztec/circuits.js'; @@ -38,7 +38,7 @@ export const ArchiverApiSchema: ApiSchemaFor = { getBlockHeader: z .function() .args(z.union([schemas.Integer, z.literal('latest')])) - .returns(Header.schema.optional()), + .returns(BlockHeader.schema.optional()), getBlocks: z .function() .args(schemas.Integer, schemas.Integer, optional(z.boolean())) diff --git a/yarn-project/circuit-types/src/interfaces/aztec-node.test.ts b/yarn-project/circuit-types/src/interfaces/aztec-node.test.ts index 30d729f4750..3bb4ee18185 100644 --- a/yarn-project/circuit-types/src/interfaces/aztec-node.test.ts +++ b/yarn-project/circuit-types/src/interfaces/aztec-node.test.ts @@ -1,12 +1,12 @@ import { ARCHIVE_HEIGHT, AztecAddress, + BlockHeader, type ContractClassPublic, type ContractInstanceWithAddress, EthAddress, Fr, GasFees, - Header, L1_TO_L2_MSG_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT, NULLIFIER_TREE_HEIGHT, @@ -284,7 +284,7 @@ describe('AztecNodeApiSchema', () => { it('getBlockHeader', async () => { const response = await context.client.getBlockHeader(); - expect(response).toBeInstanceOf(Header); + expect(response).toBeInstanceOf(BlockHeader); }); it('simulatePublicCalls', async () => { @@ -553,8 +553,8 @@ class MockAztecNode implements AztecNode { expect(slot).toBeInstanceOf(Fr); return Promise.resolve(Fr.random()); } - getBlockHeader(_blockNumber?: number | 'latest' | undefined): Promise
{ - return Promise.resolve(Header.empty()); + getBlockHeader(_blockNumber?: number | 'latest' | undefined): Promise { + return Promise.resolve(BlockHeader.empty()); } simulatePublicCalls(tx: Tx): Promise { expect(tx).toBeInstanceOf(Tx); diff --git a/yarn-project/circuit-types/src/interfaces/aztec-node.ts b/yarn-project/circuit-types/src/interfaces/aztec-node.ts index 96ac1a1f3ed..427ff8d88ac 100644 --- a/yarn-project/circuit-types/src/interfaces/aztec-node.ts +++ b/yarn-project/circuit-types/src/interfaces/aztec-node.ts @@ -1,11 +1,11 @@ import { ARCHIVE_HEIGHT, + BlockHeader, type ContractClassPublic, ContractClassPublicSchema, type ContractInstanceWithAddress, ContractInstanceWithAddressSchema, GasFees, - Header, L1_TO_L2_MSG_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT, NULLIFIER_TREE_HEIGHT, @@ -379,7 +379,7 @@ export interface AztecNode * Returns the currently committed block header. * @returns The current committed block header. */ - getBlockHeader(blockNumber?: L2BlockNumber): Promise
; + getBlockHeader(blockNumber?: L2BlockNumber): Promise; /** * Simulates the public part of a transaction with the current state. @@ -560,7 +560,7 @@ export const AztecNodeApiSchema: ApiSchemaFor = { getPublicStorageAt: z.function().args(schemas.AztecAddress, schemas.Fr, L2BlockNumberSchema).returns(schemas.Fr), - getBlockHeader: z.function().args(optional(L2BlockNumberSchema)).returns(Header.schema), + getBlockHeader: z.function().args(optional(L2BlockNumberSchema)).returns(BlockHeader.schema), simulatePublicCalls: z.function().args(Tx.schema).returns(PublicSimulationOutput.schema), diff --git a/yarn-project/circuit-types/src/interfaces/block-builder.ts b/yarn-project/circuit-types/src/interfaces/block-builder.ts index bad2bcda99b..ecb0103ff1f 100644 --- a/yarn-project/circuit-types/src/interfaces/block-builder.ts +++ b/yarn-project/circuit-types/src/interfaces/block-builder.ts @@ -1,4 +1,4 @@ -import { type Fr, type GlobalVariables, type Header } from '@aztec/circuits.js'; +import { type BlockHeader, type Fr, type GlobalVariables } from '@aztec/circuits.js'; import { type L2Block } from '../l2_block.js'; import { type ProcessedTx } from '../tx/processed_tx.js'; @@ -24,5 +24,5 @@ export interface BlockBuilder extends ProcessedTxHandler { * Pads the block with empty txs if it hasn't reached the declared number of txs. * Assembles the block and updates the archive tree. */ - setBlockCompleted(expectedBlockHeader?: Header): Promise; + setBlockCompleted(expectedBlockHeader?: BlockHeader): Promise; } diff --git a/yarn-project/circuit-types/src/interfaces/epoch-prover.ts b/yarn-project/circuit-types/src/interfaces/epoch-prover.ts index 16641c23e67..4774741ebf1 100644 --- a/yarn-project/circuit-types/src/interfaces/epoch-prover.ts +++ b/yarn-project/circuit-types/src/interfaces/epoch-prover.ts @@ -1,4 +1,4 @@ -import { type Fr, type Header, type Proof, type RootRollupPublicInputs } from '@aztec/circuits.js'; +import { type BlockHeader, type Fr, type Proof, type RootRollupPublicInputs } from '@aztec/circuits.js'; import { type L2Block } from '../l2_block.js'; import { type BlockBuilder } from './block-builder.js'; @@ -14,7 +14,7 @@ export interface EpochProver extends Omit { startNewEpoch(epochNumber: number, firstBlockNumber: number, totalNumBlocks: number): void; /** Pads the block with empty txs if it hasn't reached the declared number of txs. */ - setBlockCompleted(blockNumber: number, expectedBlockHeader?: Header): Promise; + setBlockCompleted(blockNumber: number, expectedBlockHeader?: BlockHeader): Promise; /** Pads the epoch with empty block roots if needed and blocks until proven. Throws if proving has failed. */ finaliseEpoch(): Promise<{ publicInputs: RootRollupPublicInputs; proof: Proof }>; diff --git a/yarn-project/circuit-types/src/interfaces/merkle_tree_operations.ts b/yarn-project/circuit-types/src/interfaces/merkle_tree_operations.ts index 9017c1a6a84..60f72e0e167 100644 --- a/yarn-project/circuit-types/src/interfaces/merkle_tree_operations.ts +++ b/yarn-project/circuit-types/src/interfaces/merkle_tree_operations.ts @@ -1,6 +1,6 @@ import { + type BlockHeader, type Fr, - type Header, type NullifierLeaf, type PublicDataTreeLeaf, type StateReference, @@ -133,7 +133,7 @@ export interface MerkleTreeReadOperations { /** * Gets the initial header. */ - getInitialHeader(): Header; + getInitialHeader(): BlockHeader; /** * Gets sibling path for a leaf. @@ -224,7 +224,7 @@ export interface MerkleTreeWriteOperations extends MerkleTreeReadOperations { * This includes all of the current roots of all of the data trees and the current blocks global vars. * @param header - The header to insert into the archive. */ - updateArchive(header: Header): Promise; + updateArchive(header: BlockHeader): Promise; /** * Batch insert multiple leaves into the tree. diff --git a/yarn-project/circuit-types/src/l2_block.ts b/yarn-project/circuit-types/src/l2_block.ts index 09d73fe4dd2..c6d4f570595 100644 --- a/yarn-project/circuit-types/src/l2_block.ts +++ b/yarn-project/circuit-types/src/l2_block.ts @@ -1,4 +1,4 @@ -import { AppendOnlyTreeSnapshot, Header } from '@aztec/circuits.js'; +import { AppendOnlyTreeSnapshot, BlockHeader } from '@aztec/circuits.js'; import { sha256, sha256ToField } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; @@ -17,7 +17,7 @@ export class L2Block { /** Snapshot of archive tree after the block is applied. */ public archive: AppendOnlyTreeSnapshot, /** L2 block header. */ - public header: Header, + public header: BlockHeader, /** L2 block body. */ public body: Body, ) {} @@ -26,7 +26,7 @@ export class L2Block { return z .object({ archive: AppendOnlyTreeSnapshot.schema, - header: Header.schema, + header: BlockHeader.schema, body: Body.schema, }) .transform(({ archive, header, body }) => new L2Block(archive, header, body)); @@ -38,7 +38,7 @@ export class L2Block { */ static fromBuffer(buf: Buffer | BufferReader) { const reader = BufferReader.asReader(buf); - const header = reader.readObject(Header); + const header = reader.readObject(BlockHeader); const archive = reader.readObject(AppendOnlyTreeSnapshot); const body = reader.readObject(Body); @@ -103,7 +103,7 @@ export class L2Block { * @returns The L2 block. */ static empty(): L2Block { - return new L2Block(AppendOnlyTreeSnapshot.zero(), Header.empty(), Body.empty()); + return new L2Block(AppendOnlyTreeSnapshot.zero(), BlockHeader.empty(), Body.empty()); } get number(): number { diff --git a/yarn-project/circuit-types/src/l2_block_code_to_purge.ts b/yarn-project/circuit-types/src/l2_block_code_to_purge.ts index 64e2e06db9e..70d2b3e8306 100644 --- a/yarn-project/circuit-types/src/l2_block_code_to_purge.ts +++ b/yarn-project/circuit-types/src/l2_block_code_to_purge.ts @@ -1,12 +1,12 @@ import { AppendOnlyTreeSnapshot, AztecAddress, + BlockHeader, ContentCommitment, EthAddress, Fr, GasFees, GlobalVariables, - Header, NUM_BYTES_PER_SHA256, PartialStateReference, StateReference, @@ -23,8 +23,8 @@ export function makeHeader( slotNumber: number | undefined = undefined, txsEffectsHash: Buffer | undefined = undefined, inHash: Buffer | undefined = undefined, -): Header { - return new Header( +): BlockHeader { + return new BlockHeader( makeAppendOnlyTreeSnapshot(seed + 0x100), makeContentCommitment(seed + 0x200, txsEffectsHash, inHash), makeStateReference(seed + 0x600), diff --git a/yarn-project/circuit-types/src/l2_block_downloader/l2_block_stream.test.ts b/yarn-project/circuit-types/src/l2_block_downloader/l2_block_stream.test.ts index bb8eaafc83a..ae25c222d5b 100644 --- a/yarn-project/circuit-types/src/l2_block_downloader/l2_block_stream.test.ts +++ b/yarn-project/circuit-types/src/l2_block_downloader/l2_block_stream.test.ts @@ -1,4 +1,4 @@ -import { Fr, type Header } from '@aztec/circuits.js'; +import { type BlockHeader, Fr } from '@aztec/circuits.js'; import { compactArray } from '@aztec/foundation/collection'; import { type MockProxy, mock } from 'jest-mock-extended'; @@ -42,7 +42,7 @@ describe('L2BlockStream', () => { const makeBlock = (number: number) => ({ number } as L2Block); - const makeHeader = (number: number) => mock
({ hash: () => new Fr(number) } as Header); + const makeHeader = (number: number) => mock({ hash: () => new Fr(number) } as BlockHeader); const setRemoteTips = (latest_: number, proven?: number, finalized?: number) => { proven = proven ?? 0; diff --git a/yarn-project/circuit-types/src/l2_block_source.ts b/yarn-project/circuit-types/src/l2_block_source.ts index 6f749b28189..5a62f159b38 100644 --- a/yarn-project/circuit-types/src/l2_block_source.ts +++ b/yarn-project/circuit-types/src/l2_block_source.ts @@ -1,4 +1,4 @@ -import { type EthAddress, type Header } from '@aztec/circuits.js'; +import { type BlockHeader, type EthAddress } from '@aztec/circuits.js'; import { z } from 'zod'; @@ -54,7 +54,7 @@ export interface L2BlockSource { * @param number - The block number to return or 'latest' for the most recent one. * @returns The requested L2 block header. */ - getBlockHeader(number: number | 'latest'): Promise
; + getBlockHeader(number: number | 'latest'): Promise; /** * Gets up to `limit` amount of L2 blocks starting from `from`. diff --git a/yarn-project/circuit-types/src/p2p/consensus_payload.ts b/yarn-project/circuit-types/src/p2p/consensus_payload.ts index 3c4d5e946b0..a043a8d2010 100644 --- a/yarn-project/circuit-types/src/p2p/consensus_payload.ts +++ b/yarn-project/circuit-types/src/p2p/consensus_payload.ts @@ -1,4 +1,4 @@ -import { Header } from '@aztec/circuits.js'; +import { BlockHeader } from '@aztec/circuits.js'; import { Fr } from '@aztec/foundation/fields'; import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { hexToBuffer } from '@aztec/foundation/string'; @@ -14,7 +14,7 @@ export class ConsensusPayload implements Signable { constructor( /** The block header the attestation is made over */ - public readonly header: Header, + public readonly header: BlockHeader, // TODO(https://github.com/AztecProtocol/aztec-packages/pull/7727#discussion_r1713670830): temporary public readonly archive: Fr, /** The sequence of transactions in the block */ @@ -51,7 +51,7 @@ export class ConsensusPayload implements Signable { static fromBuffer(buf: Buffer | BufferReader): ConsensusPayload { const reader = BufferReader.asReader(buf); return new ConsensusPayload( - reader.readObject(Header), + reader.readObject(BlockHeader), reader.readObject(Fr), reader.readArray(reader.readNumber(), TxHash), ); @@ -62,7 +62,7 @@ export class ConsensusPayload implements Signable { } static empty(): ConsensusPayload { - return new ConsensusPayload(Header.empty(), Fr.ZERO, []); + return new ConsensusPayload(BlockHeader.empty(), Fr.ZERO, []); } /** diff --git a/yarn-project/circuit-types/src/p2p/mocks.ts b/yarn-project/circuit-types/src/p2p/mocks.ts index 821d4fd3b4b..1e4e99ac042 100644 --- a/yarn-project/circuit-types/src/p2p/mocks.ts +++ b/yarn-project/circuit-types/src/p2p/mocks.ts @@ -1,4 +1,4 @@ -import { type Header } from '@aztec/circuits.js'; +import { type BlockHeader } from '@aztec/circuits.js'; import { makeHeader } from '@aztec/circuits.js/testing'; import { Secp256k1Signer } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; @@ -11,7 +11,7 @@ import { SignatureDomainSeperator, getHashedSignaturePayloadEthSignedMessage } f export interface MakeConsensusPayloadOptions { signer?: Secp256k1Signer; - header?: Header; + header?: BlockHeader; archive?: Fr; txHashes?: TxHash[]; } diff --git a/yarn-project/circuit-types/src/test/factories.ts b/yarn-project/circuit-types/src/test/factories.ts index 72e2c318edf..6360135750a 100644 --- a/yarn-project/circuit-types/src/test/factories.ts +++ b/yarn-project/circuit-types/src/test/factories.ts @@ -2,6 +2,7 @@ import { AvmCircuitInputs, AvmCircuitPublicInputs, AvmExecutionHints, + type BlockHeader, FIXED_DA_GAS, FIXED_L2_GAS, Fr, @@ -9,7 +10,6 @@ import { GasFees, GasSettings, GlobalVariables, - type Header, MAX_NULLIFIERS_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicCircuitPublicInputs, @@ -42,7 +42,7 @@ export function makeBloatedProcessedTx({ privateOnly = false, }: { seed?: number; - header?: Header; + header?: BlockHeader; db?: MerkleTreeReadOperations; chainId?: Fr; version?: Fr; diff --git a/yarn-project/circuit-types/src/tx/processed_tx.ts b/yarn-project/circuit-types/src/tx/processed_tx.ts index b52006846b2..6ae2779be14 100644 --- a/yarn-project/circuit-types/src/tx/processed_tx.ts +++ b/yarn-project/circuit-types/src/tx/processed_tx.ts @@ -1,10 +1,10 @@ import { + type BlockHeader, ClientIvcProof, CombinedConstantData, Fr, Gas, type GlobalVariables, - type Header, PrivateKernelTailCircuitPublicInputs, type PublicDataWrite, RevertCode, @@ -86,7 +86,7 @@ export type FailedTx = { * @returns A processed empty tx. */ export function makeEmptyProcessedTx( - header: Header, + header: BlockHeader, chainId: Fr, version: Fr, vkTreeRoot: Fr, diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 8015d4dbc7c..a0ff9ef18b1 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -177,7 +177,7 @@ export const TX_CONTEXT_LENGTH = 8; export const TX_REQUEST_LENGTH = 12; export const TOTAL_FEES_LENGTH = 1; export const TOTAL_MANA_USED_LENGTH = 1; -export const HEADER_LENGTH = 25; +export const BLOCK_HEADER_LENGTH = 25; export const PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 739; export const PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 867; export const PRIVATE_CONTEXT_INPUTS_LENGTH = 38; diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/block_header.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/block_header.test.ts.snap new file mode 100644 index 00000000000..fac31063f85 --- /dev/null +++ b/yarn-project/circuits.js/src/structs/__snapshots__/block_header.test.ts.snap @@ -0,0 +1,5 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`BlockHeader computes empty hash 1`] = `Fr<0x28e48e620bc00817609b5fc765bc74864561f25a3c941b33e5ee05266b752839>`; + +exports[`BlockHeader computes hash 1`] = `Fr<0x2352a779093c231d53586b8c09d3d63033327f5f80029f007fe9deedc67c4be3>`; diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/header.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/header.test.ts.snap deleted file mode 100644 index 175c31be182..00000000000 --- a/yarn-project/circuits.js/src/structs/__snapshots__/header.test.ts.snap +++ /dev/null @@ -1,5 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Header computes empty hash 1`] = `Fr<0x28e48e620bc00817609b5fc765bc74864561f25a3c941b33e5ee05266b752839>`; - -exports[`Header computes hash 1`] = `Fr<0x2352a779093c231d53586b8c09d3d63033327f5f80029f007fe9deedc67c4be3>`; diff --git a/yarn-project/circuits.js/src/structs/header.test.ts b/yarn-project/circuits.js/src/structs/block_header.test.ts similarity index 77% rename from yarn-project/circuits.js/src/structs/header.test.ts rename to yarn-project/circuits.js/src/structs/block_header.test.ts index 352acf4c681..053bf0d2639 100644 --- a/yarn-project/circuits.js/src/structs/header.test.ts +++ b/yarn-project/circuits.js/src/structs/block_header.test.ts @@ -1,12 +1,12 @@ import { randomInt } from '@aztec/foundation/crypto'; import { setupCustomSnapshotSerializers, updateInlineTestData } from '@aztec/foundation/testing'; -import { HEADER_LENGTH } from '../constants.gen.js'; +import { BLOCK_HEADER_LENGTH } from '../constants.gen.js'; import { makeHeader } from '../tests/factories.js'; -import { Header } from './header.js'; +import { BlockHeader } from './block_header.js'; -describe('Header', () => { - let header: Header; +describe('BlockHeader', () => { + let header: BlockHeader; beforeAll(() => { setupCustomSnapshotSerializers(expect); @@ -15,13 +15,13 @@ describe('Header', () => { it('serializes to buffer and deserializes it back', () => { const buffer = header.toBuffer(); - const res = Header.fromBuffer(buffer); + const res = BlockHeader.fromBuffer(buffer); expect(res).toEqual(header); }); it('serializes to field array and deserializes it back', () => { const fieldArray = header.toFields(); - const res = Header.fromFields(fieldArray); + const res = BlockHeader.fromFields(fieldArray); expect(res).toEqual(header); }); @@ -34,11 +34,11 @@ describe('Header', () => { it('number of fields matches constant', () => { const fields = header.toFields(); - expect(fields.length).toBe(HEADER_LENGTH); + expect(fields.length).toBe(BLOCK_HEADER_LENGTH); }); it('computes empty hash', () => { - const header = Header.empty(); + const header = BlockHeader.empty(); const hash = header.hash(); expect(hash).toMatchSnapshot(); diff --git a/yarn-project/circuits.js/src/structs/header.ts b/yarn-project/circuits.js/src/structs/block_header.ts similarity index 83% rename from yarn-project/circuits.js/src/structs/header.ts rename to yarn-project/circuits.js/src/structs/block_header.ts index 21be70c0717..8d335e7a5de 100644 --- a/yarn-project/circuits.js/src/structs/header.ts +++ b/yarn-project/circuits.js/src/structs/block_header.ts @@ -8,14 +8,14 @@ import { type FieldsOf } from '@aztec/foundation/types'; import { inspect } from 'util'; import { z } from 'zod'; -import { GeneratorIndex, HEADER_LENGTH } from '../constants.gen.js'; +import { BLOCK_HEADER_LENGTH, GeneratorIndex } from '../constants.gen.js'; import { ContentCommitment } from './content_commitment.js'; import { GlobalVariables } from './global_variables.js'; import { AppendOnlyTreeSnapshot } from './rollup/append_only_tree_snapshot.js'; import { StateReference } from './state_reference.js'; /** A header of an L2 block. */ -export class Header { +export class BlockHeader { constructor( /** Snapshot of archive before the block is applied. */ public lastArchive: AppendOnlyTreeSnapshot, @@ -41,10 +41,10 @@ export class Header { totalFees: schemas.Fr, totalManaUsed: schemas.Fr, }) - .transform(Header.from); + .transform(BlockHeader.from); } - static getFields(fields: FieldsOf
) { + static getFields(fields: FieldsOf) { // Note: The order here must match the order in the HeaderLib solidity library. return [ fields.lastArchive, @@ -56,8 +56,8 @@ export class Header { ] as const; } - static from(fields: FieldsOf
) { - return new Header(...Header.getFields(fields)); + static from(fields: FieldsOf) { + return new BlockHeader(...BlockHeader.getFields(fields)); } getSize() { @@ -72,25 +72,25 @@ export class Header { } toBuffer() { - return serializeToBuffer(...Header.getFields(this)); + return serializeToBuffer(...BlockHeader.getFields(this)); } toFields(): Fr[] { - const fields = serializeToFields(...Header.getFields(this)); - if (fields.length !== HEADER_LENGTH) { - throw new Error(`Invalid number of fields for Header. Expected ${HEADER_LENGTH}, got ${fields.length}`); + const fields = serializeToFields(...BlockHeader.getFields(this)); + if (fields.length !== BLOCK_HEADER_LENGTH) { + throw new Error(`Invalid number of fields for Header. Expected ${BLOCK_HEADER_LENGTH}, got ${fields.length}`); } return fields; } - clone(): Header { - return Header.fromBuffer(this.toBuffer()); + clone(): BlockHeader { + return BlockHeader.fromBuffer(this.toBuffer()); } - static fromBuffer(buffer: Buffer | BufferReader): Header { + static fromBuffer(buffer: Buffer | BufferReader): BlockHeader { const reader = BufferReader.asReader(buffer); - return new Header( + return new BlockHeader( reader.readObject(AppendOnlyTreeSnapshot), reader.readObject(ContentCommitment), reader.readObject(StateReference), @@ -100,10 +100,10 @@ export class Header { ); } - static fromFields(fields: Fr[] | FieldReader): Header { + static fromFields(fields: Fr[] | FieldReader): BlockHeader { const reader = FieldReader.asReader(fields); - return new Header( + return new BlockHeader( AppendOnlyTreeSnapshot.fromFields(reader), ContentCommitment.fromFields(reader), StateReference.fromFields(reader), @@ -113,8 +113,8 @@ export class Header { ); } - static empty(fields: Partial> = {}): Header { - return Header.from({ + static empty(fields: Partial> = {}): BlockHeader { + return BlockHeader.from({ lastArchive: AppendOnlyTreeSnapshot.zero(), contentCommitment: ContentCommitment.empty(), state: StateReference.empty(), @@ -144,8 +144,8 @@ export class Header { return bufferToHex(this.toBuffer()); } - static fromString(str: string): Header { - return Header.fromBuffer(hexToBuffer(str)); + static fromString(str: string): BlockHeader { + return BlockHeader.fromBuffer(hexToBuffer(str)); } hash(): Fr { diff --git a/yarn-project/circuits.js/src/structs/context/private_context_inputs.ts b/yarn-project/circuits.js/src/structs/context/private_context_inputs.ts index f930eabf3ba..4f52855805b 100644 --- a/yarn-project/circuits.js/src/structs/context/private_context_inputs.ts +++ b/yarn-project/circuits.js/src/structs/context/private_context_inputs.ts @@ -1,19 +1,19 @@ import { serializeToFields } from '@aztec/foundation/serialize'; +import { BlockHeader } from '../block_header.js'; import { CallContext } from '../call_context.js'; -import { Header } from '../header.js'; import { TxContext } from '../tx_context.js'; export class PrivateContextInputs { constructor( public callContext: CallContext, - public historicalHeader: Header, + public historicalHeader: BlockHeader, public txContext: TxContext, public startSideEffectCounter: number, ) {} public static empty(): PrivateContextInputs { - return new PrivateContextInputs(CallContext.empty(), Header.empty(), TxContext.empty(), 0); + return new PrivateContextInputs(CallContext.empty(), BlockHeader.empty(), TxContext.empty(), 0); } public toFields() { diff --git a/yarn-project/circuits.js/src/structs/index.ts b/yarn-project/circuits.js/src/structs/index.ts index 7f76ff4a96d..4959a0fb048 100644 --- a/yarn-project/circuits.js/src/structs/index.ts +++ b/yarn-project/circuits.js/src/structs/index.ts @@ -14,7 +14,7 @@ export * from './gas.js'; export * from './gas_fees.js'; export * from './gas_settings.js'; export * from './global_variables.js'; -export * from './header.js'; +export * from './block_header.js'; export * from './tagging_secret.js'; export * from './kernel/combined_accumulated_data.js'; export * from './kernel/combined_constant_data.js'; diff --git a/yarn-project/circuits.js/src/structs/kernel/combined_constant_data.ts b/yarn-project/circuits.js/src/structs/kernel/combined_constant_data.ts index 084873c7b9b..e676c34b7a9 100644 --- a/yarn-project/circuits.js/src/structs/kernel/combined_constant_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/combined_constant_data.ts @@ -5,8 +5,8 @@ import { type FieldsOf } from '@aztec/foundation/types'; import { z } from 'zod'; +import { BlockHeader } from '../block_header.js'; import { GlobalVariables } from '../global_variables.js'; -import { Header } from '../header.js'; import { TxContext } from '../tx_context.js'; import { type TxConstantData } from './tx_constant_data.js'; @@ -16,7 +16,7 @@ import { type TxConstantData } from './tx_constant_data.js'; export class CombinedConstantData { constructor( /** Header of a block whose state is used during execution (not the block the transaction is included in). */ - public historicalHeader: Header, + public historicalHeader: BlockHeader, /** * Context of the transaction. * @@ -51,7 +51,7 @@ export class CombinedConstantData { static get schema() { return z .object({ - historicalHeader: Header.schema, + historicalHeader: BlockHeader.schema, txContext: TxContext.schema, vkTreeRoot: schemas.Fr, protocolContractTreeRoot: schemas.Fr, @@ -103,7 +103,7 @@ export class CombinedConstantData { static fromBuffer(buffer: Buffer | BufferReader): CombinedConstantData { const reader = BufferReader.asReader(buffer); return new CombinedConstantData( - reader.readObject(Header), + reader.readObject(BlockHeader), reader.readObject(TxContext), Fr.fromBuffer(reader), Fr.fromBuffer(reader), @@ -114,7 +114,7 @@ export class CombinedConstantData { static fromFields(fields: Fr[] | FieldReader): CombinedConstantData { const reader = FieldReader.asReader(fields); return new CombinedConstantData( - reader.readObject(Header), + reader.readObject(BlockHeader), reader.readObject(TxContext), reader.readField(), reader.readField(), @@ -123,6 +123,6 @@ export class CombinedConstantData { } static empty() { - return new CombinedConstantData(Header.empty(), TxContext.empty(), Fr.ZERO, Fr.ZERO, GlobalVariables.empty()); + return new CombinedConstantData(BlockHeader.empty(), TxContext.empty(), Fr.ZERO, Fr.ZERO, GlobalVariables.empty()); } } diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_empty_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_empty_inputs.ts index 9fe7957baa0..ad8e7157259 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_empty_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_empty_inputs.ts @@ -5,13 +5,13 @@ import { bufferToHex, hexToBuffer } from '@aztec/foundation/string'; import { type FieldsOf } from '@aztec/foundation/types'; import { RECURSIVE_PROOF_LENGTH } from '../../constants.gen.js'; -import { Header } from '../header.js'; +import { BlockHeader } from '../block_header.js'; import { RecursiveProof } from '../recursive_proof.js'; import { VerificationKeyAsFields } from '../verification_key.js'; export class PrivateKernelEmptyInputData { constructor( - public readonly header: Header, + public readonly header: BlockHeader, public readonly chainId: Fr, public readonly version: Fr, public readonly vkTreeRoot: Fr, @@ -29,7 +29,7 @@ export class PrivateKernelEmptyInputData { static fromBuffer(buf: Buffer) { const reader = BufferReader.asReader(buf); return new PrivateKernelEmptyInputData( - reader.readObject(Header), + reader.readObject(BlockHeader), reader.readObject(Fr), reader.readObject(Fr), reader.readObject(Fr), @@ -65,7 +65,7 @@ export class PrivateKernelEmptyInputData { export class PrivateKernelEmptyInputs { constructor( public readonly emptyNested: EmptyNestedData, - public readonly header: Header, + public readonly header: BlockHeader, public readonly chainId: Fr, public readonly version: Fr, public readonly vkTreeRoot: Fr, @@ -98,7 +98,7 @@ export class PrivateKernelEmptyInputs { const reader = BufferReader.asReader(buf); return new PrivateKernelEmptyInputs( reader.readObject(EmptyNestedData), - reader.readObject(Header), + reader.readObject(BlockHeader), reader.readObject(Fr), reader.readObject(Fr), reader.readObject(Fr), diff --git a/yarn-project/circuits.js/src/structs/kernel/tx_constant_data.ts b/yarn-project/circuits.js/src/structs/kernel/tx_constant_data.ts index 84e852be92c..67549544e4a 100644 --- a/yarn-project/circuits.js/src/structs/kernel/tx_constant_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/tx_constant_data.ts @@ -2,7 +2,7 @@ import { Fr } from '@aztec/foundation/fields'; import { BufferReader, FieldReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { type FieldsOf } from '@aztec/foundation/types'; -import { Header } from '../header.js'; +import { BlockHeader } from '../block_header.js'; import { TxContext } from '../tx_context.js'; /** @@ -11,7 +11,7 @@ import { TxContext } from '../tx_context.js'; export class TxConstantData { constructor( /** Header of a block whose state is used during execution (not the block the transaction is included in). */ - public historicalHeader: Header, + public historicalHeader: BlockHeader, /** * Context of the transaction. * @@ -42,7 +42,7 @@ export class TxConstantData { static fromFields(fields: Fr[] | FieldReader): TxConstantData { const reader = FieldReader.asReader(fields); return new TxConstantData( - reader.readObject(Header), + reader.readObject(BlockHeader), reader.readObject(TxContext), reader.readField(), reader.readField(), @@ -52,7 +52,7 @@ export class TxConstantData { static fromBuffer(buffer: Buffer | BufferReader): TxConstantData { const reader = BufferReader.asReader(buffer); return new TxConstantData( - reader.readObject(Header), + reader.readObject(BlockHeader), reader.readObject(TxContext), Fr.fromBuffer(reader), Fr.fromBuffer(reader), @@ -64,7 +64,7 @@ export class TxConstantData { } static empty() { - return new TxConstantData(Header.empty(), TxContext.empty(), Fr.ZERO, Fr.ZERO); + return new TxConstantData(BlockHeader.empty(), TxContext.empty(), Fr.ZERO, Fr.ZERO); } getSize() { diff --git a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts index c6de783a93a..94c0041a925 100644 --- a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts @@ -23,7 +23,7 @@ import { MAX_PRIVATE_LOGS_PER_CALL, PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH, } from '../constants.gen.js'; -import { Header } from '../structs/header.js'; +import { BlockHeader } from '../structs/block_header.js'; import { isEmptyArray } from '../utils/index.js'; import { CallContext } from './call_context.js'; import { KeyValidationRequestAndGenerator } from './key_validation_request_and_generator.js'; @@ -126,7 +126,7 @@ export class PrivateCircuitPublicInputs { /** * Header of a block whose state is used during private execution (not the block the transaction is included in). */ - public historicalHeader: Header, + public historicalHeader: BlockHeader, /** * Transaction context. * @@ -173,7 +173,7 @@ export class PrivateCircuitPublicInputs { reader.readArray(MAX_CONTRACT_CLASS_LOGS_PER_CALL, LogHash), reader.readObject(Fr), reader.readObject(Fr), - reader.readObject(Header), + reader.readObject(BlockHeader), reader.readObject(TxContext), ); } @@ -200,7 +200,7 @@ export class PrivateCircuitPublicInputs { reader.readArray(MAX_CONTRACT_CLASS_LOGS_PER_CALL, LogHash), reader.readField(), reader.readField(), - reader.readObject(Header), + reader.readObject(BlockHeader), reader.readObject(TxContext), ); } @@ -230,7 +230,7 @@ export class PrivateCircuitPublicInputs { makeTuple(MAX_CONTRACT_CLASS_LOGS_PER_CALL, LogHash.empty), Fr.ZERO, Fr.ZERO, - Header.empty(), + BlockHeader.empty(), TxContext.empty(), ); } diff --git a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts index 46437e0da40..9834e2f4cb9 100644 --- a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts @@ -27,12 +27,12 @@ import { PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH, } from '../constants.gen.js'; import { isEmptyArray } from '../utils/index.js'; +import { BlockHeader } from './block_header.js'; import { CallContext } from './call_context.js'; import { ContractStorageRead } from './contract_storage_read.js'; import { ContractStorageUpdateRequest } from './contract_storage_update_request.js'; import { Gas } from './gas.js'; import { GlobalVariables } from './global_variables.js'; -import { Header } from './header.js'; import { L2ToL1Message } from './l2_to_l1_message.js'; import { LogHash } from './log_hash.js'; import { NoteHash } from './note_hash.js'; @@ -121,7 +121,7 @@ export class PublicCircuitPublicInputs { * Header of a block whose state is used during public execution. Set by sequencer to be a header of a block * previous to the one in which the tx is included. */ - public historicalHeader: Header, + public historicalHeader: BlockHeader, /** Global variables for the block. */ public globalVariables: GlobalVariables, /** @@ -175,7 +175,7 @@ export class PublicCircuitPublicInputs { Fr.ZERO, Fr.ZERO, makeTuple(MAX_UNENCRYPTED_LOGS_PER_CALL, LogHash.empty), - Header.empty(), + BlockHeader.empty(), GlobalVariables.empty(), AztecAddress.ZERO, RevertCode.OK, @@ -287,7 +287,7 @@ export class PublicCircuitPublicInputs { reader.readObject(Fr), reader.readObject(Fr), reader.readArray(MAX_UNENCRYPTED_LOGS_PER_CALL, LogHash), - reader.readObject(Header), + reader.readObject(BlockHeader), reader.readObject(GlobalVariables), reader.readObject(AztecAddress), reader.readObject(RevertCode), @@ -317,7 +317,7 @@ export class PublicCircuitPublicInputs { reader.readField(), reader.readField(), reader.readArray(MAX_UNENCRYPTED_LOGS_PER_CALL, LogHash), - Header.fromFields(reader), + BlockHeader.fromFields(reader), GlobalVariables.fromFields(reader), AztecAddress.fromFields(reader), RevertCode.fromFields(reader), diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 4942e174577..63f96df9097 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -117,12 +117,12 @@ import { computePublicBytecodeCommitment, makeRecursiveProof, } from '../index.js'; +import { BlockHeader } from '../structs/block_header.js'; import { ContentCommitment, NUM_BYTES_PER_SHA256 } from '../structs/content_commitment.js'; import { Gas } from '../structs/gas.js'; import { GasFees } from '../structs/gas_fees.js'; import { GasSettings } from '../structs/gas_settings.js'; import { GlobalVariables } from '../structs/global_variables.js'; -import { Header } from '../structs/header.js'; import { AvmAccumulatedData, AvmAppendTreeHint, @@ -879,8 +879,8 @@ export function makeHeader( blockNumber: number | undefined = undefined, slotNumber: number | undefined = undefined, txsEffectsHash: Buffer | undefined = undefined, -): Header { - return new Header( +): BlockHeader { + return new BlockHeader( makeAppendOnlyTreeSnapshot(seed + 0x100), makeContentCommitment(seed + 0x200, txsEffectsHash), makeStateReference(seed + 0x600), diff --git a/yarn-project/end-to-end/package.local.json b/yarn-project/end-to-end/package.local.json index e30a30e4508..39b8bc052ef 100644 --- a/yarn-project/end-to-end/package.local.json +++ b/yarn-project/end-to-end/package.local.json @@ -15,4 +15,4 @@ ] ] } -} \ No newline at end of file +} diff --git a/yarn-project/end-to-end/src/composed/integration_l1_publisher.test.ts b/yarn-project/end-to-end/src/composed/integration_l1_publisher.test.ts index 1d9f1c17801..0e44b93ce98 100644 --- a/yarn-project/end-to-end/src/composed/integration_l1_publisher.test.ts +++ b/yarn-project/end-to-end/src/composed/integration_l1_publisher.test.ts @@ -9,11 +9,11 @@ import { } from '@aztec/circuit-types'; import { makeBloatedProcessedTx } from '@aztec/circuit-types/test'; import { + type BlockHeader, EthAddress, GENESIS_ARCHIVE_ROOT, GasFees, GasSettings, - type Header, MAX_NULLIFIERS_PER_TX, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, } from '@aztec/circuits.js'; @@ -84,7 +84,7 @@ describe('L1Publisher integration', () => { let builderDb: MerkleTreeAdminDatabase; // The header of the last block - let prevHeader: Header; + let prevHeader: BlockHeader; let baseFee: GasFees; diff --git a/yarn-project/ivc-integration/webpack.config.js b/yarn-project/ivc-integration/webpack.config.js index 93ad5979167..09dafd51eff 100644 --- a/yarn-project/ivc-integration/webpack.config.js +++ b/yarn-project/ivc-integration/webpack.config.js @@ -32,7 +32,7 @@ export default { plugins: [new ResolveTypeScriptPlugin()], fallback: { tty: false, - } + }, }, devServer: { hot: false, diff --git a/yarn-project/kv-store/src/stores/l2_tips_store.test.ts b/yarn-project/kv-store/src/stores/l2_tips_store.test.ts index 2b820aaf432..10055113763 100644 --- a/yarn-project/kv-store/src/stores/l2_tips_store.test.ts +++ b/yarn-project/kv-store/src/stores/l2_tips_store.test.ts @@ -1,5 +1,5 @@ import { type L2Block } from '@aztec/circuit-types'; -import { Fr, type Header } from '@aztec/circuits.js'; +import { type BlockHeader, Fr } from '@aztec/circuits.js'; import { times } from '@aztec/foundation/collection'; import { type AztecKVStore } from '@aztec/kv-store'; import { openTmpStore } from '@aztec/kv-store/utils'; @@ -16,7 +16,7 @@ describe('L2TipsStore', () => { }); const makeBlock = (number: number): L2Block => - ({ number, header: { hash: () => new Fr(number) } as Header } as L2Block); + ({ number, header: { hash: () => new Fr(number) } as BlockHeader } as L2Block); const makeTip = (number: number) => ({ number, hash: number === 0 ? undefined : new Fr(number).toString() }); 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 77ec114a2a8..91727ff4918 100644 --- a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts +++ b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts @@ -9,6 +9,7 @@ import { AztecAddress, BaseOrMergeRollupPublicInputs, type BaseParityInputs, + BlockHeader, type BlockMergeRollupInputs, BlockRootOrBlockMergePublicInputs, type BlockRootRollupInputs, @@ -32,7 +33,6 @@ import { GlobalVariables, GrumpkinScalar, HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS, - Header, KernelCircuitPublicInputs, type KeyValidationHint, KeyValidationRequest, @@ -138,6 +138,7 @@ import type { AvmProofData as AvmProofDataNoir, BaseOrMergeRollupPublicInputs as BaseOrMergeRollupPublicInputsNoir, BaseParityInputs as BaseParityInputsNoir, + BlockHeader as BlockHeaderNoir, BlockMergeRollupInputs as BlockMergeRollupInputsNoir, BlockRootOrBlockMergePublicInputs as BlockRootOrBlockMergePublicInputsNoir, BlockRootRollupInputs as BlockRootRollupInputsNoir, @@ -159,7 +160,6 @@ import type { GasSettings as GasSettingsNoir, GlobalVariables as GlobalVariablesNoir, EmbeddedCurveScalar as GrumpkinScalarNoir, - Header as HeaderNoir, KernelCircuitPublicInputs as KernelCircuitPublicInputsNoir, KeyValidationHint as KeyValidationHintNoir, KeyValidationRequestAndGenerator as KeyValidationRequestAndGeneratorNoir, @@ -1864,11 +1864,11 @@ export function mapParityPublicInputsFromNoir(parityPublicInputs: ParityPublicIn } /** - * Maps header to Noir - * @param header - The header. - * @returns Header. + * Maps a block header to Noir + * @param header - The block header. + * @returns BlockHeader. */ -export function mapHeaderToNoir(header: Header): HeaderNoir { +export function mapHeaderToNoir(header: BlockHeader): BlockHeaderNoir { return { last_archive: mapAppendOnlyTreeSnapshotToNoir(header.lastArchive), content_commitment: mapContentCommitmentToNoir(header.contentCommitment), @@ -1880,12 +1880,12 @@ export function mapHeaderToNoir(header: Header): HeaderNoir { } /** - * Maps header from Noir. - * @param header - The header. - * @returns Header. + * Maps a block header from Noir. + * @param header - The block header. + * @returns BlockHeader. */ -export function mapHeaderFromNoir(header: HeaderNoir): Header { - return new Header( +export function mapHeaderFromNoir(header: BlockHeaderNoir): BlockHeader { + return new BlockHeader( mapAppendOnlyTreeSnapshotFromNoir(header.last_archive), mapContentCommitmentFromNoir(header.content_commitment), mapStateReferenceFromNoir(header.state), diff --git a/yarn-project/prover-client/package.local.json b/yarn-project/prover-client/package.local.json index 754bb34cec9..74d761e17a1 100644 --- a/yarn-project/prover-client/package.local.json +++ b/yarn-project/prover-client/package.local.json @@ -2,4 +2,4 @@ "scripts": { "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --testTimeout=1500000 --forceExit" } -} \ No newline at end of file +} diff --git a/yarn-project/prover-client/src/mocks/test_context.ts b/yarn-project/prover-client/src/mocks/test_context.ts index e2df1346c11..049218d91a4 100644 --- a/yarn-project/prover-client/src/mocks/test_context.ts +++ b/yarn-project/prover-client/src/mocks/test_context.ts @@ -9,7 +9,7 @@ import { type TxValidator, } from '@aztec/circuit-types'; import { makeBloatedProcessedTx } from '@aztec/circuit-types/test'; -import { type AppendOnlyTreeSnapshot, type Gas, type GlobalVariables, Header } from '@aztec/circuits.js'; +import { type AppendOnlyTreeSnapshot, BlockHeader, type Gas, type GlobalVariables } from '@aztec/circuits.js'; import { times } from '@aztec/foundation/collection'; import { Fr } from '@aztec/foundation/fields'; import { type DebugLogger } from '@aztec/foundation/log'; @@ -40,7 +40,7 @@ import { ProverAgent } from '../prover-agent/prover-agent.js'; import { getEnvironmentConfig, getSimulationProvider, makeGlobals } from './fixtures.js'; export class TestContext { - private headers: Map = new Map(); + private headers: Map = new Map(); constructor( public publicTxSimulator: PublicTxSimulator, @@ -83,7 +83,7 @@ export class TestContext { const processor = new PublicProcessor( publicDb, globalVariables, - Header.empty(), + BlockHeader.empty(), worldStateDB, publicTxSimulator, telemetry, @@ -138,9 +138,9 @@ export class TestContext { return this.worldState.fork(); } - public getHeader(blockNumber: 0): Header; - public getHeader(blockNumber: number): Header | undefined; - public getHeader(blockNumber = 0) { + public getBlockHeader(blockNumber: 0): BlockHeader; + public getBlockHeader(blockNumber: number): BlockHeader | undefined; + public getBlockHeader(blockNumber = 0) { return blockNumber === 0 ? this.worldState.getCommitted().getInitialHeader() : this.headers.get(blockNumber); } @@ -156,7 +156,7 @@ export class TestContext { public makeProcessedTx(seedOrOpts?: Parameters[0] | number): ProcessedTx { const opts = typeof seedOrOpts === 'number' ? { seed: seedOrOpts } : seedOrOpts; const blockNum = (opts?.globalVariables ?? this.globalVariables).blockNumber.toNumber(); - const header = this.getHeader(blockNum - 1); + const header = this.getBlockHeader(blockNum - 1); return makeBloatedProcessedTx({ header, vkTreeRoot: getVKTreeRoot(), diff --git a/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts b/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts index 9dc700689b6..ca78b439515 100644 --- a/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts +++ b/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts @@ -10,13 +10,13 @@ import { ARCHIVE_HEIGHT, AppendOnlyTreeSnapshot, type BaseOrMergeRollupPublicInputs, + BlockHeader, BlockMergeRollupInputs, type BlockRootOrBlockMergePublicInputs, ConstantRollupData, ContentCommitment, Fr, type GlobalVariables, - Header, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, @@ -310,7 +310,7 @@ export function buildHeaderFromCircuitOutputs( sha256Trunc(Buffer.concat([previousMergeData[0].outHash.toBuffer(), previousMergeData[1].outHash.toBuffer()])), ); const state = new StateReference(updatedL1ToL2TreeSnapshot, previousMergeData[1].end); - const header = new Header( + const header = new BlockHeader( rootRollupOutputs.previousArchive, contentCommitment, state, @@ -371,7 +371,7 @@ export async function buildHeaderAndBodyFromTxs( const fees = body.txEffects.reduce((acc, tx) => acc.add(tx.transactionFee), Fr.ZERO); const manaUsed = txs.reduce((acc, tx) => acc.add(new Fr(tx.gasUsed.totalGas.l2Gas)), Fr.ZERO); - const header = new Header(previousArchive, contentCommitment, stateReference, globalVariables, fees, manaUsed); + const header = new BlockHeader(previousArchive, contentCommitment, stateReference, globalVariables, fees, manaUsed); return { header, body }; } @@ -379,7 +379,7 @@ export async function buildHeaderAndBodyFromTxs( // Validate that the roots of all local trees match the output of the root circuit simulation export async function validateBlockRootOutput( blockRootOutput: BlockRootOrBlockMergePublicInputs, - blockHeader: Header, + blockHeader: BlockHeader, db: MerkleTreeReadOperations, ) { await Promise.all([ diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator.ts b/yarn-project/prover-client/src/orchestrator/orchestrator.ts index 713e6350c6b..73a7a425b03 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator.ts @@ -19,12 +19,12 @@ import { type BaseOrMergeRollupPublicInputs, BaseParityInputs, type BaseRollupHints, + type BlockHeader, type BlockRootOrBlockMergePublicInputs, BlockRootRollupInputs, EmptyBlockRootRollupInputs, Fr, type GlobalVariables, - type Header, L1_TO_L2_MSG_SUBTREE_HEIGHT, L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, type NESTED_RECURSIVE_PROOF_LENGTH, @@ -279,7 +279,7 @@ export class ProvingOrchestrator implements EpochProver { @trackSpan('ProvingOrchestrator.setBlockCompleted', (blockNumber: number) => ({ [Attributes.BLOCK_NUMBER]: blockNumber, })) - public async setBlockCompleted(blockNumber: number, expectedHeader?: Header): Promise { + public async setBlockCompleted(blockNumber: number, expectedHeader?: BlockHeader): Promise { const provingState = this.provingState?.getBlockProvingStateByBlockNumber(blockNumber); if (!provingState) { throw new Error(`Block proving state for ${blockNumber} not found`); @@ -407,7 +407,7 @@ export class ProvingOrchestrator implements EpochProver { return Promise.resolve(); } - private async buildBlock(provingState: BlockProvingState, expectedHeader?: Header) { + private async buildBlock(provingState: BlockProvingState, expectedHeader?: BlockHeader) { // Collect all new nullifiers, commitments, and contracts from all txs in this block to build body const txs = provingState!.allTxs.map(a => a.processedTx); diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator_multi_public_functions.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator_multi_public_functions.test.ts index 26997fca8d5..5b4adf7d34d 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator_multi_public_functions.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator_multi_public_functions.test.ts @@ -35,7 +35,7 @@ describe('prover/orchestrator/public-functions', () => { }), ); for (const tx of txs) { - tx.data.constants.historicalHeader = context.getHeader(0); + tx.data.constants.historicalHeader = context.getBlockHeader(0); tx.data.constants.vkTreeRoot = getVKTreeRoot(); tx.data.constants.protocolContractTreeRoot = protocolContractTreeRoot; } diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator_public_functions.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator_public_functions.test.ts index 393329094f1..040ab5ad44d 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator_public_functions.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator_public_functions.test.ts @@ -35,7 +35,7 @@ describe('prover/orchestrator/public-functions', () => { numberOfNonRevertiblePublicCallRequests, numberOfRevertiblePublicCallRequests, }); - tx.data.constants.historicalHeader = context.getHeader(0); + tx.data.constants.historicalHeader = context.getBlockHeader(0); tx.data.constants.vkTreeRoot = getVKTreeRoot(); tx.data.constants.protocolContractTreeRoot = protocolContractTreeRoot; diff --git a/yarn-project/prover-client/src/test/bb_prover_base_rollup.test.ts b/yarn-project/prover-client/src/test/bb_prover_base_rollup.test.ts index 154ac6c71dd..09945d2010e 100644 --- a/yarn-project/prover-client/src/test/bb_prover_base_rollup.test.ts +++ b/yarn-project/prover-client/src/test/bb_prover_base_rollup.test.ts @@ -35,7 +35,7 @@ describe('prover/bb_prover/base-rollup', () => { }); it('proves the base rollup', async () => { - const header = context.getHeader(0); + const header = context.getBlockHeader(0); const chainId = context.globalVariables.chainId; const version = context.globalVariables.version; const vkTreeRoot = getVKTreeRoot(); diff --git a/yarn-project/prover-client/src/test/bb_prover_full_rollup.test.ts b/yarn-project/prover-client/src/test/bb_prover_full_rollup.test.ts index 43684e6f1a9..182742183e6 100644 --- a/yarn-project/prover-client/src/test/bb_prover_full_rollup.test.ts +++ b/yarn-project/prover-client/src/test/bb_prover_full_rollup.test.ts @@ -39,7 +39,7 @@ describe('prover/bb_prover/full-rollup', () => { async (blockCount, totalBlocks, nonEmptyTxs, totalTxs) => { log.info(`Proving epoch with ${blockCount}/${totalBlocks} blocks with ${nonEmptyTxs}/${totalTxs} non-empty txs`); - const initialHeader = context.getHeader(0); + const initialHeader = context.getBlockHeader(0); context.orchestrator.startNewEpoch(1, 1, totalBlocks); for (let blockNum = 1; blockNum <= blockCount; blockNum++) { @@ -94,7 +94,7 @@ describe('prover/bb_prover/full-rollup', () => { }), ); for (const tx of txs) { - tx.data.constants.historicalHeader = context.getHeader(0); + tx.data.constants.historicalHeader = context.getBlockHeader(0); } const l1ToL2Messages = makeTuple( diff --git a/yarn-project/pxe/src/database/kv_pxe_database.ts b/yarn-project/pxe/src/database/kv_pxe_database.ts index 287af7b6bbd..bdb6b26336d 100644 --- a/yarn-project/pxe/src/database/kv_pxe_database.ts +++ b/yarn-project/pxe/src/database/kv_pxe_database.ts @@ -7,9 +7,9 @@ import { } from '@aztec/circuit-types'; import { AztecAddress, + BlockHeader, CompleteAddress, type ContractInstanceWithAddress, - Header, type IndexedTaggingSecret, type PublicKey, SerializableContractInstance, @@ -533,7 +533,7 @@ export class KVPxeDatabase implements PxeDatabase { return Promise.resolve(); } - async setHeader(header: Header): Promise { + async setHeader(header: BlockHeader): Promise { await this.#synchronizedBlock.set(header.toBuffer()); } @@ -543,16 +543,16 @@ export class KVPxeDatabase implements PxeDatabase { return undefined; } - return Number(Header.fromBuffer(headerBuffer).globalVariables.blockNumber.toBigInt()); + return Number(BlockHeader.fromBuffer(headerBuffer).globalVariables.blockNumber.toBigInt()); } - getHeader(): Header { + getBlockHeader(): BlockHeader { const headerBuffer = this.#synchronizedBlock.get(); if (!headerBuffer) { throw new Error(`Header not set`); } - return Header.fromBuffer(headerBuffer); + return BlockHeader.fromBuffer(headerBuffer); } async #addScope(scope: AztecAddress): Promise { diff --git a/yarn-project/pxe/src/database/pxe_database.ts b/yarn-project/pxe/src/database/pxe_database.ts index 8b884041bb9..a0dfa1ac89a 100644 --- a/yarn-project/pxe/src/database/pxe_database.ts +++ b/yarn-project/pxe/src/database/pxe_database.ts @@ -1,8 +1,8 @@ import { type InBlock, type IncomingNotesFilter, type OutgoingNotesFilter } from '@aztec/circuit-types'; import { + type BlockHeader, type CompleteAddress, type ContractInstanceWithAddress, - type Header, type IndexedTaggingSecret, type PublicKey, } from '@aztec/circuits.js'; @@ -115,7 +115,7 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD * @returns The Block Header. * @throws If no block have been processed yet. */ - getHeader(): Header; + getBlockHeader(): BlockHeader; /** * Set the latest Block Header. @@ -124,7 +124,7 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD * @param header - An object containing the most recent block header. * @returns A Promise that resolves when the hash has been successfully updated in the database. */ - setHeader(header: Header): Promise; + setHeader(header: BlockHeader): Promise; /** * Adds contact address to the database. diff --git a/yarn-project/pxe/src/database/pxe_database_test_suite.ts b/yarn-project/pxe/src/database/pxe_database_test_suite.ts index 4fcf59993b1..9947e952c51 100644 --- a/yarn-project/pxe/src/database/pxe_database_test_suite.ts +++ b/yarn-project/pxe/src/database/pxe_database_test_suite.ts @@ -380,11 +380,11 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { const header = makeHeader(randomInt(1000), INITIAL_L2_BLOCK_NUM, 0 /** slot number */); await database.setHeader(header); - expect(database.getHeader()).toEqual(header); + expect(database.getBlockHeader()).toEqual(header); }); it('rejects getting header if no block set', () => { - expect(() => database.getHeader()).toThrow(); + expect(() => database.getBlockHeader()).toThrow(); }); }); diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index 4a18b6bf758..802fe6c4214 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -14,11 +14,11 @@ import { } from '@aztec/circuit-types'; import { type AztecAddress, + type BlockHeader, type CompleteAddress, type ContractInstance, Fr, type FunctionSelector, - type Header, IndexedTaggingSecret, type KeyValidationRequest, type L1_TO_L2_MSG_TREE_HEIGHT, @@ -229,10 +229,10 @@ export class SimulatorOracle implements DBOracle { * Retrieve the databases view of the Block Header object. * This structure is fed into the circuits simulator and is used to prove against certain historical roots. * - * @returns A Promise that resolves to a Header object. + * @returns A Promise that resolves to a BlockHeader object. */ - getHeader(): Promise
{ - return Promise.resolve(this.db.getHeader()); + getBlockHeader(): Promise { + return Promise.resolve(this.db.getBlockHeader()); } /** diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.test.ts b/yarn-project/pxe/src/synchronizer/synchronizer.test.ts index e78c0dbb4ab..dd331875954 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.test.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.test.ts @@ -37,7 +37,7 @@ describe('Synchronizer', () => { const block = L2Block.random(1, 4); await synchronizer.handleBlockStreamEvent({ type: 'blocks-added', blocks: [block] }); - const obtainedHeader = database.getHeader(); + const obtainedHeader = database.getBlockHeader(); expect(obtainedHeader).toEqual(block.header); }); diff --git a/yarn-project/sequencer-client/src/publisher/l1-publisher.ts b/yarn-project/sequencer-client/src/publisher/l1-publisher.ts index 7be51664842..204dd065b06 100644 --- a/yarn-project/sequencer-client/src/publisher/l1-publisher.ts +++ b/yarn-project/sequencer-client/src/publisher/l1-publisher.ts @@ -11,9 +11,9 @@ import { type L1PublishBlockStats, type L1PublishProofStats } from '@aztec/circu import { AGGREGATION_OBJECT_LENGTH, AZTEC_MAX_EPOCH_DURATION, + type BlockHeader, EthAddress, type FeeRecipient, - type Header, type Proof, type RootRollupPublicInputs, } from '@aztec/circuits.js'; @@ -358,7 +358,7 @@ export class L1Publisher { * */ public async validateBlockForSubmission( - header: Header, + header: BlockHeader, attestationData: { digest: Buffer; signatures: Signature[] } = { digest: Buffer.alloc(32), signatures: [], diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.ts index 34c9100a4e8..d1bd7d3df1d 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.ts @@ -13,10 +13,10 @@ import type { AllowedElement, Signature, WorldStateSynchronizerStatus } from '@a import { type L2BlockBuiltStats } from '@aztec/circuit-types/stats'; import { AppendOnlyTreeSnapshot, + BlockHeader, ContentCommitment, GENESIS_ARCHIVE_ROOT, type GlobalVariables, - Header, StateReference, } from '@aztec/circuits.js'; import { AztecAddress } from '@aztec/foundation/aztec-address'; @@ -289,7 +289,7 @@ export class Sequencer { this.log.debug(`Retrieved ${pendingTxs.length} txs from P2P pool`); // If I created a "partial" header here that should make our job much easier. - const proposalHeader = new Header( + const proposalHeader = new BlockHeader( new AppendOnlyTreeSnapshot(Fr.fromBuffer(chainTipArchive), 1), ContentCommitment.empty(), StateReference.empty(), @@ -343,7 +343,7 @@ export class Sequencer { } /** Whether to skip the check of min txs per block if more than maxSecondsBetweenBlocks has passed since the previous block. */ - private skipMinTxsPerBlockCheck(historicalHeader: Header | undefined): boolean { + private skipMinTxsPerBlockCheck(historicalHeader: BlockHeader | undefined): boolean { const lastBlockTime = historicalHeader?.globalVariables.timestamp.toNumber() || 0; const currentTime = Math.floor(Date.now() / 1000); const elapsed = currentTime - lastBlockTime; @@ -422,7 +422,7 @@ export class Sequencer { this.state = proposedState; } - shouldProposeBlock(historicalHeader: Header | undefined, args: ShouldProposeArgs): boolean { + shouldProposeBlock(historicalHeader: BlockHeader | undefined, args: ShouldProposeArgs): boolean { if (this.isFlushing) { this.log.verbose(`Flushing all pending txs in new block`); return true; @@ -501,7 +501,7 @@ export class Sequencer { private async buildBlock( validTxs: Tx[], newGlobalVariables: GlobalVariables, - historicalHeader?: Header, + historicalHeader?: BlockHeader, interrupt?: (processedTxs: ProcessedTx[]) => Promise, ) { this.log.debug('Requesting L1 to L2 messages from contract'); @@ -569,8 +569,8 @@ export class Sequencer { })) private async buildBlockAndAttemptToPublish( validTxs: Tx[], - proposalHeader: Header, - historicalHeader: Header | undefined, + proposalHeader: BlockHeader, + historicalHeader: BlockHeader | undefined, ): Promise { await this.publisher.validateBlockForSubmission(proposalHeader); diff --git a/yarn-project/simulator/src/acvm/oracle/oracle.ts b/yarn-project/simulator/src/acvm/oracle/oracle.ts index cdf274883f4..99d5d5f29f2 100644 --- a/yarn-project/simulator/src/acvm/oracle/oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/oracle.ts @@ -146,10 +146,10 @@ export class Oracle { return witness.toFields().map(toACVMField); } - async getHeader([blockNumber]: ACVMField[]): Promise { + async getBlockHeader([blockNumber]: ACVMField[]): Promise { const parsedBlockNumber = frToNumber(fromACVMField(blockNumber)); - const header = await this.typedOracle.getHeader(parsedBlockNumber); + const header = await this.typedOracle.getBlockHeader(parsedBlockNumber); if (!header) { throw new Error(`Block header not found for block ${parsedBlockNumber}.`); } diff --git a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts index 197d235296a..2505a0478b0 100644 --- a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts @@ -9,8 +9,8 @@ import { type UnencryptedL2Log, } from '@aztec/circuit-types'; import { + type BlockHeader, type ContractInstance, - type Header, type IndexedTaggingSecret, type KeyValidationRequest, type L1_TO_L2_MSG_TREE_HEIGHT, @@ -127,8 +127,8 @@ export abstract class TypedOracle { throw new OracleMethodNotAvailableError('getLowNullifierMembershipWitness'); } - getHeader(_blockNumber: number): Promise
{ - throw new OracleMethodNotAvailableError('getHeader'); + getBlockHeader(_blockNumber: number): Promise { + throw new OracleMethodNotAvailableError('getBlockHeader'); } getCompleteAddress(_account: AztecAddress): Promise { diff --git a/yarn-project/simulator/src/client/client_execution_context.ts b/yarn-project/simulator/src/client/client_execution_context.ts index 0d7b8d4a122..17df6164697 100644 --- a/yarn-project/simulator/src/client/client_execution_context.ts +++ b/yarn-project/simulator/src/client/client_execution_context.ts @@ -11,9 +11,9 @@ import { type UnencryptedL2Log, } from '@aztec/circuit-types'; import { + type BlockHeader, CallContext, FunctionSelector, - type Header, PRIVATE_CONTEXT_INPUTS_LENGTH, PUBLIC_DISPATCH_SELECTOR, PrivateContextInputs, @@ -66,7 +66,7 @@ export class ClientExecutionContext extends ViewDataOracle { private readonly txContext: TxContext, private readonly callContext: CallContext, /** Header of a block whose state is used during private execution (not the block the transaction is included in). */ - protected readonly historicalHeader: Header, + protected readonly historicalHeader: BlockHeader, /** List of transient auth witnesses to be used during this simulation */ authWitnesses: AuthWitness[], private readonly packedValuesCache: PackedValuesCache, diff --git a/yarn-project/simulator/src/client/db_oracle.ts b/yarn-project/simulator/src/client/db_oracle.ts index 4047c17d83b..6702810c86a 100644 --- a/yarn-project/simulator/src/client/db_oracle.ts +++ b/yarn-project/simulator/src/client/db_oracle.ts @@ -8,9 +8,9 @@ import { type TxScopedL2Log, } from '@aztec/circuit-types'; import { + type BlockHeader, type CompleteAddress, type ContractInstance, - type Header, type IndexedTaggingSecret, type KeyValidationRequest, } from '@aztec/circuits.js'; @@ -138,7 +138,7 @@ export interface DBOracle extends CommitmentsDB { * * @returns A Promise that resolves to a Header object. */ - getHeader(): Promise
; + getBlockHeader(): Promise; /** * Fetch the index of the leaf in the respective tree diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 815f48c36bb..022022db071 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -10,13 +10,13 @@ import { } from '@aztec/circuit-types'; import { AppendOnlyTreeSnapshot, + BlockHeader, CallContext, CompleteAddress, GasFees, GasSettings, GeneratorIndex, type GrumpkinScalar, - Header, IndexedTaggingSecret, KeyValidationRequest, L1_TO_L2_MSG_TREE_HEIGHT, @@ -82,7 +82,7 @@ describe('Private Execution test suite', () => { let acirSimulator: AcirSimulator; - let header = Header.empty(); + let header = BlockHeader.empty(); let logger: DebugLogger; const defaultContractAddress = AztecAddress.random(); @@ -154,7 +154,7 @@ describe('Private Execution test suite', () => { const newSnap = new AppendOnlyTreeSnapshot(Fr.fromBuffer(tree.getRoot(true)), Number(tree.getNumLeaves(true))); if (name === 'noteHash' || name === 'l1ToL2Messages' || name === 'publicData') { - header = new Header( + header = new BlockHeader( header.lastArchive, header.contentCommitment, new StateReference( @@ -170,7 +170,7 @@ describe('Private Execution test suite', () => { header.totalManaUsed, ); } else { - header = new Header( + header = new BlockHeader( header.lastArchive, header.contentCommitment, new StateReference(newSnap, header.state.partial), @@ -241,7 +241,7 @@ describe('Private Execution test suite', () => { // We call insertLeaves here with no leaves to populate empty public data tree root --> this is necessary to be // able to get ivpk_m during execution await insertLeaves([], 'publicData'); - oracle.getHeader.mockResolvedValue(header); + oracle.getBlockHeader.mockResolvedValue(header); oracle.getCompleteAddress.mockImplementation((address: AztecAddress) => { if (address.equals(owner)) { @@ -605,7 +605,7 @@ describe('Private Execution test suite', () => { return Promise.resolve(new MessageLoadOracleInputs(0n, await tree.getSiblingPath(0n, true))); }); if (updateHeader) { - oracle.getHeader.mockResolvedValue(header); + oracle.getBlockHeader.mockResolvedValue(header); } }; @@ -653,7 +653,7 @@ describe('Private Execution test suite', () => { await mockOracles(); // Update state - oracle.getHeader.mockResolvedValue(header); + oracle.getBlockHeader.mockResolvedValue(header); await expect( runSimulator({ @@ -673,7 +673,7 @@ describe('Private Execution test suite', () => { await mockOracles(); // Update state - oracle.getHeader.mockResolvedValue(header); + oracle.getBlockHeader.mockResolvedValue(header); await expect( runSimulator({ @@ -692,7 +692,7 @@ describe('Private Execution test suite', () => { await mockOracles(); // Update state - oracle.getHeader.mockResolvedValue(header); + oracle.getBlockHeader.mockResolvedValue(header); await expect( runSimulator({ @@ -711,7 +711,7 @@ describe('Private Execution test suite', () => { await mockOracles(); // Update state - oracle.getHeader.mockResolvedValue(header); + oracle.getBlockHeader.mockResolvedValue(header); await expect( runSimulator({ @@ -731,7 +731,7 @@ describe('Private Execution test suite', () => { await mockOracles(); // Update state - oracle.getHeader.mockResolvedValue(header); + oracle.getBlockHeader.mockResolvedValue(header); await expect( runSimulator({ @@ -751,7 +751,7 @@ describe('Private Execution test suite', () => { await mockOracles(); // Update state - oracle.getHeader.mockResolvedValue(header); + oracle.getBlockHeader.mockResolvedValue(header); await expect( runSimulator({ @@ -1122,8 +1122,8 @@ describe('Private Execution test suite', () => { header = makeHeader(); - oracle.getHeader.mockClear(); - oracle.getHeader.mockResolvedValue(header); + oracle.getBlockHeader.mockClear(); + oracle.getBlockHeader.mockResolvedValue(header); }); it('Header is correctly set', async () => { diff --git a/yarn-project/simulator/src/client/simulator.ts b/yarn-project/simulator/src/client/simulator.ts index d434f75fa28..a60f634a288 100644 --- a/yarn-project/simulator/src/client/simulator.ts +++ b/yarn-project/simulator/src/client/simulator.ts @@ -57,7 +57,7 @@ export class AcirSimulator { ); } - const header = await this.db.getHeader(); + const header = await this.db.getBlockHeader(); // reserve the first side effect for the tx hash (inserted by the private kernel) const startSideEffectCounter = 1; diff --git a/yarn-project/simulator/src/client/unconstrained_execution.test.ts b/yarn-project/simulator/src/client/unconstrained_execution.test.ts index 99bb3e3842d..c285da49d9a 100644 --- a/yarn-project/simulator/src/client/unconstrained_execution.test.ts +++ b/yarn-project/simulator/src/client/unconstrained_execution.test.ts @@ -1,5 +1,5 @@ import { type AztecNode, type FunctionCall, Note } from '@aztec/circuit-types'; -import { CompleteAddress, Header } from '@aztec/circuits.js'; +import { BlockHeader, CompleteAddress } from '@aztec/circuits.js'; import { FunctionSelector, FunctionType, encodeArguments } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; @@ -55,7 +55,7 @@ describe('Unconstrained Execution test suite', () => { oracle.syncTaggedLogs.mockResolvedValue(new Map()); oracle.processTaggedLogs.mockResolvedValue(); - oracle.getHeader.mockResolvedValue(Header.empty()); + oracle.getBlockHeader.mockResolvedValue(BlockHeader.empty()); oracle.getNotes.mockResolvedValue( notes.map((note, index) => ({ contractAddress, diff --git a/yarn-project/simulator/src/client/view_data_oracle.ts b/yarn-project/simulator/src/client/view_data_oracle.ts index bd5633f2103..67af9e77df3 100644 --- a/yarn-project/simulator/src/client/view_data_oracle.ts +++ b/yarn-project/simulator/src/client/view_data_oracle.ts @@ -8,8 +8,8 @@ import { type PublicDataWitness, } from '@aztec/circuit-types'; import { + type BlockHeader, type ContractInstance, - type Header, type IndexedTaggingSecret, type KeyValidationRequest, } from '@aztec/circuits.js'; @@ -139,7 +139,7 @@ export class ViewDataOracle extends TypedOracle { * @param blockNumber - The number of a block of which to get the block header. * @returns Block extracted from a block with block number `blockNumber`. */ - public override async getHeader(blockNumber: number): Promise
{ + public override async getBlockHeader(blockNumber: number): Promise { const block = await this.db.getBlock(blockNumber); if (!block) { return undefined; diff --git a/yarn-project/simulator/src/public/fixtures/index.ts b/yarn-project/simulator/src/public/fixtures/index.ts index 68eec22d6e1..31ce0cc1cad 100644 --- a/yarn-project/simulator/src/public/fixtures/index.ts +++ b/yarn-project/simulator/src/public/fixtures/index.ts @@ -1,6 +1,7 @@ import { PublicExecutionRequest, Tx } from '@aztec/circuit-types'; import { type AvmCircuitInputs, + BlockHeader, CallContext, type ContractClassPublic, type ContractInstanceWithAddress, @@ -10,7 +11,6 @@ import { GasFees, GasSettings, GlobalVariables, - Header, MAX_L2_GAS_PER_ENQUEUED_CALL, PartialPrivateTailPublicInputsForPublic, PrivateKernelTailCircuitPublicInputs, @@ -115,7 +115,7 @@ export function createTxForPublicCall( const teardownGasLimits = isTeardown ? gasLimits : Gas.empty(); const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty()); const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings); - const constantData = new TxConstantData(Header.empty(), txContext, Fr.zero(), Fr.zero()); + const constantData = new TxConstantData(BlockHeader.empty(), txContext, Fr.zero(), Fr.zero()); const txData = new PrivateKernelTailCircuitPublicInputs( constantData, diff --git a/yarn-project/simulator/src/public/public_processor.test.ts b/yarn-project/simulator/src/public/public_processor.test.ts index 7db6b283dc8..2b2a0a27fbf 100644 --- a/yarn-project/simulator/src/public/public_processor.test.ts +++ b/yarn-project/simulator/src/public/public_processor.test.ts @@ -12,11 +12,11 @@ import { AvmCircuitInputs, type AvmCircuitPublicInputs, AztecAddress, + BlockHeader, Fr, Gas, GasFees, GlobalVariables, - Header, PublicDataWrite, RevertCode, countAccumulatedItems, @@ -86,7 +86,7 @@ describe('public_processor', () => { processor = new PublicProcessor( db, globalVariables, - Header.empty(), + BlockHeader.empty(), worldStateDB, publicTxProcessor, new NoopTelemetryClient(), diff --git a/yarn-project/simulator/src/public/public_processor.ts b/yarn-project/simulator/src/public/public_processor.ts index d11ac645e59..01e02975351 100644 --- a/yarn-project/simulator/src/public/public_processor.ts +++ b/yarn-project/simulator/src/public/public_processor.ts @@ -13,10 +13,10 @@ import { } from '@aztec/circuit-types'; import { type AztecAddress, + type BlockHeader, type ContractDataSource, Fr, type GlobalVariables, - type Header, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT, @@ -47,7 +47,7 @@ export class PublicProcessorFactory { */ public create( merkleTree: MerkleTreeWriteOperations, - maybeHistoricalHeader: Header | undefined, + maybeHistoricalHeader: BlockHeader | undefined, globalVariables: GlobalVariables, ): PublicProcessor { const historicalHeader = maybeHistoricalHeader ?? merkleTree.getInitialHeader(); @@ -75,7 +75,7 @@ export class PublicProcessor { constructor( protected db: MerkleTreeWriteOperations, protected globalVariables: GlobalVariables, - protected historicalHeader: Header, + protected historicalHeader: BlockHeader, protected worldStateDB: WorldStateDB, protected publicTxSimulator: PublicTxSimulator, telemetryClient: TelemetryClient, diff --git a/yarn-project/simulator/src/public/public_tx_simulator.test.ts b/yarn-project/simulator/src/public/public_tx_simulator.test.ts index c17d1d03bf5..eeda04eb316 100644 --- a/yarn-project/simulator/src/public/public_tx_simulator.test.ts +++ b/yarn-project/simulator/src/public/public_tx_simulator.test.ts @@ -7,12 +7,12 @@ import { } from '@aztec/circuit-types'; import { AppendOnlyTreeSnapshot, + BlockHeader, Fr, Gas, GasFees, GasSettings, GlobalVariables, - Header, NULLIFIER_SUBTREE_HEIGHT, PUBLIC_DATA_TREE_HEIGHT, PartialStateReference, @@ -194,7 +194,7 @@ describe('public_tx_simulator', () => { Fr.fromBuffer(publicDataTree.getRoot(true)), Number(publicDataTree.getNumLeaves(true)), ); - const header = Header.empty(); + const header = BlockHeader.empty(); const stateReference = new StateReference( header.state.l1ToL2MessageTree, new PartialStateReference(header.state.partial.noteHashTree, header.state.partial.nullifierTree, snap), diff --git a/yarn-project/txe/src/oracle/txe_oracle.ts b/yarn-project/txe/src/oracle/txe_oracle.ts index e9c6d1c01c9..092b952a0b9 100644 --- a/yarn-project/txe/src/oracle/txe_oracle.ts +++ b/yarn-project/txe/src/oracle/txe_oracle.ts @@ -11,13 +11,13 @@ import { } from '@aztec/circuit-types'; import { type CircuitWitnessGenerationStats } from '@aztec/circuit-types/stats'; import { + BlockHeader, CallContext, type ContractInstance, type ContractInstanceWithAddress, Gas, GasFees, GlobalVariables, - Header, IndexedTaggingSecret, type KeyValidationRequest, type L1_TO_L2_MSG_TREE_HEIGHT, @@ -362,8 +362,8 @@ export class TXE implements TypedOracle { throw new Error('Method not implemented.'); } - async getHeader(blockNumber: number): Promise
{ - const header = Header.empty(); + async getBlockHeader(blockNumber: number): Promise { + const header = BlockHeader.empty(); const db = await this.#getTreesAt(blockNumber); header.state = await db.getStateReference(); header.globalVariables.blockNumber = new Fr(blockNumber); diff --git a/yarn-project/txe/src/txe_service/txe_service.ts b/yarn-project/txe/src/txe_service/txe_service.ts index fe8ebd2d738..28cf3a97a17 100644 --- a/yarn-project/txe/src/txe_service/txe_service.ts +++ b/yarn-project/txe/src/txe_service/txe_service.ts @@ -1,9 +1,9 @@ import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr'; import { L2Block, MerkleTreeId, SimulationError } from '@aztec/circuit-types'; import { + BlockHeader, Fr, FunctionSelector, - Header, PublicDataTreeLeaf, PublicKeys, computePartialAddress, @@ -72,7 +72,7 @@ export class TXEService { const trees = (this.typedOracle as TXE).getTrees(); for (let i = 0; i < nBlocks; i++) { const blockNumber = await this.typedOracle.getBlockNumber(); - const header = Header.empty(); + const header = BlockHeader.empty(); const l2Block = L2Block.empty(); header.state = await trees.getStateReference(true); header.globalVariables.blockNumber = new Fr(blockNumber); @@ -550,8 +550,8 @@ export class TXEService { return toForeignCallResult([]); } - async getHeader(blockNumber: ForeignCallSingle) { - const header = await this.typedOracle.getHeader(fromSingle(blockNumber).toNumber()); + async getBlockHeader(blockNumber: ForeignCallSingle) { + const header = await this.typedOracle.getBlockHeader(fromSingle(blockNumber).toNumber()); if (!header) { throw new Error(`Block header not found for block ${blockNumber}.`); } diff --git a/yarn-project/validator-client/src/duties/validation_service.ts b/yarn-project/validator-client/src/duties/validation_service.ts index ee5718b2e00..e79fe5fa8c1 100644 --- a/yarn-project/validator-client/src/duties/validation_service.ts +++ b/yarn-project/validator-client/src/duties/validation_service.ts @@ -5,7 +5,7 @@ import { SignatureDomainSeperator, type TxHash, } from '@aztec/circuit-types'; -import { type Header } from '@aztec/circuits.js'; +import { type BlockHeader } from '@aztec/circuits.js'; import { Buffer32 } from '@aztec/foundation/buffer'; import { keccak256 } from '@aztec/foundation/crypto'; import { type Fr } from '@aztec/foundation/fields'; @@ -24,7 +24,7 @@ export class ValidationService { * * @returns A block proposal signing the above information (not the current implementation!!!) */ - createBlockProposal(header: Header, archive: Fr, txs: TxHash[]): Promise { + createBlockProposal(header: BlockHeader, archive: Fr, txs: TxHash[]): Promise { const payloadSigner = (payload: Buffer32) => this.keyStore.signMessage(payload); return BlockProposal.createProposalFromSigner(new ConsensusPayload(header, archive, txs), payloadSigner); diff --git a/yarn-project/validator-client/src/validator.ts b/yarn-project/validator-client/src/validator.ts index 33a78090648..5067875db34 100644 --- a/yarn-project/validator-client/src/validator.ts +++ b/yarn-project/validator-client/src/validator.ts @@ -6,7 +6,7 @@ import { type Tx, type TxHash, } from '@aztec/circuit-types'; -import { type GlobalVariables, type Header } from '@aztec/circuits.js'; +import { type BlockHeader, type GlobalVariables } from '@aztec/circuits.js'; import { type EpochCache } from '@aztec/epoch-cache'; import { Buffer32 } from '@aztec/foundation/buffer'; import { type Fr } from '@aztec/foundation/fields'; @@ -38,7 +38,7 @@ import { ValidatorMetrics } from './metrics.js'; type BlockBuilderCallback = ( txs: Tx[], globalVariables: GlobalVariables, - historicalHeader?: Header, + historicalHeader?: BlockHeader, interrupt?: (processedTxs: ProcessedTx[]) => Promise, ) => Promise<{ block: L2Block; publicProcessorDuration: number; numProcessedTxs: number; blockBuildingTimer: Timer }>; @@ -48,7 +48,7 @@ export interface Validator { registerBlockBuilder(blockBuilder: BlockBuilderCallback): void; // Block validation responsiblities - createBlockProposal(header: Header, archive: Fr, txs: TxHash[]): Promise; + createBlockProposal(header: BlockHeader, archive: Fr, txs: TxHash[]): Promise; attestToProposal(proposal: BlockProposal): void; broadcastBlockProposal(proposal: BlockProposal): void; @@ -236,7 +236,7 @@ export class ValidatorClient extends WithTracer implements Validator { } } - async createBlockProposal(header: Header, archive: Fr, txs: TxHash[]): Promise { + async createBlockProposal(header: BlockHeader, archive: Fr, txs: TxHash[]): Promise { if (this.previousProposal?.slotNumber.equals(header.globalVariables.slotNumber)) { this.log.verbose(`Already made a proposal for the same slot, skipping proposal`); return Promise.resolve(undefined); diff --git a/yarn-project/world-state/src/native/merkle_trees_facade.ts b/yarn-project/world-state/src/native/merkle_trees_facade.ts index 9ce07806d0e..6d3ea76d7fd 100644 --- a/yarn-project/world-state/src/native/merkle_trees_facade.ts +++ b/yarn-project/world-state/src/native/merkle_trees_facade.ts @@ -10,8 +10,8 @@ import { type TreeInfo, } from '@aztec/circuit-types'; import { + type BlockHeader, Fr, - type Header, NullifierLeaf, NullifierLeafPreimage, PartialStateReference, @@ -37,11 +37,11 @@ import { type NativeWorldStateInstance } from './native_world_state_instance.js' export class MerkleTreesFacade implements MerkleTreeReadOperations { constructor( protected readonly instance: NativeWorldStateInstance, - protected readonly initialHeader: Header, + protected readonly initialHeader: BlockHeader, protected readonly revision: WorldStateRevision, ) {} - getInitialHeader(): Header { + getInitialHeader(): BlockHeader { return this.initialHeader; } @@ -182,13 +182,13 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations { } export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTreeWriteOperations { - constructor(instance: NativeWorldStateInstance, initialHeader: Header, revision: WorldStateRevision) { + constructor(instance: NativeWorldStateInstance, initialHeader: BlockHeader, revision: WorldStateRevision) { assert.notEqual(revision.forkId, 0, 'Fork ID must be set'); assert.equal(revision.includeUncommitted, true, 'Fork must include uncommitted data'); super(instance, initialHeader, revision); } - async updateArchive(header: Header): Promise { + async updateArchive(header: BlockHeader): Promise { await this.instance.call(WorldStateMessageType.UPDATE_ARCHIVE, { forkId: this.revision.forkId, blockHeaderHash: header.hash().toBuffer(), diff --git a/yarn-project/world-state/src/native/native_world_state.test.ts b/yarn-project/world-state/src/native/native_world_state.test.ts index 91044fdef56..ff2767e5971 100644 --- a/yarn-project/world-state/src/native/native_world_state.test.ts +++ b/yarn-project/world-state/src/native/native_world_state.test.ts @@ -2,9 +2,9 @@ import { type L2Block, MerkleTreeId } from '@aztec/circuit-types'; import { ARCHIVE_HEIGHT, AppendOnlyTreeSnapshot, + BlockHeader, EthAddress, Fr, - Header, L1_TO_L2_MSG_TREE_HEIGHT, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, @@ -188,7 +188,7 @@ describe('NativeWorldState', () => { const stateReference = await fork.getStateReference(); const archiveInfo = await fork.getTreeInfo(MerkleTreeId.ARCHIVE); - const header = new Header( + const header = new BlockHeader( new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)), makeContentCommitment(), stateReference, @@ -218,7 +218,7 @@ describe('NativeWorldState', () => { const fork = await ws.fork(3); const stateReference = await fork.getStateReference(); const archiveInfo = await fork.getTreeInfo(MerkleTreeId.ARCHIVE); - const header = new Header( + const header = new BlockHeader( new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)), makeContentCommitment(), stateReference, diff --git a/yarn-project/world-state/src/native/native_world_state.ts b/yarn-project/world-state/src/native/native_world_state.ts index 9e0b175ac6c..6ba04682769 100644 --- a/yarn-project/world-state/src/native/native_world_state.ts +++ b/yarn-project/world-state/src/native/native_world_state.ts @@ -7,9 +7,9 @@ import { TxEffect, } from '@aztec/circuit-types'; import { + BlockHeader, EthAddress, Fr, - Header, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, @@ -52,7 +52,7 @@ export const WORLD_STATE_VERSION_FILE = 'version'; export const WORLD_STATE_DB_VERSION = 1; // The initial version export class NativeWorldStateService implements MerkleTreeDatabase { - protected initialHeader: Header | undefined; + protected initialHeader: BlockHeader | undefined; // This is read heavily and only changes when data is persisted, so we cache it private cachedStatusSummary: WorldStateStatusSummary | undefined; @@ -156,7 +156,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase { return new MerkleTreesForkFacade(this.instance, this.initialHeader!, worldStateRevision(true, resp.forkId, 0)); } - public getInitialHeader(): Header { + public getInitialHeader(): BlockHeader { return this.initialHeader!; } @@ -208,9 +208,9 @@ export class NativeWorldStateService implements MerkleTreeDatabase { await this.cleanup(); } - private async buildInitialHeader(): Promise
{ + private async buildInitialHeader(): Promise { const state = await this.getInitialStateReference(); - return Header.empty({ state }); + return BlockHeader.empty({ state }); } private sanitiseAndCacheSummaryFromFull(response: WorldStateStatusFull) { diff --git a/yarn-project/world-state/src/world-state-db/merkle_tree_operations_facade.ts b/yarn-project/world-state/src/world-state-db/merkle_tree_operations_facade.ts index a1b93999290..69f01189aef 100644 --- a/yarn-project/world-state/src/world-state-db/merkle_tree_operations_facade.ts +++ b/yarn-project/world-state/src/world-state-db/merkle_tree_operations_facade.ts @@ -6,7 +6,7 @@ import { type SequentialInsertionResult, type TreeInfo, } from '@aztec/circuit-types/interfaces'; -import { type Header, type StateReference } from '@aztec/circuits.js'; +import { type BlockHeader, type StateReference } from '@aztec/circuits.js'; import { type IndexedTreeLeafPreimage } from '@aztec/foundation/trees'; import { type MerkleTrees } from './merkle_trees.js'; @@ -39,7 +39,7 @@ export class MerkleTreeReadOperationsFacade implements MerkleTreeWriteOperations * Returns the initial header for the chain before the first block. * @returns The initial header. */ - getInitialHeader(): Header { + getInitialHeader(): BlockHeader { return this.trees.getInitialHeader(); } @@ -149,7 +149,7 @@ export class MerkleTreeReadOperationsFacade implements MerkleTreeWriteOperations * This includes all of the current roots of all of the data trees and the current blocks global vars. * @param header - The header to insert into the archive. */ - public updateArchive(header: Header): Promise { + public updateArchive(header: BlockHeader): Promise { return this.trees.updateArchive(header); } diff --git a/yarn-project/world-state/src/world-state-db/merkle_tree_snapshot_operations_facade.ts b/yarn-project/world-state/src/world-state-db/merkle_tree_snapshot_operations_facade.ts index 7f4e4bc9d6a..5e703e9c313 100644 --- a/yarn-project/world-state/src/world-state-db/merkle_tree_snapshot_operations_facade.ts +++ b/yarn-project/world-state/src/world-state-db/merkle_tree_snapshot_operations_facade.ts @@ -5,7 +5,13 @@ import { type MerkleTreeReadOperations, type TreeInfo, } from '@aztec/circuit-types/interfaces'; -import { AppendOnlyTreeSnapshot, Fr, type Header, PartialStateReference, StateReference } from '@aztec/circuits.js'; +import { + AppendOnlyTreeSnapshot, + type BlockHeader, + Fr, + PartialStateReference, + StateReference, +} from '@aztec/circuits.js'; import { type IndexedTreeLeafPreimage } from '@aztec/foundation/trees'; import { type IndexedTreeSnapshot } from '@aztec/merkle-tree'; @@ -136,7 +142,7 @@ export class MerkleTreeSnapshotOperationsFacade implements MerkleTreeReadOperati ); } - getInitialHeader(): Header { + getInitialHeader(): BlockHeader { throw new Error('Getting initial header not supported on snapshot.'); } } diff --git a/yarn-project/world-state/src/world-state-db/merkle_trees.ts b/yarn-project/world-state/src/world-state-db/merkle_trees.ts index 2842eebdae1..bb7bcd58a8d 100644 --- a/yarn-project/world-state/src/world-state-db/merkle_trees.ts +++ b/yarn-project/world-state/src/world-state-db/merkle_trees.ts @@ -10,8 +10,8 @@ import { import { ARCHIVE_HEIGHT, AppendOnlyTreeSnapshot, + BlockHeader, Fr, - Header, L1_TO_L2_MSG_TREE_HEIGHT, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, @@ -249,8 +249,8 @@ export class MerkleTrees implements MerkleTreeAdminDatabase { await this.store.delete(); } - public getInitialHeader(): Header { - return Header.empty({ state: this.#loadInitialStateReference() }); + public getInitialHeader(): BlockHeader { + return BlockHeader.empty({ state: this.#loadInitialStateReference() }); } /** @@ -285,7 +285,7 @@ export class MerkleTrees implements MerkleTreeAdminDatabase { * @param header - The header whose hash to insert into the archive. * @param includeUncommitted - Indicates whether to include uncommitted data. */ - public async updateArchive(header: Header) { + public async updateArchive(header: BlockHeader) { await this.synchronize(() => this.#updateArchive(header)); } @@ -519,7 +519,7 @@ export class MerkleTrees implements MerkleTreeAdminDatabase { return StateReference.fromBuffer(serialized); } - async #updateArchive(header: Header) { + async #updateArchive(header: BlockHeader) { const state = await this.getStateReference(true); // This method should be called only when the block builder already updated the state so we sanity check that it's