# Verification dragonfruit In order to verify the smart contract, you will need a machine with at least 256GB of RAM and 16 cores. In this tutorial we will give instructions for a r6a.8xlarge aws instance. This instance has 16 cores 32 threads, 512GB of SSD. The instance will use Ubuntu 22.04 LTS and the cost of the instance is 1.82 $/h. So lets start by launching and instance. ## Basic OS preparation ````bash sudo apt update sudo apt install -y tmux git curl ```` ## Tweeking the OS to accept high amount of memory. ````bash echo "vm.max_map_count=655300" | sudo tee -a /etc/sysctl.conf sudo sysctl -w vm.max_map_count=655300 export NODE_OPTIONS="--max-old-space-size=230000" ```` ## Install version of node and npm ````bash curl -sL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh sudo bash nodesource_setup.sh sudo apt install -y nodejs node -v ```` The version of node should be: 18 (e.g. 18.14.0 ) ## Download and prepare circom To compile circuits, we need circom installed. ````bash cd ~ git clone https://github.com/iden3/circom.git cd circom git checkout v2.1.4 git log --pretty=format:'%H' -n 1 ```` The hash of the commit should be: ca3345681549c859af1f3f42128e53e3e43fe5e2 Install and compile circom (RUST) ````bash sudo apt install -y cargo cargo build --release cargo install --path circom export PATH=$PATH:~/.cargo/bin echo 'PATH=$PATH:~/.cargo/bin' >> ~/.profile circom --version ```` The version of circom should be: 2.1.4 ## Prepare fast build constant tree ````bash cd ~ git clone https://github.com/0xPolygonHermez/zkevm-prover.git cd zkevm-prover git checkout b9179f3b870c2922b11d09462b447d0fc35dd2f9 git submodule init git submodule update sudo apt install -y build-essential libomp-dev libgmp-dev nlohmann-json3-dev libpqxx-dev nasm libgrpc++-dev libprotobuf-dev grpc-proto libsodium-dev uuid-dev libsecp256k1-dev make -j bctree ```` this step takes approximately 8 minutes. ## Prepare and launch first part of setup (zkevm-proverjs) ````bash cd ~ git clone https://github.com/0xPolygonHermez/zkevm-proverjs.git cd zkevm-proverjs git checkout 55fd7071782d78263b007c66aa57dc50aff0ce7d npm install tmux -c "npm run buildsetup --bctree=../zkevm-prover/build/bctree --to=g16setup" ```` This step is quite long, it takes approximately 4 hours. 2 out of 4 hours are for the powersOfTau28_hez_final.ptau download, a file of 288GB that it's loaded only once. > NOTE: At the end of the document there is a table with all the hashes of the files generated during this process. > ## Second part of setup - Contributions In this part of process, the contributions are included. ````bash cd ~/zkevm-proverjs curl https://de012a78750e59b808d922b39535e862.s3.eu-west-1.amazonaws.com/v0.7.0.0-rc.7-fork.1/config/final/final.g16.0001.zkey -o build/proof/final.g16.0001.zkey tmux -c "node node_modules/snarkjs/cli.js zkv build/proof/final.r1cs build/powersOfTau28_hez_final.ptau build/proof/final.g16.0001.zkey" ```` ## Final part of setup - Smart Contract generation Once all the contributions are processed, proceed with the setup process. ````bash cd ~/zkevm-proverjs tmux -c "npm run buildsetup --bctree=../zkevm-prover/build/bctree --from=g16evk" ```` > NOTE: At the end of the document there is a table with all the hashes of the files generated during this process. ## Compile generated verifier smartcontract (solidity) As a final result of the previous steps, the smart contract that verifies the test has been generated. This file is *final.g16.verifier.sol*. At this point, it is possible to verify the smart contract using the source code or verify that the bytecode is the same. **To verify the bytecode**, you must compile with the precisely same version, compiler, and parameters to be sure that even the metadata hash contained in the bytecode is exactly the same. The following instructions generate a project to build using the **hardhat** tool. ````bash cd ~ mkdir contract cd contract npm init -y npm install hardhat mkdir -p contracts/verifiers echo -e "module.exports={solidity:{compilers:[{version: \"0.6.11\",settings:{optimizer:{enabled:true,runs: 999999}}}]}}" > hardhat.config.js ```` Once the project structure is created, we proceed to copy the smart contract generated in the previous step. This smart contract was saved on *~/zkevm-proverjs/build/proof*, and must be copied to *contracts/verifiers* with exactly the name *Verifier.sol*. If the name or the path changes, the hash of metadata changes too, for this reason, is essential to respect the name and the path. To do it could execute these commands ````bash cp ~/zkevm-proverjs/build/proof/final.g16.verifier.sol contracts/verifiers/Verifier.sol sha256sum contracts/verifiers/Verifier.sol ```` The result should be: ```` 9b763c179b49bd1f6adaaff4722329bb02aab708b610ab5d88ff4b7804bb71ed ```` To compile smartcontract execute following command: ````bash npx hardhat compile ```` Bytecode of smartcontract was on bytecode property of json file *Verifier.json* generated on path *artifacts/contracts/verifiers/Verifier.sol* ```` 0x608060405234801561001057600080fd5b5061 0f6a806100206000396000f3fe60806040523480 : : 6001604052806003906020820280368337509192 915050565b604051806080016040528060049060 20820280368337509192915050565b6040518060 400160405280610eeb610f16565b815260200161 0e36610f16565b60405180602001604052806001 906020820280368337509192915050565b604051 8060400160405280600290602082028036833750 919291505056fea2646970667358221220b8a20d b88e95728ff51d4fb60d7aae3df6f322c059d62e 70d2635163c88683e164736f6c634300060b0033 ```` To extract bytecode on file in one line. If you prefer do it , you cold copy and paste in a file. ````bash grep bytecode artifacts/contracts/verifiers/Verifier.sol/Verifier.json |sed 's/.*"\(0x.*\)".*/\1/' > Verifier.sol.compiled.bytecode ```` > NOTE: if you prefer you can copy by hand the content of the bytecode of the file *artifacts/contracts/verifiers/Verifier.sol/Verifier.json* over files *Verifier.sol.compiled.bytecode*. Remember to copy only the content inside the double quotes (without double quotes). > Verify bytecode compiled: ```` sha256sum Verifier.sol.compiled.bytecode ```` The result should be: ```` 5fdc212ffafdc7e5495349ba5b6ab27e3c70173794cfa85fdef5b5f9889995a1 ```` ## Download bytecode of deployed smartcontract To download bytecode of deployed smartcontract, need the address of smart contract, in this case it's *0xb25e1624466F614FAc528A8594d22d8BBBF39Fea*. Go to Etherscan, Blockscout or Beaconcha to get transaction bytecode. Associated with address *0xb25e1624466F614FAc528A8594d22d8BBBF39Fea* found the transacction *0xa06559158d54702e4c3cebca91d6733e2123d7f4c4276f4c173528477879292f*. - ### Etherscan (https://goerli.etherscan.io) https://goerli.etherscan.io/address/0xb25e1624466F614FAc528A8594d22d8BBBF39Fea https://goerli.etherscan.io/tx/0xa06559158d54702e4c3cebca91d6733e2123d7f4c4276f4c173528477879292f Click to see more > Input Data > Select all data and copy to clipboard. - ### Blockscout (https://eth-goerli.blockscout.com) https://eth-goerli.blockscout.com/address/0xb25e1624466F614FAc528A8594d22d8BBBF39Fea https://eth-goerli.blockscout.com/tx/0xa06559158d54702e4c3cebca91d6733e2123d7f4c4276f4c173528477879292f View details > Raw input > Copy to clipboard - ### Beacocha (https://goerli.beaconcha.in) https://goerli.beaconcha.in/address/0xb25e1624466F614FAc528A8594d22d8BBBF39Fea https://goerli.beaconcha.in/tx/0xa06559158d54702e4c3cebca91d6733e2123d7f4c4276f4c173528477879292f Advanced Info > Call Data > Select all data and copy to clipboard. *NOTE: Don't use button "Copy Raw Data" because it generated non compatible format.* Some applications running on the terminal may limit the amount of input they will accept before their input buffers overflow. To avoid this situation create file *Verifier.sol.explorer.bytecode* with editor as nano or vi. ````bash cd ~/contract nano Verifier.sol.explorer.bytecode ```` In nano, to paste the clipboard to the file use CTRL+P, save content using CTRL+X, and finally press Y. To compare if two files are the same, you could use diff. ````bash cd ~/contract diff Verifier.sol.compiled.bytecode Verifier.sol.explorer.bytecode ```` Alternatively, you could check content using sha256sum: ````bash cd ~/contract ls -l Verifier.sol.*.bytecode sha256sum Verifier.sol.*.bytecode ```` The result should be: ```` -rw-rw-r-- 1 doe doe 7959 Feb 13 08:00 Verifier.sol.compiled.bytecode -rw-rw-r-- 1 doe doe 7959 Feb 13 08:30 Verifier.sol.explorer.bytecode 5fdc212ffafdc7e5495349ba5b6ab27e3c70173794cfa85fdef5b5f9889995a1 Verifier.sol.compiled.bytecode 5fdc212ffafdc7e5495349ba5b6ab27e3c70173794cfa85fdef5b5f9889995a1 Verifier.sol.explorer.bytecode ```` ## Make a public post. If you reach this point, it would be great if you can publish a public post or at least a tweet explaining that you verified the smart contract. For any incident you find, please do not hesitate to contact us in the ************ **TBD** ********** ## Generated files hash <table> <tr><th>step/file</th><th>sha256</th></tr> <tr><td colspan=2><b>buildrom</b></td></tr> <tr><td>rom.json</td><td>097d2c066426d330764ed083442ddcea<br>9516ecbe9716418264bcda36a3b01f4e</td></tr> <tr><td colspan=2><b>buildpil</b></td></tr> <tr><td>main.pil.json</td><td>27cd0e817d576c77f76403401b4e4a5b<br>c4dd420ced7bb3f2a72a5f6374c6d530</td></tr> <tr><td colspan=2><b>buildconstants</b></td></tr> <tr><td>zkevm.const</td><td>ae2f80c52bb0c14cb0c61d825105e155<br>775b9198ae39ffcce6afb8fb9039197c</td></tr> <tr><td colspan=2><b>buildstarkinfo</b></td></tr> <tr><td>zkevm.starkstruct.json</td><td>284b6ce275c637af4a0b4b10cd83a881<br>c6f1b21e21ad7ea2276379ed8393b099</td></tr> <tr><td>zkevm.starkinfo.json</td><td>8db6f6806a05ea86945540bc4ae40403<br>2dcd5831e87ad5192d66ac56aa5d0a88</td></tr> <tr><td colspan=2><b>buildconstanttree</b></td></tr> <tr><td>zkevm.verkey.json</td><td>2b32376ef86b76760b479bbd1ae437b8<br>881c65191cf35aa4ec39c0877d270eb2</td></tr> <tr><td>zkevm.consttree</td><td>0c31f0b6aa03c4b87ef17625f53c5462<br>e7f886e753f8ad313d962a846b188684</td></tr> <tr><td colspan=2><b>gencircom</b></td></tr> <tr><td>zkevm.verifier.circom</td><td>7afcd63d6a82f0e22a3f4ecfdf108890<br>8863a9da2439e9806d47fa68423a91fb</td></tr> <tr><td colspan=2><b>compilecircom</b></td></tr> <tr><td>zkevm.verifier.r1cs</td><td>3d8c2ad20293350d236d95eb82fc2d08<br>bdc05439b5f301de3d60973de78a82d2</td></tr> <tr><td>zkevm.verifier.sym</td><td>d7c115ecf61599630a7e462b5f88ef97<br>169b313641edaf004aa2f182c2649fd6</td></tr> <tr><td colspan=2><b>c12a_setup</b></td></tr> <tr><td>c12a.pil</td><td>d1aa48508d82fccf82d3aeb2447aa0d5<br>a696125710a1a1203ceb84acac9b4ec5</td></tr> <tr><td>c12a.const</td><td>b33480924078ad71f2d8198fec625d01<br>6f4cf57f630f19e65a0ce793ac945b38</td></tr> <tr><td>c12a.exec</td><td>eabceacdac55c3ecf54eee91d823b8c5<br>fa94d4eb42235e7f1a35c13175b328aa</td></tr> <tr><td colspan=2><b>c12a_buildstarkinfo</b></td></tr> <tr><td>c12a.starkstruct.json</td><td>920b777dc3d6998c99514761d35d04bc<br>4d129e3799d6ab1d0400eab19988ac6f</td></tr> <tr><td>c12a.starkinfo.json</td><td>9fc0fb3083069dc4a41501adf05423d9<br>a44dd30e980847afcd5130435be96ea3</td></tr> <tr><td colspan=2><b>c12a_buildconstanttree</b></td></tr> <tr><td>c12a.verkey.json</td><td>3638b728afa3a0138d28a9db297eb2bc<br>ef70be6e9443ea16f220597ff378ea2d</td></tr> <tr><td>c12a.consttree</td><td>3d5e17f371e91a29e06994f20eee4f29<br>f3db543cd39b9cef7728b2453031b4fa</td></tr> <tr><td colspan=2><b>c12a_gencircom</b></td></tr> <tr><td>c12a.verifier.circom</td><td>0723223b897bf6ac415f010f39dbd10c<br>438c4c71a7912e87fb3c52d312792866</td></tr> <tr><td colspan=2><b>recursive1_gencircom</b></td></tr> <tr><td>recursive1.circom</td><td>9e3c2a901a9340481bca1e2d5793e689<br>3cc6e4ece4ccde1c593c1e413263c44b</td></tr> <tr><td colspan=2><b>recursive1_compile</b></td></tr> <tr><td>recursive1.r1cs</td><td>619bae232b95a131d6bf54aa394095ef<br>ea466a1435999bede89a9d7ef6ae5d66</td></tr> <tr><td>recursive1.sym</td><td>78bb84e85815b2641ef9c9d9c4106b98<br>1282690c66d61625a3b7fa42667d4230</td></tr> <tr><td colspan=2><b>recursive1_setup</b></td></tr> <tr><td>recursive1.pil</td><td>600aaf142766eb473fcc3b7171f6afa3<br>06e09faf37f77a6ac4214c8890e3a55d</td></tr> <tr><td>recursive1.const</td><td>777878dd66d1a5560ca42de20b66607f<br>ddeb8e3cddcbca1c4ac56c0e32862674</td></tr> <tr><td>recursive1.exec</td><td>ad048f4119b4b1541092cd57aa4a255a<br>e68bb530dfc2f1fe222567343fc8abe4</td></tr> <tr><td colspan=2><b>recursive1_buildstarkinfo</b></td></tr> <tr><td>recursive.starkstruct.json</td><td>7ae67d5411a2de84e9b50e8797270a05<br>4f116fdbed6f327acb9d93628ee7549c</td></tr> <tr><td>recursive1.starkinfo.json</td><td>9e5433af9baf24e5570d780f58ef5b85<br>7c2ca5a84709489e7f322220af549cca</td></tr> <tr><td colspan=2><b>recursive1_buildconstanttree</b></td></tr> <tr><td>recursive1.verkey.json</td><td>917462aa17e45bfb53e0df7083609865<br>e30b5eb2cc8a50a6437b2dde8062d9a9</td></tr> <tr><td>recursive1.consttree</td><td>07fa2156fdb0b6f1982adba8eb0291e4<br>3c37745f114e5e3af3ad34217f362eb6</td></tr> <tr><td colspan=2><b>recursive1_verifier_gencircom</b></td></tr> <tr><td>recursive1.verifier.circom</td><td>c44140b315693106971028790011ba64<br>e82fc18090888468b3c79d0f734fe7c1</td></tr> <tr><td colspan=2><b>recursive2_gencircom</b></td></tr> <tr><td>recursive2.circom</td><td>a4d19ea1cd749dea3abe56e4b26b7590<br>53ad24b477f5be825820754fe6369f2b</td></tr> <tr><td colspan=2><b>recursive2_compile</b></td></tr> <tr><td>recursive2.r1cs</td><td>633fdef4fac115ff674201b4a82aaa6c<br>068ce8e0cae8c1b9d0ca085b8276cc66</td></tr> <tr><td>recursive2.sym</td><td>19935861c630ca15db052c9f869da6ac<br>88ad59baed74b1533dd53f23ef11df76</td></tr> <tr><td colspan=2><b>recursive2_setup</b></td></tr> <tr><td>recursive2.pil</td><td>600aaf142766eb473fcc3b7171f6afa3<br>06e09faf37f77a6ac4214c8890e3a55d</td></tr> <tr><td>recursive2.const</td><td>dc2360f3f1c9b30dfa3c6f47f249378a<br>a0165c30ad6f1a618a440dc31641bb01</td></tr> <tr><td>recursive2.exec</td><td>7f2479956334a00a61900491a267c50a<br>c6953d3d3bda871a01d3471bbe4029d5</td></tr> <tr><td colspan=2><b>recursive2_buildstarkinfo</b></td></tr> <tr><td>recursive2.starkinfo.json</td><td>9e5433af9baf24e5570d780f58ef5b85<br>7c2ca5a84709489e7f322220af549cca</td></tr> <tr><td colspan=2><b>recursive2_buildconstanttree</b></td></tr> <tr><td>recursive2.verkey.json</td><td>e4411d6b3f73d9cbc757134c55514ae6<br>f9c13f1398d5afc73b1f6fdd4fc8f076</td></tr> <tr><td>recursive2.consttree</td><td>904f1a5e4e0fcfe463f17ed2cf591fd3<br>9aab554ece494a85557d219ad2143a23</td></tr> <tr><td colspan=2><b>recursive2_verifier_gencircom</b></td></tr> <tr><td>recursive2.verifier.circom</td><td>c44140b315693106971028790011ba64<br>e82fc18090888468b3c79d0f734fe7c1</td></tr> <tr><td colspan=2><b>recursivef_gencircom</b></td></tr> <tr><td>recursivef.circom</td><td>1a77ec194e1f72969dc361a9b63ecc71<br>2fc6aca6ee911820f496b69aad7da4dc</td></tr> <tr><td colspan=2><b>recursivef_compile</b></td></tr> <tr><td>recursivef.r1cs</td><td>f031a046a97e6569e9a06aa5f9113767<br>3f3eac9b2ef1bac4d65081c50f8a3f06</td></tr> <tr><td>recursivef.sym</td><td>002f9941b0b091f1dd3c2d9755a8f4c0<br>5db2af678052de56c84ab40fc14b3edd</td></tr> <tr><td colspan=2><b>recursivef_setup</b></td></tr> <tr><td>recursivef.pil</td><td>90285d359be25e81bbbf7f7713fceed9<br>874730ae6d233b757dab884b5c88b643</td></tr> <tr><td>recursivef.const</td><td>64d6884a3e4fa7800135ce418fd79d9f<br>3cac7a010e9f277a16b7b78275a305a4</td></tr> <tr><td>recursivef.exec</td><td>8cf9b7ff7ca623cc50807a917ee30ca9<br>9de6692db89baa315d60e5d09462090b</td></tr> <tr><td colspan=2><b>recursivef_buildstarkinfo</b></td></tr> <tr><td>recursivef.starkstruct.json</td><td>5176f80126963cfac8f7956963aae3c1<br>7f4842382327a9e1de066e52bb058718</td></tr> <tr><td>recursivef.starkinfo.json</td><td>30c96563c8476073759660db21c76772<br>6b2ad78aacea0c5007c17972a74a3a6d</td></tr> <tr><td colspan=2><b>recursivef_buildconstanttree</b></td></tr> <tr><td>recursivef.verkey.json</td><td>ea8916b231578da0cfb2bc1601891714<br>44edb05354d09db19e4500fb2d3e194a</td></tr> <tr><td>recursivef.consttree</td><td>bf906d56fde5b9a58deeb85a97e5c479<br>1b8d7b75198a8aa06acb502b66b5744c</td></tr> <tr><td colspan=2><b>recursivef_verifier_gencircom</b></td></tr> <tr><td>recursivef.verifier.circom</td><td>24bae8bfe56dd0bf9dfafba483949944<br>143e423aff2033e5ca21a7282adc54f5</td></tr> <tr><td colspan=2><b>final_gencircom</b></td></tr> <tr><td>final.circom</td><td>b248cd8273754709216d8611b3bcf56d<br>ca1650f0f486690757d6109892b2379b</td></tr> <tr><td colspan=2><b>final_compile</b></td></tr> <tr><td>final.r1cs</td><td>16ab01c627ca545486c08b6d001cb36d<br>9cb4a3d2a9de3ed4bce59a150e814ce3</td></tr> <tr><td>final.sym</td><td>ac87d65dda98ff9f413d29177415a071<br>add189496be94e39f74cf1e8d135d61c</td></tr> <tr><td colspan=2><b>g16setup</b></td></tr> <tr><td>final.g16.0000.zkey</td><td>b33024c0360021010b582aa6b35a62b0<br>c78faf010504351d9277ae69875c6f1e</td></tr> <tr><td colspan=2><b>g16contribute</b></td></tr> <tr><td>final.g16.0001.zkey</td><td>3fcbf5f7fba915419c91c91d1ad86013<br>3b2e438309be04d695032c3a2e1b516f</td></tr> <tr><td colspan=2><b>g16evk</b></td></tr> <tr><td>final.g16.verkey.json</td><td>a8195600b3d310665dd09dacc9871ab6<br>eea527944c5ae0f5dbf3c3fd40a4604e</td></tr> <tr><td colspan=2><b>g16solidity</b></td></tr> <tr><td>final.g16.verifier.sol</td><td>9b763c179b49bd1f6adaaff4722329bb<br>02aab708b610ab5d88ff4b7804bb71ed</td></tr> </table> <font size=3>