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 3480487cf53e..a5121ac676eb 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -187,7 +187,7 @@ impl PrivateContext { is_fee_payer: false, args_hash, return_hash: 0, - expiration_timestamp: inputs.anchor_block_header.global_variables.timestamp + MAX_TX_LIFETIME, + expiration_timestamp: inputs.anchor_block_header.timestamp() + MAX_TX_LIFETIME, note_hash_read_requests: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), key_validation_requests_and_separators: BoundedVec::new(), diff --git a/noir-projects/aztec-nr/aztec/src/context/utility_context.nr b/noir-projects/aztec-nr/aztec/src/context/utility_context.nr index 859c3a331bc8..ce4891633a39 100644 --- a/noir-projects/aztec-nr/aztec/src/context/utility_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/utility_context.nr @@ -25,11 +25,11 @@ impl UtilityContext { } pub fn block_number(self) -> u32 { - self.block_header.global_variables.block_number + self.block_header.block_number() } pub fn timestamp(self) -> u64 { - self.block_header.global_variables.timestamp + self.block_header.timestamp() } pub fn this_address(self) -> AztecAddress { @@ -37,11 +37,11 @@ impl UtilityContext { } pub fn version(self) -> Field { - self.block_header.global_variables.version + self.block_header.version() } pub fn chain_id(self) -> Field { - self.block_header.global_variables.chain_id + self.block_header.chain_id() } pub unconstrained fn raw_storage_read(self: Self, storage_slot: Field) -> [Field; N] { diff --git a/noir-projects/aztec-nr/aztec/src/oracle/block_header.nr b/noir-projects/aztec-nr/aztec/src/oracle/block_header.nr index b64cc518a72e..99fd5edcbc77 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/block_header.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/block_header.nr @@ -11,7 +11,7 @@ unconstrained fn get_block_header_at_internal(block_number: u32) -> BlockHeader pub fn get_block_header_at(block_number: u32, context: PrivateContext) -> BlockHeader { let anchor_block_header = context.anchor_block_header; - let anchor_block_number = anchor_block_header.global_variables.block_number; + let anchor_block_number = anchor_block_header.block_number(); if (block_number == anchor_block_number) { // If the block number we want to prove against is the same as the block number in the historical header we @@ -68,7 +68,7 @@ fn constrain_get_block_header_at_internal( // 4) Check that the header hint has the same block number as the block number we are looking for, ensuring we are // actually grabbing the header we specify assert_eq( - header_hint.global_variables.block_number, + header_hint.block_number(), block_number, "Block number provided is not the same as the block number from the header hint", ); @@ -91,7 +91,7 @@ mod test { env.private_context(|context| { let anchor_block_header = context.anchor_block_header; - let target_block_number = anchor_block_header.global_variables.block_number - 2; + let target_block_number = anchor_block_header.block_number() - 2; let bad_header = get_block_header_at_internal(target_block_number); // We pass in a different block number than the header received diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/delayed_public_mutable.nr b/noir-projects/aztec-nr/aztec/src/state_vars/delayed_public_mutable.nr index 185953edabe4..3a1e884c05fe 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/delayed_public_mutable.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/delayed_public_mutable.nr @@ -507,12 +507,10 @@ where let header = self.context.get_anchor_block_header(); let address = self.context.this_address(); - let anchor_block_timestamp = header.global_variables.timestamp; - let values: DelayedPublicMutableValues = WithHash::historical_public_storage_read(header, address, self.storage_slot); - (values.svc, values.sdc, anchor_block_timestamp) + (values.svc, values.sdc, header.timestamp()) } } diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/delayed_public_mutable/test.nr b/noir-projects/aztec-nr/aztec/src/state_vars/delayed_public_mutable/test.nr index 1c10fd0e376e..8a190319d3fc 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/delayed_public_mutable/test.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/delayed_public_mutable/test.nr @@ -230,7 +230,7 @@ unconstrained fn get_current_value_in_private_initial() { assert_eq(state_var.get_current_value(), zeroed()); assert_eq( context.expiration_timestamp, - context.get_anchor_block_header().global_variables.timestamp + TEST_INITIAL_DELAY - 1, + context.get_anchor_block_header().timestamp() + TEST_INITIAL_DELAY - 1, ); }); } @@ -271,7 +271,7 @@ unconstrained fn get_current_value_in_private_immediately_before_change() { env.private_context(|context| { // Make sure we're at a block with the expected timestamp - assert_eq(context.get_anchor_block_header().global_variables.timestamp, timestamp_of_change - 1); + assert_eq(context.get_anchor_block_header().timestamp(), timestamp_of_change - 1); let state_var = in_private(context); @@ -298,14 +298,14 @@ unconstrained fn get_current_value_in_private_at_change() { env.private_context(|context| { // Make sure we're at a block with the expected timestamp - assert_eq(context.get_anchor_block_header().global_variables.timestamp, timestamp_of_change); + assert_eq(context.get_anchor_block_header().timestamp(), timestamp_of_change); let state_var = in_private(context); assert_eq(state_var.get_current_value(), new_value); assert_eq( context.expiration_timestamp, - context.get_anchor_block_header().global_variables.timestamp + TEST_INITIAL_DELAY - 1, + context.get_anchor_block_header().timestamp() + TEST_INITIAL_DELAY - 1, ); }); } @@ -326,14 +326,14 @@ unconstrained fn get_current_value_in_private_after_change() { env.private_context(|context| { // Make sure we're at a block with the expected timestamp - assert_eq(context.get_anchor_block_header().global_variables.timestamp, timestamp_of_change + 10); + assert_eq(context.get_anchor_block_header().timestamp(), timestamp_of_change + 10); let state_var = in_private(context); assert_eq(state_var.get_current_value(), new_value); assert_eq( context.expiration_timestamp, - context.get_anchor_block_header().global_variables.timestamp + TEST_INITIAL_DELAY - 1, + context.get_anchor_block_header().timestamp() + TEST_INITIAL_DELAY - 1, ); }); } @@ -356,7 +356,7 @@ unconstrained fn get_current_value_in_private_with_non_initial_delay() { env.private_context(|context| { // Make sure we're at a block with the expected timestamp - assert_eq(context.get_anchor_block_header().global_variables.timestamp, anchor_block_timestamp); + assert_eq(context.get_anchor_block_header().timestamp(), anchor_block_timestamp); let state_var = in_private(context); diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment/test/private_context.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment/test/private_context.nr index 095124c6b762..5d31ca1768a3 100644 --- a/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment/test/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment/test/private_context.nr @@ -24,14 +24,14 @@ unconstrained fn opts_sets_contract_address_and_anchor_block_number() { }); env.private_context_opts(PrivateContextOptions::new().at_anchor_block_number(anchor_block_number), |context| { - assert_eq(context.get_anchor_block_header().global_variables.block_number, anchor_block_number); + assert_eq(context.get_anchor_block_header().block_number(), anchor_block_number); }); env.private_context_opts( PrivateContextOptions::new().at_contract_address(contract_address).at_anchor_block_number(anchor_block_number), |context| { assert_eq(context.this_address(), contract_address); - assert_eq(context.get_anchor_block_header().global_variables.block_number, anchor_block_number); + assert_eq(context.get_anchor_block_header().block_number(), anchor_block_number); }, ); } @@ -42,19 +42,15 @@ unconstrained fn uses_last_block_number() { let last_block_number = env.last_block_number(); - env.private_context(|context| { - assert_eq(last_block_number, context.get_anchor_block_header().global_variables.block_number); - }); + env.private_context(|context| { assert_eq(last_block_number, context.get_anchor_block_header().block_number()); }); } #[test] unconstrained fn advances_block_number() { let env = TestEnvironment::new(); - let first_block_number = - env.private_context(|context| context.get_anchor_block_header().global_variables.block_number); - let second_block_number = - env.private_context(|context| context.get_anchor_block_header().global_variables.block_number); + let first_block_number = env.private_context(|context| context.get_anchor_block_header().block_number()); + let second_block_number = env.private_context(|context| context.get_anchor_block_header().block_number()); assert_eq(second_block_number, first_block_number + 1); } diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment/test/time.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment/test/time.nr index db1237105ded..514e2f175098 100644 --- a/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment/test/time.nr +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment/test/time.nr @@ -50,9 +50,7 @@ unconstrained fn set_next_block_timestamp_sets_next_private_context_inclusion_bl // Note that for private_context what is set is the timestamp of the block that'll be created with the effects // collected there - NOT the timestamp of the anchor block in the context, which corresponds to the last block's // timestamp. - env.private_context(|context| { - assert_eq(context.get_anchor_block_header().global_variables.timestamp, last_block_timestamp); - }); + env.private_context(|context| { assert_eq(context.get_anchor_block_header().timestamp(), last_block_timestamp); }); assert_eq(env.last_block_timestamp(), expected_next_block_timestamp); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/block_header.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/block_header.nr index 82a08efecd29..a23f002a14b2 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/block_header.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/block_header.nr @@ -28,6 +28,24 @@ pub struct BlockHeader { } // docs:end:block-header +impl BlockHeader { + pub fn chain_id(self) -> Field { + self.global_variables.chain_id + } + + pub fn version(self) -> Field { + self.global_variables.version + } + + pub fn block_number(self) -> u32 { + self.global_variables.block_number + } + + pub fn timestamp(self) -> u64 { + self.global_variables.timestamp + } +} + impl Empty for BlockHeader { fn empty() -> Self { Self {