Skip to content
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2031bb6
add verifier for Qurrency
jimthematrix Apr 13, 2025
a8f9c81
added kyber circuits
guruvamsi-policharla Apr 23, 2025
9525f2f
Merge pull request #129 from guruvamsi-policharla/qurrency
jimthematrix Apr 23, 2025
a1e5aab
Merge branch 'main' into qurrency
jimthematrix Apr 24, 2025
57a9c73
add initial artifacts for the anon_nullifier_qurrency token
jimthematrix Apr 24, 2025
7e6cf6d
update ignition deploy script
jimthematrix Apr 24, 2025
199fea1
added kyber enc to qurrency transfer
guruvamsi-policharla Apr 24, 2025
6d4ae2d
moved outputs after zeto outputs
guruvamsi-policharla Apr 24, 2025
969d7f8
circuits compile
guruvamsi-policharla Apr 24, 2025
db220a2
changed to all 0 message
guruvamsi-policharla Apr 24, 2025
0172b4b
fix circuit unit test
jimthematrix Apr 24, 2025
7d4b65d
Add generated verifier contract
jimthematrix Apr 24, 2025
5f5fcaf
changed order of m and randomness
guruvamsi-policharla Apr 24, 2025
acccdc9
moving back to old message
guruvamsi-policharla Apr 24, 2025
6550007
update verifier with the latest circuit
jimthematrix Apr 24, 2025
316181f
temporary test using prepared data
jimthematrix Apr 24, 2025
4950ef7
Merge pull request #132 from guruvamsi-policharla/qurrency
jimthematrix Apr 28, 2025
6384044
use a single public signal by hashing the inputs
jimthematrix May 5, 2025
b8321b4
move ToBits to a common util
jimthematrix May 5, 2025
d38bd25
add gas cost test for qurrency proof verification
jimthematrix May 5, 2025
9761b0a
circuit unit test for anon_nullifier_qurrency
jimthematrix May 5, 2025
21af71a
use separate input signals
jimthematrix May 6, 2025
001918c
cleanup solidity/test/test/qurrency.ts
jimthematrix May 7, 2025
1c8628b
Merge branch 'qurrency-separate-inputs' into qurrency
jimthematrix May 7, 2025
6bcd2b0
cleanup the test anon_nullifier_qurrency.js
jimthematrix May 7, 2025
43bcfa3
Fully implement the transfer() method with hardhat tests
jimthematrix May 8, 2025
0bdff10
use 1 instead of 1665 for the randomness signals
jimthematrix May 9, 2025
6bb0a44
use proper randomness for the circuit private input
jimthematrix May 20, 2025
1944732
add inline comments for the dummy randomness
jimthematrix May 20, 2025
ca18631
fix copyright and license headers
jimthematrix May 20, 2025
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
30 changes: 30 additions & 0 deletions solidity/contracts/test/qurrency.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;

import {Groth16Verifier_AnonNullifierQurrencyTransfer} from "../verifiers/verifier_anon_nullifier_qurrency_transfer.sol";
import {Commonlib} from "../lib/common.sol";

contract TestVerifierQurrency {
Groth16Verifier_AnonNullifierQurrencyTransfer verifier;

bool public lastSuccess = false;

constructor() {
verifier = new Groth16Verifier_AnonNullifierQurrencyTransfer();
}

function verifyProof(
Commonlib.Proof memory proof,
uint256[9] memory publicInputs
) public returns (bool) {
bool result = verifier.verifyProof(
proof.pA,
proof.pB,
proof.pC,
publicInputs
);
lastSuccess = result;
require(result, "Verification failed");
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
// 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_AnonNullifierQurrencyTransfer {
// 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 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
uint256 constant deltax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
uint256 constant deltay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
uint256 constant deltay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;


uint256 constant IC0x = 5903941879013718988081172462893635473765585811323635470514735721095700963702;
uint256 constant IC0y = 21080368968148086049976470300075598267152959623874995939107123143909817947630;

uint256 constant IC1x = 277297534438112389180931574864286821885419665717177767601706304294709064040;
uint256 constant IC1y = 11466710444362729136960387929371222359273358701587036714483949566745055621830;

uint256 constant IC2x = 5619666232197961834865995108107159282382923386466834757057363204096037651764;
uint256 constant IC2y = 15973294500823479376020315199547194992254305102551062619795669271634881254131;

uint256 constant IC3x = 16994365193196666529444222678662986964837189489839761617081637536084667700567;
uint256 constant IC3y = 19320170842519457147495348046335776444028148306160216329435959930056589238336;

uint256 constant IC4x = 8498610473957547996900321269894382432325081969475947517083968711252676854434;
uint256 constant IC4y = 12728107717434555757183263731054279132059277069143869361510124517810824142633;

uint256 constant IC5x = 18511559663930149009135574067307212897873211022818368060918697035060259565029;
uint256 constant IC5y = 20804557254714858706397640997162389384167991925053762942540110532256230134678;

uint256 constant IC6x = 9373814069952600731332993487809060613417950312335152043923307393139824873734;
uint256 constant IC6y = 16865467207038098604194455172286157376570508997936659278795086623618594346915;

uint256 constant IC7x = 12145839442248256913972414977521448580312614560974030542947427181163264459741;
uint256 constant IC7y = 18090427452121523061184380667980763703935420996985767299962855565988460373436;

uint256 constant IC8x = 10474776404215989914860932066594458738983457343662916641445752614561642689469;
uint256 constant IC8y = 3378834796931378107199253750169106725596319638791117099719497080177733386540;

uint256 constant IC9x = 1887249157430528165374401635262372006182704854335611145585690423537839735888;
uint256 constant IC9y = 7080674530581255597858145142316212286106173969722576181725459826182095923364;


// 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[9] 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)))


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


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

mstore(0, isValid)
return(0, 0x20)
}
}
}
Loading
Loading