1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | 423× 423× 423× 423× 423× 423× 423× 423× 423× 423× 423× 423× 423× 423× 423× 423× 423× 423× 423× 423× 423× 423× 423× 1269× 1269× 423× 423× | // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {Pairing} from '../libraries/Pairing.sol'; contract SignupVerifier { using Pairing for *; uint256 constant SNARK_SCALAR_FIELD = 21888242871839275222246405745257275088548364400416034343698204186575808495617; uint256 constant PRIME_Q = 21888242871839275222246405745257275088696311157297823662689037894645226208583; struct VerifyingKey { Pairing.G1Point alpha1; Pairing.G2Point beta2; Pairing.G2Point gamma2; Pairing.G2Point delta2; Pairing.G1Point[4] IC; } struct Proof { Pairing.G1Point A; Pairing.G2Point B; Pairing.G1Point C; } function verifyingKey() internal pure returns (VerifyingKey memory vk) { vk.alpha1 = Pairing.G1Point(uint256(20491192805390485299153009773594534940189261866228447918068658471970481763042),uint256(9383485363053290200918347156157836566562967994039712273449902621266178545958)); vk.beta2 = Pairing.G2Point([uint256(4252822878758300859123897981450591353533073413197771768651442665752259397132),uint256(6375614351688725206403948262868962793625744043794305715222011528459656738731)], [uint256(21847035105528745403288232691147584728191162732299865338377159692350059136679),uint256(10505242626370262277552901082094356697409835680220590971873171140371331206856)]); vk.gamma2 = Pairing.G2Point([uint256(11559732032986387107991004021392285783925812861821192530917403151452391805634),uint256(10857046999023057135944570762232829481370756359578518086990519993285655852781)], [uint256(4082367875863433681332203403145435568316851327593401208105741076214120093531),uint256(8495653923123431417604973247489272438418190587263600148770280649306958101930)]); vk.delta2 = Pairing.G2Point([uint256(2399621458313138061879370178413097452044914959351442645288182735086735695464),uint256(10207335199289346202475624003232253621126900895044784836692469526499653225568)], [uint256(8714646293167793824597108212947873374564821343087733224024333264402827767882),uint256(2162815149526733160314445361439913341296503298326688124858454881473488969508)]); vk.IC[0] = Pairing.G1Point(uint256(12036763950388616270781205821413594920716437089423542477312595029424823739931),uint256(1769583290303174666697002712070767193823086282130296620974688032463761027367)); vk.IC[1] = Pairing.G1Point(uint256(916815078463766422358192763205173747688565939596548452059532120280279066751),uint256(1655945753832713250321084199749355517520168832709544187018981189213726023002)); vk.IC[2] = Pairing.G1Point(uint256(3753397671745253290858518757261470900453097405107109836668429279997276220115),uint256(16878680333666397069542909218441752715473307747495617189727795221535631946484)); vk.IC[3] = Pairing.G1Point(uint256(14915449782829789574135744904892495008260306569526536483048220802382744413499),uint256(3726619472987257432399217503443146892320479331118606350467087591435353604044)); } /* * @returns Whether the proof is valid given the hardcoded verifying key * above and the public inputs */ function verifyProof( uint256[] calldata input, uint256[8] calldata _proof ) public view returns (bool) { Proof memory proof; proof.A = Pairing.G1Point(_proof[0], _proof[1]); proof.B = Pairing.G2Point([_proof[2], _proof[3]], [_proof[4], _proof[5]]); proof.C = Pairing.G1Point(_proof[6], _proof[7]); VerifyingKey memory vk = verifyingKey(); // Compute the linear combination vk_x Pairing.G1Point memory vk_x = Pairing.G1Point(0, 0); // Make sure that proof.A, B, and C are each less than the prime q Erequire(proof.A.X < PRIME_Q, "verifier-aX-gte-prime-q"); Erequire(proof.A.Y < PRIME_Q, "verifier-aY-gte-prime-q"); Erequire(proof.B.X[0] < PRIME_Q, "verifier-bX0-gte-prime-q"); Erequire(proof.B.Y[0] < PRIME_Q, "verifier-bY0-gte-prime-q"); Erequire(proof.B.X[1] < PRIME_Q, "verifier-bX1-gte-prime-q"); Erequire(proof.B.Y[1] < PRIME_Q, "verifier-bY1-gte-prime-q"); Erequire(proof.C.X < PRIME_Q, "verifier-cX-gte-prime-q"); Erequire(proof.C.Y < PRIME_Q, "verifier-cY-gte-prime-q"); // Make sure that every input is less than the snark scalar field //for (uint256 i = 0; i < input.length; i++) { for (uint256 i = 0; i < 3; i++) { Erequire(input[i] < SNARK_SCALAR_FIELD,"verifier-gte-snark-scalar-field"); vk_x = Pairing.plus(vk_x, Pairing.scalar_mul(vk.IC[i + 1], input[i])); } vk_x = Pairing.plus(vk_x, vk.IC[0]); return Pairing.pairing( Pairing.negate(proof.A), proof.B, vk.alpha1, vk.beta2, vk_x, vk.gamma2, proof.C, vk.delta2 ); } } |