@aztec/bb-prover 0.66.0 → 0.67.1-devnet
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bb/cli.js +2 -2
- package/dest/bb/execute.d.ts +3 -3
- package/dest/bb/execute.d.ts.map +1 -1
- package/dest/bb/execute.js +3 -6
- package/dest/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation.js +2 -11
- package/dest/prover/bb_private_kernel_prover.d.ts +4 -13
- package/dest/prover/bb_private_kernel_prover.d.ts.map +1 -1
- package/dest/prover/bb_private_kernel_prover.js +7 -72
- package/dest/prover/bb_prover.d.ts +1 -1
- package/dest/prover/bb_prover.d.ts.map +1 -1
- package/dest/prover/bb_prover.js +10 -9
- package/dest/prover/client_ivc_proof_utils.d.ts +23 -0
- package/dest/prover/client_ivc_proof_utils.d.ts.map +1 -0
- package/dest/prover/client_ivc_proof_utils.js +35 -0
- package/dest/prover/index.d.ts +1 -0
- package/dest/prover/index.d.ts.map +1 -1
- package/dest/prover/index.js +2 -1
- package/dest/test/test_avm.d.ts +4 -0
- package/dest/test/test_avm.d.ts.map +1 -0
- package/dest/test/test_avm.js +33 -0
- package/dest/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +11 -6
- package/dest/verification_key/verification_key_data.js +4 -4
- package/dest/verifier/bb_verifier.d.ts +2 -1
- package/dest/verifier/bb_verifier.d.ts.map +1 -1
- package/dest/verifier/bb_verifier.js +6 -5
- package/dest/wasm/index.d.ts +19 -0
- package/dest/wasm/index.d.ts.map +1 -0
- package/dest/wasm/index.js +74 -0
- package/package.json +17 -9
- package/src/bb/cli.ts +1 -1
- package/src/bb/execute.ts +4 -7
- package/src/instrumentation.ts +0 -10
- package/src/prover/bb_private_kernel_prover.ts +11 -135
- package/src/prover/bb_prover.ts +9 -8
- package/src/prover/client_ivc_proof_utils.ts +39 -0
- package/src/prover/index.ts +1 -0
- package/src/test/test_avm.ts +85 -0
- package/src/test/test_circuit_prover.ts +12 -7
- package/src/verification_key/verification_key_data.ts +3 -3
- package/src/verifier/bb_verifier.ts +6 -5
- package/src/wasm/index.ts +155 -0
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
makeEmptyRecursiveProof,
|
|
36
36
|
makeRecursiveProof,
|
|
37
37
|
} from '@aztec/circuits.js';
|
|
38
|
-
import {
|
|
38
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
39
39
|
import { sleep } from '@aztec/foundation/sleep';
|
|
40
40
|
import { Timer } from '@aztec/foundation/timer';
|
|
41
41
|
import {
|
|
@@ -46,8 +46,6 @@ import {
|
|
|
46
46
|
convertBaseParityOutputsFromWitnessMap,
|
|
47
47
|
convertBlockMergeRollupInputsToWitnessMap,
|
|
48
48
|
convertBlockMergeRollupOutputsFromWitnessMap,
|
|
49
|
-
convertBlockRootRollupInputsToWitnessMap,
|
|
50
|
-
convertBlockRootRollupOutputsFromWitnessMap,
|
|
51
49
|
convertEmptyBlockRootRollupInputsToWitnessMap,
|
|
52
50
|
convertEmptyBlockRootRollupOutputsFromWitnessMap,
|
|
53
51
|
convertMergeRollupInputsToWitnessMap,
|
|
@@ -57,6 +55,8 @@ import {
|
|
|
57
55
|
convertRootParityOutputsFromWitnessMap,
|
|
58
56
|
convertRootRollupInputsToWitnessMap,
|
|
59
57
|
convertRootRollupOutputsFromWitnessMap,
|
|
58
|
+
convertSimulatedBlockRootRollupInputsToWitnessMap,
|
|
59
|
+
convertSimulatedBlockRootRollupOutputsFromWitnessMap,
|
|
60
60
|
convertSimulatedPrivateBaseRollupInputsToWitnessMap,
|
|
61
61
|
convertSimulatedPrivateBaseRollupOutputsFromWitnessMap,
|
|
62
62
|
convertSimulatedPrivateKernelEmptyOutputsFromWitnessMap,
|
|
@@ -78,7 +78,7 @@ import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
|
|
|
78
78
|
export class TestCircuitProver implements ServerCircuitProver {
|
|
79
79
|
private wasmSimulator = new WASMSimulator();
|
|
80
80
|
private instrumentation: ProverInstrumentation;
|
|
81
|
-
private logger =
|
|
81
|
+
private logger = createLogger('bb-prover:test-prover');
|
|
82
82
|
|
|
83
83
|
constructor(
|
|
84
84
|
telemetry: TelemetryClient,
|
|
@@ -215,8 +215,8 @@ export class TestCircuitProver implements ServerCircuitProver {
|
|
|
215
215
|
input,
|
|
216
216
|
'BlockRootRollupArtifact',
|
|
217
217
|
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
218
|
-
|
|
219
|
-
|
|
218
|
+
convertSimulatedBlockRootRollupInputsToWitnessMap,
|
|
219
|
+
convertSimulatedBlockRootRollupOutputsFromWitnessMap,
|
|
220
220
|
);
|
|
221
221
|
}
|
|
222
222
|
|
|
@@ -313,7 +313,12 @@ export class TestCircuitProver implements ServerCircuitProver {
|
|
|
313
313
|
const witnessMap = convertInput(input);
|
|
314
314
|
const circuitName = mapProtocolArtifactNameToCircuitName(artifactName);
|
|
315
315
|
|
|
316
|
-
|
|
316
|
+
let simulationProvider = this.simulationProvider ?? this.wasmSimulator;
|
|
317
|
+
if (artifactName == 'BlockRootRollupArtifact') {
|
|
318
|
+
// TODO(#10323): temporarily force block root to use wasm while we simulate
|
|
319
|
+
// the blob operations with an oracle. Appears to be no way to provide nativeACVM with a foreign call hander.
|
|
320
|
+
simulationProvider = this.wasmSimulator;
|
|
321
|
+
}
|
|
317
322
|
const witness = await simulationProvider.simulateCircuit(witnessMap, SimulatedServerCircuitArtifacts[artifactName]);
|
|
318
323
|
|
|
319
324
|
const result = convertOutput(witness);
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import { hashVK } from '@aztec/circuits.js/hash';
|
|
8
8
|
|
|
9
9
|
import { strict as assert } from 'assert';
|
|
10
|
-
import
|
|
10
|
+
import { promises as fs } from 'fs';
|
|
11
11
|
import * as path from 'path';
|
|
12
12
|
|
|
13
13
|
import { VK_FIELDS_FILENAME, VK_FILENAME } from '../bb/execute.js';
|
|
@@ -23,7 +23,7 @@ export async function extractVkData(vkDirectoryPath: string): Promise<Verificati
|
|
|
23
23
|
fs.readFile(path.join(vkDirectoryPath, VK_FILENAME)),
|
|
24
24
|
]);
|
|
25
25
|
const fieldsJson = JSON.parse(rawFields);
|
|
26
|
-
const fields = fieldsJson.map(Fr.
|
|
26
|
+
const fields = fieldsJson.map(Fr.fromHexString);
|
|
27
27
|
// The hash is not included in the BB response
|
|
28
28
|
const vkHash = hashVK(fields);
|
|
29
29
|
const vkAsFields = new VerificationKeyAsFields(fields, vkHash);
|
|
@@ -37,7 +37,7 @@ export async function extractAvmVkData(vkDirectoryPath: string): Promise<Verific
|
|
|
37
37
|
fs.readFile(path.join(vkDirectoryPath, VK_FILENAME)),
|
|
38
38
|
]);
|
|
39
39
|
const fieldsJson = JSON.parse(rawFields);
|
|
40
|
-
const fields = fieldsJson.map(Fr.
|
|
40
|
+
const fields = fieldsJson.map(Fr.fromHexString);
|
|
41
41
|
// The first item is the hash, this is not part of the actual VK
|
|
42
42
|
// TODO: is the above actually the case?
|
|
43
43
|
const vkHash = fields[0];
|
|
@@ -2,14 +2,14 @@ import { type ClientProtocolCircuitVerifier, Tx } from '@aztec/circuit-types';
|
|
|
2
2
|
import { type CircuitVerificationStats } from '@aztec/circuit-types/stats';
|
|
3
3
|
import { type Proof, type VerificationKeyData } from '@aztec/circuits.js';
|
|
4
4
|
import { runInDirectory } from '@aztec/foundation/fs';
|
|
5
|
-
import { type
|
|
5
|
+
import { type LogFn, type Logger, createLogger } from '@aztec/foundation/log';
|
|
6
6
|
import {
|
|
7
7
|
type ClientProtocolArtifact,
|
|
8
8
|
type ProtocolArtifact,
|
|
9
9
|
ProtocolCircuitArtifacts,
|
|
10
10
|
} from '@aztec/noir-protocol-circuits-types';
|
|
11
11
|
|
|
12
|
-
import
|
|
12
|
+
import { promises as fs } from 'fs';
|
|
13
13
|
import * as path from 'path';
|
|
14
14
|
|
|
15
15
|
import {
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
} from '../bb/execute.js';
|
|
24
24
|
import { type BBConfig } from '../config.js';
|
|
25
25
|
import { type UltraKeccakHonkProtocolArtifact, getUltraHonkFlavorForCircuit } from '../honk.js';
|
|
26
|
+
import { writeToOutputDirectory } from '../prover/client_ivc_proof_utils.js';
|
|
26
27
|
import { isProtocolArtifactRecursive, mapProtocolArtifactNameToCircuitName } from '../stats.js';
|
|
27
28
|
import { extractVkData } from '../verification_key/verification_key_data.js';
|
|
28
29
|
|
|
@@ -30,13 +31,13 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
|
|
|
30
31
|
private constructor(
|
|
31
32
|
private config: BBConfig,
|
|
32
33
|
private verificationKeys = new Map<ProtocolArtifact, Promise<VerificationKeyData>>(),
|
|
33
|
-
private logger:
|
|
34
|
+
private logger: Logger,
|
|
34
35
|
) {}
|
|
35
36
|
|
|
36
37
|
public static async new(
|
|
37
38
|
config: BBConfig,
|
|
38
39
|
initialCircuits: ProtocolArtifact[] = [],
|
|
39
|
-
logger =
|
|
40
|
+
logger = createLogger('bb-prover:verifier'),
|
|
40
41
|
) {
|
|
41
42
|
await fs.mkdir(config.bbWorkingDirectory, { recursive: true });
|
|
42
43
|
const keys = new Map<ProtocolArtifact, Promise<VerificationKeyData>>();
|
|
@@ -162,7 +163,7 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
|
|
|
162
163
|
this.logger.debug(`${circuit} BB out - ${message}`);
|
|
163
164
|
};
|
|
164
165
|
|
|
165
|
-
await tx.clientIvcProof
|
|
166
|
+
await writeToOutputDirectory(tx.clientIvcProof, bbWorkingDirectory);
|
|
166
167
|
const result = await verifyClientIvcProof(this.config.bbBinaryPath, bbWorkingDirectory, logFunction);
|
|
167
168
|
|
|
168
169
|
if (result.status === BB_RESULT.FAILURE) {
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { AztecClientBackend } from '@aztec/bb.js';
|
|
2
|
+
import { type PrivateKernelProver, type PrivateKernelSimulateOutput } from '@aztec/circuit-types';
|
|
3
|
+
import {
|
|
4
|
+
ClientIvcProof,
|
|
5
|
+
type PrivateKernelCircuitPublicInputs,
|
|
6
|
+
type PrivateKernelInitCircuitPrivateInputs,
|
|
7
|
+
type PrivateKernelInnerCircuitPrivateInputs,
|
|
8
|
+
type PrivateKernelResetCircuitPrivateInputs,
|
|
9
|
+
type PrivateKernelTailCircuitPrivateInputs,
|
|
10
|
+
type PrivateKernelTailCircuitPublicInputs,
|
|
11
|
+
} from '@aztec/circuits.js';
|
|
12
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
13
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
14
|
+
import {
|
|
15
|
+
ClientCircuitArtifacts,
|
|
16
|
+
ClientCircuitVks,
|
|
17
|
+
type ClientProtocolArtifact,
|
|
18
|
+
convertPrivateKernelInitInputsToWitnessMap,
|
|
19
|
+
convertPrivateKernelInitOutputsFromWitnessMap,
|
|
20
|
+
convertPrivateKernelInnerInputsToWitnessMap,
|
|
21
|
+
convertPrivateKernelInnerOutputsFromWitnessMap,
|
|
22
|
+
convertPrivateKernelResetInputsToWitnessMap,
|
|
23
|
+
convertPrivateKernelResetOutputsFromWitnessMap,
|
|
24
|
+
convertPrivateKernelTailForPublicOutputsFromWitnessMap,
|
|
25
|
+
convertPrivateKernelTailInputsToWitnessMap,
|
|
26
|
+
convertPrivateKernelTailOutputsFromWitnessMap,
|
|
27
|
+
convertPrivateKernelTailToPublicInputsToWitnessMap,
|
|
28
|
+
getPrivateKernelResetArtifactName,
|
|
29
|
+
} from '@aztec/noir-protocol-circuits-types/client';
|
|
30
|
+
import { WASMSimulator } from '@aztec/simulator/client';
|
|
31
|
+
import { type NoirCompiledCircuit } from '@aztec/types/noir';
|
|
32
|
+
|
|
33
|
+
import { type WitnessMap } from '@noir-lang/noir_js';
|
|
34
|
+
import { serializeWitness } from '@noir-lang/noirc_abi';
|
|
35
|
+
import { ungzip } from 'pako';
|
|
36
|
+
|
|
37
|
+
export class BBWasmPrivateKernelProver implements PrivateKernelProver {
|
|
38
|
+
private simulator = new WASMSimulator();
|
|
39
|
+
|
|
40
|
+
constructor(private threads: number = 1, private log = createLogger('bb-prover:wasm')) {}
|
|
41
|
+
|
|
42
|
+
public async simulateProofInit(
|
|
43
|
+
inputs: PrivateKernelInitCircuitPrivateInputs,
|
|
44
|
+
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
45
|
+
return await this.simulate(
|
|
46
|
+
inputs,
|
|
47
|
+
'PrivateKernelInitArtifact',
|
|
48
|
+
convertPrivateKernelInitInputsToWitnessMap,
|
|
49
|
+
convertPrivateKernelInitOutputsFromWitnessMap,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public async simulateProofInner(
|
|
54
|
+
inputs: PrivateKernelInnerCircuitPrivateInputs,
|
|
55
|
+
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
56
|
+
return await this.simulate(
|
|
57
|
+
inputs,
|
|
58
|
+
'PrivateKernelInnerArtifact',
|
|
59
|
+
convertPrivateKernelInnerInputsToWitnessMap,
|
|
60
|
+
convertPrivateKernelInnerOutputsFromWitnessMap,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public async simulateProofReset(
|
|
65
|
+
inputs: PrivateKernelResetCircuitPrivateInputs,
|
|
66
|
+
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
67
|
+
const variantInputs = inputs.trimToSizes();
|
|
68
|
+
const artifactName = getPrivateKernelResetArtifactName(inputs.dimensions);
|
|
69
|
+
return await this.simulate(
|
|
70
|
+
variantInputs,
|
|
71
|
+
artifactName,
|
|
72
|
+
variantInputs => convertPrivateKernelResetInputsToWitnessMap(variantInputs, artifactName),
|
|
73
|
+
output => convertPrivateKernelResetOutputsFromWitnessMap(output, artifactName),
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public async simulateProofTail(
|
|
78
|
+
inputs: PrivateKernelTailCircuitPrivateInputs,
|
|
79
|
+
): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
80
|
+
if (!inputs.isForPublic()) {
|
|
81
|
+
return await this.simulate(
|
|
82
|
+
inputs,
|
|
83
|
+
'PrivateKernelTailArtifact',
|
|
84
|
+
convertPrivateKernelTailInputsToWitnessMap,
|
|
85
|
+
convertPrivateKernelTailOutputsFromWitnessMap,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return await this.simulate(
|
|
89
|
+
inputs,
|
|
90
|
+
'PrivateKernelTailToPublicArtifact',
|
|
91
|
+
convertPrivateKernelTailToPublicInputsToWitnessMap,
|
|
92
|
+
convertPrivateKernelTailForPublicOutputsFromWitnessMap,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private async simulate<
|
|
97
|
+
I extends { toBuffer: () => Buffer },
|
|
98
|
+
O extends PrivateKernelCircuitPublicInputs | PrivateKernelTailCircuitPublicInputs,
|
|
99
|
+
>(
|
|
100
|
+
inputs: I,
|
|
101
|
+
circuitType: ClientProtocolArtifact,
|
|
102
|
+
convertInputs: (inputs: I) => WitnessMap,
|
|
103
|
+
convertOutputs: (outputs: WitnessMap) => O,
|
|
104
|
+
): Promise<PrivateKernelSimulateOutput<O>> {
|
|
105
|
+
this.log.debug(`Generating witness for ${circuitType}`);
|
|
106
|
+
const compiledCircuit: NoirCompiledCircuit = ClientCircuitArtifacts[circuitType];
|
|
107
|
+
|
|
108
|
+
const witnessMap = convertInputs(inputs);
|
|
109
|
+
const timer = new Timer();
|
|
110
|
+
const outputWitness = await this.simulator.simulateCircuit(witnessMap, compiledCircuit);
|
|
111
|
+
const output = convertOutputs(outputWitness);
|
|
112
|
+
|
|
113
|
+
this.log.debug(`Generated witness for ${circuitType}`, {
|
|
114
|
+
eventName: 'circuit-witness-generation',
|
|
115
|
+
circuitName: circuitType,
|
|
116
|
+
duration: timer.ms(),
|
|
117
|
+
inputSize: inputs.toBuffer().length,
|
|
118
|
+
outputSize: output.toBuffer().length,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const verificationKey = ClientCircuitVks[circuitType].keyAsFields;
|
|
122
|
+
const bytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
|
|
123
|
+
|
|
124
|
+
const kernelOutput: PrivateKernelSimulateOutput<O> = {
|
|
125
|
+
publicInputs: output,
|
|
126
|
+
verificationKey,
|
|
127
|
+
outputWitness,
|
|
128
|
+
bytecode,
|
|
129
|
+
};
|
|
130
|
+
return kernelOutput;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async createClientIvcProof(acirs: Buffer[], witnessStack: WitnessMap[]): Promise<ClientIvcProof> {
|
|
134
|
+
const timer = new Timer();
|
|
135
|
+
this.log.info(`Generating ClientIVC proof...`);
|
|
136
|
+
const backend = new AztecClientBackend(
|
|
137
|
+
acirs.map(acir => ungzip(acir)),
|
|
138
|
+
{ threads: this.threads },
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const [proof, vk] = await backend.prove(witnessStack.map(witnessMap => ungzip(serializeWitness(witnessMap))));
|
|
142
|
+
await backend.destroy();
|
|
143
|
+
this.log.info(`Generated ClientIVC proof`, {
|
|
144
|
+
eventName: 'client-ivc-proof-generation',
|
|
145
|
+
duration: timer.ms(),
|
|
146
|
+
proofSize: proof.length,
|
|
147
|
+
vkSize: vk.length,
|
|
148
|
+
});
|
|
149
|
+
return new ClientIvcProof(Buffer.from(proof), Buffer.from(vk));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise<number> {
|
|
153
|
+
return Promise.resolve(0);
|
|
154
|
+
}
|
|
155
|
+
}
|