From 6b16ce6438f8c25350d0cc7cd86318ccc2d46118 Mon Sep 17 00:00:00 2001 From: CodeDragonVN <150457827+CodeDragonVN@users.noreply.github.com> Date: Fri, 1 Mar 2024 21:07:56 +0000 Subject: [PATCH 1/7] update function names to match version 0.24.0 specifications --- recursion/packages/hardhat/test/index.test.ts | 10 +++++----- .../packages/next/hooks/useMainProofGeneration.tsx | 6 +++--- .../packages/next/hooks/useOffChainVerification.tsx | 2 +- .../next/hooks/useRecursiveProofGeneration.tsx | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/recursion/packages/hardhat/test/index.test.ts b/recursion/packages/hardhat/test/index.test.ts index f22cd11..96631e7 100644 --- a/recursion/packages/hardhat/test/index.test.ts +++ b/recursion/packages/hardhat/test/index.test.ts @@ -55,17 +55,17 @@ describe('It compiles noir program code, receiving circuit bytes and abi object. describe.only('Proof generation', async () => { it('Should generate an intermediate proof', async () => { const { witness } = await noirs.main.execute(mainInput); - intermediateProof = await backends.main.generateIntermediateProof(witness); + intermediateProof = await backends.main.generateProof(witness); const { proof, publicInputs } = intermediateProof; expect(proof instanceof Uint8Array).to.be.true; - const verified = await backends.main.verifyIntermediateProof({ proof, publicInputs }); + const verified = await backends.main.verifyProof({ proof, publicInputs }); expect(verified).to.be.true; const numPublicInputs = 1; const { proofAsFields, vkAsFields, vkHash } = - await backends.main.generateIntermediateProofArtifacts( + await backends.main.generateRecursiveProofArtifacts( { publicInputs, proof }, numPublicInputs, ); @@ -81,7 +81,7 @@ describe('It compiles noir program code, receiving circuit bytes and abi object. }); it('Should generate a final proof with a recursive input', async () => { - finalProof = await noirs.recursive.generateFinalProof(recursiveInputs); + finalProof = await noirs.recursive.generateProof(recursiveInputs); expect(finalProof.proof instanceof Uint8Array).to.be.true; }); }); @@ -94,7 +94,7 @@ describe('It compiles noir program code, receiving circuit bytes and abi object. }); it('Should verify off-chain', async () => { - const verified = await noirs.recursive.verifyFinalProof(finalProof); + const verified = await noirs.recursive.verifyProof(finalProof); expect(verified).to.be.true; }); diff --git a/recursion/packages/next/hooks/useMainProofGeneration.tsx b/recursion/packages/next/hooks/useMainProofGeneration.tsx index a083cfe..f71135d 100644 --- a/recursion/packages/next/hooks/useMainProofGeneration.tsx +++ b/recursion/packages/next/hooks/useMainProofGeneration.tsx @@ -20,7 +20,7 @@ export function useMainProofGeneration(inputs?: { x: string; y: string }) { const { witness } = await noir.execute(inputs); const { publicInputs, proof } = await toast.promise( - backend.generateIntermediateProof(witness), + backend.generateProof(witness), { pending: 'Generating proof', success: 'Proof generated', @@ -28,13 +28,13 @@ export function useMainProofGeneration(inputs?: { x: string; y: string }) { }, ); - toast.promise(backend.verifyIntermediateProof({ proof, publicInputs }), { + toast.promise(backend.verifyProof({ proof, publicInputs }), { pending: 'Verifying intermediate proof', success: 'Intermediate proof verified', error: 'Error verifying intermediate proof', }); - const mainProofArtifacts = await backend.generateIntermediateProofArtifacts( + const mainProofArtifacts = await backend.generateRecursiveProofArtifacts( { publicInputs, proof }, 1, // 1 public input ); diff --git a/recursion/packages/next/hooks/useOffChainVerification.tsx b/recursion/packages/next/hooks/useOffChainVerification.tsx index 197110c..3aed5c1 100644 --- a/recursion/packages/next/hooks/useOffChainVerification.tsx +++ b/recursion/packages/next/hooks/useOffChainVerification.tsx @@ -10,7 +10,7 @@ export function useOffChainVerification(backend?: BarretenbergBackend, proofData if (!proofData || !backend) return; const { proof, publicInputs } = proofData; - toast.promise(backend.verifyFinalProof({ proof, publicInputs }), { + toast.promise(backend.verifyProof({ proof, publicInputs }), { pending: 'Verifying recursive proof off-chain', success: 'Recursive proof verified off-chain', error: 'Error verifying recursive proof off-chain', diff --git a/recursion/packages/next/hooks/useRecursiveProofGeneration.tsx b/recursion/packages/next/hooks/useRecursiveProofGeneration.tsx index 7bf558f..0610523 100644 --- a/recursion/packages/next/hooks/useRecursiveProofGeneration.tsx +++ b/recursion/packages/next/hooks/useRecursiveProofGeneration.tsx @@ -30,7 +30,7 @@ export function useRecursiveProofGeneration( }; const { witness } = await noir.execute(recInput); - const proofData = await backend.generateFinalProof(witness); + const proofData = await backend.generateProof(witness); setRecursiveBackend(backend); setProofData(proofData); From 45d46d63f09e768ef0661fbda9b9e4c56b490945 Mon Sep 17 00:00:00 2001 From: CodeDragonVN <150457827+CodeDragonVN@users.noreply.github.com> Date: Fri, 1 Mar 2024 21:12:23 +0000 Subject: [PATCH 2/7] update package.json versions to align with 0.24.0 update --- recursion/package.json | 6 +-- recursion/packages/next/package.json | 2 +- recursion/yarn.lock | 79 ++++++++++++++-------------- 3 files changed, 44 insertions(+), 43 deletions(-) diff --git a/recursion/package.json b/recursion/package.json index dc4869b..4b73d71 100644 --- a/recursion/package.json +++ b/recursion/package.json @@ -16,8 +16,8 @@ "build": "yarn workspace next run build" }, "dependencies": { - "@noir-lang/backend_barretenberg": "^0.23.0", - "@noir-lang/noir_js": "^0.23.0", - "@noir-lang/noir_wasm": "^0.23.0" + "@noir-lang/backend_barretenberg": "^0.24.0", + "@noir-lang/noir_js": "^0.24.0", + "@noir-lang/noir_wasm": "^0.24.0" } } diff --git a/recursion/packages/next/package.json b/recursion/packages/next/package.json index c77855f..a35953e 100644 --- a/recursion/packages/next/package.json +++ b/recursion/packages/next/package.json @@ -12,7 +12,7 @@ "typescript": "5.0.4" }, "dependencies": { - "@noir-lang/types": "^0.23.0", + "@noir-lang/types": "^0.24.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-toastify": "^10.0.4", diff --git a/recursion/yarn.lock b/recursion/yarn.lock index 956ca10..da3cef8 100644 --- a/recursion/yarn.lock +++ b/recursion/yarn.lock @@ -26,9 +26,9 @@ __metadata: languageName: node linkType: hard -"@aztec/bb.js@npm:0.19.0": - version: 0.19.0 - resolution: "@aztec/bb.js@npm:0.19.0" +"@aztec/bb.js@npm:0.23.0": + version: 0.23.0 + resolution: "@aztec/bb.js@npm:0.23.0" dependencies: comlink: "npm:^4.4.1" commander: "npm:^10.0.1" @@ -36,7 +36,7 @@ __metadata: tslib: "npm:^2.4.0" bin: bb.js: dest/node/main.js - checksum: 10c0/7f0df00d5fcc9c7a027c8fa4d02aa9ad36cfeb69dcee91770f207816fa00c1f9744113cbdc0921c43b48793ae56f1269b8300a081aa336b5971b0337af459bcf + checksum: 10c0/0765f9615ff99d486da7745c023d807505bdc99c11256200a55bcdf54f56c98435578e237b4f3acccbf3be53208b1a466ec8f84219c9dcb3f3d0985280331247 languageName: node linkType: hard @@ -940,57 +940,58 @@ __metadata: languageName: node linkType: hard -"@noir-lang/acvm_js@npm:0.39.0": - version: 0.39.0 - resolution: "@noir-lang/acvm_js@npm:0.39.0" - checksum: 10c0/0780b8abe6ab6d0c83b095877adfe9080f0cd4bedb97f709f146b26a53d5b8be2bce065c8f710b59e0a6e23506ade6cdf73aaf58868da5863d75bca5c40783ba +"@noir-lang/acvm_js@npm:0.40.0": + version: 0.40.0 + resolution: "@noir-lang/acvm_js@npm:0.40.0" + checksum: 10c0/fc2e9534890c7195118d40dcc8c567da65ab651af1bad690b7fa2f70b5beb811166e0987e9d461f5174205ddf111763166dc016da8a145a240027394c620f1b5 languageName: node linkType: hard -"@noir-lang/backend_barretenberg@npm:^0.23.0": - version: 0.23.0 - resolution: "@noir-lang/backend_barretenberg@npm:0.23.0" +"@noir-lang/backend_barretenberg@npm:^0.24.0": + version: 0.24.0 + resolution: "@noir-lang/backend_barretenberg@npm:0.24.0" dependencies: - "@aztec/bb.js": "npm:0.19.0" - "@noir-lang/types": "npm:0.23.0" + "@aztec/bb.js": "npm:0.23.0" + "@noir-lang/types": "npm:0.24.0" fflate: "npm:^0.8.0" - checksum: 10c0/52170513bae7e09df4bc88d6c020cddab47b91ab3c56c4dcb2183d2b091bcb95c557606e338daf22ee415fe61b8b218cdf6ec7971a5548804d11f83cd7795086 + checksum: 10c0/c547f1bf08e7fe5d81690a358ac484cdbdc188f7f509cc7f6bbbf848273f8dd3a3fb139790cf9460a19b10d48abf24d058499943bfe8c1fa39fbd247b786d3e5 languageName: node linkType: hard -"@noir-lang/noir_js@npm:^0.23.0": - version: 0.23.0 - resolution: "@noir-lang/noir_js@npm:0.23.0" +"@noir-lang/noir_js@npm:^0.24.0": + version: 0.24.0 + resolution: "@noir-lang/noir_js@npm:0.24.0" dependencies: - "@noir-lang/acvm_js": "npm:0.39.0" - "@noir-lang/noirc_abi": "npm:0.23.0" - "@noir-lang/types": "npm:0.23.0" - checksum: 10c0/1ccb04cf5990cc6b32c230a08e016def41bb8c002263eea226272c719d63aee06b012772d69fe5658f3fd26985f906ab30d53adf4804632d9c7b63c25b108eaf + "@noir-lang/acvm_js": "npm:0.40.0" + "@noir-lang/noirc_abi": "npm:0.24.0" + "@noir-lang/types": "npm:0.24.0" + checksum: 10c0/185d3bd525ae6e1f6d8b355511b66284977589c2799a2cf613e0d2f8381855d081255d3b42d16b80413091cdfbdec1482061d5b7d6d995531c5037dcde939d1e languageName: node linkType: hard -"@noir-lang/noir_wasm@npm:^0.23.0": - version: 0.23.0 - resolution: "@noir-lang/noir_wasm@npm:0.23.0" +"@noir-lang/noir_wasm@npm:^0.24.0": + version: 0.24.0 + resolution: "@noir-lang/noir_wasm@npm:0.24.0" dependencies: + "@noir-lang/types": "npm:0.24.0" pako: "npm:^2.1.0" - checksum: 10c0/c960ebd9eb859efab48f1e15b002d1d5edd278cafe71d61261cf0cfee2a5cd792953f9e8ffd2fe142c1be32a72ed4bb4b17a4561392d6a0359f4936eef1287f5 + checksum: 10c0/764d4a6fefd9cf00f7ee810622bf75d9212da46b5276d481961b7bb68d42614edebd9b07eef5d8fa620210e9fc7fef7d5f3973f1a6c68553d9a2abd8df28aa30 languageName: node linkType: hard -"@noir-lang/noirc_abi@npm:0.23.0": - version: 0.23.0 - resolution: "@noir-lang/noirc_abi@npm:0.23.0" - checksum: 10c0/a37a9b96e8690d766bee3f850f6a9913c2a070d99147e3672c9979c4740226b5e17fc033b520b53b79f997ca1d95aa5598f91ac8c303a5f1242c238ccbbc1587 +"@noir-lang/noirc_abi@npm:0.24.0": + version: 0.24.0 + resolution: "@noir-lang/noirc_abi@npm:0.24.0" + dependencies: + "@noir-lang/types": "npm:0.24.0" + checksum: 10c0/e6fc770a4923ee2b1e772facafe574c3eefae75d29310ac1a2054e0c2cb1eadbc8f642dbed67f66c891ef045c3ca5319e584675467540bce707e4a82dbb9f15a languageName: node linkType: hard -"@noir-lang/types@npm:0.23.0, @noir-lang/types@npm:^0.23.0": - version: 0.23.0 - resolution: "@noir-lang/types@npm:0.23.0" - dependencies: - "@noir-lang/noirc_abi": "npm:0.23.0" - checksum: 10c0/f349a2c6649988f21aecf104a31cff476af0d69b3f7352d72ac2eb36cbe14aa12a524273cce2066fa0ac7f68e62c69870b860a80c73df4d662d7d94bf321f882 +"@noir-lang/types@npm:0.24.0, @noir-lang/types@npm:^0.24.0": + version: 0.24.0 + resolution: "@noir-lang/types@npm:0.24.0" + checksum: 10c0/b9ffac8fd95ea9eae26dfc106ca943e4f0304ad19d27eab28a191d5d44f6ca01c49cc08e3e54f9742593de17a6fbea6d08533d3900812c741546a0ada0a9ab18 languageName: node linkType: hard @@ -6595,7 +6596,7 @@ __metadata: version: 0.0.0-use.local resolution: "next@workspace:packages/next" dependencies: - "@noir-lang/types": "npm:^0.23.0" + "@noir-lang/types": "npm:^0.24.0" "@types/react": "npm:^18.2.55" next: "npm:^14.1.0" react: "npm:^18.2.0" @@ -7387,9 +7388,9 @@ __metadata: version: 0.0.0-use.local resolution: "recursion@workspace:." dependencies: - "@noir-lang/backend_barretenberg": "npm:^0.23.0" - "@noir-lang/noir_js": "npm:^0.23.0" - "@noir-lang/noir_wasm": "npm:^0.23.0" + "@noir-lang/backend_barretenberg": "npm:^0.24.0" + "@noir-lang/noir_js": "npm:^0.24.0" + "@noir-lang/noir_wasm": "npm:^0.24.0" languageName: unknown linkType: soft From f24ef7651d0c21cadd4cf8dbbf63826e0de59a96 Mon Sep 17 00:00:00 2001 From: CodeDragonVN <150457827+CodeDragonVN@users.noreply.github.com> Date: Fri, 1 Mar 2024 21:14:52 +0000 Subject: [PATCH 3/7] add #[recursive] and update Nargo.toml files --- recursion/packages/noir/main/Nargo.toml | 1 + recursion/packages/noir/main/src/main.nr | 1 + recursion/packages/noir/recursion/Nargo.toml | 1 + .../recursion/contract/recursion/plonk_vk.sol | 457 +++++++++++++----- 4 files changed, 342 insertions(+), 118 deletions(-) diff --git a/recursion/packages/noir/main/Nargo.toml b/recursion/packages/noir/main/Nargo.toml index 92c044b..9307ee9 100644 --- a/recursion/packages/noir/main/Nargo.toml +++ b/recursion/packages/noir/main/Nargo.toml @@ -2,5 +2,6 @@ name = "main" type = "bin" authors = [""] +compiler_version = ">=0.24.0" [dependencies] diff --git a/recursion/packages/noir/main/src/main.nr b/recursion/packages/noir/main/src/main.nr index 6e170de..de59dd9 100644 --- a/recursion/packages/noir/main/src/main.nr +++ b/recursion/packages/noir/main/src/main.nr @@ -1,3 +1,4 @@ +#[recursive] fn main(x : Field, y : pub Field) { assert(x != y); } diff --git a/recursion/packages/noir/recursion/Nargo.toml b/recursion/packages/noir/recursion/Nargo.toml index f057b6e..212af6f 100644 --- a/recursion/packages/noir/recursion/Nargo.toml +++ b/recursion/packages/noir/recursion/Nargo.toml @@ -2,5 +2,6 @@ name = "recursion" type = "bin" authors = [""] +compiler_version = ">=0.24.0" [dependencies] diff --git a/recursion/packages/noir/recursion/contract/recursion/plonk_vk.sol b/recursion/packages/noir/recursion/contract/recursion/plonk_vk.sol index c70f9b5..a446dff 100644 --- a/recursion/packages/noir/recursion/contract/recursion/plonk_vk.sol +++ b/recursion/packages/noir/recursion/contract/recursion/plonk_vk.sol @@ -284,56 +284,49 @@ abstract contract BaseUltraVerifier { uint256 internal constant PAIRING_RHS_X_LOC = 0x3220; uint256 internal constant PAIRING_RHS_Y_LOC = 0x3240; - // ### SUCCESS FLAG MEMORY LOCATIONS - uint256 internal constant GRAND_PRODUCT_SUCCESS_FLAG = 0x3300; - uint256 internal constant ARITHMETIC_TERM_SUCCESS_FLAG = 0x3020; - uint256 internal constant BATCH_OPENING_SUCCESS_FLAG = 0x3340; - uint256 internal constant OPENING_COMMITMENT_SUCCESS_FLAG = 0x3360; - uint256 internal constant PAIRING_PREAMBLE_SUCCESS_FLAG = 0x3380; - uint256 internal constant PAIRING_SUCCESS_FLAG = 0x33a0; - uint256 internal constant RESULT_FLAG = 0x33c0; - // misc stuff - uint256 internal constant OMEGA_INVERSE_LOC = 0x3400; - uint256 internal constant C_ALPHA_SQR_LOC = 0x3420; - uint256 internal constant C_ALPHA_CUBE_LOC = 0x3440; - uint256 internal constant C_ALPHA_QUAD_LOC = 0x3460; - uint256 internal constant C_ALPHA_BASE_LOC = 0x3480; + uint256 internal constant OMEGA_INVERSE_LOC = 0x3300; + uint256 internal constant C_ALPHA_SQR_LOC = 0x3320; + uint256 internal constant C_ALPHA_CUBE_LOC = 0x3340; + uint256 internal constant C_ALPHA_QUAD_LOC = 0x3360; + uint256 internal constant C_ALPHA_BASE_LOC = 0x3380; // ### RECURSION VARIABLE MEMORY LOCATIONS - uint256 internal constant RECURSIVE_P1_X_LOC = 0x3500; - uint256 internal constant RECURSIVE_P1_Y_LOC = 0x3520; - uint256 internal constant RECURSIVE_P2_X_LOC = 0x3540; - uint256 internal constant RECURSIVE_P2_Y_LOC = 0x3560; - - uint256 internal constant PUBLIC_INPUTS_HASH_LOCATION = 0x3580; + uint256 internal constant RECURSIVE_P1_X_LOC = 0x3400; + uint256 internal constant RECURSIVE_P1_Y_LOC = 0x3420; + uint256 internal constant RECURSIVE_P2_X_LOC = 0x3440; + uint256 internal constant RECURSIVE_P2_Y_LOC = 0x3460; + uint256 internal constant PUBLIC_INPUTS_HASH_LOCATION = 0x3480; // sub-identity storage - uint256 internal constant PERMUTATION_IDENTITY = 0x3600; - uint256 internal constant PLOOKUP_IDENTITY = 0x3620; - uint256 internal constant ARITHMETIC_IDENTITY = 0x3640; - uint256 internal constant SORT_IDENTITY = 0x3660; - uint256 internal constant ELLIPTIC_IDENTITY = 0x3680; - uint256 internal constant AUX_IDENTITY = 0x36a0; - uint256 internal constant AUX_NON_NATIVE_FIELD_EVALUATION = 0x36c0; - uint256 internal constant AUX_LIMB_ACCUMULATOR_EVALUATION = 0x36e0; - uint256 internal constant AUX_RAM_CONSISTENCY_EVALUATION = 0x3700; - uint256 internal constant AUX_ROM_CONSISTENCY_EVALUATION = 0x3720; - uint256 internal constant AUX_MEMORY_EVALUATION = 0x3740; - - uint256 internal constant QUOTIENT_EVAL_LOC = 0x3760; - uint256 internal constant ZERO_POLY_INVERSE_LOC = 0x3780; + uint256 internal constant PERMUTATION_IDENTITY = 0x3500; + uint256 internal constant PLOOKUP_IDENTITY = 0x3520; + uint256 internal constant ARITHMETIC_IDENTITY = 0x3540; + uint256 internal constant SORT_IDENTITY = 0x3560; + uint256 internal constant ELLIPTIC_IDENTITY = 0x3580; + uint256 internal constant AUX_IDENTITY = 0x35a0; + uint256 internal constant AUX_NON_NATIVE_FIELD_EVALUATION = 0x35c0; + uint256 internal constant AUX_LIMB_ACCUMULATOR_EVALUATION = 0x35e0; + uint256 internal constant AUX_RAM_CONSISTENCY_EVALUATION = 0x3600; + uint256 internal constant AUX_ROM_CONSISTENCY_EVALUATION = 0x3620; + uint256 internal constant AUX_MEMORY_EVALUATION = 0x3640; + + uint256 internal constant QUOTIENT_EVAL_LOC = 0x3660; + uint256 internal constant ZERO_POLY_INVERSE_LOC = 0x3680; // when hashing public inputs we use memory at NU_CHALLENGE_INPUT_LOC_A, as the hash input size is unknown at compile time - uint256 internal constant NU_CHALLENGE_INPUT_LOC_A = 0x37a0; - uint256 internal constant NU_CHALLENGE_INPUT_LOC_B = 0x37c0; - uint256 internal constant NU_CHALLENGE_INPUT_LOC_C = 0x37e0; + uint256 internal constant NU_CHALLENGE_INPUT_LOC_A = 0x36a0; + uint256 internal constant NU_CHALLENGE_INPUT_LOC_B = 0x36c0; + uint256 internal constant NU_CHALLENGE_INPUT_LOC_C = 0x36e0; + bytes4 internal constant INVALID_VERIFICATION_KEY_SELECTOR = 0x7e5769bf; + bytes4 internal constant POINT_NOT_ON_CURVE_SELECTOR = 0xa3dad654; bytes4 internal constant PUBLIC_INPUT_INVALID_BN128_G1_POINT_SELECTOR = 0xeba9f4a6; bytes4 internal constant PUBLIC_INPUT_GE_P_SELECTOR = 0x374a972f; bytes4 internal constant MOD_EXP_FAILURE_SELECTOR = 0xf894a7bc; - bytes4 internal constant EC_SCALAR_MUL_FAILURE_SELECTOR = 0xf755f369; - bytes4 internal constant PROOF_FAILURE_SELECTOR = 0x0711fcec; + bytes4 internal constant PAIRING_PREAMBLE_FAILED_SELECTOR = 0x01882d81; + bytes4 internal constant OPENING_COMMITMENT_FAILED_SELECTOR = 0x4e719763; + bytes4 internal constant PAIRING_FAILED_SELECTOR = 0xd71fd263; uint256 internal constant ETA_INPUT_LENGTH = 0xc0; // W1, W2, W3 = 6 * 0x20 bytes @@ -357,17 +350,227 @@ abstract contract BaseUltraVerifier { // 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 INVALID_VERIFICATION_KEY(); + error POINT_NOT_ON_CURVE(); error PUBLIC_INPUT_COUNT_INVALID(uint256 expected, uint256 actual); error PUBLIC_INPUT_INVALID_BN128_G1_POINT(); error PUBLIC_INPUT_GE_P(); error MOD_EXP_FAILURE(); - error EC_SCALAR_MUL_FAILURE(); - error PROOF_FAILURE(); + error PAIRING_PREAMBLE_FAILED(); + error OPENING_COMMITMENT_FAILED(); + error PAIRING_FAILED(); function getVerificationKeyHash() public pure virtual returns (bytes32); + /** + * @dev We assume that the verification key loaded by this function is constant as we only verify it on deployment + */ function loadVerificationKey(uint256 _vk, uint256 _omegaInverseLoc) internal pure virtual; + constructor() { + loadVerificationKey(N_LOC, OMEGA_INVERSE_LOC); + + // We verify that all of the EC points in the verification key lie on the bn128 curve. + assembly { + let q := 21888242871839275222246405745257275088696311157297823662689037894645226208583 // EC group order + + let success := 1 + + // VALIDATE Q1 + { + let x := mload(Q1_X_LOC) + let y := mload(Q1_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE Q2 + { + let x := mload(Q2_X_LOC) + let y := mload(Q2_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE Q3 + { + let x := mload(Q3_X_LOC) + let y := mload(Q3_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE Q4 + { + let x := mload(Q4_X_LOC) + let y := mload(Q4_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + mstore(0x00, x) + mstore(0x20, y) + } + // VALIDATE QM + { + let x := mload(QM_X_LOC) + let y := mload(QM_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE QC + { + let x := mload(QC_X_LOC) + let y := mload(QC_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE QARITH + { + let x := mload(QARITH_X_LOC) + let y := mload(QARITH_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE QSORT + { + let x := mload(QSORT_X_LOC) + let y := mload(QSORT_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE QELLIPTIC + { + let x := mload(QELLIPTIC_X_LOC) + let y := mload(QELLIPTIC_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE QAUX + { + let x := mload(QAUX_X_LOC) + let y := mload(QAUX_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE SIGMA1 + { + let x := mload(SIGMA1_X_LOC) + let y := mload(SIGMA1_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE SIGMA2 + { + let x := mload(SIGMA2_X_LOC) + let y := mload(SIGMA2_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE SIGMA3 + { + let x := mload(SIGMA3_X_LOC) + let y := mload(SIGMA3_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE SIGMA4 + { + let x := mload(SIGMA4_X_LOC) + let y := mload(SIGMA4_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE TABLE1 + { + let x := mload(TABLE1_X_LOC) + let y := mload(TABLE1_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE TABLE2 + { + let x := mload(TABLE2_X_LOC) + let y := mload(TABLE2_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE TABLE3 + { + let x := mload(TABLE3_X_LOC) + let y := mload(TABLE3_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE TABLE4 + { + let x := mload(TABLE4_X_LOC) + let y := mload(TABLE4_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE TABLE_TYPE + { + let x := mload(TABLE_TYPE_X_LOC) + let y := mload(TABLE_TYPE_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE ID1 + { + let x := mload(ID1_X_LOC) + let y := mload(ID1_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE ID2 + { + let x := mload(ID2_X_LOC) + let y := mload(ID2_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE ID3 + { + let x := mload(ID3_X_LOC) + let y := mload(ID3_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + // VALIDATE ID4 + { + let x := mload(ID4_X_LOC) + let y := mload(ID4_Y_LOC) + let xx := mulmod(x, x, q) + // validate on curve + success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + } + + if iszero(success) { + mstore(0x0, INVALID_VERIFICATION_KEY_SELECTOR) + revert(0x00, 0x04) + } + } + } + /** * @notice Verify a Ultra Plonk proof * @param _proof - The serialized proof @@ -1786,7 +1989,10 @@ abstract contract BaseUltraVerifier { let y := mload(T1_Y_LOC) let xx := mulmod(x, x, q) // validate on curve - success := eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q)) + if iszero(eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) { + mstore(0x0, POINT_NOT_ON_CURVE_SELECTOR) + revert(0x00, 0x04) + } mstore(ACCUMULATOR_X_LOC, x) mstore(add(ACCUMULATOR_X_LOC, 0x20), y) } @@ -1796,13 +2002,16 @@ abstract contract BaseUltraVerifier { let y := mload(T2_Y_LOC) // 0x1420 let xx := mulmod(x, x, q) // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + if iszero(eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) { + mstore(0x0, POINT_NOT_ON_CURVE_SELECTOR) + revert(0x00, 0x04) + } mstore(0x00, x) mstore(0x20, y) } mstore(0x40, mload(ZETA_POW_N_LOC)) // accumulator_2 = [T2].zeta^n - success := and(success, staticcall(gas(), 7, 0x00, 0x60, ACCUMULATOR2_X_LOC, 0x40)) + success := staticcall(gas(), 7, 0x00, 0x60, ACCUMULATOR2_X_LOC, 0x40) // accumulator = [T1] + accumulator_2 success := and(success, staticcall(gas(), 6, ACCUMULATOR_X_LOC, 0x80, ACCUMULATOR_X_LOC, 0x40)) @@ -1812,7 +2021,10 @@ abstract contract BaseUltraVerifier { let y := mload(T3_Y_LOC) let xx := mulmod(x, x, q) // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + if iszero(eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) { + mstore(0x0, POINT_NOT_ON_CURVE_SELECTOR) + revert(0x00, 0x04) + } mstore(0x00, x) mstore(0x20, y) } @@ -1828,7 +2040,10 @@ abstract contract BaseUltraVerifier { let y := mload(T4_Y_LOC) let xx := mulmod(x, x, q) // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + if iszero(eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) { + mstore(0x0, POINT_NOT_ON_CURVE_SELECTOR) + revert(0x00, 0x04) + } mstore(0x00, x) mstore(0x20, y) } @@ -1844,7 +2059,10 @@ abstract contract BaseUltraVerifier { let y := mload(W1_Y_LOC) let xx := mulmod(x, x, q) // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + if iszero(eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) { + mstore(0x0, POINT_NOT_ON_CURVE_SELECTOR) + revert(0x00, 0x04) + } mstore(0x00, x) mstore(0x20, y) } @@ -1860,7 +2078,10 @@ abstract contract BaseUltraVerifier { let y := mload(W2_Y_LOC) let xx := mulmod(x, x, q) // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + if iszero(eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) { + mstore(0x0, POINT_NOT_ON_CURVE_SELECTOR) + revert(0x00, 0x04) + } mstore(0x00, x) mstore(0x20, y) } @@ -1876,7 +2097,10 @@ abstract contract BaseUltraVerifier { let y := mload(W3_Y_LOC) let xx := mulmod(x, x, q) // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + if iszero(eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) { + mstore(0x0, POINT_NOT_ON_CURVE_SELECTOR) + revert(0x00, 0x04) + } mstore(0x00, x) mstore(0x20, y) } @@ -1892,7 +2116,10 @@ abstract contract BaseUltraVerifier { let y := mload(W4_Y_LOC) let xx := mulmod(x, x, q) // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + if iszero(eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) { + mstore(0x0, POINT_NOT_ON_CURVE_SELECTOR) + revert(0x00, 0x04) + } mstore(0x00, x) mstore(0x20, y) } @@ -1908,7 +2135,10 @@ abstract contract BaseUltraVerifier { let y := mload(S_Y_LOC) let xx := mulmod(x, x, q) // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + if iszero(eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) { + mstore(0x0, POINT_NOT_ON_CURVE_SELECTOR) + revert(0x00, 0x04) + } mstore(0x00, x) mstore(0x20, y) } @@ -1924,7 +2154,10 @@ abstract contract BaseUltraVerifier { let y := mload(Z_Y_LOC) let xx := mulmod(x, x, q) // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + if iszero(eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) { + mstore(0x0, POINT_NOT_ON_CURVE_SELECTOR) + revert(0x00, 0x04) + } mstore(0x00, x) mstore(0x20, y) } @@ -1940,7 +2173,10 @@ abstract contract BaseUltraVerifier { let y := mload(Z_LOOKUP_Y_LOC) let xx := mulmod(x, x, q) // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + if iszero(eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) { + mstore(0x0, POINT_NOT_ON_CURVE_SELECTOR) + revert(0x00, 0x04) + } mstore(0x00, x) mstore(0x20, y) } @@ -1955,8 +2191,7 @@ abstract contract BaseUltraVerifier { let x := mload(Q1_X_LOC) let y := mload(Q1_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -1971,8 +2206,7 @@ abstract contract BaseUltraVerifier { let x := mload(Q2_X_LOC) let y := mload(Q2_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -1987,8 +2221,7 @@ abstract contract BaseUltraVerifier { let x := mload(Q3_X_LOC) let y := mload(Q3_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2003,8 +2236,7 @@ abstract contract BaseUltraVerifier { let x := mload(Q4_X_LOC) let y := mload(Q4_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2019,8 +2251,7 @@ abstract contract BaseUltraVerifier { let x := mload(QM_X_LOC) let y := mload(QM_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2035,8 +2266,7 @@ abstract contract BaseUltraVerifier { let x := mload(QC_X_LOC) let y := mload(QC_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2051,8 +2281,7 @@ abstract contract BaseUltraVerifier { let x := mload(QARITH_X_LOC) let y := mload(QARITH_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2067,8 +2296,7 @@ abstract contract BaseUltraVerifier { let x := mload(QSORT_X_LOC) let y := mload(QSORT_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2083,8 +2311,7 @@ abstract contract BaseUltraVerifier { let x := mload(QELLIPTIC_X_LOC) let y := mload(QELLIPTIC_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2099,8 +2326,7 @@ abstract contract BaseUltraVerifier { let x := mload(QAUX_X_LOC) let y := mload(QAUX_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2115,8 +2341,7 @@ abstract contract BaseUltraVerifier { let x := mload(SIGMA1_X_LOC) let y := mload(SIGMA1_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2131,8 +2356,7 @@ abstract contract BaseUltraVerifier { let x := mload(SIGMA2_X_LOC) let y := mload(SIGMA2_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2147,8 +2371,7 @@ abstract contract BaseUltraVerifier { let x := mload(SIGMA3_X_LOC) let y := mload(SIGMA3_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2163,8 +2386,7 @@ abstract contract BaseUltraVerifier { let x := mload(SIGMA4_X_LOC) let y := mload(SIGMA4_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2179,8 +2401,7 @@ abstract contract BaseUltraVerifier { let x := mload(TABLE1_X_LOC) let y := mload(TABLE1_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2195,8 +2416,7 @@ abstract contract BaseUltraVerifier { let x := mload(TABLE2_X_LOC) let y := mload(TABLE2_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2211,8 +2431,7 @@ abstract contract BaseUltraVerifier { let x := mload(TABLE3_X_LOC) let y := mload(TABLE3_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2227,8 +2446,7 @@ abstract contract BaseUltraVerifier { let x := mload(TABLE4_X_LOC) let y := mload(TABLE4_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2243,8 +2461,7 @@ abstract contract BaseUltraVerifier { let x := mload(TABLE_TYPE_X_LOC) let y := mload(TABLE_TYPE_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2259,8 +2476,7 @@ abstract contract BaseUltraVerifier { let x := mload(ID1_X_LOC) let y := mload(ID1_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2275,8 +2491,7 @@ abstract contract BaseUltraVerifier { let x := mload(ID2_X_LOC) let y := mload(ID2_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2291,8 +2506,7 @@ abstract contract BaseUltraVerifier { let x := mload(ID3_X_LOC) let y := mload(ID3_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2307,8 +2521,7 @@ abstract contract BaseUltraVerifier { let x := mload(ID4_X_LOC) let y := mload(ID4_Y_LOC) let xx := mulmod(x, x, q) - // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + // Verification key fields verified to be on curve at contract deployment mstore(0x00, x) mstore(0x20, y) } @@ -2496,7 +2709,10 @@ abstract contract BaseUltraVerifier { // accumulator = accumulator + accumulator_2 success := and(success, staticcall(gas(), 6, ACCUMULATOR_X_LOC, 0x80, ACCUMULATOR_X_LOC, 0x40)) - mstore(OPENING_COMMITMENT_SUCCESS_FLAG, success) + if iszero(success) { + mstore(0x0, OPENING_COMMITMENT_FAILED_SELECTOR) + revert(0x00, 0x04) + } } /** @@ -2511,13 +2727,16 @@ abstract contract BaseUltraVerifier { let y := mload(PI_Z_Y_LOC) let xx := mulmod(x, x, q) // validate on curve - success := eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q)) + if iszero(eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) { + mstore(0x0, POINT_NOT_ON_CURVE_SELECTOR) + revert(0x00, 0x04) + } mstore(0x00, x) mstore(0x20, y) } // compute zeta.[PI_Z] and add into accumulator mstore(0x40, zeta) - success := and(success, staticcall(gas(), 7, 0x00, 0x60, ACCUMULATOR2_X_LOC, 0x40)) + success := staticcall(gas(), 7, 0x00, 0x60, ACCUMULATOR2_X_LOC, 0x40) // accumulator = accumulator + accumulator_2 success := and(success, staticcall(gas(), 6, ACCUMULATOR_X_LOC, 0x80, ACCUMULATOR_X_LOC, 0x40)) @@ -2527,7 +2746,10 @@ abstract contract BaseUltraVerifier { let y := mload(PI_Z_OMEGA_Y_LOC) let xx := mulmod(x, x, q) // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + if iszero(eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) { + mstore(0x0, POINT_NOT_ON_CURVE_SELECTOR) + revert(0x00, 0x04) + } mstore(0x00, x) mstore(0x20, y) } @@ -2555,7 +2777,10 @@ abstract contract BaseUltraVerifier { let y := mload(RECURSIVE_P1_Y_LOC) let xx := mulmod(x, x, q) // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + if iszero(eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) { + mstore(0x0, POINT_NOT_ON_CURVE_SELECTOR) + revert(0x00, 0x04) + } mstore(0x00, x) mstore(0x20, y) } @@ -2569,7 +2794,10 @@ abstract contract BaseUltraVerifier { let y := mload(RECURSIVE_P2_Y_LOC) let xx := mulmod(x, x, q) // validate on curve - success := and(success, eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) + if iszero(eq(mulmod(y, y, q), addmod(mulmod(x, xx, q), 3, q))) { + mstore(0x0, POINT_NOT_ON_CURVE_SELECTOR) + revert(0x00, 0x04) + } mstore(0x00, x) mstore(0x20, y) } @@ -2589,10 +2817,9 @@ abstract contract BaseUltraVerifier { } if iszero(success) { - mstore(0x0, EC_SCALAR_MUL_FAILURE_SELECTOR) + mstore(0x0, PAIRING_PREAMBLE_FAILED_SELECTOR) revert(0x00, 0x04) } - mstore(PAIRING_PREAMBLE_SUCCESS_FLAG, success) } /** @@ -2617,18 +2844,12 @@ abstract contract BaseUltraVerifier { mstore(0x160, mload(G2X_Y1_LOC)) success := staticcall(gas(), 8, 0x00, 0x180, 0x00, 0x20) - mstore(PAIRING_SUCCESS_FLAG, success) - mstore(RESULT_FLAG, mload(0x00)) - } - if iszero( - and( - and(and(mload(PAIRING_SUCCESS_FLAG), mload(RESULT_FLAG)), mload(PAIRING_PREAMBLE_SUCCESS_FLAG)), - mload(OPENING_COMMITMENT_SUCCESS_FLAG) - ) - ) { - mstore(0x0, PROOF_FAILURE_SELECTOR) - revert(0x00, 0x04) + if iszero(and(success, mload(0x00))) { + mstore(0x0, PAIRING_FAILED_SELECTOR) + revert(0x00, 0x04) + } } + { mstore(0x00, 0x01) return(0x00, 0x20) // Proof succeeded! From deb052faa1f3e704798720d8ba52e4aef5da37b4 Mon Sep 17 00:00:00 2001 From: CodeDragonVN <150457827+CodeDragonVN@users.noreply.github.com> Date: Fri, 1 Mar 2024 21:16:37 +0000 Subject: [PATCH 4/7] improve UI on yarn dev localhost --- recursion/packages/next/pages/Page.module.css | 70 +++++++++++++++++++ recursion/packages/next/pages/index.tsx | 33 ++++++--- 2 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 recursion/packages/next/pages/Page.module.css diff --git a/recursion/packages/next/pages/Page.module.css b/recursion/packages/next/pages/Page.module.css new file mode 100644 index 0000000..3f842f5 --- /dev/null +++ b/recursion/packages/next/pages/Page.module.css @@ -0,0 +1,70 @@ +/* Page.module.css */ +.container { + max-width: 600px; + margin: 2rem auto; + padding: 2rem; + background: #f9f9f9; + border-radius: 8px; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); +} + +.title { + color: #333; + text-align: center; +} + +.proofForm { + display: flex; + flex-direction: column; + gap: 1rem; +} + +.inputGroup { + display: flex; + flex-direction: column; + gap: 0.5rem; +} + +.inputLabel { + font-size: 1rem; + color: #666; +} + +.inputField { + padding: 0.5rem; + font-size: 1rem; + border: 1px solid #ddd; + border-radius: 4px; +} + +.submitButton { + padding: 0.5rem 1rem; + font-size: 1rem; + color: white; + background-color: #5c6bc0; + border: none; + border-radius: 4px; + cursor: pointer; + transition: background-color 0.3s ease; +} + +.submitButton:hover { + background-color: #3f51b5; +} + +.submitButton:disabled { + background-color: #9fa8da; + cursor: not-allowed; +} + +.errorMessage { + color: #b71c1c; + text-align: center; + margin-top: 1rem; +} + +.successMessage { + color: #2e7d32; + text-align: center; + margin-top: 1rem; +} diff --git a/recursion/packages/next/pages/index.tsx b/recursion/packages/next/pages/index.tsx index 26ef473..bd2c73e 100644 --- a/recursion/packages/next/pages/index.tsx +++ b/recursion/packages/next/pages/index.tsx @@ -1,5 +1,7 @@ 'use client'; +import styles from './Page.module.css'; + import React, { useState } from 'react'; import { useOffChainVerification } from '../hooks/useOffChainVerification'; import { useOnChainVerification } from '../hooks/useOnChainVerification'; @@ -26,17 +28,30 @@ export default function Page() { }; return ( -