feat(avm)!: memory aware ecc add#15780
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
9bd8bcd to
b739a3d
Compare
9a654e3 to
3edaf30
Compare
623e336 to
b1e014e
Compare
b1e014e to
43d9627
Compare
3edaf30 to
0515513
Compare
43d9627 to
704a568
Compare
704a568 to
42c0ea4
Compare
| .add<lookup_poseidon2_mem_check_dst_addr_in_range_settings, InteractionType::LookupGeneric>() | ||
| // Dispatch from Execution Trace | ||
| .add<perm_poseidon2_mem_dispatch_exec_pos2_settings, InteractionType::Permutation>(); | ||
| // |
There was a problem hiding this comment.
chore: clean up from previous PR
e90a03c to
8ba5247
Compare
dbanks12
left a comment
There was a problem hiding this comment.
LGTM! Mostly nits and one real question about where to consume gas in execution sim.
| { | ||
| constexpr auto opcode = ExecutionOpCode::ECADD; | ||
| auto& memory = context.get_memory(); | ||
| get_gas_tracker().consume_gas(); | ||
|
|
||
| // Read the points from memory. | ||
| MemoryValue p_x = memory.get(p_x_addr); | ||
| MemoryValue p_y = memory.get(p_y_addr); | ||
| MemoryValue p_inf = memory.get(p_inf_addr); | ||
|
|
||
| MemoryValue q_x = memory.get(q_x_addr); | ||
| MemoryValue q_y = memory.get(q_y_addr); | ||
| MemoryValue q_inf = memory.get(q_inf_addr); | ||
|
|
||
| set_and_validate_inputs(opcode, { p_x, p_y, p_inf, q_x, q_y, q_inf }); |
There was a problem hiding this comment.
Should consume_gas come after set_and_validate_inputs? @fcarreiro mentioned that it should in this comment (after @sirasistant made that change in his PR).
There was a problem hiding this comment.
ah ok i didnt realise it was order dependent
| try { | ||
| // The resulting EmbeddedCurvePoint is a triple of (x, y, is_infinity). | ||
| // The x and y coordinates are stored at dst_address and dst_address + 1 respectively, | ||
| // and the is_infinity flag is stored at dst_address + 2. | ||
| // Therefore, the maximum address that needs to be written to is dst_address + 2. | ||
| uint64_t max_write_address = static_cast<uint64_t>(dst_address) + 2; | ||
| if (cmp.gt(max_write_address, AVM_HIGHEST_MEM_ADDRESS)) { | ||
| throw std::runtime_error("dst address out of range"); | ||
| } |
There was a problem hiding this comment.
If more efficient, could consider omitting the call to cmp.gt and just checking if the dst_address is == MAX or == MAX-1 which are the only cases where dst_address+1 or +2 can be out of bounds. Similar to what I did for GetContractInstance.
There was a problem hiding this comment.
hmm i think it ends up being less efficient for cases where there are > 1 options (i.e. a slice write of 2 or more) since it requires at least 1 batched inverse check and a higher degree error. In any case these range check rows are "free" since the memory operation is already 9 rows long
| //////////////////////////////////////////////// | ||
| // Dispatch from execution trace to ECC Add | ||
| //////////////////////////////////////////////// | ||
| #[DISPATCH_EXEC_ECC_ADD] | ||
| execution.sel_execute_ecc_add { |
There was a problem hiding this comment.
I'll be honest.... It feels confusing to me to have this inside the gadget 😅
There was a problem hiding this comment.
yeah i think there was some discussion about a exec_dispatch.pil file to house all the lookups. The downside of putting it in execution.pil is it gets really messy
8ba5247 to
fcb3687
Compare
fcb3687 to
307867f
Compare
See [merge-train-readme.md](https://github.com/AztecProtocol/aztec-packages/blob/next/.github/workflows/merge-train-readme.md). BEGIN_COMMIT_OVERRIDE feat!: constrain NullifierExists AVM opcode (#15636) feat(avm)!: memory aware ecc add (#15780) END_COMMIT_OVERRIDE --------- Co-authored-by: ludamad <adam.domurad@gmail.com> Co-authored-by: AztecBot <tech@aztecprotocol.com> Co-authored-by: Ilyas Ridhuan <ilyas@aztecprotocol.com>

Makes ECC Add memory aware and integrates into the execution trace.
Currently only handles errors related to memory - another error handling PR to follow