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 544f99d30918..e80a263ee00d 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -6,15 +6,13 @@ use crate::{ oracle::{ block_header::get_block_header_at, call_private_function::call_private_function_internal, - enqueue_public_function_call::{ - is_side_effect_counter_revertible_oracle_wrapper, notify_enqueued_public_function_call, - notify_set_min_revertible_side_effect_counter, notify_set_public_teardown_function_call, - }, execution_cache, key_validation_request::get_key_validation_request, logs::notify_created_contract_class_log, notes::notify_nullified_note, nullifiers::notify_created_nullifier, + public_call::validate_public_calldata, + tx_phase::{in_revertible_phase, notify_revertible_phase_start}, }, }; use crate::logging::aztecnr_trace_log_format; @@ -536,7 +534,7 @@ impl PrivateContext { let current_counter = self.side_effect_counter; // Safety: Kernel will validate that the claim is correct by validating the expected counters. - let is_revertible = unsafe { is_side_effect_counter_revertible_oracle_wrapper(current_counter) }; + let is_revertible = unsafe { in_revertible_phase(current_counter) }; if is_revertible { if (self.expected_revertible_side_effect_counter == 0) @@ -579,7 +577,7 @@ impl PrivateContext { self.side_effect_counter += 1; aztecnr_trace_log_format!("Ending setup at counter {0}")([self.side_effect_counter as Field]); self.min_revertible_side_effect_counter = self.next_counter(); - notify_set_min_revertible_side_effect_counter(self.min_revertible_side_effect_counter); + notify_revertible_phase_start(self.min_revertible_side_effect_counter); } /// Sets a deadline (an "include-by timestamp") for when this transaction must be included in a block. @@ -1277,7 +1275,7 @@ impl PrivateContext { let is_static_call = is_static_call | self.inputs.call_context.is_static_call; - notify_enqueued_public_function_call(contract_address, calldata_hash, counter, is_static_call); + validate_public_calldata(calldata_hash); let msg_sender = if hide_msg_sender { NULL_MSG_SENDER_CONTRACT_ADDRESS @@ -1346,11 +1344,9 @@ impl PrivateContext { is_static_call: bool, hide_msg_sender: bool, ) { - let counter = self.next_counter(); - let is_static_call = is_static_call | self.inputs.call_context.is_static_call; - notify_set_public_teardown_function_call(contract_address, calldata_hash, counter, is_static_call); + validate_public_calldata(calldata_hash); let msg_sender = if hide_msg_sender { NULL_MSG_SENDER_CONTRACT_ADDRESS diff --git a/noir-projects/aztec-nr/aztec/src/history/note.nr b/noir-projects/aztec-nr/aztec/src/history/note.nr index de62753b9248..8239eb85c65d 100644 --- a/noir-projects/aztec-nr/aztec/src/history/note.nr +++ b/noir-projects/aztec-nr/aztec/src/history/note.nr @@ -36,7 +36,7 @@ where // don't even care _where_ in the tree it is stored. This is because entries in the note hash tree are unique. assert_eq( block_header.state.partial.note_hash_tree.root, - root_from_sibling_path(unique_note_hash, witness.index, witness.path), + root_from_sibling_path(unique_note_hash, witness.leaf_index, witness.sibling_path), "Proving note inclusion failed", ); diff --git a/noir-projects/aztec-nr/aztec/src/messages/processing/mod.nr b/noir-projects/aztec-nr/aztec/src/messages/processing/mod.nr index 3f7fa63a0291..06c89b7bd84a 100644 --- a/noir-projects/aztec-nr/aztec/src/messages/processing/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/messages/processing/mod.nr @@ -154,6 +154,8 @@ pub unconstrained fn validate_and_store_enqueued_notes_and_events(contract_addre contract_address, NOTE_VALIDATION_REQUESTS_ARRAY_BASE_SLOT, EVENT_VALIDATION_REQUESTS_ARRAY_BASE_SLOT, + MAX_NOTE_PACKED_LEN as Field, + MAX_EVENT_SERIALIZED_LEN as Field, ); } diff --git a/noir-projects/aztec-nr/aztec/src/note/note_metadata.nr b/noir-projects/aztec-nr/aztec/src/note/note_metadata.nr index cf5286556e54..0a135970cb89 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_metadata.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_metadata.nr @@ -83,8 +83,7 @@ impl NoteMetadata { } /// Returns `true` if the note is settled, i.e. if it's been created in a prior transaction and is therefore - /// already - /// in the note hash tree. + /// already in the note hash tree. pub fn is_settled(self) -> bool { self.stage == NoteStage.SETTLED } 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 ea2afd317baa..d1f7b81243e2 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/block_header.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/block_header.nr @@ -61,7 +61,7 @@ fn constrain_get_block_header_at_internal( // 3) Check that the block is in the archive (i.e. the witness is valid) assert_eq( anchor_block_header.last_archive.root, - root_from_sibling_path(block_hash, witness.index, witness.path), + root_from_sibling_path(block_hash, witness.leaf_index, witness.sibling_path), "Proving membership of a block in archive failed", ); diff --git a/noir-projects/aztec-nr/aztec/src/oracle/enqueue_public_function_call.nr b/noir-projects/aztec-nr/aztec/src/oracle/enqueue_public_function_call.nr deleted file mode 100644 index 0ac1ab8d10bb..000000000000 --- a/noir-projects/aztec-nr/aztec/src/oracle/enqueue_public_function_call.nr +++ /dev/null @@ -1,101 +0,0 @@ -use crate::protocol::address::AztecAddress; - -#[oracle(aztec_prv_notifyEnqueuedPublicFunctionCall)] -unconstrained fn notify_enqueued_public_function_call_oracle( - _contract_address: AztecAddress, - _calldata_hash: Field, - _side_effect_counter: u32, - _is_static_call: bool, -) {} - -unconstrained fn notify_enqueued_public_function_call_wrapper( - contract_address: AztecAddress, - calldata_hash: Field, - side_effect_counter: u32, - is_static_call: bool, -) { - notify_enqueued_public_function_call_oracle( - contract_address, - calldata_hash, - side_effect_counter, - is_static_call, - ) -} - -pub fn notify_enqueued_public_function_call( - contract_address: AztecAddress, - calldata_hash: Field, - side_effect_counter: u32, - is_static_call: bool, -) { - // Safety: Notifies the simulator that a public call has been enqueued, allowing it to prepare hints for the AVM to - // process this call. - unsafe { - notify_enqueued_public_function_call_wrapper( - contract_address, - calldata_hash, - side_effect_counter, - is_static_call, - ) - } -} - -#[oracle(aztec_prv_notifySetPublicTeardownFunctionCall)] -unconstrained fn notify_set_public_teardown_function_call_oracle( - _contract_address: AztecAddress, - _calldata_hash: Field, - _side_effect_counter: u32, - _is_static_call: bool, -) {} - -unconstrained fn notify_set_public_teardown_function_call_wrapper( - contract_address: AztecAddress, - calldata_hash: Field, - side_effect_counter: u32, - is_static_call: bool, -) { - notify_set_public_teardown_function_call_oracle( - contract_address, - calldata_hash, - side_effect_counter, - is_static_call, - ) -} - -pub fn notify_set_public_teardown_function_call( - contract_address: AztecAddress, - calldata_hash: Field, - side_effect_counter: u32, - is_static_call: bool, -) { - // Safety: Notifies the simulator that a teardown call has been set, allowing it to prepare hints for the AVM to - // process this call. - unsafe { - notify_set_public_teardown_function_call_wrapper( - contract_address, - calldata_hash, - side_effect_counter, - is_static_call, - ) - } -} - -pub fn notify_set_min_revertible_side_effect_counter(counter: u32) { - // Safety: This oracle call returns nothing: we only call it for its side effects. It is therefore always safe to - // call. - unsafe { notify_set_min_revertible_side_effect_counter_oracle_wrapper(counter) }; -} - -pub unconstrained fn notify_set_min_revertible_side_effect_counter_oracle_wrapper(counter: u32) { - notify_set_min_revertible_side_effect_counter_oracle(counter); -} - -#[oracle(aztec_prv_notifySetMinRevertibleSideEffectCounter)] -unconstrained fn notify_set_min_revertible_side_effect_counter_oracle(_counter: u32) {} - -pub unconstrained fn is_side_effect_counter_revertible_oracle_wrapper(counter: u32) -> bool { - is_side_effect_counter_revertible_oracle(counter) -} - -#[oracle(aztec_prv_isSideEffectCounterRevertible)] -unconstrained fn is_side_effect_counter_revertible_oracle(counter: u32) -> bool {} diff --git a/noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr b/noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr index 90f83ad6f9df..8c1783f085b3 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr @@ -1,33 +1,21 @@ use crate::protocol::{ abis::block_header::BlockHeader, constants::{ARCHIVE_HEIGHT, NOTE_HASH_TREE_HEIGHT}, - traits::{Deserialize, Hash, Serialize}, + merkle_tree::MembershipWitness, + traits::Hash, }; -// Note: We have M here because we need to somehow set it when calling get_membership_witness function and one way to -// do it is to set M here and then set type of the return param, e.g.: -// -// `let witness: MembershipWitness = get_membership_witness(...);` -// -// Another way to do it would be to add "type_hint: [Field; T]" as argument to `get_membership_witness` but that's a -// bit too boilerplatey for my taste. -#[derive(Deserialize, Eq, Serialize)] -pub struct MembershipWitness { - pub index: Field, - pub path: [Field; N], -} - #[oracle(aztec_utl_getNoteHashMembershipWitness)] unconstrained fn get_note_hash_membership_witness_oracle( anchor_block_hash: Field, note_hash: Field, -) -> MembershipWitness {} +) -> MembershipWitness {} #[oracle(aztec_utl_getBlockHashMembershipWitness)] unconstrained fn get_block_hash_membership_witness_oracle( anchor_block_hash: Field, block_hash: Field, -) -> MembershipWitness {} +) -> MembershipWitness {} // Note: get_nullifier_membership_witness function is implemented in get_nullifier_membership_witness.nr @@ -36,7 +24,7 @@ unconstrained fn get_block_hash_membership_witness_oracle( pub unconstrained fn get_note_hash_membership_witness( anchor_block_header: BlockHeader, note_hash: Field, -) -> MembershipWitness { +) -> MembershipWitness { let anchor_block_hash = anchor_block_header.hash(); get_note_hash_membership_witness_oracle(anchor_block_hash, note_hash) } @@ -48,7 +36,7 @@ pub unconstrained fn get_note_hash_membership_witness( pub unconstrained fn get_block_hash_membership_witness( anchor_block_header: BlockHeader, block_hash: Field, -) -> MembershipWitness { +) -> MembershipWitness { let anchor_block_hash = anchor_block_header.hash(); get_block_hash_membership_witness_oracle(anchor_block_hash, block_hash) } diff --git a/noir-projects/aztec-nr/aztec/src/oracle/get_nullifier_membership_witness.nr b/noir-projects/aztec-nr/aztec/src/oracle/get_nullifier_membership_witness.nr index c6712ba82416..f7b6002f89ff 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/get_nullifier_membership_witness.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/get_nullifier_membership_witness.nr @@ -17,8 +17,12 @@ unconstrained fn get_low_nullifier_membership_witness_oracle( _nullifier: Field, ) -> NullifierMembershipWitness {} -// Nullifier here refers to the nullifier we are looking to get non-inclusion proof for (by proving that a lower -// nullifier's next_value is bigger than the nullifier) +/// Returns a membership witness for the low nullifier of `nullifier` in the nullifier tree whose root is defined in +/// `block_header`. +/// +/// The low nullifier is the leaf with the largest value that is still smaller than `nullifier`. This is used to prove +/// non-inclusion: if the low nullifier's `next_value` is greater than `nullifier`, then `nullifier` is not in the +/// tree. pub unconstrained fn get_low_nullifier_membership_witness( block_header: BlockHeader, nullifier: Field, @@ -33,8 +37,9 @@ unconstrained fn get_nullifier_membership_witness_oracle( _nullifier: Field, ) -> NullifierMembershipWitness {} -// Nullifier here refers to the nullifier we are looking to get non-inclusion proof for (by proving that a lower -// nullifier's next_value is bigger than the nullifier) +/// Returns a membership witness for `nullifier` in the nullifier tree whose root is defined in `block_header`. +/// +/// This is used to prove that a nullifier exists in the tree (inclusion proof). pub unconstrained fn get_nullifier_membership_witness( block_header: BlockHeader, nullifier: Field, diff --git a/noir-projects/aztec-nr/aztec/src/oracle/message_processing.nr b/noir-projects/aztec-nr/aztec/src/oracle/message_processing.nr index 76052860bffe..e6f5473f4be4 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/message_processing.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/message_processing.nr @@ -15,11 +15,15 @@ pub(crate) unconstrained fn validate_and_store_enqueued_notes_and_events( contract_address: AztecAddress, note_validation_requests_array_base_slot: Field, event_validation_requests_array_base_slot: Field, + max_note_packed_len: Field, + max_event_serialized_len: Field, ) { validate_and_store_enqueued_notes_and_events_oracle( contract_address, note_validation_requests_array_base_slot, event_validation_requests_array_base_slot, + max_note_packed_len, + max_event_serialized_len, ); } @@ -28,6 +32,8 @@ unconstrained fn validate_and_store_enqueued_notes_and_events_oracle( contract_address: AztecAddress, note_validation_requests_array_base_slot: Field, event_validation_requests_array_base_slot: Field, + max_note_packed_len: Field, + max_event_serialized_len: Field, ) {} pub(crate) unconstrained fn bulk_retrieve_logs( diff --git a/noir-projects/aztec-nr/aztec/src/oracle/mod.nr b/noir-projects/aztec-nr/aztec/src/oracle/mod.nr index 89de82720a7d..d167b1967109 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/mod.nr @@ -10,7 +10,8 @@ pub mod auth_witness; pub mod block_header; pub mod call_private_function; pub mod capsules; -pub mod enqueue_public_function_call; +pub mod public_call; +pub mod tx_phase; pub mod execution; pub mod execution_cache; pub mod get_contract_instance; diff --git a/noir-projects/aztec-nr/aztec/src/oracle/public_call.nr b/noir-projects/aztec-nr/aztec/src/oracle/public_call.nr new file mode 100644 index 000000000000..055aa3048d69 --- /dev/null +++ b/noir-projects/aztec-nr/aztec/src/oracle/public_call.nr @@ -0,0 +1,18 @@ +/// Validates public calldata by checking that the preimage exists and the cumulative size is within limits. +/// +/// The check is unconstrained and the only purpose of it is to fail early in case of calldata overflow or a bug in +/// calldata hashing. +pub(crate) fn validate_public_calldata(calldata_hash: Field) { + // Safety: This oracle call returns nothing: we only call it for its side effects (validating the calldata). + // It is therefore always safe to call. + unsafe { + validate_public_calldata_wrapper(calldata_hash) + } +} + +unconstrained fn validate_public_calldata_wrapper(calldata_hash: Field) { + validate_public_calldata_oracle(calldata_hash) +} + +#[oracle(aztec_prv_validatePublicCalldata)] +unconstrained fn validate_public_calldata_oracle(_calldata_hash: Field) {} diff --git a/noir-projects/aztec-nr/aztec/src/oracle/tx_phase.nr b/noir-projects/aztec-nr/aztec/src/oracle/tx_phase.nr new file mode 100644 index 000000000000..207e2fb26030 --- /dev/null +++ b/noir-projects/aztec-nr/aztec/src/oracle/tx_phase.nr @@ -0,0 +1,24 @@ +/// Notifies PXE of the side effect counter at which the revertible phase begins. +/// +/// PXE uses it to classify notes and nullifiers as revertible or non-revertible in its note cache. This information is +/// then fed to kernels as hints. +pub(crate) fn notify_revertible_phase_start(counter: u32) { + // Safety: This oracle call returns nothing: we only call it for its side effects. It is therefore always safe to + // call. + unsafe { notify_revertible_phase_start_oracle_wrapper(counter) }; +} + +/// Returns whether a side effect counter falls in the revertible phase of the transaction. +pub(crate) unconstrained fn in_revertible_phase(current_counter: u32) -> bool { + in_revertible_phase_oracle(current_counter) +} + +unconstrained fn notify_revertible_phase_start_oracle_wrapper(counter: u32) { + notify_revertible_phase_start_oracle(counter); +} + +#[oracle(aztec_prv_notifyRevertiblePhaseStart)] +unconstrained fn notify_revertible_phase_start_oracle(_counter: u32) {} + +#[oracle(aztec_prv_inRevertiblePhase)] +unconstrained fn in_revertible_phase_oracle(current_counter: u32) -> bool {} diff --git a/noir-projects/aztec-nr/aztec/src/oracle/version.nr b/noir-projects/aztec-nr/aztec/src/oracle/version.nr index e3040821aa8a..fd38a120f438 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/version.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/version.nr @@ -3,9 +3,8 @@ /// versions of Aztec.nr and PXE. The TypeScript counterpart is in `oracle_version.ts`. /// /// @dev Whenever a contract function or Noir test is run, the `aztec_utl_assertCompatibleOracleVersion` oracle is -/// called -/// and if the oracle version is incompatible an error is thrown. -pub global ORACLE_VERSION: Field = 14; +/// called and if the oracle version is incompatible an error is thrown. +pub global ORACLE_VERSION: Field = 15; /// Asserts that the version of the oracle is compatible with the version expected by the contract. pub fn assert_compatible_oracle_version() { diff --git a/noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/context/private_context.nr b/noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/context/private_context.nr index 7f9cfebddda5..9e4db446dabe 100644 --- a/noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/context/private_context.nr +++ b/noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/context/private_context.nr @@ -4,10 +4,8 @@ use crate::{ messaging::process_l1_to_l2_message, oracle::{ call_private_function::call_private_function_internal, - enqueue_public_function_call::{ - is_side_effect_counter_revertible_oracle_wrapper, notify_enqueued_public_function_call, - notify_set_min_revertible_side_effect_counter, - }, + public_call::validate_public_calldata, + tx_phase::{in_revertible_phase, notify_revertible_phase_start}, execution_cache, logs::notify_created_contract_class_log, nullifiers::notify_created_nullifier, @@ -190,7 +188,7 @@ impl PrivateContext { pub fn end_setup(&mut self) { self.side_effect_counter += 1; self.min_revertible_side_effect_counter = self.next_counter(); - notify_set_min_revertible_side_effect_counter(self.min_revertible_side_effect_counter); + notify_revertible_phase_start(self.min_revertible_side_effect_counter); } pub fn in_revertible_phase(&mut self) -> bool { @@ -198,7 +196,7 @@ impl PrivateContext { // Safety: Kernel will validate that the claim is correct by validating the expected counters. let is_revertible = - unsafe { is_side_effect_counter_revertible_oracle_wrapper(current_counter) }; + unsafe { in_revertible_phase(current_counter) }; if is_revertible { if (self.expected_revertible_side_effect_counter == 0) @@ -364,14 +362,9 @@ impl PrivateContext { ) { let counter = self.next_counter(); - let mut is_static_call = is_static_call | self.inputs.call_context.is_static_call; + let is_static_call = is_static_call | self.inputs.call_context.is_static_call; - notify_enqueued_public_function_call( - contract_address, - calldata_hash, - counter, - is_static_call, - ); + validate_public_calldata(calldata_hash); let msg_sender = if hide_msg_sender { NULL_MSG_SENDER_CONTRACT_ADDRESS diff --git a/noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/oracle/enqueue_public_function_call.nr b/noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/oracle/enqueue_public_function_call.nr deleted file mode 100644 index 0ac1ab8d10bb..000000000000 --- a/noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/oracle/enqueue_public_function_call.nr +++ /dev/null @@ -1,101 +0,0 @@ -use crate::protocol::address::AztecAddress; - -#[oracle(aztec_prv_notifyEnqueuedPublicFunctionCall)] -unconstrained fn notify_enqueued_public_function_call_oracle( - _contract_address: AztecAddress, - _calldata_hash: Field, - _side_effect_counter: u32, - _is_static_call: bool, -) {} - -unconstrained fn notify_enqueued_public_function_call_wrapper( - contract_address: AztecAddress, - calldata_hash: Field, - side_effect_counter: u32, - is_static_call: bool, -) { - notify_enqueued_public_function_call_oracle( - contract_address, - calldata_hash, - side_effect_counter, - is_static_call, - ) -} - -pub fn notify_enqueued_public_function_call( - contract_address: AztecAddress, - calldata_hash: Field, - side_effect_counter: u32, - is_static_call: bool, -) { - // Safety: Notifies the simulator that a public call has been enqueued, allowing it to prepare hints for the AVM to - // process this call. - unsafe { - notify_enqueued_public_function_call_wrapper( - contract_address, - calldata_hash, - side_effect_counter, - is_static_call, - ) - } -} - -#[oracle(aztec_prv_notifySetPublicTeardownFunctionCall)] -unconstrained fn notify_set_public_teardown_function_call_oracle( - _contract_address: AztecAddress, - _calldata_hash: Field, - _side_effect_counter: u32, - _is_static_call: bool, -) {} - -unconstrained fn notify_set_public_teardown_function_call_wrapper( - contract_address: AztecAddress, - calldata_hash: Field, - side_effect_counter: u32, - is_static_call: bool, -) { - notify_set_public_teardown_function_call_oracle( - contract_address, - calldata_hash, - side_effect_counter, - is_static_call, - ) -} - -pub fn notify_set_public_teardown_function_call( - contract_address: AztecAddress, - calldata_hash: Field, - side_effect_counter: u32, - is_static_call: bool, -) { - // Safety: Notifies the simulator that a teardown call has been set, allowing it to prepare hints for the AVM to - // process this call. - unsafe { - notify_set_public_teardown_function_call_wrapper( - contract_address, - calldata_hash, - side_effect_counter, - is_static_call, - ) - } -} - -pub fn notify_set_min_revertible_side_effect_counter(counter: u32) { - // Safety: This oracle call returns nothing: we only call it for its side effects. It is therefore always safe to - // call. - unsafe { notify_set_min_revertible_side_effect_counter_oracle_wrapper(counter) }; -} - -pub unconstrained fn notify_set_min_revertible_side_effect_counter_oracle_wrapper(counter: u32) { - notify_set_min_revertible_side_effect_counter_oracle(counter); -} - -#[oracle(aztec_prv_notifySetMinRevertibleSideEffectCounter)] -unconstrained fn notify_set_min_revertible_side_effect_counter_oracle(_counter: u32) {} - -pub unconstrained fn is_side_effect_counter_revertible_oracle_wrapper(counter: u32) -> bool { - is_side_effect_counter_revertible_oracle(counter) -} - -#[oracle(aztec_prv_isSideEffectCounterRevertible)] -unconstrained fn is_side_effect_counter_revertible_oracle(counter: u32) -> bool {} diff --git a/noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/oracle/mod.nr b/noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/oracle/mod.nr index 9e11d55f614c..1d62eb777f5e 100644 --- a/noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/oracle/mod.nr +++ b/noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/oracle/mod.nr @@ -7,7 +7,8 @@ pub mod storage; pub mod execution; pub mod get_l1_to_l2_membership_witness; pub mod nullifiers; -pub mod enqueue_public_function_call; +pub mod public_call; +pub mod tx_phase; pub mod call_private_function; pub mod logs; diff --git a/noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/oracle/public_call.nr b/noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/oracle/public_call.nr new file mode 100644 index 000000000000..055aa3048d69 --- /dev/null +++ b/noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/oracle/public_call.nr @@ -0,0 +1,18 @@ +/// Validates public calldata by checking that the preimage exists and the cumulative size is within limits. +/// +/// The check is unconstrained and the only purpose of it is to fail early in case of calldata overflow or a bug in +/// calldata hashing. +pub(crate) fn validate_public_calldata(calldata_hash: Field) { + // Safety: This oracle call returns nothing: we only call it for its side effects (validating the calldata). + // It is therefore always safe to call. + unsafe { + validate_public_calldata_wrapper(calldata_hash) + } +} + +unconstrained fn validate_public_calldata_wrapper(calldata_hash: Field) { + validate_public_calldata_oracle(calldata_hash) +} + +#[oracle(aztec_prv_validatePublicCalldata)] +unconstrained fn validate_public_calldata_oracle(_calldata_hash: Field) {} diff --git a/noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/oracle/tx_phase.nr b/noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/oracle/tx_phase.nr new file mode 100644 index 000000000000..207e2fb26030 --- /dev/null +++ b/noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/oracle/tx_phase.nr @@ -0,0 +1,24 @@ +/// Notifies PXE of the side effect counter at which the revertible phase begins. +/// +/// PXE uses it to classify notes and nullifiers as revertible or non-revertible in its note cache. This information is +/// then fed to kernels as hints. +pub(crate) fn notify_revertible_phase_start(counter: u32) { + // Safety: This oracle call returns nothing: we only call it for its side effects. It is therefore always safe to + // call. + unsafe { notify_revertible_phase_start_oracle_wrapper(counter) }; +} + +/// Returns whether a side effect counter falls in the revertible phase of the transaction. +pub(crate) unconstrained fn in_revertible_phase(current_counter: u32) -> bool { + in_revertible_phase_oracle(current_counter) +} + +unconstrained fn notify_revertible_phase_start_oracle_wrapper(counter: u32) { + notify_revertible_phase_start_oracle(counter); +} + +#[oracle(aztec_prv_notifyRevertiblePhaseStart)] +unconstrained fn notify_revertible_phase_start_oracle(_counter: u32) {} + +#[oracle(aztec_prv_inRevertiblePhase)] +unconstrained fn in_revertible_phase_oracle(current_counter: u32) -> bool {} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr index 22f45f274ada..effc0aa23b6f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr @@ -4,10 +4,10 @@ use crate::{ leaf_preimage::IndexedTreeLeafPreimage, root::{root_from_sibling_path, root_from_sibling_path_with_hasher}, }, - traits::Empty, + traits::{Deserialize, Empty, Serialize}, }; -#[derive(Eq)] +#[derive(Deserialize, Eq, Serialize)] pub struct MembershipWitness { pub leaf_index: Field, pub sibling_path: [Field; N], diff --git a/yarn-project/pxe/src/contract_function_simulator/noir-structs/event_validation_request.test.ts b/yarn-project/pxe/src/contract_function_simulator/noir-structs/event_validation_request.test.ts index 63816730790f..3b5d2ad06725 100644 --- a/yarn-project/pxe/src/contract_function_simulator/noir-structs/event_validation_request.test.ts +++ b/yarn-project/pxe/src/contract_function_simulator/noir-structs/event_validation_request.test.ts @@ -27,7 +27,7 @@ describe('EventValidationRequest', () => { 8, // recipient ].map(n => new Fr(n)); - const request = EventValidationRequest.fromFields(serialized); + const request = EventValidationRequest.fromFields(serialized, 10); expect(request.contractAddress).toEqual(AztecAddress.fromBigInt(1n)); expect(request.eventTypeId).toEqual(new EventSelector(2)); @@ -37,4 +37,31 @@ describe('EventValidationRequest', () => { expect(request.txHash).toEqual(TxHash.fromBigInt(7n)); expect(request.recipient).toEqual(AztecAddress.fromBigInt(8n)); }); + + it('throws if fed more fields than expected', () => { + const serialized = [ + 1, // contract_address + 2, // event_type_id + 3, // randomness + 4, // serialized_event[0] + 5, // serialized_event[1] + 0, // serialized_event padding (11 storage fields total, but maxEventSerializedLen=10) + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, // bounded_vec_len + 6, // event_commitment + 7, // tx_hash + 8, // recipient + ].map(n => new Fr(n)); + + expect(() => EventValidationRequest.fromFields(serialized, 10)).toThrow( + 'Error converting array of fields to EventValidationRequest: expected 17 fields but received 18 (maxEventSerializedLen=10).', + ); + }); }); diff --git a/yarn-project/pxe/src/contract_function_simulator/noir-structs/event_validation_request.ts b/yarn-project/pxe/src/contract_function_simulator/noir-structs/event_validation_request.ts index 8a33dd551923..ccf4b7a944ae 100644 --- a/yarn-project/pxe/src/contract_function_simulator/noir-structs/event_validation_request.ts +++ b/yarn-project/pxe/src/contract_function_simulator/noir-structs/event_validation_request.ts @@ -4,9 +4,6 @@ import { EventSelector } from '@aztec/stdlib/abi'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; import { TxHash } from '@aztec/stdlib/tx'; -// TODO(#14617): should we compute this from constants? This value is aztec-nr specific. -const MAX_EVENT_SERIALIZED_LEN = 10; - /** * Intermediate struct used to perform batch event validation by PXE. The `utilityValidateAndStoreEnqueuedNotesAndEvents` oracle * expects for values of this type to be stored in a `CapsuleArray`. @@ -22,7 +19,7 @@ export class EventValidationRequest { public recipient: AztecAddress, ) {} - static fromFields(fields: Fr[] | FieldReader): EventValidationRequest { + static fromFields(fields: Fr[], maxEventSerializedLen: number): EventValidationRequest { const reader = FieldReader.asReader(fields); const contractAddress = AztecAddress.fromField(reader.readField()); @@ -30,7 +27,7 @@ export class EventValidationRequest { const randomness = reader.readField(); - const eventStorage = reader.readFieldArray(MAX_EVENT_SERIALIZED_LEN); + const eventStorage = reader.readFieldArray(maxEventSerializedLen); const eventLen = reader.readField().toNumber(); const serializedEvent = eventStorage.slice(0, eventLen); @@ -38,6 +35,12 @@ export class EventValidationRequest { const txHash = TxHash.fromField(reader.readField()); const recipient = AztecAddress.fromField(reader.readField()); + if (reader.remainingFields() !== 0) { + throw new Error( + `Error converting array of fields to EventValidationRequest: expected ${reader.cursor} fields but received ${fields.length} (maxEventSerializedLen=${maxEventSerializedLen}).`, + ); + } + return new EventValidationRequest( contractAddress, eventTypeId, diff --git a/yarn-project/pxe/src/contract_function_simulator/noir-structs/log_retrieval_response.ts b/yarn-project/pxe/src/contract_function_simulator/noir-structs/log_retrieval_response.ts index 020270e8821a..baa4b3c58e39 100644 --- a/yarn-project/pxe/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +++ b/yarn-project/pxe/src/contract_function_simulator/noir-structs/log_retrieval_response.ts @@ -3,10 +3,7 @@ import { range } from '@aztec/foundation/array'; import { Fr } from '@aztec/foundation/curves/bn254'; import type { TxHash } from '@aztec/stdlib/tx'; -import { MAX_NOTE_PACKED_LEN } from './note_validation_request.js'; - -const MAX_PUBLIC_LOG_LEN_FOR_NOTE_COMPLETION = MAX_NOTE_PACKED_LEN; -const MAX_LOG_CONTENT_LEN = Math.max(MAX_PUBLIC_LOG_LEN_FOR_NOTE_COMPLETION, PRIVATE_LOG_CIPHERTEXT_LEN); +const MAX_LOG_CONTENT_LEN = PRIVATE_LOG_CIPHERTEXT_LEN; /** * Intermediate struct used to perform batch log retrieval by PXE. The `utilityBulkRetrieveLogs` oracle stores values of this diff --git a/yarn-project/pxe/src/contract_function_simulator/noir-structs/note_validation_request.test.ts b/yarn-project/pxe/src/contract_function_simulator/noir-structs/note_validation_request.test.ts index 4ac64de1d016..686d57c0e74a 100644 --- a/yarn-project/pxe/src/contract_function_simulator/noir-structs/note_validation_request.test.ts +++ b/yarn-project/pxe/src/contract_function_simulator/noir-structs/note_validation_request.test.ts @@ -19,7 +19,7 @@ describe('NoteValidationRequest', () => { '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000', - '0x0000000000000000000000000000000000000000000000000000000000000000', // content end (MAX_NOTE_PACKED_LEN = 8) + '0x0000000000000000000000000000000000000000000000000000000000000000', // content end (8 storage fields) '0x0000000000000000000000000000000000000000000000000000000000000002', // content length '0x0000000000000000000000000000000000000000000000000000000000000006', // note hash '0x0000000000000000000000000000000000000000000000000000000000000007', // nullifier @@ -27,7 +27,7 @@ describe('NoteValidationRequest', () => { '0x0000000000000000000000000000000000000000000000000000000000000009', // recipient ].map(Fr.fromHexString); - const request = NoteValidationRequest.fromFields(serialized); + const request = NoteValidationRequest.fromFields(serialized, 8); expect(request.contractAddress).toEqual(AztecAddress.fromBigInt(1n)); expect(request.owner).toEqual(AztecAddress.fromBigInt(50n)); @@ -56,8 +56,7 @@ describe('NoteValidationRequest', () => { '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000', - '0x0000000000000000000000000000000000000000000000000000000000000000', // content end (MAX_NOTE_PACKED_LEN = 8) - '0x0000000000000000000000000000000000000000000000000000000000000000', // extra field beyond MAX_NOTE_PACKED_LEN, this is a malformed serialization + '0x0000000000000000000000000000000000000000000000000000000000000000', // content end (9 storage fields, but maxNotePackedLen=8) '0x0000000000000000000000000000000000000000000000000000000000000002', // content length '0x0000000000000000000000000000000000000000000000000000000000000006', // note hash '0x0000000000000000000000000000000000000000000000000000000000000007', // nullifier @@ -65,8 +64,8 @@ describe('NoteValidationRequest', () => { '0x0000000000000000000000000000000000000000000000000000000000000009', // recipient ].map(Fr.fromHexString); - expect(() => NoteValidationRequest.fromFields(serialized)).toThrow( - /Error converting array of fields to NoteValidationRequest/, + expect(() => NoteValidationRequest.fromFields(serialized, 8)).toThrow( + 'Error converting array of fields to NoteValidationRequest: expected 18 fields but received 19 (maxNotePackedLen=8).', ); }); }); diff --git a/yarn-project/pxe/src/contract_function_simulator/noir-structs/note_validation_request.ts b/yarn-project/pxe/src/contract_function_simulator/noir-structs/note_validation_request.ts index 02ebba99e96e..286ad25ef377 100644 --- a/yarn-project/pxe/src/contract_function_simulator/noir-structs/note_validation_request.ts +++ b/yarn-project/pxe/src/contract_function_simulator/noir-structs/note_validation_request.ts @@ -3,9 +3,6 @@ import { FieldReader } from '@aztec/foundation/serialize'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; import { TxHash } from '@aztec/stdlib/tx'; -// TODO(#14617): should we compute this from constants? This value is aztec-nr specific. -export const MAX_NOTE_PACKED_LEN = 8; - /** * Intermediate struct used to perform batch note validation by PXE. The `utilityValidateAndStoreEnqueuedNotesAndEvents` oracle * expects for values of this type to be stored in a `CapsuleArray`. @@ -24,7 +21,7 @@ export class NoteValidationRequest { public recipient: AztecAddress, ) {} - static fromFields(fields: Fr[] | FieldReader): NoteValidationRequest { + static fromFields(fields: Fr[], maxNotePackedLen: number): NoteValidationRequest { const reader = FieldReader.asReader(fields); const contractAddress = AztecAddress.fromField(reader.readField()); @@ -33,7 +30,7 @@ export class NoteValidationRequest { const randomness = reader.readField(); const noteNonce = reader.readField(); - const contentStorage = reader.readFieldArray(MAX_NOTE_PACKED_LEN); + const contentStorage = reader.readFieldArray(maxNotePackedLen); const contentLen = reader.readField().toNumber(); const content = contentStorage.slice(0, contentLen); @@ -44,7 +41,7 @@ export class NoteValidationRequest { if (reader.remainingFields() !== 0) { throw new Error( - `Error converting array of fields to NoteValidationRequest. Hint: check that MAX_NOTE_PACKED_LEN is consistent with private_notes::MAX_NOTE_PACKED_LEN in Aztec-nr.`, + `Error converting array of fields to NoteValidationRequest: expected ${reader.cursor} fields but received ${fields.length} (maxNotePackedLen=${maxNotePackedLen}).`, ); } diff --git a/yarn-project/pxe/src/contract_function_simulator/oracle/interfaces.ts b/yarn-project/pxe/src/contract_function_simulator/oracle/interfaces.ts index 139f1204700d..7d34bdca1375 100644 --- a/yarn-project/pxe/src/contract_function_simulator/oracle/interfaces.ts +++ b/yarn-project/pxe/src/contract_function_simulator/oracle/interfaces.ts @@ -124,6 +124,8 @@ export interface IUtilityExecutionOracle { contractAddress: AztecAddress, noteValidationRequestsArrayBaseSlot: Fr, eventValidationRequestsArrayBaseSlot: Fr, + maxNotePackedLen: number, + maxEventSerializedLen: number, ): Promise; bulkRetrieveLogs( contractAddress: AztecAddress, @@ -167,20 +169,9 @@ export interface IPrivateExecutionOracle { sideEffectCounter: number, isStaticCall: boolean, ): Promise<{ endSideEffectCounter: Fr; returnsHash: Fr }>; - notifyEnqueuedPublicFunctionCall( - targetContractAddress: AztecAddress, - calldataHash: Fr, - sideEffectCounter: number, - isStaticCall: boolean, - ): Promise; - notifySetPublicTeardownFunctionCall( - targetContractAddress: AztecAddress, - calldataHash: Fr, - sideEffectCounter: number, - isStaticCall: boolean, - ): Promise; - notifySetMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: number): Promise; - isSideEffectCounterRevertible(sideEffectCounter: number): Promise; + validatePublicCalldata(calldataHash: Fr): Promise; + notifyRevertiblePhaseStart(minRevertibleSideEffectCounter: number): Promise; + inRevertiblePhase(sideEffectCounter: number): Promise; getSenderForTags(): Promise; setSenderForTags(senderForTags: AztecAddress): Promise; getNextAppTagAsSender(sender: AztecAddress, recipient: AztecAddress): Promise; diff --git a/yarn-project/pxe/src/contract_function_simulator/oracle/oracle.ts b/yarn-project/pxe/src/contract_function_simulator/oracle/oracle.ts index 81ca851245ee..12d673d745d0 100644 --- a/yarn-project/pxe/src/contract_function_simulator/oracle/oracle.ts +++ b/yarn-project/pxe/src/contract_function_simulator/oracle/oracle.ts @@ -461,52 +461,20 @@ export class Oracle { } // eslint-disable-next-line camelcase - async aztec_prv_notifyEnqueuedPublicFunctionCall( - [contractAddress]: ACVMField[], - [calldataHash]: ACVMField[], - [sideEffectCounter]: ACVMField[], - [isStaticCall]: ACVMField[], - ): Promise { - await this.handlerAsPrivate().notifyEnqueuedPublicFunctionCall( - AztecAddress.fromString(contractAddress), - Fr.fromString(calldataHash), - Fr.fromString(sideEffectCounter).toNumber(), - Fr.fromString(isStaticCall).toBool(), - ); + async aztec_prv_validatePublicCalldata([calldataHash]: ACVMField[]): Promise { + await this.handlerAsPrivate().validatePublicCalldata(Fr.fromString(calldataHash)); return []; } // eslint-disable-next-line camelcase - async aztec_prv_notifySetPublicTeardownFunctionCall( - [contractAddress]: ACVMField[], - [calldataHash]: ACVMField[], - [sideEffectCounter]: ACVMField[], - [isStaticCall]: ACVMField[], - ): Promise { - await this.handlerAsPrivate().notifySetPublicTeardownFunctionCall( - AztecAddress.fromString(contractAddress), - Fr.fromString(calldataHash), - Fr.fromString(sideEffectCounter).toNumber(), - Fr.fromString(isStaticCall).toBool(), - ); - return []; - } - - // eslint-disable-next-line camelcase - async aztec_prv_notifySetMinRevertibleSideEffectCounter([minRevertibleSideEffectCounter]: ACVMField[]): Promise< - ACVMField[] - > { - await this.handlerAsPrivate().notifySetMinRevertibleSideEffectCounter( - Fr.fromString(minRevertibleSideEffectCounter).toNumber(), - ); + async aztec_prv_notifyRevertiblePhaseStart([minRevertibleSideEffectCounter]: ACVMField[]): Promise { + await this.handlerAsPrivate().notifyRevertiblePhaseStart(Fr.fromString(minRevertibleSideEffectCounter).toNumber()); return Promise.resolve([]); } // eslint-disable-next-line camelcase - async aztec_prv_isSideEffectCounterRevertible([sideEffectCounter]: ACVMField[]): Promise { - const isRevertible = await this.handlerAsPrivate().isSideEffectCounterRevertible( - Fr.fromString(sideEffectCounter).toNumber(), - ); + async aztec_prv_inRevertiblePhase([sideEffectCounter]: ACVMField[]): Promise { + const isRevertible = await this.handlerAsPrivate().inRevertiblePhase(Fr.fromString(sideEffectCounter).toNumber()); return Promise.resolve([toACVMField(isRevertible)]); } @@ -530,11 +498,15 @@ export class Oracle { [contractAddress]: ACVMField[], [noteValidationRequestsArrayBaseSlot]: ACVMField[], [eventValidationRequestsArrayBaseSlot]: ACVMField[], + [maxNotePackedLen]: ACVMField[], + [maxEventSerializedLen]: ACVMField[], ): Promise { await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents( AztecAddress.fromString(contractAddress), Fr.fromString(noteValidationRequestsArrayBaseSlot), Fr.fromString(eventValidationRequestsArrayBaseSlot), + Fr.fromString(maxNotePackedLen).toNumber(), + Fr.fromString(maxEventSerializedLen).toNumber(), ); return []; diff --git a/yarn-project/pxe/src/contract_function_simulator/oracle/private_execution_oracle.ts b/yarn-project/pxe/src/contract_function_simulator/oracle/private_execution_oracle.ts index ea9a52d160bf..6c4a9914c8f7 100644 --- a/yarn-project/pxe/src/contract_function_simulator/oracle/private_execution_oracle.ts +++ b/yarn-project/pxe/src/contract_function_simulator/oracle/private_execution_oracle.ts @@ -608,7 +608,8 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP }; } - #onNewPublicFunctionCall(calldataHash: Fr) { + /** Validates the calldata preimage exists in the cache and checks cumulative calldata size is within limits. */ + public validatePublicCalldata(calldataHash: Fr) { const calldata = this.executionCache.getPreimage(calldataHash); if (!calldata) { throw new Error('Calldata for public call not found in cache'); @@ -618,47 +619,14 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP if (this.totalPublicCalldataCount > MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS) { throw new Error(`Too many total args to all enqueued public calls! (> ${MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS})`); } - } - - /** - * Verify relevant information when a public function is enqueued. - * @param targetContractAddress - The address of the contract to call. - * @param calldataHash - The hash of the function selector and arguments. - * @param sideEffectCounter - The side effect counter at the start of the call. - * @param isStaticCall - Whether the call is a static call. - */ - public notifyEnqueuedPublicFunctionCall( - _targetContractAddress: AztecAddress, - calldataHash: Fr, - _sideEffectCounter: number, - _isStaticCall: boolean, - ) { - this.#onNewPublicFunctionCall(calldataHash); - return Promise.resolve(); - } - - /** - * Verify relevant information when a public teardown function is set. - * @param targetContractAddress - The address of the contract to call. - * @param argsHash - The arguments hash to pass to the function. - * @param sideEffectCounter - The side effect counter at the start of the call. - * @param isStaticCall - Whether the call is a static call. - */ - public notifySetPublicTeardownFunctionCall( - _targetContractAddress: AztecAddress, - calldataHash: Fr, - _sideEffectCounter: number, - _isStaticCall: boolean, - ) { - this.#onNewPublicFunctionCall(calldataHash); return Promise.resolve(); } - public notifySetMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: number): Promise { + public notifyRevertiblePhaseStart(minRevertibleSideEffectCounter: number): Promise { return this.noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter); } - public isSideEffectCounterRevertible(sideEffectCounter: number): Promise { + public inRevertiblePhase(sideEffectCounter: number): Promise { return Promise.resolve(this.noteCache.isSideEffectCounterRevertible(sideEffectCounter)); } diff --git a/yarn-project/pxe/src/contract_function_simulator/oracle/utility_execution_oracle.ts b/yarn-project/pxe/src/contract_function_simulator/oracle/utility_execution_oracle.ts index 915b079737a3..dfb66ce833e3 100644 --- a/yarn-project/pxe/src/contract_function_simulator/oracle/utility_execution_oracle.ts +++ b/yarn-project/pxe/src/contract_function_simulator/oracle/utility_execution_oracle.ts @@ -454,6 +454,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra contractAddress: AztecAddress, noteValidationRequestsArrayBaseSlot: Fr, eventValidationRequestsArrayBaseSlot: Fr, + maxNotePackedLen: number, + maxEventSerializedLen: number, ) { // TODO(#10727): allow other contracts to store notes if (!this.contractAddress.equals(contractAddress)) { @@ -464,11 +466,11 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra // faster as we don't need to wait for the network round-trip. const noteValidationRequests = ( await this.capsuleStore.readCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, this.jobId) - ).map(NoteValidationRequest.fromFields); + ).map(fields => NoteValidationRequest.fromFields(fields, maxNotePackedLen)); const eventValidationRequests = ( await this.capsuleStore.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, this.jobId) - ).map(EventValidationRequest.fromFields); + ).map(fields => EventValidationRequest.fromFields(fields, maxEventSerializedLen)); const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId); const noteStorePromises = noteValidationRequests.map(request => diff --git a/yarn-project/pxe/src/oracle_version.ts b/yarn-project/pxe/src/oracle_version.ts index e282867c911f..c8fda38b275d 100644 --- a/yarn-project/pxe/src/oracle_version.ts +++ b/yarn-project/pxe/src/oracle_version.ts @@ -4,9 +4,9 @@ /// /// @dev Whenever a contract function or Noir test is run, the `aztec_utl_assertCompatibleOracleVersion` oracle is called /// and if the oracle version is incompatible an error is thrown. -export const ORACLE_VERSION = 14; +export const ORACLE_VERSION = 15; /// This hash is computed as by hashing the Oracle interface and it is used to detect when the Oracle interface changes, /// which in turn implies that you need to update the ORACLE_VERSION constant in this file and in /// `noir-projects/aztec-nr/aztec/src/oracle/version.nr`. -export const ORACLE_INTERFACE_HASH = '9fb918682455c164ce8dd3acb71c751e2b9b2fc48913604069c9ea885fa378ca'; +export const ORACLE_INTERFACE_HASH = '32b3efa9e08765a5fad5fba732df263f61ca13e7979e30c1843215914b76b97e'; diff --git a/yarn-project/txe/src/rpc_translator.ts b/yarn-project/txe/src/rpc_translator.ts index 7ac755c2d501..2031d48da839 100644 --- a/yarn-project/txe/src/rpc_translator.ts +++ b/yarn-project/txe/src/rpc_translator.ts @@ -652,34 +652,19 @@ export class RPCTranslator { } // eslint-disable-next-line camelcase - public aztec_prv_notifyEnqueuedPublicFunctionCall( - _foreignTargetContractAddress: ForeignCallSingle, - _foreignCalldataHash: ForeignCallSingle, - _foreignSideEffectCounter: ForeignCallSingle, - _foreignIsStaticCall: ForeignCallSingle, - ) { - throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context'); - } - - // eslint-disable-next-line camelcase - public aztec_prv_notifySetPublicTeardownFunctionCall( - _foreignTargetContractAddress: ForeignCallSingle, - _foreignCalldataHash: ForeignCallSingle, - _foreignSideEffectCounter: ForeignCallSingle, - _foreignIsStaticCall: ForeignCallSingle, - ) { + public aztec_prv_validatePublicCalldata(_foreignCalldataHash: ForeignCallSingle) { throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context'); } // eslint-disable-next-line camelcase - public aztec_prv_notifySetMinRevertibleSideEffectCounter(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) { + public aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) { throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context'); } // eslint-disable-next-line camelcase - public async aztec_prv_isSideEffectCounterRevertible(foreignSideEffectCounter: ForeignCallSingle) { + public async aztec_prv_inRevertiblePhase(foreignSideEffectCounter: ForeignCallSingle) { const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber(); - const isRevertible = await this.handlerAsPrivate().isSideEffectCounterRevertible(sideEffectCounter); + const isRevertible = await this.handlerAsPrivate().inRevertiblePhase(sideEffectCounter); return toForeignCallResult([toSingle(new Fr(isRevertible))]); } @@ -766,15 +751,21 @@ export class RPCTranslator { foreignContractAddress: ForeignCallSingle, foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle, foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle, + foreignMaxNotePackedLen: ForeignCallSingle, + foreignMaxEventSerializedLen: ForeignCallSingle, ) { const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress)); const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot); const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot); + const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber(); + const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber(); await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents( contractAddress, noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot, + maxNotePackedLen, + maxEventSerializedLen, ); return toForeignCallResult([]);