feat(Groth16): add working examples of Groth16 verification#1964
feat(Groth16): add working examples of Groth16 verification#1964delovoyhomie wants to merge 1 commit intomainfrom
Conversation
| --- | ||
| title: "Verify Groth16 examples on TON" | ||
| sidebarTitle: "Groth16 examples" | ||
| description: "Run Groth16 verifier examples on TON with Circom, Noname, Gnark, and Arkworks." | ||
| doc_type: "How-to guide" | ||
| --- |
There was a problem hiding this comment.
[HIGH] Unsupported doc_type frontmatter key
Please leave a reaction 👍/👎 to this suggestion to improve future reviews for everyone!
| --- | ||
| title: "Verify Groth16 examples on TON" | ||
| sidebarTitle: "Groth16 examples" | ||
| description: "Run Groth16 verifier examples on TON with Circom, Noname, Gnark, and Arkworks." |
There was a problem hiding this comment.
[HIGH] How‑to page title does not follow “How to X” pattern
Please leave a reaction 👍/👎 to this suggestion to improve future reviews for everyone!
| ```bash | ||
| cd circuits/Multiplier | ||
| circom Multiplier.circom --r1cs --wasm --sym --prime bls12381 | ||
| snarkjs powersoftau new bls12-381 10 pot10_0000.ptau -v | ||
| snarkjs powersoftau contribute pot10_0000.ptau pot10_0001.ptau --name="First contribution" -v -e="some random text" | ||
| snarkjs powersoftau prepare phase2 pot10_0001.ptau pot10_final.ptau -v | ||
| snarkjs groth16 setup Multiplier.r1cs pot10_final.ptau Multiplier_0000.zkey | ||
| snarkjs zkey contribute Multiplier_0000.zkey Multiplier_final.zkey --name="1st Contributor" -v -e="some random text" | ||
| snarkjs zkey export verificationkey Multiplier_final.zkey verification_key.json | ||
| cd ../.. | ||
| npx export-ton-verifier ./circuits/Multiplier/Multiplier_final.zkey ./contracts/verifier_multiplier.tact --tact | ||
| npx blueprint build --all | ||
| npx blueprint test Verifier_multiplier_tact | ||
| ``` |
There was a problem hiding this comment.
[HIGH] Unsafe mainnet‑adjacent commands lack explicit safety callout
| ```bash | |
| cd circuits/Multiplier | |
| circom Multiplier.circom --r1cs --wasm --sym --prime bls12381 | |
| snarkjs powersoftau new bls12-381 10 pot10_0000.ptau -v | |
| snarkjs powersoftau contribute pot10_0000.ptau pot10_0001.ptau --name="First contribution" -v -e="some random text" | |
| snarkjs powersoftau prepare phase2 pot10_0001.ptau pot10_final.ptau -v | |
| snarkjs groth16 setup Multiplier.r1cs pot10_final.ptau Multiplier_0000.zkey | |
| snarkjs zkey contribute Multiplier_0000.zkey Multiplier_final.zkey --name="1st Contributor" -v -e="some random text" | |
| snarkjs zkey export verificationkey Multiplier_final.zkey verification_key.json | |
| cd ../.. | |
| npx export-ton-verifier ./circuits/Multiplier/Multiplier_final.zkey ./contracts/verifier_multiplier.tact --tact | |
| npx blueprint build --all | |
| npx blueprint test Verifier_multiplier_tact | |
| ``` |
Please leave a reaction 👍/👎 to this suggestion to improve future reviews for everyone!
| ## Verify | ||
|
|
||
| Run-time verification succeeds when all of the following are true: | ||
|
|
||
| - `snarkjs.groth16.verify(...)` returns `true` | ||
| - The contract `getVerify` method returns `true` | ||
| - `npx blueprint test ...` exits with code `0` | ||
|
|
||
| Partial snippet from the upstream Tact tests. Not runnable: | ||
|
|
||
| ```ts | ||
| const okLocal = await snarkjs.groth16.verify(verificationKey, publicSignals, proof); | ||
| expect(okLocal).toBe(true); | ||
|
|
||
| const { pi_a, pi_b, pi_c, pubInputs } = await groth16CompressProof(proof, publicSignals); | ||
|
|
||
| expect( | ||
| await verifier.getVerify( | ||
| beginCell().storeBuffer(pi_a).endCell().asSlice(), | ||
| beginCell().storeBuffer(pi_b).endCell().asSlice(), | ||
| beginCell().storeBuffer(pi_c).endCell().asSlice(), | ||
| dictFromInputList(pubInputs), | ||
| ), | ||
| ).toBe(true); | ||
| ``` |
There was a problem hiding this comment.
[HIGH] Missing “Not runnable” label on partial snippet
| ## Verify | |
| Run-time verification succeeds when all of the following are true: | |
| - `snarkjs.groth16.verify(...)` returns `true` | |
| - The contract `getVerify` method returns `true` | |
| - `npx blueprint test ...` exits with code `0` | |
| Partial snippet from the upstream Tact tests. Not runnable: | |
| ```ts | |
| const okLocal = await snarkjs.groth16.verify(verificationKey, publicSignals, proof); | |
| expect(okLocal).toBe(true); | |
| const { pi_a, pi_b, pi_c, pubInputs } = await groth16CompressProof(proof, publicSignals); | |
| expect( | |
| await verifier.getVerify( | |
| beginCell().storeBuffer(pi_a).endCell().asSlice(), | |
| beginCell().storeBuffer(pi_b).endCell().asSlice(), | |
| beginCell().storeBuffer(pi_c).endCell().asSlice(), | |
| dictFromInputList(pubInputs), | |
| ), | |
| ).toBe(true); | |
| ``` |
Please leave a reaction 👍/👎 to this suggestion to improve future reviews for everyone!
| { | ||
| "group": "Privacy & ZK", | ||
| "pages": [ | ||
| "contract-dev/zero-knowledge", | ||
| "contract-dev/privacy-zk/groth16-examples" | ||
| ] |
There was a problem hiding this comment.
[HIGH] Sidebar group label uses nonstandard casing and ampersand
Please leave a reaction 👍/👎 to this suggestion to improve future reviews for everyone!
There was a problem hiding this comment.
I'd just replace "Privacy & ZK" with "ZK-proofs" or somesuch
|
|
||
| | Example | Stack | Circuit | What the proof exposes publicly | Tact test | | ||
| | ------------- | -------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------------------- | --------------------------------------------- | | ||
| | `Multiplier` | Circom | [`circuits/Multiplier`](https://github.com/zk-examples/zk-ton-examples/tree/main/circuits/Multiplier) | `c = a * b` | `npx blueprint test Verifier_multiplier_tact` | |
There was a problem hiding this comment.
tact
Here and below, let's only use and reference Tolk examples.
Closes #1840