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
86 changes: 43 additions & 43 deletions avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,38 +538,38 @@ fn handle_foreign_call(
inputs: &[ValueOrArray],
) {
match function {
"avmOpcodeCall" => handle_external_call(avm_instrs, destinations, inputs, AvmOpcode::CALL),
"avmOpcodeStaticCall" => {
"aztec_avm_call" => handle_external_call(avm_instrs, destinations, inputs, AvmOpcode::CALL),
"aztec_avm_staticCall" => {
handle_external_call(avm_instrs, destinations, inputs, AvmOpcode::STATICCALL);
}
"avmOpcodeEmitPublicLog" => {
"aztec_avm_emitPublicLog" => {
handle_emit_public_log(avm_instrs, destinations, inputs);
}
"avmOpcodeNoteHashExists" => handle_note_hash_exists(avm_instrs, destinations, inputs),
"avmOpcodeEmitNoteHash" | "avmOpcodeEmitNullifier" => handle_emit_note_hash_or_nullifier(
function == "avmOpcodeEmitNullifier",
"aztec_avm_noteHashExists" => handle_note_hash_exists(avm_instrs, destinations, inputs),
"aztec_avm_emitNoteHash" | "aztec_avm_emitNullifier" => handle_emit_note_hash_or_nullifier(
function == "aztec_avm_emitNullifier",
avm_instrs,
destinations,
inputs,
),
"avmOpcodeNullifierExists" => handle_nullifier_exists(avm_instrs, destinations, inputs),
"avmOpcodeL1ToL2MsgExists" => handle_l1_to_l2_msg_exists(avm_instrs, destinations, inputs),
"avmOpcodeSendL2ToL1Msg" => handle_send_l2_to_l1_msg(avm_instrs, destinations, inputs),
"avmOpcodeCalldataCopy" => handle_calldata_copy(avm_instrs, destinations, inputs),
"avmOpcodeSuccessCopy" => handle_success_copy(avm_instrs, destinations, inputs),
"avmOpcodeReturndataSize" => handle_returndata_size(avm_instrs, destinations, inputs),
"avmOpcodeReturndataCopy" => handle_returndata_copy(avm_instrs, destinations, inputs),
"avmOpcodeReturn" => handle_return(avm_instrs, destinations, inputs),
"avmOpcodeRevert" => handle_revert(avm_instrs, destinations, inputs),
"avmOpcodeStorageRead" => handle_storage_read(avm_instrs, destinations, inputs),
"avmOpcodeStorageWrite" => handle_storage_write(avm_instrs, destinations, inputs),
"utilityLog" => handle_debug_log(avm_instrs, destinations, inputs),
"aztec_avm_nullifierExists" => handle_nullifier_exists(avm_instrs, destinations, inputs),
"aztec_avm_l1ToL2MsgExists" => handle_l1_to_l2_msg_exists(avm_instrs, destinations, inputs),
"aztec_avm_sendL2ToL1Msg" => handle_send_l2_to_l1_msg(avm_instrs, destinations, inputs),
"aztec_avm_calldataCopy" => handle_calldata_copy(avm_instrs, destinations, inputs),
"aztec_avm_successCopy" => handle_success_copy(avm_instrs, destinations, inputs),
"aztec_avm_returndataSize" => handle_returndata_size(avm_instrs, destinations, inputs),
"aztec_avm_returndataCopy" => handle_returndata_copy(avm_instrs, destinations, inputs),
"aztec_avm_return" => handle_return(avm_instrs, destinations, inputs),
"aztec_avm_revert" => handle_revert(avm_instrs, destinations, inputs),
"aztec_avm_storageRead" => handle_storage_read(avm_instrs, destinations, inputs),
"aztec_avm_storageWrite" => handle_storage_write(avm_instrs, destinations, inputs),
"aztec_utl_log" => handle_debug_log(avm_instrs, destinations, inputs),
// Getters.
_ if inputs.is_empty() && destinations.len() == 1 => {
handle_getter_instruction(avm_instrs, function, destinations, inputs);
}
// Get contract instance variations.
_ if function.starts_with("avmOpcodeGetContractInstance") => {
_ if function.starts_with("aztec_avm_getContractInstance") => {
handle_get_contract_instance(avm_instrs, function, destinations, inputs);
}
// Anything else.
Expand All @@ -580,7 +580,7 @@ fn handle_foreign_call(
/// Handle an AVM CALL
/// (an external 'call' brillig foreign call was encountered)
/// Adds the new instruction to the avm instructions list.
// #[oracle(avmOpcodeCall)]
// #[oracle(aztec_avm_call)]
// unconstrained fn call_opcode<let N: u32>(
// l2_gas_allocation: u32,
// da_gas_allocation: u32,
Expand Down Expand Up @@ -947,18 +947,18 @@ fn handle_getter_instruction(
};

let var_idx = match function {
"avmOpcodeAddress" => EnvironmentVariable::ADDRESS,
"avmOpcodeSender" => EnvironmentVariable::SENDER,
"avmOpcodeMinFeePerL2Gas" => EnvironmentVariable::MINFEEPERL2GAS,
"avmOpcodeMinFeePerDaGas" => EnvironmentVariable::MINFEEPERDAGAS,
"avmOpcodeTransactionFee" => EnvironmentVariable::TRANSACTIONFEE,
"avmOpcodeChainId" => EnvironmentVariable::CHAINID,
"avmOpcodeVersion" => EnvironmentVariable::VERSION,
"avmOpcodeBlockNumber" => EnvironmentVariable::BLOCKNUMBER,
"avmOpcodeTimestamp" => EnvironmentVariable::TIMESTAMP,
"avmOpcodeL2GasLeft" => EnvironmentVariable::L2GASLEFT,
"avmOpcodeDaGasLeft" => EnvironmentVariable::DAGASLEFT,
"avmOpcodeIsStaticCall" => EnvironmentVariable::ISSTATICCALL,
"aztec_avm_address" => EnvironmentVariable::ADDRESS,
"aztec_avm_sender" => EnvironmentVariable::SENDER,
"aztec_avm_minFeePerL2Gas" => EnvironmentVariable::MINFEEPERL2GAS,
"aztec_avm_minFeePerDaGas" => EnvironmentVariable::MINFEEPERDAGAS,
"aztec_avm_transactionFee" => EnvironmentVariable::TRANSACTIONFEE,
"aztec_avm_chainId" => EnvironmentVariable::CHAINID,
"aztec_avm_version" => EnvironmentVariable::VERSION,
"aztec_avm_blockNumber" => EnvironmentVariable::BLOCKNUMBER,
"aztec_avm_timestamp" => EnvironmentVariable::TIMESTAMP,
"aztec_avm_l2GasLeft" => EnvironmentVariable::L2GASLEFT,
"aztec_avm_daGasLeft" => EnvironmentVariable::DAGASLEFT,
"aztec_avm_isStaticCall" => EnvironmentVariable::ISSTATICCALL,
_ => panic!("Transpiler doesn't know how to process getter {:?}", function),
};

Expand Down Expand Up @@ -1348,7 +1348,7 @@ fn handle_debug_log(
) {
// We need to handle two flavors here:
//
// #[oracle(utilityLog)]
// #[oracle(aztec_utl_log)]
// unconstrained fn log_oracle<let M: u32, let N: u32>(
// log_level: u8,
// msg: str<M>,
Expand All @@ -1358,7 +1358,7 @@ fn handle_debug_log(
//
// and
//
//#[oracle(utilityLog)]
//#[oracle(aztec_utl_log)]
// unconstrained fn log_slice_oracle<let M: u32>(log_level: u8, msg: str<M>, args: [Field]) {}
//
// Luckily, these two flavors have both 4 arguments, since noir inserts a length field for slices before the slice.
Expand Down Expand Up @@ -1420,7 +1420,7 @@ fn handle_debug_log(
});
}

// #[oracle(avmOpcodeCalldataCopy)]
// #[oracle(aztec_avm_calldataCopy)]
// unconstrained fn calldata_copy_opcode<let N: u32>(cdoffset: Field) -> [Field; N] {}
fn handle_calldata_copy(
avm_instrs: &mut Vec<AvmInstruction>,
Expand Down Expand Up @@ -1463,7 +1463,7 @@ fn handle_calldata_copy(
});
}

// #[oracle(avmOpcodeReturndataSize)]
// #[oracle(aztec_avm_returndataSize)]
// unconstrained fn returndata_size_opcode() -> u32 {}
fn handle_returndata_size(
avm_instrs: &mut Vec<AvmInstruction>,
Expand All @@ -1488,7 +1488,7 @@ fn handle_returndata_size(
});
}

// #[oracle(avmOpcodeReturndataCopy)]
// #[oracle(aztec_avm_returndataCopy)]
// unconstrained fn returndata_copy_opcode(rdoffset: u32, copy_size: u32) -> [Field] {}
fn handle_returndata_copy(
avm_instrs: &mut Vec<AvmInstruction>,
Expand Down Expand Up @@ -1546,7 +1546,7 @@ fn handle_returndata_copy(
]);
}

// #[oracle(avmOpcodeReturn)]
// #[oracle(aztec_avm_return)]
// unconstrained fn return_opcode<let N: u32>(returndata: [Field; N]) {}
fn handle_return(
avm_instrs: &mut Vec<AvmInstruction>,
Expand All @@ -1565,7 +1565,7 @@ fn handle_return(
generate_return_instruction(avm_instrs, &return_data_offset, &return_data_size);
}

// #[oracle(avmOpcodeRevert)]
// #[oracle(aztec_avm_revert)]
// unconstrained fn revert_opcode(revertdata: [Field]) {}
fn handle_revert(
avm_instrs: &mut Vec<AvmInstruction>,
Expand Down Expand Up @@ -1640,9 +1640,9 @@ fn handle_get_contract_instance(
assert_eq!(destinations.len(), 1);

let member_idx = match function {
"avmOpcodeGetContractInstanceDeployer" => ContractInstanceMember::DEPLOYER,
"avmOpcodeGetContractInstanceClassId" => ContractInstanceMember::CLASS_ID,
"avmOpcodeGetContractInstanceInitializationHash" => ContractInstanceMember::INIT_HASH,
"aztec_avm_getContractInstanceDeployer" => ContractInstanceMember::DEPLOYER,
"aztec_avm_getContractInstanceClassId" => ContractInstanceMember::CLASS_ID,
"aztec_avm_getContractInstanceInitializationHash" => ContractInstanceMember::INIT_HASH,
_ => panic!("Transpiler doesn't know how to process function {:?}", function),
};

Expand Down Expand Up @@ -1767,7 +1767,7 @@ fn tag_from_bit_size(bit_size: BitSize) -> AvmTypeTag {
}
}

/// #[oracle(avmOpcodeSuccessCopy)]
/// #[oracle(aztec_avm_successCopy)]
/// unconstrained fn success_copy_opcode() -> bool {}
fn handle_success_copy(
avm_instrs: &mut Vec<AvmInstruction>,
Expand Down
5 changes: 3 additions & 2 deletions noir-projects/aztec-nr/aztec/src/capsules/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,9 @@ mod test {
array.push(5);
array.push(6);

// We test that the utilityCopyCapsule was never called, which is the expensive operation we want to avoid.
let mock = std::test::OracleMock::mock("utilityCopyCapsule");
// We test that the aztec_utl_copyCapsule was never called, which is the expensive operation we want to
// avoid.
let mock = std::test::OracleMock::mock("aztec_utl_copyCapsule");

array.for_each(|index, _| { array.remove(index); });

Expand Down
18 changes: 7 additions & 11 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::protocol::{
Expand Down Expand Up @@ -535,7 +533,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 @@ -581,7 +579,7 @@ impl PrivateContext {
// [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 @@ -1279,7 +1277,7 @@ impl PrivateContext {

let mut 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 @@ -1348,11 +1346,9 @@ impl PrivateContext {
is_static_call: bool,
hide_msg_sender: bool,
) {
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_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
17 changes: 4 additions & 13 deletions noir-projects/aztec-nr/aztec/src/context/returns_hash.nr
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::{hash::hash_args, oracle::execution_cache};
use crate::protocol::traits::Deserialize;

/// A hash that represents a private contract function call's return value. Call `get_preimage` to get the underlying
/// value.
/// The hash of a private contract function call's return value.
///
/// Use [`ReturnsHash::get_preimage`] to get the underlying value.
///
/// The kernels don't process the actual return values but instead their hashes, so it is up to contracts to populate
/// oracles with the preimages of these hashes on return to make them available to their callers.
Expand Down Expand Up @@ -81,17 +82,7 @@ mod test {

let hash = hash_args(serialized);

let _ = OracleMock::mock("privateLoadFromExecutionCache").returns(bad_serialized);
let _ = OracleMock::mock("aztec_prv_loadFromExecutionCache").returns(bad_serialized);
assert_eq(ReturnsHash::new(hash).get_preimage(), value);
}

// This test passes due to a Noir bug. #[test(should_fail_with="Preimage mismatch")] unconstrained fn
// rejects_bad_empty_preimage() {
// let value = (); let serialized = [];

// let hash = hash_args(serialized);

// let _ = OracleMock::mock("privateLoadFromExecutionCache").returns([1]);
// assert_eq(ReturnsHash::new(hash).get_preimage(), value);
// }
}
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: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/keys/getters/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mod test {
// partial address
random_keys_and_partial_address[12] = 0x236703e2cb00a182e024e98e9f759231b556d25ff19f98896cebb69e9e678cc9;

let _ = OracleMock::mock("utilityTryGetPublicKeysAndPartialAddress").returns(Option::some(
let _ = OracleMock::mock("aztec_utl_tryGetPublicKeysAndPartialAddress").returns(Option::some(
random_keys_and_partial_address,
));
let _ = get_public_keys(account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,12 @@ mod test {

// Mock random values for deterministic test
let eph_sk = 0x1358d15019d4639393d62b97e1588c095957ce74a1c32d6ec7d62fe6705d9538;
let _ = OracleMock::mock("utilityGetRandomField").returns(eph_sk).times(1);
let _ = OracleMock::mock("aztec_utl_getRandomField").returns(eph_sk).times(1);

let randomness = 0x0101010101010101010101010101010101010101010101010101010101010101;
let _ = OracleMock::mock("utilityGetRandomField").returns(randomness).times(1000000);
let _ = OracleMock::mock("aztec_utl_getRandomField").returns(randomness).times(1000000);

let _ = OracleMock::mock("privateGetNextAppTagAsSender").returns(42);
let _ = OracleMock::mock("aztec_prv_getNextAppTagAsSender").returns(42);

// Encrypt the message
let encrypted_message = BoundedVec::from_array(AES128::encrypt(plaintext, recipient));
Expand All @@ -520,7 +520,7 @@ mod test {
recipient.to_address_point().unwrap().inner,
);

let _ = OracleMock::mock("utilityGetSharedSecret").returns(shared_secret);
let _ = OracleMock::mock("aztec_utl_getSharedSecret").returns(shared_secret);

// Decrypt the message
let decrypted = AES128::decrypt(encrypted_message, recipient).unwrap();
Expand Down
10 changes: 5 additions & 5 deletions noir-projects/aztec-nr/aztec/src/messages/logs/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ mod test {

let expected_tag = 42;

// Mock the tagging oracles - note privateGetSenderForTags returns none
let _ = OracleMock::mock("privateGetSenderForTags").returns(Option::<AztecAddress>::none());
let _ = OracleMock::mock("privateGetNextAppTagAsSender").returns(expected_tag);
// Mock the tagging oracles - note aztec_prv_getSenderForTags returns none
let _ = OracleMock::mock("aztec_prv_getSenderForTags").returns(Option::<AztecAddress>::none());
let _ = OracleMock::mock("aztec_prv_getNextAppTagAsSender").returns(expected_tag);

let log_without_tag = [1, 2, 3];
let _ = prefix_with_tag(log_without_tag, recipient);
Expand All @@ -50,8 +50,8 @@ mod test {
let expected_tag = 42;

// Mock the tagging oracles
let _ = OracleMock::mock("privateGetSenderForTags").returns(Option::some(sender));
let _ = OracleMock::mock("privateGetNextAppTagAsSender").returns(expected_tag);
let _ = OracleMock::mock("aztec_prv_getSenderForTags").returns(Option::some(sender));
let _ = OracleMock::mock("aztec_prv_getNextAppTagAsSender").returns(expected_tag);

let log_without_tag = [1, 2, 3];
let log_with_tag = prefix_with_tag(log_without_tag, recipient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{event::EventSelector, messages::logs::event::MAX_EVENT_SERIALIZED_LE
use crate::protocol::{address::AztecAddress, traits::Serialize};

/// Intermediate struct used to perform batch event validation by PXE. The
/// `utilityValidateAndStoreEnqueuedNotesAndEvents` oracle expects for values of this type to be stored in a
/// `aztec_utl_validateAndStoreEnqueuedNotesAndEvents` oracle expects for values of this type to be stored in a
/// `CapsuleArray` at the given `base_slot`.
#[derive(Serialize)]
pub(crate) struct EventValidationRequest {
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 @@ -145,6 +145,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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::messages::logs::note::MAX_NOTE_PACKED_LEN;
use crate::protocol::{address::AztecAddress, traits::Serialize};

/// Intermediate struct used to perform batch note validation by PXE. The
/// `utilityValidateAndStoreEnqueuedNotesAndEvents` oracle expects for values of this type to be stored in a
/// `aztec_utl_validateAndStoreEnqueuedNotesAndEvents` oracle expects for values of this type to be stored in a
/// `CapsuleArray`.
#[derive(Serialize)]
pub(crate) struct NoteValidationRequest {
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/note/note_metadata.nr
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ impl NoteMetadata {
}
}

/// Returns true if the note is pending **and** from the same phase, i.e. if it's been created in the current
/// Returns `true` if the note is pending **and** from the same phase, i.e. if it's been created in the current
/// transaction during the current execution phase (either non-revertible or revertible).
pub fn is_pending_same_phase(self) -> bool {
self.stage == NoteStage.PENDING_SAME_PHASE
}

/// Returns true if the note is pending **and** from the previous phase, i.e. if it's been created in the current
/// Returns `true` if the note is pending **and** from the previous phase, i.e. if it's been created in the current
/// transaction during an execution phase prior to the current one. Because private execution only has two phases
/// with strict ordering, this implies that the note was created in the non-revertible phase, and that the current
/// phase is the revertible phase.
Expand Down
Loading
Loading