Skip to content

Commit 6a29c37

Browse files
author
AztecBot
committed
feat(avm): add AvmContextInputs (AztecProtocol/aztec-packages#5396)
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.
2 parents 05c2eaa + 27fce09 commit 6a29c37

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

.aztec-sync-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
13a12d5255e788be94d575c726da141e652f14e3
1+
12e2844f9af433beb1a586640b08ce284ad91095

aztec_macros/src/transforms/functions.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ pub fn transform_vm_function(
116116
let create_context = create_avm_context()?;
117117
func.def.body.0.insert(0, create_context);
118118

119+
// Add the inputs to the params (first!)
120+
let input = create_inputs("AvmContextInputs");
121+
func.def.parameters.insert(0, input);
122+
119123
// We want the function to be seen as a public function
120124
func.def.is_unconstrained = true;
121125

@@ -353,11 +357,14 @@ fn create_context(ty: &str, params: &[Param]) -> Result<Vec<Statement>, AztecMac
353357
/// // ...
354358
/// }
355359
fn create_avm_context() -> Result<Statement, AztecMacroError> {
360+
// Create the inputs to the context
361+
let inputs_expression = variable("inputs");
362+
356363
let let_context = mutable_assignment(
357364
"context", // Assigned to
358365
call(
359366
variable_path(chained_dep!("aztec", "context", "AVMContext", "new")), // Path
360-
vec![], // args
367+
vec![inputs_expression], // args
361368
),
362369
);
363370

0 commit comments

Comments
 (0)