Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7,324 changes: 3,662 additions & 3,662 deletions batchinput.json

Large diffs are not rendered by default.

18,088 changes: 18,088 additions & 0 deletions batchinput12_val_118_len.json

Large diffs are not rendered by default.

Binary file added circuits/.DS_Store
Binary file not shown.
184 changes: 184 additions & 0 deletions circuits/batchverifier5.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
// 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 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 = 6365819893304563177984165751448019566324538181831673081327586371458809718366;
uint256 constant deltax2 = 13529006623231720241501540375982364415501445822353820874637428534680100085418;
uint256 constant deltay1 = 20995779666407209333670946803170869779586325853442448739386534617821327093100;
uint256 constant deltay2 = 1956883859976637913591393298808290763452534837492561629820561444140603310474;


uint256 constant IC0x = 19401517574313638906470847847604586248479783932513526054939834665871551779925;
uint256 constant IC0y = 13850965957014451859454191114227840228410922015967039244047448964447491076432;

uint256 constant IC1x = 13558473107284258242761277863961415162661478561115411112425114778354717633102;
uint256 constant IC1y = 19079161034842742252710635323798946497587679297404222979650808247266003868171;

uint256 constant IC2x = 3028173392691339925319653481690867168423282171922685166305459268785462143573;
uint256 constant IC2y = 12939894501092190142527862722320784263639655427724264049572350047253338262365;

uint256 constant IC3x = 20881011878073461342581565230455797075458496660126621655163114156266572684371;
uint256 constant IC3y = 4785096290686215097680302522669157911531993643845611680602398592780849611426;


// 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[3] calldata _pubSignals) public view returns (bool) {
assembly {
function checkField(v) {
if iszero(lt(v, q)) {
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)))


// -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)))


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

mstore(0, isValid)
return(0, 0x20)
}
}
}
184 changes: 184 additions & 0 deletions circuits/batchverifier9.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
// 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 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 = 6365819893304563177984165751448019566324538181831673081327586371458809718366;
uint256 constant deltax2 = 13529006623231720241501540375982364415501445822353820874637428534680100085418;
uint256 constant deltay1 = 20995779666407209333670946803170869779586325853442448739386534617821327093100;
uint256 constant deltay2 = 1956883859976637913591393298808290763452534837492561629820561444140603310474;


uint256 constant IC0x = 19401517574313638906470847847604586248479783932513526054939834665871551779925;
uint256 constant IC0y = 13850965957014451859454191114227840228410922015967039244047448964447491076432;

uint256 constant IC1x = 13558473107284258242761277863961415162661478561115411112425114778354717633102;
uint256 constant IC1y = 19079161034842742252710635323798946497587679297404222979650808247266003868171;

uint256 constant IC2x = 3028173392691339925319653481690867168423282171922685166305459268785462143573;
uint256 constant IC2y = 12939894501092190142527862722320784263639655427724264049572350047253338262365;

uint256 constant IC3x = 20881011878073461342581565230455797075458496660126621655163114156266572684371;
uint256 constant IC3y = 4785096290686215097680302522669157911531993643845611680602398592780849611426;


// 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[3] calldata _pubSignals) public view returns (bool) {
assembly {
function checkField(v) {
if iszero(lt(v, q)) {
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)))


// -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)))


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

mstore(0, isValid)
return(0, 0x20)
}
}
}
5 changes: 3 additions & 2 deletions circuits/batchverify.circom
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ template ConvertBits2Num(n) {
lc1 ==> out;
}

// 32 messages each contain 896 bits
component main {public [hash]} = BatchVerify(896, 32);
// 32 messages each contain 896 bits// OLD
// 12 messages each contain 944 bits// testnet
component main {public [hash]} = BatchVerify(944, 12);


