Skip to content

Commit

Permalink
feat(avm)!: returndatasize + returndatacopy (#9475)
Browse files Browse the repository at this point in the history
This PR
* Introduces RETURNDATASIZE and RETURNDATACOPY (also copies revert data if reverted)
* Fixes a bug in CALL in witgen
* Changes the public context to return slices when calling public functions. This was partly done because templated functions would always be inlined and I wanted to avoid that blowup

Note that the rethrowing hack is still present in the simulator, so the rethrowing branch in the public context is still not used. I will make this change once @sirasistant finishes the string encoding changes.

In a later PR we can remove the returndata from CALL.

Part of #9061.
  • Loading branch information
fcarreiro authored and AztecBot committed Oct 30, 2024
1 parent e9d88c7 commit f9dce06
Show file tree
Hide file tree
Showing 15 changed files with 835 additions and 698 deletions.
8 changes: 7 additions & 1 deletion cpp/pil/avm/main.pil
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ namespace main(256);

//===== Memory Slice Gadget Selectors =========================================
pol commit sel_op_calldata_copy;
pol commit sel_op_returndata_size;
pol commit sel_op_returndata_copy;
pol commit sel_op_external_return;
pol commit sel_op_external_revert;

Expand Down Expand Up @@ -275,6 +277,8 @@ namespace main(256);
sel_op_static_call * (1 - sel_op_static_call) = 0;

sel_op_calldata_copy * (1 - sel_op_calldata_copy) = 0;
sel_op_returndata_size * (1 - sel_op_returndata_size) = 0;
sel_op_returndata_copy * (1 - sel_op_returndata_copy) = 0;
sel_op_external_return * (1 - sel_op_external_return) = 0;
sel_op_external_revert * (1 - sel_op_external_revert) = 0;

Expand Down Expand Up @@ -409,7 +413,8 @@ namespace main(256);

//===== CONTROL_FLOW_CONSISTENCY ============================================
pol SEL_ALL_CTRL_FLOW = sel_op_jump + sel_op_jumpi + sel_op_internal_call
+ sel_op_internal_return + sel_op_external_call + sel_op_static_call + sel_op_external_return;
+ sel_op_internal_return + sel_op_external_call + sel_op_static_call
+ sel_op_external_return + sel_op_external_revert;
pol SEL_ALU_R_TAG = sel_op_add + sel_op_sub + sel_op_mul + sel_op_div + sel_op_not + sel_op_eq
+ sel_op_lt + sel_op_lte + sel_op_shr + sel_op_shl;
pol SEL_ALU_W_TAG = sel_op_cast;
Expand All @@ -420,6 +425,7 @@ namespace main(256);
+ sel_op_ecadd + sel_op_msm;
pol SEL_ALL_MEMORY = sel_op_mov + sel_op_set;
pol OPCODE_SELECTORS = sel_op_fdiv + sel_op_calldata_copy + sel_op_get_contract_instance
+ sel_op_returndata_size + sel_op_returndata_copy
+ SEL_ALL_ALU + SEL_ALL_BINARY + SEL_ALL_MEMORY + SEL_ALL_GADGET
+ KERNEL_INPUT_SELECTORS + KERNEL_OUTPUT_SELECTORS + SEL_ALL_LEFTGAS
+ SEL_ALL_CTRL_FLOW;
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co
polys.main_sel_op_or.set_if_valid_index(i, rows[i].main_sel_op_or);
polys.main_sel_op_poseidon2.set_if_valid_index(i, rows[i].main_sel_op_poseidon2);
polys.main_sel_op_radix_be.set_if_valid_index(i, rows[i].main_sel_op_radix_be);
polys.main_sel_op_returndata_copy.set_if_valid_index(i, rows[i].main_sel_op_returndata_copy);
polys.main_sel_op_returndata_size.set_if_valid_index(i, rows[i].main_sel_op_returndata_size);
polys.main_sel_op_sender.set_if_valid_index(i, rows[i].main_sel_op_sender);
polys.main_sel_op_set.set_if_valid_index(i, rows[i].main_sel_op_set);
polys.main_sel_op_sha256.set_if_valid_index(i, rows[i].main_sel_op_sha256);
Expand Down
Loading

0 comments on commit f9dce06

Please sign in to comment.