fix(avm): preserve coordinates in embedded curve point #19263
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Preamble
The representation of the point at infinity differs between BB and noir, with the latter using
{x: 0, y: 0, inf: 1}. To ensure we match with noir's expectations we wrap the bbAffinePointin a structStandardAffinePointthat outputs the noir representation if you ask for the coordinates of a point at infinity.The bug
The ECADD opcode loads points from addresses in memory (i.e. x-coord, y-coord, inf-flag). It is possible that some bytecode loads a point such that
x != 0, y != 0, inf = 1. When this happens during simulation, the execution trace will load the original coordinate values but when the EC gadget is called, it utilisesStandardAffinePointwhich incorrectly outputs{x: 0, y:0, inf = 1when building the EC events.This causes a
Lookup PERM_EXECUTION_DISPATCH_TO_ECC_ADD failed.because the value loaded in the registers in the execution trace no longer match the values in the ECC subtrace.Solution
The subtlety in
StandardAffinePointis that we only want the point at infinity to be{x: 0, y: 0, inf: 1}, when the result of an operation results in infinity. Otherwise we want to use the original coordinates of the point. This means we need to track the original coordinate values as well in theStandardAffinePoint.