Conversation
There was a problem hiding this comment.
Pull request overview
Adds native gnark circuit support for the kb8 curve over the KoalaBear field, including field-tower arithmetic, map-to-curve, and a 1-point multiset-hash accumulator intended for KoalaBear-based SNARK circuits.
Changes:
- Introduce
fields_kb8(KoalaBear-native E2/E4/E8 arithmetic) with solver hints and unit tests. - Add
sw_kb8curve gadget with affine operations plus a multiset-hash accumulator and tests/benchmarks. - Add
maptocurve_kb8y-increment map-to-curve gadget with hints and tests; register new hints instd/hints.go.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| std/hints.go | Registers kb8-related hint functions with the global solver registry. |
| std/algebra/native/sw_kb8/doc.go | Package documentation for kb8 curve + multiset-hash gadgets. |
| std/algebra/native/sw_kb8/types.go | Defines kb8 circuit types (G1Affine and field aliases) and native assignment helpers. |
| std/algebra/native/sw_kb8/g1.go | Implements kb8 affine curve operations and on-curve/subgroup assertions. |
| std/algebra/native/sw_kb8/g1_test.go | Adds correctness tests for kb8 affine operations. |
| std/algebra/native/sw_kb8/hints.go | Exposes kb8-related hints (currently forwarded from fields_kb8). |
| std/algebra/native/sw_kb8/multisethash.go | Implements 1-point multiset-hash accumulator and Curve.Hash. |
| std/algebra/native/sw_kb8/multisethash_test.go | Adds multiset-hash circuit tests and a solve benchmark. |
| std/algebra/native/maptocurve_kb8/doc.go | Package documentation for kb8 y-increment map-to-curve gadget. |
| std/algebra/native/maptocurve_kb8/types.go | Defines map-to-curve types and helpers to assemble E8 from coefficients. |
| std/algebra/native/maptocurve_kb8/maptocurve.go | Implements y-increment map-to-curve gadget and compatibility check. |
| std/algebra/native/maptocurve_kb8/maptocurve_test.go | Adds a test against gnark-crypto’s native mapping. |
| std/algebra/native/maptocurve_kb8/hints.go | Adds hint implementation for y-increment mapping (k and x output). |
| std/algebra/native/fields_kb8/doc.go | Package documentation for KoalaBear-native field-tower arithmetic. |
| std/algebra/native/fields_kb8/e2.go | Implements E2 arithmetic for KoalaBear-native circuits. |
| std/algebra/native/fields_kb8/e2_test.go | Adds tests for E2 operations. |
| std/algebra/native/fields_kb8/e4.go | Implements E4 arithmetic built on E2. |
| std/algebra/native/fields_kb8/e4_test.go | Adds tests for E4 operations. |
| std/algebra/native/fields_kb8/e8.go | Implements E8 arithmetic built on E4, including hint-based inverse/div. |
| std/algebra/native/fields_kb8/e8_test.go | Adds tests for E8 operations. |
| std/algebra/native/fields_kb8/hints.go | Registers E8 inverse/div hints and provides native (de)serialization helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Review pass from 2026-05-07. Findings:
Verification run locally:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f6f5bed. Configure here.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 35 out of 40 changed files in this pull request and generated 3 comments.
Files not reviewed (4)
- internal/smallfields/tinyfield/element.go: Language not supported
- internal/smallfields/tinyfield/element_test.go: Language not supported
- internal/smallfields/tinyfield/vector.go: Language not supported
- internal/smallfields/tinyfield/vector_test.go: Language not supported
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|

