From a59881b01d2fd614209ea12a3737eef709851968 Mon Sep 17 00:00:00 2001 From: Filip Harald Date: Tue, 31 Oct 2023 16:20:08 +0100 Subject: [PATCH] feat: use noir_js and upgrade nargo to 0.17.0 (#45) resolves: #43 #44 --- README.md | 3 +- packages/hardhat/contracts/BalloonVendor.sol | 2 + .../contracts/verifiers/LessThanSignedAge.sol | 230 ++++++++++-------- packages/hardhat/test/constants.ts | 2 +- packages/nextjs/generated/circuits.json | 134 +++++++++- .../nextjs/generated/deployedContracts.ts | 8 +- .../nextjs/hooks/noir/useProofGenerator.ts | 53 +--- packages/nextjs/package.json | 4 +- .../age-restricted-example/GenerateProof.tsx | 8 +- packages/nextjs/utils/noir/noirBrowser.ts | 69 ------ packages/noir/.gitignore | 2 - .../circuits/LessThanSignedAge/Nargo.toml | 4 +- .../circuits/LessThanSignedAge/Prover.toml | 158 ++++++++++++ .../circuits/LessThanSignedAge/Verifier.toml | 4 + .../circuits/LessThanSignedAge/src/main.nr | 8 + yarn.lock | 69 ++++-- 16 files changed, 509 insertions(+), 249 deletions(-) delete mode 100644 packages/nextjs/utils/noir/noirBrowser.ts create mode 100644 packages/noir/circuits/LessThanSignedAge/Prover.toml create mode 100644 packages/noir/circuits/LessThanSignedAge/Verifier.toml diff --git a/README.md b/README.md index ee3dd9f..0702db8 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,9 @@ This is a sandbox educational project for testing age-restricted contracts using 1. Run `yarn && yarn chain` in terminal 1 to start the hardhat chain locally 2. Run `yarn deploy --reset` in terminal 2 to deploy the contracts 3. Run `yarn start` in terminal 3 to run the UI + # Prerequisites -* requires [nargo](https://noir-lang.org/dev/getting_started/nargo_installation) (tested with v0.10.1) +* requires [nargo](https://noir-lang.org/dev/getting_started/nargo_installation) (tested with v0.17.0) * requires [node] (https://nodejs.org/en) (tested with v18.8.0) * requires [yarn] (https://yarnpkg.com/getting-started/install) (tested with 3.2.3) diff --git a/packages/hardhat/contracts/BalloonVendor.sol b/packages/hardhat/contracts/BalloonVendor.sol index 32d7443..d7b1ae0 100644 --- a/packages/hardhat/contracts/BalloonVendor.sol +++ b/packages/hardhat/contracts/BalloonVendor.sol @@ -2,6 +2,8 @@ pragma solidity >=0.8.4; // SPDX-License-Identifier: MIT import "@openzeppelin/contracts/access/Ownable.sol"; +import "hardhat/console.sol"; + import "./BalloonToken.sol"; import "./verifiers/LessThanSignedAge.sol"; diff --git a/packages/hardhat/contracts/verifiers/LessThanSignedAge.sol b/packages/hardhat/contracts/verifiers/LessThanSignedAge.sol index 1611548..1deb108 100644 --- a/packages/hardhat/contracts/verifiers/LessThanSignedAge.sol +++ b/packages/hardhat/contracts/verifiers/LessThanSignedAge.sol @@ -1,11 +1,11 @@ -// Verification Key Hash: 19a27f2f3c3f000168b1f527fb663a8542b517a4fe9c18494c9d044be48c8c17 +// Verification Key Hash: 0b7b575d354961eae92fbada7c87bdc7c640fd1483245f45465a484deb8d94e6 // SPDX-License-Identifier: Apache-2.0 // Copyright 2022 Aztec pragma solidity >=0.8.4; library UltraVerificationKey { function verificationKeyHash() internal pure returns(bytes32) { - return 0x19a27f2f3c3f000168b1f527fb663a8542b517a4fe9c18494c9d044be48c8c17; + return 0x0b7b575d354961eae92fbada7c87bdc7c640fd1483245f45465a484deb8d94e6; } function loadVerificationKey(uint256 _vk, uint256 _omegaInverseLoc) internal pure { @@ -14,34 +14,34 @@ library UltraVerificationKey { mstore(add(_vk, 0x20), 0x0000000000000000000000000000000000000000000000000000000000000055) // vk.num_inputs mstore(add(_vk, 0x40), 0x0931d596de2fd10f01ddd073fd5a90a976f169c76f039bb91c4775720042d43a) // vk.work_root mstore(add(_vk, 0x60), 0x3061482dfa038d0fb5b4c0b226194047a2616509f531d4fa3acdb77496c10001) // vk.domain_inverse - mstore(add(_vk, 0x80), 0x1a9ec40626fc189fd96e13f0d2d782a6ac626d3466165dfc695e3e5f554ab78d) // vk.Q1.x - mstore(add(_vk, 0xa0), 0x2daee0b4ae1cc5e75900b6ca8c8531cfb39aee325843a1a83029d2a1a9eae670) // vk.Q1.y - mstore(add(_vk, 0xc0), 0x254f0472c5a61b017b795c510166d58b89aaa8c0479b71c3953dfd28426c0206) // vk.Q2.x - mstore(add(_vk, 0xe0), 0x1165b7979227361f8a21d5a0da0f179d8c30d11529aa606a4c814dd8490505fa) // vk.Q2.y - mstore(add(_vk, 0x100), 0x2ed9b6cbbdc0c1c0dc14628a709a7c5e7afe9c926085a8d3652e0648da736dca) // vk.Q3.x - mstore(add(_vk, 0x120), 0x154c9c4fb0538001d2636b8a775e38140e092b076b6196127c90cd19011dc3f3) // vk.Q3.y - mstore(add(_vk, 0x140), 0x19543b69c3cd3d4e41f5510fd4c9cc38eb6c88a699e4bb485631e4e7d91da697) // vk.Q4.x - mstore(add(_vk, 0x160), 0x27d60d1276ed70814d9b0fa01dbf09ea71dc51f6d47c7d29168656ad6dfdb33e) // vk.Q4.y - mstore(add(_vk, 0x180), 0x1f99ab321383bab6bcd6066e1d4a7b95459d2747117405e196ccaebcba1baf91) // vk.Q_M.x - mstore(add(_vk, 0x1a0), 0x0d7d83510f2b89a66cddb5443badfd9edc0e50d1edf99b7fa6fb114cd078a3b0) // vk.Q_M.y - mstore(add(_vk, 0x1c0), 0x28c6dead52519637964826f79ae3be9dbbd4552d06f746b2ef6ab682aaa3c1ff) // vk.Q_C.x - mstore(add(_vk, 0x1e0), 0x257fd42415c73f1618ddde1418ff8f3008a02bae5022bfef2e758594a6de9900) // vk.Q_C.y - mstore(add(_vk, 0x200), 0x2a8dd99134b73e80578f5c68b7624820b7a78bd9d5f060ae713c252a8fbd0354) // vk.Q_ARITHMETIC.x - mstore(add(_vk, 0x220), 0x05121e7359d92d89a8a993ed1ced174ade86fb48712777bac86763c8ad771191) // vk.Q_ARITHMETIC.y - mstore(add(_vk, 0x240), 0x2ddf2c78f98c71c5d3a7f325f78b230cfc8e8357ad5e711c75c1e8ce89f2a68b) // vk.QSORT.x - mstore(add(_vk, 0x260), 0x1b1dfcec23b1a434b553c03bbd37e4639737671ee39c2639f1bb735ae29e3cac) // vk.QSORT.y + mstore(add(_vk, 0x80), 0x1d6e4f13028609bd42eb02e4d893fc9660a5131a191d05cb17f1fc3d82c6ba36) // vk.Q1.x + mstore(add(_vk, 0xa0), 0x05172994824d74de30d40dc9a119d9893b07db56769be3d0fd0e25004b8b933d) // vk.Q1.y + mstore(add(_vk, 0xc0), 0x05b968b8c3a6ec128a91f1990347de65bb55b8f33cdf08417fc529e02f015b33) // vk.Q2.x + mstore(add(_vk, 0xe0), 0x022bf0c4e1e85b5c7b0bf964ab36994e4d96501cb95784ea74a5407fc0b6b7d9) // vk.Q2.y + mstore(add(_vk, 0x100), 0x0a349ac88c23e2c255cea71281b388a1a1435ef2f9d655ef58722a228e3e43f5) // vk.Q3.x + mstore(add(_vk, 0x120), 0x04cb7c5424314b8226361fcfe2d7deba7b43ace0400b5e61ffe044c18dd42e4f) // vk.Q3.y + mstore(add(_vk, 0x140), 0x16ecbd2fd8fae5d89326ab1353dce5fa4aa2501651c8a0084bcd1da6dddb5907) // vk.Q4.x + mstore(add(_vk, 0x160), 0x10c3d04936fd1b4c330b38c81599775e418b18fe9cdb092ed7d54ff66c045d16) // vk.Q4.y + mstore(add(_vk, 0x180), 0x159deb8d85129159f2766b1faba6f0d1399342dd4f4df533b3d630d55277fc4a) // vk.Q_M.x + mstore(add(_vk, 0x1a0), 0x2595b9987b84b3ba29422193af9b3789d8f10f26ac9b26e08a8e0fb460a2300c) // vk.Q_M.y + mstore(add(_vk, 0x1c0), 0x05d457e8648298c9a0826c372792852e9e4d7f24f24f7565b098e061bc0e9d4f) // vk.Q_C.x + mstore(add(_vk, 0x1e0), 0x1994c4f45889c705d688949cb7f7c4b68b541a0ff19c696883f38e7dd8619817) // vk.Q_C.y + mstore(add(_vk, 0x200), 0x15ae0b59cdcba5959684782f22291ca43e0c071f4efde58135b25d2a9ebed8d3) // vk.Q_ARITHMETIC.x + mstore(add(_vk, 0x220), 0x2227d818afc24178b8fa0fd627a0bc3b00588eef7427c3faff43e47b8bd06d90) // vk.Q_ARITHMETIC.y + mstore(add(_vk, 0x240), 0x260ea3aecaddde0288d84fb4835fcc24a4a3ea99d80fead9ba4e18c60a33308e) // vk.QSORT.x + mstore(add(_vk, 0x260), 0x1fc01e4555422db9d031d44b9ac7f5210ae560496c3fe27691c2505896d8562b) // vk.QSORT.y mstore(add(_vk, 0x280), 0x13982fd0cf8da5082a77561113bb5ee51e2e82380da3da5ad0f24e49e5f32208) // vk.Q_ELLIPTIC.x mstore(add(_vk, 0x2a0), 0x1aa5ffd5aa4c16d1c66e18c4574a3ab0b25e9b4e4e04ad1280d1a264237717e0) // vk.Q_ELLIPTIC.y mstore(add(_vk, 0x2c0), 0x1750f44d3f9dfad78a1e2127ef91051ce018f20536fe45ca28dcc7b248389fc0) // vk.Q_AUX.x mstore(add(_vk, 0x2e0), 0x1a05418f502a965c39994cd3f83e39164b49c0f27d4f5ac4550751cc0a24bb58) // vk.Q_AUX.y - mstore(add(_vk, 0x300), 0x1db75ce8abc7497c495c4b600fbc48ca219a5eb9da888e8a49867dfba9ff1910) // vk.SIGMA1.x - mstore(add(_vk, 0x320), 0x18ab4154d542ea5f8078d517d1dec4364c645c83d5abf0e2535c2927b6eedc4b) // vk.SIGMA1.y - mstore(add(_vk, 0x340), 0x20096b0403629d2d8e6b880f99711dd610f798f17034af9079ff251140f44894) // vk.SIGMA2.x - mstore(add(_vk, 0x360), 0x0b0b2e04aa2d4a4d60d05140ef41797ec74036759a5ab08b23a61729f7685fdd) // vk.SIGMA2.y - mstore(add(_vk, 0x380), 0x1fd71f304a6060cbacff629004c57d19511671a270f61edd0291fe6825650683) // vk.SIGMA3.x - mstore(add(_vk, 0x3a0), 0x2f6de866a0d2c707c2d9b2d6b7c3dcb3d92e1663bd6f917fdfbfcb9cc065e768) // vk.SIGMA3.y - mstore(add(_vk, 0x3c0), 0x10bf0ee647447f01c1d4b2270b13dfe051643120cada3f2599e404f6d2f8d40a) // vk.SIGMA4.x - mstore(add(_vk, 0x3e0), 0x2f428b54778ca5bae89f1e598b1a0b641702f662c8f87a4043b9739de428c0cc) // vk.SIGMA4.y + mstore(add(_vk, 0x300), 0x24f567bda52b9af5ae31b4b031a77e3c57aaa74c1a37a9cf629b69b00579086d) // vk.SIGMA1.x + mstore(add(_vk, 0x320), 0x2b330b6cf63d8a042da0c37dfe05a54afb33c3a3d3fda86a41fcbfec3e4ff5a0) // vk.SIGMA1.y + mstore(add(_vk, 0x340), 0x10371462601c2b925b05c0d17ca4cf590092c2b35a8910b3397652c141a1dc9b) // vk.SIGMA2.x + mstore(add(_vk, 0x360), 0x0390563ef5c0db4668cb2512dbf1471c8c0ed0d6869a5e6dd5180ef25dc62f76) // vk.SIGMA2.y + mstore(add(_vk, 0x380), 0x038f07fd7bbc01731faa036e95210d75d3ca92c2a6800ad9ef0592e338d4532c) // vk.SIGMA3.x + mstore(add(_vk, 0x3a0), 0x2272ba867313f0d240fe4ef89818cbb602af1c82e5f5b5f13a2d06a3922761a1) // vk.SIGMA3.y + mstore(add(_vk, 0x3c0), 0x2487db6b2697ee9756bd03c587286cf78e0edd3eafe24fdd087db668cd9a8f77) // vk.SIGMA4.x + mstore(add(_vk, 0x3e0), 0x0b2a7bb08f2619ac8cc7e8ac25634c5db677cf20deb8dd7f3ef2f19240023246) // vk.SIGMA4.y mstore(add(_vk, 0x400), 0x259f452dc7fd2dda4013dba2196852bcf43c285b1d1f7f85341f3615d25fe97b) // vk.TABLE1.x mstore(add(_vk, 0x420), 0x117500555dd886209c0b10ee8cd10e711e890a1c99a8f689419da8c52d2e8e9d) // vk.TABLE1.y mstore(add(_vk, 0x440), 0x2577f542178a07dac262fdabad6f55a84fca32b13b92e520bb91a7455f78ccf1) // vk.TABLE2.x @@ -52,14 +52,14 @@ library UltraVerificationKey { mstore(add(_vk, 0x4e0), 0x2198b9feb61f8160e357b8bb7ca329713898655cc94a0ac2d84944c737cf57e5) // vk.TABLE4.y mstore(add(_vk, 0x500), 0x11c8df52c3ef754f80d11792cea4b7ad74612e486596cbe7f7d6a05f19c69444) // vk.TABLE_TYPE.x mstore(add(_vk, 0x520), 0x10c8a36cbb2fd9ed8875b5106a37162ac2932f3bd1b6942b132546d2110a63e2) // vk.TABLE_TYPE.y - mstore(add(_vk, 0x540), 0x1a1ee4f6243da86bbe596c53f24f056c94a81ac8a8146465972fcd9debf9f732) // vk.ID1.x - mstore(add(_vk, 0x560), 0x1dd32a0044c4d8f7a25d0af385497aadc80ea5b61ef82194da4c8ef78aff4373) // vk.ID1.y - mstore(add(_vk, 0x580), 0x11c03e517854ac1331eed81b3c0b43b551fc3da8a10c589a9d4bdc15e035f052) // vk.ID2.x - mstore(add(_vk, 0x5a0), 0x10a74968aa966e7c0dce313aeca14224a93af169ce2fc0b55aae3c2d9527dfb5) // vk.ID2.y - mstore(add(_vk, 0x5c0), 0x2c2203109d9e7f7437bd90baa602cb6e84c520b141d021ad16a4637e0bd5afba) // vk.ID3.x - mstore(add(_vk, 0x5e0), 0x0b6a21a3349fb98ae3e2849b16e204c0d670badc81401a918eb353e05f604946) // vk.ID3.y - mstore(add(_vk, 0x600), 0x27e8e9a04f3f2bdad05894204dfb1dccf04ec36db2ca063c4c54dcb0c826c002) // vk.ID4.x - mstore(add(_vk, 0x620), 0x01f11bc77c65d8c9b6fdb6170aba41684a7fe132cfb5f9d03785b846c7df4ddc) // vk.ID4.y + mstore(add(_vk, 0x540), 0x22326739abc8cf7245c059eca2c39750b82b86aa22d2969e41d074ccc7e726f9) // vk.ID1.x + mstore(add(_vk, 0x560), 0x1a8538e7732275868ae5f01b7b62f7f7d1c67f1446652269cd403064c77e3105) // vk.ID1.y + mstore(add(_vk, 0x580), 0x055635ace760e3b124a31d5de98cfd413105ec8446d4440dd51b68d492bfa60c) // vk.ID2.x + mstore(add(_vk, 0x5a0), 0x288f13905030075554585ecfb96b2cab108fc9a4e78e0adc03e41e174d525904) // vk.ID2.y + mstore(add(_vk, 0x5c0), 0x1d7dbf6d0a57a33dd4b8630b79e805b9460128b0cccfd5474981df3498a77e33) // vk.ID3.x + mstore(add(_vk, 0x5e0), 0x19e2f77eab53de8b1d17b6e667a5b4ce67116f68264d6b42897040912509250e) // vk.ID3.y + mstore(add(_vk, 0x600), 0x1b2f496b300ebb122a4b6af2f70867a7fd7f83f0eadf107696151165e8431913) // vk.ID4.x + mstore(add(_vk, 0x620), 0x1621ad5ca9f18e6d4331e34b222b50fdd96cc499b730f77817673df40b4a0ce1) // vk.ID4.y mstore(add(_vk, 0x640), 0x00) // vk.contains_recursive_proof mstore(add(_vk, 0x660), 0) // vk.recursive_proof_public_input_indices mstore(add(_vk, 0x680), 0x260e01b251f6f1c7e7ff4e580791dee8ea51d87a358e038b4efe30fac09383c1) // vk.g2_x.X.c1 @@ -70,7 +70,6 @@ library UltraVerificationKey { } } } - /** * @title Ultra Plonk proof verification contract * @dev Top level Plonk proof verification contract, which allows Plonk proof to be verified @@ -354,6 +353,9 @@ abstract contract BaseUltraVerifier { uint256 internal constant LIMB_SIZE = 0x100000000000000000; // 2<<68 uint256 internal constant SUBLIMB_SHIFT = 0x4000; // 2<<14 + // y^2 = x^3 + ax + b + // for Grumpkin, a = 0 and b = -17. We use b in a custom gate relation that evaluates elliptic curve arithmetic + uint256 internal constant GRUMPKIN_CURVE_B_PARAMETER_NEGATED = 17; error PUBLIC_INPUT_COUNT_INVALID(uint256 expected, uint256 actual); error PUBLIC_INPUT_INVALID_BN128_G1_POINT(); error PUBLIC_INPUT_GE_P(); @@ -1226,96 +1228,130 @@ abstract contract BaseUltraVerifier { * sign_term += sign_term * sign_term *= q_sign */ + // q_elliptic * (x3 + x2 + x1)(x2 - x1)(x2 - x1) - y2^2 - y1^2 + 2(y2y1)*q_sign = 0 + let x_diff := addmod(mload(X2_EVAL_LOC), sub(p, mload(X1_EVAL_LOC)), p) + let y2_sqr := mulmod(mload(Y2_EVAL_LOC), mload(Y2_EVAL_LOC), p) + let y1_sqr := mulmod(mload(Y1_EVAL_LOC), mload(Y1_EVAL_LOC), p) + let y1y2 := mulmod(mulmod(mload(Y1_EVAL_LOC), mload(Y2_EVAL_LOC), p), mload(QSIGN_LOC), p) - let endo_term := + let x_add_identity := + addmod( + mulmod( + addmod(mload(X3_EVAL_LOC), addmod(mload(X2_EVAL_LOC), mload(X1_EVAL_LOC), p), p), + mulmod(x_diff, x_diff, p), + p + ), + addmod( + sub( + p, + addmod(y2_sqr, y1_sqr, p) + ), + addmod(y1y2, y1y2, p), + p + ), + p + ) + x_add_identity := mulmod( mulmod( - mulmod(sub(p, mload(X2_EVAL_LOC)), mload(X1_EVAL_LOC), p), - addmod(addmod(mload(X3_EVAL_LOC), mload(X3_EVAL_LOC), p), mload(X1_EVAL_LOC), p), + x_add_identity, + addmod( + 1, + sub(p, mload(QM_EVAL_LOC)), + p + ), p ), - mload(QBETA_LOC), + mload(C_ALPHA_BASE_LOC), p ) - let endo_sqr_term := mulmod(mload(X2_EVAL_LOC), mload(X2_EVAL_LOC), p) - endo_sqr_term := mulmod(endo_sqr_term, addmod(mload(X3_EVAL_LOC), sub(p, mload(X1_EVAL_LOC)), p), p) - endo_sqr_term := mulmod(endo_sqr_term, mload(QBETA_SQR_LOC), p) + // q_elliptic * (x3 + x2 + x1)(x2 - x1)(x2 - x1) - y2^2 - y1^2 + 2(y2y1)*q_sign = 0 + let y1_plus_y3 := addmod( + mload(Y1_EVAL_LOC), + mload(Y3_EVAL_LOC), + p + ) + let y_diff := addmod(mulmod(mload(Y2_EVAL_LOC), mload(QSIGN_LOC), p), sub(p, mload(Y1_EVAL_LOC)), p) + let y_add_identity := + addmod( + mulmod(y1_plus_y3, x_diff, p), + mulmod(addmod(mload(X3_EVAL_LOC), sub(p, mload(X1_EVAL_LOC)), p), y_diff, p), + p + ) + y_add_identity := + mulmod( + mulmod(y_add_identity, addmod(1, sub(p, mload(QM_EVAL_LOC)), p), p), + mulmod(mload(C_ALPHA_BASE_LOC), mload(C_ALPHA_LOC), p), + p + ) - let leftovers := mulmod(mload(X2_EVAL_LOC), mload(X2_EVAL_LOC), p) - leftovers := mulmod(leftovers, mload(X2_EVAL_LOC), p) - leftovers := + // ELLIPTIC_IDENTITY = (x_identity + y_identity) * Q_ELLIPTIC_EVAL + mstore( + ELLIPTIC_IDENTITY, mulmod(addmod(x_add_identity, y_add_identity, p), mload(QELLIPTIC_EVAL_LOC), p) + ) + } + { + /** + * x_pow_4 = (y_1_sqr - curve_b) * x_1; + * y_1_sqr_mul_4 = y_1_sqr + y_1_sqr; + * y_1_sqr_mul_4 += y_1_sqr_mul_4; + * x_1_pow_4_mul_9 = x_pow_4; + * x_1_pow_4_mul_9 += x_1_pow_4_mul_9; + * x_1_pow_4_mul_9 += x_1_pow_4_mul_9; + * x_1_pow_4_mul_9 += x_1_pow_4_mul_9; + * x_1_pow_4_mul_9 += x_pow_4; + * x_1_sqr_mul_3 = x_1_sqr + x_1_sqr + x_1_sqr; + * x_double_identity = (x_3 + x_1 + x_1) * y_1_sqr_mul_4 - x_1_pow_4_mul_9; + * y_double_identity = x_1_sqr_mul_3 * (x_1 - x_3) - (y_1 + y_1) * (y_1 + y_3); + */ + // (x3 + x1 + x1) (4y1*y1) - 9 * x1 * x1 * x1 * x1 = 0 + let x1_sqr := mulmod(mload(X1_EVAL_LOC), mload(X1_EVAL_LOC), p) + let y1_sqr := mulmod(mload(Y1_EVAL_LOC), mload(Y1_EVAL_LOC), p) + let x_pow_4 := mulmod(addmod(y1_sqr, GRUMPKIN_CURVE_B_PARAMETER_NEGATED, p), mload(X1_EVAL_LOC), p) + let y1_sqr_mul_4 := mulmod(y1_sqr, 4, p) + let x1_pow_4_mul_9 := mulmod(x_pow_4, 9, p) + let x1_sqr_mul_3 := mulmod(x1_sqr, 3, p) + let x_double_identity := addmod( - leftovers, mulmod( - mulmod(mload(X1_EVAL_LOC), mload(X1_EVAL_LOC), p), - addmod(mload(X3_EVAL_LOC), mload(X1_EVAL_LOC), p), + addmod(mload(X3_EVAL_LOC), addmod(mload(X1_EVAL_LOC), mload(X1_EVAL_LOC), p), p), + y1_sqr_mul_4, p ), + sub(p, x1_pow_4_mul_9), p ) - leftovers := + // (y1 + y1) (2y1) - (3 * x1 * x1)(x1 - x3) = 0 + let y_double_identity := addmod( - leftovers, + mulmod(x1_sqr_mul_3, addmod(mload(X1_EVAL_LOC), sub(p, mload(X3_EVAL_LOC)), p), p), sub( p, - addmod( - mulmod(mload(Y2_EVAL_LOC), mload(Y2_EVAL_LOC), p), - mulmod(mload(Y1_EVAL_LOC), mload(Y1_EVAL_LOC), p), + mulmod( + addmod(mload(Y1_EVAL_LOC), mload(Y1_EVAL_LOC), p), + addmod(mload(Y1_EVAL_LOC), mload(Y3_EVAL_LOC), p), p ) ), p ) - - let sign_term := mulmod(mload(Y2_EVAL_LOC), mload(Y1_EVAL_LOC), p) - sign_term := addmod(sign_term, sign_term, p) - sign_term := mulmod(sign_term, mload(QSIGN_LOC), p) - - /** - * x_identity = endo_term + endo_sqr_term + sign_term + leftovers - * x_identity *= alpha_base - * endo_term = (x_2 * q_beta) * (y_3 + y_1) - * sign_term = -((y2 * q_sign) * (x_1 + x_3)) - * leftovers = - x1 * (y_3 + y_1) + y_1 * (x_1 - x_3) - * y_identity = (endo_term + sign_term + leftovers) * (alpha_base * α) - */ - - let x_identity := addmod(addmod(endo_term, endo_sqr_term, p), addmod(sign_term, leftovers, p), p) - x_identity := mulmod(x_identity, mload(C_ALPHA_BASE_LOC), p) - endo_term := - mulmod( - mulmod(mload(X2_EVAL_LOC), mload(QBETA_LOC), p), - addmod(mload(Y3_EVAL_LOC), mload(Y1_EVAL_LOC), p), - p - ) - sign_term := - sub( - p, - mulmod( - mulmod(mload(Y2_EVAL_LOC), mload(QSIGN_LOC), p), - addmod(mload(X1_EVAL_LOC), sub(p, mload(X3_EVAL_LOC)), p), - p - ) - ) - leftovers := + x_double_identity := mulmod(x_double_identity, mload(C_ALPHA_BASE_LOC), p) + y_double_identity := + mulmod(y_double_identity, mulmod(mload(C_ALPHA_BASE_LOC), mload(C_ALPHA_LOC), p), p) + x_double_identity := mulmod(x_double_identity, mload(QM_EVAL_LOC), p) + y_double_identity := mulmod(y_double_identity, mload(QM_EVAL_LOC), p) + // ELLIPTIC_IDENTITY += (x_double_identity + y_double_identity) * Q_DOUBLE_EVAL + mstore( + ELLIPTIC_IDENTITY, addmod( - sub(p, mulmod(mload(X1_EVAL_LOC), addmod(mload(Y3_EVAL_LOC), mload(Y1_EVAL_LOC), p), p)), - mulmod(mload(Y1_EVAL_LOC), addmod(mload(X1_EVAL_LOC), sub(p, mload(X3_EVAL_LOC)), p), p), + mload(ELLIPTIC_IDENTITY), + mulmod(addmod(x_double_identity, y_double_identity, p), mload(QELLIPTIC_EVAL_LOC), p), p ) - let y_identity := - mulmod( - addmod(addmod(endo_term, sign_term, p), leftovers, p), - mulmod(mload(C_ALPHA_BASE_LOC), mload(C_ALPHA_LOC), p), - p - ) - - // ELLIPTIC_IDENTITY = (x_identity + y_identity) * Q_ELLIPTIC_EVAL - mstore(ELLIPTIC_IDENTITY, mulmod(addmod(x_identity, y_identity, p), mload(QELLIPTIC_EVAL_LOC), p)) + ) // update alpha - // The paper says to use ALPHA^2, we use ALPHA^4 this is a small oversight in the prover protocol mstore(C_ALPHA_BASE_LOC, mulmod(mload(C_ALPHA_BASE_LOC), mload(C_ALPHA_QUAD_LOC), p)) } diff --git a/packages/hardhat/test/constants.ts b/packages/hardhat/test/constants.ts index 0987fc6..5daf4e4 100644 --- a/packages/hardhat/test/constants.ts +++ b/packages/hardhat/test/constants.ts @@ -1,5 +1,5 @@ export const validProof = - "0x032c5a12cfa9108a8f4605468b1e436225046b8f818877c6384cf9dcb28d48541ae3623926947254d6902c16e98c6db60a3b921eb1d1c40c5dbc701fa8b18ebc05fcb82c8746a525ec782a89a713e9f0841acdaf6ad567105c047a4e68cd0b11091b0d59dbc86e3cab576999d3868ad81e2e744bfef521708943b962edef91ce0ae98dc2ccca39f14017e794c63e3bb4ca9f6143c27297e1931cefb4ba9162082575429f71900a7e3757ab9ce44e4c0d5856889355e19ef6678945828156ce220ff0b9bc9ffaa26f60d8b078b8432168da6ae549ecde8ff30c8edf513f94a4460e25fdd8a7f1a5ba77f3283eda17c6e0b96f789636dc857184dd74085e299a701e3b45371994ea15fd7f1acc562319faff27dc0949c56b7f71d9f99d12181e32091ca21162d800926d99436fa7afaefd5a65ce2777e01d5746cb18eb90f1867e0f144b258d6e5fa9686c22122a9356a75f369efc417424c9193ebd310a700f1922230d749dac06b3278d7364a584f60fdb4eb879fca065c628de124ec7f4f2982c3858e7926297db54a5228e578f52a55c5a9e02af3736a7a02cbf1499ec1309089b40d1c7e62687ca09dd5a364e9137295dd0f4603ef11c0e21a221a224c8772bee43fd2dac0648f833412eff8079364ec1e0b801d65efe037e3648d8b0813c0ad2a36705f2d224e39b8759554c7f86a7ecd6c34b4a775df14de1a330ed4d1a030ae9b8d8a596325188da1e9fbf471c3e4a63c2af86c59fa715715ed4b037290314bd90e8e2641990266a92593adab1aaebf3978735bbfcf5b446e7ffa801880b252fceacf67de92504312446531c384ffe9986dca44f7f7d1c6e76709bfabe113992cf5accf214c2a57fc5d3518fa54eb12e31dc4f1ff4ac5dfa8b8af4e05d24d0ec2a665f124dd3b2304c190d62095697faf6e3a06b4c40e482e1ceb20f371a4ed372ea6aa02e7297c346ffbcea8d7b35f298f363baabba38b790db90d5761d7ebffe36106dace62c06c52598af448d41d695979c5c4a9351f12da2c1770d1c0a791090013952218008a2fd29e00229c8257272abd7a7261e88f52ae56cb32bbc1d4d8facf913e81ab2d0d735e1845815cb688a1b1d05df5b5e7a6fcf6f7212bb433caf54aebe5e90c9360ce8fd4ba2d0475ff5466620b217f001fb0c542c2a3ab154f28d9c0678c20601577524188b964391b91ea49997d9f22fc7eafab4237b64b951a6d3b725b9d680da422ca132db5546003301b51b2e5d89ab72217a2cd1dad1b1edb872fcaa01d82d95a3dbe6a1026aea099d301429296a230d7c9f1fa5ca97fb9f7348d412218ce3dfba9d3c45670f5dd833ad70967654f22fdc3b23d7874da6936ae9b35abae92f6c28719b819a9572c8adf1479a86e16024891b285c26e00e652eea3dde624163023cedfe47e70a0c44e186db9423227aadc8b2182af3f97d6eb53ab109f25172590a89f23da1a75e1eb7cc9a4adece4883a9ed0623108fb1456b5d9179b47e0e1814df8d39da6f3b6c19f8639a7b5902a63fda20f27a63252ce228e2a11dd3d99f59ab71d03a3809e3ceb37a7d14afdf91e8912a90ead4dadd24b8f0ae6e35b589d04e3a9e49514e94eba9446bb54e891821cb0688e0ecbdc881e67cc32aa80d281dbae087a228bbc4bc5959c62de0bfd73a342a232e6a443d747d31760d8c3382017aca7ff50c857a22f052bca4c5e65f9afe0c8b9f7018c9107b921265a6fe650ed65145c96d9c526a87bb2030eb0990df4f122ce7f56aee591a357ef469dd69e60c9d28b9df8147dd63ffd767f122e166fc248022908cf5415ed4d1195ef50797c30323931d28e89a83497c39e37b7705641d5dd672252a3a927c9900dca6e8fc8427cf2575386c13ef9480dbed6dd623f206e74a356846a62959186e3bbf66adf5535fef60785fc2d7ce561c980a9476c30f1355937482ee735890870b95d266ed79f9a68aa9df70ab1a6219174f02594c2c259587eeabd501c83bfeab042d2041d356c5b84c824f38698e3025346cb0f4088c2ba48747008899438c4ac1cd84e03c5ee087c5f0dc3d73c2e03ce28db16a1e36c58857e1792ad2a2c5379c65a16abbb346e52bc6dc3bf08bafb7a4d5ef1000e39adfa02ecbb79dc7f2a28ef3a52a6765173627d1939ee9d53d90aa43c41a0acb68c3ac271913ccf5906e4a7c1ff85e2e790622e94edb6b472aa235f90a41098e3840943237db6de8fd3b9f75b6ead0c7232502e81e6edb7af35597e7c75229b17eac26e01cff594a7a083a43b5729e03ddbcc6f7ab834926dbaff6c4da4510b96fcfbc213d8a023814561e3e3605473a57a4b12f1f575b92b5276233b80f28306814a6d748f8884417240d7063f3cd21841f24dbce286eeebecf45a4ee8f070adec0fa757380cd0cd192492251a0b6f78858b5c450141904e2a29e9fef2905f356032fff17bed31469d6c2a8e65fd61a0a28f5a47058bbd59d3ca4bdde47158f5918b6ccc13b9eb9f45190397cf624398165c5ba9f84d9e0422eb14af1ad23762561c8571955ee6b43ce51a6fd8ad0685fc4a7620879f3a0ce2ad3c0975b2e9dcf47f9e43f1d662c5b897dcf62585c3ed8cd808f6859870ced7e8c96ace014af28f0f510656b1368f6f3e2baaf3ebcb759d76ff636a38efb8eb3980cbdee101b58256e15ddf503925688047a56fb7e53d00d58e06c228b91bec8d8a0516318e6e977054e0e3a60863a9ca21f9c46f393fe6e595cad81e33cd765fb65962814e1f88acb260d95b311a8eb19fd1926adaca926b9e6641781dc6f5d6e27b3bd2192d97ac909e13fd57590df7c33533a47a8fe7d5925f28b0b1f758874e0bea02777efd75c9ef52d679883a175bea07c21b2aa2b9d26fcf40e295b60a193212013f653eb7fe1a3af7b725b59a8fa154373a11a815c2f9e56e049e7de559e018214f0d2f736054a55889e1d9f0deacd06dce1f8e8d1e2dae00fd95e4b7ddb04dc1df705f774984c273d10930f623adbb63cf0383458b7b4335cd1e4dc4b02eb80"; + "0x267aee5db68a8c31402e22654ed873d2f3de6491c49c8be14818e650c4fa50a015ce1ae0c496cef272b1c62c0583c3718c1bc85fefdcf5bcdaf869d76d25beac1a83ea857dd7ceeb1c165afa4461695f7f71f9a947b9f3db190e74b8378cbc181ec2c6151749097fb8e4e27d2257c205e372ef919cfdd941a8e7f6eef4a02e6711763ba2a554eaf1ca9c49beab9afdd1f3f39779849163b695111fef8345004616c1688ae57d90c7522a36ef02f6f6d844bbce49955659e8d154cfde2cb0592b13697b8c8ab2ce4f7660264279355a4ad917fac101169b4ae36dee319e5e873f195f8e6624ebac559e83ebb7188300af926843cafda494e79ff59a28627ba08c0c7139c34f0b14038b2c4967b1d57dd456866a7add4c781ef2f05299b11680d1106c91ee16cb2a45f6f8d33a3fa1e7d527003c3ff0aa2813d05f719fd531f1ea225237afd61a58af80f406f0ad838c57a25ebc9fbe9de73eb98d131ee87d32ab16d166262e47d0e67fc0dcdd0fc42605c32d03f2cdea0a31c9350788a68b1ed21184fefb96075fc551253b9da480b0572b5634d66ac2bca50bb0b4229588bf3000b442736763db0d5fec66c374e2e06d3ca07557ac115035d8d4727938a5476e24da8cc92ed8a8b4331b9a9a551ac6886fccccd3e7abe119c9b226f951ea895b0a1e2b51d512b8ff501a3278af6f0bb053fae859a6282b9e57562a93a66393aa023b822f9ead4c978a4abb9fe8c91af86be5d35bf71f63972893fc02d7397d401d37e14ed66c7de9b7d70fa823eaaae7708f937273bedfa03baad5dfbe30b0781bfe36f4c60bcf89f650057fa08f9bef99e0f66dcd866c8af4cd0724a0fb258e24462c3dc72ddebf65471a3be32dbd914efd7c77ad38f61bd3eb4816f9cd415d0308b5dc1dd81a1166f49eaf486062ae698647cf46234518355b9e53042f293414da342398fcd3c51e40f4cd30cee53c8b2fc6e5202d237b25893092c46503932a8c2fb92abcac15702d57c5ac9cd5f627405b8cdfae611bb0fb13cd092803821df8e29594d5dd30f241ca0a1430a529dc3aca5a44cda03866f5025b370394531e5234bbc0d8900f763e046fef5cfed53a5ebcff4cea7ddb321e0a32bcf5eed203b08cda0cea226f13d862ab2bc74aaaab820d2ab4d4d60622f9cc0bfef4841e1c8de564738ec1b9b7a7fbdf9f844f343dea9569d60edd7546da5a50977be0f104a23dcf146e4eddf496f4fc4b3377f862c4ec08f01669941f9e26f2223898341c7a66cf87e7fd42de8d385aee0e1c8090f19a83b23aa7f5bfef7177e028be7313e395b60f03494d55b99b1da58f401cfee6d45c32d7db313720b18f5bcb8e72183fe1099ab404b9abfcb28bf82f85eae78031baea2653ec61b1fcdaab604392023566a40ff1a31f1619e758bdf8e11dc7c7922d4383d007c1cd217b773d13031e4ffcd59e9b8bc703962bdb81bb9eabd5b1ab19d8115f87aee090e61a6450f91366a731d14630671b4f15ea3cc92d5402a20cb342ecfd00c28a8e9ea9787c7c043e883799fb22841c060c4a2067a9097c467907add6c83c3cc219c48be9e50a16631bcbaad9b72915e6ba73b4f753a059feda1052f506af61c44d04e4aaf146105be098bb46b8a3177ba2b30b35dd82b3ad66cff470314e72c36c5087b1ee391c48cd4154602f69b674654be7284f98e3c92badb69bd5ef482b4a48100c5068048af15e19883108f28d9f27d556b592916d5a26f90d3d63d5245853372a20730c7b755d6ab2a17b19fce90c6f7b62d8426f38a9505b6827caff88bad33485301e5c152832959ca3a24cc4cfb356d2d8b98f286e0060395d9ec38c2c10b2f70d06264ade965d5252652fce30ef2173b2a19bbb08dd481061a4316536c8f7734011460026c2d0b23d2f5e0de0a1c056fe13e6921f39f2e0c8ca5f8c9c3bb000890573880a8509d471231058963334d9e314e99f61f7a97cde32f869fd7565c08a1e19fa9a2b63763a1779d828a2e49839eac1b623b3d454e403d36d9c8c839096065c1eb6f08b77d9539312049112fe339865e49cf645bc5890cc7ba7b3a160a11f02914696e519a247fc919700c2bc8a6e3dfb5eb270945e61a77f46cabf30ad1d3163edbfe1d2d1e6f71eba450673e9674570e8b5381569a5ff5bf24e47f07f080b411fc4d6fbe994a7fdad18f73e5ada17cbb27d4efcdea48d1c90b61ed74b2304419114a41626e45570a03241ac7d491b4cf1c14e70ed9ea121510f50240d241a5b93d197c02e50c9fc07b68fd389326ef6ab2457b2c96b6091526259f50b1a29a12a0316d0ecfc7ea7d62901308e12900b11a72749b7c4562c5be94ce02501da922570fbb6d8f56fb38bbad67778ea5ec66820db587ad875d22c2f91cf431aa3834ff52be65087cfdc8cf209bc69ecd3162137c22239564eb01afdb1790a1fbfcc16ae950b3da2539dcb2cf00498cb69a3c233862714d00b6633e383579f2188b53164bf12bfc5d152ec1bc6385c776519729de74da237d44755aed9c44d27cb7063423ff6e7f1550dbe410d5fe235e2b532bc693f8d60633c27454cf64225e5924b489c36341094ccb882ad7134662e26ec21505b59334a4e787bd4422825ceee94981d418759c35129609d791dc95cacfcae6ddaf87c46d777aa1379ae2898f53bbdfb4b94609fbbdd6ebfebc73cd62eedf4b27bd6aab64ba7cb7e1ef917d13e50daa639cf5be0ee792caf5a9bb127bcb8ebb417415ca7564d78734c3807098765f751280a57222114ea9ec97025794a83e2b5b2ac0e9860f32568797726a61eedf52db66f0ab399672a0f90a1c1fec0975370bea8046b612cc25da6b726475e7253a21ff241517497bdab4c0865de90d87b02cdd799a0cfc44703bf531d695562f7113fe66291a0435c01a877d409518f52cc1373003d6e0adbf977a91656b2551d06d076b2e6a29e66b8b332867f6ebeaf86fe2f757bf52447ed54a924a999c064f08c8bc3e954cd112f9fdcf7807fba93ee8f26998aff7eadc50c8a"; export const invalidProof = "0x06cfb880a472af9775ed95274c43848b75f0d97179b878b45ac7b9156d2ee9540c78c2bc34daf9e27c2e2cd67cff6ef467bff8b475b8f3ba8b8818de8fde89f62887e4e48b1510ca6a23d0b1b0eaba1283639b686b4341b2fe940a2e9481bb7d1c04a7be2bcb41e24b866df49924491352834a367883aaad0090997f1f729429271568df0145e43646b7d990921f55a73a0a9e586b2fccc5398f574cdeb7d5cc25a878ebe5cc818081987bbee9aee299c63b483194c822344bfffaffab1563a60dd538bfbee9eeb770e44e6fed939c479b68635fd4231ac37d4002bf8edebe2f2dec9c1ecd001ec1f65352ea38223d60768c361057beed2deee86ba04970caa02f8826b7334155c3da78163576ebe85c167c4dfbd9a1bfc9e132bc7ec4dd345524ef71c4519b13fa52d98b9899cf492caea270db2df92ba7fe59903e4065f3b62d22a8a1f9f5c579d48f87e34b36ec71f213054da57d0e0cb0ac982dad3cfe52141bcfb1350a55594dc3ddc8b49aab197de320d12e274d3175b7a0fdf60f92b2018bf4f97c6485222ec16f9897ddeb87b15809436e8e34eed8912a3d9b0317f9131a5f4f5a7c4359d9b61c731e4332286ca5f06f1e802ab3ec9fae49555422ec18bf27e36ce51e4d82b8e5c8e556826dd610021cba43c3625744ae21025ccec52751eb9cd1a17d205ca94eefdb43dc441584d3e8f70c7b9f47d65f700d2ba71405bf39bc9d452d9479828b0f54e25e7dd492200ca4ffb1d770e8f55f35658ccc15c55cfd64f19c17f0e3705f530db2d64c315abe6995cb3b6f6b7b68d8df89f02831649689eff301d265e84b97f89e6cb5354e6a57883381bd46d955f8ddeeb52711715132b01720b7d71ce44474afdcbfc96e8b248b75aaf468779e147904d1096b8535af5601c3773287a3dc60fe6b56c36be43922f7e167600e2bb6e102db2f085749a4ba75c2dd98a2c7a56c483ed501221441a4f6b446698eee992387df09a5238cfc673977ec9d1e8d716e8afc819ffe3933493237fd7b4a4e38ad7e73048ae55941d1ba6e25f982c956a5546b8d156c14f1dddb3aa3b0f9d77645ff772b7cd633ddbe7f32c69e13c0b5443c1c2267a85b96c6872ecf7f5b36d1372bd41ce1a2eae0ced0036b712881de6cf9e73e78ea70ed384fd3c1c104f85055e2572b57851d904aa377e513d11bad8bf1eaeb7d622f5a7e5ad234c87eaf7086417d26cb11c9494b485cdae4da826ffdf1c3322bf61aed9321c4c4cd4766a7886fdf1c8e178c26a4ec6d576578992695660a7aa7392bb43e41a3b96c0635efb7aec81d0db0bd46014956961d4ae2113b560f9576f08df9d8806b59d2885193c8a7200bea000babda63ec88ddb6b7c27b4e2a0c6424de3e37608639c761e5691293c10ee6d186bee457e38c74f585e6029efbbef22061bbd30a4405b33a69aa6428d924c0f2c7a37beaf3b86ae3e7f01b275ef2538234b79ec6809bb0acec401da4a80d961caafffd57c3c4de0da92df5dd0b1ffc05ac9b5f774b3f0f6f02eeb9eea509ba6416c17fe258f74a87e469d14ae539d0079c4065876bd0a60c21a849d0b72b881eb224a06a2392230df848f96dddc90b3bc7921b209b6e60444a93a125a106b107ff7d1d5b2516b33fff5217575c003b2ce5a7ee685d65de7557e2580cab1c15cd25b5cd519e719da71bfc2cf086813d7185492f9d42494fe6444479a286070a9c66acfd74f0b83e090d68c3be65b34db81020e869b7396d4292e0af29a425e44e572180c1cfe8527dd79da1504532a6d4c8543ac501debb141136f96eb6182e4a88370bb4c0dfa1d2b77568d1bfeddbfcadeb5352a0cc428df079be24a804ff8d65a6a5b3f1de65e8fcc08005f74d2ddae83cc6c5e6c97160fd5d166fb316aab7b3a072f43397daa2c126a55f45f551f05b85a7112ed246f82378a235c525a242a9f9addd1c3c651c25d5a98caa84e9ce913f3d58f9b237bbf56b4f403b12f704163c7b4810a363b2c26bdcda8408b5b9c449352c9cc8766ea5a14b644d160088734583035920d9bd262d9ca7ec08c7c64d6163563f936e176166e6b24f02070454c21ef6f02ccaada7b10f9ecc994f28d37c901488d992f28cfd4dcd3318d2655c113d26cd6f02f94f5f3019c6ddf8ea2ca6ee1a38bb21e39460ad51d81fe8dc6d942fc8d044cbf5d0bdd8dd53cdb0439d4ad74f1b1507be9f7e8fec18068843eae8030b80e32b087a2bc2385cc40a8a50fcde955a833f1302501a87dd05e153d6f132f0b82b26e26b99783d42e78f73114e41c4b56266a98cc8f9f77e3039d5cdf78298cc36c004e7366f8d7b5bd0605d6452e3c3e59b469c63e6322903707766ee6c7c4ea8e339512b53a475841eb5ae7d48c6ee09320d82454490ad167374985c454c6e5563ab708fcdfa3b5a435ab5dfd15392fc39e83a6440b5351db346c074612fbfdb7d883f60b23030038012a6ea5736adbbad665536cb61f70f458a7965e45cf2a3b54b88d91c3fa850b6b832a3c2205cbc00fae4f06b64d42fdf3dd2242b95c3087dd7cc6971b77b38f4ba4a9885817ce003f8cf42b4a52911acfa6d9c09f6791dd0380103c9d751712ed0d0cd7564bbd337203850d9271d16aa34fc087b801047028b2cbf5d129ee52779a680ec0e13e7d18fd9e5ea75cc29ce2f2b3929a040b7a831cb5f9a73ca6f4515aafe4bc5a5346fa784aae1424619da9717836eaeb1dd5ea96dcda0f76138b5545550bf7650fc91c73302fbbdab2845f5598824064294ef07c6be4c149923616cb6ca35d27d9fde5d7b620941af0a09b4bdd77c24b92337d82ebe78c255ef77d9760327bd193b4a0e7fb14faeda0812d5056faa9bacd99ae0c3c793700c5fee9a887083c40dc2abed3fa65c30251d32416365a82f9a2ec4aeacfcfed52aa30ee741073f53184cb37d9eded50bde2bda00fac1150f450e1b210e7fa737a7c3fff92cc53de9493da68b8395902551294456d32b2b81fe36dc1f7c6480f09b47addf661456050adefb199c0e68de56"; diff --git a/packages/nextjs/generated/circuits.json b/packages/nextjs/generated/circuits.json index 8cc3dc4..3c243df 100644 --- a/packages/nextjs/generated/circuits.json +++ b/packages/nextjs/generated/circuits.json @@ -1,5 +1,7 @@ { "LessThanSignedAge": { + "noir_version": "0.17.0+b6819f6261e63cea3e653a1b874727a2b5919f5e", + "hash": 15292217675152964000, "backend": "acvm-backend-barretenberg", "abi": { "parameters": [ @@ -241,8 +243,134 @@ "return_type": null, "return_witnesses": [] }, - "bytecode": "H4sIAAAAAAAA/+XYZ1MTURSA4RtQFAsi9oI0ERGRLElIIiJNREREROwFIonYe2+IiIiIiAiMfvGn6jFnhzuv6AdZB2fcmbDzhOTuuacsCV+MMV9N8vB9f6ToOdOyPBZaToXnwfPhNHgBvBBOhxfBi+El8FI4A14GZ8LL4Sx4BbwSXgWvhtfAa+F18Hp4A7wRzoY3wTlwLpynljoa/b0x07Wfp79Ls2qZrnVarPVYqnlfpvldrnlcoflapXlZo/tfp/vcoPvJ1rhz9Pp5Vnz5iLcA3gwXwlvgIngrXAxvg0vg7XApvAMug/2wA5fDATgIh+AKOAxH4Ci8E66Ed8FV8G64Gq6Ba810P8pzuSZ5SB8UaL0Lta5FWr9irVOJ1qNU816m+XU0jwHNV0jzEtb9R3WflbqfKo27WuOrteKrQ7z18B64Ad4LN8L74CZ4P9wMH4Bb4INwK3wIboMPw+3wEbjDqqd7/zSax3rNV4PmpVH336T7bNb9tGjcrRpfm8bRrtfrsK53FNc/Bh+HT8An4VPwafgMfBY+B3fCXXAMPg93w3E4AV+Ae+CL8CX4MnwFvgpfg6/DN+Cb8C34NnwHvgvfg+/DD+CH8CP4MfwEfgo/g5/DvfALuA9+CffDr+AB+DU8CL+Bh+C38DD8Dh6B38Oj8Ad4DP4Ij8OfzPT9RT6v1JjkIfcBmX2Zd5lxmWuZZZlfmVmZU5nNTpOcwZhJzprMl8yUzJHMTo9JzojMhcyC9L/0vPS59Lb0s/Sw9K30qvSn9KT0ofSe9Jv0mPSV9JL0j/SM9In0Rq9J9kCf1rpfazqgtRvUGg1pLYY15yOa21HN4Zjmalxz4uZnwiQ/k6Xqg0eKnmv07J/d4fistQL+imAwHi6POwGny18ejUVC/mAoVhFxIk4oEuoujwQC8UgwEo7GomF/1AkG4k4iFA0kdLEJb+Jy5McMW//X1/6xfoq15qSep6zn0q06uq9N07PUwq25fI7Pst7ns84+a40s6z0zvcb3i3XSrefc92dYsRjvcuJPs67r1ZoZ1ppeB+y4wzhpJVMshczENVP/wrXdtbwcyNmu9dm7Pfp/l78/jTOeSEiozqSHe57ysK4e5e+nG5jPo/y5e570sM61us7//sdd5rDDqpfcS+bynzX5Zm6/nNcZb79Musc3xHiT2TEVAAA=", - "proving_key": null, - "verification_key": null + "bytecode": "H4sIAAAAAAAA/83YdXMTWwCG8ZPbey8Opbi7W7ZJ2gQt7u4OgQR3d3fXAsOHhYdNZ3Ye5A+6zLAz7c4vTbabs8me9z2fQgifQ7xlvv78U9vXJ8xPx4Tr5H/l/+T/5Q5yR7mT3FnuIneVu8nd5R5yvdxTbpB7yb3lPnJfuZ/cXx4gD5QHyYPlIfJQeZg8XB4hj5RHyaPlMfJYeZw8Xp4gT5QnyZPlKfJUeZqclSO5Uc7JebkgN8nNclEuydPlGfJMeZY8W54jt8hz5XnyfHmBvFBeJC+Wl8hL5WXycnmFvFJeJa+W18hr5XXyenmDvFHeJG+Wt8hb5W3ydnmHvFPeJe+W98h75bK8T94vV+SqfEA+KB+SD8tH5KPyMfm4fEI+KZ+ST8tn5LPyOfm8fEG+KF+SL8tX5KvyNfm6fEO+Kd+Sb8t35LvyPfm+/EB+KD+SH8tP5KfyM/m5/EJ+Kb+SX8tv5LfyO/l9iDNGXc3e2h5rqe2z7duiTOJYuWxTPl9pbqxEuWhvtrFULhay+UK5qRgVo0KxsL+xmMtVivlic6lcas6WonyuElULpVy1drD36ZxXxK8fvPXUjp0c19ba/kOIs2hIXAs28mpD4vmZxD6TuCYNidf86DmZnxynU+Kxttd3T/w9zTf/bQCS/zytY7bWBtLHbe8HqjW9c8y2XVQudL3Gti7l8fhTX6r2HutjiuP5q/H73fOsVKucatSa4nv+kOJ1TWn8vrvB/c3fm7m14xBMCaMEUEInQZNwSaAkRBIcCYt7QhwKyyEOfwQ+Qh7BjjB3MMShjaBGOCOQEcIIXoQtAhahiiBFeCIwEZIIRoQhAhChh6BDuCHQEGIILoSVmyEOJQQRwgeBg5BBsCBMECAIDQQFwgGBgBDAxM9kzwTPpM5EzuTNhM0kzfdwY+J6cS/hc88EwcTBwkXbYgU3dRYiWHxgwYFFBm7qLCZw72HRgMmAxQEWBFgEoPhT9in4lHqKPOWdwk5Jp5hTxoeHuHSPDHG5plBToinOlOXxIS7FFGHKL4WXkkuxpczywWMSoKhSTimklFCKJ2WTgkmppEhSHimMlESKIWWwJcSlb16Iyx2FjhJHcaOsLQlxKaOIUb4oXJQsihVligJFaaIoUY42JMY1uX0Bhx18m20SAAA=" + }, + "Simple": { + "noir_version": "0.17.0+b6819f6261e63cea3e653a1b874727a2b5919f5e", + "hash": 16445193290827983000, + "backend": "acvm-backend-barretenberg", + "abi": { + "parameters": [ + { + "name": "x", + "type": { + "kind": "field" + }, + "visibility": "private" + }, + { + "name": "y", + "type": { + "kind": "field" + }, + "visibility": "public" + }, + { + "name": "z", + "type": { + "kind": "array", + "length": 32, + "type": { + "kind": "integer", + "sign": "unsigned", + "width": 8 + } + }, + "visibility": "private" + }, + { + "name": "w", + "type": { + "kind": "array", + "length": 32, + "type": { + "kind": "integer", + "sign": "unsigned", + "width": 8 + } + }, + "visibility": "public" + } + ], + "param_witnesses": { + "w": [ + 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 + ], + "x": [ + 1 + ], + "y": [ + 2 + ], + "z": [ + 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 + ] + }, + "return_type": null, + "return_witnesses": [] + }, + "bytecode": "H4sIAAAAAAAA/+2daZPMVxTGH8Yy9n3f953u6Vm67YQQgiAIghhmBEEQBEEQBEEQBEEQBEEQBEGYr5IPkv+p6VTdOvJunlN1b9XtqltTJy+O3znP+N1g+t9VAP5B9atWcmonpyA5hU5dR9V1VV1P1fVVXajqBqpuqOpGqm6s6iaqbqrqZqpuruoWqm6p6laqbq3qNqpuq+p2qm6v6g6q7qjqTqrurOouqu6q6m6q7q7qHqruqepequ6t6j6q7qvqfqrur+oBqh6o6kGqHqzqIaoequphqk6pOq3qIlVnVF2s6hJVl6q6TNVZVedUPVzVI1Q9UtWjVD1a1WNUPVbV41Q9Pl+7r4L817H5r5lUaXFxRVlRRTqTXpoqypVnS1LFJeWl2XQ2XZItWV6UzWQqssXZslx5riyVSxdnKtKVJblMZar6VcvplarZK12byPUOjytVkN+pftVSu0zV7JVmMru8E1DteuS/L/T3Qj2DWaB+Hb2/pv/z36i/uEU4Ewz6TgTvm95q7on8jFJOy7eYa7qHiUacbHkWEHPqReR6F+HJk8ns8k5ClCclnEkGfSfDb3nK3JP5GZlKqQ5x/t5ErvcQnpSYzC7vFEQpUcKZYtB3KvyWksw9lZ+RqZTqEufvQ+R6H+FJicns8k5DlBIlnGkGfafDbynJ3NP5GZmwyv/RTQX/j60zEIaM6xF32ZfI9QHCkzGT2eWdiShjSjgzDfrOgt8ylrln8TMyYZVLYwb4Mp6NMGRcn7jLfkSuDxGejJnMLu8cRBlTwplj0Hcu/JaxzD2Xn5EJq1was8GX8TyEIeNC4i77E7k+QngyZjK7vPMRZUwJZ75B3wXwW8Yy9wJ+RiascmnMA1/GCxGGjBsQdzmAyPUxwpMxk9nlXYQoY0o4iwz6LobfMpa5F/MzMmGVS2Mh+DJegjBk3JC4y4FErk8QnoyZzC7vUkQZU8JZatC3HH7LWOYu52dkwiqXxhLwZbwMYci4EXGXg4hcyxGejJnMLm8Foowp4VQY9K2E3zKWuSv5GZmwyqWxDHwZr0AYMm5M3OVgItenCE/GTGaXdyWijCnhrDTouwp+y1jmXsXPyIRVLo0V4Mt4NcKQcRPiLocQuT5DeDJmMru8axBlTAlnjUHftfBbxjL3Wn5GJqxyaawGX8brEIaMmxJ3OZTI9TnCkzGT2eVdjyhjSjjrDfpugN8ylrk38DMyYZVLYx34Mt6IMGTcjLjLYUSuLxCejJnMLu8mRBlTwtlk0Hcz/JaxzL2Zn5EJq1waG8GX8RaEIePmxF2miFxfIjwZM5ld3q2IMqaEs9Wg7zb4LWOZexs/IxNWuTS2gC/j7QhDxi2Iu0wTub5CeDJmMru8OxBlTAlnh0HfnfBbxjL3Tn5GJqxyaWwHX8a7EIaMWxJ3WUTk+hrhyZjJ7PLuRpQxJZzdBn33wG8Zy9x7+BmZsMqlsQt8Ge9FGDJuRdxlhsj1DcKTMZPZ5d2HKGNKOPsM+u6H3zKWuffzMzJhlUtjL/gyPoAwZNyauMtiIte3CE/GTGaX9yCijCnhHDToewh+y1jmPsTPyIRVLo0D4Mv4MMKQcRviLkuIXN8hPBkzmV3eI4gypoRzxKDvUfgtY5n7KD8jE1a5NA6DL+NjCEPGbYm7LCVyfY/wZMxkdnmPI8qYEs5xg74n4LeMZe4T/IxMWOXSOAa+jE8iDBm3I+6yjMj1A8KTMZPZ5T2FKGNKOKcM+p6G3zKWuU/zMzJhlUvjJPgyPoMwZNyeuMssketHhCdjJrPLexZRxpRwzhr0PQe/ZSxzn+NnZMIql8YZ8GV8HmHIuANxlzki108IT8ZMZpf3AqKMKeFcMOh7EX7LWOa+yM/IhFUujfPgy/gSwpBxR+IuhxO5fkZ4MmYyu7yXEWVMCeeyQd8r8FvGMvcVfkYmrHJpXAJfxlcRhow7EXc5gsj1C8KTMZPZ5b2GKGNKONcM+l6H3zKWua/zMzJhlUvjKvgyvoEwZNyZuMuRRK5fEZ6Mmcwu701EGVPCuWnQ9xb8lrHMfYufkQmrXBo3wJfxbYQh4y7EXY4icv2G8GTMZHZ57yDKmBLOHYO+d+G3jGXuu/yMTFjl0rgNvozvIQwZdyXucjSR63eEJ2Mms8t7H1HGlHDuG/R9AL9lLHM/4GdkwiqXxj3wZfwQYci4G3GXY4hcfyA8GTOZXd5HiDKmhPPIoO9j+C1jmfsxPyMTVrk0HoIv4ycIQ8bdibscS+T6E+HJmMns8j5FlDElnKcGfZ/BbxnL3M/4GZmwyqXxBHwZP0cYMu5B3OU4ItdfCE/GTGaX9wWijCnhvDDo+xJ+y1jmfsnPyIRVLo3n4Mv4FcKQcU/iLscTuf5GeDJmMru8rxFlTAnntUHfN/BbxjL3G35GJqxyabwCX8ZVxnPXlE/yqTLIqEe+j/DKb2KRSF1UC6N+cgqT0yA5DZPTKDmNkyOfUC2/ueXz+JonRz59RB56L89alkd8ypPl5IFG8hwNefu2vGtQ3qwiPyMtP5onPxEi/xApf//dPTnC0DP/VV4isF7J6Z2cPsnpm5x+yemfnAHJGZicQckZnBz5hGv5YFX5PD9ZvIhBHpovz2qWR4TKk+nkgUjyHA55+7e861De7CI/Yy0/2ic/USL/kPnf35/LnxbG4+3Xv2dRvhPNugAA" } } \ No newline at end of file diff --git a/packages/nextjs/generated/deployedContracts.ts b/packages/nextjs/generated/deployedContracts.ts index 92cf12d..8979806 100644 --- a/packages/nextjs/generated/deployedContracts.ts +++ b/packages/nextjs/generated/deployedContracts.ts @@ -5,7 +5,7 @@ const contracts = { name: "localhost", contracts: { BalloonToken: { - address: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", + address: "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707", abi: [ { inputs: [], @@ -285,7 +285,7 @@ const contracts = { ], }, BalloonVendor: { - address: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9", + address: "0x0165878A594ca255338adfa4d48449f69242Eb8F", abi: [ { inputs: [ @@ -563,7 +563,7 @@ const contracts = { ], }, VerifierLessThanSignedAge: { - address: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", + address: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9", abi: [ { inputs: [], @@ -646,7 +646,7 @@ const contracts = { ], }, YourContract: { - address: "0x5FbDB2315678afecb367f032d93F642f64180aa3", + address: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9", abi: [ { inputs: [ diff --git a/packages/nextjs/hooks/noir/useProofGenerator.ts b/packages/nextjs/hooks/noir/useProofGenerator.ts index 6e3e515..b7be069 100644 --- a/packages/nextjs/hooks/noir/useProofGenerator.ts +++ b/packages/nextjs/hooks/noir/useProofGenerator.ts @@ -1,63 +1,26 @@ -import { Circuit, CircuitAbiParameters, CircuitName, CircuitParameterWitnesses, circuits } from "~~/utils/noir/circuit"; -import { NoirBrowser } from "~~/utils/noir/noirBrowser"; +import { BarretenbergBackend } from "@noir-lang/backend_barretenberg"; +import { Noir } from "@noir-lang/noir_js"; +import { Circuit, CircuitName, circuits } from "~~/utils/noir/circuit"; let isGeneratingProof = false; export type HexString = `0x${string}`; -export type ParsedArgs = Record; - -function formatArgs(parameterWitnesses: CircuitParameterWitnesses, parsedArgs: ParsedArgs): HexString[] { - // NOTE: workaround for not being able to use named parameters in proof generation - const sortedKeys = Object.entries(parameterWitnesses) - .map(([key, paramPostitions]) => { - return { - key, - paramPostitions, - }; - }) - .sort((a, b) => { - return a.paramPostitions[0] - b.paramPostitions[0]; - }) - .map(({ key }) => key); - - return sortedKeys.reduce((acc, key) => { - return acc.concat(parsedArgs[key]); - }, [] as HexString[]); -} - -function getPublicInputsLength(parameters: CircuitAbiParameters) { - return parameters - .filter(param => param.visibility === "public") - .reduce((acc, param) => { - if (param.type.kind === "array") { - return acc + param.type.length; - } else { - return acc + 1; - } - }, 0); -} +export type ParsedArgs = Record; // This function generates the proof ✅ export const generateProof = async (circuitName: CircuitName, parsedArgs: ParsedArgs) => { isGeneratingProof = true; - const noir = new NoirBrowser(); try { const circuit = circuits[circuitName] as Circuit; - await noir.init(circuit.bytecode); - const formattedArgs = formatArgs(circuit.abi.param_witnesses, parsedArgs); - const witness: Uint8Array = await noir.generateWitness(formattedArgs); - const proof: Uint8Array = await noir.generateProof(witness); - - const publicInputsLength = getPublicInputsLength(circuit.abi.parameters); - const slicedProof = proof.slice(32 * publicInputsLength); + const backend = new BarretenbergBackend(circuit); + const noir = new Noir(circuit, backend); + const { proof } = await noir.generateFinalProof(parsedArgs); return { - witness: Buffer.from(witness).toString("hex"), - proof: Buffer.from(slicedProof).toString("hex"), + proof: Buffer.from(proof).toString("hex"), }; } finally { isGeneratingProof = false; - noir.destroy(); } }; diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index 7e04dcd..3ebaa1d 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -14,12 +14,12 @@ "vercel:yolo": "vercel --build-env NEXT_PUBLIC_IGNORE_BUILD_ERROR=true" }, "dependencies": { - "@aztec/bb.js": "^0.3.6", "@ethersproject/networks": "^5.7.1", "@ethersproject/providers": "^5.7.2", "@ethersproject/web": "^5.7.1", "@heroicons/react": "^2.0.11", - "@noir-lang/acvm_js": "git+https://git@github.com/noir-lang/acvm-js-wasm.git#b9d9ca9dfc5140839f23998d9466307215607c42", + "@noir-lang/backend_barretenberg": "^0.17.0", + "@noir-lang/noir_js": "^0.17.0", "@rainbow-me/rainbowkit": "1.0.8", "@uniswap/sdk-core": "^4.0.1", "@uniswap/v2-sdk": "^3.0.1", diff --git a/packages/nextjs/pages/age-restricted-example/GenerateProof.tsx b/packages/nextjs/pages/age-restricted-example/GenerateProof.tsx index 81ee265..48f06fa 100644 --- a/packages/nextjs/pages/age-restricted-example/GenerateProof.tsx +++ b/packages/nextjs/pages/age-restricted-example/GenerateProof.tsx @@ -50,8 +50,8 @@ export const parseForm = (form: TForm) => { const issuer_public_key_x = pub_key_array.slice(1, Math.round(pub_key_array.length / 2)); const issuer_public_key_y = pub_key_array.slice(Math.round(pub_key_array.length / 2)); return { - required_birth_year: [ethers.utils.hexZeroPad(ethers.utils.hexlify(form.requiredBirthYear), 32)], - subject_birth_year: [ethers.utils.hexZeroPad(ethers.utils.hexlify(form.birthYear), 32)], + required_birth_year: form.requiredBirthYear, + subject_birth_year: form.birthYear, issuer_public_key_x, issuer_public_key_y, subject_eth_address: buildNoirIntArray(form.personEthereumAddress), @@ -118,10 +118,10 @@ export const GenerateProof = ({ requiredBirthYear }: { requiredBirthYear: number The proof is generated in the browser using the following libraries:
  • - - + -
  • - - + -
Check out the implementation here:{" "} diff --git a/packages/nextjs/utils/noir/noirBrowser.ts b/packages/nextjs/utils/noir/noirBrowser.ts deleted file mode 100644 index f6d52fe..0000000 --- a/packages/nextjs/utils/noir/noirBrowser.ts +++ /dev/null @@ -1,69 +0,0 @@ -// inspiration from here: https://github.com/noir-lang/noir-starter/blob/main/next-hardhat/utils/noir/noirBrowser.ts -import { CircuitBytecode } from "./circuit"; -import { BarretenbergApiAsync, Crs, RawBuffer, newBarretenbergApiAsync } from "@aztec/bb.js/dest/browser/index.js"; -import { Ptr } from "@aztec/bb.js/dest/node/types"; -import initACVM, { compressWitness, executeCircuit } from "@noir-lang/acvm_js"; -import { decompressSync } from "fflate"; - -export class NoirBrowser { - acir = ""; - acirBuffer: Uint8Array = Uint8Array.from([]); - acirBufferUncompressed: Uint8Array = Uint8Array.from([]); - - api = {} as BarretenbergApiAsync; - acirComposer = {} as Ptr; - - async init(bytecode: CircuitBytecode) { - await initACVM(); - this.acirBuffer = Buffer.from(bytecode, "base64"); - this.acirBufferUncompressed = decompressSync(this.acirBuffer); - - this.api = await newBarretenbergApiAsync(4); - - const [, total] = await this.api.acirGetCircuitSizes(this.acirBufferUncompressed); - const subgroupSize = Math.pow(2, Math.ceil(Math.log2(total))); - const crs = await Crs.new(subgroupSize + 1); - await this.api.commonInitSlabAllocator(subgroupSize); - await this.api.srsInitSrs(new RawBuffer(crs.getG1Data()), crs.numPoints, new RawBuffer(crs.getG2Data())); - - this.acirComposer = await this.api.acirNewAcirComposer(subgroupSize); - } - - async generateWitness(input: `0x${string}`[]): Promise { - const initialWitness = new Map(); - input.forEach((value, index) => { - initialWitness.set(index + 1, value); - }); - - const witnessMap = await executeCircuit(this.acirBuffer, initialWitness, () => { - throw Error("unexpected oracle"); - }); - - const witnessBuff = compressWitness(witnessMap); - return witnessBuff; - } - - async generateProof(witness: Uint8Array) { - const proof = await this.api.acirCreateProof( - this.acirComposer, - this.acirBufferUncompressed, - decompressSync(witness), - false, - ); - return proof; - } - - async verifyProof(proof: Uint8Array) { - await this.api.acirInitProvingKey(this.acirComposer, this.acirBufferUncompressed); - const verified = await this.api.acirVerifyProof(this.acirComposer, proof, false); - return verified; - } - - async destroy() { - try { - await this.api.destroy(); - } catch (err: any) { - console.error(err.stack); - } - } -} diff --git a/packages/noir/.gitignore b/packages/noir/.gitignore index 37ba137..044922a 100644 --- a/packages/noir/.gitignore +++ b/packages/noir/.gitignore @@ -3,8 +3,6 @@ node_modules coverage coverage.json temp -*Prover.toml -*Verifier.toml *plonk_vk.sol circuits/**/target* circuits/**/proofs* diff --git a/packages/noir/circuits/LessThanSignedAge/Nargo.toml b/packages/noir/circuits/LessThanSignedAge/Nargo.toml index 7114589..8f5e344 100644 --- a/packages/noir/circuits/LessThanSignedAge/Nargo.toml +++ b/packages/noir/circuits/LessThanSignedAge/Nargo.toml @@ -1,7 +1,7 @@ [package] name = "LessThanSignedAge" type = "bin" -authors = [""] -compiler_version = "0.9.0" +authors = ["Kryha"] +compiler_version = "0.17.0" [dependencies] diff --git a/packages/noir/circuits/LessThanSignedAge/Prover.toml b/packages/noir/circuits/LessThanSignedAge/Prover.toml new file mode 100644 index 0000000..e786d10 --- /dev/null +++ b/packages/noir/circuits/LessThanSignedAge/Prover.toml @@ -0,0 +1,158 @@ +required_birth_year = 2013 +subject_eth_address = [ +0x70, +0x99, +0x79, +0x70, +0xc5, +0x18, +0x12, +0xdc, +0x3a, +0x01, +0x0c, +0x7d, +0x01, +0xb5, +0x0e, +0x0d, +0x17, +0xdc, +0x79, +0xc8 +] +issuer_public_key_x = [ +0xba, +0x57, +0x34, +0xd8, +0xf7, +0x09, +0x17, +0x19, +0x47, +0x1e, +0x7f, +0x7e, +0xd6, +0xb9, +0xdf, +0x17, +0x0d, +0xc7, +0x0c, +0xc6, +0x61, +0xca, +0x05, +0xe6, +0x88, +0x60, +0x1a, +0xd9, +0x84, +0xf0, +0x68, +0xb0 +] +issuer_public_key_y = [ +0xd6, +0x73, +0x51, +0xe5, +0xf0, +0x60, +0x73, +0x09, +0x24, +0x99, +0x33, +0x6a, +0xb0, +0x83, +0x9e, +0xf8, +0xa5, +0x21, +0xaf, +0xd3, +0x34, +0xe5, +0x38, +0x07, +0x20, +0x5f, +0xa2, +0xf0, +0x8e, +0xec, +0x74, +0xf4 +] +issuer_signed_message = [ +0xb1, +0x63, +0xe6, +0xa6, +0x9d, +0x87, +0x6e, +0xe7, +0xea, +0x5f, +0x0e, +0x53, +0xa4, +0x03, +0x9d, +0x05, +0x04, +0xe5, +0xa5, +0x56, +0xf1, +0xb6, +0x78, +0x91, +0x83, +0xf5, +0x00, +0x79, +0xcb, +0x5d, +0xfc, +0x7d, +0x69, +0xe5, +0x7a, +0xf3, +0xc9, +0xed, +0xd4, +0xfd, +0x0c, +0x7f, +0x0d, +0x3b, +0xa3, +0xff, +0x02, +0xc2, +0xeb, +0xb0, +0xac, +0x0d, +0x6a, +0xe3, +0x12, +0xd2, +0x8e, +0xd5, +0x63, +0x69, +0xa2, +0xaa, +0x10, +0x1b +] +subject_birth_year = 2016 diff --git a/packages/noir/circuits/LessThanSignedAge/Verifier.toml b/packages/noir/circuits/LessThanSignedAge/Verifier.toml new file mode 100644 index 0000000..0326f44 --- /dev/null +++ b/packages/noir/circuits/LessThanSignedAge/Verifier.toml @@ -0,0 +1,4 @@ +issuer_public_key_x = ["0x00000000000000000000000000000000000000000000000000000000000000ba", "0x0000000000000000000000000000000000000000000000000000000000000057", "0x0000000000000000000000000000000000000000000000000000000000000034", "0x00000000000000000000000000000000000000000000000000000000000000d8", "0x00000000000000000000000000000000000000000000000000000000000000f7", "0x0000000000000000000000000000000000000000000000000000000000000009", "0x0000000000000000000000000000000000000000000000000000000000000017", "0x0000000000000000000000000000000000000000000000000000000000000019", "0x0000000000000000000000000000000000000000000000000000000000000047", "0x000000000000000000000000000000000000000000000000000000000000001e", "0x000000000000000000000000000000000000000000000000000000000000007f", "0x000000000000000000000000000000000000000000000000000000000000007e", "0x00000000000000000000000000000000000000000000000000000000000000d6", "0x00000000000000000000000000000000000000000000000000000000000000b9", "0x00000000000000000000000000000000000000000000000000000000000000df", "0x0000000000000000000000000000000000000000000000000000000000000017", "0x000000000000000000000000000000000000000000000000000000000000000d", "0x00000000000000000000000000000000000000000000000000000000000000c7", "0x000000000000000000000000000000000000000000000000000000000000000c", "0x00000000000000000000000000000000000000000000000000000000000000c6", "0x0000000000000000000000000000000000000000000000000000000000000061", "0x00000000000000000000000000000000000000000000000000000000000000ca", "0x0000000000000000000000000000000000000000000000000000000000000005", "0x00000000000000000000000000000000000000000000000000000000000000e6", "0x0000000000000000000000000000000000000000000000000000000000000088", "0x0000000000000000000000000000000000000000000000000000000000000060", "0x000000000000000000000000000000000000000000000000000000000000001a", "0x00000000000000000000000000000000000000000000000000000000000000d9", "0x0000000000000000000000000000000000000000000000000000000000000084", "0x00000000000000000000000000000000000000000000000000000000000000f0", "0x0000000000000000000000000000000000000000000000000000000000000068", "0x00000000000000000000000000000000000000000000000000000000000000b0"] +issuer_public_key_y = ["0x00000000000000000000000000000000000000000000000000000000000000d6", "0x0000000000000000000000000000000000000000000000000000000000000073", "0x0000000000000000000000000000000000000000000000000000000000000051", "0x00000000000000000000000000000000000000000000000000000000000000e5", "0x00000000000000000000000000000000000000000000000000000000000000f0", "0x0000000000000000000000000000000000000000000000000000000000000060", "0x0000000000000000000000000000000000000000000000000000000000000073", "0x0000000000000000000000000000000000000000000000000000000000000009", "0x0000000000000000000000000000000000000000000000000000000000000024", "0x0000000000000000000000000000000000000000000000000000000000000099", "0x0000000000000000000000000000000000000000000000000000000000000033", "0x000000000000000000000000000000000000000000000000000000000000006a", "0x00000000000000000000000000000000000000000000000000000000000000b0", "0x0000000000000000000000000000000000000000000000000000000000000083", "0x000000000000000000000000000000000000000000000000000000000000009e", "0x00000000000000000000000000000000000000000000000000000000000000f8", "0x00000000000000000000000000000000000000000000000000000000000000a5", "0x0000000000000000000000000000000000000000000000000000000000000021", "0x00000000000000000000000000000000000000000000000000000000000000af", "0x00000000000000000000000000000000000000000000000000000000000000d3", "0x0000000000000000000000000000000000000000000000000000000000000034", "0x00000000000000000000000000000000000000000000000000000000000000e5", "0x0000000000000000000000000000000000000000000000000000000000000038", "0x0000000000000000000000000000000000000000000000000000000000000007", "0x0000000000000000000000000000000000000000000000000000000000000020", "0x000000000000000000000000000000000000000000000000000000000000005f", "0x00000000000000000000000000000000000000000000000000000000000000a2", "0x00000000000000000000000000000000000000000000000000000000000000f0", "0x000000000000000000000000000000000000000000000000000000000000008e", "0x00000000000000000000000000000000000000000000000000000000000000ec", "0x0000000000000000000000000000000000000000000000000000000000000074", "0x00000000000000000000000000000000000000000000000000000000000000f4"] +required_birth_year = "0x00000000000000000000000000000000000000000000000000000000000007dd" +subject_eth_address = ["0x0000000000000000000000000000000000000000000000000000000000000070", "0x0000000000000000000000000000000000000000000000000000000000000099", "0x0000000000000000000000000000000000000000000000000000000000000079", "0x0000000000000000000000000000000000000000000000000000000000000070", "0x00000000000000000000000000000000000000000000000000000000000000c5", "0x0000000000000000000000000000000000000000000000000000000000000018", "0x0000000000000000000000000000000000000000000000000000000000000012", "0x00000000000000000000000000000000000000000000000000000000000000dc", "0x000000000000000000000000000000000000000000000000000000000000003a", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x000000000000000000000000000000000000000000000000000000000000000c", "0x000000000000000000000000000000000000000000000000000000000000007d", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000000000000000000b5", "0x000000000000000000000000000000000000000000000000000000000000000e", "0x000000000000000000000000000000000000000000000000000000000000000d", "0x0000000000000000000000000000000000000000000000000000000000000017", "0x00000000000000000000000000000000000000000000000000000000000000dc", "0x0000000000000000000000000000000000000000000000000000000000000079", "0x00000000000000000000000000000000000000000000000000000000000000c8"] diff --git a/packages/noir/circuits/LessThanSignedAge/src/main.nr b/packages/noir/circuits/LessThanSignedAge/src/main.nr index 289ee77..8d7b00d 100644 --- a/packages/noir/circuits/LessThanSignedAge/src/main.nr +++ b/packages/noir/circuits/LessThanSignedAge/src/main.nr @@ -68,6 +68,14 @@ fn main( issuer_signed_message, claim_payload, ); + // TODO: use below code when this issue is resolved: https://github.com/Kryha/scaffold-eth-2-noir/issues/12 + // let is_verified = std::ecdsa_secp256k1::verify_signature( + // issuer_public_key_x, + // issuer_public_key_y, + // issuer_signed_message, + // claim_payload, + // ); + // assert(is_verified); } #[test] diff --git a/yarn.lock b/yarn.lock index ff52d69..fd4ee36 100644 --- a/yarn.lock +++ b/yarn.lock @@ -36,17 +36,17 @@ __metadata: languageName: node linkType: hard -"@aztec/bb.js@npm:^0.3.6": - version: 0.3.6 - resolution: "@aztec/bb.js@npm:0.3.6" +"@aztec/bb.js@npm:0.8.10": + version: 0.8.10 + resolution: "@aztec/bb.js@npm:0.8.10" dependencies: comlink: ^4.4.1 commander: ^10.0.1 debug: ^4.3.4 - idb-keyval: ^6.2.1 + tslib: ^2.4.0 bin: - bb.js: dest/main.js - checksum: 49fff5414885025be8cefa1b52ac52265275f2a9121d389b8f6641088a5e4a9c44b25e754c5ff6616e1ccbb0ccfefec4a64a5862903d38fb3f3968a1e608532d + bb.js: dest/node/main.js + checksum: c77f6e27f626edca1477e4d94794d43b373dfcb527f00579e20270fc92794f9e4bc5df2c25ebbce564700c114cdf69e0b213ddb0192c24af4fc4cdf468918702 languageName: node linkType: hard @@ -2985,10 +2985,48 @@ __metadata: languageName: node linkType: hard -"@noir-lang/acvm_js@git+https://git@github.com/noir-lang/acvm-js-wasm.git#b9d9ca9dfc5140839f23998d9466307215607c42": - version: 0.0.0-d576736 - resolution: "@noir-lang/acvm_js@https://git@github.com/noir-lang/acvm-js-wasm.git#commit=b9d9ca9dfc5140839f23998d9466307215607c42" - checksum: 2c7f8ccd48d66533bfc7e0d13418f5d1130e0bdbd3484dd1bc62b45a61d15bb3571036cf17931eca36e57cac319bf130d01614ea7c2dc3bd50ca681d3b60e81b +"@noir-lang/acvm_js@npm:0.29.0": + version: 0.29.0 + resolution: "@noir-lang/acvm_js@npm:0.29.0" + checksum: 8ea2944c2f4bfb3f1160010711ab725f52925fbe214cb920116d14c20cddb1515c61718010dd6a4ccdaf8a56759adfe005d238a3fc9670dd7071dff7d84d4cfd + languageName: node + linkType: hard + +"@noir-lang/backend_barretenberg@npm:^0.17.0": + version: 0.17.0 + resolution: "@noir-lang/backend_barretenberg@npm:0.17.0" + dependencies: + "@aztec/bb.js": 0.8.10 + "@noir-lang/types": 0.17.0 + fflate: ^0.8.0 + checksum: 4ad3a30a0cf502de49caced3ffdeffb6daa679362470b02bcfcbbe67daf7283661c3f8767cedd9410cb7b004268ec83832e2a9dadae97f44df66a3a3e4c272d1 + languageName: node + linkType: hard + +"@noir-lang/noir_js@npm:^0.17.0": + version: 0.17.0 + resolution: "@noir-lang/noir_js@npm:0.17.0" + dependencies: + "@noir-lang/acvm_js": 0.29.0 + "@noir-lang/noirc_abi": 0.17.0 + "@noir-lang/types": 0.17.0 + checksum: 9ecaeca11b5740fb99d4198377cf8bb1116b668dd7d9dcc1f80e6a515893e5eb9b70f3db066643239c75b6008c3c2ccb719f5d4d4e51324a61ca31d26c7ecf2a + languageName: node + linkType: hard + +"@noir-lang/noirc_abi@npm:0.17.0": + version: 0.17.0 + resolution: "@noir-lang/noirc_abi@npm:0.17.0" + checksum: d7e1692f2c1c098b400918593bc20107c28fc12238b0dffbe1676cc134d4d121fa0d36c537b4e355d278014da83fe1a404432355f121de6d51326dd9486b47bc + languageName: node + linkType: hard + +"@noir-lang/types@npm:0.17.0": + version: 0.17.0 + resolution: "@noir-lang/types@npm:0.17.0" + dependencies: + "@noir-lang/noirc_abi": 0.17.0 + checksum: 9bc06cbfe77e447614c5751f451ec1f195803b3eea242cac8c8065b4d5c23fbf12aff6c24cfa9a009234180506daeb60d822f01b689b35121bb85b9acf591894 languageName: node linkType: hard @@ -3682,12 +3720,12 @@ __metadata: version: 0.0.0-use.local resolution: "@se-2/nextjs@workspace:packages/nextjs" dependencies: - "@aztec/bb.js": ^0.3.6 "@ethersproject/networks": ^5.7.1 "@ethersproject/providers": ^5.7.2 "@ethersproject/web": ^5.7.1 "@heroicons/react": ^2.0.11 - "@noir-lang/acvm_js": "git+https://git@github.com/noir-lang/acvm-js-wasm.git#b9d9ca9dfc5140839f23998d9466307215607c42" + "@noir-lang/backend_barretenberg": ^0.17.0 + "@noir-lang/noir_js": ^0.17.0 "@rainbow-me/rainbowkit": 1.0.8 "@trivago/prettier-plugin-sort-imports": ^4.1.1 "@types/node": ^17.0.35 @@ -11182,13 +11220,6 @@ __metadata: languageName: node linkType: hard -"idb-keyval@npm:^6.2.1": - version: 6.2.1 - resolution: "idb-keyval@npm:6.2.1" - checksum: 7c0836f832096086e99258167740181132a71dd2694c8b8454a4f5ec69114ba6d70983115153306f0b6de1c8d3bad04f67eed3dff8f50c96815b9985d6d78470 - languageName: node - linkType: hard - "ieee754@npm:^1.1.13, ieee754@npm:^1.2.1": version: 1.2.1 resolution: "ieee754@npm:1.2.1"