// below output hash[2] as 128 bits decimal representation of sha256
Expand Down
1 change: 1 addition & 0 deletions circuits/proof_pub_sigs_106.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["0x14ebf6384efcf66b38e03a5afc4c3e536fdb33ed42baa512ae8a66ef754f6bbf", "0x25b15c37712ca814ecc7ecf0574c4ad34dcfbcf2d13f68e2f209e798c1e1c1e8"],[["0x239d21c680e5631a40223024dadc23a0d22690427b71886a10b291673bba6319", "0x0faac2577bb8b04e59cbc484d2a33174cf038435b78566706a8fa851eede6768"],["0x10af92467edf4b1045e9d38b5c0944b9322109ab75742556cde3949c9fe569ec", "0x30017663960845feee19a89d815db93de6b923423cf6524a13ec20681bd7e0ec"]],["0x2a6f743cadf83796946ad749ae9f310eb20437c03243c8b731df43b593a8b69d", "0x10b1da97b404317b6ec7f71a6874d9f5b1f6d9928900b32ffe97679c5f161329"],["0x0000000000000000000000000000000000000000000000000000000000000000","0x000000000000000000000000000000002c5db2d53560f98ed0862cd0fb111f9d","0x00000000000000000000000000000000eaf8870d35483ad0b0e5813596e3cff4"]
1 change: 1 addition & 0 deletions circuits/proof_pub_sigs_46.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["0x1feb948b35d2f86daa9c5fc09dd33b88d38cac89acccb6e2908a2f5d2e869ce8", "0x21b44a83cff4197bc745ea856744e65b78d8ee8f2995052afb8c9c640cc7b1c0"],[["0x2819f96a400dbf7a17004f170fe8d72f1748f1699c4ccc08d83893062eacb8da", "0x1e8b2db4552cf6d37774548be3bddc86bf6cb7310c02e9ea78f5798f7797f122"],["0x1b2342727d891a5abc16360e2ed794ea9c361e752d34d6b477905db344ef8875", "0x253394236d62b70eca11f217668d15dc6a556790ee55ec5119ba0973c2bebe7f"]],["0x19aea1828a5ab467fa4965368300b93075c09bb0a517c2e07e4822e10554f252", "0x28c0cefd62b8c4a34c8a9498434d9d6e4829848589c413e14af7b7a4d3975684"],["0x0000000000000000000000000000000000000000000000000000000000000000","0x000000000000000000000000000000002586af6762a10395cf3bd7c9f6653e1a","0x0000000000000000000000000000000016d6213691e76395ff966d583dce2cf6"]
1 change: 1 addition & 0 deletions circuits/proof_pub_sigs_7654321.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["0x150d84373513195ccda358f1ec3763690754e36c913667bb310f6d2fa5dfe2aa", "0x2a3abd3bbabc9be98d71fcf82bf800dc42838cb1ecca97dc700cd81e59cb0705"],[["0x18c355e07cd6631c3430ae98d2cb912c34e8b90a5093a603eeb89dd39a7d9d9f", "0x096dacab929c6deac91400382588c812cea11056741c69db42677c00cc391cb5"],["0x2390e157dc92a80dd6b5611580cc760bd4f749f51ee1f0dd8fb283aad08ca6b0", "0x1d093f7e96a2845ae725113d74cf248630ea62e8cbcffbd872f55e330d7e4063"]],["0x12ee0d0a0d5477dab463153c6e69b74a74316c46da6f594b0c091cb509c6a487", "0x223762bcd6523deda8cca40a5f24272616d5283c65e43ef47e66a83fe3a5f09b"],["0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000013b7cff91a80a211b9ce7146aea27e4b","0x00000000000000000000000000000000c2d1b2e882294a7aa8f726e774bb008c"]
1 change: 1 addition & 0 deletions data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"msg":[[111,8,2,17,36,0,0,0,0,0,0,0,34,72,10,32,66,15,32,152,208,7,69,219,166,26,244,231,127,247,196,94,155,127,207,55,136,84,147,228,153,98,60,132,217,5,138,158,18,36,8,1,18,32,11,240,43,121,197,33,157,232,109,180,116,4,121,90,247,22,40,58,232,238,206,228,227,85,28,80,93,168,110,223,49,183,42,12,8,176,194,170,174,6,16,144,206,240,168,2,50,10,99,101,110,116,97,117,114,105,45,49]],"sigs":[[101,168,183,134,143,54,1,63,148,125,195,152,170,120,195,218,68,126,139,93,180,148,179,82,108,189,188,127,111,147,233,36,70,169,214,104,165,109,216,165,7,246,111,41,104,152,168,234,251,37,43,20,57,185,154,38,159,204,186,76,153,87,85,14]],"pubkeys":[[16,147,45,80,193,165,204,196,89,59,167,137,249,34,61,211,57,184,100,157,6,199,160,237,149,254,14,202,131,61,183,163]]}
Empty file added proof_2.json
Empty file.
Loading