mirror of
https://github.com/0xPARC/circom-starter.git
synced 2026-01-10 06:18:01 -05:00
chore: Remove contracts, but keep contracts dir with .gitsave
This commit is contained in:
0
contracts/.gitsave
Normal file
0
contracts/.gitsave
Normal file
@@ -1,256 +0,0 @@
|
||||
// THIS FILE IS GENERATED BY HARDHAT-CIRCOM. DO NOT EDIT THIS FILE.
|
||||
//
|
||||
// Copyright 2017 Christian Reitwiessner
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// 2019 OKIMS
|
||||
// ported to solidity 0.6
|
||||
// fixed linter warnings
|
||||
// added requiere error messages
|
||||
//
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.6.11;
|
||||
library Pairing {
|
||||
struct G1Point {
|
||||
uint X;
|
||||
uint Y;
|
||||
}
|
||||
// Encoding of field elements is: X[0] * z + X[1]
|
||||
struct G2Point {
|
||||
uint[2] X;
|
||||
uint[2] Y;
|
||||
}
|
||||
/// @return the generator of G1
|
||||
function P1() internal pure returns (G1Point memory) {
|
||||
return G1Point(1, 2);
|
||||
}
|
||||
/// @return the generator of G2
|
||||
function P2() internal pure returns (G2Point memory) {
|
||||
// Original code point
|
||||
return G2Point(
|
||||
[11559732032986387107991004021392285783925812861821192530917403151452391805634,
|
||||
10857046999023057135944570762232829481370756359578518086990519993285655852781],
|
||||
[4082367875863433681332203403145435568316851327593401208105741076214120093531,
|
||||
8495653923123431417604973247489272438418190587263600148770280649306958101930]
|
||||
);
|
||||
|
||||
/*
|
||||
// Changed by Jordi point
|
||||
return G2Point(
|
||||
[10857046999023057135944570762232829481370756359578518086990519993285655852781,
|
||||
11559732032986387107991004021392285783925812861821192530917403151452391805634],
|
||||
[8495653923123431417604973247489272438418190587263600148770280649306958101930,
|
||||
4082367875863433681332203403145435568316851327593401208105741076214120093531]
|
||||
);
|
||||
*/
|
||||
}
|
||||
/// @return r the negation of p, i.e. p.addition(p.negate()) should be zero.
|
||||
function negate(G1Point memory p) internal pure returns (G1Point memory r) {
|
||||
// The prime q in the base field F_q for G1
|
||||
uint q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
|
||||
if (p.X == 0 && p.Y == 0)
|
||||
return G1Point(0, 0);
|
||||
return G1Point(p.X, q - (p.Y % q));
|
||||
}
|
||||
/// @return r the sum of two points of G1
|
||||
function addition(G1Point memory p1, G1Point memory p2) internal view returns (G1Point memory r) {
|
||||
uint[4] memory input;
|
||||
input[0] = p1.X;
|
||||
input[1] = p1.Y;
|
||||
input[2] = p2.X;
|
||||
input[3] = p2.Y;
|
||||
bool success;
|
||||
// solium-disable-next-line security/no-inline-assembly
|
||||
assembly {
|
||||
success := staticcall(sub(gas(), 2000), 6, input, 0xc0, r, 0x60)
|
||||
// Use "invalid" to make gas estimation work
|
||||
switch success case 0 { invalid() }
|
||||
}
|
||||
require(success,"pairing-add-failed");
|
||||
}
|
||||
/// @return r the product of a point on G1 and a scalar, i.e.
|
||||
/// p == p.scalar_mul(1) and p.addition(p) == p.scalar_mul(2) for all points p.
|
||||
function scalar_mul(G1Point memory p, uint s) internal view returns (G1Point memory r) {
|
||||
uint[3] memory input;
|
||||
input[0] = p.X;
|
||||
input[1] = p.Y;
|
||||
input[2] = s;
|
||||
bool success;
|
||||
// solium-disable-next-line security/no-inline-assembly
|
||||
assembly {
|
||||
success := staticcall(sub(gas(), 2000), 7, input, 0x80, r, 0x60)
|
||||
// Use "invalid" to make gas estimation work
|
||||
switch success case 0 { invalid() }
|
||||
}
|
||||
require (success,"pairing-mul-failed");
|
||||
}
|
||||
/// @return the result of computing the pairing check
|
||||
/// e(p1[0], p2[0]) * .... * e(p1[n], p2[n]) == 1
|
||||
/// For example pairing([P1(), P1().negate()], [P2(), P2()]) should
|
||||
/// return true.
|
||||
function pairing(G1Point[] memory p1, G2Point[] memory p2) internal view returns (bool) {
|
||||
require(p1.length == p2.length,"pairing-lengths-failed");
|
||||
uint elements = p1.length;
|
||||
uint inputSize = elements * 6;
|
||||
uint[] memory input = new uint[](inputSize);
|
||||
for (uint i = 0; i < elements; i++)
|
||||
{
|
||||
input[i * 6 + 0] = p1[i].X;
|
||||
input[i * 6 + 1] = p1[i].Y;
|
||||
input[i * 6 + 2] = p2[i].X[0];
|
||||
input[i * 6 + 3] = p2[i].X[1];
|
||||
input[i * 6 + 4] = p2[i].Y[0];
|
||||
input[i * 6 + 5] = p2[i].Y[1];
|
||||
}
|
||||
uint[1] memory out;
|
||||
bool success;
|
||||
// solium-disable-next-line security/no-inline-assembly
|
||||
assembly {
|
||||
success := staticcall(sub(gas(), 2000), 8, add(input, 0x20), mul(inputSize, 0x20), out, 0x20)
|
||||
// Use "invalid" to make gas estimation work
|
||||
switch success case 0 { invalid() }
|
||||
}
|
||||
require(success,"pairing-opcode-failed");
|
||||
return out[0] != 0;
|
||||
}
|
||||
/// Convenience method for a pairing check for two pairs.
|
||||
function pairingProd2(G1Point memory a1, G2Point memory a2, G1Point memory b1, G2Point memory b2) internal view returns (bool) {
|
||||
G1Point[] memory p1 = new G1Point[](2);
|
||||
G2Point[] memory p2 = new G2Point[](2);
|
||||
p1[0] = a1;
|
||||
p1[1] = b1;
|
||||
p2[0] = a2;
|
||||
p2[1] = b2;
|
||||
return pairing(p1, p2);
|
||||
}
|
||||
/// Convenience method for a pairing check for three pairs.
|
||||
function pairingProd3(
|
||||
G1Point memory a1, G2Point memory a2,
|
||||
G1Point memory b1, G2Point memory b2,
|
||||
G1Point memory c1, G2Point memory c2
|
||||
) internal view returns (bool) {
|
||||
G1Point[] memory p1 = new G1Point[](3);
|
||||
G2Point[] memory p2 = new G2Point[](3);
|
||||
p1[0] = a1;
|
||||
p1[1] = b1;
|
||||
p1[2] = c1;
|
||||
p2[0] = a2;
|
||||
p2[1] = b2;
|
||||
p2[2] = c2;
|
||||
return pairing(p1, p2);
|
||||
}
|
||||
/// Convenience method for a pairing check for four pairs.
|
||||
function pairingProd4(
|
||||
G1Point memory a1, G2Point memory a2,
|
||||
G1Point memory b1, G2Point memory b2,
|
||||
G1Point memory c1, G2Point memory c2,
|
||||
G1Point memory d1, G2Point memory d2
|
||||
) internal view returns (bool) {
|
||||
G1Point[] memory p1 = new G1Point[](4);
|
||||
G2Point[] memory p2 = new G2Point[](4);
|
||||
p1[0] = a1;
|
||||
p1[1] = b1;
|
||||
p1[2] = c1;
|
||||
p1[3] = d1;
|
||||
p2[0] = a2;
|
||||
p2[1] = b2;
|
||||
p2[2] = c2;
|
||||
p2[3] = d2;
|
||||
return pairing(p1, p2);
|
||||
}
|
||||
}
|
||||
contract Verifier {
|
||||
using Pairing for *;
|
||||
struct VerifyingKey {
|
||||
Pairing.G1Point alfa1;
|
||||
Pairing.G2Point beta2;
|
||||
Pairing.G2Point gamma2;
|
||||
Pairing.G2Point delta2;
|
||||
Pairing.G1Point[] IC;
|
||||
}
|
||||
struct Proof {
|
||||
Pairing.G1Point A;
|
||||
Pairing.G2Point B;
|
||||
Pairing.G1Point C;
|
||||
}
|
||||
function verifyingKey() internal pure returns (VerifyingKey memory vk) {
|
||||
vk.alfa1 = Pairing.G1Point(
|
||||
19642524115522290447760970021746675789341356000653265441069630957431566301675,
|
||||
15809037446102219312954435152879098683824559980020626143453387822004586242317
|
||||
);
|
||||
|
||||
vk.beta2 = Pairing.G2Point(
|
||||
[6402738102853475583969787773506197858266321704623454181848954418090577674938,
|
||||
3306678135584565297353192801602995509515651571902196852074598261262327790404],
|
||||
[15158588411628049902562758796812667714664232742372443470614751812018801551665,
|
||||
4983765881427969364617654516554524254158908221590807345159959200407712579883]
|
||||
);
|
||||
vk.gamma2 = Pairing.G2Point(
|
||||
[11559732032986387107991004021392285783925812861821192530917403151452391805634,
|
||||
10857046999023057135944570762232829481370756359578518086990519993285655852781],
|
||||
[4082367875863433681332203403145435568316851327593401208105741076214120093531,
|
||||
8495653923123431417604973247489272438418190587263600148770280649306958101930]
|
||||
);
|
||||
vk.delta2 = Pairing.G2Point(
|
||||
[21173502052847522712343920695345049565520895905384250222105697507142194555901,
|
||||
2331074035208661256364667123862169704061449951851910379325063964198285430221],
|
||||
[1921085277078744684511176971830319952173319902281081603728474458216922605612,
|
||||
961901284356507153388088069199380552581103880001797976871193700998289486054]
|
||||
);
|
||||
vk.IC = new Pairing.G1Point[](2);
|
||||
|
||||
vk.IC[0] = Pairing.G1Point(
|
||||
3407264785759550586251917451809529842095502987998074222712950333611623480315,
|
||||
17614032285308637827589011536778700256571656917618352650614636413693719882653
|
||||
);
|
||||
|
||||
vk.IC[1] = Pairing.G1Point(
|
||||
6030549779562341043946440450999173091466246051887477277062872529880415484328,
|
||||
2201862661646432387516643227410841049878957913402627253351769249213694925553
|
||||
);
|
||||
|
||||
}
|
||||
function verify(uint[] memory input, Proof memory proof) internal view returns (uint) {
|
||||
uint256 snark_scalar_field = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
|
||||
VerifyingKey memory vk = verifyingKey();
|
||||
require(input.length + 1 == vk.IC.length,"verifier-bad-input");
|
||||
// Compute the linear combination vk_x
|
||||
Pairing.G1Point memory vk_x = Pairing.G1Point(0, 0);
|
||||
for (uint i = 0; i < input.length; i++) {
|
||||
require(input[i] < snark_scalar_field,"verifier-gte-snark-scalar-field");
|
||||
vk_x = Pairing.addition(vk_x, Pairing.scalar_mul(vk.IC[i + 1], input[i]));
|
||||
}
|
||||
vk_x = Pairing.addition(vk_x, vk.IC[0]);
|
||||
if (!Pairing.pairingProd4(
|
||||
Pairing.negate(proof.A), proof.B,
|
||||
vk.alfa1, vk.beta2,
|
||||
vk_x, vk.gamma2,
|
||||
proof.C, vk.delta2
|
||||
)) return 1;
|
||||
return 0;
|
||||
}
|
||||
/// @return r bool true if proof is valid
|
||||
function verifyProof(
|
||||
uint[2] memory a,
|
||||
uint[2][2] memory b,
|
||||
uint[2] memory c,
|
||||
uint[1] memory input
|
||||
) public view returns (bool r) {
|
||||
Proof memory proof;
|
||||
proof.A = Pairing.G1Point(a[0], a[1]);
|
||||
proof.B = Pairing.G2Point([b[0][0], b[0][1]], [b[1][0], b[1][1]]);
|
||||
proof.C = Pairing.G1Point(c[0], c[1]);
|
||||
uint[] memory inputValues = new uint[](input.length);
|
||||
for(uint i = 0; i < input.length; i++){
|
||||
inputValues[i] = input[i];
|
||||
}
|
||||
if (verify(inputValues, proof) == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,256 +0,0 @@
|
||||
// THIS FILE IS GENERATED BY HARDHAT-CIRCOM. DO NOT EDIT THIS FILE.
|
||||
//
|
||||
// Copyright 2017 Christian Reitwiessner
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// 2019 OKIMS
|
||||
// ported to solidity 0.6
|
||||
// fixed linter warnings
|
||||
// added requiere error messages
|
||||
//
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.6.11;
|
||||
library Pairing {
|
||||
struct G1Point {
|
||||
uint X;
|
||||
uint Y;
|
||||
}
|
||||
// Encoding of field elements is: X[0] * z + X[1]
|
||||
struct G2Point {
|
||||
uint[2] X;
|
||||
uint[2] Y;
|
||||
}
|
||||
/// @return the generator of G1
|
||||
function P1() internal pure returns (G1Point memory) {
|
||||
return G1Point(1, 2);
|
||||
}
|
||||
/// @return the generator of G2
|
||||
function P2() internal pure returns (G2Point memory) {
|
||||
// Original code point
|
||||
return G2Point(
|
||||
[11559732032986387107991004021392285783925812861821192530917403151452391805634,
|
||||
10857046999023057135944570762232829481370756359578518086990519993285655852781],
|
||||
[4082367875863433681332203403145435568316851327593401208105741076214120093531,
|
||||
8495653923123431417604973247489272438418190587263600148770280649306958101930]
|
||||
);
|
||||
|
||||
/*
|
||||
// Changed by Jordi point
|
||||
return G2Point(
|
||||
[10857046999023057135944570762232829481370756359578518086990519993285655852781,
|
||||
11559732032986387107991004021392285783925812861821192530917403151452391805634],
|
||||
[8495653923123431417604973247489272438418190587263600148770280649306958101930,
|
||||
4082367875863433681332203403145435568316851327593401208105741076214120093531]
|
||||
);
|
||||
*/
|
||||
}
|
||||
/// @return r the negation of p, i.e. p.addition(p.negate()) should be zero.
|
||||
function negate(G1Point memory p) internal pure returns (G1Point memory r) {
|
||||
// The prime q in the base field F_q for G1
|
||||
uint q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
|
||||
if (p.X == 0 && p.Y == 0)
|
||||
return G1Point(0, 0);
|
||||
return G1Point(p.X, q - (p.Y % q));
|
||||
}
|
||||
/// @return r the sum of two points of G1
|
||||
function addition(G1Point memory p1, G1Point memory p2) internal view returns (G1Point memory r) {
|
||||
uint[4] memory input;
|
||||
input[0] = p1.X;
|
||||
input[1] = p1.Y;
|
||||
input[2] = p2.X;
|
||||
input[3] = p2.Y;
|
||||
bool success;
|
||||
// solium-disable-next-line security/no-inline-assembly
|
||||
assembly {
|
||||
success := staticcall(sub(gas(), 2000), 6, input, 0xc0, r, 0x60)
|
||||
// Use "invalid" to make gas estimation work
|
||||
switch success case 0 { invalid() }
|
||||
}
|
||||
require(success,"pairing-add-failed");
|
||||
}
|
||||
/// @return r the product of a point on G1 and a scalar, i.e.
|
||||
/// p == p.scalar_mul(1) and p.addition(p) == p.scalar_mul(2) for all points p.
|
||||
function scalar_mul(G1Point memory p, uint s) internal view returns (G1Point memory r) {
|
||||
uint[3] memory input;
|
||||
input[0] = p.X;
|
||||
input[1] = p.Y;
|
||||
input[2] = s;
|
||||
bool success;
|
||||
// solium-disable-next-line security/no-inline-assembly
|
||||
assembly {
|
||||
success := staticcall(sub(gas(), 2000), 7, input, 0x80, r, 0x60)
|
||||
// Use "invalid" to make gas estimation work
|
||||
switch success case 0 { invalid() }
|
||||
}
|
||||
require (success,"pairing-mul-failed");
|
||||
}
|
||||
/// @return the result of computing the pairing check
|
||||
/// e(p1[0], p2[0]) * .... * e(p1[n], p2[n]) == 1
|
||||
/// For example pairing([P1(), P1().negate()], [P2(), P2()]) should
|
||||
/// return true.
|
||||
function pairing(G1Point[] memory p1, G2Point[] memory p2) internal view returns (bool) {
|
||||
require(p1.length == p2.length,"pairing-lengths-failed");
|
||||
uint elements = p1.length;
|
||||
uint inputSize = elements * 6;
|
||||
uint[] memory input = new uint[](inputSize);
|
||||
for (uint i = 0; i < elements; i++)
|
||||
{
|
||||
input[i * 6 + 0] = p1[i].X;
|
||||
input[i * 6 + 1] = p1[i].Y;
|
||||
input[i * 6 + 2] = p2[i].X[0];
|
||||
input[i * 6 + 3] = p2[i].X[1];
|
||||
input[i * 6 + 4] = p2[i].Y[0];
|
||||
input[i * 6 + 5] = p2[i].Y[1];
|
||||
}
|
||||
uint[1] memory out;
|
||||
bool success;
|
||||
// solium-disable-next-line security/no-inline-assembly
|
||||
assembly {
|
||||
success := staticcall(sub(gas(), 2000), 8, add(input, 0x20), mul(inputSize, 0x20), out, 0x20)
|
||||
// Use "invalid" to make gas estimation work
|
||||
switch success case 0 { invalid() }
|
||||
}
|
||||
require(success,"pairing-opcode-failed");
|
||||
return out[0] != 0;
|
||||
}
|
||||
/// Convenience method for a pairing check for two pairs.
|
||||
function pairingProd2(G1Point memory a1, G2Point memory a2, G1Point memory b1, G2Point memory b2) internal view returns (bool) {
|
||||
G1Point[] memory p1 = new G1Point[](2);
|
||||
G2Point[] memory p2 = new G2Point[](2);
|
||||
p1[0] = a1;
|
||||
p1[1] = b1;
|
||||
p2[0] = a2;
|
||||
p2[1] = b2;
|
||||
return pairing(p1, p2);
|
||||
}
|
||||
/// Convenience method for a pairing check for three pairs.
|
||||
function pairingProd3(
|
||||
G1Point memory a1, G2Point memory a2,
|
||||
G1Point memory b1, G2Point memory b2,
|
||||
G1Point memory c1, G2Point memory c2
|
||||
) internal view returns (bool) {
|
||||
G1Point[] memory p1 = new G1Point[](3);
|
||||
G2Point[] memory p2 = new G2Point[](3);
|
||||
p1[0] = a1;
|
||||
p1[1] = b1;
|
||||
p1[2] = c1;
|
||||
p2[0] = a2;
|
||||
p2[1] = b2;
|
||||
p2[2] = c2;
|
||||
return pairing(p1, p2);
|
||||
}
|
||||
/// Convenience method for a pairing check for four pairs.
|
||||
function pairingProd4(
|
||||
G1Point memory a1, G2Point memory a2,
|
||||
G1Point memory b1, G2Point memory b2,
|
||||
G1Point memory c1, G2Point memory c2,
|
||||
G1Point memory d1, G2Point memory d2
|
||||
) internal view returns (bool) {
|
||||
G1Point[] memory p1 = new G1Point[](4);
|
||||
G2Point[] memory p2 = new G2Point[](4);
|
||||
p1[0] = a1;
|
||||
p1[1] = b1;
|
||||
p1[2] = c1;
|
||||
p1[3] = d1;
|
||||
p2[0] = a2;
|
||||
p2[1] = b2;
|
||||
p2[2] = c2;
|
||||
p2[3] = d2;
|
||||
return pairing(p1, p2);
|
||||
}
|
||||
}
|
||||
contract Verifier {
|
||||
using Pairing for *;
|
||||
struct VerifyingKey {
|
||||
Pairing.G1Point alfa1;
|
||||
Pairing.G2Point beta2;
|
||||
Pairing.G2Point gamma2;
|
||||
Pairing.G2Point delta2;
|
||||
Pairing.G1Point[] IC;
|
||||
}
|
||||
struct Proof {
|
||||
Pairing.G1Point A;
|
||||
Pairing.G2Point B;
|
||||
Pairing.G1Point C;
|
||||
}
|
||||
function verifyingKey() internal pure returns (VerifyingKey memory vk) {
|
||||
vk.alfa1 = Pairing.G1Point(
|
||||
19642524115522290447760970021746675789341356000653265441069630957431566301675,
|
||||
15809037446102219312954435152879098683824559980020626143453387822004586242317
|
||||
);
|
||||
|
||||
vk.beta2 = Pairing.G2Point(
|
||||
[6402738102853475583969787773506197858266321704623454181848954418090577674938,
|
||||
3306678135584565297353192801602995509515651571902196852074598261262327790404],
|
||||
[15158588411628049902562758796812667714664232742372443470614751812018801551665,
|
||||
4983765881427969364617654516554524254158908221590807345159959200407712579883]
|
||||
);
|
||||
vk.gamma2 = Pairing.G2Point(
|
||||
[11559732032986387107991004021392285783925812861821192530917403151452391805634,
|
||||
10857046999023057135944570762232829481370756359578518086990519993285655852781],
|
||||
[4082367875863433681332203403145435568316851327593401208105741076214120093531,
|
||||
8495653923123431417604973247489272438418190587263600148770280649306958101930]
|
||||
);
|
||||
vk.delta2 = Pairing.G2Point(
|
||||
[21173502052847522712343920695345049565520895905384250222105697507142194555901,
|
||||
2331074035208661256364667123862169704061449951851910379325063964198285430221],
|
||||
[1921085277078744684511176971830319952173319902281081603728474458216922605612,
|
||||
961901284356507153388088069199380552581103880001797976871193700998289486054]
|
||||
);
|
||||
vk.IC = new Pairing.G1Point[](2);
|
||||
|
||||
vk.IC[0] = Pairing.G1Point(
|
||||
17176243299325047002382641914833309420655309960032511883676445797846608206106,
|
||||
9411904849838109154417627445648736822940776967919463658338903433027488353845
|
||||
);
|
||||
|
||||
vk.IC[1] = Pairing.G1Point(
|
||||
11125656666810885015334465820227931512643625400388443378156768365210358235302,
|
||||
14959371672074438883833746157839955569079060798119972633022460689980435457426
|
||||
);
|
||||
|
||||
}
|
||||
function verify(uint[] memory input, Proof memory proof) internal view returns (uint) {
|
||||
uint256 snark_scalar_field = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
|
||||
VerifyingKey memory vk = verifyingKey();
|
||||
require(input.length + 1 == vk.IC.length,"verifier-bad-input");
|
||||
// Compute the linear combination vk_x
|
||||
Pairing.G1Point memory vk_x = Pairing.G1Point(0, 0);
|
||||
for (uint i = 0; i < input.length; i++) {
|
||||
require(input[i] < snark_scalar_field,"verifier-gte-snark-scalar-field");
|
||||
vk_x = Pairing.addition(vk_x, Pairing.scalar_mul(vk.IC[i + 1], input[i]));
|
||||
}
|
||||
vk_x = Pairing.addition(vk_x, vk.IC[0]);
|
||||
if (!Pairing.pairingProd4(
|
||||
Pairing.negate(proof.A), proof.B,
|
||||
vk.alfa1, vk.beta2,
|
||||
vk_x, vk.gamma2,
|
||||
proof.C, vk.delta2
|
||||
)) return 1;
|
||||
return 0;
|
||||
}
|
||||
/// @return r bool true if proof is valid
|
||||
function verifyProof(
|
||||
uint[2] memory a,
|
||||
uint[2][2] memory b,
|
||||
uint[2] memory c,
|
||||
uint[1] memory input
|
||||
) public view returns (bool r) {
|
||||
Proof memory proof;
|
||||
proof.A = Pairing.G1Point(a[0], a[1]);
|
||||
proof.B = Pairing.G2Point([b[0][0], b[0][1]], [b[1][0], b[1][1]]);
|
||||
proof.C = Pairing.G1Point(c[0], c[1]);
|
||||
uint[] memory inputValues = new uint[](input.length);
|
||||
for(uint i = 0; i < input.length; i++){
|
||||
inputValues[i] = input[i];
|
||||
}
|
||||
if (verify(inputValues, proof) == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,620 +0,0 @@
|
||||
// THIS FILE IS GENERATED BY HARDHAT-CIRCOM. DO NOT EDIT THIS FILE.
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
/*
|
||||
Copyright 2021 0KIMS association.
|
||||
|
||||
This file is generated with [snarkJS](https://github.com/iden3/snarkjs).
|
||||
|
||||
snarkJS is a free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
snarkJS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with snarkJS. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
pragma solidity >=0.7.0 <0.9.0;
|
||||
|
||||
contract PlonkVerifier {
|
||||
|
||||
uint32 constant n = 8;
|
||||
uint16 constant nPublic = 1;
|
||||
uint16 constant nLagrange = 1;
|
||||
|
||||
uint256 constant Qmx = 3869630722971334225219837799029550508555131868827626912954255106543354712181;
|
||||
uint256 constant Qmy = 15731966387658877981703847803986494364438318826620673107047229118597284643111;
|
||||
uint256 constant Qlx = 13469885934562408630237968693772740012850184211199888084279389645972854857393;
|
||||
uint256 constant Qly = 20878943816188522830511299675341842415291572165357599904091526683109492812369;
|
||||
uint256 constant Qrx = 702350421402547822449810764334702522428124373959400773249481126958406939229;
|
||||
uint256 constant Qry = 7174202440176115649533603655367080041497497361304020407254157049212749604212;
|
||||
uint256 constant Qox = 17192482843019148457118502840511753335456501983453269453964368936053099994837;
|
||||
uint256 constant Qoy = 2164248219846880058580896366671116745524422292429897789351497850725778381088;
|
||||
uint256 constant Qcx = 14543317047630059610403962375536311834994771738707466911380655542462843889617;
|
||||
uint256 constant Qcy = 8474248672172342938108927648680289817943442201888769022971667269854720911908;
|
||||
uint256 constant S1x = 9206476714321107248459623260369230605065707770167573930481308199111167054360;
|
||||
uint256 constant S1y = 19214755705943170279720072969917648373823914194696296360040364383064098344548;
|
||||
uint256 constant S2x = 4061169991170635519484763497492054598600705446016296924413571951445298471586;
|
||||
uint256 constant S2y = 21118027326176372141352860389792627470936668345156661348749610317833214157252;
|
||||
uint256 constant S3x = 15979242314152405906512636343963653421232356714573063650582647837352772693986;
|
||||
uint256 constant S3y = 2703602879426155648125250267051115224457747763173036127602685165703730725405;
|
||||
uint256 constant k1 = 2;
|
||||
uint256 constant k2 = 3;
|
||||
uint256 constant X2x1 = 25371767501386700733739666027300007254391205882649405593008021034394568017;
|
||||
uint256 constant X2x2 = 20552802653835762701566092147783398794197494797795960746156975405114345301053;
|
||||
uint256 constant X2y1 = 2266120633678021302014656257350974309057341224963939183228127670535321017674;
|
||||
uint256 constant X2y2 = 12090959839781887596179323019902846185176620526038246046210700429454346640259;
|
||||
|
||||
uint256 constant q = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
|
||||
uint256 constant qf = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
|
||||
uint256 constant w1 = 19540430494807482326159819597004422086093766032135589407132600596362845576832;
|
||||
|
||||
uint256 constant G1x = 1;
|
||||
uint256 constant G1y = 2;
|
||||
uint256 constant G2x1 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
|
||||
uint256 constant G2x2 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
|
||||
uint256 constant G2y1 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
|
||||
uint256 constant G2y2 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
|
||||
uint16 constant pA = 32;
|
||||
uint16 constant pB = 96;
|
||||
uint16 constant pC = 160;
|
||||
uint16 constant pZ = 224;
|
||||
uint16 constant pT1 = 288;
|
||||
uint16 constant pT2 = 352;
|
||||
uint16 constant pT3 = 416;
|
||||
uint16 constant pWxi = 480;
|
||||
uint16 constant pWxiw = 544;
|
||||
uint16 constant pEval_a = 608;
|
||||
uint16 constant pEval_b = 640;
|
||||
uint16 constant pEval_c = 672;
|
||||
uint16 constant pEval_s1 = 704;
|
||||
uint16 constant pEval_s2 = 736;
|
||||
uint16 constant pEval_zw = 768;
|
||||
uint16 constant pEval_r = 800;
|
||||
|
||||
uint16 constant pAlpha = 0;
|
||||
uint16 constant pBeta = 32;
|
||||
uint16 constant pGamma = 64;
|
||||
uint16 constant pXi = 96;
|
||||
uint16 constant pXin = 128;
|
||||
uint16 constant pBetaXi = 160;
|
||||
uint16 constant pV1 = 192;
|
||||
uint16 constant pV2 = 224;
|
||||
uint16 constant pV3 = 256;
|
||||
uint16 constant pV4 = 288;
|
||||
uint16 constant pV5 = 320;
|
||||
uint16 constant pV6 = 352;
|
||||
uint16 constant pU = 384;
|
||||
uint16 constant pPl = 416;
|
||||
uint16 constant pEval_t = 448;
|
||||
uint16 constant pA1 = 480;
|
||||
uint16 constant pB1 = 544;
|
||||
uint16 constant pZh = 608;
|
||||
uint16 constant pZhInv = 640;
|
||||
|
||||
uint16 constant pEval_l1 = 672;
|
||||
|
||||
|
||||
|
||||
uint16 constant lastMem = 704;
|
||||
|
||||
|
||||
function verifyProof(bytes memory proof, uint[] memory pubSignals) public view returns (bool) {
|
||||
assembly {
|
||||
/////////
|
||||
// Computes the inverse using the extended euclidean algorithm
|
||||
/////////
|
||||
function inverse(a, q) -> inv {
|
||||
let t := 0
|
||||
let newt := 1
|
||||
let r := q
|
||||
let newr := a
|
||||
let quotient
|
||||
let aux
|
||||
|
||||
for { } newr { } {
|
||||
quotient := sdiv(r, newr)
|
||||
aux := sub(t, mul(quotient, newt))
|
||||
t:= newt
|
||||
newt:= aux
|
||||
|
||||
aux := sub(r,mul(quotient, newr))
|
||||
r := newr
|
||||
newr := aux
|
||||
}
|
||||
|
||||
if gt(r, 1) { revert(0,0) }
|
||||
if slt(t, 0) { t:= add(t, q) }
|
||||
|
||||
inv := t
|
||||
}
|
||||
|
||||
///////
|
||||
// Computes the inverse of an array of values
|
||||
// See https://vitalik.ca/general/2018/07/21/starks_part_3.html in section where explain fields operations
|
||||
//////
|
||||
function inverseArray(pVals, n) {
|
||||
|
||||
let pAux := mload(0x40) // Point to the next free position
|
||||
let pIn := pVals
|
||||
let lastPIn := add(pVals, mul(n, 32)) // Read n elemnts
|
||||
let acc := mload(pIn) // Read the first element
|
||||
pIn := add(pIn, 32) // Point to the second element
|
||||
let inv
|
||||
|
||||
|
||||
for { } lt(pIn, lastPIn) {
|
||||
pAux := add(pAux, 32)
|
||||
pIn := add(pIn, 32)
|
||||
}
|
||||
{
|
||||
mstore(pAux, acc)
|
||||
acc := mulmod(acc, mload(pIn), q)
|
||||
}
|
||||
acc := inverse(acc, q)
|
||||
|
||||
// At this point pAux pint to the next free position we substract 1 to point to the last used
|
||||
pAux := sub(pAux, 32)
|
||||
// pIn points to the n+1 element, we substract to point to n
|
||||
pIn := sub(pIn, 32)
|
||||
lastPIn := pVals // We don't process the first element
|
||||
for { } gt(pIn, lastPIn) {
|
||||
pAux := sub(pAux, 32)
|
||||
pIn := sub(pIn, 32)
|
||||
}
|
||||
{
|
||||
inv := mulmod(acc, mload(pAux), q)
|
||||
acc := mulmod(acc, mload(pIn), q)
|
||||
mstore(pIn, inv)
|
||||
}
|
||||
// pIn points to first element, we just set it.
|
||||
mstore(pIn, acc)
|
||||
}
|
||||
|
||||
function checkField(v) {
|
||||
if iszero(lt(v, q)) {
|
||||
mstore(0, 0)
|
||||
return(0,0x20)
|
||||
}
|
||||
}
|
||||
|
||||
function checkInput(pProof) {
|
||||
if iszero(eq(mload(pProof), 800 )) {
|
||||
mstore(0, 0)
|
||||
return(0,0x20)
|
||||
}
|
||||
checkField(mload(add(pProof, pEval_a)))
|
||||
checkField(mload(add(pProof, pEval_b)))
|
||||
checkField(mload(add(pProof, pEval_c)))
|
||||
checkField(mload(add(pProof, pEval_s1)))
|
||||
checkField(mload(add(pProof, pEval_s2)))
|
||||
checkField(mload(add(pProof, pEval_zw)))
|
||||
checkField(mload(add(pProof, pEval_r)))
|
||||
|
||||
// Points are checked in the point operations precompiled smart contracts
|
||||
}
|
||||
|
||||
function calculateChallanges(pProof, pMem) {
|
||||
|
||||
let a
|
||||
let b
|
||||
|
||||
b := mod(keccak256(add(pProof, pA), 192), q)
|
||||
mstore( add(pMem, pBeta), b)
|
||||
mstore( add(pMem, pGamma), mod(keccak256(add(pMem, pBeta), 32), q))
|
||||
mstore( add(pMem, pAlpha), mod(keccak256(add(pProof, pZ), 64), q))
|
||||
|
||||
a := mod(keccak256(add(pProof, pT1), 192), q)
|
||||
mstore( add(pMem, pXi), a)
|
||||
mstore( add(pMem, pBetaXi), mulmod(b, a, q))
|
||||
|
||||
a:= mulmod(a, a, q)
|
||||
|
||||
a:= mulmod(a, a, q)
|
||||
|
||||
a:= mulmod(a, a, q)
|
||||
|
||||
mstore( add(pMem, pXin), a)
|
||||
a:= mod(add(sub(a, 1),q), q)
|
||||
mstore( add(pMem, pZh), a)
|
||||
mstore( add(pMem, pZhInv), a) // We will invert later together with lagrange pols
|
||||
|
||||
let v1 := mod(keccak256(add(pProof, pEval_a), 224), q)
|
||||
mstore( add(pMem, pV1), v1)
|
||||
a := mulmod(v1, v1, q)
|
||||
mstore( add(pMem, pV2), a)
|
||||
a := mulmod(a, v1, q)
|
||||
mstore( add(pMem, pV3), a)
|
||||
a := mulmod(a, v1, q)
|
||||
mstore( add(pMem, pV4), a)
|
||||
a := mulmod(a, v1, q)
|
||||
mstore( add(pMem, pV5), a)
|
||||
a := mulmod(a, v1, q)
|
||||
mstore( add(pMem, pV6), a)
|
||||
|
||||
mstore( add(pMem, pU), mod(keccak256(add(pProof, pWxi), 128), q))
|
||||
}
|
||||
|
||||
function calculateLagrange(pMem) {
|
||||
|
||||
let w := 1
|
||||
|
||||
mstore(
|
||||
add(pMem, pEval_l1),
|
||||
mulmod(
|
||||
n,
|
||||
mod(
|
||||
add(
|
||||
sub(
|
||||
mload(add(pMem, pXi)),
|
||||
w
|
||||
),
|
||||
q
|
||||
),
|
||||
q
|
||||
),
|
||||
q
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
inverseArray(add(pMem, pZhInv), 2 )
|
||||
|
||||
let zh := mload(add(pMem, pZh))
|
||||
w := 1
|
||||
|
||||
|
||||
mstore(
|
||||
add(pMem, pEval_l1 ),
|
||||
mulmod(
|
||||
mload(add(pMem, pEval_l1 )),
|
||||
zh,
|
||||
q
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function calculatePl(pMem, pPub) {
|
||||
let pl := 0
|
||||
|
||||
|
||||
pl := mod(
|
||||
add(
|
||||
sub(
|
||||
pl,
|
||||
mulmod(
|
||||
mload(add(pMem, pEval_l1)),
|
||||
mload(add(pPub, 32)),
|
||||
q
|
||||
)
|
||||
),
|
||||
q
|
||||
),
|
||||
q
|
||||
)
|
||||
|
||||
|
||||
mstore(add(pMem, pPl), pl)
|
||||
|
||||
|
||||
}
|
||||
|
||||
function calculateT(pProof, pMem) {
|
||||
let t
|
||||
let t1
|
||||
let t2
|
||||
t := addmod(
|
||||
mload(add(pProof, pEval_r)),
|
||||
mload(add(pMem, pPl)),
|
||||
q
|
||||
)
|
||||
|
||||
t1 := mulmod(
|
||||
mload(add(pProof, pEval_s1)),
|
||||
mload(add(pMem, pBeta)),
|
||||
q
|
||||
)
|
||||
|
||||
t1 := addmod(
|
||||
t1,
|
||||
mload(add(pProof, pEval_a)),
|
||||
q
|
||||
)
|
||||
|
||||
t1 := addmod(
|
||||
t1,
|
||||
mload(add(pMem, pGamma)),
|
||||
q
|
||||
)
|
||||
|
||||
t2 := mulmod(
|
||||
mload(add(pProof, pEval_s2)),
|
||||
mload(add(pMem, pBeta)),
|
||||
q
|
||||
)
|
||||
|
||||
t2 := addmod(
|
||||
t2,
|
||||
mload(add(pProof, pEval_b)),
|
||||
q
|
||||
)
|
||||
|
||||
t2 := addmod(
|
||||
t2,
|
||||
mload(add(pMem, pGamma)),
|
||||
q
|
||||
)
|
||||
|
||||
t1 := mulmod(t1, t2, q)
|
||||
|
||||
t2 := addmod(
|
||||
mload(add(pProof, pEval_c)),
|
||||
mload(add(pMem, pGamma)),
|
||||
q
|
||||
)
|
||||
|
||||
t1 := mulmod(t1, t2, q)
|
||||
t1 := mulmod(t1, mload(add(pProof, pEval_zw)), q)
|
||||
t1 := mulmod(t1, mload(add(pMem, pAlpha)), q)
|
||||
|
||||
t2 := mulmod(
|
||||
mload(add(pMem, pEval_l1)),
|
||||
mload(add(pMem, pAlpha)),
|
||||
q
|
||||
)
|
||||
|
||||
t2 := mulmod(
|
||||
t2,
|
||||
mload(add(pMem, pAlpha)),
|
||||
q
|
||||
)
|
||||
|
||||
t1 := addmod(t1, t2, q)
|
||||
|
||||
t := mod(sub(add(t, q), t1), q)
|
||||
t := mulmod(t, mload(add(pMem, pZhInv)), q)
|
||||
|
||||
mstore( add(pMem, pEval_t) , t)
|
||||
|
||||
}
|
||||
|
||||
function g1_set(pR, pP) {
|
||||
mstore(pR, mload(pP))
|
||||
mstore(add(pR, 32), mload(add(pP,32)))
|
||||
}
|
||||
|
||||
function g1_acc(pR, pP) {
|
||||
let mIn := mload(0x40)
|
||||
mstore(mIn, mload(pR))
|
||||
mstore(add(mIn,32), mload(add(pR, 32)))
|
||||
mstore(add(mIn,64), mload(pP))
|
||||
mstore(add(mIn,96), mload(add(pP, 32)))
|
||||
|
||||
let success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64)
|
||||
|
||||
if iszero(success) {
|
||||
mstore(0, 0)
|
||||
return(0,0x20)
|
||||
}
|
||||
}
|
||||
|
||||
function g1_mulAcc(pR, pP, s) {
|
||||
let success
|
||||
let mIn := mload(0x40)
|
||||
mstore(mIn, mload(pP))
|
||||
mstore(add(mIn,32), mload(add(pP, 32)))
|
||||
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 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 g1_mulSetC(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, pR, 64)
|
||||
|
||||
if iszero(success) {
|
||||
mstore(0, 0)
|
||||
return(0,0x20)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function calculateA1(pProof, pMem) {
|
||||
let p := add(pMem, pA1)
|
||||
g1_set(p, add(pProof, pWxi))
|
||||
g1_mulAcc(p, add(pProof, pWxiw), mload(add(pMem, pU)))
|
||||
}
|
||||
|
||||
|
||||
function calculateB1(pProof, pMem) {
|
||||
let s
|
||||
let s1
|
||||
let p := add(pMem, pB1)
|
||||
|
||||
// Calculate D
|
||||
s := mulmod( mload(add(pProof, pEval_a)), mload(add(pMem, pV1)), q)
|
||||
g1_mulSetC(p, Qlx, Qly, s)
|
||||
|
||||
s := mulmod( s, mload(add(pProof, pEval_b)), q)
|
||||
g1_mulAccC(p, Qmx, Qmy, s)
|
||||
|
||||
s := mulmod( mload(add(pProof, pEval_b)), mload(add(pMem, pV1)), q)
|
||||
g1_mulAccC(p, Qrx, Qry, s)
|
||||
|
||||
s := mulmod( mload(add(pProof, pEval_c)), mload(add(pMem, pV1)), q)
|
||||
g1_mulAccC(p, Qox, Qoy, s)
|
||||
|
||||
s :=mload(add(pMem, pV1))
|
||||
g1_mulAccC(p, Qcx, Qcy, s)
|
||||
|
||||
s := addmod(mload(add(pProof, pEval_a)), mload(add(pMem, pBetaXi)), q)
|
||||
s := addmod(s, mload(add(pMem, pGamma)), q)
|
||||
s1 := mulmod(k1, mload(add(pMem, pBetaXi)), q)
|
||||
s1 := addmod(s1, mload(add(pProof, pEval_b)), q)
|
||||
s1 := addmod(s1, mload(add(pMem, pGamma)), q)
|
||||
s := mulmod(s, s1, q)
|
||||
s1 := mulmod(k2, mload(add(pMem, pBetaXi)), q)
|
||||
s1 := addmod(s1, mload(add(pProof, pEval_c)), q)
|
||||
s1 := addmod(s1, mload(add(pMem, pGamma)), q)
|
||||
s := mulmod(s, s1, q)
|
||||
s := mulmod(s, mload(add(pMem, pAlpha)), q)
|
||||
s := mulmod(s, mload(add(pMem, pV1)), q)
|
||||
s1 := mulmod(mload(add(pMem, pEval_l1)), mload(add(pMem, pAlpha)), q)
|
||||
s1 := mulmod(s1, mload(add(pMem, pAlpha)), q)
|
||||
s1 := mulmod(s1, mload(add(pMem, pV1)), q)
|
||||
s := addmod(s, s1, q)
|
||||
s := addmod(s, mload(add(pMem, pU)), q)
|
||||
g1_mulAcc(p, add(pProof, pZ), s)
|
||||
|
||||
s := mulmod(mload(add(pMem, pBeta)), mload(add(pProof, pEval_s1)), q)
|
||||
s := addmod(s, mload(add(pProof, pEval_a)), q)
|
||||
s := addmod(s, mload(add(pMem, pGamma)), q)
|
||||
s1 := mulmod(mload(add(pMem, pBeta)), mload(add(pProof, pEval_s2)), q)
|
||||
s1 := addmod(s1, mload(add(pProof, pEval_b)), q)
|
||||
s1 := addmod(s1, mload(add(pMem, pGamma)), q)
|
||||
s := mulmod(s, s1, q)
|
||||
s := mulmod(s, mload(add(pMem, pAlpha)), q)
|
||||
s := mulmod(s, mload(add(pMem, pV1)), q)
|
||||
s := mulmod(s, mload(add(pMem, pBeta)), q)
|
||||
s := mulmod(s, mload(add(pProof, pEval_zw)), q)
|
||||
s := mod(sub(q, s), q)
|
||||
g1_mulAccC(p, S3x, S3y, s)
|
||||
|
||||
|
||||
// calculate F
|
||||
g1_acc(p , add(pProof, pT1))
|
||||
|
||||
s := mload(add(pMem, pXin))
|
||||
g1_mulAcc(p, add(pProof, pT2), s)
|
||||
|
||||
s := mulmod(s, s, q)
|
||||
g1_mulAcc(p, add(pProof, pT3), s)
|
||||
|
||||
g1_mulAcc(p, add(pProof, pA), mload(add(pMem, pV2)))
|
||||
g1_mulAcc(p, add(pProof, pB), mload(add(pMem, pV3)))
|
||||
g1_mulAcc(p, add(pProof, pC), mload(add(pMem, pV4)))
|
||||
g1_mulAccC(p, S1x, S1y, mload(add(pMem, pV5)))
|
||||
g1_mulAccC(p, S2x, S2y, mload(add(pMem, pV6)))
|
||||
|
||||
// calculate E
|
||||
s := mload(add(pMem, pEval_t))
|
||||
s := addmod(s, mulmod(mload(add(pProof, pEval_r)), mload(add(pMem, pV1)), q), q)
|
||||
s := addmod(s, mulmod(mload(add(pProof, pEval_a)), mload(add(pMem, pV2)), q), q)
|
||||
s := addmod(s, mulmod(mload(add(pProof, pEval_b)), mload(add(pMem, pV3)), q), q)
|
||||
s := addmod(s, mulmod(mload(add(pProof, pEval_c)), mload(add(pMem, pV4)), q), q)
|
||||
s := addmod(s, mulmod(mload(add(pProof, pEval_s1)), mload(add(pMem, pV5)), q), q)
|
||||
s := addmod(s, mulmod(mload(add(pProof, pEval_s2)), mload(add(pMem, pV6)), q), q)
|
||||
s := addmod(s, mulmod(mload(add(pProof, pEval_zw)), mload(add(pMem, pU)), q), q)
|
||||
s := mod(sub(q, s), q)
|
||||
g1_mulAccC(p, G1x, G1y, s)
|
||||
|
||||
|
||||
// Last part of B
|
||||
s := mload(add(pMem, pXi))
|
||||
g1_mulAcc(p, add(pProof, pWxi), s)
|
||||
|
||||
s := mulmod(mload(add(pMem, pU)), mload(add(pMem, pXi)), q)
|
||||
s := mulmod(s, w1, q)
|
||||
g1_mulAcc(p, add(pProof, pWxiw), s)
|
||||
|
||||
}
|
||||
|
||||
function checkPairing(pMem) -> isOk {
|
||||
let mIn := mload(0x40)
|
||||
mstore(mIn, mload(add(pMem, pA1)))
|
||||
mstore(add(mIn,32), mload(add(add(pMem, pA1), 32)))
|
||||
mstore(add(mIn,64), X2x2)
|
||||
mstore(add(mIn,96), X2x1)
|
||||
mstore(add(mIn,128), X2y2)
|
||||
mstore(add(mIn,160), X2y1)
|
||||
mstore(add(mIn,192), mload(add(pMem, pB1)))
|
||||
let s := mload(add(add(pMem, pB1), 32))
|
||||
s := mod(sub(qf, s), qf)
|
||||
mstore(add(mIn,224), s)
|
||||
mstore(add(mIn,256), G2x2)
|
||||
mstore(add(mIn,288), G2x1)
|
||||
mstore(add(mIn,320), G2y2)
|
||||
mstore(add(mIn,352), G2y1)
|
||||
|
||||
let success := staticcall(sub(gas(), 2000), 8, mIn, 384, mIn, 0x20)
|
||||
|
||||
isOk := and(success, mload(mIn))
|
||||
}
|
||||
|
||||
let pMem := mload(0x40)
|
||||
mstore(0x40, add(pMem, lastMem))
|
||||
|
||||
checkInput(proof)
|
||||
calculateChallanges(proof, pMem)
|
||||
calculateLagrange(pMem)
|
||||
calculatePl(pMem, pubSignals)
|
||||
calculateT(proof, pMem)
|
||||
calculateA1(proof, pMem)
|
||||
calculateB1(proof, pMem)
|
||||
let isValid := checkPairing(pMem)
|
||||
|
||||
mstore(0x40, sub(pMem, lastMem))
|
||||
mstore(0, isValid)
|
||||
return(0,0x20)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user