@aztec/bb-prover 0.0.0-test.1 → 0.0.1-commit.b655e406
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 +14 -17
- package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
- package/dest/avm_proving_tests/avm_proving_tester.js +128 -78
- package/dest/bb/execute.d.ts +13 -46
- package/dest/bb/execute.d.ts.map +1 -1
- package/dest/bb/execute.js +120 -228
- package/dest/config.d.ts +2 -0
- package/dest/config.d.ts.map +1 -1
- package/dest/honk.d.ts +2 -2
- package/dest/honk.d.ts.map +1 -1
- package/dest/honk.js +3 -2
- package/dest/index.d.ts +1 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/instrumentation.d.ts +2 -2
- package/dest/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation.js +2 -4
- package/dest/prover/{bb_private_kernel_prover.d.ts → client/bb_private_kernel_prover.d.ts} +10 -10
- package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -0
- package/dest/prover/{bb_private_kernel_prover.js → client/bb_private_kernel_prover.js} +21 -18
- package/dest/prover/client/native/bb_native_private_kernel_prover.d.ts +23 -0
- package/dest/prover/client/native/bb_native_private_kernel_prover.d.ts.map +1 -0
- package/dest/prover/{bb_native_private_kernel_prover.js → client/native/bb_native_private_kernel_prover.js} +19 -22
- package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.d.ts +15 -0
- package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.d.ts.map +1 -0
- package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.js +46 -0
- package/dest/prover/client/wasm/bundle.d.ts +6 -0
- package/dest/prover/client/wasm/bundle.d.ts.map +1 -0
- package/dest/{wasm → prover/client/wasm}/bundle.js +2 -2
- package/dest/prover/client/wasm/lazy.d.ts +6 -0
- package/dest/prover/client/wasm/lazy.d.ts.map +1 -0
- package/dest/{wasm → prover/client/wasm}/lazy.js +2 -2
- package/dest/prover/index.d.ts +2 -3
- package/dest/prover/index.d.ts.map +1 -1
- package/dest/prover/index.js +2 -3
- package/dest/prover/proof_utils.d.ts +19 -0
- package/dest/prover/proof_utils.d.ts.map +1 -0
- package/dest/prover/proof_utils.js +72 -0
- package/dest/prover/server/bb_prover.d.ts +109 -0
- package/dest/prover/server/bb_prover.d.ts.map +1 -0
- package/dest/prover/server/bb_prover.js +339 -0
- package/dest/test/delay_values.d.ts.map +1 -1
- package/dest/test/delay_values.js +30 -18
- package/dest/test/test_circuit_prover.d.ts +24 -33
- package/dest/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +85 -59
- package/dest/test/test_verifier.d.ts +3 -2
- package/dest/test/test_verifier.d.ts.map +1 -1
- package/dest/test/test_verifier.js +8 -1
- 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 +23 -29
- package/dest/verifier/bb_verifier.d.ts +5 -4
- package/dest/verifier/bb_verifier.d.ts.map +1 -1
- package/dest/verifier/bb_verifier.js +43 -25
- package/dest/verifier/index.d.ts +1 -0
- package/dest/verifier/index.d.ts.map +1 -1
- package/dest/verifier/index.js +1 -0
- package/dest/verifier/queued_chonk_verifier.d.ts +15 -0
- package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -0
- package/dest/verifier/queued_chonk_verifier.js +132 -0
- package/package.json +32 -31
- package/src/avm_proving_tests/avm_proving_tester.ts +209 -103
- package/src/bb/execute.ts +98 -242
- package/src/config.ts +2 -0
- package/src/honk.ts +3 -2
- package/src/index.ts +1 -0
- package/src/instrumentation.ts +2 -4
- package/src/prover/{bb_private_kernel_prover.ts → client/bb_private_kernel_prover.ts} +53 -29
- package/src/prover/{bb_native_private_kernel_prover.ts → client/native/bb_native_private_kernel_prover.ts} +23 -37
- package/src/{wasm → prover/client/wasm}/bb_wasm_private_kernel_prover.ts +18 -15
- package/src/{wasm → prover/client/wasm}/bundle.ts +3 -3
- package/src/{wasm → prover/client/wasm}/lazy.ts +3 -3
- package/src/prover/index.ts +2 -3
- package/src/prover/proof_utils.ts +115 -0
- package/src/prover/server/bb_prover.ts +733 -0
- package/src/test/delay_values.ts +30 -18
- package/src/test/test_circuit_prover.ts +260 -147
- package/src/test/test_verifier.ts +7 -3
- package/src/verification_key/verification_key_data.ts +29 -24
- package/src/verifier/bb_verifier.ts +60 -32
- package/src/verifier/index.ts +1 -0
- package/src/verifier/queued_chonk_verifier.ts +140 -0
- package/dest/prover/bb_native_private_kernel_prover.d.ts +0 -25
- package/dest/prover/bb_native_private_kernel_prover.d.ts.map +0 -1
- package/dest/prover/bb_private_kernel_prover.d.ts.map +0 -1
- package/dest/prover/bb_prover.d.ts +0 -120
- package/dest/prover/bb_prover.d.ts.map +0 -1
- package/dest/prover/bb_prover.js +0 -423
- package/dest/prover/client_ivc_proof_utils.d.ts +0 -25
- package/dest/prover/client_ivc_proof_utils.d.ts.map +0 -1
- package/dest/prover/client_ivc_proof_utils.js +0 -43
- package/dest/stats.d.ts +0 -5
- package/dest/stats.d.ts.map +0 -1
- package/dest/stats.js +0 -62
- package/dest/wasm/bb_wasm_private_kernel_prover.d.ts +0 -17
- package/dest/wasm/bb_wasm_private_kernel_prover.d.ts.map +0 -1
- package/dest/wasm/bb_wasm_private_kernel_prover.js +0 -46
- package/dest/wasm/bundle.d.ts +0 -6
- package/dest/wasm/bundle.d.ts.map +0 -1
- package/dest/wasm/lazy.d.ts +0 -6
- package/dest/wasm/lazy.d.ts.map +0 -1
- package/src/prover/bb_prover.ts +0 -781
- package/src/prover/client_ivc_proof_utils.ts +0 -42
- package/src/stats.ts +0 -64
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
import { PublicTxSimulationTester, type TestEnqueuedCall } from '@aztec/simulator/public/fixtures';
|
|
2
|
-
import {
|
|
3
|
-
import type
|
|
1
|
+
import { PublicTxSimulationTester, SimpleContractDataSource, type TestEnqueuedCall, type TestExecutorMetrics, type TestPrivateInsertions } from '@aztec/simulator/public/fixtures';
|
|
2
|
+
import type { PublicTxResult } from '@aztec/simulator/server';
|
|
3
|
+
import { type AvmCircuitInputs, AvmCircuitPublicInputs } from '@aztec/stdlib/avm';
|
|
4
4
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
5
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
6
|
+
import type { GlobalVariables } from '@aztec/stdlib/tx';
|
|
7
|
+
import { NativeWorldStateService } from '@aztec/world-state';
|
|
6
8
|
import { type BBResult, type BBSuccess } from '../bb/execute.js';
|
|
7
9
|
export declare class AvmProvingTester extends PublicTxSimulationTester {
|
|
8
|
-
private bbWorkingDirectory;
|
|
9
10
|
private checkCircuitOnly;
|
|
10
|
-
constructor(bbWorkingDirectory: string, checkCircuitOnly: boolean, worldStateDB: WorldStateDB, contractDataSource: SimpleContractDataSource, merkleTrees: MerkleTreeWriteOperations);
|
|
11
|
-
static create(checkCircuitOnly?: boolean): Promise<AvmProvingTester>;
|
|
12
|
-
prove(avmCircuitInputs: AvmCircuitInputs): Promise<BBResult>;
|
|
13
|
-
verify(proofRes: BBSuccess): Promise<BBResult>;
|
|
14
|
-
simProveVerify(sender: AztecAddress, setupCalls: TestEnqueuedCall[], appCalls: TestEnqueuedCall[], teardownCall: TestEnqueuedCall | undefined, expectRevert: boolean | undefined, feePayer?: AztecAddress): Promise<void>;
|
|
15
|
-
simProveVerifyAppLogic(appCall: TestEnqueuedCall, expectRevert?: boolean): Promise<void>;
|
|
16
|
-
}
|
|
17
|
-
export declare class AvmProvingTesterV2 extends PublicTxSimulationTester {
|
|
18
11
|
private bbWorkingDirectory;
|
|
19
|
-
constructor(
|
|
20
|
-
static
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
constructor(checkCircuitOnly: boolean, contractDataSource: SimpleContractDataSource, merkleTrees: MerkleTreeWriteOperations, globals?: GlobalVariables, metrics?: TestExecutorMetrics);
|
|
13
|
+
static new(worldStateService: NativeWorldStateService, // make sure to close this later
|
|
14
|
+
checkCircuitOnly?: boolean, globals?: GlobalVariables, metrics?: TestExecutorMetrics): Promise<AvmProvingTester>;
|
|
15
|
+
prove(avmCircuitInputs: AvmCircuitInputs, txLabel?: string): Promise<BBResult>;
|
|
16
|
+
verify(proofRes: BBSuccess, publicInputs: AvmCircuitPublicInputs): Promise<BBResult>;
|
|
17
|
+
proveVerify(avmCircuitInputs: AvmCircuitInputs, txLabel?: string): Promise<void>;
|
|
18
|
+
simProveVerify(sender: AztecAddress, setupCalls: TestEnqueuedCall[], appCalls: TestEnqueuedCall[], teardownCall: TestEnqueuedCall | undefined, expectRevert: boolean | undefined, feePayer?: AztecAddress, privateInsertions?: TestPrivateInsertions, txLabel?: string, disableRevertCheck?: boolean): Promise<PublicTxResult>;
|
|
19
|
+
executeTxWithLabel(txLabel: string, sender: AztecAddress, setupCalls?: TestEnqueuedCall[], appCalls?: TestEnqueuedCall[], teardownCall?: TestEnqueuedCall, feePayer?: AztecAddress, privateInsertions?: TestPrivateInsertions): Promise<PublicTxResult>;
|
|
20
|
+
simProveVerifyAppLogic(appCall: TestEnqueuedCall, expectRevert?: boolean, txLabel?: string): Promise<void>;
|
|
24
21
|
}
|
|
25
22
|
//# sourceMappingURL=avm_proving_tester.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avm_proving_tester.d.ts","sourceRoot":"","sources":["../../src/avm_proving_tests/avm_proving_tester.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"avm_proving_tester.d.ts","sourceRoot":"","sources":["../../src/avm_proving_tests/avm_proving_tester.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC3B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,c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AAG,SAAS,EACjC,QAAQ,eAAS,EACjB,iBAAiB,CAAC,EAAE,qBAAqB,EACzC,OAAO,GAAE,MAAsB,EAC/B,kBAAkB,GAAE,OAAe,GAClC,OAAO,CAAC,cAAc,CAAC;IAyBJ,kBAAkB,CACtC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,YAAY,EACpB,UAAU,CAAC,EAAE,gBAAgB,EAAE,EAC/B,QAAQ,CAAC,EAAE,gBAAgB,EAAE,EAC7B,YAAY,CAAC,EAAE,gBAAgB,EAC/B,QAAQ,CAAC,EAAE,YAAY,EACvB,iBAAiB,CAAC,EAAE,qBAAqB;IAe9B,sBAAsB,CACjC,OAAO,EAAE,gBAAgB,EACzB,YAAY,CAAC,EAAE,OAAO,EACtB,OAAO,GAAE,MAAsB;CAalC"}
|
|
@@ -1,105 +1,155 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
2
|
+
import { PublicTxSimulationTester, SimpleContractDataSource } from '@aztec/simulator/public/fixtures';
|
|
3
3
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
-
import { makeAvmCircuitInputs } from '@aztec/stdlib/testing';
|
|
5
|
-
import { VerificationKeyData } from '@aztec/stdlib/vks';
|
|
6
|
-
import { NativeWorldStateService } from '@aztec/world-state';
|
|
7
4
|
import fs from 'node:fs/promises';
|
|
8
5
|
import { tmpdir } from 'node:os';
|
|
9
6
|
import path from 'path';
|
|
10
|
-
import { BB_RESULT,
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
import { BB_RESULT, VK_FILENAME, generateAvmProof, verifyAvmProof } from '../bb/execute.js';
|
|
8
|
+
const BB_PATH = path.resolve('../../barretenberg/cpp/build/bin/bb-avm');
|
|
9
|
+
// An InterceptingLogger that records all log messages and forwards them to a wrapped logger.
|
|
10
|
+
class InterceptingLogger {
|
|
11
|
+
logs = [];
|
|
12
|
+
level;
|
|
13
|
+
module;
|
|
14
|
+
logger;
|
|
15
|
+
constructor(logger){
|
|
16
|
+
this.logger = logger;
|
|
17
|
+
this.level = logger.level;
|
|
18
|
+
this.module = logger.module;
|
|
19
|
+
}
|
|
20
|
+
isLevelEnabled(level) {
|
|
21
|
+
return this.logger.isLevelEnabled(level);
|
|
22
|
+
}
|
|
23
|
+
createChild(_childModule) {
|
|
24
|
+
throw new Error('Not implemented');
|
|
25
|
+
}
|
|
26
|
+
intercept(level, msg, ...args) {
|
|
27
|
+
this.logs.push(...msg.split('\n'));
|
|
28
|
+
// Forward to the wrapped logger
|
|
29
|
+
this.logger[level](msg, ...args);
|
|
30
|
+
}
|
|
31
|
+
// Log methods for each level
|
|
32
|
+
silent(msg, ...args) {
|
|
33
|
+
this.intercept('silent', msg, ...args);
|
|
34
|
+
}
|
|
35
|
+
fatal(msg, ...args) {
|
|
36
|
+
this.intercept('fatal', msg, ...args);
|
|
37
|
+
}
|
|
38
|
+
warn(msg, ...args) {
|
|
39
|
+
this.intercept('warn', msg, ...args);
|
|
40
|
+
}
|
|
41
|
+
info(msg, ...args) {
|
|
42
|
+
this.intercept('info', msg, ...args);
|
|
43
|
+
}
|
|
44
|
+
verbose(msg, ...args) {
|
|
45
|
+
this.intercept('verbose', msg, ...args);
|
|
46
|
+
}
|
|
47
|
+
debug(msg, ...args) {
|
|
48
|
+
this.intercept('debug', msg, ...args);
|
|
49
|
+
}
|
|
50
|
+
trace(msg, ...args) {
|
|
51
|
+
this.intercept('trace', msg, ...args);
|
|
52
|
+
}
|
|
53
|
+
// Error log function can be string or Error
|
|
54
|
+
error(err, ...args) {
|
|
55
|
+
const msg = typeof err === 'string' ? err : err.message;
|
|
56
|
+
this.logs.push(msg);
|
|
57
|
+
this.logger.error(msg, err, ...args);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
13
60
|
export class AvmProvingTester extends PublicTxSimulationTester {
|
|
14
|
-
bbWorkingDirectory;
|
|
15
61
|
checkCircuitOnly;
|
|
16
|
-
|
|
17
|
-
|
|
62
|
+
bbWorkingDirectory;
|
|
63
|
+
constructor(checkCircuitOnly, contractDataSource, merkleTrees, globals, metrics){
|
|
64
|
+
super(merkleTrees, contractDataSource, globals, metrics), this.checkCircuitOnly = checkCircuitOnly, this.bbWorkingDirectory = '';
|
|
18
65
|
}
|
|
19
|
-
static async
|
|
20
|
-
const bbWorkingDirectory = await fs.mkdtemp(path.join(tmpdir(), 'bb-'));
|
|
66
|
+
static async new(worldStateService, checkCircuitOnly = false, globals, metrics) {
|
|
21
67
|
const contractDataSource = new SimpleContractDataSource();
|
|
22
|
-
const merkleTrees = await
|
|
23
|
-
|
|
24
|
-
return new AvmProvingTester(bbWorkingDirectory, checkCircuitOnly, worldStateDB, contractDataSource, merkleTrees);
|
|
68
|
+
const merkleTrees = await worldStateService.fork();
|
|
69
|
+
return new AvmProvingTester(checkCircuitOnly, contractDataSource, merkleTrees, globals, metrics);
|
|
25
70
|
}
|
|
26
|
-
async prove(avmCircuitInputs) {
|
|
71
|
+
async prove(avmCircuitInputs, txLabel = 'unlabeledTx') {
|
|
72
|
+
// We use a new working directory for each proof.
|
|
73
|
+
this.bbWorkingDirectory = await fs.mkdtemp(path.join(tmpdir(), 'bb-'));
|
|
74
|
+
const interceptingLogger = new InterceptingLogger(this.logger);
|
|
27
75
|
// Then we prove.
|
|
28
|
-
const proofRes = await generateAvmProof(BB_PATH, this.bbWorkingDirectory, avmCircuitInputs,
|
|
76
|
+
const proofRes = await generateAvmProof(BB_PATH, this.bbWorkingDirectory, avmCircuitInputs, interceptingLogger, this.checkCircuitOnly);
|
|
29
77
|
if (proofRes.status === BB_RESULT.FAILURE) {
|
|
30
78
|
this.logger.error(`Proof generation failed: ${proofRes.reason}`);
|
|
31
79
|
}
|
|
80
|
+
expect(proofRes.status).toEqual(BB_RESULT.SUCCESS);
|
|
81
|
+
// Parse the logs into a structured format.
|
|
82
|
+
const logs = interceptingLogger.logs;
|
|
83
|
+
// const traceSizes: { name: string; size: number }[] = [];
|
|
84
|
+
// logs.forEach(log => {
|
|
85
|
+
// const match = log.match(/\b(\w+): (\d+) \(~2/);
|
|
86
|
+
// if (match) {
|
|
87
|
+
// traceSizes.push({
|
|
88
|
+
// name: match[1],
|
|
89
|
+
// size: parseInt(match[2]),
|
|
90
|
+
// });
|
|
91
|
+
// }
|
|
92
|
+
// });
|
|
93
|
+
const times = {};
|
|
94
|
+
logs.forEach((log)=>{
|
|
95
|
+
const match = log.match(/\b([\w/]+)_ms: (\d+)/);
|
|
96
|
+
if (match) {
|
|
97
|
+
times[match[1]] = parseInt(match[2]);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
// Throw if logs did not contain any times.
|
|
101
|
+
if (Object.keys(times).length === 0) {
|
|
102
|
+
throw new Error('AVM stdout did not contain any proving times in the stats!');
|
|
103
|
+
}
|
|
104
|
+
// Hack to make labels match.
|
|
105
|
+
const txLabelWithCount = `${txLabel}/${this.txCount - 1}`;
|
|
106
|
+
// I need to cast because TS doesnt realize metrics is protected not private.
|
|
107
|
+
this.metrics?.recordProverMetrics(txLabelWithCount, {
|
|
108
|
+
proverSimulationStepMs: times['simulation/all'],
|
|
109
|
+
proverProvingStepMs: times['proving/all'],
|
|
110
|
+
proverTraceGenerationStepMs: times['tracegen/all'],
|
|
111
|
+
traceGenerationInteractionsMs: times['tracegen/interactions'],
|
|
112
|
+
traceGenerationTracesMs: times['tracegen/traces'],
|
|
113
|
+
provingSumcheckMs: times['prove/sumcheck'],
|
|
114
|
+
provingPcsMs: times['prove/pcs_rounds'],
|
|
115
|
+
provingLogDerivativeInverseMs: times['prove/log_derivative_inverse_round'],
|
|
116
|
+
provingLogDerivativeInverseCommitmentsMs: times['prove/log_derivative_inverse_commitments_round'],
|
|
117
|
+
provingWireCommitmentsMs: times['prove/wire_commitments_round']
|
|
118
|
+
});
|
|
32
119
|
return proofRes;
|
|
33
120
|
}
|
|
34
|
-
async verify(proofRes) {
|
|
121
|
+
async verify(proofRes, publicInputs) {
|
|
35
122
|
if (this.checkCircuitOnly) {
|
|
36
|
-
// Skip verification if we
|
|
37
|
-
// Check-circuit
|
|
123
|
+
// Skip verification if we are only checking the circuit.
|
|
124
|
+
// Check-circuit does not generate a proof to verify.
|
|
38
125
|
return proofRes;
|
|
39
126
|
}
|
|
40
|
-
|
|
41
|
-
const succeededRes = proofRes;
|
|
42
|
-
const vkData = await extractAvmVkData(succeededRes.vkPath);
|
|
43
|
-
VerificationKeyData.fromBuffer(vkData.toBuffer());
|
|
44
|
-
// Then we verify.
|
|
45
|
-
const rawVkPath = path.join(succeededRes.vkPath, 'vk');
|
|
46
|
-
return await verifyAvmProof(BB_PATH, succeededRes.proofPath, rawVkPath, this.logger);
|
|
47
|
-
}
|
|
48
|
-
async simProveVerify(sender, setupCalls, appCalls, teardownCall, expectRevert, feePayer = sender) {
|
|
49
|
-
const simRes = await this.simulateTx(sender, setupCalls, appCalls, teardownCall, feePayer);
|
|
50
|
-
expect(simRes.revertCode.isOK()).toBe(expectRevert ? false : true);
|
|
51
|
-
const avmCircuitInputs = simRes.avmProvingRequest.inputs;
|
|
52
|
-
const provingRes = await this.prove(avmCircuitInputs);
|
|
53
|
-
expect(provingRes.status).toEqual(BB_RESULT.SUCCESS);
|
|
54
|
-
const verificationRes = await this.verify(provingRes);
|
|
55
|
-
expect(verificationRes.status).toBe(BB_RESULT.SUCCESS);
|
|
127
|
+
return await verifyAvmProof(BB_PATH, this.bbWorkingDirectory, proofRes.proofPath, publicInputs, path.join(proofRes.vkDirectoryPath, VK_FILENAME), this.logger);
|
|
56
128
|
}
|
|
57
|
-
async
|
|
58
|
-
const
|
|
59
|
-
appCall
|
|
60
|
-
]);
|
|
61
|
-
expect(simRes.revertCode.isOK()).toBe(expectRevert ? false : true);
|
|
62
|
-
const avmCircuitInputs = simRes.avmProvingRequest.inputs;
|
|
63
|
-
const provingRes = await this.prove(avmCircuitInputs);
|
|
129
|
+
async proveVerify(avmCircuitInputs, txLabel = 'unlabeledTx') {
|
|
130
|
+
const provingRes = await this.prove(avmCircuitInputs, txLabel);
|
|
64
131
|
expect(provingRes.status).toEqual(BB_RESULT.SUCCESS);
|
|
65
|
-
const verificationRes = await this.verify(provingRes);
|
|
132
|
+
const verificationRes = await this.verify(provingRes, avmCircuitInputs.publicInputs);
|
|
66
133
|
expect(verificationRes.status).toBe(BB_RESULT.SUCCESS);
|
|
67
134
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
super(worldStateDB, contractDataSource, merkleTrees), this.bbWorkingDirectory = bbWorkingDirectory;
|
|
73
|
-
}
|
|
74
|
-
static async create() {
|
|
75
|
-
const bbWorkingDirectory = await fs.mkdtemp(path.join(tmpdir(), 'bb-'));
|
|
76
|
-
const contractDataSource = new SimpleContractDataSource();
|
|
77
|
-
const merkleTrees = await (await NativeWorldStateService.tmp()).fork();
|
|
78
|
-
const worldStateDB = new WorldStateDB(merkleTrees, contractDataSource);
|
|
79
|
-
return new AvmProvingTesterV2(bbWorkingDirectory, worldStateDB, contractDataSource, merkleTrees);
|
|
80
|
-
}
|
|
81
|
-
async proveV2(avmCircuitInputs) {
|
|
82
|
-
// Then we prove.
|
|
83
|
-
const proofRes = await generateAvmProofV2(BB_PATH, this.bbWorkingDirectory, avmCircuitInputs, this.logger);
|
|
84
|
-
if (proofRes.status === BB_RESULT.FAILURE) {
|
|
85
|
-
this.logger.error(`Proof generation failed: ${proofRes.reason}`);
|
|
135
|
+
async simProveVerify(sender, setupCalls, appCalls, teardownCall, expectRevert, feePayer = sender, privateInsertions, txLabel = 'unlabeledTx', disableRevertCheck = false) {
|
|
136
|
+
const simRes = await this.simulateTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions, txLabel);
|
|
137
|
+
if (!disableRevertCheck) {
|
|
138
|
+
expect(simRes.revertCode.isOK()).toBe(expectRevert ? false : true);
|
|
86
139
|
}
|
|
87
|
-
|
|
88
|
-
|
|
140
|
+
const opString = this.checkCircuitOnly ? 'Check circuit' : 'Proving and verification';
|
|
141
|
+
const avmCircuitInputs = simRes.avmProvingRequest.inputs;
|
|
142
|
+
const timer = new Timer();
|
|
143
|
+
await this.proveVerify(avmCircuitInputs, txLabel);
|
|
144
|
+
this.logger.info(`${opString} took ${timer.ms()} ms for tx ${txLabel}`);
|
|
145
|
+
return simRes;
|
|
89
146
|
}
|
|
90
|
-
async
|
|
91
|
-
|
|
92
|
-
const inputs = await makeAvmCircuitInputs();
|
|
93
|
-
const rawVkPath = path.join(proofRes.vkPath, 'vk');
|
|
94
|
-
return await verifyAvmProofV2(BB_PATH, this.bbWorkingDirectory, proofRes.proofPath, inputs.publicInputs, rawVkPath, this.logger);
|
|
147
|
+
async executeTxWithLabel(txLabel, sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions) {
|
|
148
|
+
return await this.simProveVerify(sender, setupCalls ?? [], appCalls ?? [], teardownCall, undefined, feePayer, privateInsertions, txLabel, true);
|
|
95
149
|
}
|
|
96
|
-
async
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const provingRes = await this.proveV2(avmCircuitInputs);
|
|
101
|
-
expect(provingRes.status).toEqual(BB_RESULT.SUCCESS);
|
|
102
|
-
const verificationRes = await this.verifyV2(provingRes);
|
|
103
|
-
expect(verificationRes.status).toBe(BB_RESULT.SUCCESS);
|
|
150
|
+
async simProveVerifyAppLogic(appCall, expectRevert, txLabel = 'unlabeledTx') {
|
|
151
|
+
await this.simProveVerify(/*sender=*/ AztecAddress.fromNumber(42), /*setupCalls=*/ [], [
|
|
152
|
+
appCall
|
|
153
|
+
], undefined, expectRevert, /*feePayer=*/ undefined, /*privateInsertions=*/ undefined, txLabel);
|
|
104
154
|
}
|
|
105
155
|
}
|
package/dest/bb/execute.d.ts
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
1
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
4
2
|
import type { AvmCircuitInputs, AvmCircuitPublicInputs } from '@aztec/stdlib/avm';
|
|
5
3
|
import type { UltraHonkFlavor } from '../honk.js';
|
|
6
4
|
export declare const VK_FILENAME = "vk";
|
|
7
|
-
export declare const
|
|
5
|
+
export declare const PUBLIC_INPUTS_FILENAME = "public_inputs";
|
|
8
6
|
export declare const PROOF_FILENAME = "proof";
|
|
9
|
-
export declare const PROOF_FIELDS_FILENAME = "proof_fields.json";
|
|
10
7
|
export declare const AVM_INPUTS_FILENAME = "avm_inputs.bin";
|
|
11
8
|
export declare const AVM_BYTECODE_FILENAME = "avm_bytecode.bin";
|
|
12
9
|
export declare const AVM_PUBLIC_INPUTS_FILENAME = "avm_public_inputs.bin";
|
|
13
|
-
export declare const AVM_HINTS_FILENAME = "avm_hints.bin";
|
|
14
10
|
export declare enum BB_RESULT {
|
|
15
11
|
SUCCESS = 0,
|
|
16
12
|
FAILURE = 1,
|
|
@@ -22,7 +18,7 @@ export type BBSuccess = {
|
|
|
22
18
|
/** Full path of the public key. */
|
|
23
19
|
pkPath?: string;
|
|
24
20
|
/** Base directory for the VKs (raw, fields). */
|
|
25
|
-
|
|
21
|
+
vkDirectoryPath?: string;
|
|
26
22
|
/** Full path of the proof. */
|
|
27
23
|
proofPath?: string;
|
|
28
24
|
/** Full path of the contract. */
|
|
@@ -36,7 +32,6 @@ export type BBFailure = {
|
|
|
36
32
|
retry?: boolean;
|
|
37
33
|
};
|
|
38
34
|
export type BBResult = BBSuccess | BBFailure;
|
|
39
|
-
export type VerificationFunction = typeof verifyProof | typeof verifyAvmProof;
|
|
40
35
|
type BBExecResult = {
|
|
41
36
|
status: BB_RESULT;
|
|
42
37
|
exitCode: number;
|
|
@@ -48,11 +43,12 @@ type BBExecResult = {
|
|
|
48
43
|
* @param command - The command to execute
|
|
49
44
|
* @param args - The arguments to pass
|
|
50
45
|
* @param logger - A log function
|
|
46
|
+
* @param timeout - An optional timeout before killing the BB process
|
|
51
47
|
* @param resultParser - An optional handler for detecting success or failure
|
|
52
48
|
* @returns The completed partial witness outputted from the circuit
|
|
53
49
|
*/
|
|
54
|
-
export declare function executeBB(pathToBB: string, command: string, args: string[], logger: LogFn, resultParser?: (code: number) =>
|
|
55
|
-
export declare function
|
|
50
|
+
export declare function executeBB(pathToBB: string, command: string, args: string[], logger: LogFn, concurrency?: number, timeout?: number, resultParser?: (code: number) => code is 0): Promise<BBExecResult>;
|
|
51
|
+
export declare function executeBbChonkProof(pathToBB: string, workingDirectory: string, inputsPath: string, log: LogFn, writeVk?: boolean): Promise<BBFailure | BBSuccess>;
|
|
56
52
|
/**
|
|
57
53
|
* Used for generating proofs of noir circuits.
|
|
58
54
|
* It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
|
|
@@ -64,39 +60,18 @@ export declare function executeBbClientIvcProof(pathToBB: string, workingDirecto
|
|
|
64
60
|
* @param log - A logging function
|
|
65
61
|
* @returns An object containing a result indication, the location of the proof and the duration taken
|
|
66
62
|
*/
|
|
67
|
-
export declare function generateProof(pathToBB: string, workingDirectory: string, circuitName: string, bytecode: Buffer,
|
|
68
|
-
/**
|
|
69
|
-
* Used for generating proofs of the tube circuit
|
|
70
|
-
* It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
|
|
71
|
-
* @param pathToBB - The full path to the bb binary
|
|
72
|
-
* @param workingDirectory - A working directory for use by bb
|
|
73
|
-
* @param circuitName - An identifier for the circuit
|
|
74
|
-
* @param bytecode - The compiled circuit bytecode
|
|
75
|
-
* @param inputWitnessFile - The circuit input witness
|
|
76
|
-
* @param log - A logging function
|
|
77
|
-
* @returns An object containing a result indication, the location of the proof and the duration taken
|
|
78
|
-
*/
|
|
79
|
-
export declare function generateTubeProof(pathToBB: string, workingDirectory: string, log: LogFn): Promise<BBFailure | BBSuccess>;
|
|
63
|
+
export declare function generateProof(pathToBB: string, workingDirectory: string, circuitName: string, bytecode: Buffer, verificationKey: Buffer, inputWitnessFile: string, flavor: UltraHonkFlavor, log: Logger): Promise<BBFailure | BBSuccess>;
|
|
80
64
|
/**
|
|
81
65
|
* Used for generating AVM proofs.
|
|
82
66
|
* It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
|
|
83
67
|
* @param pathToBB - The full path to the bb binary
|
|
84
68
|
* @param workingDirectory - A working directory for use by bb
|
|
85
69
|
* @param input - The inputs for the public function to be proven
|
|
86
|
-
* @param
|
|
70
|
+
* @param logger - A logging function
|
|
71
|
+
* @param checkCircuitOnly - A boolean to toggle a "check-circuit only" operation instead of proving.
|
|
87
72
|
* @returns An object containing a result indication, the location of the proof and the duration taken
|
|
88
73
|
*/
|
|
89
|
-
export declare function
|
|
90
|
-
/**
|
|
91
|
-
* Used for generating AVM proofs (or doing check-circuit).
|
|
92
|
-
* It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
|
|
93
|
-
* @param pathToBB - The full path to the bb binary
|
|
94
|
-
* @param workingDirectory - A working directory for use by bb
|
|
95
|
-
* @param bytecode - The AVM bytecode for the public function to be proven (expected to be decompressed)
|
|
96
|
-
* @param log - A logging function
|
|
97
|
-
* @returns An object containing a result indication, the location of the proof and the duration taken
|
|
98
|
-
*/
|
|
99
|
-
export declare function generateAvmProof(pathToBB: string, workingDirectory: string, _input: AvmCircuitInputs, logger: Logger, checkCircuitOnly?: boolean): Promise<BBFailure | BBSuccess>;
|
|
74
|
+
export declare function generateAvmProof(pathToBB: string, workingDirectory: string, input: AvmCircuitInputs, logger: Logger, checkCircuitOnly?: boolean): Promise<BBFailure | BBSuccess>;
|
|
100
75
|
/**
|
|
101
76
|
* Used for verifying proofs of noir circuits
|
|
102
77
|
* @param pathToBB - The full path to the bb binary
|
|
@@ -106,25 +81,17 @@ export declare function generateAvmProof(pathToBB: string, workingDirectory: str
|
|
|
106
81
|
* @returns An object containing a result indication and duration taken
|
|
107
82
|
*/
|
|
108
83
|
export declare function verifyProof(pathToBB: string, proofFullPath: string, verificationKeyPath: string, ultraHonkFlavor: UltraHonkFlavor, log: Logger): Promise<BBFailure | BBSuccess>;
|
|
84
|
+
export declare function verifyAvmProof(pathToBB: string, workingDirectory: string, proofFullPath: string, publicInputs: AvmCircuitPublicInputs, verificationKeyPath: string, logger: Logger): Promise<BBFailure | BBSuccess>;
|
|
109
85
|
/**
|
|
110
|
-
*
|
|
111
|
-
* @param pathToBB - The full path to the bb binary
|
|
112
|
-
* @param proofFullPath - The full path to the proof to be verified
|
|
113
|
-
* @param verificationKeyPath - The full path to the circuit verification key
|
|
114
|
-
* @param log - A logging function
|
|
115
|
-
* @returns An object containing a result indication and duration taken
|
|
116
|
-
*/
|
|
117
|
-
export declare function verifyAvmProof(pathToBB: string, proofFullPath: string, verificationKeyPath: string, logger: Logger): Promise<BBFailure | BBSuccess>;
|
|
118
|
-
export declare function verifyAvmProofV2(pathToBB: string, workingDirectory: string, proofFullPath: string, publicInputs: AvmCircuitPublicInputs, verificationKeyPath: string, logger: Logger): Promise<BBFailure | BBSuccess>;
|
|
119
|
-
/**
|
|
120
|
-
* Verifies a ClientIvcProof
|
|
86
|
+
* Verifies a ChonkProof
|
|
121
87
|
* TODO(#7370) The verification keys should be supplied separately
|
|
122
88
|
* @param pathToBB - The full path to the bb binary
|
|
123
89
|
* @param targetPath - The path to the folder with the proof, accumulator, and verification keys
|
|
124
90
|
* @param log - A logging function
|
|
91
|
+
* @param concurrency - The number of threads to use for the verification
|
|
125
92
|
* @returns An object containing a result indication and duration taken
|
|
126
93
|
*/
|
|
127
|
-
export declare function
|
|
94
|
+
export declare function verifyChonkProof(pathToBB: string, proofPath: string, keyPath: string, log: LogFn, concurrency?: number): Promise<BBFailure | BBSuccess>;
|
|
128
95
|
export declare function generateContractForVerificationKey(pathToBB: string, vkFilePath: string, contractPath: string, log: LogFn): Promise<BBFailure | BBSuccess>;
|
|
129
96
|
/**
|
|
130
97
|
* Compute bb gate count for a given circuit
|
package/dest/bb/execute.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/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