Skip to content

Commit

Permalink
reverted public context change
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunkar committed Apr 16, 2024
1 parent 6802f9c commit 189edf1
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 64 deletions.
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/authwit/src/auth.nr
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn assert_current_call_valid_authwit_public<TPublicContext>(
context,
on_behalf_of,
function_selector,
[inner_hash].as_slice(),
[inner_hash],
GasOpts::default()
).deserialize_into();
assert(result == IS_VALID_SELECTOR, "Message not authorized by account");
Expand Down
16 changes: 8 additions & 8 deletions noir-projects/aztec-nr/aztec/src/context/avm_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,17 @@ impl PublicContextInterface for AvmContext {
send_l2_to_l1_msg(recipient, content);
}

fn call_public_function<RETURNS_COUNT>(
fn call_public_function<ARGS_COUNT, RETURNS_COUNT>(
self: &mut Self,
contract_address: AztecAddress,
temporary_function_selector: FunctionSelector,
args: [Field],
args: [Field; ARGS_COUNT],
gas_opts: GasOpts
) -> FunctionReturns<RETURNS_COUNT> {
let results = call(
gas_for_call(gas_opts),
contract_address,
args,
args.as_slice(),
temporary_function_selector.to_field()
);
let data_to_return: [Field; RETURNS_COUNT] = results.0;
Expand All @@ -156,29 +156,29 @@ impl PublicContextInterface for AvmContext {
FunctionReturns::new(data_to_return)
}

fn static_call_public_function<RETURNS_COUNT>(
fn static_call_public_function<ARGS_COUNT, RETURNS_COUNT>(
self: &mut Self,
contract_address: AztecAddress,
temporary_function_selector: FunctionSelector,
args: [Field],
args: [Field; ARGS_COUNT],
gas_opts: GasOpts
) -> FunctionReturns<RETURNS_COUNT> {
let (data_to_return, success): ([Field; RETURNS_COUNT], u8) = call_static(
gas_for_call(gas_opts),
contract_address,
args,
args.as_slice(),
temporary_function_selector.to_field()
);

assert(success == 1, "Nested static call failed!");
FunctionReturns::new(data_to_return)
}

fn delegate_call_public_function<RETURNS_COUNT>(
fn delegate_call_public_function<ARGS_COUNT, RETURNS_COUNT>(
self: &mut Self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field]
args: [Field; ARGS_COUNT]
) -> FunctionReturns<RETURNS_COUNT> {
assert(false, "'delegate_call_public_function' not implemented!");
FunctionReturns::new([0; RETURNS_COUNT])
Expand Down
64 changes: 45 additions & 19 deletions noir-projects/aztec-nr/aztec/src/context/interface.nr
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ trait PublicContextInterface {
fn consume_l1_to_l2_message(&mut self, content: Field, secret: Field, sender: EthAddress);
fn accumulate_encrypted_logs<N>(&mut self, log: [Field; N]);
fn accumulate_unencrypted_logs<T>(&mut self, log: T);
fn call_public_function<RETURNS_COUNT>(
fn call_public_function<ARGS_COUNT, RETURNS_COUNT>(
self: &mut Self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field],
args: [Field; ARGS_COUNT],
gas_opts: GasOpts
) -> FunctionReturns<RETURNS_COUNT>;
fn static_call_public_function<RETURNS_COUNT>(
fn static_call_public_function<ARGS_COUNT, RETURNS_COUNT>(
self: &mut Self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field],
args: [Field; ARGS_COUNT],
gas_opts: GasOpts
) -> FunctionReturns<RETURNS_COUNT>;
fn delegate_call_public_function<RETURNS_COUNT>(
fn delegate_call_public_function<ARGS_COUNT, RETURNS_COUNT>(
self: &mut Self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field]
args: [Field; ARGS_COUNT]
) -> FunctionReturns<RETURNS_COUNT>;
fn nullifier_exists(self, unsiloed_nullifier: Field, address: AztecAddress) -> bool;
}
Expand Down Expand Up @@ -215,22 +215,35 @@ struct AvmCallInterface<T> {

impl<T> AvmCallInterface<T> {
pub fn call<N>(self, context: &mut AvmContext, gas_opts: GasOpts) -> T where T: Deserialize<N> {
let returns = context.call_public_function(self.target_contract, self.selector, self.args, gas_opts);
returns.deserialize_into()
let (data_to_return, success) = context.call_public_function_raw(
gas_opts,
self.target_contract,
self.selector.to_field(),
self.args
);
assert(success == 1, "Nested call failed!");

FunctionReturns::new(data_to_return).deserialize_into()
}

pub fn static_call<N>(
self,
context: &mut AvmContext,
gas_opts: GasOpts
) -> T where T: Deserialize<N> {
let returns = context.static_call_public_function(self.target_contract, self.selector, self.args, gas_opts);
returns.deserialize_into()
let (data_to_return, success) = context.static_call_public_function_raw(
gas_opts,
self.target_contract,
self.selector.to_field(),
self.args
);
assert(success == 1, "Nested call failed!");

FunctionReturns::new(data_to_return).deserialize_into()
}

pub fn delegate_call<N>(self, context: &mut AvmContext) -> T where T: Deserialize<N> {
let returns = context.delegate_call_public_function(self.target_contract, self.selector, self.args);
returns.deserialize_into()
pub fn delegate_call<N>(self, context: &mut AvmContext) {
assert(false, "'delegate_call_public_function' not implemented!");
}
}

Expand All @@ -242,17 +255,30 @@ struct AvmVoidCallInterface {

impl AvmVoidCallInterface {
pub fn call<N>(self, context: &mut AvmContext, gas_opts: GasOpts) {
let returns = context.call_public_function(self.target_contract, self.selector, self.args, gas_opts);
returns.assert_empty()
let (data_to_return, success) = context.call_public_function_raw(
gas_opts,
self.target_contract,
self.selector.to_field(),
self.args
);
assert(success == 1, "Nested call failed!");

FunctionReturns::new(data_to_return).assert_empty()
}

pub fn static_call<N>(self, context: &mut AvmContext, gas_opts: GasOpts) {
let returns = context.static_call_public_function(self.target_contract, self.selector, self.args, gas_opts);
returns.assert_empty()
let (data_to_return, success) = context.static_call_public_function_raw(
gas_opts,
self.target_contract,
self.selector.to_field(),
self.args
);
assert(success == 1, "Nested call failed!");

FunctionReturns::new(data_to_return).assert_empty()
}

pub fn delegate_call<N>(self, context: &mut AvmContext) {
let returns = context.delegate_call_public_function(self.target_contract, self.selector, self.args);
returns.assert_empty()
assert(false, "'delegate_call_public_function' not implemented!");
}
}
26 changes: 13 additions & 13 deletions noir-projects/aztec-nr/aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
},
messaging::process_l1_to_l2_message,
oracle::{arguments, public_call::call_public_function_internal, returns},
hash::{hash_args, ArgsHasher}
hash::{hash_args_array, ArgsHasher}
};
use dep::protocol_types::{
abis::{
Expand Down Expand Up @@ -291,38 +291,38 @@ impl PublicContextInterface for PublicContext {
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)
}

fn call_public_function<RETURNS_COUNT>(
fn call_public_function<ARGS_COUNT, RETURNS_COUNT>(
self: &mut Self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field],
args: [Field; ARGS_COUNT],
_gas: GasOpts
) -> FunctionReturns<RETURNS_COUNT> {
let args_hash = hash_args(args);
assert(args_hash == arguments::pack_arguments(args));
let args_hash = hash_args_array(args);
assert(args_hash == arguments::pack_arguments_array(args));
self.call_public_function_with_packed_args(contract_address, function_selector, args_hash, false, false)
}

fn static_call_public_function<RETURNS_COUNT>(
fn static_call_public_function<ARGS_COUNT, RETURNS_COUNT>(
self: &mut Self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field],
args: [Field; ARGS_COUNT],
_gas: GasOpts
) -> FunctionReturns<RETURNS_COUNT> {
let args_hash = hash_args(args);
assert(args_hash == arguments::pack_arguments(args));
let args_hash = hash_args_array(args);
assert(args_hash == arguments::pack_arguments_array(args));
self.call_public_function_with_packed_args(contract_address, function_selector, args_hash, true, false)
}

fn delegate_call_public_function<RETURNS_COUNT>(
fn delegate_call_public_function<ARGS_COUNT, RETURNS_COUNT>(
self: &mut Self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field]
args: [Field; ARGS_COUNT]
) -> FunctionReturns<RETURNS_COUNT> {
let args_hash = hash_args(args);
assert(args_hash == arguments::pack_arguments(args));
let args_hash = hash_args_array(args);
assert(args_hash == arguments::pack_arguments_array(args));
self.call_public_function_with_packed_args(contract_address, function_selector, args_hash, false, true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract AvmAcvmInteropTest {
context.call_public_function(
context.this_address(),
FunctionSelector::from_signature("constant_field_acvm()"),
[].as_slice(),
[],
GasOpts::default()
).deserialize_into()
}
Expand All @@ -52,19 +52,14 @@ contract AvmAcvmInteropTest {
context.call_public_function(
context.this_address(),
FunctionSelector::from_signature("constant_field_avm()"),
[].as_slice(),
[],
GasOpts::default()
).deserialize_into()
}

#[aztec(public-vm)]
fn avm_to_acvm_call(selector: FunctionSelector, args: Field) {
context.call_public_function(
context.this_address(),
selector,
[args].as_slice(),
GasOpts::default()
).assert_empty();
context.call_public_function(context.this_address(), selector, [args], GasOpts::default()).assert_empty();
}

/************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ contract Crowdfunding {
#[aztec(private)]
fn donate(amount: u64) {
// 1) Check that the deadline has not passed
context.call_public_function(
context.this_address(),
FunctionSelector::from_signature("_check_deadline()"),
[]
);
Crowdfunding::at(context.this_address())._check_deadline().enqueue(&mut context);

// 2) Transfer the donation tokens from donor to this contract
Token::at(storage.donation_token.read_private()).transfer(
Expand Down
15 changes: 5 additions & 10 deletions noir-projects/noir-contracts/contracts/parent_contract/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract Parent {
context.call_public_function(
target_contract,
target_selector,
[init_value].as_slice(),
[init_value],
GasOpts::default()
).deserialize_into()
}
Expand All @@ -35,13 +35,13 @@ contract Parent {
let return_value: Field = context.call_public_function(
target_contract,
target_selector,
[init_value].as_slice(),
[init_value],
GasOpts::default()
).deserialize_into();
context.call_public_function(
target_contract,
target_selector,
[return_value].as_slice(),
[return_value],
GasOpts::default()
).deserialize_into()
}
Expand Down Expand Up @@ -189,12 +189,7 @@ contract Parent {
target_selector: FunctionSelector,
args: [Field; 1]
) -> Field {
context.static_call_public_function(
target_contract,
target_selector,
args.as_slice(),
GasOpts::default()
).deserialize_into()
context.static_call_public_function(target_contract, target_selector, args, GasOpts::default()).deserialize_into()
}

// Public function to set a static context and verify correct propagation for nested public calls
Expand All @@ -210,7 +205,7 @@ contract Parent {
context.static_call_public_function(
this_address,
pub_entry_point_selector,
[target_contract.to_field(), target_selector.to_field(), args[0]].as_slice(),
[target_contract.to_field(), target_selector.to_field(), args[0]],
GasOpts::default()
).deserialize_into()
}
Expand Down

0 comments on commit 189edf1

Please sign in to comment.