Repository navigation
Description
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) runsisCanonicalNonInfinityG1/G2onpiA, piB, piC, vkAlpha, vkBeta, vkGamma, vkDelta(L187–193). Each check callsbls12_381_G*_uncompress. The method then callsuncompressagain on all seven (L197–204). - The IC points are decompressed twice.
verify(L92) runsvalidIcPoints(L255), which round-trips every IC point throughisCanonicalNonInfinityG1.computeVkX(L264) then decompresses each IC point again; so does thevkXhead at L111. - The helpers that decompress.
isCanonicalG1(L276) andisCanonicalNonInfinityG2(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
falsefrom the length check; after the change, possibly a builtin error fromuncompress.
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
PlonkBLS12381Libhas the same pattern: itsisCanonicalNonInfinityG1/G2round-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
uncompressalready 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
Merge pull request #85 from bloxbean/perf/issue-84-groth16-decompress…
Merge pull request #86 from bloxbean/perf/issue-84-ic-single-decompre…