// 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 TransactVerifier { // 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 = 11558715336555757039642994281208653283840119327060640220532048284191389392009; uint256 constant deltax2 = 19919680049690174141902304696803418526243317727275177350669081160779341871785; uint256 constant deltay1 = 18967012362683510719592365485905408537470306814764577165307204988251708285030; uint256 constant deltay2 = 10310741582428925982459159021428234227930144140844782580753103782899358455623; uint256 constant IC0x = 10543373053747236945848372337393310641493127784176282602620289491642155238855; uint256 constant IC0y = 10513090186464858754190380325321419748562657196269627226907358325244251353463; uint256 constant IC1x = 1629130929063887649934130751455982971653675351051565745972632492235248851693; uint256 constant IC1y = 20171677281530807243720329564011359316467153660239909816673853546782680491282; uint256 constant IC2x = 11612447725356261651521112432930689630433614191542697404849947849438619241560; uint256 constant IC2y = 17121372186315870160222209754699028160755668278300523563975099373158964342299; uint256 constant IC3x = 19984089044656783122450564635789855847812712750897839284326033776633590464406; uint256 constant IC3y = 9084755999828942057330867764441618771520273770926962492646950031249647415363; uint256 constant IC4x = 20402273790500227385354739902595252224060505648867385190454159663116632033898; uint256 constant IC4y = 7995380465228022207001434334538832243870154226163983415819294031344507485969; uint256 constant IC5x = 9128934266102426827581425101496055527207101397114864177462890388857827310656; uint256 constant IC5y = 4048039616748962346909835396876100254464840512983301343659341374796729383171; uint256 constant IC6x = 7371528565169897273868845834363668017355264266039572904574545806691324168189; uint256 constant IC6y = 13665865882326828962600250978899448852640457909108939515316821222745259057543; uint256 constant IC7x = 20957600565675064442599498489792873111424844361595084288751881186081001321910; uint256 constant IC7y = 8130215951241878519100900182441163017183207462437571080529654161397755914571; uint256 constant IC8x = 10223602999095195586244671304497534627830633952982353468001347420040679381538; uint256 constant IC8y = 10166035067947343938228440271707506540411008733237528971157193826568817886957; uint256 constant IC9x = 9248253321420453988114196453605711091856055509193555880097860972628445068086; uint256 constant IC9y = 3085431176176611751917002514184155369591908947629009018089618902844932791319; uint256 constant IC10x = 15689881709007395034781060204110055973523155613215892345305132172363916542521; uint256 constant IC10y = 21235179298973569508870560649519338956876483459507607503651493770606182733854; uint256 constant IC11x = 15437121613270747986067965246815163492014554666559839812097999840063270763000; uint256 constant IC11y = 14922599228168373798149689098039886728038911529082093740917299182298506114047; // 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[11] 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))) // -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))) // Validate all evaluations let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem) mstore(0, isValid) return(0, 0x20) } } }