Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: delegate calls #4586

Merged
merged 54 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
bf6df00
initial static impl private
Thunkar Jan 17, 2024
e7ea9f2
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Jan 17, 2024
91e60ce
initial version for private calls
Thunkar Jan 17, 2024
05287b9
Merge branch 'master' into gj/static_calls
Thunkar Jan 17, 2024
73a5d1b
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Jan 19, 2024
a4067f0
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 2, 2024
f32dc71
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 2, 2024
47a254c
merge
Thunkar Feb 2, 2024
84866c9
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 5, 2024
c74857c
public static calls
Thunkar Feb 6, 2024
4ec039c
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 6, 2024
457245d
working static calls in aztec.js
Thunkar Feb 7, 2024
ac6ed93
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 7, 2024
21de063
removed duplicate tests
Thunkar Feb 7, 2024
373dae6
added tests to CI
Thunkar Feb 7, 2024
5a20896
properly added new e2e test. probably
Thunkar Feb 7, 2024
a5753ae
added static support to simulate
Thunkar Feb 7, 2024
b41b0bc
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 7, 2024
791a97b
Merge branch 'master' into gj/static_calls
Thunkar Feb 8, 2024
a47d987
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 12, 2024
954c875
logs and l2-l1 messages checks
Thunkar Feb 12, 2024
6b3d71c
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 12, 2024
5276480
more checks and moved to simulate call
Thunkar Feb 12, 2024
65c7856
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 12, 2024
0bcd86c
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 12, 2024
f093395
merge change
Thunkar Feb 12, 2024
e48e5ed
fixes
Thunkar Feb 13, 2024
361400c
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 13, 2024
0c4293c
fixes and removed static in aztec.js
Thunkar Feb 13, 2024
afd4ea3
Merge branch 'master' into gj/static_calls
Thunkar Feb 13, 2024
8fe5bda
initial approach
Thunkar Feb 13, 2024
c65473d
fix
Thunkar Feb 14, 2024
eb3ccdf
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 14, 2024
0dc6217
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 14, 2024
0191d2c
fix and format
Thunkar Feb 14, 2024
5255c39
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 14, 2024
341962d
Merge branch 'gj/static_calls' of github.com:AztecProtocol/aztec-pack…
Thunkar Feb 14, 2024
9540cd5
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 14, 2024
35e1758
working version
Thunkar Feb 14, 2024
5875bb9
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 14, 2024
de7bab8
readded caller verifications in kernel
Thunkar Feb 14, 2024
6fb5939
fixed kernel checks
Thunkar Feb 15, 2024
305562f
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 15, 2024
6ca54a9
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 15, 2024
8eeb79d
kernel and callrequest fixes
Thunkar Feb 15, 2024
99ef0e1
Merge branch 'master' into gj/delegate_calls
Thunkar Feb 15, 2024
b363167
fixed test
Thunkar Feb 16, 2024
dbf01f1
Merge branch 'gj/delegate_calls' of github.com:AztecProtocol/aztec-pa…
Thunkar Feb 16, 2024
0872f37
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 16, 2024
c44b87b
fix yp
Thunkar Feb 16, 2024
5df6ca2
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Feb 16, 2024
953595d
test fixes
Thunkar Feb 16, 2024
255e4da
merge and PR fixes
Thunkar Feb 16, 2024
591b9c0
readded modifier
Thunkar Feb 16, 2024
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
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,17 @@ jobs:
name: "Test"
command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=e2e_static_calls.test.ts

e2e-delegate-calls:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
steps:
- *checkout
- *setup_env
- run:
name: "Test"
command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=e2e_delegate_calls.test.ts

