From f5bbb4a895b0f778f142f004199ab37416197e93 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Tue, 26 Sep 2023 10:23:09 +0000 Subject: [PATCH 1/3] execute and serialize witness --- tooling/noir_js/src/witness_generation.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tooling/noir_js/src/witness_generation.ts b/tooling/noir_js/src/witness_generation.ts index d72033b275a..bce95ba0c5c 100644 --- a/tooling/noir_js/src/witness_generation.ts +++ b/tooling/noir_js/src/witness_generation.ts @@ -2,6 +2,7 @@ import { abiEncode } from '@noir-lang/noirc_abi'; import { validateInputs } from './input_validation.js'; import { base64Decode } from './base64_decode.js'; import { WitnessMap, executeCircuit } from '@noir-lang/acvm_js'; +import { witnessMapToUint8Array } from './serialize.js'; // Generates the witnesses needed to feed into the chosen proving system export async function generateWitness(compiledProgram, inputs): Promise { @@ -12,12 +13,13 @@ export async function generateWitness(compiledProgram, inputs): Promise { throw Error('unexpected oracle during execution'); }); - return solvedWitness; + return witnessMapToUint8Array(solvedWitness); } catch (err) { throw new Error(`Circuit execution failed: ${err}`); } From 64bdf5db080a9e4f2bd987e116bebcaefeeb6d3f Mon Sep 17 00:00:00 2001 From: kevaundray Date: Tue, 26 Sep 2023 10:24:36 +0000 Subject: [PATCH 2/3] modify end-to-end tests --- tooling/noir_js/test/node/e2e.test.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tooling/noir_js/test/node/e2e.test.ts b/tooling/noir_js/test/node/e2e.test.ts index ddd91cca834..18413074871 100644 --- a/tooling/noir_js/test/node/e2e.test.ts +++ b/tooling/noir_js/test/node/e2e.test.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import assert_lt_json from '../noir_compiled_examples/assert_lt/target/assert_lt.json' assert { type: 'json' }; -import { generateWitness, witnessMapToUint8Array } from '../../src/index.js'; +import { generateWitness } from '../../src/index.js'; import { Backend } from '../backend/barretenberg.js'; it('end-to-end proof creation and verification (outer)', async () => { @@ -9,14 +9,13 @@ it('end-to-end proof creation and verification (outer)', async () => { x: '2', y: '3', }; - const solvedWitness = await generateWitness(assert_lt_json, inputs); + const serializedWitness = await generateWitness(assert_lt_json, inputs); // bb.js part // // Proof creation const prover = new Backend(assert_lt_json.bytecode); await prover.init(); - const serializedWitness = witnessMapToUint8Array(solvedWitness); const proof = await prover.generateOuterProof(serializedWitness); // Proof verification @@ -30,14 +29,13 @@ it('end-to-end proof creation and verification (inner)', async () => { x: '2', y: '3', }; - const solvedWitness = await generateWitness(assert_lt_json, inputs); + const serializedWitness = await generateWitness(assert_lt_json, inputs); // bb.js part // // Proof creation const prover = new Backend(assert_lt_json.bytecode); await prover.init(); - const serializedWitness = witnessMapToUint8Array(solvedWitness); const proof = await prover.generateInnerProof(serializedWitness); // Proof verification @@ -63,13 +61,12 @@ it('[BUG] -- bb.js null function or function signature mismatch (different insta x: '2', y: '3', }; - const solvedWitness = await generateWitness(assert_lt_json, inputs); + const serializedWitness = await generateWitness(assert_lt_json, inputs); // bb.js part const prover = new Backend(assert_lt_json.bytecode); await prover.init(); - const serializedWitness = witnessMapToUint8Array(solvedWitness); const proof = await prover.generateOuterProof(serializedWitness); try { @@ -98,7 +95,7 @@ it('[BUG] -- bb.js null function or function signature mismatch (outer-inner) ', x: '2', y: '3', }; - const solvedWitness = await generateWitness(assert_lt_json, inputs); + const serializedWitness = await generateWitness(assert_lt_json, inputs); // bb.js part // @@ -106,7 +103,6 @@ it('[BUG] -- bb.js null function or function signature mismatch (outer-inner) ', // const prover = new Backend(assert_lt_json.bytecode); await prover.init(); - const serializedWitness = witnessMapToUint8Array(solvedWitness); // Create a proof using both proving systems, the majority of the time // one would only use outer proofs. const proofOuter = await prover.generateOuterProof(serializedWitness); From 8430ef611b7a0c89b110fde023100ec5b6556513 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Tue, 26 Sep 2023 10:28:12 +0000 Subject: [PATCH 3/3] linting fix --- .../test/browser/execute_circuit.test.ts | 22 ++++++++--------- .../acvm_js/test/node/execute_circuit.test.ts | 24 +++++++++---------- .../acvm_js/test/shared/schnorr_verify.ts | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-) 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 407aa830c65..280b08abed3 100644 --- a/acvm-repo/acvm_js/test/browser/execute_circuit.test.ts +++ b/acvm-repo/acvm_js/test/browser/execute_circuit.test.ts @@ -24,7 +24,7 @@ it("successfully executes circuit and extracts return value", async () => { initialWitnessMap, () => { throw Error("unexpected oracle"); - } + }, ); // Solved witness should be consistent with initial witness @@ -50,7 +50,7 @@ it("successfully processes simple brillig foreign call opcodes", async () => { let observedInputs: string[][] = []; const foreignCallHandler: ForeignCallHandler = async ( name: string, - inputs: 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. @@ -63,7 +63,7 @@ it("successfully processes simple brillig foreign call opcodes", async () => { const solved_witness: WitnessMap = await executeCircuit( bytecode, initialWitnessMap, - foreignCallHandler + foreignCallHandler, ); // Check that expected values were passed to oracle callback. @@ -89,7 +89,7 @@ it("successfully processes complex brillig foreign call opcodes", async () => { let observedInputs: string[][] = []; const foreignCallHandler: ForeignCallHandler = async ( name: string, - inputs: 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. @@ -102,7 +102,7 @@ it("successfully processes complex brillig foreign call opcodes", async () => { const solved_witness: WitnessMap = await executeCircuit( bytecode, initialWitnessMap, - foreignCallHandler + foreignCallHandler, ); // Check that expected values were passed to oracle callback. @@ -124,7 +124,7 @@ it("successfully executes a Pedersen opcode", async function () { initialWitnessMap, () => { throw Error("unexpected oracle"); - } + }, ); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); @@ -140,7 +140,7 @@ it("successfully executes a FixedBaseScalarMul opcode", async () => { initialWitnessMap, () => { throw Error("unexpected oracle"); - } + }, ); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); @@ -156,7 +156,7 @@ it("successfully executes a SchnorrVerify opcode", async () => { initialWitnessMap, () => { throw Error("unexpected oracle"); - } + }, ); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); @@ -172,7 +172,7 @@ it("successfully executes a MemoryOp opcode", async () => { initialWitnessMap, () => { throw Error("unexpected oracle"); - } + }, ); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); @@ -194,7 +194,7 @@ it("successfully executes two circuits with same backend", async function () { initialWitnessMap, () => { throw Error("unexpected oracle"); - } + }, ); expect(solvedWitness0).to.be.deep.eq(expectedWitnessMap); @@ -205,7 +205,7 @@ it("successfully executes two circuits with same backend", async function () { initialWitnessMap, () => { throw Error("unexpected oracle"); - } + }, ); expect(solvedWitness1).to.be.deep.eq(expectedWitnessMap); }); 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 dac93b9f10c..0523d01b9ca 100644 --- a/acvm-repo/acvm_js/test/node/execute_circuit.test.ts +++ b/acvm-repo/acvm_js/test/node/execute_circuit.test.ts @@ -17,7 +17,7 @@ it("successfully executes circuit and extracts return value", async () => { initialWitnessMap, () => { throw Error("unexpected oracle"); - } + }, ); // Solved witness should be consistent with initial witness @@ -43,7 +43,7 @@ it("successfully processes simple brillig foreign call opcodes", async () => { let observedInputs: string[][] = []; const foreignCallHandler: ForeignCallHandler = async ( name: string, - inputs: 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. @@ -56,7 +56,7 @@ it("successfully processes simple brillig foreign call opcodes", async () => { const solved_witness: WitnessMap = await executeCircuit( bytecode, initialWitnessMap, - foreignCallHandler + foreignCallHandler, ); // Check that expected values were passed to oracle callback. @@ -82,7 +82,7 @@ it("successfully processes complex brillig foreign call opcodes", async () => { let observedInputs: string[][] = []; const foreignCallHandler: ForeignCallHandler = async ( name: string, - inputs: 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. @@ -95,7 +95,7 @@ it("successfully processes complex brillig foreign call opcodes", async () => { const solved_witness: WitnessMap = await executeCircuit( bytecode, initialWitnessMap, - foreignCallHandler + foreignCallHandler, ); // Check that expected values were passed to oracle callback. @@ -118,7 +118,7 @@ it("successfully executes a Pedersen opcode", async function () { initialWitnessMap, () => { throw Error("unexpected oracle"); - } + }, ); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); @@ -134,7 +134,7 @@ it("successfully executes a FixedBaseScalarMul opcode", async () => { initialWitnessMap, () => { throw Error("unexpected oracle"); - } + }, ); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); @@ -150,7 +150,7 @@ it("successfully executes a SchnorrVerify opcode", async () => { initialWitnessMap, () => { throw Error("unexpected oracle"); - } + }, ); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); @@ -166,7 +166,7 @@ it("successfully executes a MemoryOp opcode", async () => { initialWitnessMap, () => { throw Error("unexpected oracle"); - } + }, ); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); @@ -190,7 +190,7 @@ it("successfully executes two circuits with same backend", async function () { initialWitnessMap, () => { throw Error("unexpected oracle"); - } + }, ); const solvedWitness1 = await executeCircuitWithBlackBoxSolver( @@ -199,7 +199,7 @@ it("successfully executes two circuits with same backend", async function () { initialWitnessMap, () => { throw Error("unexpected oracle"); - } + }, ); expect(solvedWitness0).to.be.deep.eq(expectedWitnessMap); @@ -225,7 +225,7 @@ it("successfully executes 500 circuits with same backend", async function () { initialWitnessMap, () => { throw Error("unexpected oracle"); - } + }, ); expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); diff --git a/acvm-repo/acvm_js/test/shared/schnorr_verify.ts b/acvm-repo/acvm_js/test/shared/schnorr_verify.ts index fa91713474e..de9e61e757c 100644 --- a/acvm-repo/acvm_js/test/shared/schnorr_verify.ts +++ b/acvm-repo/acvm_js/test/shared/schnorr_verify.ts @@ -101,5 +101,5 @@ export const initialWitnessMap = new Map([ export const expectedWitnessMap = new Map(initialWitnessMap).set( 77, - "0x0000000000000000000000000000000000000000000000000000000000000001" + "0x0000000000000000000000000000000000000000000000000000000000000001", );