diff --git a/.eslintrc.js b/.eslintrc.js index b1346a8792f..f47f171561c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,19 +1,19 @@ module.exports = { root: true, - parser: "@typescript-eslint/parser", - plugins: ["@typescript-eslint", "prettier"], - extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"], + parser: '@typescript-eslint/parser', + plugins: ['@typescript-eslint', 'prettier'], + extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], rules: { - "comma-spacing": ["error", { before: false, after: true }], - "no-unused-vars": "off", - "@typescript-eslint/no-unused-vars": [ - "warn", // or "error" + 'comma-spacing': ['error', { before: false, after: true }], + 'no-unused-vars': 'off', + '@typescript-eslint/no-unused-vars': [ + 'warn', // or "error" { - argsIgnorePattern: "^_", - varsIgnorePattern: "^_", - caughtErrorsIgnorePattern: "^_", + argsIgnorePattern: '^_', + varsIgnorePattern: '^_', + caughtErrorsIgnorePattern: '^_', }, ], - "prettier/prettier": "error", + 'prettier/prettier': 'error', }, }; diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000000..ef937f9697a --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "parser": "typescript", + "printWidth": 120, + "singleQuote": true, + "trailingComma": "all" +} \ No newline at end of file diff --git a/acvm-repo/acvm_js/test/browser/execute_circuit.test.ts b/acvm-repo/acvm_js/test/browser/execute_circuit.test.ts index 601deffc79e..925c1a07eb8 100644 --- a/acvm-repo/acvm_js/test/browser/execute_circuit.test.ts +++ b/acvm-repo/acvm_js/test/browser/execute_circuit.test.ts @@ -1,4 +1,4 @@ -import { expect } from "@esm-bundle/chai"; +import { expect } from '@esm-bundle/chai'; import initACVM, { createBlackBoxSolver, executeCircuit, @@ -7,25 +7,20 @@ import initACVM, { WitnessMap, initLogLevel, ForeignCallHandler, -} from "@noir-lang/acvm_js"; +} from '@noir-lang/acvm_js'; beforeEach(async () => { await initACVM(); - initLogLevel("INFO"); + initLogLevel('INFO'); }); -it("successfully executes circuit and extracts return value", async () => { - const { bytecode, initialWitnessMap, resultWitness, expectedResult } = - await import("../shared/addition"); +it('successfully executes circuit and extracts return value', async () => { + const { bytecode, initialWitnessMap, resultWitness, expectedResult } = await import('../shared/addition'); - const solvedWitness: WitnessMap = await executeCircuit( - bytecode, - initialWitnessMap, - () => { - throw Error("unexpected oracle"); - }, - ); + const solvedWitness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, () => { + throw Error('unexpected oracle'); + }); // Solved witness should be consistent with initial witness initialWitnessMap.forEach((value, key) => { @@ -36,22 +31,13 @@ it("successfully executes circuit and extracts return value", async () => { expect(solvedWitness.get(resultWitness)).to.be.eq(expectedResult); }); -it("successfully processes simple brillig foreign call opcodes", async () => { - const { - bytecode, - initialWitnessMap, - expectedWitnessMap, - oracleResponse, - oracleCallName, - oracleCallInputs, - } = await import("../shared/foreign_call"); - - let observedName = ""; +it('successfully processes simple brillig foreign call opcodes', async () => { + const { bytecode, initialWitnessMap, expectedWitnessMap, oracleResponse, oracleCallName, oracleCallInputs } = + await import('../shared/foreign_call'); + + let observedName = ''; let observedInputs: string[][] = []; - const foreignCallHandler: ForeignCallHandler = async ( - name: string, - inputs: string[][], - ) => { + const foreignCallHandler: ForeignCallHandler = async (name: string, inputs: string[][]) => { // Throwing inside the oracle callback causes a timeout so we log the observed values // and defer the check against expected values until after the execution is complete. observedName = name; @@ -60,11 +46,7 @@ it("successfully processes simple brillig foreign call opcodes", async () => { return oracleResponse; }; - const solved_witness: WitnessMap = await executeCircuit( - bytecode, - initialWitnessMap, - foreignCallHandler, - ); + const solved_witness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, foreignCallHandler); // Check that expected values were passed to oracle callback. expect(observedName).to.be.eq(oracleCallName); @@ -75,22 +57,13 @@ it("successfully processes simple brillig foreign call opcodes", async () => { expect(solved_witness).to.be.deep.eq(expectedWitnessMap); }); -it("successfully processes complex brillig foreign call opcodes", async () => { - const { - bytecode, - initialWitnessMap, - expectedWitnessMap, - oracleResponse, - oracleCallName, - oracleCallInputs, - } = await import("../shared/complex_foreign_call"); - - let observedName = ""; +it('successfully processes complex brillig foreign call opcodes', async () => { + const { bytecode, initialWitnessMap, expectedWitnessMap, oracleResponse, oracleCallName, oracleCallInputs } = + await import('../shared/complex_foreign_call'); + + let observedName = ''; let observedInputs: string[][] = []; - const foreignCallHandler: ForeignCallHandler = async ( - name: string, - inputs: string[][], - ) => { + const foreignCallHandler: ForeignCallHandler = async (name: string, inputs: string[][]) => { // Throwing inside the oracle callback causes a timeout so we log the observed values // and defer the check against expected values until after the execution is complete. observedName = name; @@ -99,11 +72,7 @@ it("successfully processes complex brillig foreign call opcodes", async () => { return oracleResponse; }; - const solved_witness: WitnessMap = await executeCircuit( - bytecode, - initialWitnessMap, - foreignCallHandler, - ); + const solved_witness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, foreignCallHandler); // Check that expected values were passed to oracle callback. expect(observedName).to.be.eq(oracleCallName); @@ -114,98 +83,62 @@ it("successfully processes complex brillig foreign call opcodes", async () => { expect(solved_witness).to.be.deep.eq(expectedWitnessMap); }); -it("successfully executes a Pedersen opcode", async function () { - const { bytecode, initialWitnessMap, expectedWitnessMap } = await import( - "../shared/pedersen" - ); +it('successfully executes a Pedersen opcode', async function () { + const { bytecode, initialWitnessMap, expectedWitnessMap } = await import('../shared/pedersen'); - const solvedWitness: WitnessMap = await executeCircuit( - bytecode, - initialWitnessMap, - () => { - throw Error("unexpected oracle"); - }, - ); + const solvedWitness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, () => { + throw Error('unexpected oracle'); + }); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); }); -it("successfully executes a FixedBaseScalarMul opcode", async () => { - const { bytecode, initialWitnessMap, expectedWitnessMap } = await import( - "../shared/fixed_base_scalar_mul" - ); +it('successfully executes a FixedBaseScalarMul opcode', async () => { + const { bytecode, initialWitnessMap, expectedWitnessMap } = await import('../shared/fixed_base_scalar_mul'); - const solvedWitness: WitnessMap = await executeCircuit( - bytecode, - initialWitnessMap, - () => { - throw Error("unexpected oracle"); - }, - ); + const solvedWitness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, () => { + throw Error('unexpected oracle'); + }); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); }); -it("successfully executes a SchnorrVerify opcode", async () => { - const { bytecode, initialWitnessMap, expectedWitnessMap } = await import( - "../shared/schnorr_verify" - ); +it('successfully executes a SchnorrVerify opcode', async () => { + const { bytecode, initialWitnessMap, expectedWitnessMap } = await import('../shared/schnorr_verify'); - const solvedWitness: WitnessMap = await executeCircuit( - bytecode, - initialWitnessMap, - () => { - throw Error("unexpected oracle"); - }, - ); + const solvedWitness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, () => { + throw Error('unexpected oracle'); + }); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); }); -it("successfully executes a MemoryOp opcode", async () => { - const { bytecode, initialWitnessMap, expectedWitnessMap } = await import( - "../shared/memory_op" - ); +it('successfully executes a MemoryOp opcode', async () => { + const { bytecode, initialWitnessMap, expectedWitnessMap } = await import('../shared/memory_op'); - const solvedWitness: WitnessMap = await executeCircuit( - bytecode, - initialWitnessMap, - () => { - throw Error("unexpected oracle"); - }, - ); + const solvedWitness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, () => { + throw Error('unexpected oracle'); + }); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); }); -it("successfully executes two circuits with same backend", async function () { +it('successfully executes two circuits with same backend', async function () { // chose pedersen op here because it is the one with slow initialization // that led to the decision to pull backend initialization into a separate // function/wasmbind const solver: WasmBlackBoxFunctionSolver = await createBlackBoxSolver(); - const { bytecode, initialWitnessMap, expectedWitnessMap } = await import( - "../shared/pedersen" - ); + const { bytecode, initialWitnessMap, expectedWitnessMap } = await import('../shared/pedersen'); - const solvedWitness0: WitnessMap = await executeCircuitWithBlackBoxSolver( - solver, - bytecode, - initialWitnessMap, - () => { - throw Error("unexpected oracle"); - }, - ); + const solvedWitness0: WitnessMap = await executeCircuitWithBlackBoxSolver(solver, bytecode, initialWitnessMap, () => { + throw Error('unexpected oracle'); + }); expect(solvedWitness0).to.be.deep.eq(expectedWitnessMap); - const solvedWitness1: WitnessMap = await executeCircuitWithBlackBoxSolver( - solver, - bytecode, - initialWitnessMap, - () => { - throw Error("unexpected oracle"); - }, - ); + const solvedWitness1: WitnessMap = await executeCircuitWithBlackBoxSolver(solver, bytecode, initialWitnessMap, () => { + throw Error('unexpected oracle'); + }); expect(solvedWitness1).to.be.deep.eq(expectedWitnessMap); }); diff --git a/acvm-repo/acvm_js/test/browser/witness_conversion.test.ts b/acvm-repo/acvm_js/test/browser/witness_conversion.test.ts index 67c6c998923..bb309f472b1 100644 --- a/acvm-repo/acvm_js/test/browser/witness_conversion.test.ts +++ b/acvm-repo/acvm_js/test/browser/witness_conversion.test.ts @@ -1,24 +1,18 @@ -import { expect } from "@esm-bundle/chai"; -import initACVM, { - compressWitness, - decompressWitness, -} from "@noir-lang/acvm_js"; -import { - expectedCompressedWitnessMap, - expectedWitnessMap, -} from "../shared/witness_compression"; +import { expect } from '@esm-bundle/chai'; +import initACVM, { compressWitness, decompressWitness } from '@noir-lang/acvm_js'; +import { expectedCompressedWitnessMap, expectedWitnessMap } from '../shared/witness_compression'; beforeEach(async () => { await initACVM(); }); -it("successfully compresses the witness", async () => { +it('successfully compresses the witness', async () => { const compressedWitnessMap = compressWitness(expectedWitnessMap); expect(compressedWitnessMap).to.be.deep.eq(expectedCompressedWitnessMap); }); -it("successfully decompresses the witness", async () => { +it('successfully decompresses the witness', async () => { const witnessMap = decompressWitness(expectedCompressedWitnessMap); expect(witnessMap).to.be.deep.eq(expectedWitnessMap); diff --git a/acvm-repo/acvm_js/test/node/build_info.test.ts b/acvm-repo/acvm_js/test/node/build_info.test.ts index fcbdd9e45b7..23100505011 100644 --- a/acvm-repo/acvm_js/test/node/build_info.test.ts +++ b/acvm-repo/acvm_js/test/node/build_info.test.ts @@ -1,17 +1,14 @@ -import { expect } from "chai"; -import { BuildInfo, buildInfo } from "@noir-lang/acvm_js"; -import child_process from "child_process"; -import pkg from "../../package.json"; +import { expect } from 'chai'; +import { BuildInfo, buildInfo } from '@noir-lang/acvm_js'; +import child_process from 'child_process'; +import pkg from '../../package.json'; -it("returns the correct build into", () => { +it('returns the correct build into', () => { const info: BuildInfo = buildInfo(); // TODO: enforce that `package.json` and `Cargo.toml` are consistent. expect(info.version).to.be.eq(pkg.version); - const revision = child_process - .execSync("git rev-parse HEAD") - .toString() - .trim(); + const revision = child_process.execSync('git rev-parse HEAD').toString().trim(); expect(info.gitHash).to.be.eq(revision); }); diff --git a/acvm-repo/acvm_js/test/node/execute_circuit.test.ts b/acvm-repo/acvm_js/test/node/execute_circuit.test.ts index a9807b48aa7..b28b9e72591 100644 --- a/acvm-repo/acvm_js/test/node/execute_circuit.test.ts +++ b/acvm-repo/acvm_js/test/node/execute_circuit.test.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import { expect } from 'chai'; import { createBlackBoxSolver, executeCircuit, @@ -6,19 +6,14 @@ import { WasmBlackBoxFunctionSolver, WitnessMap, ForeignCallHandler, -} from "@noir-lang/acvm_js"; +} from '@noir-lang/acvm_js'; -it("successfully executes circuit and extracts return value", async () => { - const { bytecode, initialWitnessMap, resultWitness, expectedResult } = - await import("../shared/addition"); +it('successfully executes circuit and extracts return value', async () => { + const { bytecode, initialWitnessMap, resultWitness, expectedResult } = await import('../shared/addition'); - const solvedWitness: WitnessMap = await executeCircuit( - bytecode, - initialWitnessMap, - () => { - throw Error("unexpected oracle"); - }, - ); + const solvedWitness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, () => { + throw Error('unexpected oracle'); + }); // Solved witness should be consistent with initial witness initialWitnessMap.forEach((value, key) => { @@ -29,22 +24,13 @@ it("successfully executes circuit and extracts return value", async () => { expect(solvedWitness.get(resultWitness)).to.be.eq(expectedResult); }); -it("successfully processes simple brillig foreign call opcodes", async () => { - const { - bytecode, - initialWitnessMap, - expectedWitnessMap, - oracleResponse, - oracleCallName, - oracleCallInputs, - } = await import("../shared/foreign_call"); - - let observedName = ""; +it('successfully processes simple brillig foreign call opcodes', async () => { + const { bytecode, initialWitnessMap, expectedWitnessMap, oracleResponse, oracleCallName, oracleCallInputs } = + await import('../shared/foreign_call'); + + let observedName = ''; let observedInputs: string[][] = []; - const foreignCallHandler: ForeignCallHandler = async ( - name: string, - inputs: string[][], - ) => { + const foreignCallHandler: ForeignCallHandler = async (name: string, inputs: string[][]) => { // Throwing inside the oracle callback causes a timeout so we log the observed values // and defer the check against expected values until after the execution is complete. observedName = name; @@ -53,11 +39,7 @@ it("successfully processes simple brillig foreign call opcodes", async () => { return oracleResponse; }; - const solved_witness: WitnessMap = await executeCircuit( - bytecode, - initialWitnessMap, - foreignCallHandler, - ); + const solved_witness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, foreignCallHandler); // Check that expected values were passed to oracle callback. expect(observedName).to.be.eq(oracleCallName); @@ -68,22 +50,13 @@ it("successfully processes simple brillig foreign call opcodes", async () => { expect(solved_witness).to.be.deep.eq(expectedWitnessMap); }); -it("successfully processes complex brillig foreign call opcodes", async () => { - const { - bytecode, - initialWitnessMap, - expectedWitnessMap, - oracleResponse, - oracleCallName, - oracleCallInputs, - } = await import("../shared/complex_foreign_call"); - - let observedName = ""; +it('successfully processes complex brillig foreign call opcodes', async () => { + const { bytecode, initialWitnessMap, expectedWitnessMap, oracleResponse, oracleCallName, oracleCallInputs } = + await import('../shared/complex_foreign_call'); + + let observedName = ''; let observedInputs: string[][] = []; - const foreignCallHandler: ForeignCallHandler = async ( - name: string, - inputs: string[][], - ) => { + const foreignCallHandler: ForeignCallHandler = async (name: string, inputs: string[][]) => { // Throwing inside the oracle callback causes a timeout so we log the observed values // and defer the check against expected values until after the execution is complete. observedName = name; @@ -92,11 +65,7 @@ it("successfully processes complex brillig foreign call opcodes", async () => { return oracleResponse; }; - const solved_witness: WitnessMap = await executeCircuit( - bytecode, - initialWitnessMap, - foreignCallHandler, - ); + const solved_witness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, foreignCallHandler); // Check that expected values were passed to oracle callback. expect(observedName).to.be.eq(oracleCallName); @@ -107,72 +76,48 @@ it("successfully processes complex brillig foreign call opcodes", async () => { expect(solved_witness).to.be.deep.eq(expectedWitnessMap); }); -it("successfully executes a Pedersen opcode", async function () { +it('successfully executes a Pedersen opcode', async function () { this.timeout(10000); - const { bytecode, initialWitnessMap, expectedWitnessMap } = await import( - "../shared/pedersen" - ); - - const solvedWitness: WitnessMap = await executeCircuit( - bytecode, - initialWitnessMap, - () => { - throw Error("unexpected oracle"); - }, - ); + const { bytecode, initialWitnessMap, expectedWitnessMap } = await import('../shared/pedersen'); + + const solvedWitness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, () => { + throw Error('unexpected oracle'); + }); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); }); -it("successfully executes a FixedBaseScalarMul opcode", async () => { - const { bytecode, initialWitnessMap, expectedWitnessMap } = await import( - "../shared/fixed_base_scalar_mul" - ); +it('successfully executes a FixedBaseScalarMul opcode', async () => { + const { bytecode, initialWitnessMap, expectedWitnessMap } = await import('../shared/fixed_base_scalar_mul'); - const solvedWitness: WitnessMap = await executeCircuit( - bytecode, - initialWitnessMap, - () => { - throw Error("unexpected oracle"); - }, - ); + const solvedWitness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, () => { + throw Error('unexpected oracle'); + }); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); }); -it("successfully executes a SchnorrVerify opcode", async () => { - const { bytecode, initialWitnessMap, expectedWitnessMap } = await import( - "../shared/schnorr_verify" - ); +it('successfully executes a SchnorrVerify opcode', async () => { + const { bytecode, initialWitnessMap, expectedWitnessMap } = await import('../shared/schnorr_verify'); - const solvedWitness: WitnessMap = await executeCircuit( - bytecode, - initialWitnessMap, - () => { - throw Error("unexpected oracle"); - }, - ); + const solvedWitness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, () => { + throw Error('unexpected oracle'); + }); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); }); -it("successfully executes a MemoryOp opcode", async () => { - const { bytecode, initialWitnessMap, expectedWitnessMap } = await import( - "../shared/memory_op" - ); +it('successfully executes a MemoryOp opcode', async () => { + const { bytecode, initialWitnessMap, expectedWitnessMap } = await import('../shared/memory_op'); - const solvedWitness: WitnessMap = await executeCircuit( - bytecode, - initialWitnessMap, - () => { - throw Error("unexpected oracle"); - }, - ); + const solvedWitness: WitnessMap = await executeCircuit(bytecode, initialWitnessMap, () => { + throw Error('unexpected oracle'); + }); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); }); -it("successfully executes two circuits with same backend", async function () { +it('successfully executes two circuits with same backend', async function () { this.timeout(10000); // chose pedersen op here because it is the one with slow initialization @@ -180,33 +125,21 @@ it("successfully executes two circuits with same backend", async function () { // function/wasmbind const solver: WasmBlackBoxFunctionSolver = await createBlackBoxSolver(); - const { bytecode, initialWitnessMap, expectedWitnessMap } = await import( - "../shared/pedersen" - ); - - const solvedWitness0 = await executeCircuitWithBlackBoxSolver( - solver, - bytecode, - initialWitnessMap, - () => { - throw Error("unexpected oracle"); - }, - ); - - const solvedWitness1 = await executeCircuitWithBlackBoxSolver( - solver, - bytecode, - initialWitnessMap, - () => { - throw Error("unexpected oracle"); - }, - ); + const { bytecode, initialWitnessMap, expectedWitnessMap } = await import('../shared/pedersen'); + + const solvedWitness0 = await executeCircuitWithBlackBoxSolver(solver, bytecode, initialWitnessMap, () => { + throw Error('unexpected oracle'); + }); + + const solvedWitness1 = await executeCircuitWithBlackBoxSolver(solver, bytecode, initialWitnessMap, () => { + throw Error('unexpected oracle'); + }); expect(solvedWitness0).to.be.deep.eq(expectedWitnessMap); expect(solvedWitness1).to.be.deep.eq(expectedWitnessMap); }); -it("successfully executes 500 circuits with same backend", async function () { +it('successfully executes 500 circuits with same backend', async function () { this.timeout(100000); // chose pedersen op here because it is the one with slow initialization @@ -214,19 +147,12 @@ it("successfully executes 500 circuits with same backend", async function () { // function/wasmbind const solver: WasmBlackBoxFunctionSolver = await createBlackBoxSolver(); - const { bytecode, initialWitnessMap, expectedWitnessMap } = await import( - "../shared/pedersen" - ); + const { bytecode, initialWitnessMap, expectedWitnessMap } = await import('../shared/pedersen'); for (let i = 0; i < 500; i++) { - const solvedWitness = await executeCircuitWithBlackBoxSolver( - solver, - bytecode, - initialWitnessMap, - () => { - throw Error("unexpected oracle"); - }, - ); + const solvedWitness = await executeCircuitWithBlackBoxSolver(solver, bytecode, initialWitnessMap, () => { + throw Error('unexpected oracle'); + }); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); } diff --git a/acvm-repo/acvm_js/test/node/witness_conversion.test.ts b/acvm-repo/acvm_js/test/node/witness_conversion.test.ts index 86a716c6d70..41291c894ea 100644 --- a/acvm-repo/acvm_js/test/node/witness_conversion.test.ts +++ b/acvm-repo/acvm_js/test/node/witness_conversion.test.ts @@ -1,17 +1,14 @@ -import { expect } from "chai"; -import { compressWitness, decompressWitness } from "@noir-lang/acvm_js"; -import { - expectedCompressedWitnessMap, - expectedWitnessMap, -} from "../shared/witness_compression"; +import { expect } from 'chai'; +import { compressWitness, decompressWitness } from '@noir-lang/acvm_js'; +import { expectedCompressedWitnessMap, expectedWitnessMap } from '../shared/witness_compression'; -it("successfully compresses the witness", () => { +it('successfully compresses the witness', () => { const compressedWitnessMap = compressWitness(expectedWitnessMap); expect(compressedWitnessMap).to.be.deep.eq(expectedCompressedWitnessMap); }); -it("successfully decompresses the witness", () => { +it('successfully decompresses the witness', () => { const witnessMap = decompressWitness(expectedCompressedWitnessMap); expect(witnessMap).to.be.deep.eq(expectedWitnessMap); diff --git a/acvm-repo/acvm_js/test/shared/addition.ts b/acvm-repo/acvm_js/test/shared/addition.ts index 02b7d8457a8..982b9b685ce 100644 --- a/acvm-repo/acvm_js/test/shared/addition.ts +++ b/acvm-repo/acvm_js/test/shared/addition.ts @@ -1,21 +1,18 @@ -import { WitnessMap } from "@noir-lang/acvm_js"; +import { WitnessMap } from '@noir-lang/acvm_js'; // See `addition_circuit` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 144, 187, 13, 192, 32, 12, 68, 249, - 100, 32, 27, 219, 96, 119, 89, 37, 40, 176, 255, 8, 17, 18, 5, 74, 202, 240, - 154, 235, 158, 238, 238, 112, 206, 121, 247, 37, 206, 60, 103, 194, 63, 208, - 111, 116, 133, 197, 69, 144, 153, 91, 73, 13, 9, 47, 72, 86, 85, 128, 165, - 102, 69, 69, 81, 185, 147, 18, 53, 101, 45, 86, 173, 128, 33, 83, 195, 46, 70, - 125, 202, 226, 190, 94, 16, 166, 103, 108, 13, 203, 151, 254, 245, 233, 224, - 1, 1, 52, 166, 127, 120, 1, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 144, 187, 13, 192, 32, 12, 68, 249, 100, 32, 27, 219, 96, 119, 89, 37, 40, + 176, 255, 8, 17, 18, 5, 74, 202, 240, 154, 235, 158, 238, 238, 112, 206, 121, 247, 37, 206, 60, 103, 194, 63, 208, + 111, 116, 133, 197, 69, 144, 153, 91, 73, 13, 9, 47, 72, 86, 85, 128, 165, 102, 69, 69, 81, 185, 147, 18, 53, 101, 45, + 86, 173, 128, 33, 83, 195, 46, 70, 125, 202, 226, 190, 94, 16, 166, 103, 108, 13, 203, 151, 254, 245, 233, 224, 1, 1, + 52, 166, 127, 120, 1, 0, 0, ]); export const initialWitnessMap: WitnessMap = new Map([ - [1, "0x0000000000000000000000000000000000000000000000000000000000000001"], - [2, "0x0000000000000000000000000000000000000000000000000000000000000002"], + [1, '0x0000000000000000000000000000000000000000000000000000000000000001'], + [2, '0x0000000000000000000000000000000000000000000000000000000000000002'], ]); export const resultWitness = 3; -export const expectedResult = - "0x0000000000000000000000000000000000000000000000000000000000000003"; +export const expectedResult = '0x0000000000000000000000000000000000000000000000000000000000000003'; diff --git a/acvm-repo/acvm_js/test/shared/complex_foreign_call.ts b/acvm-repo/acvm_js/test/shared/complex_foreign_call.ts index 5fb6b2559e1..9fad300add1 100644 --- a/acvm-repo/acvm_js/test/shared/complex_foreign_call.ts +++ b/acvm-repo/acvm_js/test/shared/complex_foreign_call.ts @@ -1,49 +1,46 @@ -import { WitnessMap } from "@noir-lang/acvm_js"; +import { WitnessMap } from '@noir-lang/acvm_js'; // See `complex_brillig_foreign_call` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 83, 219, 10, 128, 48, 8, 245, 210, - 101, 159, 179, 254, 160, 127, 137, 222, 138, 122, 236, 243, 27, 228, 64, 44, - 232, 33, 7, 237, 128, 56, 157, 147, 131, 103, 6, 0, 64, 184, 192, 201, 72, - 206, 40, 177, 70, 174, 27, 197, 199, 111, 24, 208, 175, 87, 44, 197, 145, 42, - 224, 200, 5, 56, 230, 255, 240, 83, 189, 61, 117, 113, 157, 31, 63, 236, 79, - 147, 172, 77, 214, 73, 220, 139, 15, 106, 214, 168, 114, 249, 126, 218, 214, - 125, 153, 15, 54, 37, 90, 26, 155, 39, 227, 95, 223, 232, 230, 4, 247, 157, - 215, 56, 1, 153, 86, 63, 138, 44, 4, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 83, 219, 10, 128, 48, 8, 245, 210, 101, 159, 179, 254, 160, 127, 137, 222, + 138, 122, 236, 243, 27, 228, 64, 44, 232, 33, 7, 237, 128, 56, 157, 147, 131, 103, 6, 0, 64, 184, 192, 201, 72, 206, + 40, 177, 70, 174, 27, 197, 199, 111, 24, 208, 175, 87, 44, 197, 145, 42, 224, 200, 5, 56, 230, 255, 240, 83, 189, 61, + 117, 113, 157, 31, 63, 236, 79, 147, 172, 77, 214, 73, 220, 139, 15, 106, 214, 168, 114, 249, 126, 218, 214, 125, 153, + 15, 54, 37, 90, 26, 155, 39, 227, 95, 223, 232, 230, 4, 247, 157, 215, 56, 1, 153, 86, 63, 138, 44, 4, 0, 0, ]); export const initialWitnessMap: WitnessMap = new Map([ - [1, "0x0000000000000000000000000000000000000000000000000000000000000001"], - [2, "0x0000000000000000000000000000000000000000000000000000000000000002"], - [3, "0x0000000000000000000000000000000000000000000000000000000000000003"], + [1, '0x0000000000000000000000000000000000000000000000000000000000000001'], + [2, '0x0000000000000000000000000000000000000000000000000000000000000002'], + [3, '0x0000000000000000000000000000000000000000000000000000000000000003'], ]); -export const oracleCallName = "complex"; +export const oracleCallName = 'complex'; export const oracleCallInputs = [ [ - "0x0000000000000000000000000000000000000000000000000000000000000001", - "0x0000000000000000000000000000000000000000000000000000000000000002", - "0x0000000000000000000000000000000000000000000000000000000000000003", + '0x0000000000000000000000000000000000000000000000000000000000000001', + '0x0000000000000000000000000000000000000000000000000000000000000002', + '0x0000000000000000000000000000000000000000000000000000000000000003', ], - ["0x0000000000000000000000000000000000000000000000000000000000000006"], + ['0x0000000000000000000000000000000000000000000000000000000000000006'], ]; export const oracleResponse = [ [ - "0x0000000000000000000000000000000000000000000000000000000000000002", - "0x0000000000000000000000000000000000000000000000000000000000000006", - "0x000000000000000000000000000000000000000000000000000000000000000c", + '0x0000000000000000000000000000000000000000000000000000000000000002', + '0x0000000000000000000000000000000000000000000000000000000000000006', + '0x000000000000000000000000000000000000000000000000000000000000000c', ], - "0x0000000000000000000000000000000000000000000000000000000000000006", - "0x000000000000000000000000000000000000000000000000000000000000000c", + '0x0000000000000000000000000000000000000000000000000000000000000006', + '0x000000000000000000000000000000000000000000000000000000000000000c', ]; export const expectedWitnessMap = new Map([ - [1, "0x0000000000000000000000000000000000000000000000000000000000000001"], - [2, "0x0000000000000000000000000000000000000000000000000000000000000002"], - [3, "0x0000000000000000000000000000000000000000000000000000000000000003"], - [4, "0x0000000000000000000000000000000000000000000000000000000000000002"], - [5, "0x0000000000000000000000000000000000000000000000000000000000000006"], - [6, "0x000000000000000000000000000000000000000000000000000000000000000c"], - [7, "0x0000000000000000000000000000000000000000000000000000000000000006"], - [8, "0x000000000000000000000000000000000000000000000000000000000000000c"], + [1, '0x0000000000000000000000000000000000000000000000000000000000000001'], + [2, '0x0000000000000000000000000000000000000000000000000000000000000002'], + [3, '0x0000000000000000000000000000000000000000000000000000000000000003'], + [4, '0x0000000000000000000000000000000000000000000000000000000000000002'], + [5, '0x0000000000000000000000000000000000000000000000000000000000000006'], + [6, '0x000000000000000000000000000000000000000000000000000000000000000c'], + [7, '0x0000000000000000000000000000000000000000000000000000000000000006'], + [8, '0x000000000000000000000000000000000000000000000000000000000000000c'], ]); diff --git a/acvm-repo/acvm_js/test/shared/fixed_base_scalar_mul.ts b/acvm-repo/acvm_js/test/shared/fixed_base_scalar_mul.ts index 4240b424999..e5f35e2b8fc 100644 --- a/acvm-repo/acvm_js/test/shared/fixed_base_scalar_mul.ts +++ b/acvm-repo/acvm_js/test/shared/fixed_base_scalar_mul.ts @@ -1,18 +1,17 @@ // See `fixed_base_scalar_mul_circuit` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 77, 138, 91, 10, 0, 48, 12, 194, 178, 215, - 207, 78, 189, 163, 175, 165, 10, 21, 36, 10, 57, 192, 160, 146, 188, 226, 139, - 78, 113, 69, 183, 190, 61, 111, 218, 182, 231, 124, 68, 185, 243, 207, 92, 0, - 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 77, 138, 91, 10, 0, 48, 12, 194, 178, 215, 207, 78, 189, 163, 175, 165, 10, 21, 36, + 10, 57, 192, 160, 146, 188, 226, 139, 78, 113, 69, 183, 190, 61, 111, 218, 182, 231, 124, 68, 185, 243, 207, 92, 0, 0, + 0, ]); export const initialWitnessMap = new Map([ - [1, "0x0000000000000000000000000000000000000000000000000000000000000001"], - [2, "0x0000000000000000000000000000000000000000000000000000000000000000"], + [1, '0x0000000000000000000000000000000000000000000000000000000000000001'], + [2, '0x0000000000000000000000000000000000000000000000000000000000000000'], ]); export const expectedWitnessMap = new Map([ - [1, "0x0000000000000000000000000000000000000000000000000000000000000001"], - [2, "0x0000000000000000000000000000000000000000000000000000000000000000"], - [3, "0x0000000000000000000000000000000000000000000000000000000000000001"], - [4, "0x0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272c"], + [1, '0x0000000000000000000000000000000000000000000000000000000000000001'], + [2, '0x0000000000000000000000000000000000000000000000000000000000000000'], + [3, '0x0000000000000000000000000000000000000000000000000000000000000001'], + [4, '0x0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272c'], ]); diff --git a/acvm-repo/acvm_js/test/shared/foreign_call.ts b/acvm-repo/acvm_js/test/shared/foreign_call.ts index 615f705f064..8f4c76effd2 100644 --- a/acvm-repo/acvm_js/test/shared/foreign_call.ts +++ b/acvm-repo/acvm_js/test/shared/foreign_call.ts @@ -1,27 +1,22 @@ -import { WitnessMap } from "@noir-lang/acvm_js"; +import { WitnessMap } from '@noir-lang/acvm_js'; // See `simple_brillig_foreign_call` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 143, 81, 10, 0, 16, 16, 68, 199, 42, - 57, 14, 55, 112, 25, 31, 126, 124, 72, 206, 79, 161, 86, 225, 135, 87, 219, - 78, 187, 53, 205, 104, 0, 2, 29, 201, 52, 103, 222, 220, 216, 230, 13, 43, - 254, 121, 25, 158, 151, 54, 153, 117, 27, 53, 116, 136, 197, 167, 124, 107, - 184, 64, 236, 73, 56, 83, 1, 18, 139, 122, 157, 67, 1, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 143, 81, 10, 0, 16, 16, 68, 199, 42, 57, 14, 55, 112, 25, 31, 126, 124, 72, + 206, 79, 161, 86, 225, 135, 87, 219, 78, 187, 53, 205, 104, 0, 2, 29, 201, 52, 103, 222, 220, 216, 230, 13, 43, 254, + 121, 25, 158, 151, 54, 153, 117, 27, 53, 116, 136, 197, 167, 124, 107, 184, 64, 236, 73, 56, 83, 1, 18, 139, 122, 157, + 67, 1, 0, 0, ]); export const initialWitnessMap: WitnessMap = new Map([ - [1, "0x0000000000000000000000000000000000000000000000000000000000000005"], + [1, '0x0000000000000000000000000000000000000000000000000000000000000005'], ]); -export const oracleCallName = "invert"; -export const oracleCallInputs = [ - ["0x0000000000000000000000000000000000000000000000000000000000000005"], -]; +export const oracleCallName = 'invert'; +export const oracleCallInputs = [['0x0000000000000000000000000000000000000000000000000000000000000005']]; -export const oracleResponse = [ - "0x135b52945a13d9aa49b9b57c33cd568ba9ae5ce9ca4a2d06e7f3fbd4c6666667", -]; +export const oracleResponse = ['0x135b52945a13d9aa49b9b57c33cd568ba9ae5ce9ca4a2d06e7f3fbd4c6666667']; export const expectedWitnessMap = new Map([ - [1, "0x0000000000000000000000000000000000000000000000000000000000000005"], - [2, "0x135b52945a13d9aa49b9b57c33cd568ba9ae5ce9ca4a2d06e7f3fbd4c6666667"], + [1, '0x0000000000000000000000000000000000000000000000000000000000000005'], + [2, '0x135b52945a13d9aa49b9b57c33cd568ba9ae5ce9ca4a2d06e7f3fbd4c6666667'], ]); diff --git a/acvm-repo/acvm_js/test/shared/memory_op.ts b/acvm-repo/acvm_js/test/shared/memory_op.ts index ffb37df3404..ce88f491893 100644 --- a/acvm-repo/acvm_js/test/shared/memory_op.ts +++ b/acvm-repo/acvm_js/test/shared/memory_op.ts @@ -1,21 +1,20 @@ // See `memory_op_circuit` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 146, 49, 14, 0, 32, 8, 3, 139, 192, - 127, 240, 7, 254, 255, 85, 198, 136, 9, 131, 155, 48, 216, 165, 76, 77, 57, - 80, 0, 140, 45, 117, 111, 238, 228, 179, 224, 174, 225, 110, 111, 234, 213, - 185, 148, 156, 203, 121, 89, 86, 13, 215, 126, 131, 43, 153, 187, 115, 40, - 185, 62, 153, 3, 136, 83, 60, 30, 96, 2, 12, 235, 225, 124, 14, 3, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 146, 49, 14, 0, 32, 8, 3, 139, 192, 127, 240, 7, 254, 255, 85, 198, 136, 9, + 131, 155, 48, 216, 165, 76, 77, 57, 80, 0, 140, 45, 117, 111, 238, 228, 179, 224, 174, 225, 110, 111, 234, 213, 185, + 148, 156, 203, 121, 89, 86, 13, 215, 126, 131, 43, 153, 187, 115, 40, 185, 62, 153, 3, 136, 83, 60, 30, 96, 2, 12, + 235, 225, 124, 14, 3, 0, 0, ]); export const initialWitnessMap = new Map([ - [1, "0x0000000000000000000000000000000000000000000000000000000000000001"], - [2, "0x0000000000000000000000000000000000000000000000000000000000000001"], - [3, "0x0000000000000000000000000000000000000000000000000000000000000002"], + [1, '0x0000000000000000000000000000000000000000000000000000000000000001'], + [2, '0x0000000000000000000000000000000000000000000000000000000000000001'], + [3, '0x0000000000000000000000000000000000000000000000000000000000000002'], ]); export const expectedWitnessMap = new Map([ - [1, "0x0000000000000000000000000000000000000000000000000000000000000001"], - [2, "0x0000000000000000000000000000000000000000000000000000000000000001"], - [3, "0x0000000000000000000000000000000000000000000000000000000000000002"], - [4, "0x0000000000000000000000000000000000000000000000000000000000000002"], + [1, '0x0000000000000000000000000000000000000000000000000000000000000001'], + [2, '0x0000000000000000000000000000000000000000000000000000000000000001'], + [3, '0x0000000000000000000000000000000000000000000000000000000000000002'], + [4, '0x0000000000000000000000000000000000000000000000000000000000000002'], ]); diff --git a/acvm-repo/acvm_js/test/shared/pedersen.ts b/acvm-repo/acvm_js/test/shared/pedersen.ts index 16e5ded5eaf..a973718e31c 100644 --- a/acvm-repo/acvm_js/test/shared/pedersen.ts +++ b/acvm-repo/acvm_js/test/shared/pedersen.ts @@ -1,16 +1,13 @@ // See `pedersen_circuit` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 138, 9, 10, 0, 64, 8, 2, 103, 15, 250, - 255, 139, 163, 162, 130, 72, 16, 149, 241, 3, 135, 84, 164, 172, 173, 213, - 175, 251, 45, 198, 96, 243, 211, 50, 152, 67, 220, 211, 92, 0, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 138, 9, 10, 0, 64, 8, 2, 103, 15, 250, 255, 139, 163, 162, 130, 72, 16, 149, + 241, 3, 135, 84, 164, 172, 173, 213, 175, 251, 45, 198, 96, 243, 211, 50, 152, 67, 220, 211, 92, 0, 0, 0, ]); -export const initialWitnessMap = new Map([ - [1, "0x0000000000000000000000000000000000000000000000000000000000000001"], -]); +export const initialWitnessMap = new Map([[1, '0x0000000000000000000000000000000000000000000000000000000000000001']]); export const expectedWitnessMap = new Map([ - [1, "0x0000000000000000000000000000000000000000000000000000000000000001"], - [2, "0x09489945604c9686e698cb69d7bd6fc0cdb02e9faae3e1a433f1c342c1a5ecc4"], - [3, "0x24f50d25508b4dfb1e8a834e39565f646e217b24cb3a475c2e4991d1bb07a9d8"], + [1, '0x0000000000000000000000000000000000000000000000000000000000000001'], + [2, '0x09489945604c9686e698cb69d7bd6fc0cdb02e9faae3e1a433f1c342c1a5ecc4'], + [3, '0x24f50d25508b4dfb1e8a834e39565f646e217b24cb3a475c2e4991d1bb07a9d8'], ]); diff --git a/acvm-repo/acvm_js/test/shared/schnorr_verify.ts b/acvm-repo/acvm_js/test/shared/schnorr_verify.ts index de9e61e757c..afd57d8ffb5 100644 --- a/acvm-repo/acvm_js/test/shared/schnorr_verify.ts +++ b/acvm-repo/acvm_js/test/shared/schnorr_verify.ts @@ -1,105 +1,99 @@ // See `schnorr_verify_circuit` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 77, 210, 87, 78, 2, 1, 20, 134, 209, 177, - 247, 222, 123, 71, 68, 68, 68, 68, 68, 68, 68, 68, 68, 221, 133, 251, 95, 130, - 145, 27, 206, 36, 78, 50, 57, 16, 94, 200, 253, 191, 159, 36, 73, 134, 146, - 193, 19, 142, 241, 183, 255, 14, 179, 233, 247, 145, 254, 59, 217, 127, 71, - 57, 198, 113, 78, 48, 125, 167, 56, 205, 25, 206, 114, 142, 243, 92, 224, 34, - 151, 184, 204, 21, 174, 114, 141, 235, 220, 224, 38, 183, 184, 205, 29, 238, - 114, 143, 251, 60, 224, 33, 143, 120, 204, 19, 158, 242, 140, 25, 158, 51, - 203, 11, 230, 120, 201, 60, 175, 88, 224, 53, 139, 188, 97, 137, 183, 44, 243, - 142, 21, 222, 179, 202, 7, 214, 248, 200, 58, 159, 216, 224, 51, 155, 124, 97, - 235, 223, 142, 241, 188, 250, 222, 230, 27, 59, 124, 103, 151, 31, 236, 241, - 147, 95, 252, 246, 57, 158, 104, 47, 186, 139, 214, 162, 179, 104, 44, 250, - 74, 219, 154, 242, 63, 162, 165, 232, 40, 26, 138, 126, 162, 157, 232, 38, - 154, 137, 94, 162, 149, 232, 36, 26, 137, 62, 162, 141, 232, 34, 154, 136, 30, - 162, 133, 232, 32, 26, 136, 253, 99, 251, 195, 100, 176, 121, 236, 29, 91, - 159, 218, 56, 99, 219, 172, 77, 115, 182, 204, 219, 176, 96, 187, 162, 205, - 74, 182, 42, 219, 168, 98, 155, 170, 77, 106, 182, 168, 219, 160, 225, 246, - 77, 55, 111, 185, 113, 219, 109, 59, 110, 218, 117, 203, 158, 27, 166, 55, 75, - 239, 150, 184, 101, 250, 252, 1, 19, 89, 159, 101, 220, 3, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 77, 210, 87, 78, 2, 1, 20, 134, 209, 177, 247, 222, 123, 71, 68, 68, 68, 68, 68, + 68, 68, 68, 68, 221, 133, 251, 95, 130, 145, 27, 206, 36, 78, 50, 57, 16, 94, 200, 253, 191, 159, 36, 73, 134, 146, + 193, 19, 142, 241, 183, 255, 14, 179, 233, 247, 145, 254, 59, 217, 127, 71, 57, 198, 113, 78, 48, 125, 167, 56, 205, + 25, 206, 114, 142, 243, 92, 224, 34, 151, 184, 204, 21, 174, 114, 141, 235, 220, 224, 38, 183, 184, 205, 29, 238, 114, + 143, 251, 60, 224, 33, 143, 120, 204, 19, 158, 242, 140, 25, 158, 51, 203, 11, 230, 120, 201, 60, 175, 88, 224, 53, + 139, 188, 97, 137, 183, 44, 243, 142, 21, 222, 179, 202, 7, 214, 248, 200, 58, 159, 216, 224, 51, 155, 124, 97, 235, + 223, 142, 241, 188, 250, 222, 230, 27, 59, 124, 103, 151, 31, 236, 241, 147, 95, 252, 246, 57, 158, 104, 47, 186, 139, + 214, 162, 179, 104, 44, 250, 74, 219, 154, 242, 63, 162, 165, 232, 40, 26, 138, 126, 162, 157, 232, 38, 154, 137, 94, + 162, 149, 232, 36, 26, 137, 62, 162, 141, 232, 34, 154, 136, 30, 162, 133, 232, 32, 26, 136, 253, 99, 251, 195, 100, + 176, 121, 236, 29, 91, 159, 218, 56, 99, 219, 172, 77, 115, 182, 204, 219, 176, 96, 187, 162, 205, 74, 182, 42, 219, + 168, 98, 155, 170, 77, 106, 182, 168, 219, 160, 225, 246, 77, 55, 111, 185, 113, 219, 109, 59, 110, 218, 117, 203, + 158, 27, 166, 55, 75, 239, 150, 184, 101, 250, 252, 1, 19, 89, 159, 101, 220, 3, 0, 0, ]); export const initialWitnessMap = new Map([ - [1, "0x17cbd3ed3151ccfd170efe1d54280a6a4822640bf5c369908ad74ea21518a9c5"], - [2, "0x0e0456e3795c1a31f20035b741cd6158929eeccd320d299cfcac962865a6bc74"], - [3, "0x0000000000000000000000000000000000000000000000000000000000000005"], - [4, "0x00000000000000000000000000000000000000000000000000000000000000ca"], - [5, "0x000000000000000000000000000000000000000000000000000000000000001f"], - [6, "0x0000000000000000000000000000000000000000000000000000000000000092"], - [7, "0x0000000000000000000000000000000000000000000000000000000000000051"], - [8, "0x00000000000000000000000000000000000000000000000000000000000000f2"], - [9, "0x00000000000000000000000000000000000000000000000000000000000000f6"], - [10, "0x0000000000000000000000000000000000000000000000000000000000000045"], - [11, "0x000000000000000000000000000000000000000000000000000000000000002b"], - [12, "0x000000000000000000000000000000000000000000000000000000000000006b"], - [13, "0x00000000000000000000000000000000000000000000000000000000000000f9"], - [14, "0x0000000000000000000000000000000000000000000000000000000000000099"], - [15, "0x00000000000000000000000000000000000000000000000000000000000000c6"], - [16, "0x000000000000000000000000000000000000000000000000000000000000002c"], - [17, "0x000000000000000000000000000000000000000000000000000000000000000e"], - [18, "0x000000000000000000000000000000000000000000000000000000000000006f"], - [19, "0x00000000000000000000000000000000000000000000000000000000000000bf"], - [20, "0x0000000000000000000000000000000000000000000000000000000000000079"], - [21, "0x0000000000000000000000000000000000000000000000000000000000000089"], - [22, "0x00000000000000000000000000000000000000000000000000000000000000a6"], - [23, "0x00000000000000000000000000000000000000000000000000000000000000a0"], - [24, "0x0000000000000000000000000000000000000000000000000000000000000067"], - [25, "0x0000000000000000000000000000000000000000000000000000000000000012"], - [26, "0x00000000000000000000000000000000000000000000000000000000000000b5"], - [27, "0x00000000000000000000000000000000000000000000000000000000000000f3"], - [28, "0x00000000000000000000000000000000000000000000000000000000000000e9"], - [29, "0x00000000000000000000000000000000000000000000000000000000000000e2"], - [30, "0x000000000000000000000000000000000000000000000000000000000000005f"], - [31, "0x0000000000000000000000000000000000000000000000000000000000000043"], - [32, "0x0000000000000000000000000000000000000000000000000000000000000010"], - [33, "0x0000000000000000000000000000000000000000000000000000000000000025"], - [34, "0x0000000000000000000000000000000000000000000000000000000000000080"], - [35, "0x0000000000000000000000000000000000000000000000000000000000000055"], - [36, "0x000000000000000000000000000000000000000000000000000000000000004c"], - [37, "0x0000000000000000000000000000000000000000000000000000000000000013"], - [38, "0x00000000000000000000000000000000000000000000000000000000000000fd"], - [39, "0x000000000000000000000000000000000000000000000000000000000000001e"], - [40, "0x000000000000000000000000000000000000000000000000000000000000004d"], - [41, "0x00000000000000000000000000000000000000000000000000000000000000c0"], - [42, "0x0000000000000000000000000000000000000000000000000000000000000035"], - [43, "0x000000000000000000000000000000000000000000000000000000000000008a"], - [44, "0x00000000000000000000000000000000000000000000000000000000000000cd"], - [45, "0x0000000000000000000000000000000000000000000000000000000000000045"], - [46, "0x0000000000000000000000000000000000000000000000000000000000000021"], - [47, "0x00000000000000000000000000000000000000000000000000000000000000ec"], - [48, "0x00000000000000000000000000000000000000000000000000000000000000a3"], - [49, "0x0000000000000000000000000000000000000000000000000000000000000053"], - [50, "0x00000000000000000000000000000000000000000000000000000000000000c2"], - [51, "0x0000000000000000000000000000000000000000000000000000000000000054"], - [52, "0x0000000000000000000000000000000000000000000000000000000000000089"], - [53, "0x00000000000000000000000000000000000000000000000000000000000000b8"], - [54, "0x00000000000000000000000000000000000000000000000000000000000000dd"], - [55, "0x00000000000000000000000000000000000000000000000000000000000000b0"], - [56, "0x0000000000000000000000000000000000000000000000000000000000000079"], - [57, "0x00000000000000000000000000000000000000000000000000000000000000b3"], - [58, "0x000000000000000000000000000000000000000000000000000000000000001b"], - [59, "0x000000000000000000000000000000000000000000000000000000000000003f"], - [60, "0x0000000000000000000000000000000000000000000000000000000000000046"], - [61, "0x0000000000000000000000000000000000000000000000000000000000000036"], - [62, "0x0000000000000000000000000000000000000000000000000000000000000010"], - [63, "0x00000000000000000000000000000000000000000000000000000000000000b0"], - [64, "0x00000000000000000000000000000000000000000000000000000000000000fa"], - [65, "0x0000000000000000000000000000000000000000000000000000000000000027"], - [66, "0x00000000000000000000000000000000000000000000000000000000000000ef"], - [67, "0x0000000000000000000000000000000000000000000000000000000000000000"], - [68, "0x0000000000000000000000000000000000000000000000000000000000000001"], - [69, "0x0000000000000000000000000000000000000000000000000000000000000002"], - [70, "0x0000000000000000000000000000000000000000000000000000000000000003"], - [71, "0x0000000000000000000000000000000000000000000000000000000000000004"], - [72, "0x0000000000000000000000000000000000000000000000000000000000000005"], - [73, "0x0000000000000000000000000000000000000000000000000000000000000006"], - [74, "0x0000000000000000000000000000000000000000000000000000000000000007"], - [75, "0x0000000000000000000000000000000000000000000000000000000000000008"], - [76, "0x0000000000000000000000000000000000000000000000000000000000000009"], + [1, '0x17cbd3ed3151ccfd170efe1d54280a6a4822640bf5c369908ad74ea21518a9c5'], + [2, '0x0e0456e3795c1a31f20035b741cd6158929eeccd320d299cfcac962865a6bc74'], + [3, '0x0000000000000000000000000000000000000000000000000000000000000005'], + [4, '0x00000000000000000000000000000000000000000000000000000000000000ca'], + [5, '0x000000000000000000000000000000000000000000000000000000000000001f'], + [6, '0x0000000000000000000000000000000000000000000000000000000000000092'], + [7, '0x0000000000000000000000000000000000000000000000000000000000000051'], + [8, '0x00000000000000000000000000000000000000000000000000000000000000f2'], + [9, '0x00000000000000000000000000000000000000000000000000000000000000f6'], + [10, '0x0000000000000000000000000000000000000000000000000000000000000045'], + [11, '0x000000000000000000000000000000000000000000000000000000000000002b'], + [12, '0x000000000000000000000000000000000000000000000000000000000000006b'], + [13, '0x00000000000000000000000000000000000000000000000000000000000000f9'], + [14, '0x0000000000000000000000000000000000000000000000000000000000000099'], + [15, '0x00000000000000000000000000000000000000000000000000000000000000c6'], + [16, '0x000000000000000000000000000000000000000000000000000000000000002c'], + [17, '0x000000000000000000000000000000000000000000000000000000000000000e'], + [18, '0x000000000000000000000000000000000000000000000000000000000000006f'], + [19, '0x00000000000000000000000000000000000000000000000000000000000000bf'], + [20, '0x0000000000000000000000000000000000000000000000000000000000000079'], + [21, '0x0000000000000000000000000000000000000000000000000000000000000089'], + [22, '0x00000000000000000000000000000000000000000000000000000000000000a6'], + [23, '0x00000000000000000000000000000000000000000000000000000000000000a0'], + [24, '0x0000000000000000000000000000000000000000000000000000000000000067'], + [25, '0x0000000000000000000000000000000000000000000000000000000000000012'], + [26, '0x00000000000000000000000000000000000000000000000000000000000000b5'], + [27, '0x00000000000000000000000000000000000000000000000000000000000000f3'], + [28, '0x00000000000000000000000000000000000000000000000000000000000000e9'], + [29, '0x00000000000000000000000000000000000000000000000000000000000000e2'], + [30, '0x000000000000000000000000000000000000000000000000000000000000005f'], + [31, '0x0000000000000000000000000000000000000000000000000000000000000043'], + [32, '0x0000000000000000000000000000000000000000000000000000000000000010'], + [33, '0x0000000000000000000000000000000000000000000000000000000000000025'], + [34, '0x0000000000000000000000000000000000000000000000000000000000000080'], + [35, '0x0000000000000000000000000000000000000000000000000000000000000055'], + [36, '0x000000000000000000000000000000000000000000000000000000000000004c'], + [37, '0x0000000000000000000000000000000000000000000000000000000000000013'], + [38, '0x00000000000000000000000000000000000000000000000000000000000000fd'], + [39, '0x000000000000000000000000000000000000000000000000000000000000001e'], + [40, '0x000000000000000000000000000000000000000000000000000000000000004d'], + [41, '0x00000000000000000000000000000000000000000000000000000000000000c0'], + [42, '0x0000000000000000000000000000000000000000000000000000000000000035'], + [43, '0x000000000000000000000000000000000000000000000000000000000000008a'], + [44, '0x00000000000000000000000000000000000000000000000000000000000000cd'], + [45, '0x0000000000000000000000000000000000000000000000000000000000000045'], + [46, '0x0000000000000000000000000000000000000000000000000000000000000021'], + [47, '0x00000000000000000000000000000000000000000000000000000000000000ec'], + [48, '0x00000000000000000000000000000000000000000000000000000000000000a3'], + [49, '0x0000000000000000000000000000000000000000000000000000000000000053'], + [50, '0x00000000000000000000000000000000000000000000000000000000000000c2'], + [51, '0x0000000000000000000000000000000000000000000000000000000000000054'], + [52, '0x0000000000000000000000000000000000000000000000000000000000000089'], + [53, '0x00000000000000000000000000000000000000000000000000000000000000b8'], + [54, '0x00000000000000000000000000000000000000000000000000000000000000dd'], + [55, '0x00000000000000000000000000000000000000000000000000000000000000b0'], + [56, '0x0000000000000000000000000000000000000000000000000000000000000079'], + [57, '0x00000000000000000000000000000000000000000000000000000000000000b3'], + [58, '0x000000000000000000000000000000000000000000000000000000000000001b'], + [59, '0x000000000000000000000000000000000000000000000000000000000000003f'], + [60, '0x0000000000000000000000000000000000000000000000000000000000000046'], + [61, '0x0000000000000000000000000000000000000000000000000000000000000036'], + [62, '0x0000000000000000000000000000000000000000000000000000000000000010'], + [63, '0x00000000000000000000000000000000000000000000000000000000000000b0'], + [64, '0x00000000000000000000000000000000000000000000000000000000000000fa'], + [65, '0x0000000000000000000000000000000000000000000000000000000000000027'], + [66, '0x00000000000000000000000000000000000000000000000000000000000000ef'], + [67, '0x0000000000000000000000000000000000000000000000000000000000000000'], + [68, '0x0000000000000000000000000000000000000000000000000000000000000001'], + [69, '0x0000000000000000000000000000000000000000000000000000000000000002'], + [70, '0x0000000000000000000000000000000000000000000000000000000000000003'], + [71, '0x0000000000000000000000000000000000000000000000000000000000000004'], + [72, '0x0000000000000000000000000000000000000000000000000000000000000005'], + [73, '0x0000000000000000000000000000000000000000000000000000000000000006'], + [74, '0x0000000000000000000000000000000000000000000000000000000000000007'], + [75, '0x0000000000000000000000000000000000000000000000000000000000000008'], + [76, '0x0000000000000000000000000000000000000000000000000000000000000009'], ]); export const expectedWitnessMap = new Map(initialWitnessMap).set( 77, - "0x0000000000000000000000000000000000000000000000000000000000000001", + '0x0000000000000000000000000000000000000000000000000000000000000001', ); diff --git a/acvm-repo/acvm_js/test/shared/witness_compression.ts b/acvm-repo/acvm_js/test/shared/witness_compression.ts index 8885364bf6d..36b9a0284af 100644 --- a/acvm-repo/acvm_js/test/shared/witness_compression.ts +++ b/acvm-repo/acvm_js/test/shared/witness_compression.ts @@ -6,19 +6,17 @@ // } export const expectedCompressedWitnessMap = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 2, 255, 173, 208, 187, 13, 128, 48, 12, 4, 80, 190, - 153, 199, 142, 237, 196, 238, 88, 133, 8, 103, 255, 17, 64, 34, 5, 61, 62, - 233, 164, 171, 94, 113, 105, 122, 51, 63, 61, 198, 134, 127, 193, 37, 206, - 202, 235, 199, 34, 40, 204, 94, 179, 35, 225, 9, 217, 154, 10, 176, 180, 162, - 168, 40, 42, 87, 86, 34, 87, 214, 106, 205, 42, 24, 50, 57, 118, 49, 234, 3, - 219, 2, 173, 61, 240, 175, 20, 103, 209, 13, 151, 252, 77, 33, 208, 1, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 2, 255, 173, 208, 187, 13, 128, 48, 12, 4, 80, 190, 153, 199, 142, 237, 196, 238, 88, 133, + 8, 103, 255, 17, 64, 34, 5, 61, 62, 233, 164, 171, 94, 113, 105, 122, 51, 63, 61, 198, 134, 127, 193, 37, 206, 202, + 235, 199, 34, 40, 204, 94, 179, 35, 225, 9, 217, 154, 10, 176, 180, 162, 168, 40, 42, 87, 86, 34, 87, 214, 106, 205, + 42, 24, 50, 57, 118, 49, 234, 3, 219, 2, 173, 61, 240, 175, 20, 103, 209, 13, 151, 252, 77, 33, 208, 1, 0, 0, ]); export const expectedWitnessMap = new Map([ - [1, "0x0000000000000000000000000000000000000000000000000000000000000001"], - [2, "0x0000000000000000000000000000000000000000000000000000000000000002"], - [3, "0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000"], - [4, "0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000"], - [5, "0x0000000000000000000000000000000000000000000000000000000000000001"], - [6, "0x0000000000000000000000000000000000000000000000000000000000000003"], + [1, '0x0000000000000000000000000000000000000000000000000000000000000001'], + [2, '0x0000000000000000000000000000000000000000000000000000000000000002'], + [3, '0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000'], + [4, '0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000'], + [5, '0x0000000000000000000000000000000000000000000000000000000000000001'], + [6, '0x0000000000000000000000000000000000000000000000000000000000000003'], ]); diff --git a/compiler/integration-tests/test/index.d.ts b/compiler/integration-tests/test/index.d.ts index 4db9e01cacd..7ae9da01261 100644 --- a/compiler/integration-tests/test/index.d.ts +++ b/compiler/integration-tests/test/index.d.ts @@ -1 +1 @@ -declare module "@aztec/bb.js"; +declare module '@aztec/bb.js'; diff --git a/compiler/integration-tests/test/integration/browser/compile_prove_verify.test.ts b/compiler/integration-tests/test/integration/browser/compile_prove_verify.test.ts index ea9f4db73a9..f45734f6327 100644 --- a/compiler/integration-tests/test/integration/browser/compile_prove_verify.test.ts +++ b/compiler/integration-tests/test/integration/browser/compile_prove_verify.test.ts @@ -1,22 +1,19 @@ -import { expect } from "@esm-bundle/chai"; -import { TEST_LOG_LEVEL } from "../../environment.js"; -import { Logger } from "tslog"; -import { initializeResolver } from "@noir-lang/source-resolver"; -import newCompiler, { - compile, - init_log_level as compilerLogLevel, -} from "@noir-lang/noir_wasm"; -import { acvm, abi } from "@noir-lang/noir_js"; -import { Barretenberg, RawBuffer, Crs } from "@aztec/bb.js"; -import { decompressSync as gunzip } from "fflate"; -import { ethers } from "ethers"; -import * as TOML from "smol-toml"; - -const mnemonic = "test test test test test test test test test test test junk"; -const provider = new ethers.JsonRpcProvider("http://localhost:8545"); +import { expect } from '@esm-bundle/chai'; +import { TEST_LOG_LEVEL } from '../../environment.js'; +import { Logger } from 'tslog'; +import { initializeResolver } from '@noir-lang/source-resolver'; +import newCompiler, { compile, init_log_level as compilerLogLevel } from '@noir-lang/noir_wasm'; +import { acvm, abi } from '@noir-lang/noir_js'; +import { Barretenberg, RawBuffer, Crs } from '@aztec/bb.js'; +import { decompressSync as gunzip } from 'fflate'; +import { ethers } from 'ethers'; +import * as TOML from 'smol-toml'; + +const mnemonic = 'test test test test test test test test test test test junk'; +const provider = new ethers.JsonRpcProvider('http://localhost:8545'); const walletMnemonic = ethers.Wallet.fromPhrase(mnemonic); const wallet = walletMnemonic.connect(provider); -const logger = new Logger({ name: "test", minLevel: TEST_LOG_LEVEL }); +const logger = new Logger({ name: 'test', minLevel: TEST_LOG_LEVEL }); const { default: initACVM, executeCircuit, compressWitness } = acvm; const { default: newABICoder, abiEncode } = abi; @@ -27,12 +24,12 @@ await newCompiler(); await newABICoder(); await initACVM(); -compilerLogLevel("INFO"); +compilerLogLevel('INFO'); async function getFile(url: URL): Promise { const response = await fetch(url); - if (!response.ok) throw new Error("Network response was not OK"); + if (!response.ok) throw new Error('Network response was not OK'); return await response.text(); } @@ -42,178 +39,138 @@ const FIELD_ELEMENT_BYTES = 32; const test_cases = [ { - case: "tooling/nargo_cli/tests/execution_success/1_mul", - compiled: "foundry-project/out/1_mul.sol/UltraVerifier.json", - deployInformation: "foundry-project/mul_output.json", + case: 'tooling/nargo_cli/tests/execution_success/1_mul', + compiled: 'foundry-project/out/1_mul.sol/UltraVerifier.json', + deployInformation: 'foundry-project/mul_output.json', numPublicInputs: 0, }, { - case: "compiler/integration-tests/test/circuits/main", - compiled: "foundry-project/out/main.sol/UltraVerifier.json", - deployInformation: "foundry-project/main_output.json", + case: 'compiler/integration-tests/test/circuits/main', + compiled: 'foundry-project/out/main.sol/UltraVerifier.json', + deployInformation: 'foundry-project/main_output.json', numPublicInputs: 1, }, ]; const numberOfThreads = navigator.hardwareConcurrency || 1; -const suite = Mocha.Suite.create(mocha.suite, "Noir end to end test"); +const suite = Mocha.Suite.create(mocha.suite, 'Noir end to end test'); suite.timeout(60 * 20e3); //20mins test_cases.forEach((testInfo) => { - const test_name = testInfo.case.split("/").pop(); + const test_name = testInfo.case.split('/').pop(); const caseLogger = logger.getSubLogger({ prefix: [test_name], }); - const mochaTest = new Mocha.Test( - `${test_name} (Compile, Execute, Prove, Verify)`, - async () => { - const base_relative_path = "../../../../.."; - const test_case = testInfo.case; - - const noir_source_url = new URL( - `${base_relative_path}/${test_case}/src/main.nr`, - import.meta.url, - ); - const prover_toml_url = new URL( - `${base_relative_path}/${test_case}/Prover.toml`, - import.meta.url, - ); - const compiled_contract_url = new URL( - `${base_relative_path}/${testInfo.compiled}`, - import.meta.url, - ); - const deploy_information_url = new URL( - `${base_relative_path}/${testInfo.deployInformation}`, - import.meta.url, - ); - - const noir_source = await getFile(noir_source_url); - const prover_toml = await getFile(prover_toml_url); - const compiled_contract = await getFile(compiled_contract_url); - const deploy_information = await getFile(deploy_information_url); - - const { abi } = JSON.parse(compiled_contract); - const { deployedTo } = JSON.parse(deploy_information); - - const contract = new ethers.Contract(deployedTo, abi, wallet); - - expect(noir_source).to.be.a.string; - - initializeResolver((id: string) => { - caseLogger.debug("source-resolver: resolving:", id); - return noir_source; + const mochaTest = new Mocha.Test(`${test_name} (Compile, Execute, Prove, Verify)`, async () => { + const base_relative_path = '../../../../..'; + const test_case = testInfo.case; + + const noir_source_url = new URL(`${base_relative_path}/${test_case}/src/main.nr`, import.meta.url); + const prover_toml_url = new URL(`${base_relative_path}/${test_case}/Prover.toml`, import.meta.url); + const compiled_contract_url = new URL(`${base_relative_path}/${testInfo.compiled}`, import.meta.url); + const deploy_information_url = new URL(`${base_relative_path}/${testInfo.deployInformation}`, import.meta.url); + + const noir_source = await getFile(noir_source_url); + const prover_toml = await getFile(prover_toml_url); + const compiled_contract = await getFile(compiled_contract_url); + const deploy_information = await getFile(deploy_information_url); + + const { abi } = JSON.parse(compiled_contract); + const { deployedTo } = JSON.parse(deploy_information); + + const contract = new ethers.Contract(deployedTo, abi, wallet); + + expect(noir_source).to.be.a.string; + + initializeResolver((id: string) => { + caseLogger.debug('source-resolver: resolving:', id); + return noir_source; + }); + + const inputs = TOML.parse(prover_toml); + + expect(inputs, 'Prover.toml').to.be.an('object'); + + let compile_output; + + try { + compile_output = await compile({}); + + expect(await compile_output, 'Compile output ').to.be.an('object'); + } catch (e) { + expect(e, 'Compilation Step').to.not.be.an('error'); + throw e; + } + + let witnessMap: WitnessMap; + try { + witnessMap = abiEncode(compile_output.abi, inputs, null); + } catch (e) { + expect(e, 'Abi Encoding Step').to.not.be.an('error'); + throw e; + } + + let solvedWitness: WitnessMap; + let compressedByteCode; + try { + compressedByteCode = Uint8Array.from(atob(compile_output.circuit), (c) => c.charCodeAt(0)); + + solvedWitness = await executeCircuit(compressedByteCode, witnessMap, () => { + throw Error('unexpected oracle'); }); + } catch (e) { + expect(e, 'Abi Encoding Step').to.not.be.an('error'); + throw e; + } - const inputs = TOML.parse(prover_toml); + try { + const compressedWitness = compressWitness(solvedWitness); + const acirUint8Array = gunzip(compressedByteCode); + const witnessUint8Array = gunzip(compressedWitness); - expect(inputs, "Prover.toml").to.be.an("object"); + const isRecursive = false; + const api = await Barretenberg.new(numberOfThreads); + await api.commonInitSlabAllocator(CIRCUIT_SIZE); - let compile_output; + // Plus 1 needed! + const crs = await Crs.new(CIRCUIT_SIZE + 1); + await api.srsInitSrs(new RawBuffer(crs.getG1Data()), crs.numPoints, new RawBuffer(crs.getG2Data())); - try { - compile_output = await compile({}); + const acirComposer = await api.acirNewAcirComposer(CIRCUIT_SIZE); - expect(await compile_output, "Compile output ").to.be.an("object"); - } catch (e) { - expect(e, "Compilation Step").to.not.be.an("error"); - throw e; - } + // This took ~6.5 minutes! + const proof = await api.acirCreateProof(acirComposer, acirUint8Array, witnessUint8Array, isRecursive); - let witnessMap: WitnessMap; - try { - witnessMap = abiEncode(compile_output.abi, inputs, null); - } catch (e) { - expect(e, "Abi Encoding Step").to.not.be.an("error"); - throw e; - } + // And this took ~5 minutes! + const verified = await api.acirVerifyProof(acirComposer, proof, isRecursive); - let solvedWitness: WitnessMap; - let compressedByteCode; - try { - compressedByteCode = Uint8Array.from( - atob(compile_output.circuit), - (c) => c.charCodeAt(0), - ); - - solvedWitness = await executeCircuit( - compressedByteCode, - witnessMap, - () => { - throw Error("unexpected oracle"); - }, - ); - } catch (e) { - expect(e, "Abi Encoding Step").to.not.be.an("error"); - throw e; - } + expect(verified, 'Proof fails verification in JS').to.be.true; try { - const compressedWitness = compressWitness(solvedWitness); - const acirUint8Array = gunzip(compressedByteCode); - const witnessUint8Array = gunzip(compressedWitness); - - const isRecursive = false; - const api = await Barretenberg.new(numberOfThreads); - await api.commonInitSlabAllocator(CIRCUIT_SIZE); - - // Plus 1 needed! - const crs = await Crs.new(CIRCUIT_SIZE + 1); - await api.srsInitSrs( - new RawBuffer(crs.getG1Data()), - crs.numPoints, - new RawBuffer(crs.getG2Data()), - ); - - const acirComposer = await api.acirNewAcirComposer(CIRCUIT_SIZE); - - // This took ~6.5 minutes! - const proof = await api.acirCreateProof( - acirComposer, - acirUint8Array, - witnessUint8Array, - isRecursive, - ); - - // And this took ~5 minutes! - const verified = await api.acirVerifyProof( - acirComposer, - proof, - isRecursive, - ); - - expect(verified, "Proof fails verification in JS").to.be.true; - - try { - let result; - if (testInfo.numPublicInputs === 0) { - result = await contract.verify(proof, []); - } else { - const publicInputs = Array.from( - { length: testInfo.numPublicInputs }, - (_, i) => { - const offset = i * FIELD_ELEMENT_BYTES; - return proof.slice(offset, offset + FIELD_ELEMENT_BYTES); - }, - ); - const slicedProof = proof.slice( - testInfo.numPublicInputs * FIELD_ELEMENT_BYTES, - ); - result = await contract.verify(slicedProof, publicInputs); - } - - expect(result).to.be.true; - } catch (error) { - console.error("Error while submitting the proof:", error); - throw error; + let result; + if (testInfo.numPublicInputs === 0) { + result = await contract.verify(proof, []); + } else { + const publicInputs = Array.from({ length: testInfo.numPublicInputs }, (_, i) => { + const offset = i * FIELD_ELEMENT_BYTES; + return proof.slice(offset, offset + FIELD_ELEMENT_BYTES); + }); + const slicedProof = proof.slice(testInfo.numPublicInputs * FIELD_ELEMENT_BYTES); + result = await contract.verify(slicedProof, publicInputs); } - } catch (e) { - expect(e, "Proving and Verifying").to.not.be.an("error"); - throw e; + + expect(result).to.be.true; + } catch (error) { + console.error('Error while submitting the proof:', error); + throw error; } - }, - ); + } catch (e) { + expect(e, 'Proving and Verifying').to.not.be.an('error'); + throw e; + } + }); suite.addTest(mochaTest); }); diff --git a/compiler/integration-tests/test/integration/browser/recursion.test.ts b/compiler/integration-tests/test/integration/browser/recursion.test.ts index 41c807f1ca0..88d9fe44099 100644 --- a/compiler/integration-tests/test/integration/browser/recursion.test.ts +++ b/compiler/integration-tests/test/integration/browser/recursion.test.ts @@ -1,21 +1,18 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ -import { expect } from "@esm-bundle/chai"; -import { TEST_LOG_LEVEL } from "../../environment.js"; -import { Logger } from "tslog"; -import { initializeResolver } from "@noir-lang/source-resolver"; -import newCompiler, { - compile, - init_log_level as compilerLogLevel, -} from "@noir-lang/noir_wasm"; -import { decompressSync as gunzip } from "fflate"; -import { acvm, abi, generateWitness } from "@noir-lang/noir_js"; +import { expect } from '@esm-bundle/chai'; +import { TEST_LOG_LEVEL } from '../../environment.js'; +import { Logger } from 'tslog'; +import { initializeResolver } from '@noir-lang/source-resolver'; +import newCompiler, { compile, init_log_level as compilerLogLevel } from '@noir-lang/noir_wasm'; +import { decompressSync as gunzip } from 'fflate'; +import { acvm, abi, generateWitness } from '@noir-lang/noir_js'; // @ts-ignore -import { Barretenberg, RawBuffer, Crs } from "@aztec/bb.js"; +import { Barretenberg, RawBuffer, Crs } from '@aztec/bb.js'; -import * as TOML from "smol-toml"; +import * as TOML from 'smol-toml'; -const logger = new Logger({ name: "test", minLevel: TEST_LOG_LEVEL }); +const logger = new Logger({ name: 'test', minLevel: TEST_LOG_LEVEL }); const { default: initACVM } = acvm; const { default: newABICoder } = abi; @@ -24,18 +21,18 @@ await newCompiler(); await newABICoder(); await initACVM(); -compilerLogLevel("INFO"); +compilerLogLevel('INFO'); const numberOfThreads = navigator.hardwareConcurrency || 1; -const base_relative_path = "../../../../.."; -const circuit_main = "compiler/integration-tests/test/circuits/main"; -const circuit_recursion = "compiler/integration-tests/test/circuits/recursion"; +const base_relative_path = '../../../../..'; +const circuit_main = 'compiler/integration-tests/test/circuits/main'; +const circuit_recursion = 'compiler/integration-tests/test/circuits/recursion'; async function getFile(url: URL): Promise { const response = await fetch(url); - if (!response.ok) throw new Error("Network response was not OK"); + if (!response.ok) throw new Error('Network response was not OK'); return await response.text(); } @@ -46,62 +43,39 @@ const api = await Barretenberg.new(numberOfThreads); await api.commonInitSlabAllocator(CIRCUIT_SIZE); // Plus 1 needed! const crs = await Crs.new(CIRCUIT_SIZE + 1); -await api.srsInitSrs( - new RawBuffer(crs.getG1Data()), - crs.numPoints, - new RawBuffer(crs.getG2Data()), -); +await api.srsInitSrs(new RawBuffer(crs.getG1Data()), crs.numPoints, new RawBuffer(crs.getG2Data())); const acirComposer = await api.acirNewAcirComposer(CIRCUIT_SIZE); async function getCircuit(noirSource: string) { // eslint-disable-next-line @typescript-eslint/no-unused-vars initializeResolver((id: string) => { - logger.debug("source-resolver: resolving:", id); + logger.debug('source-resolver: resolving:', id); return noirSource; }); return compile({}); } -async function generateProof( - acirUint8Array: Uint8Array, - witnessUint8Array: Uint8Array, - optimizeForRecursion: boolean, -) { +async function generateProof(acirUint8Array: Uint8Array, witnessUint8Array: Uint8Array, optimizeForRecursion: boolean) { // This took ~6.5 minutes! - return api.acirCreateProof( - acirComposer, - acirUint8Array, - witnessUint8Array, - optimizeForRecursion, - ); + return api.acirCreateProof(acirComposer, acirUint8Array, witnessUint8Array, optimizeForRecursion); } async function verifyProof(proof: Uint8Array, optimizeForRecursion: boolean) { await api.acirInitVerificationKey(acirComposer); - const verified = await api.acirVerifyProof( - acirComposer, - proof, - optimizeForRecursion, - ); + const verified = await api.acirVerifyProof(acirComposer, proof, optimizeForRecursion); return verified; } -describe("It compiles noir program code, receiving circuit bytes and abi object.", () => { +describe('It compiles noir program code, receiving circuit bytes and abi object.', () => { let circuit_main_source; let circuit_main_toml; let circuit_recursion_source; before(async () => { - const circuit_main_source_url = new URL( - `${base_relative_path}/${circuit_main}/src/main.nr`, - import.meta.url, - ); - const circuit_main_toml_url = new URL( - `${base_relative_path}/${circuit_main}/Prover.toml`, - import.meta.url, - ); + const circuit_main_source_url = new URL(`${base_relative_path}/${circuit_main}/src/main.nr`, import.meta.url); + const circuit_main_toml_url = new URL(`${base_relative_path}/${circuit_main}/Prover.toml`, import.meta.url); circuit_main_source = await getFile(circuit_main_source_url); circuit_main_toml = await getFile(circuit_main_toml_url); @@ -114,9 +88,8 @@ describe("It compiles noir program code, receiving circuit bytes and abi object. circuit_recursion_source = await getFile(circuit_recursion_source_url); }); - it("Should generate valid inner proof for correct input, then verify proof within a proof", async () => { - const { circuit: main_circuit, abi: main_abi } = - await getCircuit(circuit_main_source); + it('Should generate valid inner proof for correct input, then verify proof within a proof', async () => { + const { circuit: main_circuit, abi: main_abi } = await getCircuit(circuit_main_source); const main_inputs = TOML.parse(circuit_main_toml); const main_witnessUint8Array = await generateWitness( @@ -126,36 +99,23 @@ describe("It compiles noir program code, receiving circuit bytes and abi object. }, main_inputs, ); - const main_compressedByteCode = Uint8Array.from(atob(main_circuit), (c) => - c.charCodeAt(0), - ); + const main_compressedByteCode = Uint8Array.from(atob(main_circuit), (c) => c.charCodeAt(0)); const main_acirUint8Array = gunzip(main_compressedByteCode); const optimizeMainProofForRecursion = true; - const main_proof = await generateProof( - main_acirUint8Array, - main_witnessUint8Array, - optimizeMainProofForRecursion, - ); + const main_proof = await generateProof(main_acirUint8Array, main_witnessUint8Array, optimizeMainProofForRecursion); - const main_verification = await verifyProof( - main_proof, - optimizeMainProofForRecursion, - ); + const main_verification = await verifyProof(main_proof, optimizeMainProofForRecursion); - logger.debug("main_verification", main_verification); + logger.debug('main_verification', main_verification); expect(main_verification).to.be.true; const numPublicInputs = 1; - const proofAsFields = ( - await api.acirSerializeProofIntoFields( - acirComposer, - main_proof, - numPublicInputs, - ) - ).map((p) => p.toString()); + const proofAsFields = (await api.acirSerializeProofIntoFields(acirComposer, main_proof, numPublicInputs)).map((p) => + p.toString(), + ); const vk = await api.acirSerializeVerificationKeyIntoFields(acirComposer); @@ -167,15 +127,12 @@ describe("It compiles noir program code, receiving circuit bytes and abi object. proof: proofAsFields, public_inputs: [main_inputs.y], key_hash: vkHash, - // eslint-disable-next-line prettier/prettier - input_aggregation_object: ["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"], + input_aggregation_object: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'], }; - logger.debug("recursion_inputs", recursion_inputs); + logger.debug('recursion_inputs', recursion_inputs); - const { circuit: recursion_circuit, abi: recursion_abi } = await getCircuit( - circuit_recursion_source, - ); + const { circuit: recursion_circuit, abi: recursion_abi } = await getCircuit(circuit_recursion_source); const recursion_witnessUint8Array = await generateWitness( { @@ -185,10 +142,7 @@ describe("It compiles noir program code, receiving circuit bytes and abi object. recursion_inputs, ); - const recursion_compressedByteCode = Uint8Array.from( - atob(recursion_circuit), - (c) => c.charCodeAt(0), - ); + const recursion_compressedByteCode = Uint8Array.from(atob(recursion_circuit), (c) => c.charCodeAt(0)); const recursion_acirUint8Array = gunzip(recursion_compressedByteCode); @@ -203,18 +157,14 @@ describe("It compiles noir program code, receiving circuit bytes and abi object. const recursion_numPublicInputs = 1; const recursion_proofAsFields = ( - await api.acirSerializeProofIntoFields( - acirComposer, - recursion_proof, - recursion_numPublicInputs, - ) + await api.acirSerializeProofIntoFields(acirComposer, recursion_proof, recursion_numPublicInputs) ).map((p) => p.toString()); - logger.debug("recursion_proofAsFields", recursion_proofAsFields); + logger.debug('recursion_proofAsFields', recursion_proofAsFields); const recursion_verification = await verifyProof(recursion_proof, false); - logger.debug("recursion_verification", recursion_verification); + logger.debug('recursion_verification', recursion_verification); expect(recursion_verification).to.be.true; }).timeout(60 * 20e3); diff --git a/compiler/source-resolver/src/index.ts b/compiler/source-resolver/src/index.ts index 66ff1e947aa..3498c195fbd 100644 --- a/compiler/source-resolver/src/index.ts +++ b/compiler/source-resolver/src/index.ts @@ -4,34 +4,28 @@ export const read_file = function (source_id: string): string { if (resolveFunction) { const result = resolveFunction(source_id); - if (typeof result === "string") { + if (typeof result === 'string') { return result; } else { throw new Error( - "Noir source resolver function MUST return String synchronously. Are you trying to return anything else, eg. `Promise`?", + 'Noir source resolver function MUST return String synchronously. Are you trying to return anything else, eg. `Promise`?', ); } } else { - throw new Error( - "Not yet initialized. Use initializeResolver(() => string)", - ); + throw new Error('Not yet initialized. Use initializeResolver(() => string)'); } }; -function initialize( - noir_resolver: (source_id: string) => string, -): (source_id: string) => string { - if (typeof noir_resolver === "function") { +function initialize(noir_resolver: (source_id: string) => string): (source_id: string) => string { + if (typeof noir_resolver === 'function') { return noir_resolver; } else { throw new Error( - "Provided Noir Resolver is not a function, hint: use function(module_id) => NoirSource as second parameter", + 'Provided Noir Resolver is not a function, hint: use function(module_id) => NoirSource as second parameter', ); } } -export function initializeResolver( - resolver: (source_id: string) => string, -): void { +export function initializeResolver(resolver: (source_id: string) => string): void { resolveFunction = initialize(resolver); } diff --git a/compiler/source-resolver/src/index_node.ts b/compiler/source-resolver/src/index_node.ts index 016e118d044..14b7efd30c5 100644 --- a/compiler/source-resolver/src/index_node.ts +++ b/compiler/source-resolver/src/index_node.ts @@ -1,13 +1,13 @@ /// -import { initializeResolver, read_file } from "./index.js"; +import { initializeResolver, read_file } from './index.js'; initializeResolver((source_id: string) => { - let fileContent = ""; + let fileContent = ''; try { // eslint-disable-next-line @typescript-eslint/no-var-requires - const fs = require("fs"); - fileContent = fs.readFileSync(source_id, { encoding: "utf8" }) as string; + const fs = require('fs'); + fileContent = fs.readFileSync(source_id, { encoding: 'utf8' }) as string; } catch (e) { console.log(e); } diff --git a/compiler/source-resolver/types/index.d.ts b/compiler/source-resolver/types/index.d.ts index bf144c3928f..a17f7bc36bb 100644 --- a/compiler/source-resolver/types/index.d.ts +++ b/compiler/source-resolver/types/index.d.ts @@ -1,4 +1,2 @@ export declare const read_file: (source_id: string) => string; -export declare function initializeResolver( - resolver: (source_id: string) => string, -): void; +export declare function initializeResolver(resolver: (source_id: string) => string): void; diff --git a/compiler/source-resolver/types/index_node.d.ts b/compiler/source-resolver/types/index_node.d.ts index 2a645e138bb..3a109e47e73 100644 --- a/compiler/source-resolver/types/index_node.d.ts +++ b/compiler/source-resolver/types/index_node.d.ts @@ -1,2 +1,2 @@ -import { initializeResolver, read_file } from "./index.js"; +import { initializeResolver, read_file } from './index.js'; export { initializeResolver, read_file }; diff --git a/compiler/wasm/test/browser/index.test.ts b/compiler/wasm/test/browser/index.test.ts index 6f79a7ab60c..5b586344f80 100644 --- a/compiler/wasm/test/browser/index.test.ts +++ b/compiler/wasm/test/browser/index.test.ts @@ -1,10 +1,6 @@ -import { expect } from "@esm-bundle/chai"; -import initNoirWasm from "@noir-lang/noir_wasm"; -import { - compileNoirSource, - nargoArtifactPath, - noirSourcePath, -} from "../shared"; +import { expect } from '@esm-bundle/chai'; +import initNoirWasm from '@noir-lang/noir_wasm'; +import { compileNoirSource, nargoArtifactPath, noirSourcePath } from '../shared'; beforeEach(async () => { await initNoirWasm(); @@ -25,8 +21,8 @@ async function getPrecompiledSource(): Promise { return JSON.parse(compiledData).bytecode; } -describe("noir wasm compilation", () => { - it("matches nargos compilation", async () => { +describe('noir wasm compilation', () => { + it('matches nargos compilation', async () => { const source = await getSource(); const wasmCircuitBase64 = await compileNoirSource(source); diff --git a/compiler/wasm/test/index.d.ts b/compiler/wasm/test/index.d.ts index 35743f263cf..2b4401d3bc8 100644 --- a/compiler/wasm/test/index.d.ts +++ b/compiler/wasm/test/index.d.ts @@ -1 +1 @@ -declare module "@noir-lang/source-resolver"; +declare module '@noir-lang/source-resolver'; diff --git a/compiler/wasm/test/node/index.test.ts b/compiler/wasm/test/node/index.test.ts index f823db35944..9c4bb4439fa 100644 --- a/compiler/wasm/test/node/index.test.ts +++ b/compiler/wasm/test/node/index.test.ts @@ -1,11 +1,7 @@ -import { expect } from "chai"; -import { - compileNoirSource, - nargoArtifactPath, - noirSourcePath, -} from "../shared"; -import { readFileSync } from "node:fs"; -import { join } from "node:path"; +import { expect } from 'chai'; +import { compileNoirSource, nargoArtifactPath, noirSourcePath } from '../shared'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; async function getFileContent(path: string): Promise { return readFileSync(join(__dirname, path)).toString(); @@ -20,22 +16,19 @@ async function getPrecompiledSource(): Promise { return JSON.parse(compiledData).bytecode; } -describe("noir wasm compilation", () => { - it("matches nargos compilation", async () => { +describe('noir wasm compilation', () => { + it('matches nargos compilation', async () => { const source = await getSource(); const wasmCircuitBase64 = await compileNoirSource(source); const cliCircuitBase64 = await getPrecompiledSource(); - console.log("wasm", wasmCircuitBase64); + console.log('wasm', wasmCircuitBase64); - console.log("cli", cliCircuitBase64); + console.log('cli', cliCircuitBase64); - console.log( - "Compilation is a match? ", - wasmCircuitBase64 === cliCircuitBase64, - ); + console.log('Compilation is a match? ', wasmCircuitBase64 === cliCircuitBase64); expect(wasmCircuitBase64).to.equal(cliCircuitBase64); }).timeout(10e3); diff --git a/compiler/wasm/test/shared.ts b/compiler/wasm/test/shared.ts index 6e5ad5969f3..d1b7831befa 100644 --- a/compiler/wasm/test/shared.ts +++ b/compiler/wasm/test/shared.ts @@ -1,19 +1,18 @@ -import { initializeResolver } from "@noir-lang/source-resolver"; -import { compile } from "@noir-lang/noir_wasm"; +import { initializeResolver } from '@noir-lang/source-resolver'; +import { compile } from '@noir-lang/noir_wasm'; -export const noirSourcePath = "../../noir-script/src/main.nr"; -export const nargoArtifactPath = - "../../noir-script/target/noir_wasm_testing.json"; +export const noirSourcePath = '../../noir-script/src/main.nr'; +export const nargoArtifactPath = '../../noir-script/target/noir_wasm_testing.json'; export async function compileNoirSource(noir_source: string): Promise { - console.log("Compiling Noir source..."); + console.log('Compiling Noir source...'); initializeResolver((id: string) => { console.log(`Resolving source ${id}`); const source = noir_source; - if (typeof source === "undefined") { + if (typeof source === 'undefined') { throw Error(`Could not resolve source for '${id}'`); } else { return source; @@ -23,10 +22,10 @@ export async function compileNoirSource(noir_source: string): Promise { try { const compiled_noir = compile({}); - console.log("Noir source compilation done."); + console.log('Noir source compilation done.'); return compiled_noir.circuit; } catch (e) { - console.log("Error while compiling:", e); + console.log('Error while compiling:', e); } } diff --git a/tooling/noir_js/src/base64_decode.ts b/tooling/noir_js/src/base64_decode.ts index fddbc2640cb..d53aed187c7 100644 --- a/tooling/noir_js/src/base64_decode.ts +++ b/tooling/noir_js/src/base64_decode.ts @@ -1,13 +1,13 @@ // Since this is a simple function, we can use feature detection to // see if we are in the nodeJs environment or the browser environment. export function base64Decode(input: string): Uint8Array { - if (typeof Buffer !== "undefined") { + if (typeof Buffer !== 'undefined') { // Node.js environment - return Buffer.from(input, "base64"); - } else if (typeof atob === "function") { + return Buffer.from(input, 'base64'); + } else if (typeof atob === 'function') { // Browser environment return Uint8Array.from(atob(input), (c) => c.charCodeAt(0)); } else { - throw new Error("No implementation found for base64 decoding."); + throw new Error('No implementation found for base64 decoding.'); } } diff --git a/tooling/noir_js/src/index.ts b/tooling/noir_js/src/index.ts index 2d3801bf2c1..71914d59dbf 100644 --- a/tooling/noir_js/src/index.ts +++ b/tooling/noir_js/src/index.ts @@ -1,9 +1,9 @@ -import * as acvm from "@noir-lang/acvm_js"; -import * as abi from "@noir-lang/noirc_abi"; +import * as acvm from '@noir-lang/acvm_js'; +import * as abi from '@noir-lang/noirc_abi'; export { acvm, abi }; -export { generateWitness } from "./witness_generation.js"; -export { acirToUint8Array, witnessMapToUint8Array } from "./serialize.js"; +export { generateWitness } from './witness_generation.js'; +export { acirToUint8Array, witnessMapToUint8Array } from './serialize.js'; -export { Noir } from "./program.js"; +export { Noir } from './program.js'; diff --git a/tooling/noir_js/src/program.ts b/tooling/noir_js/src/program.ts index 1aea14644c9..0c129aa3a72 100644 --- a/tooling/noir_js/src/program.ts +++ b/tooling/noir_js/src/program.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { Backend, CompiledCircuit } from "@noir-lang/types"; -import { generateWitness } from "./witness_generation.js"; +import { Backend, CompiledCircuit } from '@noir-lang/types'; +import { generateWitness } from './witness_generation.js'; export class Noir { constructor( diff --git a/tooling/noir_js/src/serialize.ts b/tooling/noir_js/src/serialize.ts index 0193f465091..df01769c06e 100644 --- a/tooling/noir_js/src/serialize.ts +++ b/tooling/noir_js/src/serialize.ts @@ -1,6 +1,6 @@ -import { WitnessMap, compressWitness } from "@noir-lang/acvm_js"; -import { decompressSync as gunzip } from "fflate"; -import { base64Decode } from "./base64_decode.js"; +import { WitnessMap, compressWitness } from '@noir-lang/acvm_js'; +import { decompressSync as gunzip } from 'fflate'; +import { base64Decode } from './base64_decode.js'; // After solving the witness, to pass it a backend, we need to serialize it to a Uint8Array export function witnessMapToUint8Array(solvedWitness: WitnessMap): Uint8Array { diff --git a/tooling/noir_js/src/witness_generation.ts b/tooling/noir_js/src/witness_generation.ts index f3b31e0eb77..3b1dfd90109 100644 --- a/tooling/noir_js/src/witness_generation.ts +++ b/tooling/noir_js/src/witness_generation.ts @@ -1,27 +1,20 @@ -import { abiEncode } from "@noir-lang/noirc_abi"; -import { base64Decode } from "./base64_decode.js"; -import { executeCircuit } from "@noir-lang/acvm_js"; -import { witnessMapToUint8Array } from "./serialize.js"; -import { CompiledCircuit } from "@noir-lang/types"; +import { abiEncode } from '@noir-lang/noirc_abi'; +import { base64Decode } from './base64_decode.js'; +import { executeCircuit } from '@noir-lang/acvm_js'; +import { witnessMapToUint8Array } from './serialize.js'; +import { CompiledCircuit } from '@noir-lang/types'; // Generates the witnesses needed to feed into the chosen proving system -export async function generateWitness( - compiledProgram: CompiledCircuit, - inputs: unknown, -): Promise { +export async function generateWitness(compiledProgram: CompiledCircuit, inputs: unknown): Promise { // Throws on ABI encoding error const witnessMap = abiEncode(compiledProgram.abi, inputs, null); // Execute the circuit to generate the rest of the witnesses and serialize // them into a Uint8Array. try { - const solvedWitness = await executeCircuit( - base64Decode(compiledProgram.bytecode), - witnessMap, - () => { - throw Error("unexpected oracle during execution"); - }, - ); + const solvedWitness = await executeCircuit(base64Decode(compiledProgram.bytecode), witnessMap, () => { + throw Error('unexpected oracle during execution'); + }); return witnessMapToUint8Array(solvedWitness); } catch (err) { throw new Error(`Circuit execution failed: ${err}`); diff --git a/tooling/noir_js/test/node/e2e.test.ts b/tooling/noir_js/test/node/e2e.test.ts index 3d13119e422..1120f08c81b 100644 --- a/tooling/noir_js/test/node/e2e.test.ts +++ b/tooling/noir_js/test/node/e2e.test.ts @@ -1,14 +1,14 @@ -import { expect } from "chai"; -import assert_lt_json from "../noir_compiled_examples/assert_lt/target/assert_lt.json" assert { type: "json" }; -import { generateWitness } from "../../src/index.js"; -import { Noir } from "../../src/program.js"; -import { BarretenbergBackend as Backend } from "../backend/barretenberg.js"; +import { expect } from 'chai'; +import assert_lt_json from '../noir_compiled_examples/assert_lt/target/assert_lt.json' assert { type: 'json' }; +import { generateWitness } from '../../src/index.js'; +import { Noir } from '../../src/program.js'; +import { BarretenbergBackend as Backend } from '../backend/barretenberg.js'; -it("end-to-end proof creation and verification (outer)", async () => { +it('end-to-end proof creation and verification (outer)', async () => { // Noir.Js part const inputs = { - x: "2", - y: "3", + x: '2', + y: '3', }; const serializedWitness = await generateWitness(assert_lt_json, inputs); @@ -23,11 +23,11 @@ it("end-to-end proof creation and verification (outer)", async () => { expect(isValid).to.be.true; }); -it("end-to-end proof creation and verification (outer) -- Program API", async () => { +it('end-to-end proof creation and verification (outer) -- Program API', async () => { // Noir.Js part const inputs = { - x: "2", - y: "3", + x: '2', + y: '3', }; // Initialize backend @@ -42,11 +42,11 @@ it("end-to-end proof creation and verification (outer) -- Program API", async () expect(isValid).to.be.true; }); -it("end-to-end proof creation and verification (inner)", async () => { +it('end-to-end proof creation and verification (inner)', async () => { // Noir.Js part const inputs = { - x: "2", - y: "3", + x: '2', + y: '3', }; const serializedWitness = await generateWitness(assert_lt_json, inputs); @@ -73,11 +73,11 @@ it("end-to-end proof creation and verification (inner)", async () => { // a prover and verifier class to more accurately reflect what happens in production. // // If its not fixable, we can leave it in as documentation of this behavior. -it("[BUG] -- bb.js null function or function signature mismatch (different instance) ", async () => { +it('[BUG] -- bb.js null function or function signature mismatch (different instance) ', async () => { // Noir.Js part const inputs = { - x: "2", - y: "3", + x: '2', + y: '3', }; const serializedWitness = await generateWitness(assert_lt_json, inputs); @@ -90,13 +90,11 @@ it("[BUG] -- bb.js null function or function signature mismatch (different insta const verifier = await Backend.initialize(assert_lt_json); await verifier.verifyFinalProof(proof); expect.fail( - "bb.js currently returns a bug when we try to verify a proof with a different Barretenberg instance that created it.", + 'bb.js currently returns a bug when we try to verify a proof with a different Barretenberg instance that created it.', ); } catch (error) { const knownError = error as Error; - expect(knownError.message).to.contain( - "null function or function signature mismatch", - ); + expect(knownError.message).to.contain('null function or function signature mismatch'); } }); @@ -107,11 +105,11 @@ it("[BUG] -- bb.js null function or function signature mismatch (different insta // If we only create one type of proof, then this works as expected. // // If we do not create an inner proof, then this will work as expected. -it("[BUG] -- bb.js null function or function signature mismatch (outer-inner) ", async () => { +it('[BUG] -- bb.js null function or function signature mismatch (outer-inner) ', async () => { // Noir.Js part const inputs = { - x: "2", - y: "3", + x: '2', + y: '3', }; const serializedWitness = await generateWitness(assert_lt_json, inputs); @@ -133,13 +131,9 @@ it("[BUG] -- bb.js null function or function signature mismatch (outer-inner) ", // We can also try verifying an inner proof and it will fail. // const isValidInner = await prover.verifyInnerProof(_proofInner); // expect(isValidInner).to.be.true; - expect.fail( - "bb.js currently returns a bug when we try to verify an inner and outer proof with the same backend", - ); + expect.fail('bb.js currently returns a bug when we try to verify an inner and outer proof with the same backend'); } catch (error) { const knownError = error as Error; - expect(knownError.message).to.contain( - "null function or function signature mismatch", - ); + expect(knownError.message).to.contain('null function or function signature mismatch'); } }); diff --git a/tooling/noir_js/test/node/smoke.test.ts b/tooling/noir_js/test/node/smoke.test.ts index c78b297f4b2..4b0291c0f41 100644 --- a/tooling/noir_js/test/node/smoke.test.ts +++ b/tooling/noir_js/test/node/smoke.test.ts @@ -1,89 +1,73 @@ -import { expect } from "chai"; -import assert_lt_json from "../noir_compiled_examples/assert_lt/target/assert_lt.json" assert { type: "json" }; -import { generateWitness } from "../../src/index.js"; +import { expect } from 'chai'; +import assert_lt_json from '../noir_compiled_examples/assert_lt/target/assert_lt.json' assert { type: 'json' }; +import { generateWitness } from '../../src/index.js'; -it("generates witnesses successfully", async () => { +it('generates witnesses successfully', async () => { const inputs = { - x: "2", - y: "3", + x: '2', + y: '3', }; expect(() => generateWitness(assert_lt_json, inputs)).to.not.throw; }); -it("string input and number input are the same", async () => { +it('string input and number input are the same', async () => { const inputsString = { - x: "2", - y: "3", + x: '2', + y: '3', }; const inputsNumber = { x: 2, y: 3, }; - const solvedWitnessString = await generateWitness( - assert_lt_json, - inputsString, - ); - const solvedWitnessNumber = await generateWitness( - assert_lt_json, - inputsNumber, - ); + const solvedWitnessString = await generateWitness(assert_lt_json, inputsString); + const solvedWitnessNumber = await generateWitness(assert_lt_json, inputsNumber); expect(solvedWitnessString).to.deep.equal(solvedWitnessNumber); }); -it("string input and number input are the same", async () => { +it('string input and number input are the same', async () => { const inputsString = { - x: "2", - y: "3", + x: '2', + y: '3', }; const inputsNumber = { x: 2, y: 3, }; - const solvedWitnessString = await generateWitness( - assert_lt_json, - inputsString, - ); - const solvedWitnessNumber = await generateWitness( - assert_lt_json, - inputsNumber, - ); + const solvedWitnessString = await generateWitness(assert_lt_json, inputsString); + const solvedWitnessNumber = await generateWitness(assert_lt_json, inputsNumber); expect(solvedWitnessString).to.deep.equal(solvedWitnessNumber); }); -it("0x prefixed string input for inputs will throw", async () => { +it('0x prefixed string input for inputs will throw', async () => { const inputsHexPrefix = { - x: "0x2", - y: "0x3", + x: '0x2', + y: '0x3', }; try { await generateWitness(assert_lt_json, inputsHexPrefix); - expect.fail( - "Expected generatedWitness to throw, due to inputs being prefixed with 0x. Currently not supported", - ); + expect.fail('Expected generatedWitness to throw, due to inputs being prefixed with 0x. Currently not supported'); } catch (error) { // Successfully errored due to 0x not being supported. Update this test once/if we choose // to support 0x prefixed inputs. } }); -describe("input validation", () => { - it("x should be a uint64 not a string", async () => { +describe('input validation', () => { + it('x should be a uint64 not a string', async () => { const inputs = { - x: "foo", - y: "3", + x: 'foo', + y: '3', }; try { await generateWitness(assert_lt_json, inputs); - expect.fail( - "Expected generatedWitness to throw, due to x not being convertible to a uint64", - ); + expect.fail('Expected generatedWitness to throw, due to x not being convertible to a uint64'); } catch (error) { const knownError = error as Error; expect(knownError.message).to.equal( - "Expected witness values to be integers, provided value causes `invalid digit found in string` error", + 'Expected witness values to be integers, provided value causes `invalid digit found in string` error', ); } }); diff --git a/tooling/noirc_abi_wasm/test/browser/abi_encode.test.ts b/tooling/noirc_abi_wasm/test/browser/abi_encode.test.ts index 8cdf19c43a7..5e604aa5b66 100644 --- a/tooling/noirc_abi_wasm/test/browser/abi_encode.test.ts +++ b/tooling/noirc_abi_wasm/test/browser/abi_encode.test.ts @@ -1,27 +1,19 @@ -import { expect } from "@esm-bundle/chai"; -import initNoirAbi, { - abiEncode, - abiDecode, - WitnessMap, -} from "@noir-lang/noirc_abi"; -import { DecodedInputs } from "../types"; +import { expect } from '@esm-bundle/chai'; +import initNoirAbi, { abiEncode, abiDecode, WitnessMap } from '@noir-lang/noirc_abi'; +import { DecodedInputs } from '../types'; beforeEach(async () => { await initNoirAbi(); }); -it("recovers original inputs when abi encoding and decoding", async () => { - const { abi, inputs } = await import("../shared/abi_encode"); +it('recovers original inputs when abi encoding and decoding', async () => { + const { abi, inputs } = await import('../shared/abi_encode'); const initial_witness: WitnessMap = abiEncode(abi, inputs, null); const decoded_inputs: DecodedInputs = abiDecode(abi, initial_witness); expect(BigInt(decoded_inputs.inputs.foo)).to.be.equal(BigInt(inputs.foo)); - expect(BigInt(decoded_inputs.inputs.bar[0])).to.be.equal( - BigInt(inputs.bar[0]), - ); - expect(BigInt(decoded_inputs.inputs.bar[1])).to.be.equal( - BigInt(inputs.bar[1]), - ); + expect(BigInt(decoded_inputs.inputs.bar[0])).to.be.equal(BigInt(inputs.bar[0])); + expect(BigInt(decoded_inputs.inputs.bar[1])).to.be.equal(BigInt(inputs.bar[1])); expect(decoded_inputs.return_value).to.be.null; }); diff --git a/tooling/noirc_abi_wasm/test/browser/errors.test.ts b/tooling/noirc_abi_wasm/test/browser/errors.test.ts index 6cfb3d6b192..5f9b40a195c 100644 --- a/tooling/noirc_abi_wasm/test/browser/errors.test.ts +++ b/tooling/noirc_abi_wasm/test/browser/errors.test.ts @@ -1,30 +1,26 @@ -import { expect } from "@esm-bundle/chai"; -import initNoirAbi, { abiEncode } from "@noir-lang/noirc_abi"; +import { expect } from '@esm-bundle/chai'; +import initNoirAbi, { abiEncode } from '@noir-lang/noirc_abi'; beforeEach(async () => { await initNoirAbi(); }); -it("errors when an integer input overflows", async () => { - const { abi, inputs } = await import("../shared/uint_overflow"); +it('errors when an integer input overflows', async () => { + const { abi, inputs } = await import('../shared/uint_overflow'); expect(() => abiEncode(abi, inputs, null)).to.throw( - "The parameter foo is expected to be a Integer { sign: Unsigned, width: 32 } but found incompatible value Field(2³⁸)", + 'The parameter foo is expected to be a Integer { sign: Unsigned, width: 32 } but found incompatible value Field(2³⁸)', ); }); -it("errors when passing a field in place of an array", async () => { - const { abi, inputs } = await import("../shared/field_as_array"); +it('errors when passing a field in place of an array', async () => { + const { abi, inputs } = await import('../shared/field_as_array'); - expect(() => abiEncode(abi, inputs, null)).to.throw( - "cannot parse value into Array { length: 2, typ: Field }", - ); + expect(() => abiEncode(abi, inputs, null)).to.throw('cannot parse value into Array { length: 2, typ: Field }'); }); -it("errors when passing an array in place of a field", async () => { - const { abi, inputs } = await import("../shared/array_as_field"); +it('errors when passing an array in place of a field', async () => { + const { abi, inputs } = await import('../shared/array_as_field'); - expect(() => abiEncode(abi, inputs, null)).to.throw( - "cannot parse value into Field", - ); + expect(() => abiEncode(abi, inputs, null)).to.throw('cannot parse value into Field'); }); diff --git a/tooling/noirc_abi_wasm/test/node/abi_encode.test.ts b/tooling/noirc_abi_wasm/test/node/abi_encode.test.ts index b84d84fdd77..830e45cf10b 100644 --- a/tooling/noirc_abi_wasm/test/node/abi_encode.test.ts +++ b/tooling/noirc_abi_wasm/test/node/abi_encode.test.ts @@ -1,19 +1,15 @@ -import { expect } from "chai"; -import { abiEncode, abiDecode, WitnessMap } from "@noir-lang/noirc_abi"; -import { DecodedInputs } from "../types"; +import { expect } from 'chai'; +import { abiEncode, abiDecode, WitnessMap } from '@noir-lang/noirc_abi'; +import { DecodedInputs } from '../types'; -it("recovers original inputs when abi encoding and decoding", async () => { - const { abi, inputs } = await import("../shared/abi_encode"); +it('recovers original inputs when abi encoding and decoding', async () => { + const { abi, inputs } = await import('../shared/abi_encode'); const initial_witness: WitnessMap = abiEncode(abi, inputs, null); const decoded_inputs: DecodedInputs = abiDecode(abi, initial_witness); expect(BigInt(decoded_inputs.inputs.foo)).to.be.equal(BigInt(inputs.foo)); - expect(BigInt(decoded_inputs.inputs.bar[0])).to.be.equal( - BigInt(inputs.bar[0]), - ); - expect(BigInt(decoded_inputs.inputs.bar[1])).to.be.equal( - BigInt(inputs.bar[1]), - ); + expect(BigInt(decoded_inputs.inputs.bar[0])).to.be.equal(BigInt(inputs.bar[0])); + expect(BigInt(decoded_inputs.inputs.bar[1])).to.be.equal(BigInt(inputs.bar[1])); expect(decoded_inputs.return_value).to.be.null; }); diff --git a/tooling/noirc_abi_wasm/test/node/errors.test.ts b/tooling/noirc_abi_wasm/test/node/errors.test.ts index a1bda73763f..ee0670ab5be 100644 --- a/tooling/noirc_abi_wasm/test/node/errors.test.ts +++ b/tooling/noirc_abi_wasm/test/node/errors.test.ts @@ -1,26 +1,22 @@ -import { expect } from "chai"; -import { abiEncode } from "@noir-lang/noirc_abi"; +import { expect } from 'chai'; +import { abiEncode } from '@noir-lang/noirc_abi'; -it("errors when an integer input overflows", async () => { - const { abi, inputs } = await import("../shared/uint_overflow"); +it('errors when an integer input overflows', async () => { + const { abi, inputs } = await import('../shared/uint_overflow'); expect(() => abiEncode(abi, inputs, null)).to.throw( - "The parameter foo is expected to be a Integer { sign: Unsigned, width: 32 } but found incompatible value Field(2³⁸)", + 'The parameter foo is expected to be a Integer { sign: Unsigned, width: 32 } but found incompatible value Field(2³⁸)', ); }); -it("errors when passing a field in place of an array", async () => { - const { abi, inputs } = await import("../shared/field_as_array"); +it('errors when passing a field in place of an array', async () => { + const { abi, inputs } = await import('../shared/field_as_array'); - expect(() => abiEncode(abi, inputs, null)).to.throw( - "cannot parse value into Array { length: 2, typ: Field }", - ); + expect(() => abiEncode(abi, inputs, null)).to.throw('cannot parse value into Array { length: 2, typ: Field }'); }); -it("errors when passing an array in place of a field", async () => { - const { abi, inputs } = await import("../shared/array_as_field"); +it('errors when passing an array in place of a field', async () => { + const { abi, inputs } = await import('../shared/array_as_field'); - expect(() => abiEncode(abi, inputs, null)).to.throw( - "cannot parse value into Field", - ); + expect(() => abiEncode(abi, inputs, null)).to.throw('cannot parse value into Field'); }); diff --git a/tooling/noirc_abi_wasm/test/shared/abi_encode.ts b/tooling/noirc_abi_wasm/test/shared/abi_encode.ts index 9664f4e5a45..0f9c93a4f76 100644 --- a/tooling/noirc_abi_wasm/test/shared/abi_encode.ts +++ b/tooling/noirc_abi_wasm/test/shared/abi_encode.ts @@ -2,11 +2,11 @@ export const abi = { parameters: [ - { name: "foo", type: { kind: "field" }, visibility: "private" }, + { name: 'foo', type: { kind: 'field' }, visibility: 'private' }, { - name: "bar", - type: { kind: "array", length: 2, type: { kind: "field" } }, - visibility: "private", + name: 'bar', + type: { kind: 'array', length: 2, type: { kind: 'field' } }, + visibility: 'private', }, ], param_witnesses: { foo: [1], bar: [2, 3] }, @@ -15,6 +15,6 @@ export const abi = { }; export const inputs = { - foo: "1", - bar: ["1", "2"], + foo: '1', + bar: ['1', '2'], }; diff --git a/tooling/noirc_abi_wasm/test/shared/array_as_field.ts b/tooling/noirc_abi_wasm/test/shared/array_as_field.ts index ff62ec75259..06e6a7beebf 100644 --- a/tooling/noirc_abi_wasm/test/shared/array_as_field.ts +++ b/tooling/noirc_abi_wasm/test/shared/array_as_field.ts @@ -1,9 +1,9 @@ export const abi = { parameters: [ { - name: "foo", - type: { kind: "field" }, - visibility: "private", + name: 'foo', + type: { kind: 'field' }, + visibility: 'private', }, ], param_witnesses: { foo: [1, 2] }, @@ -12,5 +12,5 @@ export const abi = { }; export const inputs = { - foo: ["1", "2"], + foo: ['1', '2'], }; diff --git a/tooling/noirc_abi_wasm/test/shared/field_as_array.ts b/tooling/noirc_abi_wasm/test/shared/field_as_array.ts index c669154962a..89ae529d6b1 100644 --- a/tooling/noirc_abi_wasm/test/shared/field_as_array.ts +++ b/tooling/noirc_abi_wasm/test/shared/field_as_array.ts @@ -1,9 +1,9 @@ export const abi = { parameters: [ { - name: "foo", - type: { kind: "array", length: 2, type: { kind: "field" } }, - visibility: "private", + name: 'foo', + type: { kind: 'array', length: 2, type: { kind: 'field' } }, + visibility: 'private', }, ], param_witnesses: { foo: [1, 2] }, @@ -12,5 +12,5 @@ export const abi = { }; export const inputs = { - foo: "1", + foo: '1', }; diff --git a/tooling/noirc_abi_wasm/test/shared/uint_overflow.ts b/tooling/noirc_abi_wasm/test/shared/uint_overflow.ts index 97bfe79e926..87f59b1440e 100644 --- a/tooling/noirc_abi_wasm/test/shared/uint_overflow.ts +++ b/tooling/noirc_abi_wasm/test/shared/uint_overflow.ts @@ -1,9 +1,9 @@ export const abi = { parameters: [ { - name: "foo", - type: { kind: "integer", sign: "unsigned", width: 32 }, - visibility: "private", + name: 'foo', + type: { kind: 'integer', sign: 'unsigned', width: 32 }, + visibility: 'private', }, ], param_witnesses: { foo: [1] },