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
22 changes: 12 additions & 10 deletions avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,12 @@ fn handle_foreign_call(
/// (an external 'call' brillig foreign call was encountered)
/// Adds the new instruction to the avm instructions list.
// #[oracle(avmOpcodeCall)]
// unconstrained fn call_opcode(
// gas: [Field; 2], // gas allocation: [l2_gas, da_gas]
// unconstrained fn call_opcode<let N: u32>(
// l2_gas_allocation: u32,
// da_gas_allocation: u32,
// address: AztecAddress,
// args: [Field],
// length: u32,
// args: [Field; N],
// ) {}
fn handle_external_call(
avm_instrs: &mut Vec<AvmInstruction>,
Expand Down Expand Up @@ -611,14 +613,14 @@ fn handle_external_call(
ValueOrArray::MemoryAddress(offset) => offset,
_ => panic!("Call instruction's target address input should be a basic MemoryAddress",),
};
// The args are a slice, and this is represented as a (Field, HeapVector).
// The field is the length (memory address) and the HeapVector has the data and length again.
// This is an ACIR internal representation detail that leaks to the SSA.
// Observe that below, we use `inputs[4]` and therefore skip the length field.
let args_size_offset = match &inputs[3] {
ValueOrArray::MemoryAddress(offset) => offset,
_ => panic!("Call instruction's length input should be a basic MemoryAddress"),
};
let args = &inputs[4];
let (args_offset_ptr, args_size_offset) = match args {
ValueOrArray::HeapVector(HeapVector { pointer, size }) => (pointer, size),
_ => panic!("Call instruction's args input should be a HeapVector input"),
let args_offset_ptr = match args {
ValueOrArray::HeapArray(HeapArray { pointer, size: _ }) => pointer,
_ => panic!("Call instruction's args input should be a HeapArray input"),
};

avm_instrs.push(AvmInstruction {
Expand Down
10 changes: 5 additions & 5 deletions noir-projects/aztec-nr/aztec/src/authwit/auth.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
authorization_selector::AuthorizationSelector,
},
context::{gas::GasOpts, PrivateContext, PublicContext},
hash::hash_args_array,
hash::hash_args,
macros::authorization::authorization,
oracle::{execution_cache::load, offchain_effect::emit_offchain_effect},
};
Expand Down Expand Up @@ -344,7 +344,7 @@ pub unconstrained fn assert_inner_hash_valid_authwit_public(
let results: [Field] = context.call_public_function(
CANONICAL_AUTH_REGISTRY_ADDRESS,
comptime { FunctionSelector::from_signature("consume((Field),Field)") },
[on_behalf_of.to_field(), inner_hash].as_slice(),
[on_behalf_of.to_field(), inner_hash],
GasOpts::default(),
);
assert(results.len() == 1, "Invalid response from registry");
Expand Down Expand Up @@ -373,7 +373,7 @@ pub fn compute_authwit_message_hash_from_call<let N: u32>(
selector: FunctionSelector,
args: [Field; N],
) -> Field {
let args_hash = hash_args_array(args);
let args_hash = hash_args(args);
let inner_hash =
compute_inner_authwit_hash([caller.to_field(), selector.to_field(), args_hash]);
compute_authwit_message_hash(consumer, chain_id, version, inner_hash)
Expand Down Expand Up @@ -438,7 +438,7 @@ pub unconstrained fn set_authorized(context: PublicContext, message_hash: Field,
let res = context.call_public_function(
CANONICAL_AUTH_REGISTRY_ADDRESS,
comptime { FunctionSelector::from_signature("set_authorized(Field,bool)") },
[message_hash, authorize as Field].as_slice(),
[message_hash, authorize as Field],
GasOpts::default(),
);
assert(res.len() == 0);
Expand All @@ -455,7 +455,7 @@ pub unconstrained fn set_reject_all(context: PublicContext, reject: bool) {
let res = context.call_public_function(
CANONICAL_AUTH_REGISTRY_ADDRESS,
comptime { FunctionSelector::from_signature("set_reject_all(bool)") },
[context.this_address().to_field(), reject as Field].as_slice(),
[context.this_address().to_field(), reject as Field],
GasOpts::default(),
);
assert(res.len() == 0);
Expand Down
61 changes: 30 additions & 31 deletions noir-projects/aztec-nr/aztec/src/context/calls.nr
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@ use dep::protocol_types::{
};

use crate::context::{gas::GasOpts, private_context::PrivateContext, public_context::PublicContext};
use crate::hash::{hash_args, hash_calldata};
use crate::hash::{hash_args, hash_calldata_array};
use crate::oracle::execution_cache;

// PrivateCall

#[must_use = "Your private call needs to be passed into the `self.call(...)` method to be executed (e.g. `self.call(MyContract::at(address).my_private_function(...args))`"]
pub struct PrivateCall<let M: u32, T> {
pub struct PrivateCall<let M: u32, let N: u32, T> {
pub target_contract: AztecAddress,
pub selector: FunctionSelector,
pub name: str<M>,
args_hash: Field,
pub args: [Field],
pub args: [Field; N],
return_type: T,
}

impl<let M: u32, T> PrivateCall<M, T> {
impl<let M: u32, let N: u32, T> PrivateCall<M, N, T> {
pub fn new(
target_contract: AztecAddress,
selector: FunctionSelector,
name: str<M>,
args: [Field],
args: [Field; N],
) -> Self {
let args_hash = hash_args(args);
Self { target_contract, selector, name, args_hash, args, return_type: std::mem::zeroed() }
}
}

impl<let M: u32, T> PrivateCall<M, T>
impl<let M: u32, let N: u32, T> PrivateCall<M, N, T>
where
T: Deserialize,
{
Expand All @@ -58,21 +58,21 @@ where
// PrivateStaticCall

#[must_use = "Your private static call needs to be passed into the `self.view(...)` method to be executed (e.g. `self.view(MyContract::at(address).my_private_static_function(...args))`"]
pub struct PrivateStaticCall<let M: u32, T> {
pub struct PrivateStaticCall<let M: u32, let N: u32, T> {
pub target_contract: AztecAddress,
pub selector: FunctionSelector,
pub name: str<M>,
args_hash: Field,
pub args: [Field],
pub args: [Field; N],
return_type: T,
}

impl<let M: u32, T> PrivateStaticCall<M, T> {
impl<let M: u32, let N: u32, T> PrivateStaticCall<M, N, T> {
pub fn new(
target_contract: AztecAddress,
selector: FunctionSelector,
name: str<M>,
args: [Field],
args: [Field; N],
) -> Self {
let args_hash = hash_args(args);
Self { target_contract, selector, name, args_hash, args, return_type: std::mem::zeroed() }
Expand Down Expand Up @@ -100,22 +100,21 @@ impl<let M: u32, T> PrivateStaticCall<M, T> {
// PublicCall

#[must_use = "Your public call needs to be passed into the `self.call(...)`, `self.enqueue(...)` or `self.enqueue_incognito(...)` method to be executed (e.g. `self.call(MyContract::at(address).my_public_function(...args))`"]
pub struct PublicCall<let M: u32, T> {
pub struct PublicCall<let M: u32, let N: u32, T> {
pub target_contract: AztecAddress,
pub selector: FunctionSelector,
pub name: str<M>,
// TODO(F-131): Determine the length at comptime and drop the use of slices.
pub args: [Field],
pub args: [Field; N],
gas_opts: GasOpts,
return_type: T,
}

impl<let M: u32, T> PublicCall<M, T> {
impl<let M: u32, let N: u32, T> PublicCall<M, N, T> {
pub fn new(
target_contract: AztecAddress,
selector: FunctionSelector,
name: str<M>,
args: [Field],
args: [Field; N],
) -> Self {
Self {
target_contract,
Expand Down Expand Up @@ -173,8 +172,8 @@ impl<let M: u32, T> PublicCall<M, T> {
is_static_call: bool,
hide_msg_sender: bool,
) {
let calldata = self.args.push_front(self.selector.to_field());
let calldata_hash = hash_calldata(calldata);
let calldata = [self.selector.to_field()].concat(self.args);
let calldata_hash = hash_calldata_array(calldata);
execution_cache::store(calldata, calldata_hash);
context.call_public_function_with_calldata_hash(
self.target_contract,
Expand All @@ -201,8 +200,8 @@ impl<let M: u32, T> PublicCall<M, T> {
}

fn set_as_teardown_impl(self, context: &mut PrivateContext, hide_msg_sender: bool) {
let calldata = self.args.push_front(self.selector.to_field());
let calldata_hash = hash_calldata(calldata);
let calldata = [self.selector.to_field()].concat(self.args);
let calldata_hash = hash_calldata_array(calldata);
execution_cache::store(calldata, calldata_hash);
context.set_public_teardown_function_with_calldata_hash(
self.target_contract,
Expand All @@ -216,21 +215,21 @@ impl<let M: u32, T> PublicCall<M, T> {
// PublicStaticCall

#[must_use = "Your public static call needs to be passed into the `self.view(...)`, `self.enqueue_view(...)` or `self.enqueue_view_incognito(...)` method to be executed (e.g. `self.view(MyContract::at(address).my_public_static_function(...args))`"]
pub struct PublicStaticCall<let M: u32, T> {
pub struct PublicStaticCall<let M: u32, let N: u32, T> {
pub target_contract: AztecAddress,
pub selector: FunctionSelector,
pub name: str<M>,
pub args: [Field],
pub args: [Field; N],
return_type: T,
gas_opts: GasOpts,
}

impl<let M: u32, T> PublicStaticCall<M, T> {
impl<let M: u32, let N: u32, T> PublicStaticCall<M, N, T> {
pub fn new(
target_contract: AztecAddress,
selector: FunctionSelector,
name: str<M>,
args: [Field],
args: [Field; N],
) -> Self {
Self {
target_contract,
Expand Down Expand Up @@ -269,8 +268,8 @@ impl<let M: u32, T> PublicStaticCall<M, T> {
/// `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) {
let calldata = self.args.push_front(self.selector.to_field());
let calldata_hash = hash_calldata(calldata);
let calldata = [self.selector.to_field()].concat(self.args);
let calldata_hash = hash_calldata_array(calldata);
execution_cache::store(calldata, calldata_hash);
context.call_public_function_with_calldata_hash(
self.target_contract,
Expand All @@ -286,8 +285,8 @@ impl<let M: u32, T> PublicStaticCall<M, T> {
/// `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) {
let calldata = self.args.push_front(self.selector.to_field());
let calldata_hash = hash_calldata(calldata);
let calldata = [self.selector.to_field()].concat(self.args);
let calldata_hash = hash_calldata_array(calldata);
execution_cache::store(calldata, calldata_hash);
context.call_public_function_with_calldata_hash(
self.target_contract,
Expand All @@ -301,21 +300,21 @@ impl<let M: u32, T> PublicStaticCall<M, T> {

// UtilityCall

pub struct UtilityCall<let M: u32, T> {
pub struct UtilityCall<let M: u32, let N: u32, T> {
pub target_contract: AztecAddress,
pub selector: FunctionSelector,
pub name: str<M>,
args_hash: Field,
pub args: [Field],
pub args: [Field; N],
return_type: T,
}

impl<let M: u32, T> UtilityCall<M, T> {
impl<let M: u32, let N: u32, T> UtilityCall<M, N, T> {
pub fn new(
target_contract: AztecAddress,
selector: FunctionSelector,
name: str<M>,
args: [Field],
args: [Field; N],
) -> Self {
let args_hash = hash_args(args);
Self { target_contract, selector, name, args_hash, args, return_type: std::mem::zeroed() }
Expand Down
8 changes: 4 additions & 4 deletions noir-projects/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
context::{
inputs::PrivateContextInputs, note_hash_read::NoteHashRead, returns_hash::ReturnsHash,
},
hash::{hash_args_array, hash_calldata_array},
hash::{hash_args, hash_calldata_array},
keys::constants::{NULLIFIER_INDEX, NUM_KEY_TYPES, OUTGOING_INDEX, sk_generators},
messaging::process_l1_to_l2_message,
oracle::{
Expand Down Expand Up @@ -572,7 +572,7 @@ impl PrivateContext {
/// * `serialized_return_values` - The serialized return values as a field array
///
pub fn set_return_hash<let N: u32>(&mut self, serialized_return_values: [Field; N]) {
let return_hash = hash_args_array(serialized_return_values);
let return_hash = hash_args(serialized_return_values);
self.return_hash = return_hash;
execution_cache::store(serialized_return_values, return_hash);
}
Expand Down Expand Up @@ -1263,7 +1263,7 @@ impl PrivateContext {
function_selector: FunctionSelector,
args: [Field; ArgsCount],
) -> ReturnsHash {
let args_hash = hash_args_array(args);
let args_hash = hash_args(args);
execution_cache::store(args, args_hash);
self.call_private_function_with_args_hash(
contract_address,
Expand Down Expand Up @@ -1297,7 +1297,7 @@ impl PrivateContext {
function_selector: FunctionSelector,
args: [Field; ArgsCount],
) -> ReturnsHash {
let args_hash = hash_args_array(args);
let args_hash = hash_args(args);
execution_cache::store(args, args_hash);
self.call_private_function_with_args_hash(
contract_address,
Expand Down
Loading
Loading