Skip to content

Commit

Permalink
Update the verifier and prover and fix the integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Jun 27, 2024
1 parent de6413b commit e7d793b
Show file tree
Hide file tree
Showing 22 changed files with 383 additions and 387 deletions.
2 changes: 1 addition & 1 deletion packages/circuits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Its instances are as follows:

### Run tests
At `packages/circuits`, make a `build` directory, download the zip file from the following link, and place its unziped files under `build`.
https://drive.google.com/file/d/1b49VLOoUsf5c2bFXSQwx1eGIX7_g30TN/view?usp=sharing
https://drive.google.com/file/d/1F1cw9eTlgJwPcXR4wF8kQrWPMhRsFnIy/view?usp=sharing

Then run the following command.
`yarn test`
Expand Down
2 changes: 1 addition & 1 deletion packages/circuits/scripts/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const snarkjs = require("snarkjs");
program
.requiredOption("--email-addr <string>", "User's email address")
.requiredOption("--email-addr-rand <string>", "Randomness for the email address commitment")
.requiredOption("--account-key <string>", "User's account key")
.requiredOption("--account-code <string>", "User's account code")
.requiredOption("--input-file <string>", "Path of a json file to write the generated input")
.option("--silent", "No console logs")
.option("--prove", "Also generate proof");
Expand Down
2 changes: 1 addition & 1 deletion packages/circuits/scripts/email_sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const snarkjs = require("snarkjs");

program
.requiredOption("--email-file <string>", "Path to an email file")
.requiredOption("--account-key <string>", "Sender's account key")
.requiredOption("--account-code <string>", "Sender's account code")
.requiredOption("--input-file <string>", "Path of a json file to write the generated input")
.option("--silent", "No console logs")
.option("--prove", "Also generate proof");
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#### Tests
- `tests/*.t.sol` - Contains unit tests for all contracts/functionalities.
- `tests/Integration.t.sol` - Contains all integration tests. Integration tests generate the proof using the circuit and verify it using contracts. Before running those tests, you need to make a `packages/contracts/test/build_integration` directory, download the zip file from the following link, and place its unziped files under that directory.
https://drive.google.com/file/d/1sYlhq4tU7ZZGN1r9HM0pJcA4q6pHErXb/view?usp=sharing
https://drive.google.com/file/d/1F1cw9eTlgJwPcXR4wF8kQrWPMhRsFnIy/view?usp=sharing

## Build and Test

Expand Down
199 changes: 99 additions & 100 deletions packages/contracts/src/verifier/AccountCreationVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,91 +22,94 @@ pragma solidity >=0.7.0 <0.9.0;

