Skip to content

Commit

Permalink
feat(avm): add AvmContextInputs (AztecProtocol/aztec-packages#5396)
Browse files Browse the repository at this point in the history
NOTE: I don't know why this triggered a change in the snapshot.

---

This structure lets us easily pass things from the (TS) context to the constructor of the `AvmContext` in Noir, using `calldata` as a vehicle (effectively adding them as public inputs).

The choice to add the structure to the function arguments as LAST and not first is because adding them first would break any non-noir-generated bytecode (since they would have to shift their expected calldata by a magic number `N = sizeof(AvmContextInputs)`). Putting it last, makes it transparent for them. A calldatacopy would still work.

However, having this makes any external call always have `AvmContextInputs` in the calldata, bloating it (on chain) for non-noir-generated bytecode. This is not an issue now.

For the moment, this is temporary, but might be useful long term. (Sean mentioned passing maybe env getters like this).

---

Implemented `AvmContext.selector()` and `AvmContext.get_args_hash()` using the above.
  • Loading branch information
AztecBot committed Mar 25, 2024
2 parents 05c2eaa + 27fce09 commit 6a29c37
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
13a12d5255e788be94d575c726da141e652f14e3
12e2844f9af433beb1a586640b08ce284ad91095
9 changes: 8 additions & 1 deletion aztec_macros/src/transforms/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ pub fn transform_vm_function(
let create_context = create_avm_context()?;
func.def.body.0.insert(0, create_context);

// Add the inputs to the params (first!)
let input = create_inputs("AvmContextInputs");
func.def.parameters.insert(0, input);

// We want the function to be seen as a public function
func.def.is_unconstrained = true;

Expand Down Expand Up @@ -353,11 +357,14 @@ fn create_context(ty: &str, params: &[Param]) -> Result<Vec<Statement>, AztecMac
/// // ...
/// }
fn create_avm_context() -> Result<Statement, AztecMacroError> {
// Create the inputs to the context
let inputs_expression = variable("inputs");

let let_context = mutable_assignment(
"context", // Assigned to
call(
variable_path(chained_dep!("aztec", "context", "AVMContext", "new")), // Path
vec![], // args
vec![inputs_expression], // args
),
);

Expand Down

0 comments on commit 6a29c37

Please sign in to comment.