-
Couldn't load subscription status.
- Fork 220
feat: batch subgroup membership testing #710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds batch subgroup membership checking for curve points across all supported ECC curves, using a naive per-point check for small batches and a probabilistic MSM-based check for larger batches. It also includes corresponding property-based tests for high-confidence validation.
- Introduce
IsInSubGroupBatch*,isInSubGroupBatch*Naive, andisInSubGroupBatch*Probfunctions in generator templates and per-curve implementations. - Update imports to include
crypto/randandsync/atomicwhere needed. - Add
TestIsInSubGroupBatch*property tests in all curve-specific test files.
Reviewed Changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/generator/ecc/template/tests/point.go.tmpl | Add template for TestIsInSubGroupBatch* |
| internal/generator/ecc/template/point.go.tmpl | Add IsInSubGroupBatch* methods and imports |
| ecc/stark-curve/g1.go | Add IsInSubGroupBatchG1 probabilistic batch check |
| ecc/secp256k1/g1.go | Add IsInSubGroupBatchG1 (naive + probabilistic) |
| ecc/secp256k1/g1_test.go | Add TestIsInSubGroupBatchG1 |
| ecc/grumpkin/g1.go | Add IsInSubGroupBatchG1 (naive + probabilistic) |
| ecc/grumpkin/g1_test.go | Add TestIsInSubGroupBatchG1 |
| ecc/bw6-761/g1.go | Add IsInSubGroupBatchG1 (naive + probabilistic) |
| ecc/bw6-761/g1_test.go | Add TestIsInSubGroupBatchG1 |
| ecc/bw6-761/g2.go | Add IsInSubGroupBatchG2 (naive + probabilistic) |
| ecc/bw6-761/g2_test.go | Add TestIsInSubGroupBatchG2 |
| ecc/bw6-633/g1.go | Add IsInSubGroupBatchG1 (naive + probabilistic) |
| ecc/bw6-633/g1_test.go | Add TestIsInSubGroupBatchG1 |
| ecc/bw6-633/g2.go | Add IsInSubGroupBatchG2 (naive + probabilistic) |
| ecc/bw6-633/g2_test.go | Add TestIsInSubGroupBatchG2 |
| ecc/bn254/g1.go | Add IsInSubGroupBatchG1 (naive + probabilistic) |
| ecc/bn254/g1_test.go | Add TestIsInSubGroupBatchG1 |
| ecc/bn254/g2.go | Add IsInSubGroupBatchG2 (naive + probabilistic) |
| ecc/bn254/g2_test.go | Add TestIsInSubGroupBatchG2 |
| ecc/bls24-317/g1.go | Add IsInSubGroupBatchG1 (naive + probabilistic) |
| ecc/bls24-317/g1_test.go | Add TestIsInSubGroupBatchG1 |
| ecc/bls24-317/g2.go | Add IsInSubGroupBatchG2 (naive + probabilistic) |
| ecc/bls24-317/g2_test.go | Add TestIsInSubGroupBatchG2 |
| ecc/bls24-315/g1.go | Add IsInSubGroupBatchG1 (naive + probabilistic) |
| ecc/bls24-315/g1_test.go | Add TestIsInSubGroupBatchG1 |
| ecc/bls24-315/g2.go | Add IsInSubGroupBatchG2 (naive + probabilistic) |
| ecc/bls24-315/g2_test.go | Add TestIsInSubGroupBatchG2 |
| ecc/bls12-381/g1.go | Add IsInSubGroupBatchG1 (naive + probabilistic) |
| ecc/bls12-381/g1_test.go | Add TestIsInSubGroupBatchG1 |
| ecc/bls12-381/g2.go | Add IsInSubGroupBatchG2 (naive + probabilistic) |
| ecc/bls12-381/g2_test.go | Add TestIsInSubGroupBatchG2 |
| ecc/bls12-377/g1.go | Add IsInSubGroupBatchG1 (naive + probabilistic) |
| ecc/bls12-377/g1_test.go | Add TestIsInSubGroupBatchG1 |
| ecc/bls12-377/g2.go | Add IsInSubGroupBatchG2 (naive + probabilistic) |
| ecc/bls12-377/g2_test.go | Add TestIsInSubGroupBatchG2 |
Comments suppressed due to low confidence (2)
ecc/bw6-761/g2.go:216
- The comment mentions
G1but this function checks subgroup membership forG2. Update the comment to referenceG2.
// IsInSubGroupBatchG2 checks if a batch of points P_i are in G1.
internal/generator/ecc/template/point.go.tmpl:338
- The loop
for j := range len(points)is invalid syntax. Replace it withfor j := 0; j < len(points); j++ {orfor j := range points {to iterate over the slice.
for j := range len(points) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool algo! Just one thing, the test currently only looks for false positives ("positive" being off-subgroup) but it seems pretty obvious that there can't possibly be any. It'd be more interesting imo to look for false negatives, or both at least.
Thank for the review! yeah it seems tests are not complete. I'll push something. |
Description
This PR introduces batch subgroup membership for all curves. For small batches we individually check that all points are on
G1/2. For large batches, for an error probability1/2^64, we check that 64 random MSMs with coefficients in{0,1}are onG1/2. These coefficients do not kill small torsions points. For a higher probability we can redo the test. Empirically, we find that< 80and< 160are considered small batches forG1and respectivelyG2.Type of change
How has this been tested?
TestIsInSubGroupBatchG1/2ing1/2_test.goHow has this been benchmarked?
Please describe the benchmarks that you ran to verify your changes.
Checklist:
golangci-lintdoes not output errors locallyNote
Introduce batched subgroup membership APIs for G1/G2 across curves with naive (<80/<160) and probabilistic MSM strategies, plus supporting helpers and tests; minor import cleanups.
IsInSubGroupBatchG1andIsInSubGroupBatchG2for batched subgroup checks.<80forG1,<160forG2).{0,1}scalars,crypto/rand,parallel,sync/atomic) for large batches.fuzzCofactorOfG1/G2for BLS12-377/381) and necessary imports.TestIsInSubGroupBatchG1/TestIsInSubGroupBatchG2covering positive and negative cases (including cofactor-torsion).vector_test.gofiles.internal/generator/ecc/template/point.go.tmplto generate batched subgroup APIs and required imports.internal/generator/ecc/template/tests/point.go.tmplto generate batch tests and cofactor checks.Written by Cursor Bugbot for commit fec8f67. This will update automatically on new commits. Configure here.