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: TXE 2: Electric boogaloo #7154

Merged
merged 95 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 80 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
39e88bf
Adapt public immutable
nventuro May 30, 2024
de4dfef
Add comments to private imnmutable
nventuro May 31, 2024
584250d
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Jun 3, 2024
8c5bdf1
TXE
Thunkar Jun 3, 2024
3fbc3ee
improvements
Thunkar Jun 3, 2024
58c4c82
fixed tsconfig
Thunkar Jun 3, 2024
84af5e8
public data tree witness
Thunkar Jun 3, 2024
aab9959
return null
Thunkar Jun 3, 2024
c94d32e
more oracle calls
Thunkar Jun 4, 2024
5d857ae
more oracles, timetravel
Thunkar Jun 4, 2024
717a16a
fix
Thunkar Jun 4, 2024
58e7bfa
Sketch nr tests for txe testing
nventuro Jun 4, 2024
d543edf
fix
Thunkar Jun 4, 2024
92b9a48
Begin test refactor
nventuro Jun 4, 2024
c6fdef6
fix
Thunkar Jun 4, 2024
b29b3a4
fixes
Thunkar Jun 4, 2024
6628ab0
fix
Thunkar Jun 4, 2024
460a1d1
private context inputs
Thunkar Jun 4, 2024
069a09a
return struct
Thunkar Jun 4, 2024
7edc719
fix
Thunkar Jun 4, 2024
f2820a7
configurable private inputs
Thunkar Jun 4, 2024
cbe1564
???
nventuro Jun 4, 2024
2250b98
???
nventuro Jun 4, 2024
45434f9
fixes
Thunkar Jun 4, 2024
c180bdb
git add .
nventuro Jun 4, 2024
a34bf85
fixes and moar
Thunkar Jun 4, 2024
fdbeaf8
note handling
Thunkar Jun 4, 2024
12453ea
Samples
nventuro Jun 5, 2024
fdd5cf1
Add address fixes
nventuro Jun 7, 2024
ff3fa71
almost there
Thunkar Jun 7, 2024
ea506ab
working proto
Thunkar Jun 7, 2024
562e92e
initial txe version
Thunkar Jun 10, 2024
e037804
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Jun 10, 2024
21f3178
removed file
Thunkar Jun 10, 2024
c543a2c
Add TXE
nventuro Jun 10, 2024
0d1221a
Merge branch 'gj_nv/txe' of github.com:AztecProtocol/aztec-packages i…
Thunkar Jun 10, 2024
6083ade
fixes
Thunkar Jun 10, 2024
b80f6c7
fixes
Thunkar Jun 10, 2024
ca42523
account abstraction
Thunkar Jun 11, 2024
38fb77e
reverted parallel changes since we have session ids now
Thunkar Jun 11, 2024
dc373da
Merge branch 'master' into gj_nv/txe
Thunkar Jun 11, 2024
85b7dec
updated tsconfig
Thunkar Jun 11, 2024
84292d0
Merge branch 'master' into gj_nv/txe
Thunkar Jun 11, 2024
907e26d
external calls
Thunkar Jun 12, 2024
5a92553
private calls
Thunkar Jun 12, 2024
8b278a1
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Jun 12, 2024
cf027a2
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Jun 12, 2024
5e9486e
public initializers
Thunkar Jun 13, 2024
bbeaa00
34 token transfer
Thunkar Jun 13, 2024
963990a
cleanup
Thunkar Jun 14, 2024
a68fec7
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Jun 14, 2024
44d63aa
sessionId compatibility
Thunkar Jun 14, 2024
9f1dbe6
corrected docs
Thunkar Jun 14, 2024
93f32d0
cleanup
Thunkar Jun 14, 2024
19123bd
formatting
Thunkar Jun 14, 2024
35fe257
better comment
Thunkar Jun 14, 2024
e41a19c
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Jun 14, 2024
1ccfe4f
Merge branch 'master' into gj_nv/txe
Thunkar Jun 14, 2024
eb48006
Merge branch 'master' into gj_nv/txe
Thunkar Jun 17, 2024
cca4e8c
test ci
Thunkar Jun 17, 2024
83c16e5
Merge branch 'gj_nv/txe' of github.com:AztecProtocol/aztec-packages i…
Thunkar Jun 17, 2024
f564d92
working CI
Thunkar Jun 17, 2024
083b1f8
better dockerfile
Thunkar Jun 17, 2024
2155e79
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Jun 18, 2024
d214093
wip
Thunkar Jun 18, 2024
0a1c2e1
fixed account contract deployments
Thunkar Jun 18, 2024
2d934d3
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Jun 18, 2024
e711f21
compatibility with new deployment
Thunkar Jun 18, 2024
553a904
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Jun 19, 2024
9a09e2b
working private authwits
Thunkar Jun 19, 2024
e3c5f71
avoid unnecesary account contract creation
Thunkar Jun 19, 2024
891d331
public execution
Thunkar Jun 20, 2024
c6b4675
authwits, expect failures, token suite
Thunkar Jun 20, 2024
fcf7823
more tests
Thunkar Jun 21, 2024
5dc4c9a
test constrained
Thunkar Jun 21, 2024
1206b87
Revert "test constrained"
Thunkar Jun 21, 2024
05cdb9c
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Jun 21, 2024
aa8e006
moar tests
Thunkar Jun 21, 2024
53b2192
test tweaks
Thunkar Jun 21, 2024
f180efd
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Jun 21, 2024
2c2424d
use only public avm exports
Thunkar Jun 24, 2024
937f561
added comments for context
Thunkar Jun 24, 2024
04d215a
tweaked sideEffectCounters
Thunkar Jun 24, 2024
e76229a
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Jun 24, 2024
899c65a
fixed problem with initializers, more flexibility on nullifiers and n…
Thunkar Jun 24, 2024
bd944d2
typo
Thunkar Jun 24, 2024
9b80629
removed contract import restriction
Thunkar Jun 24, 2024
44366a5
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Jun 24, 2024
0227efe
nargo fmt
Thunkar Jun 24, 2024
625a492
increased timeouts
Thunkar Jun 24, 2024
151e312
yarn formatting
Thunkar Jun 24, 2024
19e323f
formatting
Thunkar Jun 24, 2024
d5f28b4
comments from PR
Thunkar Jun 25, 2024
9c55d33
more comments
Thunkar Jun 25, 2024
8095410
removed unnecessary tree accesses
Thunkar Jun 25, 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
44 changes: 44 additions & 0 deletions noir-projects/aztec-nr/authwit/src/cheatcodes.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use dep::aztec::{
Copy link
Contributor

Choose a reason for hiding this comment

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

I find some of the cheatcode structure slightly odd, e.g., having it a bit all over the place instead of having a folder just with cheatcodes. Ideally think it would be nice to have it outside of the others, to not pollute 🤷. But it is something I think we could deal with in a separate PR.

Might also just be that I am not thinking about something and we need it this way 👍.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of it is in aztec-nr, but for authwits it was necessary to do it this way due to circular dependencies: aztec-nr -> auth -> aztec-nr.

We could have a separate crate, but I though it wouldn't be so bad if our packages exported their tests interfaces themselves.

protocol_types::address::AztecAddress,
context::{public_context::PublicContext, call_interfaces::CallInterface}, test::helpers::cheatcodes,
hash::hash_args
};

use crate::auth::{compute_inner_authwit_hash, compute_outer_authwit_hash, set_authorized};

pub fn add_private_authwit_from_call_interface<C, M, T, P, Env>(
on_behalf_of: AztecAddress,
caller: AztecAddress,
call_interface: C
) where C: CallInterface<M, T, P, Env> {
let target = call_interface.get_contract_address();
let inputs = cheatcodes::get_private_context_inputs(cheatcodes::get_block_number());
let chain_id = inputs.tx_context.chain_id;
let version = inputs.tx_context.version;
let args_hash = hash_args(call_interface.get_args());
let selector = call_interface.get_selector();
let inner_hash = compute_inner_authwit_hash([caller.to_field(), selector.to_field(), args_hash]);
let message_hash = compute_outer_authwit_hash(target, chain_id, version, inner_hash);
cheatcodes::add_authwit(on_behalf_of, message_hash);
}

pub fn add_public_authwit_from_call_interface<C, M, T, P, Env>(
on_behalf_of: AztecAddress,
caller: AztecAddress,
call_interface: C
) where C: CallInterface<M, T, P, Env> {
let current_contract = cheatcodes::get_contract_address();
cheatcodes::set_contract_address(on_behalf_of);
let target = call_interface.get_contract_address();
let inputs = cheatcodes::get_private_context_inputs(cheatcodes::get_block_number());
let chain_id = inputs.tx_context.chain_id;
let version = inputs.tx_context.version;
let args_hash = hash_args(call_interface.get_args());
let selector = call_interface.get_selector();
let inner_hash = compute_inner_authwit_hash([caller.to_field(), selector.to_field(), args_hash]);
let message_hash = compute_outer_authwit_hash(target, chain_id, version, inner_hash);
let mut inputs = cheatcodes::get_public_context_inputs();
let mut context = PublicContext::new(inputs);
set_authorized(&mut context, message_hash, true);
cheatcodes::set_contract_address(current_contract);
}
1 change: 1 addition & 0 deletions noir-projects/aztec-nr/authwit/src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ mod account;
mod auth_witness;
mod auth;
mod entrypoint;
mod cheatcodes;
59 changes: 50 additions & 9 deletions noir-projects/aztec-nr/aztec/src/context/call_interfaces.nr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ trait CallInterface<N, T, P, Env> {
fn get_selector(self) -> FunctionSelector;
fn get_name(self) -> str<N>;
fn get_contract_address(self) -> AztecAddress;
fn get_is_static(self) -> bool;
}

impl<N, T, P, Env> CallInterface<N, PrivateContextInputs, PrivateCircuitPublicInputs, Env> for PrivateCallInterface<N, T, Env> {
Expand All @@ -38,6 +39,10 @@ impl<N, T, P, Env> CallInterface<N, PrivateContextInputs, PrivateCircuitPublicIn
fn get_contract_address(self) -> AztecAddress {
self.target_contract
}

fn get_is_static(self) -> bool {
self.is_static
}
}

struct PrivateCallInterface<N, T, Env> {
Expand All @@ -46,7 +51,8 @@ struct PrivateCallInterface<N, T, Env> {
name: str<N>,
args_hash: Field,
args: [Field],
original: fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs
original: fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs,
is_static: bool
}

impl<N, T, Env> PrivateCallInterface<N, T, Env> {
Expand Down Expand Up @@ -93,6 +99,10 @@ impl<N, T, P, Env> CallInterface<N, PrivateContextInputs, PrivateCircuitPublicIn
fn get_contract_address(self) -> AztecAddress {
self.target_contract
}

fn get_is_static(self) -> bool {
self.is_static
}
}

struct PrivateVoidCallInterface<N, Env> {
Expand All @@ -101,7 +111,8 @@ struct PrivateVoidCallInterface<N, Env> {
name: str<N>,
args_hash: Field,
args: [Field],
original: fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs
original: fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs,
is_static: bool
}

impl<N, Env> PrivateVoidCallInterface<N, Env> {
Expand Down Expand Up @@ -144,6 +155,10 @@ impl<N, T, P, Env> CallInterface<N, PrivateContextInputs, PrivateCircuitPublicIn
fn get_contract_address(self) -> AztecAddress {
self.target_contract
}

fn get_is_static(self) -> bool {
self.is_static
}
}

struct PrivateStaticCallInterface<N, T, Env> {
Expand All @@ -152,7 +167,8 @@ struct PrivateStaticCallInterface<N, T, Env> {
name: str<N>,
args_hash: Field,
args: [Field],
original: fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs
original: fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs,
is_static: bool
}

impl<N, T, Env> PrivateStaticCallInterface<N, T, Env> {
Expand Down Expand Up @@ -182,6 +198,10 @@ impl<N, T, P, Env> CallInterface<N, PrivateContextInputs, PrivateCircuitPublicIn
fn get_contract_address(self) -> AztecAddress {
self.target_contract
}

fn get_is_static(self) -> bool {
self.is_static
}
}

struct PrivateStaticVoidCallInterface<N, Env> {
Expand All @@ -190,7 +210,8 @@ struct PrivateStaticVoidCallInterface<N, Env> {
name: str<N>,
args_hash: Field,
args: [Field],
original: fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs
original: fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs,
is_static: bool
}

impl<N, Env> PrivateStaticVoidCallInterface<N, Env> {
Expand Down Expand Up @@ -219,6 +240,10 @@ impl<N, T, P, Env> CallInterface<N, PublicContextInputs, T, Env> for PublicCallI
fn get_contract_address(self) -> AztecAddress {
self.target_contract
}

fn get_is_static(self) -> bool {
self.is_static
}
}

struct PublicCallInterface<N, T, Env> {
Expand All @@ -227,7 +252,8 @@ struct PublicCallInterface<N, T, Env> {
name: str<N>,
args: [Field],
gas_opts: GasOpts,
original: fn[Env](PublicContextInputs) -> T
original: fn[Env](PublicContextInputs) -> T,
is_static: bool
}

impl<N, T, Env> PublicCallInterface<N, T, Env> {
Expand Down Expand Up @@ -308,6 +334,10 @@ impl<N, T, P, Env> CallInterface<N, PublicContextInputs, (), Env> for PublicVoid
fn get_contract_address(self) -> AztecAddress {
self.target_contract
}

fn get_is_static(self) -> bool {
self.is_static
}
}

struct PublicVoidCallInterface<N, Env> {
Expand All @@ -316,7 +346,8 @@ struct PublicVoidCallInterface<N, Env> {
name: str<N>,
args: [Field],
gas_opts: GasOpts,
original: fn[Env](PublicContextInputs) -> ()
original: fn[Env](PublicContextInputs) -> (),
is_static: bool
}

impl<N, Env> PublicVoidCallInterface<N, Env> {
Expand Down Expand Up @@ -378,7 +409,7 @@ impl<N, Env> PublicVoidCallInterface<N, Env> {
}

impl<N, T, P, Env> CallInterface<N, PublicContextInputs, T, Env> for PublicStaticCallInterface<N, T, Env> {
fn get_args(self) -> [Field] {
fn get_args(self) -> [Field] {
self.args
}

Expand All @@ -397,6 +428,10 @@ impl<N, T, P, Env> CallInterface<N, PublicContextInputs, T, Env> for PublicStati
fn get_contract_address(self) -> AztecAddress {
self.target_contract
}

fn get_is_static(self) -> bool {
self.is_static
}
}

struct PublicStaticCallInterface<N, T, Env> {
Expand All @@ -405,7 +440,8 @@ struct PublicStaticCallInterface<N, T, Env> {
name: str<N>,
args: [Field],
gas_opts: GasOpts,
original: fn[Env](PublicContextInputs) -> T
original: fn[Env](PublicContextInputs) -> T,
is_static: bool
}

impl<N, T, Env> PublicStaticCallInterface<N, T, Env> {
Expand Down Expand Up @@ -453,6 +489,10 @@ impl<N, T, P, Env> CallInterface<N, PublicContextInputs, (), Env> for PublicStat
fn get_contract_address(self) -> AztecAddress {
self.target_contract
}

fn get_is_static(self) -> bool {
self.is_static
}
}

struct PublicStaticVoidCallInterface<N, Env> {
Expand All @@ -461,7 +501,8 @@ struct PublicStaticVoidCallInterface<N, Env> {
name: str<N>,
args: [Field],
gas_opts: GasOpts,
original: fn[Env](PublicContextInputs) -> ()
original: fn[Env](PublicContextInputs) -> (),
is_static: bool
}

impl<N, Env> PublicStaticVoidCallInterface<N, Env> {
Expand Down
69 changes: 55 additions & 14 deletions noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use dep::protocol_types::{abis::function_selector::FunctionSelector, address::{AztecAddress, PartialAddress}};
use dep::protocol_types::{
abis::function_selector::FunctionSelector, address::{AztecAddress, PartialAddress},
constants::CONTRACT_INSTANCE_LENGTH, contract_instance::ContractInstance
};
use crate::context::inputs::{PublicContextInputs, PrivateContextInputs};
use crate::test::helpers::types::{Deployer, TestAccount};
use crate::keys::public_keys::PublicKeys;
Expand Down Expand Up @@ -31,20 +34,12 @@ unconstrained pub fn get_public_context_inputs() -> PublicContextInputs {
oracle_get_public_context_inputs()
}

unconstrained pub fn deploy<N, M>(
path: str<N>,
initializer: str<M>,
args: [Field],
public_keys_hash: Field
) -> AztecAddress {
oracle_deploy(path, initializer, args, public_keys_hash)
unconstrained pub fn deploy<N, M>(path: str<N>, initializer: str<M>, args: [Field], public_keys_hash: Field) -> ContractInstance {
let instance_fields = oracle_deploy(path, initializer, args, public_keys_hash);
ContractInstance::deserialize(instance_fields)
}

unconstrained pub fn direct_storage_write<N>(
contract_address: AztecAddress,
storage_slot: Field,
fields: [Field; N]
) {
unconstrained pub fn direct_storage_write<N>(contract_address: AztecAddress, storage_slot: Field, fields: [Field; N]) {
let _hash = direct_storage_write_oracle(contract_address, storage_slot, fields);
}

Expand Down Expand Up @@ -72,6 +67,32 @@ unconstrained pub fn get_side_effects_counter() -> u32 {
oracle_get_side_effects_counter()
}

unconstrained pub fn add_authwit(address: AztecAddress, message_hash: Field) {
orable_add_authwit(address, message_hash)
}

unconstrained pub fn assert_public_call_fails(target_address: AztecAddress, function_selector: FunctionSelector, args: [Field]) {
oracle_assert_public_call_fails(target_address, function_selector, args)
}

unconstrained pub fn assert_private_call_fails(
target_address: AztecAddress,
function_selector: FunctionSelector,
argsHash: Field,
sideEffectsCounter: Field,
isStaticCall: bool,
isDelegateCall: bool
) {
oracle_assert_private_call_fails(
target_address,
function_selector,
argsHash,
sideEffectsCounter,
isStaticCall,
isDelegateCall
)
}

#[oracle(reset)]
fn oracle_reset() {}

Expand Down Expand Up @@ -99,7 +120,7 @@ fn oracle_deploy<N, M>(
initializer: str<M>,
args: [Field],
public_keys_hash: Field
) -> AztecAddress {}
) -> [Field; CONTRACT_INSTANCE_LENGTH] {}

#[oracle(directStorageWrite)]
fn direct_storage_write_oracle<N>(
Expand All @@ -125,3 +146,23 @@ fn oracle_set_msg_sender(msg_sender: AztecAddress) {}

#[oracle(getSideEffectsCounter)]
fn oracle_get_side_effects_counter() -> u32 {}

#[oracle(addAuthWitness)]
fn orable_add_authwit(address: AztecAddress, message_hash: Field) {}

#[oracle(assertPublicCallFails)]
fn oracle_assert_public_call_fails(
target_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field]
) {}

#[oracle(assertPrivateCallFails)]
fn oracle_assert_private_call_fails(
target_address: AztecAddress,
function_selector: FunctionSelector,
argsHash: Field,
sideEffectsCounter: Field,
isStaticCall: bool,
isDelegateCall: bool
) {}
Loading
Loading