docs+test: pin and document the G2 ordering contract for the Groth16 verifier - #631
Open
pjkundert wants to merge 1 commit into
Open
docs+test: pin and document the G2 ordering contract for the Groth16 verifier#631pjkundert wants to merge 1 commit into
pjkundert wants to merge 1 commit into
Conversation
No behavioural change. Existing verifiers, calldata and proofs are unaffected and nothing needs regenerating. This only writes down a contract that already holds, and adds the test that would keep it holding. The contract: the exported Groth16 verifier expects the proof's B component in EIP-197 order ([x_im, x_re, y_im, y_re]), the reverse of proof.json's, and the verification-key constants it embeds are im-first to match. The swap is the CALLER's job, and `zkey export soliditycalldata` does it for you. End to end this is correct: stock exporter plus stock verifier verifies on-chain, which the smart_contract_tests confirm. The trap is not a defect, it is an undocumented ABI. Reading the verifier alone, the B assembly looks like it is missing a swap the VK constants clearly received -- there is no hint that the caller is expected to have done it already. Anyone constructing calldata by hand from a proof.json will pass natural order, produce an off-curve G2 point, and get `false` from a proof that `snarkjs groth16 verify` accepts off-chain. Off-chain verification uses one internal ordering for both proving and verifying, so it never exercises the discrepancy and gives no warning. Completeness only; soundness is unaffected. Documented where the problem is actually met, rather than in the root README: - templates/verifier_groth16.sol.ejs -- a note above the `// B` block, so it ships inside every generated verifier. That contract is what someone opens when verifyProof returns false. - cli.js -- the help for both export commands. A one-line summary in each description keeps the `snarkjs --help` command table aligned; the detail lives in longDescription, shown by the command's own --help. `soliditycalldata` states that its output is already in verifier order; `solidityverifier` points at the note and at the calldata command. That is what is on screen at the moment the calldata is produced. - README.md -- a Common Issues entry pointing at those, no more. And pinned: - smart_contract_tests: a test feeding `exportSolidityCallData` output straight into `verifyProof`. Nothing covered this link -- every existing test builds calldata by hand, so exporter and verifier could drift apart while CI stayed green. Since verifiers are deployed immutably, that agreement is an ABI in the strict sense: changing either side would desynchronise every deployment that already exists from its own tooling. This test makes that impossible to do by accident. `npm test` in smart_contract_tests: 8 passing.
pjkundert
force-pushed
the
docs/groth16-verifier-pb-convention
branch
from
August 18, 2026 17:28
45f0b37 to
719bb9d
Compare
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.
No behavioural change. Existing verifiers, calldata and proofs are unaffected and nothing needs regenerating. This only writes down a contract that already holds, and adds the test that would keep it holding. This cost us a day, so we're documenting it so it doesn't cost someone else.
The contract: the exported Groth16 verifier expects the proof's B component in EIP-197 order ([x_im, x_re, y_im, y_re]), the reverse of proof.json's, and the verification-key constants it embeds are im-first to match. The swap is the CALLER's job, and
zkey export soliditycalldatadoes it for you. End to end this is correct: stock exporter plus stock verifier verifies on-chain, which the smart_contract_tests confirm.The trap is not a defect, it is an undocumented ABI. Reading the verifier alone, the B assembly looks like it is missing a swap the VK constants clearly received -- there is no hint that the caller is expected to have done it already. Anyone constructing calldata by hand from a proof.json will pass natural order, produce an off-curve G2 point, and get
falsefrom a proof thatsnarkjs groth16 verifyaccepts off-chain. Off-chain verification uses one internal ordering for both proving and verifying, so it never exercises the discrepancy and gives no warning. Completeness only; soundness is unaffected.Documented where the problem is actually met, rather than in the root README:
// Bblock, so it ships inside every generated verifier. That contract is what someone opens when verifyProof returns false.soliditycalldatastates that its output is already in verifier order;solidityverifierpoints at the note and at the calldata command. That is what is on screen at the moment the calldata is produced.And pinned:
exportSolidityCallDataoutput straight intoverifyProof. Nothing covered this link -- every existing test builds calldata by hand, so exporter and verifier could drift apart while CI stayed green. Since verifiers are deployed immutably, that agreement is an ABI in the strict sense: changing either side would desynchronise every deployment that already exists from its own tooling. This test makes that impossible to do by accident.npm testin smart_contract_tests: 8 passing.