contract AccountCreationVerifier {
// Scalar field size
uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
// Base field size
uint256 constant q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
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 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 = 394495987856382417489648320495229814478921837284687621672127718015891407894;
uint256 constant deltax2 = 20003026255182470220763198008306097063266502241908640198565111261382894563584;
uint256 constant deltay1 = 5153732139172663003461773433682950750534947429330430744721968822842995208827;
uint256 constant deltay2 = 9602455228490272404836338596621746312766674457420929437774724091012936152901;


uint256 constant IC0x = 10761170875748090112170297380238730368276891615062163268413943079435958653371;
uint256 constant IC0y = 8944016340177153704963076504937615447109384661225789112731882124613355165601;

uint256 constant IC1x = 17979990935963504933487306736336915927955798068180920219740458942815178684762;
uint256 constant IC1y = 16651731519252621727291032465742601071725203601712801999466397627257027752439;

uint256 constant IC2x = 14663083415816073773614642098554430040806805847360853621405589403936291810943;
uint256 constant IC2y = 6317766953870455290983252471349807582261719818751587162636603167241752907019;

uint256 constant IC3x = 20377132757024599402375642350276067534346274863781762490063405930966274284526;
uint256 constant IC3y = 12086270144824945128175128808957490235743489471884156078712186793933843050515;

uint256 constant IC4x = 16126469816518283218015250316726151133937714065156910136141275337000050251959;
uint256 constant IC4y = 2882543809944777834758955897995483535988968195866892899048811406029715502558;

uint256 constant IC5x = 16933676122096524832393639429006045996778001648500464809189178080785378457033;
uint256 constant IC5y = 17675425177211431901565328496164868318795809526930475038921835665163536863805;

uint256 constant IC6x = 11949822495323679488648331393913487834230781988564644883110118850042355052494;
uint256 constant IC6y = 2114298792051364765081120188122331514146120674219559670615708764639987683578;

uint256 constant IC7x = 17046242840418791255319669093641916116335302381443802342953653114019496143623;
uint256 constant IC7y = 11226266136835877534735852382545951482471609496239681768167987376211288564459;

uint256 constant IC8x = 7616070070898941974315808779493511392754098449699781176845235034505328607786;
uint256 constant IC8y = 8973118153612121314736490009824474041817435080146517807216576036316012442875;

uint256 constant IC9x = 17911893871706320472103169130449640238981055192170374352402065310737604138808;
uint256 constant IC9y = 11791305601551499733557766166291194901125262967559914237423713749785496417898;

uint256 constant deltax1 = 11114560653783032795769978402668997922764798791992790495675160043621411997801;
uint256 constant deltax2 = 3198999855294235728192506458450875036685930377596205860400413714993248266885;
uint256 constant deltay1 = 1523796211344669216163805197677304708752963255953394481336634783831675131245;
uint256 constant deltay2 = 14060851925777885121263038403694493227539086494639512834950884844662555344536;

uint256 constant IC0x = 10574649930384280210824214092710431237060299651800579626698390114245349962308;
uint256 constant IC0y = 7469131383340391131566690610819205666048254938232521535030918193954548562197;

uint256 constant IC1x = 4918407869632104706514309489325865612719165977194795206345316814734879790155;
uint256 constant IC1y = 427590774636016404095653689428061975446819778365411103122822564075988962618;

uint256 constant IC2x = 9240439318546565743793913443222203703320064941493667472707905026791949687424;
uint256 constant IC2y = 20415392271551446577471308330283787626511450232165866586751060590059472619966;

uint256 constant IC3x = 18273079006058891978922176611671028315844837573233541645939722729879196569509;
uint256 constant IC3y = 4179125134414822982303432671494358190279106619415359456660212971819209966192;

uint256 constant IC4x = 9297048699558444881703737090866304690509775760660454829474271514067117308997;
uint256 constant IC4y = 13565303606019575117935795847122304926263961668898798918417925853327147644591;

uint256 constant IC5x = 6542569569545875615167147622806959100255975349492935905848007572208690916126;
uint256 constant IC5y = 21293150530857626714694934781193973969876061137030766299044643500852647172384;

uint256 constant IC6x = 19558839295223996200409518237268427437645216162898037719899830937713536994394;
uint256 constant IC6y = 12781794639466114294602598700111940254122344910105781355108879417559365513523;

uint256 constant IC7x = 16918074591482504589511560802322192522783986604746129772602056384208683074931;
uint256 constant IC7y = 19646313841956880288891609872276831357540061844356528286490966059146810384971;

uint256 constant IC8x = 10827728734071199839170506656148143522392214520559885850723905200978435764798;
uint256 constant IC8y = 3242112565171231789845409792002666704421691226545775280194259051479756741267;

uint256 constant IC9x = 9125077233354669116951783802069584813354708524358665331588433101675900974243;
uint256 constant IC9y = 7589068801965692889510641452560025828019358360508905551281637512823176104458;

uint256 constant IC10x = 13095809173149064990041447127638667842331098941363942128063910739947384949889;
uint256 constant IC10y = 11623517517259510779480048136366634699145191856666061684367509912930858877561;
uint256 constant IC11x = 9951106165113610997230963464215177277527154163598154321453335829293575115166;
uint256 constant IC11y = 12048337881330301994376382472987584879401674121012526502751942835901867150834;

uint256 constant IC11x = 5043237383304541429511381442510512373806846320952360137211894651659024751403;
uint256 constant IC11y = 550893153460291284560976184557899076262180781407155792139292950979094783291;

uint256 constant IC12x = 14720279726342358412892450667847530215243501087316853231801527146749312905742;
uint256 constant IC12y = 16371354465076218854866398746554182242515563117357477174715937450709014132326;

uint256 constant IC13x = 17715568608065378010764597489935245928760845561530536927109146975431790820022;
uint256 constant IC13y = 9654257669853909597688213072068227805115499316415452451512149706636088943268;

uint256 constant IC14x = 11512969057921681794318964885528643607554619161189031136343109550170942372570;
uint256 constant IC14y = 3020836647969348141940556963585248575639186503149333312914418617952605961660;

uint256 constant IC15x = 1316180717904281335382405778620805277977806904733594414161909151779777967901;
uint256 constant IC15y = 19299276711474140391561721956740819633578380584022009440596799512059770074508;



uint256 constant IC13x = 12750376374402432663610429273530594794079997018858097272669578093923121597809;
uint256 constant IC13y = 2311948973136263808436295464985114053831618135131643934382355702998719570383;

uint256 constant IC14x = 3093477216240154075903136430902607428868040575153219563570941445447676841903;
uint256 constant IC14y = 13676003283193285695177063595846830773808254092093075628535519191724190878011;

uint256 constant IC15x = 21459591627931003521210134408477579646508710109540553844082545432313637866958;
uint256 constant IC15y = 11629135630635756238596028722317663923558798104574485111862117311271384206554;

// 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[15] calldata _pubSignals) public view returns (bool) {
function verifyProof(
uint[2] calldata _pA,
uint[2][2] calldata _pB,
uint[2] calldata _pC,
uint[15] 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
Expand Down Expand Up @@ -141,37 +144,36 @@ contract AccountCreationVerifier {
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)))


// -A
mstore(_pPairing, calldataload(pA))
Expand All @@ -197,7 +199,6 @@ contract AccountCreationVerifier {
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)
Expand All @@ -214,7 +215,6 @@ contract AccountCreationVerifier {
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))
Expand All @@ -224,45 +224,44 @@ contract AccountCreationVerifier {
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)))


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

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

0 comments on commit e7d793b

Please sign in to comment.