e2e-non-contract-account:
docker:
- image: aztecprotocol/alpine-build-image
Expand Down Expand Up @@ -1330,6 +1341,7 @@ workflows:
- e2e-block-building: *e2e_test
- e2e-nested-contract: *e2e_test
- e2e-static-calls: *e2e_test
- e2e-delegate-calls: *e2e_test
- e2e-non-contract-account: *e2e_test
- e2e-multiple-accounts-1-enc-key: *e2e_test
- e2e-cli: *e2e_test
Expand Down Expand Up @@ -1373,6 +1385,7 @@ workflows:
- e2e-block-building
- e2e-nested-contract
- e2e-static-calls
- e2e-delegate-calls
- e2e-non-contract-account
- e2e-multiple-accounts-1-enc-key
- e2e-cli
Expand Down
2 changes: 2 additions & 0 deletions noir-projects/aztec-nr/authwit/src/entrypoint/app.nr
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ impl AppPayload {
call.target_address,
call.function_selector,
call.args_hash,
false,
false
);
} else {
let _result = context.call_private_function_with_packed_args(
call.target_address,
call.function_selector,
call.args_hash,
false,
false
);
}
Expand Down
2 changes: 2 additions & 0 deletions noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ impl FeePayload {
call.target_address,
call.function_selector,
call.args_hash,
false,
false
);
} else {
let _result = context.call_private_function_with_packed_args(
Thunkar marked this conversation as resolved.
Show resolved Hide resolved
call.target_address,
call.function_selector,
call.args_hash,
false,
false
);
}
Expand Down
122 changes: 89 additions & 33 deletions noir-projects/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -251,49 +251,70 @@ impl PrivateContext {
) -> [Field; RETURN_VALUES_LENGTH] {
let args_hash = hash_args(args);
assert(args_hash == arguments::pack_arguments(args));
self.call_private_function_with_packed_args(contract_address, function_selector, args_hash, false)
self.call_private_function_with_packed_args(contract_address, function_selector, args_hash, false, false)
}

pub fn call_private_function_static<ARGS_COUNT>(
pub fn static_call_private_function<ARGS_COUNT>(
&mut self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT]
) -> [Field; RETURN_VALUES_LENGTH] {
let args_hash = hash_args(args);
assert(args_hash == arguments::pack_arguments(args));
self.call_private_function_with_packed_args(contract_address, function_selector, args_hash, true)
self.call_private_function_with_packed_args(contract_address, function_selector, args_hash, true, false)
}

pub fn delegate_call_private_function<ARGS_COUNT>(
&mut self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT]
) -> [Field; RETURN_VALUES_LENGTH] {
let args_hash = hash_args(args);
assert(args_hash == arguments::pack_arguments(args));
self.call_private_function_with_packed_args(contract_address, function_selector, args_hash, false, true)
}

pub fn call_private_function_no_args(
&mut self,
contract_address: AztecAddress,
function_selector: FunctionSelector
) -> [Field; RETURN_VALUES_LENGTH] {
self.call_private_function_with_packed_args(contract_address, function_selector, 0, false)
self.call_private_function_with_packed_args(contract_address, function_selector, 0, false, false)
}

pub fn static_call_private_function_no_args(
&mut self,
contract_address: AztecAddress,
function_selector: FunctionSelector
) -> [Field; RETURN_VALUES_LENGTH] {
self.call_private_function_with_packed_args(contract_address, function_selector, 0, true, false)
}

