Skip to content

feat: Some extension field utilities - #901

Merged
ivokub merged 20 commits into
masterfrom
feat/ext-multilin
Oct 8, 2026
Merged

ivokub merged 20 commits into
masterfrom
feat/ext-multilin

Conversation

@Tabaie

@Tabaie Tabaie commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds convenient I/O methods to extension fields to make GKR code generation in gnark cleaner and more uniform.


Note

Medium Risk
Touches low-level field encoding and arithmetic used by FFT/GKR paths; Vector remains aliased but new APIs must stay consistent with fr.Element canonical rules.

Overview
Adds canonical serialization and integer/base-field helpers on extension types E2/E4/E6 across babybear, goldilocks, and koalabear: BytesE*, Marshal / SetBytesCanonical, SetInt64/SetUint64/SetBigInt/BigInt, and embedded-base ops (SetElement, AddElement, SubElement, SubFromElement), with round-trip and non-canonical rejection tests.

Renames the E4 slice type to VectorE4 (keeping Vector as a deprecated alias) and wires serialization/FFT call sites to BytesE4 and VectorE4. VectorE6 gains SetRandom / MustSetRandom.

Introduces koalabear polynomial (dense MultiLin, Polynomial, pooling) and extensions/polynomial for E6 multilinear/polynomial utilities (MultiLinE6, FoldFromBase, EvaluateBase, PolynomialE6, PoolE6).

Reviewed by Cursor Bugbot for commit 5798e08. Bugbot is set up for automated code reviews on this repo. Configure here.

Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
@Tabaie
Tabaie requested a review from a team as a code owner October 2, 2026 03:19

@ivokub ivokub left a comment

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.

Please see comments:

  • lets not start panicking when we didn't before (it is not programming error, but input error, it is not worth a panic). I think here we can also fix the silent parsing error for extension.SetString (i.e. it fails silently right now)
  • in code generation, lets try to avoid f.Name == "koalabear" and instead define properties in the configuration we base the configuration on. Then all the configuration is kept in a single place.

Comment thread field/babybear/extensions/e2.go Outdated
Comment thread field/babybear/extensions/e2_test.go Outdated
Comment thread internal/generator/main.go Outdated

@ivokub ivokub left a comment

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.

And I think the code generation we have right now is a bit messy, we have some "IsKoalaBear" in the templates as well, but we really shouldn't. It should be about the properties "SupportsAVX512()" etc which is then computed based on the width etc.

But lets keep it for another PR to clean up, I think there is an open issue for that already.

Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
@Tabaie

Tabaie commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Fair comments. All addressed. Instead of a boolean for polynomial implementations did a slice of which extensions to generate polynomials for, which defaults to empty.

@Tabaie
Tabaie requested a review from ivokub October 5, 2026 02:25

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 454ab67. Configure here.

Comment thread internal/generator/polynomial/template/polynomial.go.tmpl
Tabaie added 9 commits October 5, 2026 13:44
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>

@ivokub ivokub left a comment

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.

Thanks for the changes. Yes, you have addressed my comments, but added Poseidon2 matrix getters, this is extends the scope of this PR significantly (and I didn't check it for now, I think @ThomasPiellard or @yelhousni would be better to review the correctness of the matrices).

Comment thread internal/poseidon2/matrices.go Outdated
Comment thread ecc/bls12-377/fr/poseidon2/poseidon2_test.go Outdated
Comment thread field/babybear/extensions/e6.go Outdated
Comment thread field/babybear/extensions/vector.go
Comment thread internal/generator/main.go Outdated
Tabaie added 3 commits October 7, 2026 13:29
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
…t least one ext

Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
Revert "build: go generate" and "feat: export external and internal
matrices". They are unrelated to the extension work of this PR and continue in
feat/poseidon2-matrices.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
@Tabaie
Tabaie requested a review from ivokub October 7, 2026 18:43

@ivokub ivokub left a comment

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.

Thanks for addressing all the comments! Perfect now!

@ivokub
ivokub merged commit f49b800 into master Oct 8, 2026
15 checks passed
@ivokub
ivokub deleted the feat/ext-multilin branch October 8, 2026 10:21
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