Repository navigation
Reject affine points whose y isn't the point's own (#15) - #24
Merged
Merged
Conversation
g1_affine_compress kept x and only the sign of y, so any y on the same side of (p - 1) / 2 gave the same compressed bytes, and many AffineProof values decoded to one proof. It now fails unless the new g1_affine_valid holds: each coordinate exactly 48 bytes and below p, and y^2 = x^3 + 4. With x below p its top three bits are clear, so flag bits already set in x are rejected too. Each G1 point now has exactly one G1Affine form. Subgroup membership is still left to g1.decompress, which rejects an on-curve point outside G1 (checked with (0, 2)). Failing, rather than returning an Option, keeps the signature and matches how g1.decompress already treats a bad x further down the same path. Callers who want to branch can call g1_affine_valid first. known_issue_15 is replaced by prop_g1_affine_rejects_wrong_y, plus a property for coordinates at or above p, with a flag bit set, or with an extra leading zero byte, and a fail test that compression itself stops. Mutation-checked: removing the check from compression, the 48-byte and below-p checks, or the curve equation each fails a test. Cost: about 10K mem / 4.3M CPU per finite point. The PLONK fixture run (prepare and verify) goes from 4.78M mem / 8.03B CPU to 4.94M / 8.10B. Fixes #15 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The issue names g1_affine_compress, but g2_affine_compress has the same flaw: it keeps x and only the sign of y. It now fails unless the new g2_affine_valid holds: each of the four Fp components exactly 48 bytes and below p, and y^2 = x^3 + 4(1 + u) in Fp2. In PLONK the only G2 point is the key's x2, which a validator normally fixes, so this matters less than the G1 change. Tests use the standard G2 generator, since recovering random G2 points from blst's bytes would need an Fp2 square root. The generator and its negation compress to exactly blst's bytes and the fixture's x2 is valid; a changed y component, a component at or above p, x1 with the sort bit set, and an extra leading zero byte are rejected; compressing a wrong y fails. test_g2_compression_format used made-up coordinates that aren't on the curve in any component order, so it now uses the generator. Mutation-checked: removing the check from compression, the four 48-byte and below-p checks, or the curve equation each fails a test. Cost: about 31K mem / 16M CPU on the fixture run, now 4.97M mem / 8.11B CPU. Refs #15 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
The report counts 16 finite G1 points instead of 15, so its marginal validation cost estimates need recalculation to match the stated aggregate.
1 open issue
What changed in this PR
Addresses #15 by validating affine coordinates before compression in PLONK’s affine input path, preventing altered y values from silently producing the same compressed proof.
Changes:
- Adds G1 and G2 coordinate-length, field-bound, and curve-equation checks while preserving downstream subgroup validation.
- Adds regression tests for invalid coordinates and compatibility checks against native compression.
- Updates documentation with validation behavior, execution costs, and reported test totals.
| File | Description |
|---|---|
zkp/lib/tests/point_tests.ak |
Adds G2 validation and compression regression tests. |
zkp/lib/tests/point_props.ak |
Adds G1 rejection properties and a compression-failure test. |
zkp/lib/common/blst_affine.ak |
Validates canonical coordinates and curve membership before compression. |
zkp/docs/plonk-implementation-report.md |
Documents validation, test coverage, and updated costs; removes the resolved limitation. |
zkp/docs/groth16-implementation-report.md |
Updates the reported package test total. |
zkp/docs/bulletproofs-implementation-report.md |
Updates the reported package test total. |
README.md |
Updates the reported package test total. |
Review effort: Balanced
Both q_r and q_c in the fixture key are the point at infinity, which the check skips, so 15 G1 points are checked (six in the key, nine in the proof). The per-point figure had been the total divided by 16. Measured again with each check removed in turn: the G1 check costs 160,635 mem / 68.3M CPU on the fixture run, about 10.7K / 4.6M per point; the G2 check on x2 costs 31,156 mem / 15.6M CPU, as stated. From Copilot's review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Fixes #15.
g1_affine_compresskeptxand only the sign ofy, so anyyon the same side of(p - 1) / 2gave the same compressed bytes, and many differentAffineProofvalues decoded to one proof. It now checks the point first. The second commit givesg2_affine_compressthe same check, which the issue didn't name; it's separate so it can be dropped.Changes
cec530cg1_affine_valid: true for the point at infinity, or when each coordinate is exactly 48 bytes and belowpandy² = x³ + 4.g1_affine_compressfails unless it holds. Withxbelowpits top three bits are clear, so anxwith a flag bit already set is rejected too. Each G1 point now has exactly oneG1Affineform.574da4cg2_affine_valid, the same check over Fp2: each of the four components exactly 48 bytes and belowp, andy² = x³ + 4(1 + u).g2_affine_compressfails unless it holds. In PLONK the only G2 point is the key'sx2, which a validator normally fixes, so this matters less than the G1 change.a204e6bSubgroup membership is still left to
g1.decompress/g2.decompress, which already check it:g1.decompressrejects (0, 2), a point on the curve but outside G1.Behaviour changes
g1_affine_compressandg2_affine_compressnow fail on an invalid point instead of returning bytes. That matches howg1.decompressalready treats a badxfurther down the same path, and keeps the signatures. Callers who want to branch can callg1_affine_validorg2_affine_validfirst.plonk/raw_affine.ak) uses these functions, so Groth16 and Bulletproofs are unaffected.Tests
known_issue_15_g1_affine_compress_ignores_yis replaced byprop_g1_affine_rejects_wrong_y(a differentyon the same side of the half-way point is rejected). Also new: a property rejecting a coordinate at or abovep, anxwith the sort bit set, or an extra leading zero byte; afailtest showing that compressing a wrongystops; andprop_g1_affine_compress_matches_blstnow also checks that each point and its negation are valid.x2are valid, and the first two compress to the builtin's bytes; a changedycomponent, a component at or abovep,x1with the sort bit set, and an extra leading zero byte are rejected; compressing a wrongyfails.test_g2_compression_formatused made-up coordinates that aren't on the curve in any component order, so it now uses the generator.pchecks, or the curve equation each fails a test, for both G1 and G2.Cost
Measured with each check removed in turn: the G1 check costs 161K memory and 68M CPU for the fixture's 15 finite points (about 11K and 4.6M each;
q_randq_care the point at infinity, which isn't checked), and the G2 check on the key'sx231K memory and 16M CPU.Documentation
The README and the three implementation reports give the new test count. The PLONK report describes the checks and their cost and drops the #15 limitation bullet.
Checks
aiken check -D: 79 tests, all pass, no warningsaiken fmt --checkandaiken buildpass