Skip to content
Merged
16 changes: 6 additions & 10 deletions noir-projects/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/history/note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);

Expand Down
2 changes: 2 additions & 0 deletions noir-projects/aztec-nr/aztec/src/messages/processing/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand Down
3 changes: 1 addition & 2 deletions noir-projects/aztec-nr/aztec/src/note/note_metadata.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/block_header.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<NOTE_HASH_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT + 1> = 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<let N: u32, let M: u32> {
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<NOTE_HASH_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT + 1> {}
) -> MembershipWitness<NOTE_HASH_TREE_HEIGHT> {}

#[oracle(aztec_utl_getBlockHashMembershipWitness)]
unconstrained fn get_block_hash_membership_witness_oracle(
anchor_block_hash: Field,
block_hash: Field,
) -> MembershipWitness<ARCHIVE_HEIGHT, ARCHIVE_HEIGHT + 1> {}
) -> MembershipWitness<ARCHIVE_HEIGHT> {}

// Note: get_nullifier_membership_witness function is implemented in get_nullifier_membership_witness.nr

Expand All @@ -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<NOTE_HASH_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT + 1> {
) -> MembershipWitness<NOTE_HASH_TREE_HEIGHT> {
let anchor_block_hash = anchor_block_header.hash();
get_note_hash_membership_witness_oracle(anchor_block_hash, note_hash)
}
Expand All @@ -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<ARCHIVE_HEIGHT, ARCHIVE_HEIGHT + 1> {
) -> MembershipWitness<ARCHIVE_HEIGHT> {
let anchor_block_hash = anchor_block_header.hash();
get_block_hash_membership_witness_oracle(anchor_block_hash, block_hash)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand All @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions noir-projects/aztec-nr/aztec/src/oracle/public_call.nr
Original file line number Diff line number Diff line change
@@ -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) {}
24 changes: 24 additions & 0 deletions noir-projects/aztec-nr/aztec/src/oracle/tx_phase.nr
Original file line number Diff line number Diff line change
@@ -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 {}
5 changes: 2 additions & 3 deletions noir-projects/aztec-nr/aztec/src/oracle/version.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading
Loading