diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b00d7b8bf..1dc59ba6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -226,4 +226,23 @@ jobs: - name: Run tests run: yarn hardhat test + check-verifier-generator: + runs-on: ubuntu-latest + + steps: + - name: Checkout the repository + uses: actions/checkout@v3 + with: + submodules: "recursive" + + - name: Install rust + uses: actions-rs/toolchain@v1 + with: + toolchain: 1.72.0 + + - name: Generete Verifier.sol + working-directory: tools + run: cargo run + - name: Compare + run: diff tools/data/Verifier.sol ethereum/contracts/zksync/Verifier.sol diff --git a/tools/data/scheduler_key.json b/tools/data/scheduler_key.json index 460fdfab3..586ca4d9a 100644 --- a/tools/data/scheduler_key.json +++ b/tools/data/scheduler_key.json @@ -6,121 +6,121 @@ "gate_setup_commitments": [ { "x": [ - 17594402018597181026, - 13727266004857936655, - 4714664015870427948, - 1394303137462233376 + 2224517667504888251, + 5912818835784168526, + 1111535000905649453, + 319269576845656765 ], "y": [ - 6526005704359308625, - 10449694427901360145, - 15086455287830986775, - 1864377956597492555 + 11120788872048639870, + 13123473843834118559, + 11006337926588718399, + 1693094874597911874 ], "infinity": false }, { "x": [ - 6442869886292765702, - 470631830099167485, - 13697958512656395863, - 3239349454957439636 + 5897728081958793979, + 6833573505420406014, + 8892333702386322308, + 1628848503250072943 ], "y": [ - 1348452587747815007, - 6856197573863561089, - 8497780716227515051, - 3328886581758369840 + 384262179703873891, + 5059975218394949890, + 8220240956645454851, + 2596011989961367462 ], "infinity": false }, { "x": [ - 10989820805534739564, - 9824454085984454699, - 6358142065374293007, - 249913521573460057 + 5322159730374322388, + 3659894232098455483, + 10171880280094971243, + 431515299767226515 ], "y": [ - 16228101767241488970, - 983709565083361956, - 18382922608176957791, - 927347524962839017 + 14791449638831932512, + 10738337476109754900, + 1862661053125068636, + 731793996122181075 ], "infinity": false }, { "x": [ - 295140417017791555, - 18197624951429329770, - 15774295153400712824, - 297838786969948511 + 12917630644677941752, + 4937729565530658654, + 8556480575682662733, + 961697364679101001 ], "y": [ - 17493664288906300385, - 3401716771771611019, - 151838409744935293, - 1081243118696697250 + 8840334103693104877, + 10869978277378103213, + 5520782129896593813, + 2404823286335940024 ], "infinity": false }, { "x": [ - 2504896301341419231, - 5579815447832193044, - 7906209143481974004, - 72896210632653506 + 4177624058108552844, + 7496286594337546064, + 12327303478390769977, + 1884447338697134452 ], "y": [ - 4041048381320048971, - 11710775402846905317, - 15015043042208331520, - 2457322459333810210 + 11592594644619014749, + 1292793399956228893, + 17148866035827453124, + 2259449579930654777 ], "infinity": false }, { "x": [ - 11984418274823067266, - 16496616136320482352, - 8690364473909850702, - 2783152610280540254 + 18120818717781619238, + 16711368075993785449, + 16673817803744408050, + 700058928459046347 ], "y": [ - 16762671120895705772, - 15455915706676685959, - 15137619686845663149, - 86889243887511321 + 7622480271915550714, + 13902980411406060504, + 6164172017934139902, + 1836938876363296665 ], "infinity": false }, { "x": [ - 6562547500299311125, - 12023322154563159589, - 8300642285034494632, - 564372035602029711 + 16821965459015940209, + 16502520825403405563, + 4933134856324568875, + 971914902671623933 ], "y": [ - 4065818489027077486, - 16782980764869638854, - 187491978679299427, - 1653699293812850565 + 8708758630145674281, + 11568462267224108675, + 15920534706957442557, + 2205222521283673407 ], "infinity": false }, { "x": [ - 7272437807968051018, - 16383173516966693760, - 5233705855304303396, - 2084843580173829559 + 13887807756011277977, + 6633952600242750048, + 12933639896153908639, + 1634594860965316349 ], "y": [ - 1945545285616405347, - 11090657413754499713, - 1584981444845638692, - 15483990457410158 + 5219211762505995590, + 3805451927973946744, + 18239167495029817450, + 1620516238642646611 ], "infinity": false } @@ -128,31 +128,31 @@ "gate_selectors_commitments": [ { "x": [ - 2495673539683036265, - 1632020303066964133, - 12421251226958024413, - 1766824016630474366 + 9648237812026707665, + 3394846795043056222, + 4629068839178038498, + 1935924284954725357 ], "y": [ - 16593891732304238653, - 679560656365323651, - 12609189231331785957, - 986143182483620695 + 7429667519719510580, + 9655284945806121212, + 10303170318619716429, + 1450391691397826178 ], "infinity": false }, { "x": [ - 5488925323379543169, - 15884434430617404984, - 2619482091093058395, - 2403360174105428831 + 12328426125821267783, + 14677689403443047323, + 2357692814373165823, + 3268494923353713205 ], "y": [ - 18424859552366064337, - 3217074203004732159, - 3381839436033938516, - 2282990107042495498 + 9394214569640955242, + 450630302635608118, + 1477019964334489453, + 1150908451828220680 ], "infinity": false } @@ -160,61 +160,61 @@ "permutation_commitments": [ { "x": [ - 14205482285409103588, - 4293533900329639146, - 15044988907843772443, - 3397035731454034821 + 14847495908726407963, + 16855284351914487461, + 18211889533001639981, + 2155135400931744246 ], "y": [ - 9091290462832666755, - 13035068257032586999, - 6653434361897150475, - 2202511038693632069 + 10702169610220940865, + 9956121846187196036, + 8949798846882497976, + 2163047794650360669 ], "infinity": false }, { "x": [ - 10595701783879761616, - 1760419279745939647, - 9629156082297835016, - 1336725125155475644 + 378831953168999386, + 9293735894762022592, + 14386665413246396021, + 3071878788754443116 ], "y": [ - 2372896239977265980, - 13229998910487288740, - 4800586654752505377, - 1126182427080184770 + 15896087542596050393, + 17239768855300757555, + 1302380423903460425, + 1070516261187880368 ], "infinity": false }, { "x": [ - 5502581077816805325, - 17655298669514830221, - 7817421360364638165, - 3469705148393998329 + 15681530546748660775, + 15325947204107855582, + 6169941741627651138, + 1438247605769128980 ], "y": [ - 9463722688892810660, - 12340769565473406466, - 11232888947078289597, - 2312085159346807385 + 1709841937332991257, + 3205925128833409221, + 10381982057624226277, + 3302314191697651889 ], "infinity": false }, { "x": [ - 13692318898109463281, - 919764237998990260, - 2432207090405589511, - 756920509450475008 + 7915449484973597791, + 14858122728404062261, + 17806747946577351454, + 1879592080912408858 ], "y": [ - 11815954022684911057, - 10901711436478333928, - 7848970102084501121, - 1813849435398644774 + 15677256576208223457, + 8628800709300512291, + 18168431650113296999, + 252714218130055622 ], "infinity": false } @@ -222,16 +222,16 @@ "total_lookup_entries_length": 1786644, "lookup_selector_commitment": { "x": [ - 1078318040483818758, - 8661469016704600898, - 793379326661434476, - 3459366369695274876 + 9218954341000481996, + 1038591043397823945, + 2355917848722531772, + 1603833229224637991 ], "y": [ - 7529564463317884817, - 6617424140244288891, - 650928162673930424, - 3245921848148438629 + 9294257929334679357, + 9665091690516467420, + 7057032139323633744, + 2846067557162208306 ], "infinity": false }, @@ -299,16 +299,16 @@ ], "lookup_table_type_commitment": { "x": [ - 8190232998277167582, - 10118567615888234126, - 16238500941812062054, - 31348628753253395 + 2681380516794566972, + 967983640969946255, + 2727464508424142824, + 1972327038478390223 ], "y": [ - 9940345244426584302, - 5217477231979664240, - 7040994619944981908, - 1753321375162811736 + 7977458078956869600, + 12274734452276806231, + 29244742286950686, + 667948288229117220 ], "infinity": false }, @@ -396,4 +396,4 @@ "infinity": false } ] -} +} \ No newline at end of file diff --git a/tools/data/verifier_contract_template.txt b/tools/data/verifier_contract_template.txt index 1ded9b453..6d6d5f760 100644 --- a/tools/data/verifier_contract_template.txt +++ b/tools/data/verifier_contract_template.txt @@ -241,7 +241,6 @@ contract Verifier is IVerifier { uint256 internal constant FR_MASK = 0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; {{residue_g2_elements}} - /// @notice Calculates a keccak256 hash of the runtime loaded verification keys. /// @return vkHash The keccak256 hash of the loaded verification keys. function verificationKeyHash() external pure returns (bytes32 vkHash) { @@ -270,7 +269,7 @@ contract Verifier is IVerifier { /// [table_type] - lookup table type commitment function _loadVerificationKey() internal pure virtual { assembly { - {{commitments}} +{{commitments}} // flag for using recursive part mstore(VK_RECURSIVE_FLAG_SLOT, 0) } diff --git a/tools/src/main.rs b/tools/src/main.rs index 39681bda2..3ac8c3ff1 100644 --- a/tools/src/main.rs +++ b/tools/src/main.rs @@ -136,8 +136,8 @@ fn insert_residue_elements_and_commitments( vk: &HashMap, ) -> Result> { let reg = Handlebars::new(); - let residue_g2_elements = generate_residue_g2_elements(&vk); - let commitments = generate_commitments(&vk); + let residue_g2_elements = generate_residue_g2_elements(vk); + let commitments = generate_commitments(vk); let verifier_contract_template = template.replace("{{residue_g2_elements}}", &residue_g2_elements); @@ -178,7 +178,7 @@ fn extract_commitment_slots(items: &[Value], slot_tuple: CommitmentSlot) -> Stri items .iter() .enumerate() - .filter_map(|(idx, item)| { + .map(|(idx, item)| { let map = item.as_object().unwrap(); let x = map.get("x").unwrap().as_array().unwrap(); let y = map.get("y").unwrap().as_array().unwrap(); @@ -186,7 +186,7 @@ fn extract_commitment_slots(items: &[Value], slot_tuple: CommitmentSlot) -> Stri let mstore_x = format_mstore(&x, &slot_tuple.x.replace("{}", &idx.to_string())); let y = convert_list_to_hexadecimal(y); let mstore_y = format_mstore(&y, &slot_tuple.y.replace("{}", &idx.to_string())); - Some(format!("{}{}", mstore_x, mstore_y)) + format!("{}{}", mstore_x, mstore_y) }) .collect::>() .join("") @@ -278,13 +278,13 @@ fn generate_commitments(vk: &HashMap) -> String { .map(|(key, comment)| { let data = vk.get(*key).unwrap().as_array().unwrap(); format!( - "\n // {}\n{}", + " // {}\n{}", comment, extract_commitment_slots(data, COMMITMENTS_SLOTS[*key]) ) }) .collect::>() - .join(""); + .join("\n"); let individual_commitments = individual_commitments_data .iter() @@ -305,14 +305,14 @@ fn generate_residue_g2_elements(vk: &HashMap) -> String { let mut residue_g2_elements = String::new(); let vk_non_residues = vk.get("non_residues").unwrap().as_array().unwrap(); - residue_g2_elements.push_str("\n // non residues\n"); + residue_g2_elements.push_str("// non residues\n"); residue_g2_elements.push_str(&extract_non_residues( vk_non_residues, NON_RESIDUES["non_residues"], )); let vk_g2_elements = vk.get("g2_elements").unwrap().as_array().unwrap(); - residue_g2_elements.push_str("\n // g2 elements\n"); + residue_g2_elements.push_str("\n // trusted setup g2 elements\n"); residue_g2_elements.push_str(&extract_g2_elements( vk_g2_elements, G2_ELEMENTS["g2_elements"],