Skip to content
Verified contractPartialGPL-3.0

SwapGroth16VerifierEVM3x2x1

Address0x14ebe78ae7cf7e4eed6df7eb837c29e17f376cab
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.28

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.28+commit.7893614a
Language
solidity
Optimization
Yes, 500 runs
EVM version
paris
License
GPL-3.0
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,595,245
Creation transaction
0x187c3baaa0…ad2bc2a714

contracts/swap/SwapGroth16VerifierEVM3x2x1.sol

// 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 <https://www.gnu.org/licenses/>.
*/

// NOTE: The original source of this contract is not public. This file was reconstructed from the
// deployed bytecode: it is the snarkJS Groth16 verifier template with the verification key read
// from the bytecode. It compiles to the deployed bytecode (solc 0.8.28, optimizer 500 runs,
// evmVersion paris) except for the metadata hash. The contract name is not the original one.
pragma solidity >=0.7.0 <0.9.0;

contract SwapGroth16VerifierEVM3x2x1 {
    // 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 = 18700633367395549103093662707503732905384988923749313550484320427752768542406;
    uint256 constant deltax2 = 2167557505942722852296636769524343847286539060964323922224596773966353310898;
    uint256 constant deltay1 = 806136583030109177389615628290382398544595280951408167521811735045286176594;
    uint256 constant deltay2 = 16762117586810008787897977323581396712021039275229574186830658708761575895915;

    
    uint256 constant IC0x = 9755153446184271987394840600770307498554331455460118617324948926841224075536;
    uint256 constant IC0y = 1550804539734418048028062616068893235609479479020585411053979791468497527071;
    
    uint256 constant IC1x = 14989811457443831332600992894324782372689406514808657055138045809607585228655;
    uint256 constant IC1y = 14039336441866507339123861015024214829322545610214292132314261003337152479831;
    
    uint256 constant IC2x = 1271220916176356863430919993397422629693115135397540551567182054820969773271;
    uint256 constant IC2y = 20925417367664951342449847285000516954523562415677411365707609020605495240850;
    
    uint256 constant IC3x = 6557825736441272550243135519929632654459042782458045007446060332657284093450;
    uint256 constant IC3y = 21473172430478067136631349108818609744946785269879529020544999715534078746212;
    
    uint256 constant IC4x = 10932145541864505218212167723603009692941771359147652307802110682561704537224;
    uint256 constant IC4y = 17830458768773039937755107921471080608740993909933949298526251548258469354059;
    
    uint256 constant IC5x = 6295421295117138087036903405779525805933171666645496168202831689797589592153;
    uint256 constant IC5y = 726281811998538641350258645084234487595765901083578361195676874531010454445;
    
    uint256 constant IC6x = 744911580845614722555697268842958634163191860218605569525974647668619245638;
    uint256 constant IC6y = 13529561027668755404968156396833394588388337966577490348722961728757061812006;
    
    uint256 constant IC7x = 16517110594246114524934034806260706666219152889064820683263682617098567523906;
    uint256 constant IC7y = 5660411889343840217826841264187694446797663016530080291194301287687782704179;
    
    uint256 constant IC8x = 7956703599914723412116668918553881366499583544617008379239198937686740395625;
    uint256 constant IC8y = 5670015599799677575457311700043383142166572333966077000065163350256659142115;
    
    uint256 constant IC9x = 4263222624128830743836127854007175305855437343342048293816811685948593711673;
    uint256 constant IC9y = 5663054610877321928212406371966324630362302300898861229507736348528129950298;
    
    uint256 constant IC10x = 17246319736958665220207288879151439963043048771335153604649097497708897750233;
    uint256 constant IC10y = 4906428810128096471706299665359550941851670565727513699187914503522079559208;
    
    uint256 constant IC11x = 5509992170685687740600526866350478641456363164745667321479328263549034551067;
    uint256 constant IC11y = 7812297129830121419576199560451347838424501476483761144621684492419404659452;
    
    uint256 constant IC12x = 11904423048137475370800284732936831355872833206012947603530138302854487900404;
    uint256 constant IC12y = 3652674296838651302529637924943356647668842473646508448970051481543474199260;
    
    uint256 constant IC13x = 663437493199436001394784977310296578104905952978673858762642637889242576750;
    uint256 constant IC13y = 482201162345129705237838527799482181625039555643452499068347418968952032101;
    
    uint256 constant IC14x = 13411199690380751632460562692803768293751630567361684151696146412049772182041;
    uint256 constant IC14y = 9588943039314434490521182778648594764510513530005101185925446301988591047224;
    
    uint256 constant IC15x = 3095410158798404046273875657523957139448648803839952875970826078969119943811;
    uint256 constant IC15y = 11625008675968909911833272625018437974595012743544340985487121612286917308938;
    
    uint256 constant IC16x = 12675371053083209165826331024131614818720070779236481493059507463535752392699;
    uint256 constant IC16y = 7064469986571896529570796869313793075877593243633271190137976758396692718074;
    
    uint256 constant IC17x = 18342961272423211517462913849529763158921681965301252047848495512957846131318;
    uint256 constant IC17y = 15809341388714715825302837497558763426373300119187152054593302802997079411114;
    
    uint256 constant IC18x = 15756381827849970922599898303706872255096906721606278034320549395784413431257;
    uint256 constant IC18y = 15980098858475059747860168482912734079152679276151135488250173802093461399729;
    
    uint256 constant IC19x = 4032738632107820706751997935287975820566304262284719672183645656418917677164;
    uint256 constant IC19y = 9298769156507937785468471159161323416804819874171347391199658310974893452860;
    
    uint256 constant IC20x = 14542383325468210076823724027992180941343310049973319242116843178036639064283;
    uint256 constant IC20y = 1292955983162941924354707442270602938366753058841870933163506613790056810816;
    
    uint256 constant IC21x = 12531662621501677219115873031517860471915264761973556822585413065917939839169;
    uint256 constant IC21y = 20929233963203456573585798066276153377538952996960637209809631134688493733153;
    
    uint256 constant IC22x = 4733179316636925201542422916089694594756886162532319992619930906175816239768;
    uint256 constant IC22y = 19624177757988010046806366152651838751581970883056388211003719051552680125287;
    
    uint256 constant IC23x = 149420561716940218005703978809580859653091207874086954734284375626928538680;
    uint256 constant IC23y = 15948726366105871421061550845584621412523018077947968302287275529525502068704;
    
    uint256 constant IC24x = 13112167023277000067026036306119167013794523740197112755114906015447818494774;
    uint256 constant IC24y = 9013942978328735605224408787884727185839950262953193377208757815643204457849;
    
    uint256 constant IC25x = 7700681375099581441479854268071056318652309917152132680319099353387717530238;
    uint256 constant IC25y = 7467936120365054599480052400407795700933539741195362103868671090433444279936;
    
 
    // 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[25] 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)))
                
                g1_mulAccC(_pVk, IC24x, IC24y, calldataload(add(pubSignals, 736)))
                
                g1_mulAccC(_pVk, IC25x, IC25y, calldataload(add(pubSignals, 768)))
                

                // -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)))
            
            checkField(calldataload(add(_pubSignals, 736)))
            
            checkField(calldataload(add(_pubSignals, 768)))
            

            // Validate all evaluations
            let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)

            mstore(0, isValid)
             return(0, 0x20)
         }
     }
 }
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 500,
    "enabled": true
  },
  "evmVersion": "paris",
  "remappings": [
    "@openzeppelin/=node_modules/@openzeppelin/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.