Description
This PR adds native
gnarksupport for theOctoBearcurve over the degree-8 extension of KoalaBear field together with the circuit components needed to use both single-point and vector-point multiset hashes in KoalaBear-based SNARKs.The main additions are:
OctoBearfield tower (Fp², Fp⁴, Fp⁸) understd/algebra/native/fields_octobear, with separate R1CS and Plonk multiplication/squaring pathsOctoBearaffine curve arithmetic understd/algebra/native/sw_octobear(incomplete add, double, unified add, double-and-add, Brier–Joye variants)OctoBeary-increment map-to-curve gadget understd/algebra/native/maptocurve_octobear, plus two N-coordinate (N = 23) vector map-to-curve variants:MapLinear)MapPoseidon2) over the KoalaBear field, width 16OctoBearinsw_octobear:Accumulator(insert-only, fixed public offset point derived from theOctoBeargenerator)LinearAccumulatorusing the linear vector mapPoseidon2Accumulatorusing the Poseidon2 vector mapstd/permutation/poseidon2/poseidon2_koalabear.go), matching the native gnark-crypto round keys and M4std/hints.go, plus a bump to the matchinggnark-cryptorevision (go.mod/go.sum)internal/smallfields/tinyfieldupdates:CbrtandCubeonElement, and aparallel.Executevector decode path.golangci.ymlentry to keep theoctobeartoken out of misspellThe multiset-hash circuits are aligned with the current
gnark-cryptoOctoBearconstruction and are intended for later use in zkVM memory-check arguments defined over the KoalaBear field. All three accumulators are insert-only and start from a fixed public offset point derived from theOctoBeargenerator, which preserves the incomplete-addition safety argument (acc ± Map(m) = 0succeeds with negligible probability over the 2²⁴⁸ group) and keeps the in-circuit addition path simple and cheap.Type of change
How has this been tested?
go test ./std/algebra/native/fields_octobear ./std/algebra/native/maptocurve_octobear ./std/algebra/native/sw_octobearTestHash,TestHashInvalidDigest,TestLinearHash,TestLinearHashHomomorphic,TestPoseidon2Hash,TestPoseidon2HashHomomorphicgo test ./std/permutation/poseidon2— including the newTestPoseidon2KoalaBearMatchesNativego test ./internal/smallfields/tinyfield— covers the newCbrt/Cubeand the parallel vector decode pathgo test ./std/algebra/native/...How has this been benchmarked?
go test ./std/algebra/native/sw_octobear -run '^$' -bench BenchmarkMultisetHashCircuitSolve -benchtime=1x, on Apple M5, 24 GB RAMgo test ./std/algebra/native/sw_octobear -run '^$' -bench BenchmarkLinearMultisetHashCircuitSolve -benchtime=1xgo test ./std/algebra/native/sw_octobear -run '^$' -bench BenchmarkPoseidon2MultisetHashCircuitSolve -benchtime=1xCurrent benchmark numbers on Apple M5:
OctoBearmultiset-hash insert:660scsconstraints,268r1csconstraintsscs261792 ns/op,r1cs216833 ns/op9580scsconstraints,4022r1csconstraintsscs1644375 ns/op,r1cs941667 ns/op14117scsconstraints,5890r1csconstraintsscs936625 ns/op,r1cs1088375 ns/opChecklist:
golangci-lintdoes not output errors locallyNote
Medium Risk
Large new cryptographic surface (Fp⁸ inverses, map-to-curve, incomplete EC adds, Poseidon2 sponge) with tight coupling to a bumped gnark-crypto revision; mistakes could break soundness of multiset-hash circuits, though changes are additive with broad tests.
Overview
Adds KoalaBear-native circuit support for the OctoBear curve and multiset-hash constructions, aimed at small-field SNARKs (e.g. zkVM memory checks).
New packages
fields_octobear(Fp²/Fp⁴/Fp⁸ with R1CS vs Plonk mul/square paths),maptocurve_octobear(y-increment map plus linear and Poseidon2 23-point vector maps with hints), andsw_octobear(affine G1 ops, 1-point accumulator, linear and Poseidon2 vector accumulators starting from a fixed generator offset).std/permutation/poseidon2gains a KoalaBear width-16 path (round keys, circulant M4, internal diagonal) aligned with gnark-crypto;std/hints.goregisters the new hints.gnark-cryptois bumped to a pre-release revision that supplies OctoBear multiset-hash and extension APIs.Smaller diffs:
tinyfieldaddsCbrt/Cube, switches vector decode toparallel.Execute, and assorted Go 1.22+ loop/anycleanups;.golangci.ymlignores misspell onoctobear;koalabear_ext_testrenames toMulByQuadraticNonResidue.Reviewed by Cursor Bugbot for commit a27b2aa. Bugbot is set up for automated code reviews on this repo. Configure here.