Skip to content

On-chain Groth16 verifier decompresses every point twice (~1e9–1.8e9 wasted steps per verification) #84

Open

Description

@beanbot-gh

Summary

Groth16BLS12381Lib (zeroj-onchain-julc) decompresses every proof and verification-key point twice per verification: once inside the canonical-encoding check (compress(uncompress(b)) == b), and again to use the point. The second decompression is pure cost. Decompressing each point once and reusing it for both the canonical check and the computation would accept and reject exactly the same inputs, and would save about 1e9 to 1.8e9 CPU steps (10–18% of maxTxExSteps) per verification.

Found while profiling the fees of the Pedersen-commitment demos in zeroj-usecases (bloxbean/zeroj-usecases#9). Decompression is the largest single item in a sealed-bid auction bid: 39% of its steps.

Where (origin/main 458bfb1)

zeroj-onchain-julc/src/main/java/org/zeroj/onchain/julc/groth16/lib/Groth16BLS12381Lib.java:

  • The proof and vk points are decompressed twice. verifyWithPublicInputs (from L160) runs isCanonicalNonInfinityG1/G2 on piA, piB, piC, vkAlpha, vkBeta, vkGamma, vkDelta (L187–193). Each check calls bls12_381_G*_uncompress. The method then calls uncompress again on all seven (L197–204).
  • The IC points are decompressed twice. verify (L92) runs validIcPoints (L255), which round-trips every IC point through isCanonicalNonInfinityG1. computeVkX (L264) then decompresses each IC point again; so does the vkX head at L111.
  • The helpers that decompress. isCanonicalG1 (L276) and isCanonicalNonInfinityG2 (L287).
  • verifyFour (L116) follows the same pattern.

Cost (Plutus V3, PV11 cost model; identical to the Yaci DevKit parameters, checked value by value)

Builtin CPU steps
bls12_381_G1_uncompress 52,948,122
bls12_381_G2_uncompress 74,698,472

With n public inputs, one verification decompresses n + 4 G1 points (A, C, alpha, and n + 1 IC) and 4 G2 points (B, beta, gamma, delta). The duplicate decompressions cost:

(n + 4) · 52,948,122 + 4 · 74,698,472 steps

Circuit (zeroj-usecases) n Wasted steps Share of maxTxExSteps Fee at 0.0000721 lovelace/step
Sealed-bid auction bid 9 987,119,474 9.9% ≈ 0.071 ADA
Confidential note transfer 24 1,781,341,304 17.8% ≈ 0.128 ADA

The Julc VM measurement agrees. A bid's 5.12e9 steps split into:

Part Steps Share
Decompression 1.97e9 39%
Pairing 1.35e9 26%
Public-input MSM 0.70e9 14%
Validator logic 0.94e9 18%

Proposal (no change to what is accepted)

Decompress once, check the canonical encoding against the decompressed point, and use that point:

JulcG1 a = Builtins.bls12_381_G1_uncompress(piA);           // fails on malformed / off-curve / non-subgroup input, as today
if (!Builtins.equalsByteString(Builtins.bls12_381_G1_compress(a), piA)
        || isCompressedInfinityG1(piA)) return false;           // same canonical + non-infinity rule as today
// … use `a` in the pairing …

Apply the same change to the vk points, the IC points (validIcPoints + computeVkX), and verifyFour. The length check is subsumed: uncompress rejects any other length. Keep it anyway if a false result, rather than a builtin failure, matters to callers.

Semantics. Today a point is accepted iff uncompress succeeds, compress(uncompress(b)) == b, and the infinity flag is clear. After the change the same three conditions are evaluated on the same bytes. The only difference is how some rejections surface:

  • Wrong length: today false from the length check; after the change, possibly a builtin error from uncompress.

Both reject the transaction. If the distinction matters to any caller, keep the explicit length check first.

Verification

  • Existing on-chain negative vectors: non-canonical encodings, infinity points, wrong lengths, off-curve and non-subgroup points, swapped or tampered proofs. All must still be rejected.
  • Positive vectors, and the snarkjs interop vectors, still verify.
  • A cost regression test asserts the step reduction above for n = 1, 4 and 9.
  • Script hashes of the shipped verifier validators change. Note this for consumers that pin hashes.

Related

  • PlonkBLS12381Lib has the same pattern: its isCanonicalNonInfinityG1/G2 round-trips (L341–364) decompress the same vk points and commitments that it decompresses again for use (e.g. L213–219). Worth applying the same pattern there.
  • Out of scope: whether the canonical round-trip can be dropped entirely because uncompress already rejects every non-canonical encoding (CIP-0381 / blst). That would change the validation argument, so it needs the normative reference first; this issue only removes duplicated work.

Risk class: R2 (on-chain verifier implementation). No change to the accepted language; needs review against the negative vectors.

Activity

  1. added 2 commits that reference this issue on Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions