Skip to content

Reject affine points whose y isn't the point's own (#15) - #24

Merged
SamDelaney merged 3 commits into
mainfrom
sam/point-decoding
Nov 18, 2026
Merged

SamDelaney merged 3 commits into
mainfrom
sam/point-decoding

Conversation

@SamDelaney

@SamDelaney SamDelaney commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #15. 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 different AffineProof values decoded to one proof. It now checks the point first. The second commit gives g2_affine_compress the same check, which the issue didn't name; it's separate so it can be dropped.

Changes

Commit Change
cec530c New g1_affine_valid: true for the point at infinity, or when each coordinate is exactly 48 bytes and below p and y² = x³ + 4. g1_affine_compress fails unless it holds. With x below p its top three bits are clear, so an x with a flag bit already set is rejected too. Each G1 point now has exactly one G1Affine form.
574da4c New g2_affine_valid, the same check over Fp2: each of the four components exactly 48 bytes and below p, and y² = x³ + 4(1 + u). g2_affine_compress fails unless it holds. In PLONK the only G2 point is the key's x2, which a validator normally fixes, so this matters less than the G1 change.
a204e6b Report fix from Copilot's review: the fixture has 15 finite G1 points, not 16, so the per-point cost is about 11K memory and 4.6M CPU.

Subgroup membership is still left to g1.decompress / g2.decompress, which already check it: g1.decompress rejects (0, 2), a point on the curve but outside G1.

Behaviour changes

  • g1_affine_compress and g2_affine_compress now fail on an invalid point instead of returning bytes. That matches how g1.decompress already treats a bad x further down the same path, and keeps the signatures. Callers who want to branch can call g1_affine_valid or g2_affine_valid first.
  • Only PLONK's affine front door (plonk/raw_affine.ak) uses these functions, so Groth16 and Bulletproofs are unaffected.

Tests

  • G1: known_issue_15_g1_affine_compress_ignores_y is replaced by prop_g1_affine_rejects_wrong_y (a different y on the same side of the half-way point is rejected). Also new: a property rejecting a coordinate at or above p, an x with the sort bit set, or an extra leading zero byte; a fail test showing that compressing a wrong y stops; and prop_g1_affine_compress_matches_blst now also checks that each point and its negation are valid.
  • G2: three tests with the standard G2 generator, since recovering random G2 points from compressed bytes would need an Fp2 square root. The generator, its negation and the fixture's x2 are valid, and the first two compress to the builtin's bytes; 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 check: removing the check from compression, the 48-byte and below-p checks, or the curve equation each fails a test, for both G1 and G2.

Cost

Before After
PLONK fixture (prepare and verify) 4.78M mem / 8.03B CPU 4.97M mem / 8.11B CPU

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_r and q_c are the point at infinity, which isn't checked), and the G2 check on the key's x2 31K 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 warnings
  • aiken fmt --check and aiken build pass

SamDelaney and others added 2 commits November 18, 2026 11:33
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>

Copilot AI 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.

🟡 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

Comment thread zkp/docs/plonk-implementation-report.md Resolved
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>
@SamDelaney
SamDelaney merged commit 5304bd0 into main Nov 18, 2026
1 check passed
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.

g1_affine_compress ignores y except for its sign bit, so different AffineProofs decode to the same proof

2 participants