Skip to content

Commit 57d3f37

Browse files
authored
chore!: generateWitness now returns a serialized witness file (#2842)
1 parent 76ab555 commit 57d3f37

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

tooling/noir_js/src/witness_generation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { abiEncode } from '@noir-lang/noirc_abi';
22
import { validateInputs } from './input_validation.js';
33
import { base64Decode } from './base64_decode.js';
44
import { WitnessMap, executeCircuit } from '@noir-lang/acvm_js';
5+
import { witnessMapToUint8Array } from './serialize.js';
56

67
// Generates the witnesses needed to feed into the chosen proving system
78
export async function generateWitness(compiledProgram, inputs): Promise<WitnessMap> {
@@ -12,12 +13,13 @@ export async function generateWitness(compiledProgram, inputs): Promise<WitnessM
1213
}
1314
const witnessMap = abiEncode(compiledProgram.abi, inputs, null);
1415

15-
// Execute the circuit to generate the rest of the witnesses
16+
// Execute the circuit to generate the rest of the witnesses and serialize
17+
// them into a Uint8Array.
1618
try {
1719
const solvedWitness = await executeCircuit(base64Decode(compiledProgram.bytecode), witnessMap, () => {
1820
throw Error('unexpected oracle during execution');
1921
});
20-
return solvedWitness;
22+
return witnessMapToUint8Array(solvedWitness);
2123
} catch (err) {
2224
throw new Error(`Circuit execution failed: ${err}`);
2325
}

tooling/noir_js/test/node/e2e.test.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai';
22
import assert_lt_json from '../noir_compiled_examples/assert_lt/target/assert_lt.json' assert { type: 'json' };
3-
import { generateWitness, witnessMapToUint8Array } from '../../src/index.js';
3+
import { generateWitness } from '../../src/index.js';
44
import { Backend } from '../backend/barretenberg.js';
55

66
it('end-to-end proof creation and verification (outer)', async () => {
@@ -9,14 +9,13 @@ it('end-to-end proof creation and verification (outer)', async () => {
99
x: '2',
1010
y: '3',
1111
};
12-
const solvedWitness = await generateWitness(assert_lt_json, inputs);
12+
const serializedWitness = await generateWitness(assert_lt_json, inputs);
1313

1414
// bb.js part
1515
//
1616
// Proof creation
1717
const prover = new Backend(assert_lt_json.bytecode);
1818
await prover.init();
19-
const serializedWitness = witnessMapToUint8Array(solvedWitness);
2019
const proof = await prover.generateOuterProof(serializedWitness);
2120

2221
// Proof verification
@@ -30,14 +29,13 @@ it('end-to-end proof creation and verification (inner)', async () => {
3029
x: '2',
3130
y: '3',
3231
};
33-
const solvedWitness = await generateWitness(assert_lt_json, inputs);
32+
const serializedWitness = await generateWitness(assert_lt_json, inputs);
3433

3534
// bb.js part
3635
//
3736
// Proof creation
3837
const prover = new Backend(assert_lt_json.bytecode);
3938
await prover.init();
40-
const serializedWitness = witnessMapToUint8Array(solvedWitness);
4139
const proof = await prover.generateInnerProof(serializedWitness);
4240

4341
// Proof verification
@@ -63,13 +61,12 @@ it('[BUG] -- bb.js null function or function signature mismatch (different insta
6361
x: '2',
6462
y: '3',
6563
};
66-
const solvedWitness = await generateWitness(assert_lt_json, inputs);
64+
const serializedWitness = await generateWitness(assert_lt_json, inputs);
6765

6866
// bb.js part
6967
const prover = new Backend(assert_lt_json.bytecode);
7068
await prover.init();
7169

72-
const serializedWitness = witnessMapToUint8Array(solvedWitness);
7370
const proof = await prover.generateOuterProof(serializedWitness);
7471

7572
try {
@@ -98,15 +95,14 @@ it('[BUG] -- bb.js null function or function signature mismatch (outer-inner) ',
9895
x: '2',
9996
y: '3',
10097
};
101-
const solvedWitness = await generateWitness(assert_lt_json, inputs);
98+
const serializedWitness = await generateWitness(assert_lt_json, inputs);
10299

103100
// bb.js part
104101
//
105102
// Proof creation
106103
//
107104
const prover = new Backend(assert_lt_json.bytecode);
108105
await prover.init();
109-
const serializedWitness = witnessMapToUint8Array(solvedWitness);
110106
// Create a proof using both proving systems, the majority of the time
111107
// one would only use outer proofs.
112108
const proofOuter = await prover.generateOuterProof(serializedWitness);

0 commit comments

Comments
 (0)