Repository navigation
ADR-0067: enforce verifier/envelope binding, canonical codecs, and legacy BN254 gating - #124
Conversation
…gacy BN254 gating
|
[reviewer1] Changes requested on
|
|
Initial automated review · Aster Hi @satran004, thanks for the PR! 🙏 This is an automatic first check by an AI reviewer. It does not replace maintainer review and may be wrong. Reviewed commit: Issues found:
Not tested: Code and tests were read only; I did not run the build or verifier and codec tests. |
… publicInputs, WTNS version cap
|
Addressed all Round 1 review items in commit
Verification (
|
|
[reviewer1] Approved My isolated Gradle run covered the codec, verifier SPI, Groth16 and PlonK verifier suites, BBS service tests, and witness importer tests. All 173 tests passed with zero skips. |
|
[reviewer3] Review of head Scope: engineering, cross-backend consistency, codec and wire compatibility, API surface, docs. Cross-backend binding
CBOR wire compatibility (independent check with cbor-java 0.9)
Tests (my runs)
Non-blocking (P3)
|
|
[reviewer3] Follow-up to my approval: the full |
Summary
Implements ADR-0067 (
docs/adr/0067-offchain-verifier-binding-codecs-and-legacy-bn254-gating.md,Proposed, Risk R2):EnvelopeBindinghelper inzeroj-backend-spienforcing envelope presence/version (1..currentVersion),proofSystem,curve,circuitId,material.vkHash() == SHA-256(vkBytes), andByHashvkRefmatchingSHA-256(vkBytes)(returningVK_MISMATCH/MALFORMED_ENVELOPEwithout rejecting BBS raw public keys or emptypublicInputs).VerifierOrchestratorand defensively inGroth16BLS12381Verifier,Groth16BLS12381PureJavaVerifier,PlonkBLS12381Verifier, andBbsZkVerifier.proofFormat("snarkjs-json"), validate parsed JSONprotocol/curve/IC.size(), and classifyCodecExceptionasMALFORMED_ENVELOPE(preserving pure-Java /blstReasonCodeparity).BbsZkVerifierclassifies malformed CBOR/keyBbsExceptionerrors asMALFORMED_ENVELOPE.InMemoryVerificationKeyRegistry.registerrejects spoofedvkHash != SHA-256(vkBytes);VerifierRegistryuses thread-safeCopyOnWriteArrayListand returns an immutable snapshot fromall().SnarkjsJsonCodec.toEnvelope& PlonK VK validation:SnarkjsJsonCodec.serializeProofToBytes/serializeVkToBytes(and added publictoVerificationKeyBytes(SnarkjsVerificationKey)) to emit canonical snarkjs JSON (pi_a,pi_b,pi_c,vk_alpha_1, ...,IC, decimal strings) that round-trips throughparseProof/parseVerificationKeyand verifies directly on both BLS12-381 Groth16 backends.SnarkjsPlonkCodec.toEnvelopeFromJsonto parse and cross-checkvkJson(protocol == "plonk", matchingcurve,nPublic == inputs.size()).CborEnvelopeCodec+ optional keys 8–10:8(domainTag),9(metadata, sorted in RFC 8949 canonical UTF-8 byte-length-then-lexicographical order), and10(proofFormat) while keeping 7-key envelopes byte-identical when optional fields are absent/empty.CborEnvelopeCodec.decodewithsetRejectDuplicateKeys(true),setMaxPreallocationSize(MAX_CBOR_BYTES), allowed-key filtering (1..10), version bounds, minimal non-negativeBigIntegervalidation, omission of empty optional keys, and canonical round-trip byte equality.LegacyCurvePolicy.requireLegacyBn254Enabled()plus bounded section framing, exact BN254FRprime check, and canonical scalar range check toZkeyImporter.importWtns.isAvailable()onGroth16BN254VerifierandPlonkBN254Verifierto reflectLegacyCurvePolicy.legacyBn254Enabled(), added explicit"unsound against adversarial input"warnings inLegacyCurvePolicyand legacy verifier Javadocs, and added unit tests pinning ServiceLoader isolation.www/src/content/docs/guides/verifying/off-chain.mdwith the new verifier binding, CBOR canonical encoding, and legacy BN254 guarantees.Verification
./gradlew :zeroj-api:test :zeroj-backend-spi:test :zeroj-codec:test :zeroj-verifier-groth16:test :zeroj-verifier-plonk:test :zeroj-bbs:test :zeroj-crypto:test --tests 'org.zeroj.crypto.groth16.*' :zeroj-integration-tests:test --tests 'org.zeroj.it.spi.VerifierServiceLoaderPackagingTest' --stacktrace— PASSED across all 8 modules.