Skip to content
Draft
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
4 changes: 2 additions & 2 deletions docs/examples/contracts/aave_bridge/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub contract AaveBridge {
);

// Mint tokens (including any yield from Aave)
self.call(Token::at(config.token).mint_to_public(to, amount));
self.call(&Token::at(config.token).mint_to_public(to, amount));
}
// docs:end:claim_public

Expand Down Expand Up @@ -103,7 +103,7 @@ pub contract AaveBridge {
self.context.message_portal(config.portal, content);

// Burn tokens
self.call(Token::at(config.token).burn_public(self.msg_sender(), amount, authwit_nonce));
self.call(&Token::at(config.token).burn_public(self.msg_sender(), amount, authwit_nonce));
}
// docs:end:exit_to_l1_public

Expand Down
8 changes: 4 additions & 4 deletions docs/examples/contracts/example_uniswap/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub contract ExampleUniswap {
}

let input_asset_bridge_config =
self.view(TokenBridge::at(input_asset_bridge).get_config_public());
self.view(&TokenBridge::at(input_asset_bridge).get_config_public());

let input_asset = input_asset_bridge_config.token;
let input_asset_bridge_portal_address = input_asset_bridge_config.portal;
Expand All @@ -78,7 +78,7 @@ pub contract ExampleUniswap {
);
set_authorized(self.context, transfer_msg_hash, true);

self.call(Token::at(input_asset).transfer_in_public(
self.call(&Token::at(input_asset).transfer_in_public(
sender,
self.address,
input_amount,
Expand All @@ -95,7 +95,7 @@ pub contract ExampleUniswap {

// Create swap message and send to Outbox for Uniswap Portal
let output_asset_bridge_portal_address =
self.view(TokenBridge::at(output_asset_bridge).get_config_public()).portal;
self.view(&TokenBridge::at(output_asset_bridge).get_config_public()).portal;

// Ensure portals exist - else funds might be lost
assert(
Expand Down Expand Up @@ -210,7 +210,7 @@ pub contract ExampleUniswap {

let this_portal_address = self.storage.portal_address.read();
// Exit to L1 Uniswap Portal
self.call(TokenBridge::at(token_bridge).exit_to_l1_public(
self.call(&TokenBridge::at(token_bridge).exit_to_l1_public(
this_portal_address,
amount,
this_portal_address,
Expand Down
20 changes: 10 additions & 10 deletions noir-projects/aztec-nr/aztec/src/context/calls.nr
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<let M: u32, let N: u32, T> PublicCall<M, N, T> {
///
/// Please use the new contract API: `self.call(MyContract::at(address).my_public_function(...args))` instead of
/// manually constructing and calling `PublicCall`.
pub unconstrained fn call(self, context: PublicContext) -> T
pub unconstrained fn call(&self, context: &PublicContext) -> T
where
T: Deserialize,
{
Expand All @@ -120,19 +120,19 @@ impl<let M: u32, let N: u32, T> PublicCall<M, N, T> {
///
/// Please use the new contract API: `self.enqueue(MyContract::at(address).my_public_function(...args))` instead of
/// manually constructing and calling `PublicCall`.
pub fn enqueue(self, context: &mut PrivateContext) {
pub fn enqueue(&self, context: &mut PrivateContext) {
self.enqueue_impl(context, false, false)
}

/// **DEPRECATED**.
///
/// Please use the new contract API: `self.enqueue_incognito(MyContract::at(address).my_public_function(...args))`
/// instead of manually constructing and calling `PublicCall`.
pub fn enqueue_incognito(self, context: &mut PrivateContext) {
pub fn enqueue_incognito(&self, context: &mut PrivateContext) {
self.enqueue_impl(context, false, true)
}

fn enqueue_impl(self, context: &mut PrivateContext, is_static_call: bool, hide_msg_sender: bool) {
fn enqueue_impl(&self, context: &mut PrivateContext, is_static_call: bool, hide_msg_sender: bool) {
let calldata = [self.selector.to_field()].concat(self.args);
let calldata_hash = hash_calldata_array(calldata);
execution_cache::store(calldata, calldata_hash);
Expand All @@ -148,7 +148,7 @@ impl<let M: u32, let N: u32, T> PublicCall<M, N, T> {
///
/// Please use the new contract API: `self.set_as_teardown(MyContract::at(address).my_public_function(...args))`
/// instead of manually constructing and setting the teardown function `PublicCall`.
pub fn set_as_teardown(self, context: &mut PrivateContext) {
pub fn set_as_teardown(&self, context: &mut PrivateContext) {
self.set_as_teardown_impl(context, false);
}

Expand All @@ -157,11 +157,11 @@ impl<let M: u32, let N: u32, T> PublicCall<M, N, T> {
/// Please use the new contract API:
/// `self.set_as_teardown_incognito(MyContract::at(address).my_public_function(...args))` instead of manually
/// constructing and setting the teardown function `PublicCall`.
pub fn set_as_teardown_incognito(self, context: &mut PrivateContext) {
pub fn set_as_teardown_incognito(&self, context: &mut PrivateContext) {
self.set_as_teardown_impl(context, true);
}

fn set_as_teardown_impl(self, context: &mut PrivateContext, hide_msg_sender: bool) {
fn set_as_teardown_impl(&self, context: &mut PrivateContext, hide_msg_sender: bool) {
let calldata = [self.selector.to_field()].concat(self.args);
let calldata_hash = hash_calldata_array(calldata);
execution_cache::store(calldata, calldata_hash);
Expand Down Expand Up @@ -200,7 +200,7 @@ impl<let M: u32, let N: u32, T> PublicStaticCall<M, N, T> {
///
/// Please use the new contract API: `self.view(MyContract::at(address).my_public_static_function(...args))`
/// instead of manually constructing and calling `PublicStaticCall`.
pub unconstrained fn view(self, context: PublicContext) -> T
pub unconstrained fn view(&self, context: &PublicContext) -> T
where
T: Deserialize,
{
Expand All @@ -214,7 +214,7 @@ impl<let M: u32, let N: u32, T> PublicStaticCall<M, N, T> {
/// Please use the new contract API:
/// `self.enqueue_view(MyContract::at(address).my_public_static_function(...args))` instead of manually
/// constructing and calling `PublicStaticCall`.
pub fn enqueue_view(self, context: &mut PrivateContext) {
pub fn enqueue_view(&self, context: &mut PrivateContext) {
let calldata = [self.selector.to_field()].concat(self.args);
let calldata_hash = hash_calldata_array(calldata);
execution_cache::store(calldata, calldata_hash);
Expand All @@ -233,7 +233,7 @@ impl<let M: u32, let N: u32, T> PublicStaticCall<M, N, T> {
/// Please use the new contract API:
/// `self.enqueue_view_incognito(MyContract::at(address).my_public_static_function(...args))` instead of manually
/// constructing and calling `PublicStaticCall`.
pub fn enqueue_view_incognito(self, context: &mut PrivateContext) {
pub fn enqueue_view_incognito(&self, context: &mut PrivateContext) {
let calldata = [self.selector.to_field()].concat(self.args);
let calldata_hash = hash_calldata_array(calldata);
execution_cache::store(calldata, calldata_hash);
Expand Down
54 changes: 27 additions & 27 deletions noir-projects/aztec-nr/aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl PublicContext {
/// collisions between logs from different sources. Without domain separation, two unrelated log types that
/// happen to share a raw tag value become indistinguishable. Prefer `self.emit(event)` for events, which
/// handles tagging automatically.
pub fn emit_public_log_unsafe<T>(_self: Self, tag: Field, log: T)
pub fn emit_public_log_unsafe<T>(_self: &Self, tag: Field, log: T)
where
T: Serialize,
{
Expand All @@ -129,7 +129,7 @@ impl PublicContext {
/// # Returns
/// * `bool` - True if the note hash exists at the specified index
///
pub fn note_hash_exists(_self: Self, note_hash: Field, leaf_index: u64) -> bool {
pub fn note_hash_exists(_self: &Self, note_hash: Field, leaf_index: u64) -> bool {
// Safety: AVM opcodes are constrained by the AVM itself
unsafe { avm::note_hash_exists(note_hash, leaf_index) } == 1
}
Expand All @@ -151,7 +151,7 @@ impl PublicContext {
/// * Uses the AVM l1_to_l2_msg_exists opcode for tree lookup
/// * Messages are copied from L1 Inbox to L2 by block proposers
///
pub fn l1_to_l2_msg_exists(_self: Self, msg_hash: Field, msg_leaf_index: Field) -> bool {
pub fn l1_to_l2_msg_exists(_self: &Self, msg_hash: Field, msg_leaf_index: Field) -> bool {
// Safety: AVM opcodes are constrained by the AVM itself TODO(alvaro): Make l1l2msg leaf index a u64 upstream
unsafe { avm::l1_to_l2_msg_exists(msg_hash, msg_leaf_index as u64) } == 1
}
Expand Down Expand Up @@ -201,7 +201,7 @@ impl PublicContext {
///
/// This emits the `CHECKNULLIFIEREXISTS` opcode, which conceptually performs a merkle inclusion proof on the
/// nullifier tree (both when the nullifier exists and when it doesn't).
pub fn nullifier_exists_unsafe(_self: Self, unsiloed_nullifier: Field, contract_address: AztecAddress) -> bool {
pub fn nullifier_exists_unsafe(_self: &Self, unsiloed_nullifier: Field, contract_address: AztecAddress) -> bool {
let siloed_nullifier = compute_siloed_nullifier(contract_address, unsiloed_nullifier);
// Safety: AVM opcodes are constrained by the AVM itself
unsafe { avm::nullifier_exists(siloed_nullifier) } == 1
Expand Down Expand Up @@ -230,7 +230,7 @@ impl PublicContext {
/// * Message hash is computed from all parameters + chain context
/// * Will revert if message doesn't exist or was already consumed
///
pub fn consume_l1_to_l2_message(self: Self, content: Field, secret: Field, sender: EthAddress, leaf_index: Field) {
pub fn consume_l1_to_l2_message(self: &Self, content: Field, secret: Field, sender: EthAddress, leaf_index: Field) {
let secret_hash = compute_secret_hash(secret);
let message_hash = compute_l1_to_l2_message_hash(
sender,
Expand Down Expand Up @@ -268,7 +268,7 @@ impl PublicContext {
/// * `recipient` - Ethereum address that will receive the message
/// * `content` - Message content (32 bytes as a Field element)
///
pub fn message_portal(_self: Self, recipient: EthAddress, content: Field) {
pub fn message_portal(_self: &Self, recipient: EthAddress, content: Field) {
// Safety: AVM opcodes are constrained by the AVM itself
unsafe { avm::send_l2_to_l1_msg(recipient, content) };
}
Expand All @@ -287,7 +287,7 @@ impl PublicContext {
/// * `[Field]` - Return data from the called function
///
pub unconstrained fn call_public_function<let N: u32>(
_self: Self,
_self: &Self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field; N],
Expand Down Expand Up @@ -331,7 +331,7 @@ impl PublicContext {
/// * `[Field]` - Return data from the called function
///
pub unconstrained fn static_call_public_function<let N: u32>(
_self: Self,
_self: &Self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field; N],
Expand Down Expand Up @@ -375,7 +375,7 @@ impl PublicContext {
/// # Advanced
/// * The note hash will be siloed with the contract address by the protocol
///
pub fn push_note_hash(_self: Self, note_hash: Field) {
pub fn push_note_hash(_self: &Self, note_hash: Field) {
// Safety: AVM opcodes are constrained by the AVM itself
unsafe { avm::emit_note_hash(note_hash) };
}
Expand All @@ -400,7 +400,7 @@ impl PublicContext {
/// The raw `nullifier` is not what is inserted into the Aztec state tree: it will be first siloed by contract
/// address via [`crate::protocol::hash::compute_siloed_nullifier`] in order to prevent accidental or malicious
/// interference of nullifiers from different contracts.
pub fn push_nullifier(_self: Self, nullifier: Field) {
pub fn push_nullifier(_self: &Self, nullifier: Field) {
// Safety: AVM opcodes are constrained by the AVM itself
unsafe { avm::emit_nullifier(nullifier) };
}
Expand All @@ -413,7 +413,7 @@ impl PublicContext {
/// # Returns
/// * `AztecAddress` - The contract address of the current function being executed.
///
pub fn this_address(_self: Self) -> AztecAddress {
pub fn this_address(_self: &Self) -> AztecAddress {
// Safety: AVM opcodes are constrained by the AVM itself
unsafe {
avm::address()
Expand All @@ -437,7 +437,7 @@ impl PublicContext {
/// * Value is provided by the AVM sender opcode
/// * In nested calls, this is the immediate caller, not the original transaction sender
///
pub fn maybe_msg_sender(_self: Self) -> Option<AztecAddress> {
pub fn maybe_msg_sender(_self: &Self) -> Option<AztecAddress> {
// Safety: AVM opcodes are constrained by the AVM itself
let maybe_msg_sender = unsafe { avm::sender() };
if maybe_msg_sender == NULL_MSG_SENDER_CONTRACT_ADDRESS {
Expand All @@ -458,7 +458,7 @@ impl PublicContext {
/// * Extracted from the first element of calldata
/// * Used internally for function dispatch in the AVM
///
pub fn selector(_self: Self) -> FunctionSelector {
pub fn selector(_self: &Self) -> FunctionSelector {
// The selector is the first element of the calldata when calling a public function through dispatch.
// Safety: AVM opcodes are constrained by the AVM itself.
let raw_selector: [Field; 1] = unsafe { avm::calldata_copy(0, 1) };
Expand Down Expand Up @@ -497,7 +497,7 @@ impl PublicContext {
/// fee value. The teardown phase does not consume a variable amount of gas: it always consumes a pre-allocated
/// amount of gas, as specified by the user when they generate their tx.
///
pub fn transaction_fee(_self: Self) -> Field {
pub fn transaction_fee(_self: &Self) -> Field {
// Safety: AVM opcodes are constrained by the AVM itself
unsafe {
avm::transaction_fee()
Expand All @@ -514,7 +514,7 @@ impl PublicContext {
/// # Returns
/// * `Field` - The chain ID as a field element
///
pub fn chain_id(_self: Self) -> Field {
pub fn chain_id(_self: &Self) -> Field {
// Safety: AVM opcodes are constrained by the AVM itself
unsafe {
avm::chain_id()
Expand All @@ -533,7 +533,7 @@ impl PublicContext {
/// # Returns
/// * `Field` - The protocol version as a field element
///
pub fn version(_self: Self) -> Field {
pub fn version(_self: &Self) -> Field {
// Safety: AVM opcodes are constrained by the AVM itself
unsafe {
avm::version()
Expand All @@ -554,7 +554,7 @@ impl PublicContext {
/// # Returns
/// * `u32` - The current block number
///
pub fn block_number(_self: Self) -> u32 {
pub fn block_number(_self: &Self) -> u32 {
// Safety: AVM opcodes are constrained by the AVM itself
unsafe {
avm::block_number()
Expand All @@ -577,7 +577,7 @@ impl PublicContext {
/// # Returns
/// * `u64` - Unix timestamp in seconds
///
pub fn timestamp(_self: Self) -> u64 {
pub fn timestamp(_self: &Self) -> u64 {
// Safety: AVM opcodes are constrained by the AVM itself
unsafe {
avm::timestamp()
Expand All @@ -601,7 +601,7 @@ impl PublicContext {
/// - the exact user (if the gas price is explicitly chosen by the user to be some unique number like 0.123456789,
/// or their favorite number). Wallet devs might wish to consider fuzzing the choice of gas price.
///
pub fn min_fee_per_l2_gas(_self: Self) -> u128 {
pub fn min_fee_per_l2_gas(_self: &Self) -> u128 {
// Safety: AVM opcodes are constrained by the AVM itself
unsafe {
avm::min_fee_per_l2_gas()
Expand All @@ -617,7 +617,7 @@ impl PublicContext {
/// # Returns
/// * `u128` - Fee per unit of DA gas
///
pub fn min_fee_per_da_gas(_self: Self) -> u128 {
pub fn min_fee_per_da_gas(_self: &Self) -> u128 {
// Safety: AVM opcodes are constrained by the AVM itself
unsafe {
avm::min_fee_per_da_gas()
Expand All @@ -631,7 +631,7 @@ impl PublicContext {
/// # Returns
/// * `u32` - Remaining L2 gas units
///
pub fn l2_gas_left(_self: Self) -> u32 {
pub fn l2_gas_left(_self: &Self) -> u32 {
// Safety: AVM opcodes are constrained by the AVM itself
unsafe {
avm::l2_gas_left()
Expand All @@ -647,7 +647,7 @@ impl PublicContext {
/// # Returns
/// * `u32` - Remaining DA gas units
///
pub fn da_gas_left(_self: Self) -> u32 {
pub fn da_gas_left(_self: &Self) -> u32 {
// Safety: AVM opcodes are constrained by the AVM itself
unsafe {
avm::da_gas_left()
Expand All @@ -660,7 +660,7 @@ impl PublicContext {
/// # Returns
/// * `bool` - True if in staticcall context, false otherwise
///
pub fn is_static_call(_self: Self) -> bool {
pub fn is_static_call(_self: &Self) -> bool {
// Safety: AVM opcodes are constrained by the AVM itself
unsafe { avm::is_static_call() } == 1
}
Expand All @@ -679,7 +679,7 @@ impl PublicContext {
/// # Generic Parameters
/// * `N` - the number of consecutive slots to return, starting from the `storage_slot`.
///
pub fn raw_storage_read<let N: u32>(self: Self, storage_slot: Field) -> [Field; N] {
pub fn raw_storage_read<let N: u32>(self: &Self, storage_slot: Field) -> [Field; N] {
let mut out = [0; N];
for i in 0..N {
// Safety: AVM opcodes are constrained by the AVM itself
Expand All @@ -702,7 +702,7 @@ impl PublicContext {
/// # Generic Parameters
/// * `T` - The type that the caller expects to read from the `storage_slot`.
///
pub fn storage_read<T>(self, storage_slot: Field) -> T
pub fn storage_read<T>(&self, storage_slot: Field) -> T
where
T: Packable,
{
Expand All @@ -720,7 +720,7 @@ impl PublicContext {
/// * `storage_slot` - The starting storage slot to write to
/// * `values` - Array of N Fields to write to storage
///
pub fn raw_storage_write<let N: u32>(_self: Self, storage_slot: Field, values: [Field; N]) {
pub fn raw_storage_write<let N: u32>(_self: &Self, storage_slot: Field, values: [Field; N]) {
for i in 0..N {
// Safety: AVM opcodes are constrained by the AVM itself
unsafe { avm::storage_write(storage_slot + i as Field, values[i]) };
Expand All @@ -739,7 +739,7 @@ impl PublicContext {
/// # Generic Parameters
/// * `T` - The type to write to storage.
///
pub fn storage_write<T>(self, storage_slot: Field, value: T)
pub fn storage_write<T>(&self, storage_slot: Field, value: T)
where
T: Packable,
{
Expand Down
Loading
Loading