From 9a824945ea96e763eca0d3d387f0e2189f269185 Mon Sep 17 00:00:00 2001 From: Jim Zhang Date: Thu, 30 Jan 2025 09:33:49 -0500 Subject: [PATCH] rename deposit, withdraw circuits and solidity verifiers Signed-off-by: Jim Zhang --- solidity/contracts/lib/zeto_fungible.sol | 7 +- .../contracts/lib/zeto_fungible_withdraw.sol | 17 +- .../lib/zeto_fungible_withdraw_nullifier.sol | 16 +- .../verifier_check_nullifiers_value.sol | 210 ------------ .../verifier_check_nullifiers_value_batch.sol | 322 ------------------ ..._hashes_value.sol => verifier_deposit.sol} | 2 +- ...utputs_value.sol => verifier_withdraw.sol} | 2 +- ..._batch.sol => verifier_withdraw_batch.sol} | 2 +- ...ue.sol => verifier_withdraw_nullifier.sol} | 2 +- ... => verifier_withdraw_nullifier_batch.sol} | 2 +- solidity/contracts/zeto_anon.sol | 16 +- solidity/contracts/zeto_anon_enc.sol | 16 +- .../contracts/zeto_anon_enc_nullifier.sol | 12 +- .../contracts/zeto_anon_enc_nullifier_kyc.sol | 12 +- ...eto_anon_enc_nullifier_non_repudiation.sol | 12 +- solidity/contracts/zeto_anon_nullifier.sol | 12 +- .../contracts/zeto_anon_nullifier_kyc.sol | 12 +- solidity/ignition/modules/lib/deps.ts | 20 +- solidity/test/utils.ts | 20 +- ...eck_hashes_value.circom => deposit.circom} | 0 zkp/circuits/gen-config.json | 6 +- ...s_outputs_value.circom => withdraw.circom} | 0 ...lue_batch.circom => withdraw_batch.circom} | 0 ...value.circom => withdraw_nullifier.circom} | 0 ...circom => withdraw_nullifier_batch.circom} | 0 .../{check_hashes_value.js => deposit.js} | 7 +- zkp/js/integration-test/nf_anon_nullifier.js | 5 +- ...ck_inputs_outputs_value.js => withdraw.js} | 8 +- ...lifiers_value.js => withdraw_nullifier.js} | 9 +- .../{check_hashes_value.js => deposit.js} | 4 +- ...ck_inputs_outputs_value.js => withdraw.js} | 4 +- ...lifiers_value.js => withdraw_nullifier.js} | 4 +- 32 files changed, 108 insertions(+), 653 deletions(-) delete mode 100644 solidity/contracts/verifiers/verifier_check_nullifiers_value.sol delete mode 100644 solidity/contracts/verifiers/verifier_check_nullifiers_value_batch.sol rename solidity/contracts/verifiers/{verifier_check_hashes_value.sol => verifier_deposit.sol} (99%) rename solidity/contracts/verifiers/{verifier_check_inputs_outputs_value.sol => verifier_withdraw.sol} (99%) rename solidity/contracts/verifiers/{verifier_check_inputs_outputs_value_batch.sol => verifier_withdraw_batch.sol} (99%) rename solidity/contracts/verifiers/{verifier_check_nullifier_value.sol => verifier_withdraw_nullifier.sol} (99%) rename solidity/contracts/verifiers/{verifier_check_nullifier_value_batch.sol => verifier_withdraw_nullifier_batch.sol} (99%) rename zkp/circuits/{check_hashes_value.circom => deposit.circom} (100%) rename zkp/circuits/{check_inputs_outputs_value.circom => withdraw.circom} (100%) rename zkp/circuits/{check_inputs_outputs_value_batch.circom => withdraw_batch.circom} (100%) rename zkp/circuits/{check_nullifiers_value.circom => withdraw_nullifier.circom} (100%) rename zkp/circuits/{check_nullifiers_value_batch.circom => withdraw_nullifier_batch.circom} (100%) rename zkp/js/integration-test/{check_hashes_value.js => deposit.js} (94%) rename zkp/js/integration-test/{check_inputs_outputs_value.js => withdraw.js} (94%) rename zkp/js/integration-test/{check_nullifiers_value.js => withdraw_nullifier.js} (95%) rename zkp/js/test/{check_hashes_value.js => deposit.js} (98%) rename zkp/js/test/{check_inputs_outputs_value.js => withdraw.js} (97%) rename zkp/js/test/{check_nullifiers_value.js => withdraw_nullifier.js} (98%) diff --git a/solidity/contracts/lib/zeto_fungible.sol b/solidity/contracts/lib/zeto_fungible.sol index 8344722..ac64e38 100644 --- a/solidity/contracts/lib/zeto_fungible.sol +++ b/solidity/contracts/lib/zeto_fungible.sol @@ -15,8 +15,7 @@ // limitations under the License. pragma solidity ^0.8.27; -import {Groth16Verifier_CheckHashesValue} from "../verifiers/verifier_check_hashes_value.sol"; -import {Groth16Verifier_CheckNullifierValue} from "../verifiers/verifier_check_nullifier_value.sol"; +import {Groth16Verifier_Deposit} from "../verifiers/verifier_deposit.sol"; import {Commonlib} from "./common.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; @@ -28,14 +27,14 @@ abstract contract ZetoFungible is OwnableUpgradeable { // _depositVerifier library for checking UTXOs against a claimed value. // this can be used in the optional deposit calls to verify that // the UTXOs match the deposited value - Groth16Verifier_CheckHashesValue internal _depositVerifier; + Groth16Verifier_Deposit internal _depositVerifier; error WithdrawArrayTooLarge(uint256 maxAllowed); IERC20 internal _erc20; function __ZetoFungible_init( - Groth16Verifier_CheckHashesValue depositVerifier + Groth16Verifier_Deposit depositVerifier ) public onlyInitializing { _depositVerifier = depositVerifier; } diff --git a/solidity/contracts/lib/zeto_fungible_withdraw.sol b/solidity/contracts/lib/zeto_fungible_withdraw.sol index c757322..1ea6d6c 100644 --- a/solidity/contracts/lib/zeto_fungible_withdraw.sol +++ b/solidity/contracts/lib/zeto_fungible_withdraw.sol @@ -15,9 +15,9 @@ // limitations under the License. pragma solidity ^0.8.27; -import {Groth16Verifier_CheckHashesValue} from "../verifiers/verifier_check_hashes_value.sol"; -import {Groth16Verifier_CheckInputsOutputsValue} from "../verifiers/verifier_check_inputs_outputs_value.sol"; -import {Groth16Verifier_CheckInputsOutputsValueBatch} from "../verifiers/verifier_check_inputs_outputs_value_batch.sol"; +import {Groth16Verifier_Deposit} from "../verifiers/verifier_deposit.sol"; +import {Groth16Verifier_Withdraw} from "../verifiers/verifier_withdraw.sol"; +import {Groth16Verifier_WithdrawBatch} from "../verifiers/verifier_withdraw_batch.sol"; import {ZetoFungible} from "./zeto_fungible.sol"; import {Commonlib} from "./common.sol"; @@ -31,14 +31,13 @@ abstract contract ZetoFungibleWithdraw is ZetoFungible { // nullifierVerifier library for checking nullifiers against a claimed value. // this can be used in the optional withdraw calls to verify that the nullifiers // match the withdrawn value - Groth16Verifier_CheckInputsOutputsValue internal _withdrawVerifier; - Groth16Verifier_CheckInputsOutputsValueBatch - internal _batchWithdrawVerifier; + Groth16Verifier_Withdraw internal _withdrawVerifier; + Groth16Verifier_WithdrawBatch internal _batchWithdrawVerifier; function __ZetoFungibleWithdraw_init( - Groth16Verifier_CheckHashesValue depositVerifier, - Groth16Verifier_CheckInputsOutputsValue withdrawVerifier, - Groth16Verifier_CheckInputsOutputsValueBatch batchWithdrawVerifier + Groth16Verifier_Deposit depositVerifier, + Groth16Verifier_Withdraw withdrawVerifier, + Groth16Verifier_WithdrawBatch batchWithdrawVerifier ) public onlyInitializing { __ZetoFungible_init(depositVerifier); _withdrawVerifier = withdrawVerifier; diff --git a/solidity/contracts/lib/zeto_fungible_withdraw_nullifier.sol b/solidity/contracts/lib/zeto_fungible_withdraw_nullifier.sol index 0c010d0..5942035 100644 --- a/solidity/contracts/lib/zeto_fungible_withdraw_nullifier.sol +++ b/solidity/contracts/lib/zeto_fungible_withdraw_nullifier.sol @@ -15,9 +15,9 @@ // limitations under the License. pragma solidity ^0.8.27; -import {Groth16Verifier_CheckHashesValue} from "../verifiers/verifier_check_hashes_value.sol"; -import {Groth16Verifier_CheckNullifierValue} from "../verifiers/verifier_check_nullifier_value.sol"; -import {Groth16Verifier_CheckNullifierValueBatch} from "../verifiers/verifier_check_nullifier_value_batch.sol"; +import {Groth16Verifier_Deposit} from "../verifiers/verifier_deposit.sol"; +import {Groth16Verifier_WithdrawNullifier} from "../verifiers/verifier_withdraw_nullifier.sol"; +import {Groth16Verifier_WithdrawNullifierBatch} from "../verifiers/verifier_withdraw_nullifier_batch.sol"; import {ZetoFungible} from "./zeto_fungible.sol"; import {Commonlib} from "./common.sol"; @@ -31,13 +31,13 @@ abstract contract ZetoFungibleWithdrawWithNullifiers is ZetoFungible { // nullifierVerifier library for checking nullifiers against a claimed value. // this can be used in the optional withdraw calls to verify that the nullifiers // match the withdrawn value - Groth16Verifier_CheckNullifierValue internal _withdrawVerifier; - Groth16Verifier_CheckNullifierValueBatch internal _batchWithdrawVerifier; + Groth16Verifier_WithdrawNullifier internal _withdrawVerifier; + Groth16Verifier_WithdrawNullifierBatch internal _batchWithdrawVerifier; function __ZetoFungibleWithdrawWithNullifiers_init( - Groth16Verifier_CheckHashesValue depositVerifier, - Groth16Verifier_CheckNullifierValue withdrawVerifier, - Groth16Verifier_CheckNullifierValueBatch batchWithdrawVerifier + Groth16Verifier_Deposit depositVerifier, + Groth16Verifier_WithdrawNullifier withdrawVerifier, + Groth16Verifier_WithdrawNullifierBatch batchWithdrawVerifier ) internal onlyInitializing { __ZetoFungible_init(depositVerifier); _withdrawVerifier = withdrawVerifier; diff --git a/solidity/contracts/verifiers/verifier_check_nullifiers_value.sol b/solidity/contracts/verifiers/verifier_check_nullifiers_value.sol deleted file mode 100644 index 008685d..0000000 --- a/solidity/contracts/verifiers/verifier_check_nullifiers_value.sol +++ /dev/null @@ -1,210 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -/* - Copyright 2021 0KIMS association. - - This file is generated with [snarkJS](https://github.com/iden3/snarkjs). - - snarkJS is a free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - snarkJS is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - License for more details. - - You should have received a copy of the GNU General Public License - along with snarkJS. If not, see . -*/ - -pragma solidity >=0.7.0 <0.9.0; - -contract Groth16Verifier_CheckNullifiersValue { - // Scalar field size - uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617; - // Base field size - uint256 constant q = 21888242871839275222246405745257275088696311157297823662689037894645226208583; - - // Verification Key data - uint256 constant alphax = 20491192805390485299153009773594534940189261866228447918068658471970481763042; - uint256 constant alphay = 9383485363053290200918347156157836566562967994039712273449902621266178545958; - uint256 constant betax1 = 4252822878758300859123897981450591353533073413197771768651442665752259397132; - uint256 constant betax2 = 6375614351688725206403948262868962793625744043794305715222011528459656738731; - uint256 constant betay1 = 21847035105528745403288232691147584728191162732299865338377159692350059136679; - uint256 constant betay2 = 10505242626370262277552901082094356697409835680220590971873171140371331206856; - uint256 constant gammax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634; - uint256 constant gammax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781; - uint256 constant gammay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531; - uint256 constant gammay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930; - uint256 constant deltax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634; - uint256 constant deltax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781; - uint256 constant deltay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531; - uint256 constant deltay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930; - - - uint256 constant IC0x = 5372465145930131904181936844224539702598562677294839351793739913813002422248; - uint256 constant IC0y = 17408194426033394784509716657563038781374557284116121966988820958100327208947; - - uint256 constant IC1x = 18721682748794380402768397518142652407455353988834810677058243887163649195944; - uint256 constant IC1y = 3510524177671077561512337051711627169148530693705071780712030685548737096143; - - uint256 constant IC2x = 8122158197879371180286109309676763127376056183929764072927375068599106569793; - uint256 constant IC2y = 14069702746185228450937432180611779524058868979912356630903216371660230563795; - - uint256 constant IC3x = 12054470835972212708497793935866295196617705336672489963811855490085993758837; - uint256 constant IC3y = 3414164109693343726343912594769661343694119217245254408298451715214194698056; - - uint256 constant IC4x = 20788158480360140113733456986338078732985477544997534478761000739379167086988; - uint256 constant IC4y = 18739927009843693757028260696367700177351944363013044083149375549875761468959; - - uint256 constant IC5x = 19951574778071643021012085154476313617081511627644669051221009630908944086558; - uint256 constant IC5y = 16230451990376817064850835151093534344795062721521761792474659514233372650410; - - uint256 constant IC6x = 13177431207016748663806898438333194070079646082467860253233651704586403557256; - uint256 constant IC6y = 20902096558452622927027397347274817235993975444465062231225253027029751104905; - - uint256 constant IC7x = 16080914620084423806474567527530474918486311214600624165372750879022214015497; - uint256 constant IC7y = 11018353982179097918136151910235210507904716869524646248692012722240219927007; - - - // Memory data - uint16 constant pVk = 0; - uint16 constant pPairing = 128; - - uint16 constant pLastMem = 896; - - function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[7] calldata _pubSignals) public view returns (bool) { - assembly { - function checkField(v) { - if iszero(lt(v, r)) { - mstore(0, 0) - return(0, 0x20) - } - } - - // G1 function to multiply a G1 value(x,y) to value in an address - function g1_mulAccC(pR, x, y, s) { - let success - let mIn := mload(0x40) - mstore(mIn, x) - mstore(add(mIn, 32), y) - mstore(add(mIn, 64), s) - - success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64) - - if iszero(success) { - mstore(0, 0) - return(0, 0x20) - } - - mstore(add(mIn, 64), mload(pR)) - mstore(add(mIn, 96), mload(add(pR, 32))) - - success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64) - - if iszero(success) { - mstore(0, 0) - return(0, 0x20) - } - } - - function checkPairing(pA, pB, pC, pubSignals, pMem) -> isOk { - let _pPairing := add(pMem, pPairing) - let _pVk := add(pMem, pVk) - - mstore(_pVk, IC0x) - mstore(add(_pVk, 32), IC0y) - - // Compute the linear combination vk_x - - g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0))) - - g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32))) - - g1_mulAccC(_pVk, IC3x, IC3y, calldataload(add(pubSignals, 64))) - - g1_mulAccC(_pVk, IC4x, IC4y, calldataload(add(pubSignals, 96))) - - g1_mulAccC(_pVk, IC5x, IC5y, calldataload(add(pubSignals, 128))) - - g1_mulAccC(_pVk, IC6x, IC6y, calldataload(add(pubSignals, 160))) - - g1_mulAccC(_pVk, IC7x, IC7y, calldataload(add(pubSignals, 192))) - - - // -A - mstore(_pPairing, calldataload(pA)) - mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q)) - - // B - mstore(add(_pPairing, 64), calldataload(pB)) - mstore(add(_pPairing, 96), calldataload(add(pB, 32))) - mstore(add(_pPairing, 128), calldataload(add(pB, 64))) - mstore(add(_pPairing, 160), calldataload(add(pB, 96))) - - // alpha1 - mstore(add(_pPairing, 192), alphax) - mstore(add(_pPairing, 224), alphay) - - // beta2 - mstore(add(_pPairing, 256), betax1) - mstore(add(_pPairing, 288), betax2) - mstore(add(_pPairing, 320), betay1) - mstore(add(_pPairing, 352), betay2) - - // vk_x - mstore(add(_pPairing, 384), mload(add(pMem, pVk))) - mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32)))) - - - // gamma2 - mstore(add(_pPairing, 448), gammax1) - mstore(add(_pPairing, 480), gammax2) - mstore(add(_pPairing, 512), gammay1) - mstore(add(_pPairing, 544), gammay2) - - // C - mstore(add(_pPairing, 576), calldataload(pC)) - mstore(add(_pPairing, 608), calldataload(add(pC, 32))) - - // delta2 - mstore(add(_pPairing, 640), deltax1) - mstore(add(_pPairing, 672), deltax2) - mstore(add(_pPairing, 704), deltay1) - mstore(add(_pPairing, 736), deltay2) - - - let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20) - - isOk := and(success, mload(_pPairing)) - } - - let pMem := mload(0x40) - mstore(0x40, add(pMem, pLastMem)) - - // Validate that all evaluations ∈ F - - checkField(calldataload(add(_pubSignals, 0))) - - checkField(calldataload(add(_pubSignals, 32))) - - checkField(calldataload(add(_pubSignals, 64))) - - checkField(calldataload(add(_pubSignals, 96))) - - checkField(calldataload(add(_pubSignals, 128))) - - checkField(calldataload(add(_pubSignals, 160))) - - checkField(calldataload(add(_pubSignals, 192))) - - - // Validate all evaluations - let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem) - - mstore(0, isValid) - return(0, 0x20) - } - } - } diff --git a/solidity/contracts/verifiers/verifier_check_nullifiers_value_batch.sol b/solidity/contracts/verifiers/verifier_check_nullifiers_value_batch.sol deleted file mode 100644 index 96db7f1..0000000 --- a/solidity/contracts/verifiers/verifier_check_nullifiers_value_batch.sol +++ /dev/null @@ -1,322 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -/* - Copyright 2021 0KIMS association. - - This file is generated with [snarkJS](https://github.com/iden3/snarkjs). - - snarkJS is a free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - snarkJS is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - License for more details. - - You should have received a copy of the GNU General Public License - along with snarkJS. If not, see . -*/ - -pragma solidity >=0.7.0 <0.9.0; - -contract Groth16Verifier_CheckNullifiersValueBatch { - // Scalar field size - uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617; - // Base field size - uint256 constant q = 21888242871839275222246405745257275088696311157297823662689037894645226208583; - - // Verification Key data - uint256 constant alphax = 20491192805390485299153009773594534940189261866228447918068658471970481763042; - uint256 constant alphay = 9383485363053290200918347156157836566562967994039712273449902621266178545958; - uint256 constant betax1 = 4252822878758300859123897981450591353533073413197771768651442665752259397132; - uint256 constant betax2 = 6375614351688725206403948262868962793625744043794305715222011528459656738731; - uint256 constant betay1 = 21847035105528745403288232691147584728191162732299865338377159692350059136679; - uint256 constant betay2 = 10505242626370262277552901082094356697409835680220590971873171140371331206856; - uint256 constant gammax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634; - uint256 constant gammax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781; - uint256 constant gammay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531; - uint256 constant gammay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930; - uint256 constant deltax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634; - uint256 constant deltax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781; - uint256 constant deltay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531; - uint256 constant deltay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930; - - - uint256 constant IC0x = 17366683354852295992407143995504174653074195591417819551747878918252419851555; - uint256 constant IC0y = 19483006769124497327131823516486718544957590921235503972246996412536778649980; - - uint256 constant IC1x = 10366104846534137715500591309814118886022119944596398433735317084138833334792; - uint256 constant IC1y = 18643499405451183547036528756385786304465469271907167766660424194164058707394; - - uint256 constant IC2x = 21527677578578888285885541980444416714072945316839881166233809028918267698233; - uint256 constant IC2y = 6063324619444599539166268744543898744271662754151538561975809930969069774378; - - uint256 constant IC3x = 5659430035828023753430174422783281723178462397264403842527625530517452189999; - uint256 constant IC3y = 2524917828174102567027356560699115590340023663960388221257861988015650700591; - - uint256 constant IC4x = 7238189621429832667411485007166185860893028785898240074557092538061430786966; - uint256 constant IC4y = 20390153919215256777155824947030000580196832273416110104565624202061427202468; - - uint256 constant IC5x = 15894469854222667910812295936601612004318640816386618401404798091678758027724; - uint256 constant IC5y = 14356168113450460554678860751069980826494953509135368818216408384111747891420; - - uint256 constant IC6x = 3942663716298823998869531263141686282324249719050386829948592397432348708056; - uint256 constant IC6y = 3035466022559911517709445948547486025175916218731187151424634579526798275616; - - uint256 constant IC7x = 1553309902541816224998744612658270612542776491552112107717121674403292493359; - uint256 constant IC7y = 11180635816568547989345458896877617901909650248852843301038895683628956771263; - - uint256 constant IC8x = 3701018914736177770292204885016878725979532325238333503986400101377864703276; - uint256 constant IC8y = 19833990420531737080526472786919541772537650521778260464568233706284118513049; - - uint256 constant IC9x = 12025524461625658475137301154601859231184602771266597356005073433551998537077; - uint256 constant IC9y = 1456393002982685462391054585518332799475085362766843390052131361397104224000; - - uint256 constant IC10x = 16807793107311666302190473961042321317453287634331068595488371659019485509298; - uint256 constant IC10y = 18660554898013959088019910686200094855986079232329695676414858332384484100222; - - uint256 constant IC11x = 9789863392723531300259587179323466696537747572630489833683814294587664776868; - uint256 constant IC11y = 4021843822169944439345128570575352294119541799048090956488246619674844965472; - - uint256 constant IC12x = 10214507374407129083284926029820451365753765776330479881523358522180753325104; - uint256 constant IC12y = 6174874849309167082617299735152158687361915126002906606614371830494266455367; - - uint256 constant IC13x = 10940606823101131233309979818887945079384613067709355569336590477206410424368; - uint256 constant IC13y = 1529208575010684508442716482754348867936757320711258330891648162641538044536; - - uint256 constant IC14x = 10087732249910916073426006557040806210935045993195380389004671191499603659207; - uint256 constant IC14y = 7443393664317545329254912123081736912386566669005719193913868247214148583503; - - uint256 constant IC15x = 16404969434890860611574834353483070312895732476387812161187868979316241878917; - uint256 constant IC15y = 19676747737804121937999539792895793757453717532009730518885557633073507270372; - - uint256 constant IC16x = 11130436916472796659130880446782841087239080661463103611590285506562232306164; - uint256 constant IC16y = 13396283331421200879055216177372556296918660983129101109962712961278727949285; - - uint256 constant IC17x = 18218360746339548031724109374686253420716818661174497636632005644706100544635; - uint256 constant IC17y = 21172625106199967128593353246092551188199701584176729699213074514231209994675; - - uint256 constant IC18x = 19758930414401357761821077915160309020962693098586679596228991300362584487736; - uint256 constant IC18y = 13569184175490052261123892597281797139167978224682715950489992695657542966533; - - uint256 constant IC19x = 13280061894247793894958942691701119684528737183396784669637060695805643386178; - uint256 constant IC19y = 13473180960238185615076221510950965535376963989105989970070499050578446283305; - - uint256 constant IC20x = 1883062788684859331882578642430274233076862028256499324766210198222044285374; - uint256 constant IC20y = 21175110562847535813966290632423195949054616850607561678958250643497836918190; - - uint256 constant IC21x = 12895836754941507779121370416231719346694197724945981683615558906276745887603; - uint256 constant IC21y = 6646006890301769910107555005644233902910512644919054229046263085688091816853; - - uint256 constant IC22x = 17308914241678938030422526322338288734470378999652358159021166607108962704968; - uint256 constant IC22y = 18406851446505143717056856075557317602320041669211343434213146566599365910852; - - uint256 constant IC23x = 7080930845263346356578029481773118223285460683970543357645916770136148160025; - uint256 constant IC23y = 1811823263315974161935966519923924161086093162314533117675697138869841933466; - - - // Memory data - uint16 constant pVk = 0; - uint16 constant pPairing = 128; - - uint16 constant pLastMem = 896; - - function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[23] calldata _pubSignals) public view returns (bool) { - assembly { - function checkField(v) { - if iszero(lt(v, r)) { - mstore(0, 0) - return(0, 0x20) - } - } - - // G1 function to multiply a G1 value(x,y) to value in an address - function g1_mulAccC(pR, x, y, s) { - let success - let mIn := mload(0x40) - mstore(mIn, x) - mstore(add(mIn, 32), y) - mstore(add(mIn, 64), s) - - success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64) - - if iszero(success) { - mstore(0, 0) - return(0, 0x20) - } - - mstore(add(mIn, 64), mload(pR)) - mstore(add(mIn, 96), mload(add(pR, 32))) - - success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64) - - if iszero(success) { - mstore(0, 0) - return(0, 0x20) - } - } - - function checkPairing(pA, pB, pC, pubSignals, pMem) -> isOk { - let _pPairing := add(pMem, pPairing) - let _pVk := add(pMem, pVk) - - mstore(_pVk, IC0x) - mstore(add(_pVk, 32), IC0y) - - // Compute the linear combination vk_x - - g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0))) - - g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32))) - - g1_mulAccC(_pVk, IC3x, IC3y, calldataload(add(pubSignals, 64))) - - g1_mulAccC(_pVk, IC4x, IC4y, calldataload(add(pubSignals, 96))) - - g1_mulAccC(_pVk, IC5x, IC5y, calldataload(add(pubSignals, 128))) - - g1_mulAccC(_pVk, IC6x, IC6y, calldataload(add(pubSignals, 160))) - - g1_mulAccC(_pVk, IC7x, IC7y, calldataload(add(pubSignals, 192))) - - g1_mulAccC(_pVk, IC8x, IC8y, calldataload(add(pubSignals, 224))) - - g1_mulAccC(_pVk, IC9x, IC9y, calldataload(add(pubSignals, 256))) - - g1_mulAccC(_pVk, IC10x, IC10y, calldataload(add(pubSignals, 288))) - - g1_mulAccC(_pVk, IC11x, IC11y, calldataload(add(pubSignals, 320))) - - g1_mulAccC(_pVk, IC12x, IC12y, calldataload(add(pubSignals, 352))) - - g1_mulAccC(_pVk, IC13x, IC13y, calldataload(add(pubSignals, 384))) - - g1_mulAccC(_pVk, IC14x, IC14y, calldataload(add(pubSignals, 416))) - - g1_mulAccC(_pVk, IC15x, IC15y, calldataload(add(pubSignals, 448))) - - g1_mulAccC(_pVk, IC16x, IC16y, calldataload(add(pubSignals, 480))) - - g1_mulAccC(_pVk, IC17x, IC17y, calldataload(add(pubSignals, 512))) - - g1_mulAccC(_pVk, IC18x, IC18y, calldataload(add(pubSignals, 544))) - - g1_mulAccC(_pVk, IC19x, IC19y, calldataload(add(pubSignals, 576))) - - g1_mulAccC(_pVk, IC20x, IC20y, calldataload(add(pubSignals, 608))) - - g1_mulAccC(_pVk, IC21x, IC21y, calldataload(add(pubSignals, 640))) - - g1_mulAccC(_pVk, IC22x, IC22y, calldataload(add(pubSignals, 672))) - - g1_mulAccC(_pVk, IC23x, IC23y, calldataload(add(pubSignals, 704))) - - - // -A - mstore(_pPairing, calldataload(pA)) - mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q)) - - // B - mstore(add(_pPairing, 64), calldataload(pB)) - mstore(add(_pPairing, 96), calldataload(add(pB, 32))) - mstore(add(_pPairing, 128), calldataload(add(pB, 64))) - mstore(add(_pPairing, 160), calldataload(add(pB, 96))) - - // alpha1 - mstore(add(_pPairing, 192), alphax) - mstore(add(_pPairing, 224), alphay) - - // beta2 - mstore(add(_pPairing, 256), betax1) - mstore(add(_pPairing, 288), betax2) - mstore(add(_pPairing, 320), betay1) - mstore(add(_pPairing, 352), betay2) - - // vk_x - mstore(add(_pPairing, 384), mload(add(pMem, pVk))) - mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32)))) - - - // gamma2 - mstore(add(_pPairing, 448), gammax1) - mstore(add(_pPairing, 480), gammax2) - mstore(add(_pPairing, 512), gammay1) - mstore(add(_pPairing, 544), gammay2) - - // C - mstore(add(_pPairing, 576), calldataload(pC)) - mstore(add(_pPairing, 608), calldataload(add(pC, 32))) - - // delta2 - mstore(add(_pPairing, 640), deltax1) - mstore(add(_pPairing, 672), deltax2) - mstore(add(_pPairing, 704), deltay1) - mstore(add(_pPairing, 736), deltay2) - - - let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20) - - isOk := and(success, mload(_pPairing)) - } - - let pMem := mload(0x40) - mstore(0x40, add(pMem, pLastMem)) - - // Validate that all evaluations ∈ F - - checkField(calldataload(add(_pubSignals, 0))) - - checkField(calldataload(add(_pubSignals, 32))) - - checkField(calldataload(add(_pubSignals, 64))) - - checkField(calldataload(add(_pubSignals, 96))) - - checkField(calldataload(add(_pubSignals, 128))) - - checkField(calldataload(add(_pubSignals, 160))) - - checkField(calldataload(add(_pubSignals, 192))) - - checkField(calldataload(add(_pubSignals, 224))) - - checkField(calldataload(add(_pubSignals, 256))) - - checkField(calldataload(add(_pubSignals, 288))) - - checkField(calldataload(add(_pubSignals, 320))) - - checkField(calldataload(add(_pubSignals, 352))) - - checkField(calldataload(add(_pubSignals, 384))) - - checkField(calldataload(add(_pubSignals, 416))) - - checkField(calldataload(add(_pubSignals, 448))) - - checkField(calldataload(add(_pubSignals, 480))) - - checkField(calldataload(add(_pubSignals, 512))) - - checkField(calldataload(add(_pubSignals, 544))) - - checkField(calldataload(add(_pubSignals, 576))) - - checkField(calldataload(add(_pubSignals, 608))) - - checkField(calldataload(add(_pubSignals, 640))) - - checkField(calldataload(add(_pubSignals, 672))) - - checkField(calldataload(add(_pubSignals, 704))) - - - // Validate all evaluations - let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem) - - mstore(0, isValid) - return(0, 0x20) - } - } - } diff --git a/solidity/contracts/verifiers/verifier_check_hashes_value.sol b/solidity/contracts/verifiers/verifier_deposit.sol similarity index 99% rename from solidity/contracts/verifiers/verifier_check_hashes_value.sol rename to solidity/contracts/verifiers/verifier_deposit.sol index 8cd834a..29f9c41 100644 --- a/solidity/contracts/verifiers/verifier_check_hashes_value.sol +++ b/solidity/contracts/verifiers/verifier_deposit.sol @@ -20,7 +20,7 @@ pragma solidity >=0.7.0 <0.9.0; -contract Groth16Verifier_CheckHashesValue { +contract Groth16Verifier_Deposit { // Scalar field size uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617; // Base field size diff --git a/solidity/contracts/verifiers/verifier_check_inputs_outputs_value.sol b/solidity/contracts/verifiers/verifier_withdraw.sol similarity index 99% rename from solidity/contracts/verifiers/verifier_check_inputs_outputs_value.sol rename to solidity/contracts/verifiers/verifier_withdraw.sol index 26a2246..5a43a30 100644 --- a/solidity/contracts/verifiers/verifier_check_inputs_outputs_value.sol +++ b/solidity/contracts/verifiers/verifier_withdraw.sol @@ -20,7 +20,7 @@ pragma solidity >=0.7.0 <0.9.0; -contract Groth16Verifier_CheckInputsOutputsValue { +contract Groth16Verifier_Withdraw { // Scalar field size uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617; // Base field size diff --git a/solidity/contracts/verifiers/verifier_check_inputs_outputs_value_batch.sol b/solidity/contracts/verifiers/verifier_withdraw_batch.sol similarity index 99% rename from solidity/contracts/verifiers/verifier_check_inputs_outputs_value_batch.sol rename to solidity/contracts/verifiers/verifier_withdraw_batch.sol index 27c1450..a73c12c 100644 --- a/solidity/contracts/verifiers/verifier_check_inputs_outputs_value_batch.sol +++ b/solidity/contracts/verifiers/verifier_withdraw_batch.sol @@ -20,7 +20,7 @@ pragma solidity >=0.7.0 <0.9.0; -contract Groth16Verifier_CheckInputsOutputsValueBatch { +contract Groth16Verifier_WithdrawBatch { // Scalar field size uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617; // Base field size diff --git a/solidity/contracts/verifiers/verifier_check_nullifier_value.sol b/solidity/contracts/verifiers/verifier_withdraw_nullifier.sol similarity index 99% rename from solidity/contracts/verifiers/verifier_check_nullifier_value.sol rename to solidity/contracts/verifiers/verifier_withdraw_nullifier.sol index e8cf64d..6ea30a8 100644 --- a/solidity/contracts/verifiers/verifier_check_nullifier_value.sol +++ b/solidity/contracts/verifiers/verifier_withdraw_nullifier.sol @@ -20,7 +20,7 @@ pragma solidity >=0.7.0 <0.9.0; -contract Groth16Verifier_CheckNullifierValue { +contract Groth16Verifier_WithdrawNullifier { // Scalar field size uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617; // Base field size diff --git a/solidity/contracts/verifiers/verifier_check_nullifier_value_batch.sol b/solidity/contracts/verifiers/verifier_withdraw_nullifier_batch.sol similarity index 99% rename from solidity/contracts/verifiers/verifier_check_nullifier_value_batch.sol rename to solidity/contracts/verifiers/verifier_withdraw_nullifier_batch.sol index 3d60365..831960c 100644 --- a/solidity/contracts/verifiers/verifier_check_nullifier_value_batch.sol +++ b/solidity/contracts/verifiers/verifier_withdraw_nullifier_batch.sol @@ -20,7 +20,7 @@ pragma solidity >=0.7.0 <0.9.0; -contract Groth16Verifier_CheckNullifierValueBatch { +contract Groth16Verifier_WithdrawNullifierBatch { // Scalar field size uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617; // Base field size diff --git a/solidity/contracts/zeto_anon.sol b/solidity/contracts/zeto_anon.sol index 8d5442f..0ba3a3e 100644 --- a/solidity/contracts/zeto_anon.sol +++ b/solidity/contracts/zeto_anon.sol @@ -16,9 +16,9 @@ pragma solidity ^0.8.27; import {IZeto} from "./lib/interfaces/izeto.sol"; -import {Groth16Verifier_CheckHashesValue} from "./verifiers/verifier_check_hashes_value.sol"; -import {Groth16Verifier_CheckInputsOutputsValue} from "./verifiers/verifier_check_inputs_outputs_value.sol"; -import {Groth16Verifier_CheckInputsOutputsValueBatch} from "./verifiers/verifier_check_inputs_outputs_value_batch.sol"; +import {Groth16Verifier_Deposit} from "./verifiers/verifier_deposit.sol"; +import {Groth16Verifier_Withdraw} from "./verifiers/verifier_withdraw.sol"; +import {Groth16Verifier_WithdrawBatch} from "./verifiers/verifier_withdraw_batch.sol"; import {Groth16Verifier_Anon} from "./verifiers/verifier_anon.sol"; import {Groth16Verifier_AnonBatch} from "./verifiers/verifier_anon_batch.sol"; import {Commonlib} from "./lib/common.sol"; @@ -53,13 +53,9 @@ contract Zeto_Anon is ) public initializer { __ZetoBase_init(initialOwner); __ZetoFungibleWithdraw_init( - (Groth16Verifier_CheckHashesValue)(verifiers.depositVerifier), - (Groth16Verifier_CheckInputsOutputsValue)( - verifiers.withdrawVerifier - ), - (Groth16Verifier_CheckInputsOutputsValueBatch)( - verifiers.batchWithdrawVerifier - ) + (Groth16Verifier_Deposit)(verifiers.depositVerifier), + (Groth16Verifier_Withdraw)(verifiers.withdrawVerifier), + (Groth16Verifier_WithdrawBatch)(verifiers.batchWithdrawVerifier) ); _verifier = (Groth16Verifier_Anon)(verifiers.verifier); _batchVerifier = (Groth16Verifier_AnonBatch)(verifiers.batchVerifier); diff --git a/solidity/contracts/zeto_anon_enc.sol b/solidity/contracts/zeto_anon_enc.sol index 9f9fe34..2f5e255 100644 --- a/solidity/contracts/zeto_anon_enc.sol +++ b/solidity/contracts/zeto_anon_enc.sol @@ -16,9 +16,9 @@ pragma solidity ^0.8.27; import {IZeto} from "./lib/interfaces/izeto.sol"; -import {Groth16Verifier_CheckHashesValue} from "./verifiers/verifier_check_hashes_value.sol"; -import {Groth16Verifier_CheckInputsOutputsValue} from "./verifiers/verifier_check_inputs_outputs_value.sol"; -import {Groth16Verifier_CheckInputsOutputsValueBatch} from "./verifiers/verifier_check_inputs_outputs_value_batch.sol"; +import {Groth16Verifier_Deposit} from "./verifiers/verifier_deposit.sol"; +import {Groth16Verifier_Withdraw} from "./verifiers/verifier_withdraw.sol"; +import {Groth16Verifier_WithdrawBatch} from "./verifiers/verifier_withdraw_batch.sol"; import {Groth16Verifier_AnonEnc} from "./verifiers/verifier_anon_enc.sol"; import {Groth16Verifier_AnonEncBatch} from "./verifiers/verifier_anon_enc_batch.sol"; import {ZetoFungibleWithdraw} from "./lib/zeto_fungible_withdraw.sol"; @@ -55,13 +55,9 @@ contract Zeto_AnonEnc is ) public initializer { __ZetoBase_init(initialOwner); __ZetoFungibleWithdraw_init( - (Groth16Verifier_CheckHashesValue)(verifiers.depositVerifier), - (Groth16Verifier_CheckInputsOutputsValue)( - verifiers.withdrawVerifier - ), - (Groth16Verifier_CheckInputsOutputsValueBatch)( - verifiers.batchWithdrawVerifier - ) + (Groth16Verifier_Deposit)(verifiers.depositVerifier), + (Groth16Verifier_Withdraw)(verifiers.withdrawVerifier), + (Groth16Verifier_WithdrawBatch)(verifiers.batchWithdrawVerifier) ); _verifier = (Groth16Verifier_AnonEnc)(verifiers.verifier); _batchVerifier = (Groth16Verifier_AnonEncBatch)( diff --git a/solidity/contracts/zeto_anon_enc_nullifier.sol b/solidity/contracts/zeto_anon_enc_nullifier.sol index ca5b145..7de53de 100644 --- a/solidity/contracts/zeto_anon_enc_nullifier.sol +++ b/solidity/contracts/zeto_anon_enc_nullifier.sol @@ -16,9 +16,9 @@ pragma solidity ^0.8.27; import {IZeto} from "./lib/interfaces/izeto.sol"; -import {Groth16Verifier_CheckHashesValue} from "./verifiers/verifier_check_hashes_value.sol"; -import {Groth16Verifier_CheckNullifierValue} from "./verifiers/verifier_check_nullifier_value.sol"; -import {Groth16Verifier_CheckNullifierValueBatch} from "./verifiers/verifier_check_nullifier_value_batch.sol"; +import {Groth16Verifier_Deposit} from "./verifiers/verifier_deposit.sol"; +import {Groth16Verifier_WithdrawNullifier} from "./verifiers/verifier_withdraw_nullifier.sol"; +import {Groth16Verifier_WithdrawNullifierBatch} from "./verifiers/verifier_withdraw_nullifier_batch.sol"; import {Groth16Verifier_AnonEncNullifier} from "./verifiers/verifier_anon_enc_nullifier.sol"; import {Groth16Verifier_AnonEncNullifierBatch} from "./verifiers/verifier_anon_enc_nullifier_batch.sol"; import {ZetoNullifier} from "./lib/zeto_nullifier.sol"; @@ -55,9 +55,9 @@ contract Zeto_AnonEncNullifier is ) public initializer { __ZetoNullifier_init(initialOwner); __ZetoFungibleWithdrawWithNullifiers_init( - (Groth16Verifier_CheckHashesValue)(verifiers.depositVerifier), - (Groth16Verifier_CheckNullifierValue)(verifiers.withdrawVerifier), - (Groth16Verifier_CheckNullifierValueBatch)( + (Groth16Verifier_Deposit)(verifiers.depositVerifier), + (Groth16Verifier_WithdrawNullifier)(verifiers.withdrawVerifier), + (Groth16Verifier_WithdrawNullifierBatch)( verifiers.batchWithdrawVerifier ) ); diff --git a/solidity/contracts/zeto_anon_enc_nullifier_kyc.sol b/solidity/contracts/zeto_anon_enc_nullifier_kyc.sol index 0cee396..4db51de 100644 --- a/solidity/contracts/zeto_anon_enc_nullifier_kyc.sol +++ b/solidity/contracts/zeto_anon_enc_nullifier_kyc.sol @@ -16,9 +16,9 @@ pragma solidity ^0.8.27; import {IZeto} from "./lib/interfaces/izeto.sol"; -import {Groth16Verifier_CheckHashesValue} from "./verifiers/verifier_check_hashes_value.sol"; -import {Groth16Verifier_CheckNullifierValue} from "./verifiers/verifier_check_nullifier_value.sol"; -import {Groth16Verifier_CheckNullifierValueBatch} from "./verifiers/verifier_check_nullifier_value_batch.sol"; +import {Groth16Verifier_Deposit} from "./verifiers/verifier_deposit.sol"; +import {Groth16Verifier_WithdrawNullifier} from "./verifiers/verifier_withdraw_nullifier.sol"; +import {Groth16Verifier_WithdrawNullifierBatch} from "./verifiers/verifier_withdraw_nullifier_batch.sol"; import {Groth16Verifier_AnonEncNullifierKyc} from "./verifiers/verifier_anon_enc_nullifier_kyc.sol"; import {Groth16Verifier_AnonEncNullifierKycBatch} from "./verifiers/verifier_anon_enc_nullifier_kyc_batch.sol"; import {ZetoNullifier} from "./lib/zeto_nullifier.sol"; @@ -58,9 +58,9 @@ contract Zeto_AnonEncNullifierKyc is __Registry_init(); __ZetoNullifier_init(initialOwner); __ZetoFungibleWithdrawWithNullifiers_init( - (Groth16Verifier_CheckHashesValue)(verifiers.depositVerifier), - (Groth16Verifier_CheckNullifierValue)(verifiers.withdrawVerifier), - (Groth16Verifier_CheckNullifierValueBatch)( + (Groth16Verifier_Deposit)(verifiers.depositVerifier), + (Groth16Verifier_WithdrawNullifier)(verifiers.withdrawVerifier), + (Groth16Verifier_WithdrawNullifierBatch)( verifiers.batchWithdrawVerifier ) ); diff --git a/solidity/contracts/zeto_anon_enc_nullifier_non_repudiation.sol b/solidity/contracts/zeto_anon_enc_nullifier_non_repudiation.sol index 0121895..f15536e 100644 --- a/solidity/contracts/zeto_anon_enc_nullifier_non_repudiation.sol +++ b/solidity/contracts/zeto_anon_enc_nullifier_non_repudiation.sol @@ -16,9 +16,9 @@ pragma solidity ^0.8.27; import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; -import {Groth16Verifier_CheckHashesValue} from "./verifiers/verifier_check_hashes_value.sol"; -import {Groth16Verifier_CheckNullifierValue} from "./verifiers/verifier_check_nullifier_value.sol"; -import {Groth16Verifier_CheckNullifierValueBatch} from "./verifiers/verifier_check_nullifier_value_batch.sol"; +import {Groth16Verifier_Deposit} from "./verifiers/verifier_deposit.sol"; +import {Groth16Verifier_WithdrawNullifier} from "./verifiers/verifier_withdraw_nullifier.sol"; +import {Groth16Verifier_WithdrawNullifierBatch} from "./verifiers/verifier_withdraw_nullifier_batch.sol"; import {Groth16Verifier_AnonEncNullifierNonRepudiation} from "./verifiers/verifier_anon_enc_nullifier_non_repudiation.sol"; import {Groth16Verifier_AnonEncNullifierNonRepudiationBatch} from "./verifiers/verifier_anon_enc_nullifier_non_repudiation_batch.sol"; import {ZetoNullifier} from "./lib/zeto_nullifier.sol"; @@ -67,9 +67,9 @@ contract Zeto_AnonEncNullifierNonRepudiation is ) public initializer { __ZetoNullifier_init(initialOwner); __ZetoFungibleWithdrawWithNullifiers_init( - (Groth16Verifier_CheckHashesValue)(verifiers.depositVerifier), - (Groth16Verifier_CheckNullifierValue)(verifiers.withdrawVerifier), - (Groth16Verifier_CheckNullifierValueBatch)( + (Groth16Verifier_Deposit)(verifiers.depositVerifier), + (Groth16Verifier_WithdrawNullifier)(verifiers.withdrawVerifier), + (Groth16Verifier_WithdrawNullifierBatch)( verifiers.batchWithdrawVerifier ) ); diff --git a/solidity/contracts/zeto_anon_nullifier.sol b/solidity/contracts/zeto_anon_nullifier.sol index ea45954..f832a24 100644 --- a/solidity/contracts/zeto_anon_nullifier.sol +++ b/solidity/contracts/zeto_anon_nullifier.sol @@ -17,9 +17,9 @@ pragma solidity ^0.8.27; import {IZeto} from "./lib/interfaces/izeto.sol"; import {MAX_BATCH} from "./lib/interfaces/izeto.sol"; -import {Groth16Verifier_CheckHashesValue} from "./verifiers/verifier_check_hashes_value.sol"; -import {Groth16Verifier_CheckNullifierValue} from "./verifiers/verifier_check_nullifier_value.sol"; -import {Groth16Verifier_CheckNullifierValueBatch} from "./verifiers/verifier_check_nullifier_value_batch.sol"; +import {Groth16Verifier_Deposit} from "./verifiers/verifier_deposit.sol"; +import {Groth16Verifier_WithdrawNullifier} from "./verifiers/verifier_withdraw_nullifier.sol"; +import {Groth16Verifier_WithdrawNullifierBatch} from "./verifiers/verifier_withdraw_nullifier_batch.sol"; import {Groth16Verifier_AnonNullifierTransfer} from "./verifiers/verifier_anon_nullifier_transfer.sol"; import {Groth16Verifier_AnonNullifierTransferLocked} from "./verifiers/verifier_anon_nullifier_transferLocked.sol"; import {Groth16Verifier_AnonNullifierTransferBatch} from "./verifiers/verifier_anon_nullifier_transfer_batch.sol"; @@ -63,9 +63,9 @@ contract Zeto_AnonNullifier is ) public initializer { __ZetoNullifier_init(initialOwner); __ZetoFungibleWithdrawWithNullifiers_init( - (Groth16Verifier_CheckHashesValue)(verifiers.depositVerifier), - (Groth16Verifier_CheckNullifierValue)(verifiers.withdrawVerifier), - (Groth16Verifier_CheckNullifierValueBatch)( + (Groth16Verifier_Deposit)(verifiers.depositVerifier), + (Groth16Verifier_WithdrawNullifier)(verifiers.withdrawVerifier), + (Groth16Verifier_WithdrawNullifierBatch)( verifiers.batchWithdrawVerifier ) ); diff --git a/solidity/contracts/zeto_anon_nullifier_kyc.sol b/solidity/contracts/zeto_anon_nullifier_kyc.sol index 7132ae2..e6733e1 100644 --- a/solidity/contracts/zeto_anon_nullifier_kyc.sol +++ b/solidity/contracts/zeto_anon_nullifier_kyc.sol @@ -16,9 +16,9 @@ pragma solidity ^0.8.27; import {IZeto} from "./lib/interfaces/izeto.sol"; -import {Groth16Verifier_CheckHashesValue} from "./verifiers/verifier_check_hashes_value.sol"; -import {Groth16Verifier_CheckNullifierValue} from "./verifiers/verifier_check_nullifier_value.sol"; -import {Groth16Verifier_CheckNullifierValueBatch} from "./verifiers/verifier_check_nullifier_value_batch.sol"; +import {Groth16Verifier_Deposit} from "./verifiers/verifier_deposit.sol"; +import {Groth16Verifier_WithdrawNullifier} from "./verifiers/verifier_withdraw_nullifier.sol"; +import {Groth16Verifier_WithdrawNullifierBatch} from "./verifiers/verifier_withdraw_nullifier_batch.sol"; import {Groth16Verifier_AnonNullifierKyc} from "./verifiers/verifier_anon_nullifier_kyc.sol"; import {Groth16Verifier_AnonNullifierKycBatch} from "./verifiers/verifier_anon_nullifier_kyc_batch.sol"; import {ZetoNullifier} from "./lib/zeto_nullifier.sol"; @@ -57,9 +57,9 @@ contract Zeto_AnonNullifierKyc is __Registry_init(); __ZetoNullifier_init(initialOwner); __ZetoFungibleWithdrawWithNullifiers_init( - (Groth16Verifier_CheckHashesValue)(verifiers.depositVerifier), - (Groth16Verifier_CheckNullifierValue)(verifiers.withdrawVerifier), - (Groth16Verifier_CheckNullifierValueBatch)( + (Groth16Verifier_Deposit)(verifiers.depositVerifier), + (Groth16Verifier_WithdrawNullifier)(verifiers.withdrawVerifier), + (Groth16Verifier_WithdrawNullifierBatch)( verifiers.batchWithdrawVerifier ) ); diff --git a/solidity/ignition/modules/lib/deps.ts b/solidity/ignition/modules/lib/deps.ts index 71df1eb..2add0bb 100644 --- a/solidity/ignition/modules/lib/deps.ts +++ b/solidity/ignition/modules/lib/deps.ts @@ -31,40 +31,40 @@ export const SmtLibModule = buildModule("SmtLib", (m) => { }); export const DepositVerifierModule = buildModule( - "Groth16Verifier_CheckHashesValue", + "Groth16Verifier_Deposit", (m) => { - const verifier = m.contract("Groth16Verifier_CheckHashesValue", []); + const verifier = m.contract("Groth16Verifier_Deposit", []); return { verifier }; }, ); export const WithdrawNullifierVerifierModule = buildModule( - "Groth16Verifier_CheckNullifierValue", + "Groth16Verifier_WithdrawNullifier", (m) => { - const verifier = m.contract("Groth16Verifier_CheckNullifierValue", []); + const verifier = m.contract("Groth16Verifier_WithdrawNullifier", []); return { verifier }; }, ); export const BatchWithdrawNullifierVerifierModule = buildModule( - "Groth16Verifier_CheckNullifierValueBatch", + "Groth16Verifier_WithdrawNullifierBatch", (m) => { - const verifier = m.contract("Groth16Verifier_CheckNullifierValueBatch", []); + const verifier = m.contract("Groth16Verifier_WithdrawNullifierBatch", []); return { verifier }; }, ); export const WithdrawVerifierModule = buildModule( - "Groth16Verifier_CheckInputsOutputsValue", + "Groth16Verifier_Withdraw", (m) => { - const verifier = m.contract("Groth16Verifier_CheckInputsOutputsValue", []); + const verifier = m.contract("Groth16Verifier_Withdraw", []); return { verifier }; }, ); export const BatchWithdrawVerifierModule = buildModule( - "Groth16Verifier_CheckInputsOutputsValueBatch", + "Groth16Verifier_WithdrawBatch", (m) => { const verifier = m.contract( - "Groth16Verifier_CheckInputsOutputsValueBatch", + "Groth16Verifier_WithdrawBatch", [], ); return { verifier }; diff --git a/solidity/test/utils.ts b/solidity/test/utils.ts index 9430935..2101ada 100644 --- a/solidity/test/utils.ts +++ b/solidity/test/utils.ts @@ -67,8 +67,8 @@ export async function prepareDepositProof(signer: User, outputs: [UTXO, UTXO]) { outputOwnerPublicKeys, }; - const circuit = await loadCircuit("check_hashes_value"); - const { provingKeyFile } = loadProvingKeys("check_hashes_value"); + const circuit = await loadCircuit("deposit"); + const { provingKeyFile } = loadProvingKeys("deposit"); const startWitnessCalculation = Date.now(); const witness = await circuit.calculateWTNSBin(inputObj, true); @@ -128,11 +128,11 @@ export async function prepareNullifierWithdrawProof( outputSalts: [output.salt || 0n], outputOwnerPublicKeys, }; - let circuit = await loadCircuit("check_nullifiers_value"); - let { provingKeyFile } = loadProvingKeys("check_nullifiers_value"); + let circuit = await loadCircuit("withdraw_nullifier"); + let { provingKeyFile } = loadProvingKeys("withdraw_nullifier"); if (inputCommitments.length > 2) { - circuit = await loadCircuit("check_nullifiers_value_batch"); - ({ provingKeyFile } = loadProvingKeys("check_nullifiers_value_batch")); + circuit = await loadCircuit("withdraw_nullifier_batch"); + ({ provingKeyFile } = loadProvingKeys("withdraw_nullifier_batch")); } const startWitnessCalculation = Date.now(); @@ -185,11 +185,11 @@ export async function prepareWithdrawProof( outputOwnerPublicKeys, }; - let circuit = await loadCircuit("check_inputs_outputs_value"); - let { provingKeyFile } = loadProvingKeys("check_inputs_outputs_value"); + let circuit = await loadCircuit("withdraw"); + let { provingKeyFile } = loadProvingKeys("withdraw"); if (inputCommitments.length > 2) { - circuit = await loadCircuit("check_inputs_outputs_value_batch"); - ({ provingKeyFile } = loadProvingKeys("check_inputs_outputs_value_batch")); + circuit = await loadCircuit("withdraw_batch"); + ({ provingKeyFile } = loadProvingKeys("withdraw_batch")); } const startWitnessCalculation = Date.now(); diff --git a/zkp/circuits/check_hashes_value.circom b/zkp/circuits/deposit.circom similarity index 100% rename from zkp/circuits/check_hashes_value.circom rename to zkp/circuits/deposit.circom diff --git a/zkp/circuits/gen-config.json b/zkp/circuits/gen-config.json index b0f0f44..be08899 100644 --- a/zkp/circuits/gen-config.json +++ b/zkp/circuits/gen-config.json @@ -53,16 +53,16 @@ "ptau": "powersOfTau28_hez_final_16", "skipSolidityGenaration": false }, - "check_hashes_value": { + "deposit": { "ptau": "powersOfTau28_hez_final_11", "skipSolidityGenaration": false }, - "check_inputs_outputs_value": { + "withdraw": { "ptau": "powersOfTau28_hez_final_13", "batchPtau": "powersOfTau28_hez_final_14", "skipSolidityGenaration": false }, - "check_nullifiers_value": { + "withdraw_nullifier": { "ptau": "powersOfTau28_hez_final_17", "batchPtau": "powersOfTau28_hez_final_19", "skipSolidityGenaration": false diff --git a/zkp/circuits/check_inputs_outputs_value.circom b/zkp/circuits/withdraw.circom similarity index 100% rename from zkp/circuits/check_inputs_outputs_value.circom rename to zkp/circuits/withdraw.circom diff --git a/zkp/circuits/check_inputs_outputs_value_batch.circom b/zkp/circuits/withdraw_batch.circom similarity index 100% rename from zkp/circuits/check_inputs_outputs_value_batch.circom rename to zkp/circuits/withdraw_batch.circom diff --git a/zkp/circuits/check_nullifiers_value.circom b/zkp/circuits/withdraw_nullifier.circom similarity index 100% rename from zkp/circuits/check_nullifiers_value.circom rename to zkp/circuits/withdraw_nullifier.circom diff --git a/zkp/circuits/check_nullifiers_value_batch.circom b/zkp/circuits/withdraw_nullifier_batch.circom similarity index 100% rename from zkp/circuits/check_nullifiers_value_batch.circom rename to zkp/circuits/withdraw_nullifier_batch.circom diff --git a/zkp/js/integration-test/check_hashes_value.js b/zkp/js/integration-test/deposit.js similarity index 94% rename from zkp/js/integration-test/check_hashes_value.js rename to zkp/js/integration-test/deposit.js index f16a3f0..6c4d531 100644 --- a/zkp/js/integration-test/check_hashes_value.js +++ b/zkp/js/integration-test/deposit.js @@ -22,11 +22,11 @@ const { loadProvingKeys } = require("./utils.js"); const poseidonHash = Poseidon.poseidon4; -describe("check-hashes-value circuit tests", () => { +describe("deposit circuit tests", () => { let circuit; const sender = {}; before(async () => { - circuit = await loadCircuit("check_hashes_value"); + circuit = await loadCircuit("deposit"); let keypair = genKeypair(); sender.privKey = keypair.privKey; sender.pubKey = keypair.pubKey; @@ -70,8 +70,7 @@ describe("check-hashes-value circuit tests", () => { }, true, ); - const { provingKeyFile, verificationKey } = - loadProvingKeys("check_hashes_value"); + const { provingKeyFile, verificationKey } = loadProvingKeys("deposit"); const startTime = Date.now(); const { proof, publicSignals } = await groth16.prove( provingKeyFile, diff --git a/zkp/js/integration-test/nf_anon_nullifier.js b/zkp/js/integration-test/nf_anon_nullifier.js index 3165be5..8c5e352 100644 --- a/zkp/js/integration-test/nf_anon_nullifier.js +++ b/zkp/js/integration-test/nf_anon_nullifier.js @@ -39,8 +39,9 @@ describe("main circuit tests for Zeto non-fungible tokens with anonymity using n before(async () => { circuit = await loadCircuit("nf_anon_nullifier_transfer"); - ({ provingKeyFile, verificationKey } = - loadProvingKeys("nf_anon_nullifier_transfer")); + ({ provingKeyFile, verificationKey } = loadProvingKeys( + "nf_anon_nullifier_transfer", + )); let keypair = genKeypair(); Alice.privKey = keypair.privKey; diff --git a/zkp/js/integration-test/check_inputs_outputs_value.js b/zkp/js/integration-test/withdraw.js similarity index 94% rename from zkp/js/integration-test/check_inputs_outputs_value.js rename to zkp/js/integration-test/withdraw.js index ff174f2..9e1041d 100644 --- a/zkp/js/integration-test/check_inputs_outputs_value.js +++ b/zkp/js/integration-test/withdraw.js @@ -24,17 +24,15 @@ const { loadProvingKeys } = require("./utils.js"); const SMT_HEIGHT = 64; const poseidonHash = Poseidon.poseidon4; -describe("check_inputs_outputs_value circuit tests", () => { +describe("withdraw circuit tests", () => { let circuit, provingKeyFile, verificationKey, smtAlice; const Alice = {}; let senderPrivateKey; before(async () => { - circuit = await loadCircuit("check_inputs_outputs_value"); - ({ provingKeyFile, verificationKey } = loadProvingKeys( - "check_inputs_outputs_value", - )); + circuit = await loadCircuit("withdraw"); + ({ provingKeyFile, verificationKey } = loadProvingKeys("withdraw")); let keypair = genKeypair(); Alice.privKey = keypair.privKey; diff --git a/zkp/js/integration-test/check_nullifiers_value.js b/zkp/js/integration-test/withdraw_nullifier.js similarity index 95% rename from zkp/js/integration-test/check_nullifiers_value.js rename to zkp/js/integration-test/withdraw_nullifier.js index 0419fb7..18e7599 100644 --- a/zkp/js/integration-test/check_nullifiers_value.js +++ b/zkp/js/integration-test/withdraw_nullifier.js @@ -30,17 +30,16 @@ const SMT_HEIGHT = 64; const poseidonHash = Poseidon.poseidon4; const poseidonHash3 = Poseidon.poseidon3; -describe("check_nullifiers_value circuit tests", () => { +describe("withdraw_nullifier circuit tests", () => { let circuit, provingKeyFile, verificationKey, smtAlice; const Alice = {}; let senderPrivateKey; before(async () => { - circuit = await loadCircuit("check_nullifiers_value"); - ({ provingKeyFile, verificationKey } = loadProvingKeys( - "check_nullifiers_value", - )); + circuit = await loadCircuit("withdraw_nullifier"); + ({ provingKeyFile, verificationKey } = + loadProvingKeys("withdraw_nullifier")); let keypair = genKeypair(); Alice.privKey = keypair.privKey; diff --git a/zkp/js/test/check_hashes_value.js b/zkp/js/test/deposit.js similarity index 98% rename from zkp/js/test/check_hashes_value.js rename to zkp/js/test/deposit.js index 1bff94f..06d7e2b 100644 --- a/zkp/js/test/check_hashes_value.js +++ b/zkp/js/test/deposit.js @@ -23,7 +23,7 @@ const { Poseidon, newSalt } = require("../index.js"); const MAX_VALUE = 2n ** 100n - 1n; const poseidonHash = Poseidon.poseidon4; -describe("check_hashes_value circuit tests", () => { +describe("deposit circuit tests", () => { let circuit; const sender = {}; @@ -31,7 +31,7 @@ describe("check_hashes_value circuit tests", () => { this.timeout(60000); circuit = await wasm_tester( - join(__dirname, "../../circuits/check_hashes_value.circom"), + join(__dirname, "../../circuits/deposit.circom"), ); let keypair = genKeypair(); diff --git a/zkp/js/test/check_inputs_outputs_value.js b/zkp/js/test/withdraw.js similarity index 97% rename from zkp/js/test/check_inputs_outputs_value.js rename to zkp/js/test/withdraw.js index 1a0f2b1..7023a66 100644 --- a/zkp/js/test/check_inputs_outputs_value.js +++ b/zkp/js/test/withdraw.js @@ -24,7 +24,7 @@ const { Poseidon, newSalt } = require("../index.js"); const SMT_HEIGHT = 64; const poseidonHash = Poseidon.poseidon4; -describe("check_inputs_outputs_value circuit tests", () => { +describe("withdraw circuit tests", () => { let circuit, smtAlice; const Alice = {}; @@ -34,7 +34,7 @@ describe("check_inputs_outputs_value circuit tests", () => { this.timeout(60000); circuit = await wasm_tester( - join(__dirname, "../../circuits/check_inputs_outputs_value.circom"), + join(__dirname, "../../circuits/withdraw.circom"), ); let keypair = genKeypair(); diff --git a/zkp/js/test/check_nullifiers_value.js b/zkp/js/test/withdraw_nullifier.js similarity index 98% rename from zkp/js/test/check_nullifiers_value.js rename to zkp/js/test/withdraw_nullifier.js index 0b73210..c6475d3 100644 --- a/zkp/js/test/check_nullifiers_value.js +++ b/zkp/js/test/withdraw_nullifier.js @@ -30,7 +30,7 @@ const SMT_HEIGHT = 64; const poseidonHash = Poseidon.poseidon4; const poseidonHash3 = Poseidon.poseidon3; -describe("check_nullifiers_value circuit tests", () => { +describe("withdraw_nullifier circuit tests", () => { let circuit, smtAlice; const Alice = {}; @@ -40,7 +40,7 @@ describe("check_nullifiers_value circuit tests", () => { this.timeout(60000); circuit = await wasm_tester( - join(__dirname, "../../circuits/check_nullifiers_value.circom"), + join(__dirname, "../../circuits/withdraw_nullifier.circom"), ); let keypair = genKeypair();