Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prover: verify: update verify command to EIP-4844 #18

Merged
merged 1 commit into from
Sep 9, 2024

Conversation

wzmuda
Copy link
Collaborator

@wzmuda wzmuda commented Sep 3, 2024

Problem

Prior to this change the following problem occurred

cat proof.txt | ./gnark-mbu verify --keys-file test_insertion.ps --mode insertion --input-hash "0x2e7fa6e0106ec5f1f0d1f1cf2e88a83be4ccd41252e58a3c5d4d3e2a5732c823" 
21:42:10 DBG Reading tree depth
21:42:10 DBG Reading batch size
21:42:10 DBG Reading proving key
21:42:39 DBG Reading verifying key
21:42:39 DBG Reading constraint system
21:42:39 INF Read proving system batchSize=3 treeDepth=16
21:42:39 INF reading proof from stdin
21:42:39 INF proof read successfully
21:42:39 FTL App failed. error="can't set fr.Element with <nil>"

This is because the handler of the verify command did not took EIP-4844 changes into consideration. It still operated on the old insertion circuit structure. It compiled accidentally, because the new structure extends the old one. The verify handler still used valid field names of the circuit's structure, but didn't populate all of them. Therefore proof verification failed.

Solution

gnark-mbu verify was neglected in EIP-4844 changes. Update the VerifyInsertion handler, so that it uses the recent insertion circuit structure. Fields of the structure are populated both from:

  • standard input (previously only proof was provided via stdin, now it's full response, which also contains proof),
  • new --params flag (previously parameters were not needed).

The new --params flag accepts input from gnark-mbu gen-test-params command.

Dedicated --input-hash flag is not needed for the insertion mode, as input hash is included in the response. This flag was made optional and is checked in deletion only.

Demonstration

Prior gnark-mbu setup is implied.

➜  semaphore-mtb git:(wz/4844-fix-verify) ✗ go build 

➜  semaphore-mtb git:(wz/4844-fix-verify) ✗ ./gnark-mbu gen-test-params --mode insertion --tree-depth 16 --batch-size 3 | tee params.txt                                                   
22:13:26 INF Generating test params for the insertion circuit
{"startIndex":0,"preRoot":"0x2a7c7c9b6ce5880b9f6f228d72bf6a575a526f29c66ecceef8b753d38bba7323","postRoot":"0x193289951bec3e4a099d9f1b0fb22cf20fe9dc4ea75c253352f22848b08c888b","identityCommitments":["0x1","0x2","0x3"],"merkleProofs":[["0x0","0x2098f5fb9e239eab3ceac3f27b81e481dc3124d55ffed523a839ee8446b64864","0x1069673dcdb12263df301a6ff584a7ec261a44cb9dc68df067a4774460b1f1e1","0x18f43331537ee2af2e3d758d50f72106467c6eea50371dd528d57eb2b856d238","0x7f9d837cb17b0d36320ffe93ba52345f1b728571a568265caac97559dbc952a","0x2b94cf5e8746b3f5c9631f4c5df32907a699c58c94b2ad4d7b5cec1639183f55","0x2dee93c5a666459646ea7d22cca9e1bcfed71e6951b953611d11dda32ea09d78","0x78295e5a22b84e982cf601eb639597b8b0515a88cb5ac7fa8a4aabe3c87349d","0x2fa5e5f18f6027a6501bec864564472a616b2e274a41211a444cbe3a99f3cc61","0xe884376d0d8fd21ecb780389e941f66e45e7acce3e228ab3e2156a614fcd747","0x1b7201da72494f1e28717ad1a52eb469f95892f957713533de6175e5da190af2","0x1f8d8822725e36385200c0b201249819a6e6e1e4650808b5bebc6bface7d7636","0x2c5d82f66c914bafb9701589ba8cfcfb6162b0a12acf88a8d0879a0471b5f85a","0x14c54148a0940bb820957f5adf3fa1134ef5c4aaa113f4646458f270e0bfbfd0","0x190d33b12f986f961e10c0ee44d8b9af11be25588cad89d416118e4bf4ebe80c","0x22f98aa9ce704152ac17354914ad73ed1167ae6596af510aa5b3649325e06c92"],["0x1","0x2098f5fb9e239eab3ceac3f27b81e481dc3124d55ffed523a839ee8446b64864","0x1069673dcdb12263df301a6ff584a7ec261a44cb9dc68df067a4774460b1f1e1","0x18f43331537ee2af2e3d758d50f72106467c6eea50371dd528d57eb2b856d238","0x7f9d837cb17b0d36320ffe93ba52345f1b728571a568265caac97559dbc952a","0x2b94cf5e8746b3f5c9631f4c5df32907a699c58c94b2ad4d7b5cec1639183f55","0x2dee93c5a666459646ea7d22cca9e1bcfed71e6951b953611d11dda32ea09d78","0x78295e5a22b84e982cf601eb639597b8b0515a88cb5ac7fa8a4aabe3c87349d","0x2fa5e5f18f6027a6501bec864564472a616b2e274a41211a444cbe3a99f3cc61","0xe884376d0d8fd21ecb780389e941f66e45e7acce3e228ab3e2156a614fcd747","0x1b7201da72494f1e28717ad1a52eb469f95892f957713533de6175e5da190af2","0x1f8d8822725e36385200c0b201249819a6e6e1e4650808b5bebc6bface7d7636","0x2c5d82f66c914bafb9701589ba8cfcfb6162b0a12acf88a8d0879a0471b5f85a","0x14c54148a0940bb820957f5adf3fa1134ef5c4aaa113f4646458f270e0bfbfd0","0x190d33b12f986f961e10c0ee44d8b9af11be25588cad89d416118e4bf4ebe80c","0x22f98aa9ce704152ac17354914ad73ed1167ae6596af510aa5b3649325e06c92"],["0x0","0x115cc0f5e7d690413df64c6b9662e9cf2a3617f2743245519e19607a4417189a","0x1069673dcdb12263df301a6ff584a7ec261a44cb9dc68df067a4774460b1f1e1","0x18f43331537ee2af2e3d758d50f72106467c6eea50371dd528d57eb2b856d238","0x7f9d837cb17b0d36320ffe93ba52345f1b728571a568265caac97559dbc952a","0x2b94cf5e8746b3f5c9631f4c5df32907a699c58c94b2ad4d7b5cec1639183f55","0x2dee93c5a666459646ea7d22cca9e1bcfed71e6951b953611d11dda32ea09d78","0x78295e5a22b84e982cf601eb639597b8b0515a88cb5ac7fa8a4aabe3c87349d","0x2fa5e5f18f6027a6501bec864564472a616b2e274a41211a444cbe3a99f3cc61","0xe884376d0d8fd21ecb780389e941f66e45e7acce3e228ab3e2156a614fcd747","0x1b7201da72494f1e28717ad1a52eb469f95892f957713533de6175e5da190af2","0x1f8d8822725e36385200c0b201249819a6e6e1e4650808b5bebc6bface7d7636","0x2c5d82f66c914bafb9701589ba8cfcfb6162b0a12acf88a8d0879a0471b5f85a","0x14c54148a0940bb820957f5adf3fa1134ef5c4aaa113f4646458f270e0bfbfd0","0x190d33b12f986f961e10c0ee44d8b9af11be25588cad89d416118e4bf4ebe80c","0x22f98aa9ce704152ac17354914ad73ed1167ae6596af510aa5b3649325e06c92"]]}

➜  semaphore-mtb git:(wz/4844-fix-verify) ✗ cat params.txt | ./gnark-mbu prove --mode insertion --keys-file test_insertion.ps | tee response.txt
22:14:17 DBG Reading tree depth
22:14:17 DBG Reading batch size
22:14:17 DBG Reading proving key
22:14:44 DBG Reading verifying key
22:14:44 DBG Reading constraint system
22:14:45 INF Read proving system batchSize=3 treeDepth=16
22:14:45 INF reading params from stdin
22:14:45 INF params read successfully
22:14:45 INF generating proof
22:14:45 DBG constraint system solver done nbConstraints=3064883 took=761.679917
22:14:50 DBG prover done acceleration=none backend=groth16 curve=bn254 nbConstraints=3064883 took=4460.716167
22:14:50 INF proof generated successfully
{"inputHash":"0x2e7fa6e0106ec5f1f0d1f1cf2e88a83be4ccd41252e58a3c5d4d3e2a5732c823","expectedEvaluation":"00e82ed85cd41af83628b179b6ec8cfeaed10e9eb679080e0d56cb1cfee37ad5","commitment4844":"943df914ff6ba2182903cefc2f215b4e9299eaba67dd7457cf30946fe0888dce6a52d73f04a255dde9c6edaddda577bb","proof":{"ar":["0x264ba7c59750f01e6f10f94eaeaa67243bfa217c56b03110c295645dbaa93630","0x1bf2f5e17a10de668a5ca8455cbfdbd7826b3e30dc95804941c903f7099a13e5"],"bs":[["0x2f3850f03b55d6ee3d5d49077c90ac47b47a130b6891f4a68da375e21758a722","0x25a23ecb7eb9e001fe784bfa21c8eba4faf865263eee7c66100dc3109db1c1d4"],["0x22a56a8e45ed07b81f96f65809539289dca94cf53b085258a1d0a846cf42b5e7","0x2c990952ab5753d128e07b129338ae07b8ec11133fec868d7062d54ab52b9a49"]],"krs":["0xa450468c95a1200754cbc6e67a5aba5771441b1f9f9badc3fc7af8e9023c07c","0xa8bc5230872dd57ad4916774cd4f49696c7cc4c48ae69da7892bc20a51b7dec"],"commitments":[["0x83b1901a8d941fa5dedb1e2b679fd81a5250a280d7d17afc100a3aa4d11293d","0x118f103da1555ab1b3c88bd2f2605499795c4f9748e86ec6176f91504a278679"]],"commitmentPok":["0x14e1588310b5f73b38252836ad7d3eb99060efd561a1b002e882197bdd19bf71","0x2337305cf9a94028e6c46af91c9370280240c49db6bce5de4e1c7d6813b1cdff"]},"kzgProof":"a07a587538ec18338434ee25996aa8ae6e56b7db70d0be9ed7032483454c0c416ebc14f156b06b5f7a65c3a8e4bf7d7c"}

➜  semaphore-mtb git:(wz/4844-fix-verify) ✗ cat response.txt | ./gnark-mbu verify --keys-file test_insertion.ps --mode insertion --params $(cat params.txt)
22:21:27 DBG Reading tree depth
22:21:27 DBG Reading batch size
22:21:27 DBG Reading proving key
22:21:54 DBG Reading verifying key
22:21:54 DBG Reading constraint system
22:21:54 INF Read proving system batchSize=3 treeDepth=16
22:21:54 INF reading proof from stdin
22:21:54 INF proof read successfully
22:21:54 INF reading parameters
22:21:54 INF params read successfully
22:21:54 DBG verifier done backend=groth16 curve=bn254 took=1.612
22:21:54 INF verification complete

@wzmuda wzmuda requested a review from kustosz September 3, 2024 20:34
`gnark-mbu verify` was neglected in EIP-4844 changes. Update the
VerifyInsertion handler, so that it uses the recent insertion circuit
structure. Fields of the structure are populated both from:
 - standard input (previously only proof was provided via stdin, now
   it's full response, which also contains proof),
- new --params flag (previously parameters were not needed).

The new --params flag accepts input from `gnark-mbu gen-test-params`
command.

Dedicated --input-hash flag is not needed for the insertion mode, as
input hash is included in the response. This flag was made optional and
is checked in deletion only.

Signed-off-by: Wojciech Zmuda <[email protected]>
@wzmuda wzmuda force-pushed the wz/4844-fix-verify branch from 9d2a8c1 to d3d69d5 Compare September 3, 2024 20:35
prover/insertion_proving_system.go Show resolved Hide resolved
@wzmuda wzmuda merged commit 52a4a1d into next Sep 9, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants