Skip to content

chore: ecc/fields ASM audit#20892

Merged
notnotraju merged 6 commits into
merge-train/barretenbergfrom
rk/ecc-field-asm-1
Mar 12, 2026
Merged

chore: ecc/fields ASM audit#20892
notnotraju merged 6 commits into
merge-train/barretenbergfrom
rk/ecc-field-asm-1

Conversation

@notnotraju

@notnotraju notnotraju commented Feb 26, 2026

Copy link
Copy Markdown
Contributor
  • Killed dead code
  • Changed a few names to be more explanatory
  • had many iterations with Claude to improve the documentation, which includes proofs that the bounds were correct etc.

* @note the 2p is because for 254 bit fields, we use the _coarse_ representation.
**/
#define ADD_REDUCE(b, modulus_0, modulus_1, modulus_2, modulus_3) \
#define ADD_REDUCE(b, twice_not_modulus_0, twice_not_modulus_1, twice_not_modulus_2, twice_not_modulus_3) \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

only called with -2p

* 2. `asm_sub_with_coarse_reduction`: b = 2p. If r wrapped negative, return r + 2p.
**/
#define REDUCE_FIELD_ELEMENT(neg_modulus_0, neg_modulus_1, neg_modulus_2, neg_modulus_3) \
#define CONDITIONAL_ADD(b_0, b_1, b_2, b_3) \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

naming was confusing, as it wasn't MERELY used to do a single reduce, but also to conditionally add 2p in another method.

@notnotraju notnotraju changed the title chore: first part of ecc/fields ASM audit chore: ecc/fields ASM audit Mar 11, 2026
@notnotraju notnotraju marked this pull request as ready for review March 11, 2026 11:59
@notnotraju notnotraju self-assigned this Mar 11, 2026
@notnotraju notnotraju added the bberg-int-audit All things related to barretenberg internal audit label Mar 11, 2026
**/
#define MUL_FOO(a1, a2, a3, a4, b) \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

dead

**/
#define SQR(a) \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

as explained above, this was unused due to a rare bug.

@iakovenkos iakovenkos self-requested a review March 11, 2026 13:42
// 3: we replace `(p - *this).reduce_once()` with an assembly block that is equivalent to `p - *this`,
// but we call `REDUCE_FIELD_ELEMENT` with `not_twice_modulus` instead of `twice_modulus`
// but we call `CONDITIONAL_ADD` with `not_twice_modulus` instead of `twice_modulus`
// not sure which is faster and whether any of the above might break something!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment seemingly needs to be more conclusive

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh, yeah -- let me figure out what to do with that TODO, thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, figured out what we were doing and added some comments. Definitely a micro-optimization...

notnotraju added 6 commits March 12, 2026 10:55
…UCE_FIELD_ELEMENT to CONDITIONAL_ADD, as it is not *only* used to with argument -p.
Fix systematic comment errors across SQR, ADX MUL, and both MUL_256 macros:
- wrong k variable indices in reduction comments (e.g. k = r[9] instead of r[0])
- wrong modulus index comments (e.g. modulus[2] on mulxq %[modulus_3])
- swapped flag_c/flag_o on adcxq/adoxq instructions
- flag_i typo
- addq comments incorrectly claiming + flag_c (addq does not consume carry)
- reused temp names across consecutive mulxq pairs (t[0],t[1] used twice)
- wrong temp indices in downstream add comments
- "move r_inv into %rdx" instead of "move r[3] into %rdx"
- "(%rsi now free)" instead of "(%r10 now free)"

Add register convention block comments and per-round register dictionaries
to ADX MUL (matching the style already applied to non-ADX MUL).

Remove MUL_FOO: identical copy of ADX MUL, never referenced anywhere.
@notnotraju notnotraju enabled auto-merge (squash) March 12, 2026 10:59
@notnotraju notnotraju merged commit 9ce609e into merge-train/barretenberg Mar 12, 2026
10 checks passed
@notnotraju notnotraju deleted the rk/ecc-field-asm-1 branch March 12, 2026 11:09
github-merge-queue Bot pushed a commit that referenced this pull request Mar 12, 2026
BEGIN_COMMIT_OVERRIDE
chore: unify tests in ecc/curves and ecc/groups (#21392)
chore: `ecc/fields` ASM audit (#20892)
chore: audit the `ecc/field` extension field (#21409)
chore: responding to external IPA audit (#20334)
feat: committed sumcheck for batched Hiding Translator (#21376)
chore: documentation fixes for ECCVM after first external audit (#20348)
chore: Document RAM gate cost optimization opportunity (#21426)
refactor: rename MSGPACK_FIELDS to SERIALIZATION_FIELDS (#21175)
END_COMMIT_OVERRIDE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bberg-int-audit All things related to barretenberg internal audit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants