diff --git a/packages/hardhat/contracts/Groth16Verifier.sol b/packages/hardhat/contracts/Groth16Verifier.sol
new file mode 100644
index 0000000..c42dcfa
--- /dev/null
+++ b/packages/hardhat/contracts/Groth16Verifier.sol
@@ -0,0 +1,929 @@
+// 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 {
+ // 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 =
+ 1866766967684475077026429609556327106093807957741725946793964808023715990993;
+ uint256 constant deltax2 =
+ 4659311190982864441450729518864924847905216029076592248289990634575680082687;
+ uint256 constant deltay1 =
+ 21724169671419676774033717936126866779574439945101235323290178202491573424937;
+ uint256 constant deltay2 =
+ 18110855247484914672502198436947586961718950553755585790284240244644051838539;
+
+ uint256 constant IC0x =
+ 18309573688944280386125138623088688452809083872692035376744546048640448830013;
+ uint256 constant IC0y =
+ 8252545664804877655090584019431224476651831706926205661274438486717503078517;
+
+ uint256 constant IC1x =
+ 13724968256971608639683042303568749222860593419566750935710775838848837986435;
+ uint256 constant IC1y =
+ 15381662839978225352321616022337218020109204566049031666416886460526425965869;
+
+ uint256 constant IC2x =
+ 6658337158533056435209096505560783453195590085837382213813946443291522907745;
+ uint256 constant IC2y =
+ 9306572662774936565995161999022633816072552576090366864841219594069985311045;
+
+ uint256 constant IC3x =
+ 3016212379656281472280944594543865425517575371433088764117523134258049272378;
+ uint256 constant IC3y =
+ 2602541768252815682625947578833586588696693258602863952863513327213075022415;
+
+ uint256 constant IC4x =
+ 9816742021460791515218039132784611020094104961681834748400830069126900470998;
+ uint256 constant IC4y =
+ 10348426808259784844463456918035576955520609745619107315011093049401321052907;
+
+ uint256 constant IC5x =
+ 12390552360156525734091763827502679328587811743107273011015150606880160766528;
+ uint256 constant IC5y =
+ 183638701568878646260356724728606591551612270852066271019765173548740571911;
+
+ uint256 constant IC6x =
+ 18835793819754396966418324264338243421396665011470795519919492253397941511415;
+ uint256 constant IC6y =
+ 16276864664271038368712888193551459260270588753753324433645906101416426262868;
+
+ uint256 constant IC7x =
+ 17694389750473427714713340305217978269360025960743432126841431716792259216553;
+ uint256 constant IC7y =
+ 9650947012756037818471691383867973710225705683344930781931870909910681707965;
+
+ uint256 constant IC8x =
+ 681023809986507260745544777274775765194577408747661170783243702960142805219;
+ uint256 constant IC8y =
+ 1932661796175590584789349969886643788412159408887985979675775490813383802431;
+
+ uint256 constant IC9x =
+ 21017849571203201162910042984857063559850050358879473333160388606658656055561;
+ uint256 constant IC9y =
+ 3911553907221003467466493259384657847945603900216601273901250192843649327135;
+
+ uint256 constant IC10x =
+ 4697167604081360102767597310388954224248974287943019142969867281938252033279;
+ uint256 constant IC10y =
+ 20914530672636702782558652284783707697405729135251189269702367472029790810871;
+
+ uint256 constant IC11x =
+ 7369949482368171676645913938455574124222481706187847883741316060813160352388;
+ uint256 constant IC11y =
+ 4727140828630085863185239991710228583927761523693680497222423087252568656621;
+
+ uint256 constant IC12x =
+ 14064206758912584845837663247671777117618297224535288981280182234011836042358;
+ uint256 constant IC12y =
+ 2471602382851033672482675609087779227944480110933367708761146613365806260639;
+
+ uint256 constant IC13x =
+ 10736269799746324370561665190090163352937604329850809414102258159966416105084;
+ uint256 constant IC13y =
+ 19020761783205714677938272320357485323859845690764961473649357529923739843742;
+
+ uint256 constant IC14x =
+ 15341136362541358347806190520786075906481708522139600214759885728822520600097;
+ uint256 constant IC14y =
+ 12763186920235818095034854522833621355232606893991661714344676885217537892439;
+
+ uint256 constant IC15x =
+ 578923187875322718929551148864821444409122480112505090445143545076478253219;
+ uint256 constant IC15y =
+ 7225896456622788032015215894875412641425708855961584676292424041024877345434;
+
+ uint256 constant IC16x =
+ 18658344448625472361514517723847121242242621605616951126291199815235032180726;
+ uint256 constant IC16y =
+ 809276442226723012951716236123315663471583381870386200917746106613185945511;
+
+ uint256 constant IC17x =
+ 5982511498346272830450928090657905047310027938091831616388986968174660586744;
+ uint256 constant IC17y =
+ 15509127295444748557090617809365430814867930584899709527225185467490860295086;
+
+ uint256 constant IC18x =
+ 15365343054745101753330314041829116085855183564203118460990124415505406826969;
+ uint256 constant IC18y =
+ 17550334504170479775394246899009393639023697741142100255396130594222187928235;
+
+ uint256 constant IC19x =
+ 7866355633237906295444698578127110324394052841768366342612858876150827405474;
+ uint256 constant IC19y =
+ 21464430858041884878748298065323900366619776908859780580478489782011725400869;
+
+ uint256 constant IC20x =
+ 11409965274336198784885022968006318806697639878378509836184034039018205539006;
+ uint256 constant IC20y =
+ 2443082599914764314285778254288797740317850473858339183835017083972658705816;
+
+ uint256 constant IC21x =
+ 20631196981412679591470644564470136894629638047203062147303028037747691665185;
+ uint256 constant IC21y =
+ 16030610042702802775194942172772282453105682971282460674664358376585398028650;
+
+ uint256 constant IC22x =
+ 5932873505001011489814504863389327841014515111140308423692006170058593510855;
+ uint256 constant IC22y =
+ 17566953660226211786235303649779767015859352055560931781743606930162242017339;
+
+ uint256 constant IC23x =
+ 3570407908188742187942244566545561532804329313116603204071955254293457835048;
+ uint256 constant IC23y =
+ 888957545326078483334559831881533014254240676372674098014547184419455701116;
+
+ uint256 constant IC24x =
+ 3277288689053454364185820642980692937625084036430455814141706935377344738916;
+ uint256 constant IC24y =
+ 2696579421093670315121077129338319488278396897166913536990931383538616930167;
+
+ uint256 constant IC25x =
+ 8817735724143429914354176447563561385550814562843114609784812848112341015983;
+ uint256 constant IC25y =
+ 13601212939446098126684839800441456907956559897949946002758742646493707282910;
+
+ uint256 constant IC26x =
+ 242520524804255889063254246699618495647968774167019791729252562138656964225;
+ uint256 constant IC26y =
+ 16973052504220229148399058252278309977055266771019496607437733674562578695485;
+
+ uint256 constant IC27x =
+ 9013440492883720882679839217393830253117904651891690131192913212688263035425;
+ uint256 constant IC27y =
+ 2315255966339599410626919212510568554886702627946488701592576459930568620330;
+
+ uint256 constant IC28x =
+ 20679024761061200931816572597032340280314547584004877718544566240873670628592;
+ uint256 constant IC28y =
+ 18414855204652616530204390391588003816097467665749731519336041029937302999453;
+
+ uint256 constant IC29x =
+ 15072238453926190207791223017865893501821923615348984249884825516230481256082;
+ uint256 constant IC29y =
+ 8895769322320811707816032509589818173329092645233968889885933660205774178706;
+
+ uint256 constant IC30x =
+ 8094336611135960044601785233929226833486685560260660169986135663954428520824;
+ uint256 constant IC30y =
+ 8369015164321101629728699871242940331641480615160209965994546508586139206741;
+
+ uint256 constant IC31x =
+ 7731401541551544766699504483993337254794583686019158504985376407109162651461;
+ uint256 constant IC31y =
+ 6875232187288241504932091965559094778639331441478864488775043444383484728099;
+
+ uint256 constant IC32x =
+ 15499568761668065997918859624568562489526362773924227148983177629553450965712;
+ uint256 constant IC32y =
+ 37183277849483539583991543127527538945636653775623877772561407984346105078;
+
+ uint256 constant IC33x =
+ 4830297224837660087468639850081711742034935708467584422471158078126920708577;
+ uint256 constant IC33y =
+ 3176598632718619413479684717877505425106590182052247940017298335183173430555;
+
+ uint256 constant IC34x =
+ 10903574547819748549732540241229407360774915035217537369261916171194637443689;
+ uint256 constant IC34y =
+ 8858084338009697021205337490679360111246956214665724578280033119614287642646;
+
+ uint256 constant IC35x =
+ 15154785802553093403431522473988497260639725114747604440906057109686573477260;
+ uint256 constant IC35y =
+ 17795783893908215353511907097930773017805088530085337443958991067967762102655;
+
+ uint256 constant IC36x =
+ 2877376750994603714365289452890690316758364618871559804575161188222888112659;
+ uint256 constant IC36y =
+ 21735034166232609946148691607738854948236880094749663970921800614808406570078;
+
+ uint256 constant IC37x =
+ 3106333406220985162662100498986097229503869771836880247449360175981334157219;
+ uint256 constant IC37y =
+ 17865223479402419176248696836928756900496547663372228667207093311437768295043;
+
+ uint256 constant IC38x =
+ 697616770606607558981076211967433584976298008163992912003754086388870284439;
+ uint256 constant IC38y =
+ 11906015812090725752663954648490567553779437355520102774022319868767187695689;
+
+ uint256 constant IC39x =
+ 3066310853266947605681856994423652372406552925855313167141079102185871744170;
+ uint256 constant IC39y =
+ 7626480973749375313659327633446078949888566319591497861831619014932519116751;
+
+ uint256 constant IC40x =
+ 15547701183470494067964667727872231581260922370486244851758214336411550884118;
+ uint256 constant IC40y =
+ 17254233622002752357409825536770526543691283207810763163037848030419243484107;
+
+ uint256 constant IC41x =
+ 148292111307819306551390818446543424926350137834811534314052769163101561615;
+ uint256 constant IC41y =
+ 5500278154531033306799803347968647249419995483363964893976872863860493675643;
+
+ uint256 constant IC42x =
+ 12743968346040894236883464766141708515376809290327284933867605208542292732858;
+ uint256 constant IC42y =
+ 8018727597120067346853370292627401274187160859591238514067106241642604330800;
+
+ uint256 constant IC43x =
+ 691582148862529301778359900102607488395950567870758626909238499283070907403;
+ uint256 constant IC43y =
+ 8322981267261297384216741120713931240448479642727454047966782335276500598941;
+
+ uint256 constant IC44x =
+ 9278556347697362408180475360650302879696956102573343825404708863886542469887;
+ uint256 constant IC44y =
+ 9707313610712975990137006496452650791189150375669922886361334038088982701633;
+
+ uint256 constant IC45x =
+ 16829628853824851952140218215780485977108634939746967111056084269789078029054;
+ uint256 constant IC45y =
+ 4014469364669616007649171544577204356746921930709274053313209030043418033476;
+
+ uint256 constant IC46x =
+ 6641507292884053256398842662760831671384924006947363057533254043701551586373;
+ uint256 constant IC46y =
+ 7538020194481282455458251442306108143426114350545149178408028117651220441472;
+
+ uint256 constant IC47x =
+ 12391637512080499257662827283609890066662280564827165438208548685097578037073;
+ uint256 constant IC47y =
+ 19437801841177143231245408244309863501557488312715256561188881154500655967430;
+
+ uint256 constant IC48x =
+ 2890419354616910106196901223286921838329798511800552609084640710443390163241;
+ uint256 constant IC48y =
+ 17975752498184815248395543766804130572102816400153672759006930380470336365869;
+
+ uint256 constant IC49x =
+ 6356005874902387613526417303680497717538411035346314609640597118219882038318;
+ uint256 constant IC49y =
+ 8302058795733576312472765323167781290091115643523515316545093550229011458540;
+
+ uint256 constant IC50x =
+ 11467131470051250993846835458840241675362424681819054061438248446919198169881;
+ uint256 constant IC50y =
+ 3871876403715839319031033065719065817272850181251392446785808539701071977102;
+
+ uint256 constant IC51x =
+ 15418086696872287571839851755232562114887233182615521852215658895185306876954;
+ uint256 constant IC51y =
+ 15382077575814602641342651729699573330025044617981182458503295491525153173084;
+
+ uint256 constant IC52x =
+ 3518987841129817544165039005314383353101340037797957633052466976442785122773;
+ uint256 constant IC52y =
+ 13837229004430570059744211328338876274484428344134154507669720190847659718233;
+
+ uint256 constant IC53x =
+ 7836949953256230571863851319029582093455769148252637278978059072186916563644;
+ uint256 constant IC53y =
+ 16016031450925672052785771223602323332437162896094661214304742145432039577613;
+
+ uint256 constant IC54x =
+ 20068450523518386339209415533919057643114001865737097665607475828358564264945;
+ uint256 constant IC54y =
+ 16421501709602348379027099074800499750625346088991760891399592152922510486159;
+
+ uint256 constant IC55x =
+ 6956561678992452882033176540383047718724367746360885744508319174475838500863;
+ uint256 constant IC55y =
+ 852570432177137889322374252700826029568865060946246166272021327148649269580;
+
+ uint256 constant IC56x =
+ 19239577481052852428204088163978921314665017300758086261251463662450612991642;
+ uint256 constant IC56y =
+ 3132276701298581485739714988349614613303009325166772769288844918814734649647;
+
+ // 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[56] 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))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC26x,
+ IC26y,
+ calldataload(add(pubSignals, 800))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC27x,
+ IC27y,
+ calldataload(add(pubSignals, 832))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC28x,
+ IC28y,
+ calldataload(add(pubSignals, 864))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC29x,
+ IC29y,
+ calldataload(add(pubSignals, 896))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC30x,
+ IC30y,
+ calldataload(add(pubSignals, 928))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC31x,
+ IC31y,
+ calldataload(add(pubSignals, 960))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC32x,
+ IC32y,
+ calldataload(add(pubSignals, 992))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC33x,
+ IC33y,
+ calldataload(add(pubSignals, 1024))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC34x,
+ IC34y,
+ calldataload(add(pubSignals, 1056))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC35x,
+ IC35y,
+ calldataload(add(pubSignals, 1088))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC36x,
+ IC36y,
+ calldataload(add(pubSignals, 1120))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC37x,
+ IC37y,
+ calldataload(add(pubSignals, 1152))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC38x,
+ IC38y,
+ calldataload(add(pubSignals, 1184))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC39x,
+ IC39y,
+ calldataload(add(pubSignals, 1216))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC40x,
+ IC40y,
+ calldataload(add(pubSignals, 1248))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC41x,
+ IC41y,
+ calldataload(add(pubSignals, 1280))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC42x,
+ IC42y,
+ calldataload(add(pubSignals, 1312))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC43x,
+ IC43y,
+ calldataload(add(pubSignals, 1344))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC44x,
+ IC44y,
+ calldataload(add(pubSignals, 1376))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC45x,
+ IC45y,
+ calldataload(add(pubSignals, 1408))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC46x,
+ IC46y,
+ calldataload(add(pubSignals, 1440))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC47x,
+ IC47y,
+ calldataload(add(pubSignals, 1472))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC48x,
+ IC48y,
+ calldataload(add(pubSignals, 1504))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC49x,
+ IC49y,
+ calldataload(add(pubSignals, 1536))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC50x,
+ IC50y,
+ calldataload(add(pubSignals, 1568))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC51x,
+ IC51y,
+ calldataload(add(pubSignals, 1600))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC52x,
+ IC52y,
+ calldataload(add(pubSignals, 1632))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC53x,
+ IC53y,
+ calldataload(add(pubSignals, 1664))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC54x,
+ IC54y,
+ calldataload(add(pubSignals, 1696))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC55x,
+ IC55y,
+ calldataload(add(pubSignals, 1728))
+ )
+
+ g1_mulAccC(
+ _pVk,
+ IC56x,
+ IC56y,
+ calldataload(add(pubSignals, 1760))
+ )
+
+ // -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)))
+
+ checkField(calldataload(add(_pubSignals, 800)))
+
+ checkField(calldataload(add(_pubSignals, 832)))
+
+ checkField(calldataload(add(_pubSignals, 864)))
+
+ checkField(calldataload(add(_pubSignals, 896)))
+
+ checkField(calldataload(add(_pubSignals, 928)))
+
+ checkField(calldataload(add(_pubSignals, 960)))
+
+ checkField(calldataload(add(_pubSignals, 992)))
+
+ checkField(calldataload(add(_pubSignals, 1024)))
+
+ checkField(calldataload(add(_pubSignals, 1056)))
+
+ checkField(calldataload(add(_pubSignals, 1088)))
+
+ checkField(calldataload(add(_pubSignals, 1120)))
+
+ checkField(calldataload(add(_pubSignals, 1152)))
+
+ checkField(calldataload(add(_pubSignals, 1184)))
+
+ checkField(calldataload(add(_pubSignals, 1216)))
+
+ checkField(calldataload(add(_pubSignals, 1248)))
+
+ checkField(calldataload(add(_pubSignals, 1280)))
+
+ checkField(calldataload(add(_pubSignals, 1312)))
+
+ checkField(calldataload(add(_pubSignals, 1344)))
+
+ checkField(calldataload(add(_pubSignals, 1376)))
+
+ checkField(calldataload(add(_pubSignals, 1408)))
+
+ checkField(calldataload(add(_pubSignals, 1440)))
+
+ checkField(calldataload(add(_pubSignals, 1472)))
+
+ checkField(calldataload(add(_pubSignals, 1504)))
+
+ checkField(calldataload(add(_pubSignals, 1536)))
+
+ checkField(calldataload(add(_pubSignals, 1568)))
+
+ checkField(calldataload(add(_pubSignals, 1600)))
+
+ checkField(calldataload(add(_pubSignals, 1632)))
+
+ checkField(calldataload(add(_pubSignals, 1664)))
+
+ checkField(calldataload(add(_pubSignals, 1696)))
+
+ checkField(calldataload(add(_pubSignals, 1728)))
+
+ checkField(calldataload(add(_pubSignals, 1760)))
+
+ checkField(calldataload(add(_pubSignals, 1792)))
+
+ // Validate all evaluations
+ let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
+
+ mstore(0, isValid)
+ return(0, 0x20)
+ }
+ }
+}
diff --git a/packages/hardhat/contracts/Poseidon.sol b/packages/hardhat/contracts/Poseidon.sol
new file mode 100644
index 0000000..b9afc93
--- /dev/null
+++ b/packages/hardhat/contracts/Poseidon.sol
@@ -0,0 +1,688 @@
+/// SPDX-License-Identifier: MIT
+pragma solidity >=0.7.0;
+
+contract Poseidon {
+ uint constant M00 =
+ 0x066f6f85d6f68a85ec10345351a23a3aaf07f38af8c952a7bceca70bd2af7ad5;
+ uint constant M01 =
+ 0x0cc57cdbb08507d62bf67a4493cc262fb6c09d557013fff1f573f431221f8ff9;
+ uint constant M10 =
+ 0x2b9d4b4110c9ae997782e1509b1d0fdb20a7c02bbd8bea7305462b9f8125b1e8;
+ uint constant M11 =
+ 0x1274e649a32ed355a31a6ed69724e1adade857e86eb5c3a121bcd147943203c8;
+
+ // See here for a simplified implementation: https://github.com/vimwitch/poseidon-solidity/blob/e57becdabb65d99fdc586fe1e1e09e7108202d53/contracts/Poseidon.sol#L40
+ // Inspired by: https://github.com/iden3/circomlibjs/blob/v0.0.8/src/poseidon_slow.js
+ function hash(uint[1] memory) public pure returns (uint) {
+ assembly {
+ let
+ F
+ := 21888242871839275222246405745257275088548364400416034343698204186575808495617
+
+ // load the inputs from memory
+ let state1 := add(
+ mod(mload(0x80), F),
+ 0x0c0356530896eec42a97ed937f3135cfc5142b3ae405b8343c1d83ffa604cb81
+ )
+ let scratch0 := mulmod(state1, state1, F)
+ state1 := mulmod(mulmod(scratch0, scratch0, F), state1, F)
+ scratch0 := add(
+ 0x1e28a1d935698ad1142e51182bb54cf4a00ea5aabd6268bd317ea977cc154a30,
+ add(
+ 2135211596334038589877319861485022046541061518379136709265746501298180122869,
+ mulmod(state1, M10, F)
+ )
+ )
+ let scratch1 := add(
+ 0x27af2d831a9d2748080965db30e298e40e5757c3e008db964cf9e2b12b91251f,
+ add(
+ 14770526369429531795265880089668477939070475643153877209429555040029415045210,
+ mulmod(state1, M11, F)
+ )
+ )
+ let state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := mulmod(scratch1, scratch1, F)
+ scratch1 := mulmod(mulmod(state0, state0, F), scratch1, F)
+ state0 := add(
+ 0x1e6f11ce60fc8f513a6a3cfe16ae175a41291462f214cd0879aaf43545b74e03,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x2a67384d3bbd5e438541819cb681f0be04462ed14c3613d8f719206268d142d3,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := mulmod(state1, state1, F)
+ state1 := mulmod(mulmod(scratch0, scratch0, F), state1, F)
+ scratch0 := add(
+ 0x0b66fdf356093a611609f8e12fbfecf0b985e381f025188936408f5d5c9f45d0,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x012ee3ec1e78d470830c61093c2ade370b26c83cc5cebeeddaa6852dbdb09e21,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := mulmod(scratch1, scratch1, F)
+ scratch1 := mulmod(mulmod(state0, state0, F), scratch1, F)
+ state0 := add(
+ 0x0252ba5f6760bfbdfd88f67f8175e3fd6cd1c431b099b6bb2d108e7b445bb1b9,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x179474cceca5ff676c6bec3cef54296354391a8935ff71d6ef5aeaad7ca932f1,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x2c24261379a51bfa9228ff4a503fd4ed9c1f974a264969b37e1a2589bbed2b91,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x1cc1d7b62692e63eac2f288bd0695b43c2f63f5001fc0fc553e66c0551801b05,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x255059301aada98bb2ed55f852979e9600784dbf17fbacd05d9eff5fd9c91b56,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x28437be3ac1cb2e479e1f5c0eccd32b3aea24234970a8193b11c29ce7e59efd9,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x28216a442f2e1f711ca4fa6b53766eb118548da8fb4f78d4338762c37f5f2043,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x2c1f47cd17fa5adf1f39f4e7056dd03feee1efce03094581131f2377323482c9,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x07abad02b7a5ebc48632bcc9356ceb7dd9dafca276638a63646b8566a621afc9,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x0230264601ffdf29275b33ffaab51dfe9429f90880a69cd137da0c4d15f96c3c,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x1bc973054e51d905a0f168656497ca40a864414557ee289e717e5d66899aa0a9,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x2e1c22f964435008206c3157e86341edd249aff5c2d8421f2a6b22288f0a67fc,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x1224f38df67c5378121c1d5f461bbc509e8ea1598e46c9f7a70452bc2bba86b8,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x02e4e69d8ba59e519280b4bd9ed0068fd7bfe8cd9dfeda1969d2989186cde20e,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x1f1eccc34aaba0137f5df81fc04ff3ee4f19ee364e653f076d47e9735d98018e,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x1672ad3d709a353974266c3039a9a7311424448032cd1819eacb8a4d4284f582,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x283e3fdc2c6e420c56f44af5192b4ae9cda6961f284d24991d2ed602df8c8fc7,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x1c2a3d120c550ecfd0db0957170fa013683751f8fdff59d6614fbd69ff394bcc,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x216f84877aac6172f7897a7323456efe143a9a43773ea6f296cb6b8177653fbd,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x2c0d272becf2a75764ba7e8e3e28d12bceaa47ea61ca59a411a1f51552f94788,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x16e34299865c0e28484ee7a74c454e9f170a5480abe0508fcb4a6c3d89546f43,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x175ceba599e96f5b375a232a6fb9cc71772047765802290f48cd939755488fc5,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x0c7594440dc48c16fead9e1758b028066aa410bfbc354f54d8c5ffbb44a1ee32,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x1a3c29bc39f21bb5c466db7d7eb6fd8f760e20013ccf912c92479882d919fd8d,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x0ccfdd906f3426e5c0986ea049b253400855d349074f5a6695c8eeabcd22e68f,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x14f6bc81d9f186f62bdb475ce6c9411866a7a8a3fd065b3ce0e699b67dd9e796,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x0962b82789fb3d129702ca70b2f6c5aacc099810c9c495c888edeb7386b97052,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x1a880af7074d18b3bf20c79de25127bc13284ab01ef02575afef0c8f6a31a86d,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x10cba18419a6a332cd5e77f0211c154b20af2924fc20ff3f4c3012bb7ae9311b,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x057e62a9a8f89b3ebdc76ba63a9eaca8fa27b7319cae3406756a2849f302f10d,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x287c971de91dc0abd44adf5384b4988cb961303bbf65cff5afa0413b44280cee,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x21df3388af1687bbb3bca9da0cca908f1e562bc46d4aba4e6f7f7960e306891d,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x1be5c887d25bce703e25cc974d0934cd789df8f70b498fd83eff8b560e1682b3,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x268da36f76e568fb68117175cea2cd0dd2cb5d42fda5acea48d59c2706a0d5c1,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x0e17ab091f6eae50c609beaf5510ececc5d8bb74135ebd05bd06460cc26a5ed6,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x04d727e728ffa0a67aee535ab074a43091ef62d8cf83d270040f5caa1f62af40,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x0ddbd7bf9c29341581b549762bc022ed33702ac10f1bfd862b15417d7e39ca6e,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x2790eb3351621752768162e82989c6c234f5b0d1d3af9b588a29c49c8789654b,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x1e457c601a63b73e4471950193d8a570395f3d9ab8b2fd0984b764206142f9e9,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x21ae64301dca9625638d6ab2bbe7135ffa90ecd0c43ff91fc4c686fc46e091b0,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x0379f63c8ce3468d4da293166f494928854be9e3432e09555858534eed8d350b,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x002d56420359d0266a744a080809e054ca0e4921a46686ac8c9f58a324c35049,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x123158e5965b5d9b1d68b3cd32e10bbeda8d62459e21f4090fc2c5af963515a6,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x0be29fc40847a941661d14bbf6cbe0420fbb2b6f52836d4e60c80eb49cad9ec1,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x1ac96991dec2bb0557716142015a453c36db9d859cad5f9a233802f24fdf4c1a,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x1596443f763dbcc25f4964fc61d23b3e5e12c9fa97f18a9251ca3355bcb0627e,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x12e0bcd3654bdfa76b2861d4ec3aeae0f1857d9f17e715aed6d049eae3ba3212,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x0fc92b4f1bbea82b9ea73d4af9af2a50ceabac7f37154b1904e6c76c7cf964ba,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x1f9c0b1610446442d6f2e592a8013f40b14f7c7722236f4f9c7e965233872762,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x0ebd74244ae72675f8cde06157a782f4050d914da38b4c058d159f643dbbf4d3,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x2cb7f0ed39e16e9f69a9fafd4ab951c03b0671e97346ee397a839839dccfc6d1,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x1a9d6e2ecff022cc5605443ee41bab20ce761d0514ce526690c72bca7352d9bf,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x2a115439607f335a5ea83c3bc44a9331d0c13326a9a7ba3087da182d648ec72f,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x23f9b6529b5d040d15b8fa7aee3e3410e738b56305cd44f29535c115c5a4c060,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x05872c16db0f72a2249ac6ba484bb9c3a3ce97c16d58b68b260eb939f0e6e8a7,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x1300bdee08bb7824ca20fb80118075f40219b6151d55b5c52b624a7cdeddf6a7,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x19b9b63d2f108e17e63817863a8f6c288d7ad29916d98cb1072e4e7b7d52b376,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x015bee1357e3c015b5bda237668522f613d1c88726b5ec4224a20128481b4f7f,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x2953736e94bb6b9f1b9707a4f1615e4efe1e1ce4bab218cbea92c785b128ffd1,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x0b069353ba091618862f806180c0385f851b98d372b45f544ce7266ed6608dfc,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x304f74d461ccc13115e4e0bcfb93817e55aeb7eb9306b64e4f588ac97d81f429,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x15bbf146ce9bca09e8a33f5e77dfe4f5aad2a164a4617a4cb8ee5415cde913fc,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x0ab4dfe0c2742cde44901031487964ed9b8f4b850405c10ca9ff23859572c8c6,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x0e32db320a044e3197f45f7649a19675ef5eedfea546dea9251de39f9639779a,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x0a1756aa1f378ca4b27635a78b6888e66797733a82774896a3078efa516da016,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x044c4a33b10f693447fd17177f952ef895e61d328f85efa94254d6a2a25d93ef,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x2ed3611b725b8a70be655b537f66f700fe0879d79a496891d37b07b5466c4b8b,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x1f9ba4e8bab7ce42c8ecc3d722aa2e0eadfdeb9cfdd347b5d8339ea7120858aa,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x1b233043052e8c288f7ee907a84e518aa38e82ac4502066db74056f865c5d3da,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x2431e1cc164bb8d074031ab72bd55b4c902053bfc0f14db0ca2f97b020875954,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x082f934c91f5aac330cd6953a0a7db45a13e322097583319a791f273965801fd,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x2b9a0a223e7538b0a34be074315542a3c77245e2ae7cbe999ad6bb930c48997c,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x0e1cd91edd2cfa2cceb85483b887a9be8164163e75a8a00eb0b589cc70214e7d,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x2e1eac0f2bfdfd63c951f61477e3698999774f19854d00f588d324601cebe2f9,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x0cbfa95f37fb74060c76158e769d6d157345784d8efdb33c23d748115b500b83,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x08f05b3be923ed44d65ad49d8a61e9a676d991e3a77513d9980c232dfa4a4f84,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x22719e2a070bcd0852bf8e21984d0443e7284925dc0758a325a2dd510c047ef6,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x041f596a9ee1cb2bc060f7fcc3a1ab4c7bdbf036119982c0f41f62b2f26830c0,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x233fd35de1be520a87628eb06f6b1d4c021be1c2d0dc464a19fcdd0986b10f89,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x0524b46d1aa87a5e4325e0a423ebc810d31e078aa1b4707eefcb453c61c9c267,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x2c34f424c81e5716ce47fcac894b85824227bb954b0f3199cc4486237c515211,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x0b5f2a4b63387819207effc2b5541fb72dd2025b5457cc97f33010327de4915e,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x22207856082ccc54c5b72fe439d2cfd6c17435d2f57af6ceaefac41fe05c659f,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x24d57a8bf5da63fe4e24159b7f8950b5cdfb210194caf79f27854048ce2c8171,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x0afab181fdd5e0583b371d75bd693f98374ad7097bb01a8573919bb23b79396e,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x2dba9b108f208772998a52efac7cbd5676c0057194c16c0bf16290d62b1128ee,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x26349b66edb8b16f56f881c788f53f83cbb83de0bd592b255aff13e6bce420b3,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x25af7ce0e5e10357685e95f92339753ad81a56d28ecc193b235288a3e6f137db,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x25b4ce7bd2294390c094d6a55edd68b970eed7aae88b2bff1f7c0187fe35011f,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x22c543f10f6c89ec387e53f1908a88e5de9cef28ebdf30b18cb9d54c1e02b631,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x0236f93e7789c4724fc7908a9f191e1e425e906a919d7a34df668e74882f87a9,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x29350b401166ca010e7d27e37d05da99652bdae114eb01659cb497af980c4b52,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x0eed787d65820d3f6bd31bbab547f75a65edb75d844ebb89ee1260916652363f,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x07cc1170f13b46f2036a753f520b3291fdcd0e99bd94297d1906f656f4de6fad,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x22b939233b1d7205f49bcf613a3d30b1908786d7f9f5d10c2059435689e8acea,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x01451762a0aab81c8aad1dc8bc33e870740f083a5aa85438add650ace60ae5a6,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x23506bb5d8727d4461fabf1025d46d1fe32eaa61dec7da57e704fec0892fce89,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x2e484c44e838aea0bac06ae3f71bdd092a3709531e1efea97f8bd68907355522,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x0f4bc7d07ebafd64379e78c50bd2e42baf4a594545cedc2545418da26835b54c,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x1f4d3c8f6583e9e5fa76637862faaee851582388725df460e620996d50d8e74e,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x093514e0c70711f82660d07be0e4a988fae02abc7b681d9153eb9bcb48fe7389,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x1adab0c8e2b3bad346699a2b5f3bc03643ee83ece47228f24a58e0a347e153d8,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x1672b1726057d99dd14709ebb474641a378c1b94b8072bac1a22dbef9e80dad2,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x1dfd53d4576af2e38f44f53fdcab468cc5d8e2fae0acc4ee30d47b239b479c14,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x0c6888a10b75b0f3a70a36263a37e17fe6d77d640f6fc3debc7f207753205c60,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x1addb933a65be77092b34a7e77d12fe8611a61e00ee6848b85091ecca9d1e508,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x00d7540dcd268a845c10ae18d1de933cf638ff5425f0afff7935628e299d1791,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x140c0e42687e9ead01b2827a5664ca9c26fedde4acd99db1d316939d20b82c0e,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x2f0c3a115d4317d191ba89b8d13d1806c20a0f9b24f8c5edc091e2ae56565984,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x0c4ee778ff7c14553006ed220cf9c81008a0cff670b22b82d8c538a1dc958c61,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := add(
+ 0x1704f2766d46f82c3693f00440ccc3609424ed26c0acc66227c3d7485de74c69,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x2f2d19cc3ea5d78ea7a02c1b51d244abf0769c9f8544e40239b66fe9009c3cfa,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := add(
+ 0x1ae03853b75fcaba5053f112e2a8e8dcdd7ee6cb9cfed9c7d6c766a806fc6629,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x0971aabf795241df51d131d0fa61aa5f3556921b2d6f014e4e41a86ddaf056d5,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := mulmod(state1, state1, F)
+ state1 := mulmod(mulmod(scratch0, scratch0, F), state1, F)
+ scratch0 := add(
+ 0x1408c316e6014e1a91d4cf6b6e0de73eda624f8380df1c875f5c29f7bfe2f646,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x1667f3fe2edbe850248abe42b543093b6c89f1f773ef285341691f39822ef5bd,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := mulmod(scratch1, scratch1, F)
+ scratch1 := mulmod(mulmod(state0, state0, F), scratch1, F)
+ state0 := add(
+ 0x13bf7c5d0d2c4376a48b0a03557cdf915b81718409e5c133424c69576500fe37,
+ add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F))
+ )
+ state1 := add(
+ 0x07620a6dfb0b6cec3016adf3d3533c24024b95347856b79719bc0ba743a62c2c,
+ add(mulmod(scratch0, M01, F), mulmod(scratch1, M11, F))
+ )
+ scratch0 := mulmod(state0, state0, F)
+ state0 := mulmod(mulmod(scratch0, scratch0, F), state0, F)
+ scratch0 := mulmod(state1, state1, F)
+ state1 := mulmod(mulmod(scratch0, scratch0, F), state1, F)
+ scratch0 := add(
+ 0x1574c7ef0c43545f36a8ca08bdbdd8b075d2959e2f322b731675de3e1982b4d0,
+ add(mulmod(state0, M00, F), mulmod(state1, M10, F))
+ )
+ scratch1 := add(
+ 0x269e4b5b7a2eb21afd567970a717ceec5bd4184571c254fdc06e03a7ff8378f0,
+ add(mulmod(state0, M01, F), mulmod(state1, M11, F))
+ )
+ state0 := mulmod(scratch0, scratch0, F)
+ scratch0 := mulmod(mulmod(state0, state0, F), scratch0, F)
+ state0 := mulmod(scratch1, scratch1, F)
+ scratch1 := mulmod(mulmod(state0, state0, F), scratch1, F)
+
+ mstore(
+ 0x0,
+ mod(add(mulmod(scratch0, M00, F), mulmod(scratch1, M10, F)), F)
+ )
+
+ return(0, 0x20)
+ }
+ }
+}
diff --git a/packages/hardhat/contracts/YourContract.sol b/packages/hardhat/contracts/YourContract.sol
index 3d364a0..daa8eb7 100644
--- a/packages/hardhat/contracts/YourContract.sol
+++ b/packages/hardhat/contracts/YourContract.sol
@@ -1,87 +1,82 @@
-//SPDX-License-Identifier: MIT
-pragma solidity >=0.8.0 <0.9.0;
+// SPDX-License-Identifier: MIT
+pragma solidity ^0.8.0;
-// Useful for debugging. Remove when deploying to a live network.
+import "./Poseidon.sol";
import "hardhat/console.sol";
+import "./Groth16Verifier.sol";
-// Use openzeppelin to inherit battle-tested implementations (ERC20, ERC721, etc)
-// import "@openzeppelin/contracts/access/Ownable.sol";
+contract YourContract is Groth16Verifier, Poseidon {
+ // The known hash of the FrogCrypto signer
+ uint256 constant FROGCRYPTO_SIGNER_HASH =
+ 320469162396708332516033932244029190181315114284264408621970394677041964715;
-/**
- * A smart contract that allows changing a state variable of the contract and tracking the changes
- * It also allows the owner to withdraw the Ether in the contract
- * @author BuidlGuidl
- */
-contract YourContract {
- // State Variables
- address public immutable owner;
- string public greeting = "Building Unstoppable Apps!!!";
- bool public premium = false;
- uint256 public totalCounter = 0;
- mapping(address => uint) public userGreetingCounter;
-
- // Events: a way to emit log statements from smart contract that can be listened to by external parties
- event GreetingChange(
- address indexed greetingSetter,
- string newGreeting,
- bool premium,
- uint256 value
- );
-
- // Constructor: Called once on contract deployment
- // Check packages/hardhat/deploy/00_deploy_your_contract.ts
- constructor(address _owner) {
- owner = _owner;
+ struct ProofArgs {
+ uint256[2] _pA;
+ uint256[2][2] _pB;
+ uint256[2] _pC;
+ uint256[56] _pubSignals;
}
- // Modifier: used to define a set of rules that must be met before or after a function is executed
- // Check the withdraw() function
- modifier isOwner() {
- // msg.sender: predefined variable that represents address of the account that called the current function
- require(msg.sender == owner, "Not the Owner");
+ modifier verifiedProof(ProofArgs calldata proof) {
+ require(
+ this.verifyProof(
+ proof._pA,
+ proof._pB,
+ proof._pC,
+ proof._pubSignals
+ ),
+ "Invalid proof"
+ );
_;
}
- /**
- * Function that allows anyone to change the state variable "greeting" of the contract and increase the counters
- *
- * @param _newGreeting (string memory) - new greeting to save on the contract
- */
- function setGreeting(string memory _newGreeting) public payable {
- // Print data to the hardhat chain console. Remove when deploying to a live network.
- console.log(
- "Setting new greeting '%s' from %s",
- _newGreeting,
- msg.sender
+ function verifyAndExtractFrog(
+ ProofArgs calldata proof,
+ // User provided values to verify
+ uint256 beauty,
+ uint256 biome,
+ uint256 intelligence,
+ uint256 jump,
+ uint256 speed,
+ uint256 rarity,
+ uint256 owner
+ ) public view returns (bool) {
+ uint256[56] memory pubSignals = proof._pubSignals;
+ // Verify FrogCrypto signer
+ require(pubSignals[23] == FROGCRYPTO_SIGNER_HASH, "Invalid signer");
+
+ uint256[1] memory input;
+ // Verify beauty
+ input[0] = beauty;
+ require(this.hash(input) == pubSignals[0], "Invalid beauty value");
+
+ // Verify biome
+ input[0] = biome;
+ require(this.hash(input) == pubSignals[1], "Invalid biome value");
+
+ // Verify intelligence
+ input[0] = intelligence;
+ require(
+ this.hash(input) == pubSignals[2],
+ "Invalid intelligence value"
);
- // Change state variables
- greeting = _newGreeting;
- totalCounter += 1;
- userGreetingCounter[msg.sender] += 1;
+ // Verify jump
+ input[0] = jump;
+ require(this.hash(input) == pubSignals[3], "Invalid jump value");
- // msg.value: built-in global variable that represents the amount of ether sent with the transaction
- if (msg.value > 0) {
- premium = true;
- } else {
- premium = false;
- }
+ // Verify owner
+ input[0] = owner;
+ require(this.hash(input) == pubSignals[5], "Invalid owner value");
- // emit: keyword used to trigger an event
- emit GreetingChange(msg.sender, _newGreeting, msg.value > 0, msg.value);
- }
+ // Verify rarity
+ input[0] = rarity;
+ require(this.hash(input) == pubSignals[6], "Invalid rarity value");
- /**
- * Function that allows the owner to withdraw all the Ether in the contract
- * The function can only be called by the owner of the contract as defined by the isOwner modifier
- */
- function withdraw() public isOwner {
- (bool success, ) = owner.call{ value: address(this).balance }("");
- require(success, "Failed to send Ether");
- }
+ // Verify speed
+ input[0] = speed;
+ require(this.hash(input) == pubSignals[7], "Invalid speed value");
- /**
- * Function that allows the contract to receive ETH
- */
- receive() external payable {}
+ return true;
+ }
}
diff --git a/packages/hardhat/contracts/verifier.sol b/packages/hardhat/contracts/verifier.sol
deleted file mode 100644
index ef2b829..0000000
--- a/packages/hardhat/contracts/verifier.sol
+++ /dev/null
@@ -1,555 +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 {
- // 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 = 1866766967684475077026429609556327106093807957741725946793964808023715990993;
- uint256 constant deltax2 = 4659311190982864441450729518864924847905216029076592248289990634575680082687;
- uint256 constant deltay1 = 21724169671419676774033717936126866779574439945101235323290178202491573424937;
- uint256 constant deltay2 = 18110855247484914672502198436947586961718950553755585790284240244644051838539;
-
-
- uint256 constant IC0x = 18309573688944280386125138623088688452809083872692035376744546048640448830013;
- uint256 constant IC0y = 8252545664804877655090584019431224476651831706926205661274438486717503078517;
-
- uint256 constant IC1x = 13724968256971608639683042303568749222860593419566750935710775838848837986435;
- uint256 constant IC1y = 15381662839978225352321616022337218020109204566049031666416886460526425965869;
-
- uint256 constant IC2x = 6658337158533056435209096505560783453195590085837382213813946443291522907745;
- uint256 constant IC2y = 9306572662774936565995161999022633816072552576090366864841219594069985311045;
-
- uint256 constant IC3x = 3016212379656281472280944594543865425517575371433088764117523134258049272378;
- uint256 constant IC3y = 2602541768252815682625947578833586588696693258602863952863513327213075022415;
-
- uint256 constant IC4x = 9816742021460791515218039132784611020094104961681834748400830069126900470998;
- uint256 constant IC4y = 10348426808259784844463456918035576955520609745619107315011093049401321052907;
-
- uint256 constant IC5x = 12390552360156525734091763827502679328587811743107273011015150606880160766528;
- uint256 constant IC5y = 183638701568878646260356724728606591551612270852066271019765173548740571911;
-
- uint256 constant IC6x = 18835793819754396966418324264338243421396665011470795519919492253397941511415;
- uint256 constant IC6y = 16276864664271038368712888193551459260270588753753324433645906101416426262868;
-
- uint256 constant IC7x = 17694389750473427714713340305217978269360025960743432126841431716792259216553;
- uint256 constant IC7y = 9650947012756037818471691383867973710225705683344930781931870909910681707965;
-
- uint256 constant IC8x = 681023809986507260745544777274775765194577408747661170783243702960142805219;
- uint256 constant IC8y = 1932661796175590584789349969886643788412159408887985979675775490813383802431;
-
- uint256 constant IC9x = 21017849571203201162910042984857063559850050358879473333160388606658656055561;
- uint256 constant IC9y = 3911553907221003467466493259384657847945603900216601273901250192843649327135;
-
- uint256 constant IC10x = 4697167604081360102767597310388954224248974287943019142969867281938252033279;
- uint256 constant IC10y = 20914530672636702782558652284783707697405729135251189269702367472029790810871;
-
- uint256 constant IC11x = 7369949482368171676645913938455574124222481706187847883741316060813160352388;
- uint256 constant IC11y = 4727140828630085863185239991710228583927761523693680497222423087252568656621;
-
- uint256 constant IC12x = 14064206758912584845837663247671777117618297224535288981280182234011836042358;
- uint256 constant IC12y = 2471602382851033672482675609087779227944480110933367708761146613365806260639;
-
- uint256 constant IC13x = 10736269799746324370561665190090163352937604329850809414102258159966416105084;
- uint256 constant IC13y = 19020761783205714677938272320357485323859845690764961473649357529923739843742;
-
- uint256 constant IC14x = 15341136362541358347806190520786075906481708522139600214759885728822520600097;
- uint256 constant IC14y = 12763186920235818095034854522833621355232606893991661714344676885217537892439;
-
- uint256 constant IC15x = 578923187875322718929551148864821444409122480112505090445143545076478253219;
- uint256 constant IC15y = 7225896456622788032015215894875412641425708855961584676292424041024877345434;
-
- uint256 constant IC16x = 18658344448625472361514517723847121242242621605616951126291199815235032180726;
- uint256 constant IC16y = 809276442226723012951716236123315663471583381870386200917746106613185945511;
-
- uint256 constant IC17x = 5982511498346272830450928090657905047310027938091831616388986968174660586744;
- uint256 constant IC17y = 15509127295444748557090617809365430814867930584899709527225185467490860295086;
-
- uint256 constant IC18x = 15365343054745101753330314041829116085855183564203118460990124415505406826969;
- uint256 constant IC18y = 17550334504170479775394246899009393639023697741142100255396130594222187928235;
-
- uint256 constant IC19x = 7866355633237906295444698578127110324394052841768366342612858876150827405474;
- uint256 constant IC19y = 21464430858041884878748298065323900366619776908859780580478489782011725400869;
-
- uint256 constant IC20x = 11409965274336198784885022968006318806697639878378509836184034039018205539006;
- uint256 constant IC20y = 2443082599914764314285778254288797740317850473858339183835017083972658705816;
-
- uint256 constant IC21x = 20631196981412679591470644564470136894629638047203062147303028037747691665185;
- uint256 constant IC21y = 16030610042702802775194942172772282453105682971282460674664358376585398028650;
-
- uint256 constant IC22x = 5932873505001011489814504863389327841014515111140308423692006170058593510855;
- uint256 constant IC22y = 17566953660226211786235303649779767015859352055560931781743606930162242017339;
-
- uint256 constant IC23x = 3570407908188742187942244566545561532804329313116603204071955254293457835048;
- uint256 constant IC23y = 888957545326078483334559831881533014254240676372674098014547184419455701116;
-
- uint256 constant IC24x = 3277288689053454364185820642980692937625084036430455814141706935377344738916;
- uint256 constant IC24y = 2696579421093670315121077129338319488278396897166913536990931383538616930167;
-
- uint256 constant IC25x = 8817735724143429914354176447563561385550814562843114609784812848112341015983;
- uint256 constant IC25y = 13601212939446098126684839800441456907956559897949946002758742646493707282910;
-
- uint256 constant IC26x = 242520524804255889063254246699618495647968774167019791729252562138656964225;
- uint256 constant IC26y = 16973052504220229148399058252278309977055266771019496607437733674562578695485;
-
- uint256 constant IC27x = 9013440492883720882679839217393830253117904651891690131192913212688263035425;
- uint256 constant IC27y = 2315255966339599410626919212510568554886702627946488701592576459930568620330;
-
- uint256 constant IC28x = 20679024761061200931816572597032340280314547584004877718544566240873670628592;
- uint256 constant IC28y = 18414855204652616530204390391588003816097467665749731519336041029937302999453;
-
- uint256 constant IC29x = 15072238453926190207791223017865893501821923615348984249884825516230481256082;
- uint256 constant IC29y = 8895769322320811707816032509589818173329092645233968889885933660205774178706;
-
- uint256 constant IC30x = 8094336611135960044601785233929226833486685560260660169986135663954428520824;
- uint256 constant IC30y = 8369015164321101629728699871242940331641480615160209965994546508586139206741;
-
- uint256 constant IC31x = 7731401541551544766699504483993337254794583686019158504985376407109162651461;
- uint256 constant IC31y = 6875232187288241504932091965559094778639331441478864488775043444383484728099;
-
- uint256 constant IC32x = 15499568761668065997918859624568562489526362773924227148983177629553450965712;
- uint256 constant IC32y = 37183277849483539583991543127527538945636653775623877772561407984346105078;
-
- uint256 constant IC33x = 4830297224837660087468639850081711742034935708467584422471158078126920708577;
- uint256 constant IC33y = 3176598632718619413479684717877505425106590182052247940017298335183173430555;
-
- uint256 constant IC34x = 10903574547819748549732540241229407360774915035217537369261916171194637443689;
- uint256 constant IC34y = 8858084338009697021205337490679360111246956214665724578280033119614287642646;
-
- uint256 constant IC35x = 15154785802553093403431522473988497260639725114747604440906057109686573477260;
- uint256 constant IC35y = 17795783893908215353511907097930773017805088530085337443958991067967762102655;
-
- uint256 constant IC36x = 2877376750994603714365289452890690316758364618871559804575161188222888112659;
- uint256 constant IC36y = 21735034166232609946148691607738854948236880094749663970921800614808406570078;
-
- uint256 constant IC37x = 3106333406220985162662100498986097229503869771836880247449360175981334157219;
- uint256 constant IC37y = 17865223479402419176248696836928756900496547663372228667207093311437768295043;
-
- uint256 constant IC38x = 697616770606607558981076211967433584976298008163992912003754086388870284439;
- uint256 constant IC38y = 11906015812090725752663954648490567553779437355520102774022319868767187695689;
-
- uint256 constant IC39x = 3066310853266947605681856994423652372406552925855313167141079102185871744170;
- uint256 constant IC39y = 7626480973749375313659327633446078949888566319591497861831619014932519116751;
-
- uint256 constant IC40x = 15547701183470494067964667727872231581260922370486244851758214336411550884118;
- uint256 constant IC40y = 17254233622002752357409825536770526543691283207810763163037848030419243484107;
-
- uint256 constant IC41x = 148292111307819306551390818446543424926350137834811534314052769163101561615;
- uint256 constant IC41y = 5500278154531033306799803347968647249419995483363964893976872863860493675643;
-
- uint256 constant IC42x = 12743968346040894236883464766141708515376809290327284933867605208542292732858;
- uint256 constant IC42y = 8018727597120067346853370292627401274187160859591238514067106241642604330800;
-
- uint256 constant IC43x = 691582148862529301778359900102607488395950567870758626909238499283070907403;
- uint256 constant IC43y = 8322981267261297384216741120713931240448479642727454047966782335276500598941;
-
- uint256 constant IC44x = 9278556347697362408180475360650302879696956102573343825404708863886542469887;
- uint256 constant IC44y = 9707313610712975990137006496452650791189150375669922886361334038088982701633;
-
- uint256 constant IC45x = 16829628853824851952140218215780485977108634939746967111056084269789078029054;
- uint256 constant IC45y = 4014469364669616007649171544577204356746921930709274053313209030043418033476;
-
- uint256 constant IC46x = 6641507292884053256398842662760831671384924006947363057533254043701551586373;
- uint256 constant IC46y = 7538020194481282455458251442306108143426114350545149178408028117651220441472;
-
- uint256 constant IC47x = 12391637512080499257662827283609890066662280564827165438208548685097578037073;
- uint256 constant IC47y = 19437801841177143231245408244309863501557488312715256561188881154500655967430;
-
- uint256 constant IC48x = 2890419354616910106196901223286921838329798511800552609084640710443390163241;
- uint256 constant IC48y = 17975752498184815248395543766804130572102816400153672759006930380470336365869;
-
- uint256 constant IC49x = 6356005874902387613526417303680497717538411035346314609640597118219882038318;
- uint256 constant IC49y = 8302058795733576312472765323167781290091115643523515316545093550229011458540;
-
- uint256 constant IC50x = 11467131470051250993846835458840241675362424681819054061438248446919198169881;
- uint256 constant IC50y = 3871876403715839319031033065719065817272850181251392446785808539701071977102;
-
- uint256 constant IC51x = 15418086696872287571839851755232562114887233182615521852215658895185306876954;
- uint256 constant IC51y = 15382077575814602641342651729699573330025044617981182458503295491525153173084;
-
- uint256 constant IC52x = 3518987841129817544165039005314383353101340037797957633052466976442785122773;
- uint256 constant IC52y = 13837229004430570059744211328338876274484428344134154507669720190847659718233;
-
- uint256 constant IC53x = 7836949953256230571863851319029582093455769148252637278978059072186916563644;
- uint256 constant IC53y = 16016031450925672052785771223602323332437162896094661214304742145432039577613;
-
- uint256 constant IC54x = 20068450523518386339209415533919057643114001865737097665607475828358564264945;
- uint256 constant IC54y = 16421501709602348379027099074800499750625346088991760891399592152922510486159;
-
- uint256 constant IC55x = 6956561678992452882033176540383047718724367746360885744508319174475838500863;
- uint256 constant IC55y = 852570432177137889322374252700826029568865060946246166272021327148649269580;
-
- uint256 constant IC56x = 19239577481052852428204088163978921314665017300758086261251463662450612991642;
- uint256 constant IC56y = 3132276701298581485739714988349614613303009325166772769288844918814734649647;
-
-
- // 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[56] 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)))
-
- g1_mulAccC(_pVk, IC26x, IC26y, calldataload(add(pubSignals, 800)))
-
- g1_mulAccC(_pVk, IC27x, IC27y, calldataload(add(pubSignals, 832)))
-
- g1_mulAccC(_pVk, IC28x, IC28y, calldataload(add(pubSignals, 864)))
-
- g1_mulAccC(_pVk, IC29x, IC29y, calldataload(add(pubSignals, 896)))
-
- g1_mulAccC(_pVk, IC30x, IC30y, calldataload(add(pubSignals, 928)))
-
- g1_mulAccC(_pVk, IC31x, IC31y, calldataload(add(pubSignals, 960)))
-
- g1_mulAccC(_pVk, IC32x, IC32y, calldataload(add(pubSignals, 992)))
-
- g1_mulAccC(_pVk, IC33x, IC33y, calldataload(add(pubSignals, 1024)))
-
- g1_mulAccC(_pVk, IC34x, IC34y, calldataload(add(pubSignals, 1056)))
-
- g1_mulAccC(_pVk, IC35x, IC35y, calldataload(add(pubSignals, 1088)))
-
- g1_mulAccC(_pVk, IC36x, IC36y, calldataload(add(pubSignals, 1120)))
-
- g1_mulAccC(_pVk, IC37x, IC37y, calldataload(add(pubSignals, 1152)))
-
- g1_mulAccC(_pVk, IC38x, IC38y, calldataload(add(pubSignals, 1184)))
-
- g1_mulAccC(_pVk, IC39x, IC39y, calldataload(add(pubSignals, 1216)))
-
- g1_mulAccC(_pVk, IC40x, IC40y, calldataload(add(pubSignals, 1248)))
-
- g1_mulAccC(_pVk, IC41x, IC41y, calldataload(add(pubSignals, 1280)))
-
- g1_mulAccC(_pVk, IC42x, IC42y, calldataload(add(pubSignals, 1312)))
-
- g1_mulAccC(_pVk, IC43x, IC43y, calldataload(add(pubSignals, 1344)))
-
- g1_mulAccC(_pVk, IC44x, IC44y, calldataload(add(pubSignals, 1376)))
-
- g1_mulAccC(_pVk, IC45x, IC45y, calldataload(add(pubSignals, 1408)))
-
- g1_mulAccC(_pVk, IC46x, IC46y, calldataload(add(pubSignals, 1440)))
-
- g1_mulAccC(_pVk, IC47x, IC47y, calldataload(add(pubSignals, 1472)))
-
- g1_mulAccC(_pVk, IC48x, IC48y, calldataload(add(pubSignals, 1504)))
-
- g1_mulAccC(_pVk, IC49x, IC49y, calldataload(add(pubSignals, 1536)))
-
- g1_mulAccC(_pVk, IC50x, IC50y, calldataload(add(pubSignals, 1568)))
-
- g1_mulAccC(_pVk, IC51x, IC51y, calldataload(add(pubSignals, 1600)))
-
- g1_mulAccC(_pVk, IC52x, IC52y, calldataload(add(pubSignals, 1632)))
-
- g1_mulAccC(_pVk, IC53x, IC53y, calldataload(add(pubSignals, 1664)))
-
- g1_mulAccC(_pVk, IC54x, IC54y, calldataload(add(pubSignals, 1696)))
-
- g1_mulAccC(_pVk, IC55x, IC55y, calldataload(add(pubSignals, 1728)))
-
- g1_mulAccC(_pVk, IC56x, IC56y, calldataload(add(pubSignals, 1760)))
-
-
- // -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)))
-
- checkField(calldataload(add(_pubSignals, 800)))
-
- checkField(calldataload(add(_pubSignals, 832)))
-
- checkField(calldataload(add(_pubSignals, 864)))
-
- checkField(calldataload(add(_pubSignals, 896)))
-
- checkField(calldataload(add(_pubSignals, 928)))
-
- checkField(calldataload(add(_pubSignals, 960)))
-
- checkField(calldataload(add(_pubSignals, 992)))
-
- checkField(calldataload(add(_pubSignals, 1024)))
-
- checkField(calldataload(add(_pubSignals, 1056)))
-
- checkField(calldataload(add(_pubSignals, 1088)))
-
- checkField(calldataload(add(_pubSignals, 1120)))
-
- checkField(calldataload(add(_pubSignals, 1152)))
-
- checkField(calldataload(add(_pubSignals, 1184)))
-
- checkField(calldataload(add(_pubSignals, 1216)))
-
- checkField(calldataload(add(_pubSignals, 1248)))
-
- checkField(calldataload(add(_pubSignals, 1280)))
-
- checkField(calldataload(add(_pubSignals, 1312)))
-
- checkField(calldataload(add(_pubSignals, 1344)))
-
- checkField(calldataload(add(_pubSignals, 1376)))
-
- checkField(calldataload(add(_pubSignals, 1408)))
-
- checkField(calldataload(add(_pubSignals, 1440)))
-
- checkField(calldataload(add(_pubSignals, 1472)))
-
- checkField(calldataload(add(_pubSignals, 1504)))
-
- checkField(calldataload(add(_pubSignals, 1536)))
-
- checkField(calldataload(add(_pubSignals, 1568)))
-
- checkField(calldataload(add(_pubSignals, 1600)))
-
- checkField(calldataload(add(_pubSignals, 1632)))
-
- checkField(calldataload(add(_pubSignals, 1664)))
-
- checkField(calldataload(add(_pubSignals, 1696)))
-
- checkField(calldataload(add(_pubSignals, 1728)))
-
- checkField(calldataload(add(_pubSignals, 1760)))
-
- checkField(calldataload(add(_pubSignals, 1792)))
-
-
- // Validate all evaluations
- let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
-
- mstore(0, isValid)
- return(0, 0x20)
- }
- }
- }
diff --git a/packages/hardhat/deploy/00_deploy_your_contract.ts b/packages/hardhat/deploy/00_deploy_your_contract.ts
index 716fec7..68dfcab 100644
--- a/packages/hardhat/deploy/00_deploy_your_contract.ts
+++ b/packages/hardhat/deploy/00_deploy_your_contract.ts
@@ -1,6 +1,5 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
-import { Contract } from "ethers";
/**
* Deploys a contract named "YourContract" using the deployer account and
@@ -22,19 +21,19 @@ const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEn
const { deployer } = await hre.getNamedAccounts();
const { deploy } = hre.deployments;
+ await deploy("Poseidon", {
+ from: deployer,
+ log: true,
+ autoMine: true,
+ });
+
await deploy("YourContract", {
from: deployer,
- // Contract constructor arguments
- args: [deployer],
log: true,
// autoMine: can be passed to the deploy function to make the deployment process faster on local networks by
// automatically mining the contract deployment transaction. There is no effect on live networks.
autoMine: true,
});
-
- // Get the deployed contract to interact with it after deploying.
- const yourContract = await hre.ethers.getContract("YourContract", deployer);
- console.log("👋 Initial greeting:", await yourContract.greeting());
};
export default deployYourContract;
diff --git a/packages/nextjs/app/zpass/page.tsx b/packages/nextjs/app/zpass/page.tsx
index f0527c8..fce2150 100644
--- a/packages/nextjs/app/zpass/page.tsx
+++ b/packages/nextjs/app/zpass/page.tsx
@@ -8,6 +8,7 @@ import { ProtoPODGPC } from "@pcd/gpcircuits";
import { POD, PODEntries } from "@pcd/pod";
import { PartialDeep } from "type-fest";
import { useAccount } from "wagmi";
+import { useScaffoldContract } from "~~/hooks/scaffold-eth";
import { notification } from "~~/utils/scaffold-eth";
export interface PODData {
@@ -71,6 +72,10 @@ const ZuAuth = () => {
const { address: connectedAddress } = useAccount();
const [z, setZ] = useState(null);
+ const { data: YourContract } = useScaffoldContract({
+ contractName: "YourContract",
+ });
+
const handleAuth = async () => {
try {
if (!connectedAddress) return notification.error("Please connect your address");
@@ -127,11 +132,39 @@ const ZuAuth = () => {
const boundConfig = result.boundConfig;
const revealedClaims = result.revealedClaims;
console.log("The revealed claims", revealedClaims);
- console.log("The piA is", result.proof.pi);
+ console.log("The proof is:", result.proof);
const circuit = gpcPreVerify(boundConfig, revealedClaims);
const pubSignals = ProtoPODGPC.makePublicSignals(circuit.circuitPublicInputs, circuit.circuitOutputs);
console.log("The public signals", pubSignals);
+
+ console.log("The fields are:", revealedClaims.pods.FROGCRYPTO?.entries);
+
+ const beauty = revealedClaims.pods.FROGCRYPTO?.entries?.beauty.value as any as bigint;
+ const biome = revealedClaims.pods.FROGCRYPTO?.entries?.biome.value as any as bigint;
+ const intelligence = revealedClaims.pods.FROGCRYPTO?.entries?.intelligence.value as any as bigint;
+ const jump = revealedClaims.pods.FROGCRYPTO?.entries?.jump.value as any as bigint;
+ const speed = revealedClaims.pods.FROGCRYPTO?.entries?.speed.value as any as bigint;
+ const rarity = revealedClaims.pods.FROGCRYPTO?.entries?.rarity.value as any as bigint;
+ const owner = revealedClaims.pods.FROGCRYPTO?.entries?.owner.value as any as bigint;
+
+ const readResult = await YourContract?.read.verifyAndExtractFrog([
+ {
+ _pA: result.proof.pi_a.slice(0, -1),
+ _pB: result.proof.pi_b.slice(0, -1),
+ _pC: result.proof.pi_c.slice(0, -1),
+ _pubSignals: pubSignals as any,
+ },
+ beauty,
+ biome,
+ intelligence,
+ jump,
+ speed,
+ rarity,
+ owner,
+ ]);
+
+ console.log("The read result", readResult);
}
console.log("The result after the insert", result);
diff --git a/packages/nextjs/contracts/deployedContracts.ts b/packages/nextjs/contracts/deployedContracts.ts
index 008d4eb..49f3cec 100644
--- a/packages/nextjs/contracts/deployedContracts.ts
+++ b/packages/nextjs/contracts/deployedContracts.ts
@@ -4,6 +4,172 @@
*/
import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract";
-const deployedContracts = {} as const;
+const deployedContracts = {
+ 31337: {
+ Poseidon: {
+ address: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
+ abi: [
+ {
+ inputs: [
+ {
+ internalType: "uint256[1]",
+ name: "",
+ type: "uint256[1]",
+ },
+ ],
+ name: "hash",
+ outputs: [
+ {
+ internalType: "uint256",
+ name: "",
+ type: "uint256",
+ },
+ ],
+ stateMutability: "pure",
+ type: "function",
+ },
+ ],
+ inheritedFunctions: {},
+ },
+ YourContract: {
+ address: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
+ abi: [
+ {
+ inputs: [
+ {
+ internalType: "uint256[1]",
+ name: "",
+ type: "uint256[1]",
+ },
+ ],
+ name: "hash",
+ outputs: [
+ {
+ internalType: "uint256",
+ name: "",
+ type: "uint256",
+ },
+ ],
+ stateMutability: "pure",
+ type: "function",
+ },
+ {
+ inputs: [
+ {
+ components: [
+ {
+ internalType: "uint256[2]",
+ name: "_pA",
+ type: "uint256[2]",
+ },
+ {
+ internalType: "uint256[2][2]",
+ name: "_pB",
+ type: "uint256[2][2]",
+ },
+ {
+ internalType: "uint256[2]",
+ name: "_pC",
+ type: "uint256[2]",
+ },
+ {
+ internalType: "uint256[56]",
+ name: "_pubSignals",
+ type: "uint256[56]",
+ },
+ ],
+ internalType: "struct YourContract.ProofArgs",
+ name: "proof",
+ type: "tuple",
+ },
+ {
+ internalType: "uint256",
+ name: "beauty",
+ type: "uint256",
+ },
+ {
+ internalType: "uint256",
+ name: "biome",
+ type: "uint256",
+ },
+ {
+ internalType: "uint256",
+ name: "intelligence",
+ type: "uint256",
+ },
+ {
+ internalType: "uint256",
+ name: "jump",
+ type: "uint256",
+ },
+ {
+ internalType: "uint256",
+ name: "speed",
+ type: "uint256",
+ },
+ {
+ internalType: "uint256",
+ name: "rarity",
+ type: "uint256",
+ },
+ {
+ internalType: "uint256",
+ name: "owner",
+ type: "uint256",
+ },
+ ],
+ name: "verifyAndExtractFrog",
+ outputs: [
+ {
+ internalType: "bool",
+ name: "",
+ type: "bool",
+ },
+ ],
+ stateMutability: "view",
+ type: "function",
+ },
+ {
+ inputs: [
+ {
+ internalType: "uint256[2]",
+ name: "_pA",
+ type: "uint256[2]",
+ },
+ {
+ internalType: "uint256[2][2]",
+ name: "_pB",
+ type: "uint256[2][2]",
+ },
+ {
+ internalType: "uint256[2]",
+ name: "_pC",
+ type: "uint256[2]",
+ },
+ {
+ internalType: "uint256[56]",
+ name: "_pubSignals",
+ type: "uint256[56]",
+ },
+ ],
+ name: "verifyProof",
+ outputs: [
+ {
+ internalType: "bool",
+ name: "",
+ type: "bool",
+ },
+ ],
+ stateMutability: "view",
+ type: "function",
+ },
+ ],
+ inheritedFunctions: {
+ verifyProof: "contracts/Groth16Verifier.sol",
+ hash: "contracts/Poseidon.sol",
+ },
+ },
+ },
+} as const;
export default deployedContracts satisfies GenericContractsDeclaration;
diff --git a/packages/nextjs/scaffold.config.ts b/packages/nextjs/scaffold.config.ts
index fc23e89..86c737a 100644
--- a/packages/nextjs/scaffold.config.ts
+++ b/packages/nextjs/scaffold.config.ts
@@ -10,7 +10,7 @@ export type ScaffoldConfig = {
const scaffoldConfig = {
// The networks on which your DApp is live
- targetNetworks: [chains.mainnet],
+ targetNetworks: [chains.hardhat],
// The interval at which your front-end polls the RPC servers for new data
// it has no effect if you only target the local network (default is 4000)