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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do all the oracles have the aztec prefix? Is it the expectation that there will be non-aztec oracles?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See noir-lang/noir#10105. We want for nargo to be able to detect that a user is calling aztec oracles with no resolver, and to tell them to go read the docs. E.g. some other protocol mayan might use Noir and have similar oracle names.

Our oracles would always have the aztec prefix probably.

"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 @@ -312,8 +312,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
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/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 @@ -483,12 +483,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 @@ -499,7 +499,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
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/// Note that we accept ciphertext as a BoundedVec, not as an array. This is because this function is typically used
/// when processing logs and at that point we don't have a comptime information about the length of the ciphertext as
/// the log is not specific to any individual note.
#[oracle(utilityAes128Decrypt)]
#[oracle(aztec_utl_aes128Decrypt)]
pub unconstrained fn aes128_decrypt_oracle<let N: u32>(
ciphertext: BoundedVec<u8, N>,
iv: [u8; 16],
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/auth_witness.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[oracle(utilityGetAuthWitness)]
#[oracle(aztec_utl_getAuthWitness)]
unconstrained fn get_auth_witness_oracle<let N: u32>(_message_hash: Field) -> [Field; N] {}

/// Oracle wrapper to fetch an `auth_witness` for a given `message_hash` from the PXE.
Expand Down
Loading
Loading