diff --git a/noir-projects/aztec-nr/aztec/src/context/avm_context.nr b/noir-projects/aztec-nr/aztec/src/context/avm_context.nr index 68925164b65a..34c3e9640006 100644 --- a/noir-projects/aztec-nr/aztec/src/context/avm_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/avm_context.nr @@ -78,7 +78,7 @@ impl PublicContextInterface for AVMContext { block_number() } - fn timestamp(self) -> Field { + fn timestamp(self) -> u64 { timestamp() } @@ -238,7 +238,7 @@ fn version() -> Field {} fn block_number() -> Field {} #[oracle(avmOpcodeTimestamp)] -fn timestamp() -> Field {} +fn timestamp() -> u64 {} #[oracle(avmOpcodeNoteHashExists)] fn note_hash_exists(note_hash: Field, leaf_index: Field) -> u8 {} diff --git a/noir-projects/aztec-nr/aztec/src/context/interface.nr b/noir-projects/aztec-nr/aztec/src/context/interface.nr index cc18ffba5708..c536ad02c08f 100644 --- a/noir-projects/aztec-nr/aztec/src/context/interface.nr +++ b/noir-projects/aztec-nr/aztec/src/context/interface.nr @@ -21,7 +21,7 @@ trait ContextInterface { // If you are adding something here, then you should also implement it in the AVMContext. trait PublicContextInterface { fn block_number(self) -> Field; - fn timestamp(self) -> Field; + fn timestamp(self) -> u64; fn coinbase(self) -> EthAddress; fn fee_recipient(self) -> AztecAddress; fn push_nullifier_read_request(&mut self, nullifier: Field); diff --git a/noir-projects/aztec-nr/aztec/src/context/public_context.nr b/noir-projects/aztec-nr/aztec/src/context/public_context.nr index dfca49a36959..1d2789d9a2c1 100644 --- a/noir-projects/aztec-nr/aztec/src/context/public_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/public_context.nr @@ -204,7 +204,7 @@ impl PublicContextInterface for PublicContext { self.inputs.public_global_variables.block_number } - fn timestamp(self) -> Field { + fn timestamp(self) -> u64 { self.inputs.public_global_variables.timestamp } diff --git a/noir-projects/aztec-nr/slow-updates-tree/src/slow_map.nr b/noir-projects/aztec-nr/slow-updates-tree/src/slow_map.nr index 641abcc16b49..ddfaf6bfa035 100644 --- a/noir-projects/aztec-nr/slow-updates-tree/src/slow_map.nr +++ b/noir-projects/aztec-nr/slow-updates-tree/src/slow_map.nr @@ -46,7 +46,7 @@ impl SlowMap { // Reads the "CURRENT" value of the root pub fn current_root(self: Self) -> Field { - let time = self.context.public.unwrap().timestamp() as u64; + let time = self.context.public.unwrap().timestamp(); let root_object = self.read_root(); if time <= root_object.next_change as u64 { root_object.before @@ -66,7 +66,7 @@ impl SlowMap { // docs:start:read_at // Reads the "CURRENT" value of the leaf pub fn read_at(self: Self, key: Field) -> Field { - let time = self.context.public.unwrap().timestamp() as u64; + let time = self.context.public.unwrap().timestamp(); let leaf = self.read_leaf_at(key); if time <= leaf.next_change as u64 { leaf.before @@ -87,7 +87,7 @@ impl SlowMap { // The calling function should ensure that the index is within the tree. // This must be done separately to ensure we are not constraining too tight here. - let time = self.context.public.unwrap().timestamp() as u64; + let time = self.context.public.unwrap().timestamp(); let next_change = compute_next_change(time as Field); let mut root = self.read_root(); @@ -132,7 +132,7 @@ impl SlowMap { // in public, limiting the cost of the update. pub fn update_unsafe_at(self: Self, index: Field, leaf_value: Field, new_root: Field) { // User must ensure that the checks from update_at is performed for safety - let time = self.context.public.unwrap().timestamp() as u64; + let time = self.context.public.unwrap().timestamp(); let next_change = compute_next_change(time as Field); let mut root = self.read_root(); diff --git a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr index 96081c707680..f6f628e848e7 100644 --- a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr @@ -223,7 +223,7 @@ contract AvmTest { } #[aztec(public-vm)] - fn get_timestamp() -> pub Field { + fn get_timestamp() -> pub u64 { context.timestamp() } diff --git a/noir-projects/noir-contracts/contracts/child_contract/src/main.nr b/noir-projects/noir-contracts/contracts/child_contract/src/main.nr index e9fdcc07ad80..0ba6c5946cff 100644 --- a/noir-projects/noir-contracts/contracts/child_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/child_contract/src/main.nr @@ -33,7 +33,7 @@ contract Child { + context.chain_id() + context.version() + context.block_number() - + context.timestamp(); + + context.timestamp() as Field; return_value } diff --git a/noir-projects/noir-contracts/contracts/crowdfunding_contract/src/main.nr b/noir-projects/noir-contracts/contracts/crowdfunding_contract/src/main.nr index 010bd593b5ef..a48a17e3da54 100644 --- a/noir-projects/noir-contracts/contracts/crowdfunding_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/crowdfunding_contract/src/main.nr @@ -44,7 +44,7 @@ contract Crowdfunding { #[aztec(internal)] fn _check_deadline() { let deadline = storage.deadline.read(); - assert(context.timestamp() as u64 < deadline, "Deadline has passed"); + assert(context.timestamp() < deadline, "Deadline has passed"); } #[aztec(private)] diff --git a/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr b/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr index 63e568edacd4..c43fbf2b3da0 100644 --- a/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr @@ -56,7 +56,7 @@ contract Lending { assert(asset.last_updated_ts == 0); assert(asset.interest_accumulator == U128::from_integer(0)); - let last_updated_ts = context.timestamp() as u64; + let last_updated_ts = context.timestamp(); asset_loc.write( Asset { interest_accumulator: U128::from_integer(1000000000), last_updated_ts, loan_to_value, oracle } @@ -72,7 +72,7 @@ contract Lending { let asset_loc = storage.assets.at(0); let mut asset = asset_loc.read(); - let timestamp = context.timestamp() as u64; + let timestamp = context.timestamp(); let dt = timestamp - asset.last_updated_ts; // Only update if time has passed. @@ -84,7 +84,7 @@ contract Lending { // accumulator *= multiplier, and multiplier >= 1 asset.interest_accumulator = (asset.interest_accumulator * multiplier) / precision; - asset.last_updated_ts = context.timestamp() as u64; + asset.last_updated_ts = context.timestamp(); asset_loc.write(asset); } diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index c4f81d0335ba..ea921b20d1a3 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -261,7 +261,7 @@ contract Test { // docs:start:is-time-equal #[aztec(public)] - fn is_time_equal(time: Field) -> Field { + fn is_time_equal(time: u64) -> u64 { assert(context.timestamp() == time); time } @@ -334,7 +334,7 @@ contract Test { chain_id: Field, version: Field, block_number: Field, - timestamp: Field, + timestamp: u64, coinbase: EthAddress, fee_recipient: AztecAddress ) { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr index 68097f779ee8..d636c867a3a8 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr @@ -10,7 +10,7 @@ struct GlobalVariables { chain_id : Field, version : Field, block_number : Field, - timestamp : Field, + timestamp : u64, coinbase : EthAddress, fee_recipient : AztecAddress, } @@ -22,7 +22,7 @@ impl Serialize for GlobalVariables { self.chain_id, self.version, self.block_number, - self.timestamp, + self.timestamp as Field, self.coinbase.to_field(), self.fee_recipient.to_field(), ] @@ -35,7 +35,7 @@ impl Deserialize for GlobalVariables { chain_id: serialized[0], version: serialized[1], block_number: serialized[2], - timestamp: serialized[3], + timestamp: serialized[3] as u64, coinbase: EthAddress::from_field(serialized[4]), fee_recipient: AztecAddress::from_field(serialized[5]), }