Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 4 additions & 4 deletions noir-projects/aztec-nr/aztec/src/context/utility_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ 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 {
self.contract_address
}

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<let N: u32>(self: Self, storage_slot: Field) -> [Field; N] {
Expand Down
6 changes: 3 additions & 3 deletions noir-projects/aztec-nr/aztec/src/oracle/block_header.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
);
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, InitialDelay> =
WithHash::historical_public_storage_read(header, address, self.storage_slot);

(values.svc, values.sdc, anchor_block_timestamp)
(values.svc, values.sdc, header.timestamp())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
});
}
Expand Down Expand Up @@ -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);

Expand All @@ -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,
);
});
}
Expand All @@ -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,
);
});
}
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading