Skip to content

Commit

Permalink
refactor: nuking mental model of "packing into a hash" (#11200)
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored Jan 14, 2025
1 parent 2c3ab84 commit e1ebcc0
Show file tree
Hide file tree
Showing 48 changed files with 350 additions and 383 deletions.
5 changes: 2 additions & 3 deletions docs/docs/_protocol-specs/transactions/local-execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Mike review:
- (We should probably adopt this approach throughout the protocol specs)
- Link to any types / fields which are defined on some other page of the protocol specs (e.g. `AuthWitness`).
- Is the hash used to compute `argsHash` protocol-defined or app-defined? If the former, we should define it (in a way which is consistent with all other hash definitions).
- How are the packed arguments packed? What's the encoding? Or is it app-specific and hence out-of-protocol?
- "Entrypoint" is such an important term, perhaps it needs to be a subheading (with the text rearranged to accommodate such a subheading), for easier referencing and searching?
- Do we need to describe how public functions will be simulated? (I'm not sure the sandbox does such simulation yet, but it ought to, eventually).
- Where we link to definitions (such as "transaction"), if that definition is actually a specific struct, we should use the exact name of the struct, wrapped in backticks, to a subheading whose name exactly matches the name of the struct.
Expand All @@ -25,12 +24,12 @@ A transaction execution request has the following structure. Note that, since Az
| `functionSelector` | u32 | Selector (identifier) of the function to be called as entrypoint in the origin contract. |
| `argsHash` | `Field` | Hash of the arguments to be used for calling the entrypoint function. |
| `txContext` | `TxContext` | Includes chain id, protocol version, and gas settings. |
| `packedArguments` | `PackedValues[]` | Preimages for argument hashes. When executing a function call with the hash of the arguments, the PXE will look for the preimage of that hash in this list, and expand the arguments to execute the call. |
| `hashedArguments` | `HashedValues[]` | Preimages for argument hashes. When executing a function call with the hash of the arguments, the PXE will look for the preimage of that hash in this list, and expand the arguments to execute the call. |
| `authWitnesses` | `AuthWitness[]` | Authorization witnesses. When authorizing an action identified by a hash, the PXE will look for the authorization witness identified by that hash and provide that value to the account contract. |

## Simulation step

Upon receiving a transaction execution request to _simulate_, the PXE will locally execute the function identified by the given `functionSelector` in the given `origin` contract with the arguments committed to by `argsHash`. We refer to this function as the _entrypoint_. During execution, contracts may request authorization witnesses or expanded arguments from the _execution oracle_ <!-- n/d -->, which are answered with the `packedArguments` and `authWitnesses` from the request.
Upon receiving a transaction execution request to _simulate_, the PXE will locally execute the function identified by the given `functionSelector` in the given `origin` contract with the arguments committed to by `argsHash`. We refer to this function as the _entrypoint_. During execution, contracts may request authorization witnesses or expanded arguments from the _execution oracle_ <!-- n/d -->, which are answered with the `hashedArguments` and `authWitnesses` from the request.

The _entrypoint_ may enqueue additional function calls, either private or public. The simulation step will always execute all private functions in the call stack until emptied. The result of the simulation is a [_transaction_](./tx-object.md) object without an associated _proof_ which is returned to the application that requested the simulation.

Expand Down
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 @@ -232,7 +232,7 @@ pub fn assert_inner_hash_valid_authwit(
comptime { FunctionSelector::from_signature("verify_private_authwit(Field)") },
[inner_hash],
)
.unpack_into();
.get_preimage();
assert(result == IS_VALID_SELECTOR, "Message not authorized by account");
// Compute the nullifier, similar computation to the outer hash, but without the chain_id and version.
// Those should already be handled in the verification, so we just need something to nullify, that allows the same inner_hash for multiple actors.
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/authwit/src/entrypoint/app.nr
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ impl AppPayload {
for call in self.function_calls {
if !call.target_address.is_zero() {
if call.is_public {
context.call_public_function_with_packed_args(
context.call_public_function_with_args_hash(
call.target_address,
call.function_selector,
call.args_hash,
call.is_static,
);
} else {
let _result = context.call_private_function_with_packed_args(
let _result = context.call_private_function_with_args_hash(
call.target_address,
call.function_selector,
call.args_hash,
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ impl FeePayload {
for call in self.function_calls {
if !call.target_address.is_zero() {
if call.is_public {
context.call_public_function_with_packed_args(
context.call_public_function_with_args_hash(
call.target_address,
call.function_selector,
call.args_hash,
call.is_static,
);
} else {
let _result = context.call_private_function_with_packed_args(
let _result = context.call_private_function_with_args_hash(
call.target_address,
call.function_selector,
call.args_hash,
Expand Down
58 changes: 29 additions & 29 deletions noir-projects/aztec-nr/aztec/src/context/call_interfaces.nr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use dep::protocol_types::{
use crate::context::{gas::GasOpts, private_context::PrivateContext, public_context::PublicContext};

use crate::hash::hash_args;
use crate::oracle::arguments::pack_arguments;
use crate::oracle::execution_cache;

pub trait CallInterface<let N: u32> {
fn get_args(self) -> [Field];
Expand All @@ -30,29 +30,29 @@ impl<let N: u32, T> PrivateCallInterface<N, T> {
where
T: Deserialize<M>,
{
pack_arguments(self.args);
let returns = context.call_private_function_with_packed_args(
execution_cache::store(self.args);
let returns_hash = context.call_private_function_with_args_hash(
self.target_contract,
self.selector,
self.args_hash,
false,
);
let unpacked: T = returns.unpack_into();
unpacked
let returns: T = returns_hash.get_preimage();
returns
}

pub fn view<let M: u32>(self, context: &mut PrivateContext) -> T
where
T: Deserialize<M>,
{
pack_arguments(self.args);
let returns = context.call_private_function_with_packed_args(
execution_cache::store(self.args);
let returns_hash = context.call_private_function_with_args_hash(
self.target_contract,
self.selector,
self.args_hash,
true,
);
returns.unpack_into()
returns_hash.get_preimage()
}
}

Expand Down Expand Up @@ -90,9 +90,9 @@ pub struct PrivateVoidCallInterface<let N: u32> {

impl<let N: u32> PrivateVoidCallInterface<N> {
pub fn call(self, context: &mut PrivateContext) {
pack_arguments(self.args);
execution_cache::store(self.args);
context
.call_private_function_with_packed_args(
.call_private_function_with_args_hash(
self.target_contract,
self.selector,
self.args_hash,
Expand All @@ -102,9 +102,9 @@ impl<let N: u32> PrivateVoidCallInterface<N> {
}

pub fn view(self, context: &mut PrivateContext) {
pack_arguments(self.args);
execution_cache::store(self.args);
context
.call_private_function_with_packed_args(
.call_private_function_with_args_hash(
self.target_contract,
self.selector,
self.args_hash,
Expand Down Expand Up @@ -151,14 +151,14 @@ impl<let N: u32, T> PrivateStaticCallInterface<N, T> {
where
T: Deserialize<M>,
{
pack_arguments(self.args);
let returns = context.call_private_function_with_packed_args(
execution_cache::store(self.args);
let returns = context.call_private_function_with_args_hash(
self.target_contract,
self.selector,
self.args_hash,
true,
);
returns.unpack_into()
returns.get_preimage()
}
}

Expand Down Expand Up @@ -196,9 +196,9 @@ pub struct PrivateStaticVoidCallInterface<let N: u32> {

impl<let N: u32> PrivateStaticVoidCallInterface<N> {
pub fn view(self, context: &mut PrivateContext) {
pack_arguments(self.args);
execution_cache::store(self.args);
context
.call_private_function_with_packed_args(
.call_private_function_with_args_hash(
self.target_contract,
self.selector,
self.args_hash,
Expand Down Expand Up @@ -274,8 +274,8 @@ impl<let N: u32, T> PublicCallInterface<N, T> {

pub fn enqueue(self, context: &mut PrivateContext) {
let args_hash = hash_args(self.args);
pack_arguments(self.args);
context.call_public_function_with_packed_args(
execution_cache::store(self.args);
context.call_public_function_with_args_hash(
self.target_contract,
self.selector,
args_hash,
Expand All @@ -286,8 +286,8 @@ impl<let N: u32, T> PublicCallInterface<N, T> {

pub fn enqueue_view(self, context: &mut PrivateContext) {
let args_hash = hash_args(self.args);
pack_arguments(self.args);
context.call_public_function_with_packed_args(
execution_cache::store(self.args);
context.call_public_function_with_args_hash(
self.target_contract,
self.selector,
args_hash,
Expand Down Expand Up @@ -357,8 +357,8 @@ impl<let N: u32> PublicVoidCallInterface<N> {

pub fn enqueue(self, context: &mut PrivateContext) {
let args_hash = hash_args(self.args);
pack_arguments(self.args);
context.call_public_function_with_packed_args(
execution_cache::store(self.args);
context.call_public_function_with_args_hash(
self.target_contract,
self.selector,
args_hash,
Expand All @@ -369,8 +369,8 @@ impl<let N: u32> PublicVoidCallInterface<N> {

pub fn enqueue_view(self, context: &mut PrivateContext) {
let args_hash = hash_args(self.args);
pack_arguments(self.args);
context.call_public_function_with_packed_args(
execution_cache::store(self.args);
context.call_public_function_with_args_hash(
self.target_contract,
self.selector,
args_hash,
Expand Down Expand Up @@ -433,8 +433,8 @@ impl<let N: u32, T> PublicStaticCallInterface<N, T> {

pub fn enqueue_view(self, context: &mut PrivateContext) {
let args_hash = hash_args(self.args);
pack_arguments(self.args);
context.call_public_function_with_packed_args(
execution_cache::store(self.args);
context.call_public_function_with_args_hash(
self.target_contract,
self.selector,
args_hash,
Expand Down Expand Up @@ -494,8 +494,8 @@ impl<let N: u32> PublicStaticVoidCallInterface<N> {

pub fn enqueue_view(self, context: &mut PrivateContext) {
let args_hash = hash_args(self.args);
pack_arguments(self.args);
context.call_public_function_with_packed_args(
execution_cache::store(self.args);
context.call_public_function_with_args_hash(
self.target_contract,
self.selector,
args_hash,
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/context/mod.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod globals;
pub mod inputs;

pub mod packed_returns;
pub mod returns_hash;
pub mod private_context;
pub mod public_context;
pub mod unconstrained_context;
Expand All @@ -14,7 +14,7 @@ pub use call_interfaces::{
PrivateVoidCallInterface, PublicCallInterface, PublicStaticCallInterface,
PublicStaticVoidCallInterface, PublicVoidCallInterface,
};
pub use packed_returns::PackedReturns;
pub use private_context::PrivateContext;
pub use public_context::PublicContext;
pub use returns_hash::ReturnsHash;
pub use unconstrained_context::UnconstrainedContext;
36 changes: 0 additions & 36 deletions noir-projects/aztec-nr/aztec/src/context/packed_returns.nr

This file was deleted.

Loading

0 comments on commit e1ebcc0

Please sign in to comment.