pub fn call_private_function_no_args_static(
pub fn delegate_call_private_function_no_args<ARGS_COUNT>(
&mut self,
contract_address: AztecAddress,
function_selector: FunctionSelector
) -> [Field; RETURN_VALUES_LENGTH] {
self.call_private_function_with_packed_args(contract_address, function_selector, 0, true)
self.call_private_function_with_packed_args(contract_address, function_selector, 0, false, true)
}

fn call_private_function_with_packed_args(
pub fn call_private_function_with_packed_args(
&mut self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args_hash: Field,
is_static_call: bool
is_static_call: bool,
is_delegate_call: bool
) -> [Field; RETURN_VALUES_LENGTH] {
let item = call_private_function_internal(
contract_address,
function_selector,
args_hash,
self.side_effect_counter,
is_static_call
is_static_call,
is_delegate_call
);

assert_eq(item.public_inputs.call_context.start_side_effect_counter, self.side_effect_counter);
Expand All @@ -305,16 +326,23 @@ impl PrivateContext {
assert(args_hash == item.public_inputs.args_hash);

// Assert that the call context of the enqueued call generated by the oracle matches our request.
// We are issuing a regular call which is not delegate, static, or deployment. We also constrain
// the msg_sender in the nested call to be equal to our address, and the execution context address
// for the nested call to be equal to the address we actually called.
assert(item.public_inputs.call_context.is_delegate_call == false);
assert(item.public_inputs.call_context.is_delegate_call == is_delegate_call);
assert(item.public_inputs.call_context.is_static_call == is_static_call);
assert(item.public_inputs.call_context.is_contract_deployment == false);
assert(
item.public_inputs.call_context.msg_sender.eq(self.inputs.call_context.storage_contract_address)
);
assert(item.public_inputs.call_context.storage_contract_address.eq(contract_address));

if (is_delegate_call) {
Thunkar marked this conversation as resolved.
Show resolved Hide resolved
// For delegate calls, we also constrain the execution context address for the nested call to be equal to our address.
assert(
item.public_inputs.call_context.storage_contract_address.eq(self.inputs.call_context.storage_contract_address)
);
assert(item.public_inputs.call_context.msg_sender.eq(self.inputs.call_context.msg_sender));
} else {
// For non-delegate calls, we also constrain the execution context address for the nested call to be equal to the address we called.
assert(item.public_inputs.call_context.storage_contract_address.eq(contract_address));
assert(
item.public_inputs.call_context.msg_sender.eq(self.inputs.call_context.storage_contract_address)
);
}

self.private_call_stack_hashes.push(item.hash());

Expand All @@ -329,49 +357,70 @@ impl PrivateContext {
) {
let args_hash = hash_args(args);
assert(args_hash == arguments::pack_arguments(args));
self.call_public_function_with_packed_args(contract_address, function_selector, args_hash, false)
self.call_public_function_with_packed_args(contract_address, function_selector, args_hash, false, false)
}

pub fn call_public_function_static<ARGS_COUNT>(
pub fn static_call_public_function<ARGS_COUNT>(
&mut self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT]
) {
let args_hash = hash_args(args);
assert(args_hash == arguments::pack_arguments(args));
self.call_public_function_with_packed_args(contract_address, function_selector, args_hash, true)
self.call_public_function_with_packed_args(contract_address, function_selector, args_hash, true, false)
}

pub fn delegate_call_public_function<ARGS_COUNT>(
&mut self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT]
) {
let args_hash = hash_args(args);
assert(args_hash == arguments::pack_arguments(args));
self.call_public_function_with_packed_args(contract_address, function_selector, args_hash, false, true)
}

pub fn call_public_function_no_args(
&mut self,
contract_address: AztecAddress,
function_selector: FunctionSelector
) {
self.call_public_function_with_packed_args(contract_address, function_selector, 0, false)
self.call_public_function_with_packed_args(contract_address, function_selector, 0, false, false)
}

pub fn static_call_public_function_no_args(
&mut self,
contract_address: AztecAddress,
function_selector: FunctionSelector
) {
self.call_public_function_with_packed_args(contract_address, function_selector, 0, true, false)
}

pub fn call_public_function_no_args_static(
pub fn delegate_call_public_function_no_args(
&mut self,
contract_address: AztecAddress,
function_selector: FunctionSelector
) {
self.call_public_function_with_packed_args(contract_address, function_selector, 0, true)
self.call_public_function_with_packed_args(contract_address, function_selector, 0, false, true)
}

pub fn call_public_function_with_packed_args(
&mut self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args_hash: Field,
is_static_call: bool
is_static_call: bool,
is_delegate_call: bool
) {
let fields = enqueue_public_function_call_internal(
contract_address,
function_selector,
args_hash,
self.side_effect_counter,
is_static_call
is_static_call,
is_delegate_call
);

let mut reader = Reader::new(fields);
Expand Down Expand Up @@ -410,16 +459,23 @@ impl PrivateContext {
assert(args_hash == item.public_inputs.args_hash);

// Assert that the call context of the enqueued call generated by the oracle matches our request.
// We are issuing a regular call which is not delegate, static, or deployment. We also constrain
// the msg_sender in the nested call to be equal to our address, and the execution context address
// for the nested call to be equal to the address we actually called.
assert(item.public_inputs.call_context.is_delegate_call == false);
assert(item.public_inputs.call_context.is_delegate_call == is_delegate_call);
assert(item.public_inputs.call_context.is_static_call == is_static_call);
assert(item.public_inputs.call_context.is_contract_deployment == false);
assert(
item.public_inputs.call_context.msg_sender.eq(self.inputs.call_context.storage_contract_address)
);
assert(item.public_inputs.call_context.storage_contract_address.eq(contract_address));

if (is_delegate_call) {
// For delegate calls, we also constrain the execution context address for the nested call to be equal to our address.
assert(
item.public_inputs.call_context.storage_contract_address.eq(self.inputs.call_context.storage_contract_address)
);
assert(item.public_inputs.call_context.msg_sender.eq(self.inputs.call_context.msg_sender));
} else {
// For non-delegate calls, we also constrain the execution context address for the nested call to be equal to the address we called.
assert(item.public_inputs.call_context.storage_contract_address.eq(contract_address));
assert(
item.public_inputs.call_context.msg_sender.eq(self.inputs.call_context.storage_contract_address)
);
}

self.public_call_stack_hashes.push(item.hash());
}
Expand Down
31 changes: 25 additions & 6 deletions noir-projects/aztec-nr/aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -194,33 +194,52 @@ impl PublicContext {
) -> [Field; RETURN_VALUES_LENGTH] {
let args_hash = hash_args(args);
assert(args_hash == arguments::pack_arguments(args));
call_public_function_internal(contract_address, function_selector, args_hash, false)
call_public_function_internal(contract_address, function_selector, args_hash, false, false)
}

pub fn call_public_function_static<ARGS_COUNT>(
pub fn static_call_public_function<ARGS_COUNT>(
_self: Self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT]
) -> [Field; RETURN_VALUES_LENGTH] {
let args_hash = hash_args(args);
assert(args_hash == arguments::pack_arguments(args));
call_public_function_internal(contract_address, function_selector, args_hash, true)
call_public_function_internal(contract_address, function_selector, args_hash, true, false)
}

pub fn delegate_call_public_function<ARGS_COUNT>(
_self: Self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT]
) -> [Field; RETURN_VALUES_LENGTH] {
let args_hash = hash_args(args);
assert(args_hash == arguments::pack_arguments(args));
call_public_function_internal(contract_address, function_selector, args_hash, false, true)
}

pub fn call_public_function_no_args(
_self: Self,
contract_address: AztecAddress,
function_selector: FunctionSelector
) -> [Field; RETURN_VALUES_LENGTH] {
call_public_function_internal(contract_address, function_selector, 0, false)
call_public_function_internal(contract_address, function_selector, 0, false, false)
}

pub fn static_call_public_function_no_args(
_self: Self,
contract_address: AztecAddress,
function_selector: FunctionSelector
) -> [Field; RETURN_VALUES_LENGTH] {
call_public_function_internal(contract_address, function_selector, 0, true, false)
}

pub fn call_public_function_no_args_static(
pub fn delegate_call_public_function_no_args(
_self: Self,
contract_address: AztecAddress,
function_selector: FunctionSelector
) -> [Field; RETURN_VALUES_LENGTH] {
call_public_function_internal(contract_address, function_selector, 0, true)
call_public_function_internal(contract_address, function_selector, 0, false, true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@ fn call_private_function_oracle(
_function_selector: FunctionSelector,
_args_hash: Field,
_start_side_effect_counter: u32,
_is_static_call: bool
_is_static_call: bool,
_is_delegate_call: bool
) -> [Field; PRIVATE_CALL_STACK_ITEM_LENGTH] {}

unconstrained pub fn call_private_function_internal(
contract_address: AztecAddress,
function_selector: FunctionSelector,
args_hash: Field,
start_side_effect_counter: u32,
is_static_call: bool
is_static_call: bool,
is_delegate_call: bool
) -> PrivateCallStackItem {
let fields = call_private_function_oracle(
contract_address,
function_selector,
args_hash,
start_side_effect_counter,
is_static_call
is_static_call,
is_delegate_call
);

PrivateCallStackItem::deserialize(fields)
Expand Down
Loading
Loading