Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: generateWitness now returns a serialized witness file #2842

Merged
merged 4 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tooling/noir_js/src/witness_generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<WitnessMap> {
Expand All @@ -12,12 +13,13 @@ export async function generateWitness(compiledProgram, inputs): Promise<WitnessM
}
const witnessMap = abiEncode(compiledProgram.abi, inputs, null);

// Execute the circuit to generate the rest of the witnesses
// 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');
});
return solvedWitness;
return witnessMapToUint8Array(solvedWitness);
} catch (err) {
throw new Error(`Circuit execution failed: ${err}`);
}
Expand Down
14 changes: 5 additions & 9 deletions tooling/noir_js/test/node/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -98,15 +95,14 @@ 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
//
// Proof creation
//
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);
Expand Down
Loading