Skip to content

feat(avm)!: memory aware ecc add#15780

Merged
IlyasRidhuan merged 1 commit intomerge-train/avmfrom
ir/mem_aware_ecc_add
Jul 21, 2025
Merged

feat(avm)!: memory aware ecc add#15780
IlyasRidhuan merged 1 commit intomerge-train/avmfrom
ir/mem_aware_ecc_add

Conversation

@IlyasRidhuan
Copy link
Contributor

@IlyasRidhuan IlyasRidhuan commented Jul 16, 2025

Makes ECC Add memory aware and integrates into the execution trace.

Currently only handles errors related to memory - another error handling PR to follow

Copy link
Contributor Author

IlyasRidhuan commented Jul 16, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@IlyasRidhuan IlyasRidhuan changed the title feat(avm)! : comparison subtrace feat(avm)! : memory aware ecc add Jul 16, 2025
@IlyasRidhuan IlyasRidhuan force-pushed the ir/mem_aware_ecc_add branch 2 times, most recently from 9bd8bcd to b739a3d Compare July 16, 2025 17:16
@IlyasRidhuan IlyasRidhuan changed the title feat(avm)! : memory aware ecc add feat(avm)!: memory aware ecc add Jul 16, 2025
@IlyasRidhuan IlyasRidhuan force-pushed the ir/07-04-feat_avm_poseidon2_mem_errs branch from 9a654e3 to 3edaf30 Compare July 17, 2025 10:01
@IlyasRidhuan IlyasRidhuan force-pushed the ir/mem_aware_ecc_add branch 3 times, most recently from 623e336 to b1e014e Compare July 17, 2025 15:15
@IlyasRidhuan IlyasRidhuan changed the base branch from ir/07-04-feat_avm_poseidon2_mem_errs to graphite-base/15780 July 17, 2025 16:02
@IlyasRidhuan IlyasRidhuan force-pushed the ir/mem_aware_ecc_add branch from b1e014e to 43d9627 Compare July 19, 2025 14:43
@IlyasRidhuan IlyasRidhuan force-pushed the graphite-base/15780 branch from 3edaf30 to 0515513 Compare July 19, 2025 14:43
@IlyasRidhuan IlyasRidhuan changed the base branch from graphite-base/15780 to next July 19, 2025 14:43
@IlyasRidhuan IlyasRidhuan force-pushed the ir/mem_aware_ecc_add branch from 43d9627 to 704a568 Compare July 19, 2025 15:02
@IlyasRidhuan IlyasRidhuan changed the base branch from next to graphite-base/15780 July 21, 2025 14:01
@IlyasRidhuan IlyasRidhuan force-pushed the ir/mem_aware_ecc_add branch from 704a568 to 42c0ea4 Compare July 21, 2025 14:01
@IlyasRidhuan IlyasRidhuan changed the base branch from graphite-base/15780 to merge-train/avm July 21, 2025 14:01
.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>();
//
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chore: clean up from previous PR

@IlyasRidhuan IlyasRidhuan force-pushed the ir/mem_aware_ecc_add branch 2 times, most recently from e90a03c to 8ba5247 Compare July 21, 2025 14:31
@IlyasRidhuan IlyasRidhuan requested a review from dbanks12 July 21, 2025 14:32
@IlyasRidhuan IlyasRidhuan marked this pull request as ready for review July 21, 2025 14:32
Copy link
Contributor

@dbanks12 dbanks12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Mostly nits and one real question about where to consume gas in execution sim.

Comment on lines +693 to +731
{
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 });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok i didnt realise it was order dependent

Comment on lines +54 to +62
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");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +58 to +92
////////////////////////////////////////////////
// Dispatch from execution trace to ECC Add
////////////////////////////////////////////////
#[DISPATCH_EXEC_ECC_ADD]
execution.sel_execute_ecc_add {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be honest.... It feels confusing to me to have this inside the gadget 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@IlyasRidhuan IlyasRidhuan force-pushed the ir/mem_aware_ecc_add branch from 8ba5247 to fcb3687 Compare July 21, 2025 16:44
@IlyasRidhuan IlyasRidhuan force-pushed the ir/mem_aware_ecc_add branch from fcb3687 to 307867f Compare July 21, 2025 17:00
@IlyasRidhuan IlyasRidhuan merged commit 66ee06d into merge-train/avm Jul 21, 2025
5 checks passed
@IlyasRidhuan IlyasRidhuan deleted the ir/mem_aware_ecc_add branch July 21, 2025 17:35
github-merge-queue bot pushed a commit that referenced this pull request Jul 22, 2025
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants