@aztec/bb-prover 0.67.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/prover/bb_private_kernel_prover.d.ts +2 -11
- package/dest/prover/bb_private_kernel_prover.d.ts.map +1 -1
- package/dest/prover/bb_private_kernel_prover.js +4 -69
- 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 +3 -2
- 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_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +9 -4
- package/dest/verifier/bb_verifier.d.ts.map +1 -1
- package/dest/verifier/bb_verifier.js +3 -2
- 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 +13 -9
- package/src/prover/bb_private_kernel_prover.ts +7 -131
- package/src/prover/bb_prover.ts +2 -1
- package/src/prover/client_ivc_proof_utils.ts +39 -0
- package/src/prover/index.ts +1 -0
- package/src/test/test_circuit_prover.ts +10 -5
- package/src/verifier/bb_verifier.ts +2 -1
- package/src/wasm/index.ts +155 -0
|
@@ -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
|
+
}
|