@aztec/bb-prover 0.87.7 → 1.0.0-nightly.20250604
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/avm_proving_tests/avm_proving_tester.d.ts +3 -10
- package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
- package/dest/avm_proving_tests/avm_proving_tester.js +18 -62
- package/dest/bb/execute.d.ts +5 -24
- package/dest/bb/execute.d.ts.map +1 -1
- package/dest/bb/execute.js +18 -119
- package/dest/prover/server/bb_prover.d.ts +5 -5
- package/dest/prover/server/bb_prover.d.ts.map +1 -1
- package/dest/prover/server/bb_prover.js +22 -13
- package/dest/test/test_circuit_prover.d.ts +2 -2
- package/dest/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +2 -2
- package/dest/verification_key/verification_key_data.d.ts +6 -0
- package/dest/verification_key/verification_key_data.d.ts.map +1 -1
- package/dest/verification_key/verification_key_data.js +16 -16
- package/package.json +16 -18
- package/src/avm_proving_tests/avm_proving_tester.ts +30 -87
- package/src/bb/execute.ts +24 -138
- package/src/prover/server/bb_prover.ts +48 -30
- package/src/test/test_circuit_prover.ts +7 -5
- package/src/verification_key/verification_key_data.ts +20 -13
|
@@ -4,7 +4,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
4
4
|
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
}
|
|
7
|
-
import {
|
|
7
|
+
import { AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED, AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED, NESTED_RECURSIVE_PROOF_LENGTH, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, RECURSIVE_PROOF_LENGTH, TUBE_PROOF_LENGTH } from '@aztec/constants';
|
|
8
8
|
import { createLogger } from '@aztec/foundation/log';
|
|
9
9
|
import { sleep } from '@aztec/foundation/sleep';
|
|
10
10
|
import { Timer } from '@aztec/foundation/timer';
|
|
@@ -105,7 +105,7 @@ import { PROOF_DELAY_MS, WITGEN_DELAY_MS } from './delay_values.js';
|
|
|
105
105
|
// We can't simulate the AVM because we don't have enough context to do so (e.g., DBs).
|
|
106
106
|
// We just return an empty proof and VK data.
|
|
107
107
|
this.logger.debug('Skipping AVM simulation in TestCircuitProver.');
|
|
108
|
-
return this.applyDelay(ProvingRequestType.PUBLIC_VM, ()=>makeProofAndVerificationKey(makeEmptyRecursiveProof(
|
|
108
|
+
return this.applyDelay(ProvingRequestType.PUBLIC_VM, ()=>makeProofAndVerificationKey(makeEmptyRecursiveProof(AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED), VerificationKeyData.makeFake(AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED)));
|
|
109
109
|
}
|
|
110
110
|
async applyDelay(type, fn) {
|
|
111
111
|
const timer = new Timer();
|
|
@@ -5,5 +5,11 @@ import { VerificationKeyData } from '@aztec/stdlib/vks';
|
|
|
5
5
|
* @returns The verification key data
|
|
6
6
|
*/
|
|
7
7
|
export declare function extractVkData(vkDirectoryPath: string): Promise<VerificationKeyData>;
|
|
8
|
+
/**
|
|
9
|
+
* Reads the verification key data stored in a binary file at the specified directory location and parses into a VerificationKeyData.
|
|
10
|
+
* We do not assume any JSON file available but only the binary version, contrary to the above extractVkData() method.
|
|
11
|
+
* @param vkDirectoryPath - The directory containing the verification key binary data file.
|
|
12
|
+
* @returns The verification key data
|
|
13
|
+
*/
|
|
8
14
|
export declare function extractAvmVkData(vkDirectoryPath: string): Promise<VerificationKeyData>;
|
|
9
15
|
//# sourceMappingURL=verification_key_data.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verification_key_data.d.ts","sourceRoot":"","sources":["../../src/verification_key/verification_key_data.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"verification_key_data.d.ts","sourceRoot":"","sources":["../../src/verification_key/verification_key_data.ts"],"names":[],"mappings":"AAIA,OAAO,EAA2B,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAQjF;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAWzF;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAe5F"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import { BufferReader } from '@aztec/foundation/serialize';
|
|
3
4
|
import { hashVK } from '@aztec/stdlib/hash';
|
|
4
5
|
import { VerificationKeyAsFields, VerificationKeyData } from '@aztec/stdlib/vks';
|
|
5
6
|
import { strict as assert } from 'assert';
|
|
@@ -24,21 +25,20 @@ import { VK_FIELDS_FILENAME, VK_FILENAME } from '../bb/execute.js';
|
|
|
24
25
|
const vkAsFields = new VerificationKeyAsFields(fields, vkHash);
|
|
25
26
|
return new VerificationKeyData(vkAsFields, rawBinary);
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const vkAsFields = new VerificationKeyAsFields(fields, vkHash);
|
|
28
|
+
/**
|
|
29
|
+
* Reads the verification key data stored in a binary file at the specified directory location and parses into a VerificationKeyData.
|
|
30
|
+
* We do not assume any JSON file available but only the binary version, contrary to the above extractVkData() method.
|
|
31
|
+
* @param vkDirectoryPath - The directory containing the verification key binary data file.
|
|
32
|
+
* @returns The verification key data
|
|
33
|
+
*/ export async function extractAvmVkData(vkDirectoryPath) {
|
|
34
|
+
const rawBinary = await fs.readFile(path.join(vkDirectoryPath, VK_FILENAME));
|
|
35
|
+
const numFields = rawBinary.length / Fr.SIZE_IN_BYTES;
|
|
36
|
+
assert(numFields <= AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED, 'Invalid AVM verification key length');
|
|
37
|
+
const reader = BufferReader.asReader(rawBinary);
|
|
38
|
+
const fieldsArray = reader.readArray(numFields, Fr);
|
|
39
|
+
const fieldsArrayPadded = fieldsArray.concat(Array(AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED - fieldsArray.length).fill(new Fr(0)));
|
|
40
|
+
// Currently, we do not need the vk hash for the AVM as we are not adding in the vk tree.
|
|
41
|
+
const vkAsFields = new VerificationKeyAsFields(fieldsArrayPadded, new Fr(0));
|
|
42
42
|
const vk = new VerificationKeyData(vkAsFields, rawBinary);
|
|
43
43
|
return vk;
|
|
44
44
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/bb-prover",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-nightly.20250604",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -66,32 +66,30 @@
|
|
|
66
66
|
]
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@aztec/bb.js": "0.
|
|
70
|
-
"@aztec/constants": "0.
|
|
71
|
-
"@aztec/foundation": "0.
|
|
72
|
-
"@aztec/noir-noirc_abi": "0.
|
|
73
|
-
"@aztec/noir-protocol-circuits-types": "0.
|
|
74
|
-
"@aztec/noir-types": "0.
|
|
75
|
-
"@aztec/simulator": "0.
|
|
76
|
-
"@aztec/stdlib": "0.
|
|
77
|
-
"@aztec/telemetry-client": "0.
|
|
78
|
-
"@aztec/world-state": "0.
|
|
69
|
+
"@aztec/bb.js": "1.0.0-nightly.20250604",
|
|
70
|
+
"@aztec/constants": "1.0.0-nightly.20250604",
|
|
71
|
+
"@aztec/foundation": "1.0.0-nightly.20250604",
|
|
72
|
+
"@aztec/noir-noirc_abi": "1.0.0-nightly.20250604",
|
|
73
|
+
"@aztec/noir-protocol-circuits-types": "1.0.0-nightly.20250604",
|
|
74
|
+
"@aztec/noir-types": "1.0.0-nightly.20250604",
|
|
75
|
+
"@aztec/simulator": "1.0.0-nightly.20250604",
|
|
76
|
+
"@aztec/stdlib": "1.0.0-nightly.20250604",
|
|
77
|
+
"@aztec/telemetry-client": "1.0.0-nightly.20250604",
|
|
78
|
+
"@aztec/world-state": "1.0.0-nightly.20250604",
|
|
79
79
|
"commander": "^12.1.0",
|
|
80
80
|
"pako": "^2.1.0",
|
|
81
|
-
"pidusage": "^4.0.1",
|
|
82
81
|
"source-map-support": "^0.5.21",
|
|
83
82
|
"tslib": "^2.4.0"
|
|
84
83
|
},
|
|
85
84
|
"devDependencies": {
|
|
86
|
-
"@aztec/ethereum": "0.
|
|
87
|
-
"@aztec/kv-store": "0.
|
|
88
|
-
"@aztec/noir-contracts.js": "0.
|
|
89
|
-
"@aztec/noir-test-contracts.js": "0.
|
|
90
|
-
"@aztec/protocol-contracts": "0.
|
|
85
|
+
"@aztec/ethereum": "1.0.0-nightly.20250604",
|
|
86
|
+
"@aztec/kv-store": "1.0.0-nightly.20250604",
|
|
87
|
+
"@aztec/noir-contracts.js": "1.0.0-nightly.20250604",
|
|
88
|
+
"@aztec/noir-test-contracts.js": "1.0.0-nightly.20250604",
|
|
89
|
+
"@aztec/protocol-contracts": "1.0.0-nightly.20250604",
|
|
91
90
|
"@jest/globals": "^29.5.0",
|
|
92
91
|
"@types/jest": "^29.5.0",
|
|
93
92
|
"@types/node": "^22.15.17",
|
|
94
|
-
"@types/pidusage": "^2.0.5",
|
|
95
93
|
"@types/source-map-support": "^0.5.10",
|
|
96
94
|
"jest": "^29.5.0",
|
|
97
95
|
"jest-mock-extended": "^3.0.3",
|
|
@@ -7,7 +7,6 @@ import { type AvmCircuitInputs, AvmCircuitPublicInputs } from '@aztec/stdlib/avm
|
|
|
7
7
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
8
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
9
9
|
import type { GlobalVariables } from '@aztec/stdlib/tx';
|
|
10
|
-
import { VerificationKeyData } from '@aztec/stdlib/vks';
|
|
11
10
|
import { NativeWorldStateService } from '@aztec/world-state';
|
|
12
11
|
|
|
13
12
|
import fs from 'node:fs/promises';
|
|
@@ -18,12 +17,10 @@ import {
|
|
|
18
17
|
type BBResult,
|
|
19
18
|
type BBSuccess,
|
|
20
19
|
BB_RESULT,
|
|
20
|
+
VK_FILENAME,
|
|
21
21
|
generateAvmProof,
|
|
22
|
-
generateAvmProofV2,
|
|
23
22
|
verifyAvmProof,
|
|
24
|
-
verifyAvmProofV2,
|
|
25
23
|
} from '../bb/execute.js';
|
|
26
|
-
import { extractAvmVkData } from '../verification_key/verification_key_data.js';
|
|
27
24
|
|
|
28
25
|
const BB_PATH = path.resolve('../../barretenberg/cpp/build/bin/bb');
|
|
29
26
|
|
|
@@ -31,20 +28,19 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
31
28
|
constructor(
|
|
32
29
|
private bbWorkingDirectory: string,
|
|
33
30
|
private checkCircuitOnly: boolean,
|
|
34
|
-
merkleTree: MerkleTreeWriteOperations,
|
|
35
31
|
contractDataSource: SimpleContractDataSource,
|
|
32
|
+
merkleTrees: MerkleTreeWriteOperations,
|
|
36
33
|
globals?: GlobalVariables,
|
|
37
34
|
) {
|
|
38
|
-
super(
|
|
35
|
+
super(merkleTrees, contractDataSource, globals);
|
|
39
36
|
}
|
|
40
37
|
|
|
41
|
-
// overriding parent class' create is a pain, so we use a different nam
|
|
42
38
|
static async new(checkCircuitOnly: boolean = false, globals?: GlobalVariables) {
|
|
43
39
|
const bbWorkingDirectory = await fs.mkdtemp(path.join(tmpdir(), 'bb-'));
|
|
44
40
|
|
|
45
41
|
const contractDataSource = new SimpleContractDataSource();
|
|
46
42
|
const merkleTrees = await (await NativeWorldStateService.tmp()).fork();
|
|
47
|
-
return new AvmProvingTester(bbWorkingDirectory, checkCircuitOnly,
|
|
43
|
+
return new AvmProvingTester(bbWorkingDirectory, checkCircuitOnly, contractDataSource, merkleTrees, globals);
|
|
48
44
|
}
|
|
49
45
|
|
|
50
46
|
async prove(avmCircuitInputs: AvmCircuitInputs): Promise<BBResult> {
|
|
@@ -59,95 +55,36 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
59
55
|
if (proofRes.status === BB_RESULT.FAILURE) {
|
|
60
56
|
this.logger.error(`Proof generation failed: ${proofRes.reason}`);
|
|
61
57
|
}
|
|
62
|
-
|
|
58
|
+
expect(proofRes.status).toEqual(BB_RESULT.SUCCESS);
|
|
59
|
+
return proofRes as BBSuccess;
|
|
63
60
|
}
|
|
64
61
|
|
|
65
|
-
async verify(proofRes: BBSuccess): Promise<BBResult> {
|
|
62
|
+
async verify(proofRes: BBSuccess, publicInputs: AvmCircuitPublicInputs): Promise<BBResult> {
|
|
66
63
|
if (this.checkCircuitOnly) {
|
|
67
|
-
// Skip verification if we
|
|
68
|
-
// Check-circuit
|
|
64
|
+
// Skip verification if we are only checking the circuit.
|
|
65
|
+
// Check-circuit does not generate a proof to verify.
|
|
69
66
|
return proofRes;
|
|
70
67
|
}
|
|
71
|
-
// Then we test VK extraction and serialization.
|
|
72
|
-
const succeededRes = proofRes as BBSuccess;
|
|
73
|
-
const vkData = await extractAvmVkData(succeededRes.vkPath!);
|
|
74
|
-
VerificationKeyData.fromBuffer(vkData.toBuffer());
|
|
75
|
-
|
|
76
|
-
// Then we verify.
|
|
77
|
-
const rawVkPath = path.join(succeededRes.vkPath!, 'vk');
|
|
78
|
-
return await verifyAvmProof(BB_PATH, succeededRes.proofPath!, rawVkPath, this.logger);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public async simProveVerify(
|
|
82
|
-
sender: AztecAddress,
|
|
83
|
-
setupCalls: TestEnqueuedCall[],
|
|
84
|
-
appCalls: TestEnqueuedCall[],
|
|
85
|
-
teardownCall: TestEnqueuedCall | undefined,
|
|
86
|
-
expectRevert: boolean | undefined,
|
|
87
|
-
feePayer = sender,
|
|
88
|
-
) {
|
|
89
|
-
const simRes = await this.simulateTx(sender, setupCalls, appCalls, teardownCall, feePayer);
|
|
90
|
-
expect(simRes.revertCode.isOK()).toBe(expectRevert ? false : true);
|
|
91
|
-
const avmCircuitInputs = simRes.avmProvingRequest.inputs;
|
|
92
|
-
const provingRes = await this.prove(avmCircuitInputs);
|
|
93
|
-
expect(provingRes.status).toEqual(BB_RESULT.SUCCESS);
|
|
94
|
-
const verificationRes = await this.verify(provingRes as BBSuccess);
|
|
95
|
-
expect(verificationRes.status).toBe(BB_RESULT.SUCCESS);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public async simProveVerifyAppLogic(appCall: TestEnqueuedCall, expectRevert?: boolean) {
|
|
99
|
-
const simRes = await this.simulateTx(/*sender=*/ AztecAddress.fromNumber(42), /*setupCalls=*/ [], [appCall]);
|
|
100
|
-
expect(simRes.revertCode.isOK()).toBe(expectRevert ? false : true);
|
|
101
|
-
|
|
102
|
-
const avmCircuitInputs = simRes.avmProvingRequest.inputs;
|
|
103
|
-
const provingRes = await this.prove(avmCircuitInputs);
|
|
104
|
-
expect(provingRes.status).toEqual(BB_RESULT.SUCCESS);
|
|
105
|
-
|
|
106
|
-
const verificationRes = await this.verify(provingRes as BBSuccess);
|
|
107
|
-
expect(verificationRes.status).toBe(BB_RESULT.SUCCESS);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export class AvmProvingTesterV2 extends PublicTxSimulationTester {
|
|
112
|
-
constructor(
|
|
113
|
-
private bbWorkingDirectory: string,
|
|
114
|
-
contractDataSource: SimpleContractDataSource,
|
|
115
|
-
merkleTrees: MerkleTreeWriteOperations,
|
|
116
|
-
globals?: GlobalVariables,
|
|
117
|
-
) {
|
|
118
|
-
super(merkleTrees, contractDataSource, globals);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
static async new(globals?: GlobalVariables) {
|
|
122
|
-
const bbWorkingDirectory = await fs.mkdtemp(path.join(tmpdir(), 'bb-'));
|
|
123
|
-
|
|
124
|
-
const contractDataSource = new SimpleContractDataSource();
|
|
125
|
-
const merkleTrees = await (await NativeWorldStateService.tmp()).fork();
|
|
126
|
-
return new AvmProvingTesterV2(bbWorkingDirectory, contractDataSource, merkleTrees, globals);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async proveV2(avmCircuitInputs: AvmCircuitInputs): Promise<BBResult> {
|
|
130
|
-
// Then we prove.
|
|
131
|
-
const proofRes = await generateAvmProofV2(BB_PATH, this.bbWorkingDirectory, avmCircuitInputs, this.logger);
|
|
132
|
-
if (proofRes.status === BB_RESULT.FAILURE) {
|
|
133
|
-
this.logger.error(`Proof generation failed: ${proofRes.reason}`);
|
|
134
|
-
}
|
|
135
|
-
expect(proofRes.status).toEqual(BB_RESULT.SUCCESS);
|
|
136
|
-
return proofRes as BBSuccess;
|
|
137
|
-
}
|
|
138
68
|
|
|
139
|
-
|
|
140
|
-
return await verifyAvmProofV2(
|
|
69
|
+
return await verifyAvmProof(
|
|
141
70
|
BB_PATH,
|
|
142
71
|
this.bbWorkingDirectory,
|
|
143
72
|
proofRes.proofPath!,
|
|
144
73
|
publicInputs,
|
|
145
|
-
proofRes.
|
|
74
|
+
path.join(proofRes.vkDirectoryPath!, VK_FILENAME),
|
|
146
75
|
this.logger,
|
|
147
76
|
);
|
|
148
77
|
}
|
|
149
78
|
|
|
150
|
-
public async
|
|
79
|
+
public async proveVerify(avmCircuitInputs: AvmCircuitInputs) {
|
|
80
|
+
const provingRes = await this.prove(avmCircuitInputs);
|
|
81
|
+
expect(provingRes.status).toEqual(BB_RESULT.SUCCESS);
|
|
82
|
+
|
|
83
|
+
const verificationRes = await this.verify(provingRes as BBSuccess, avmCircuitInputs.publicInputs);
|
|
84
|
+
expect(verificationRes.status).toBe(BB_RESULT.SUCCESS);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public async simProveVerify(
|
|
151
88
|
sender: AztecAddress,
|
|
152
89
|
setupCalls: TestEnqueuedCall[],
|
|
153
90
|
appCalls: TestEnqueuedCall[],
|
|
@@ -159,10 +96,16 @@ export class AvmProvingTesterV2 extends PublicTxSimulationTester {
|
|
|
159
96
|
expect(simRes.revertCode.isOK()).toBe(expectRevert ? false : true);
|
|
160
97
|
|
|
161
98
|
const avmCircuitInputs = simRes.avmProvingRequest.inputs;
|
|
162
|
-
|
|
163
|
-
|
|
99
|
+
await this.proveVerify(avmCircuitInputs);
|
|
100
|
+
}
|
|
164
101
|
|
|
165
|
-
|
|
166
|
-
|
|
102
|
+
public async simProveVerifyAppLogic(appCall: TestEnqueuedCall, expectRevert?: boolean) {
|
|
103
|
+
await this.simProveVerify(
|
|
104
|
+
/*sender=*/ AztecAddress.fromNumber(42),
|
|
105
|
+
/*setupCalls=*/ [],
|
|
106
|
+
[appCall],
|
|
107
|
+
undefined,
|
|
108
|
+
expectRevert,
|
|
109
|
+
);
|
|
167
110
|
}
|
|
168
111
|
}
|
package/src/bb/execute.ts
CHANGED
|
@@ -6,7 +6,6 @@ import type { AvmCircuitInputs, AvmCircuitPublicInputs } from '@aztec/stdlib/avm
|
|
|
6
6
|
import * as proc from 'child_process';
|
|
7
7
|
import { promises as fs } from 'fs';
|
|
8
8
|
import { basename, dirname, join } from 'path';
|
|
9
|
-
import pidusage from 'pidusage';
|
|
10
9
|
|
|
11
10
|
import type { UltraHonkFlavor } from '../honk.js';
|
|
12
11
|
|
|
@@ -33,7 +32,7 @@ export type BBSuccess = {
|
|
|
33
32
|
/** Full path of the public key. */
|
|
34
33
|
pkPath?: string;
|
|
35
34
|
/** Base directory for the VKs (raw, fields). */
|
|
36
|
-
|
|
35
|
+
vkDirectoryPath?: string;
|
|
37
36
|
/** Full path of the proof. */
|
|
38
37
|
proofPath?: string;
|
|
39
38
|
/** Full path of the contract. */
|
|
@@ -50,8 +49,6 @@ export type BBFailure = {
|
|
|
50
49
|
|
|
51
50
|
export type BBResult = BBSuccess | BBFailure;
|
|
52
51
|
|
|
53
|
-
export type VerificationFunction = typeof verifyProof | typeof verifyAvmProof;
|
|
54
|
-
|
|
55
52
|
type BBExecResult = {
|
|
56
53
|
status: BB_RESULT;
|
|
57
54
|
exitCode: number;
|
|
@@ -98,23 +95,11 @@ export function executeBB(
|
|
|
98
95
|
|
|
99
96
|
bb.stdout.on('data', data => {
|
|
100
97
|
const message = data.toString('utf-8').replace(/\n$/, '');
|
|
101
|
-
|
|
102
|
-
if (err) {
|
|
103
|
-
logger(message);
|
|
104
|
-
} else {
|
|
105
|
-
logger(`${message} (mem: ${(stats.memory / 1024 / 1024).toFixed(2)}MiB)`);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
98
|
+
logger(message);
|
|
108
99
|
});
|
|
109
100
|
bb.stderr.on('data', data => {
|
|
110
101
|
const message = data.toString('utf-8').replace(/\n$/, '');
|
|
111
|
-
|
|
112
|
-
if (err) {
|
|
113
|
-
logger(message);
|
|
114
|
-
} else {
|
|
115
|
-
logger(`${message} (mem: ${(stats.memory / 1024 / 1024).toFixed(2)}MiB)`);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
102
|
+
logger(message);
|
|
118
103
|
});
|
|
119
104
|
bb.on('close', (exitCode: number, signal?: string) => {
|
|
120
105
|
if (timeoutId) {
|
|
@@ -175,7 +160,7 @@ export async function executeBbClientIvcProof(
|
|
|
175
160
|
durationMs,
|
|
176
161
|
proofPath: `${outputPath}`,
|
|
177
162
|
pkPath: undefined,
|
|
178
|
-
|
|
163
|
+
vkDirectoryPath: `${outputPath}`,
|
|
179
164
|
};
|
|
180
165
|
}
|
|
181
166
|
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
@@ -279,7 +264,7 @@ export async function generateProof(
|
|
|
279
264
|
durationMs: duration,
|
|
280
265
|
proofPath: `${outputPath}`,
|
|
281
266
|
pkPath: undefined,
|
|
282
|
-
|
|
267
|
+
vkDirectoryPath: `${outputPath}`,
|
|
283
268
|
};
|
|
284
269
|
}
|
|
285
270
|
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
@@ -347,7 +332,7 @@ export async function generateTubeProof(
|
|
|
347
332
|
durationMs,
|
|
348
333
|
proofPath: outputPath,
|
|
349
334
|
pkPath: undefined,
|
|
350
|
-
|
|
335
|
+
vkDirectoryPath: outputPath,
|
|
351
336
|
};
|
|
352
337
|
}
|
|
353
338
|
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
@@ -367,14 +352,16 @@ export async function generateTubeProof(
|
|
|
367
352
|
* @param pathToBB - The full path to the bb binary
|
|
368
353
|
* @param workingDirectory - A working directory for use by bb
|
|
369
354
|
* @param input - The inputs for the public function to be proven
|
|
370
|
-
* @param
|
|
355
|
+
* @param logger - A logging function
|
|
356
|
+
* @param checkCircuitOnly - A boolean to toggle a "check-circuit only" operation instead of proving.
|
|
371
357
|
* @returns An object containing a result indication, the location of the proof and the duration taken
|
|
372
358
|
*/
|
|
373
|
-
export async function
|
|
359
|
+
export async function generateAvmProof(
|
|
374
360
|
pathToBB: string,
|
|
375
361
|
workingDirectory: string,
|
|
376
362
|
input: AvmCircuitInputs,
|
|
377
363
|
logger: Logger,
|
|
364
|
+
checkCircuitOnly: boolean = false,
|
|
378
365
|
): Promise<BBFailure | BBSuccess> {
|
|
379
366
|
// Check that the working directory exists
|
|
380
367
|
try {
|
|
@@ -414,99 +401,12 @@ export async function generateAvmProofV2(
|
|
|
414
401
|
args.push(loggingArg);
|
|
415
402
|
}
|
|
416
403
|
const timer = new Timer();
|
|
417
|
-
const logFunction = (message: string) => {
|
|
418
|
-
logger.verbose(`AvmCircuit (prove) BB out - ${message}`);
|
|
419
|
-
};
|
|
420
|
-
const result = await executeBB(pathToBB, 'avm2_prove', args, logFunction);
|
|
421
|
-
const duration = timer.ms();
|
|
422
|
-
|
|
423
|
-
if (result.status == BB_RESULT.SUCCESS) {
|
|
424
|
-
return {
|
|
425
|
-
status: BB_RESULT.SUCCESS,
|
|
426
|
-
durationMs: duration,
|
|
427
|
-
proofPath: join(outputPath, PROOF_FILENAME),
|
|
428
|
-
pkPath: undefined,
|
|
429
|
-
vkPath: join(outputPath, VK_FILENAME),
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
433
|
-
return {
|
|
434
|
-
status: BB_RESULT.FAILURE,
|
|
435
|
-
reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
|
|
436
|
-
retry: !!result.signal,
|
|
437
|
-
};
|
|
438
|
-
} catch (error) {
|
|
439
|
-
return { status: BB_RESULT.FAILURE, reason: `${error}` };
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
/**
|
|
444
|
-
* Used for generating AVM proofs (or doing check-circuit).
|
|
445
|
-
* It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
|
|
446
|
-
* @param pathToBB - The full path to the bb binary
|
|
447
|
-
* @param workingDirectory - A working directory for use by bb
|
|
448
|
-
* @param bytecode - The AVM bytecode for the public function to be proven (expected to be decompressed)
|
|
449
|
-
* @param log - A logging function
|
|
450
|
-
* @returns An object containing a result indication, the location of the proof and the duration taken
|
|
451
|
-
*/
|
|
452
|
-
export async function generateAvmProof(
|
|
453
|
-
pathToBB: string,
|
|
454
|
-
workingDirectory: string,
|
|
455
|
-
_input: AvmCircuitInputs,
|
|
456
|
-
logger: Logger,
|
|
457
|
-
checkCircuitOnly: boolean = false,
|
|
458
|
-
): Promise<BBFailure | BBSuccess> {
|
|
459
|
-
// Check that the working directory exists
|
|
460
|
-
try {
|
|
461
|
-
await fs.access(workingDirectory);
|
|
462
|
-
} catch {
|
|
463
|
-
return { status: BB_RESULT.FAILURE, reason: `Working directory ${workingDirectory} does not exist` };
|
|
464
|
-
}
|
|
465
404
|
|
|
466
|
-
|
|
467
|
-
const publicInputsPath = join(workingDirectory, AVM_PUBLIC_INPUTS_FILENAME);
|
|
468
|
-
|
|
469
|
-
// The proof is written to e.g. /workingDirectory/proof
|
|
470
|
-
const outputPath = workingDirectory;
|
|
471
|
-
|
|
472
|
-
const filePresent = async (file: string) =>
|
|
473
|
-
await fs
|
|
474
|
-
.access(file, fs.constants.R_OK)
|
|
475
|
-
.then(_ => true)
|
|
476
|
-
.catch(_ => false);
|
|
477
|
-
|
|
478
|
-
const binaryPresent = await filePresent(pathToBB);
|
|
479
|
-
if (!binaryPresent) {
|
|
480
|
-
return { status: BB_RESULT.FAILURE, reason: `Failed to find bb binary at ${pathToBB}` };
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
try {
|
|
484
|
-
// Write the inputs to the working directory.
|
|
485
|
-
|
|
486
|
-
// WARNING: Not writing the inputs since VM1 is disabled!
|
|
487
|
-
// await fs.writeFile(publicInputsPath, input.publicInputs.toBuffer());
|
|
488
|
-
// if (!(await filePresent(publicInputsPath))) {
|
|
489
|
-
// return { status: BB_RESULT.FAILURE, reason: `Could not write publicInputs at ${publicInputsPath}` };
|
|
490
|
-
// }
|
|
491
|
-
|
|
492
|
-
// await fs.writeFile(avmHintsPath, input.avmHints.toBuffer());
|
|
493
|
-
// if (!(await filePresent(avmHintsPath))) {
|
|
494
|
-
// return { status: BB_RESULT.FAILURE, reason: `Could not write avmHints at ${avmHintsPath}` };
|
|
495
|
-
// }
|
|
496
|
-
|
|
497
|
-
const args = ['--avm-public-inputs', publicInputsPath, '-o', outputPath];
|
|
498
|
-
const loggingArg =
|
|
499
|
-
logger.level === 'debug' || logger.level === 'trace' ? '-d' : logger.level === 'verbose' ? '-v' : '';
|
|
500
|
-
if (loggingArg !== '') {
|
|
501
|
-
args.push(loggingArg);
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
const timer = new Timer();
|
|
505
|
-
const cmd = checkCircuitOnly ? 'check_circuit' : 'prove';
|
|
405
|
+
const cmd = checkCircuitOnly ? 'avm_check_circuit' : 'avm_prove';
|
|
506
406
|
const logFunction = (message: string) => {
|
|
507
407
|
logger.verbose(`AvmCircuit (${cmd}) BB out - ${message}`);
|
|
508
408
|
};
|
|
509
|
-
const result = await executeBB(pathToBB,
|
|
409
|
+
const result = await executeBB(pathToBB, cmd, args, logFunction);
|
|
510
410
|
const duration = timer.ms();
|
|
511
411
|
|
|
512
412
|
if (result.status == BB_RESULT.SUCCESS) {
|
|
@@ -515,7 +415,7 @@ export async function generateAvmProof(
|
|
|
515
415
|
durationMs: duration,
|
|
516
416
|
proofPath: join(outputPath, PROOF_FILENAME),
|
|
517
417
|
pkPath: undefined,
|
|
518
|
-
|
|
418
|
+
vkDirectoryPath: outputPath,
|
|
519
419
|
};
|
|
520
420
|
}
|
|
521
421
|
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
@@ -554,24 +454,7 @@ export async function verifyProof(
|
|
|
554
454
|
);
|
|
555
455
|
}
|
|
556
456
|
|
|
557
|
-
/**
|
|
558
|
-
* Used for verifying proofs of the AVM
|
|
559
|
-
* @param pathToBB - The full path to the bb binary
|
|
560
|
-
* @param proofFullPath - The full path to the proof to be verified
|
|
561
|
-
* @param verificationKeyPath - The full path to the circuit verification key
|
|
562
|
-
* @param log - A logging function
|
|
563
|
-
* @returns An object containing a result indication and duration taken
|
|
564
|
-
*/
|
|
565
457
|
export async function verifyAvmProof(
|
|
566
|
-
pathToBB: string,
|
|
567
|
-
proofFullPath: string,
|
|
568
|
-
verificationKeyPath: string,
|
|
569
|
-
logger: Logger,
|
|
570
|
-
): Promise<BBFailure | BBSuccess> {
|
|
571
|
-
return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, 'avm_verify', logger);
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
export async function verifyAvmProofV2(
|
|
575
458
|
pathToBB: string,
|
|
576
459
|
workingDirectory: string,
|
|
577
460
|
proofFullPath: string,
|
|
@@ -593,7 +476,7 @@ export async function verifyAvmProofV2(
|
|
|
593
476
|
return { status: BB_RESULT.FAILURE, reason: `Could not write avm inputs to ${avmInputsPath}` };
|
|
594
477
|
}
|
|
595
478
|
|
|
596
|
-
return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, '
|
|
479
|
+
return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, 'avm_verify', logger, [
|
|
597
480
|
'--avm-public-inputs',
|
|
598
481
|
avmInputsPath,
|
|
599
482
|
]);
|
|
@@ -654,7 +537,7 @@ async function verifyProofInternal(
|
|
|
654
537
|
pathToBB: string,
|
|
655
538
|
proofFullPath: string,
|
|
656
539
|
verificationKeyPath: string,
|
|
657
|
-
command: 'verify' | 'avm_verify'
|
|
540
|
+
command: 'verify' | 'avm_verify',
|
|
658
541
|
logger: Logger,
|
|
659
542
|
extraArgs: string[] = [],
|
|
660
543
|
): Promise<BBFailure | BBSuccess> {
|
|
@@ -670,24 +553,27 @@ async function verifyProofInternal(
|
|
|
670
553
|
logger.verbose(`bb-prover (verify) BB out - ${message}`);
|
|
671
554
|
};
|
|
672
555
|
|
|
673
|
-
// take proofFullPath and remove the suffix past the / to get the directory
|
|
674
|
-
const proofDir = proofFullPath.substring(0, proofFullPath.lastIndexOf('/'));
|
|
675
|
-
const publicInputsFullPath = join(proofDir, '/public_inputs');
|
|
676
|
-
|
|
677
|
-
logger.debug(`public inputs path: ${publicInputsFullPath}`);
|
|
678
556
|
try {
|
|
679
557
|
let args;
|
|
680
|
-
|
|
558
|
+
|
|
681
559
|
if (command == 'verify') {
|
|
560
|
+
// Specify the public inputs path in the case of UH verification.
|
|
561
|
+
// Take proofFullPath and remove the suffix past the / to get the directory.
|
|
562
|
+
const proofDir = proofFullPath.substring(0, proofFullPath.lastIndexOf('/'));
|
|
563
|
+
const publicInputsFullPath = join(proofDir, '/public_inputs');
|
|
564
|
+
logger.debug(`public inputs path: ${publicInputsFullPath}`);
|
|
565
|
+
|
|
682
566
|
args = ['-p', proofFullPath, '-k', verificationKeyPath, '-i', publicInputsFullPath, ...extraArgs];
|
|
683
567
|
} else {
|
|
684
568
|
args = ['-p', proofFullPath, '-k', verificationKeyPath, ...extraArgs];
|
|
685
569
|
}
|
|
570
|
+
|
|
686
571
|
const loggingArg =
|
|
687
572
|
logger.level === 'debug' || logger.level === 'trace' ? '-d' : logger.level === 'verbose' ? '-v' : '';
|
|
688
573
|
if (loggingArg !== '') {
|
|
689
574
|
args.push(loggingArg);
|
|
690
575
|
}
|
|
576
|
+
|
|
691
577
|
const timer = new Timer();
|
|
692
578
|
const result = await executeBB(pathToBB, command, args, logFunction);
|
|
693
579
|
const duration = timer.ms();
|