@aztec/bb-prover 0.0.0-test.1 → 0.0.1-commit.017a351

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.
Files changed (130) hide show
  1. package/dest/avm_proving_tests/avm_proving_tester.d.ts +21 -20
  2. package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
  3. package/dest/avm_proving_tests/avm_proving_tester.js +196 -87
  4. package/dest/bb/bb_js_backend.d.ts +196 -0
  5. package/dest/bb/bb_js_backend.d.ts.map +1 -0
  6. package/dest/bb/bb_js_backend.js +379 -0
  7. package/dest/bb/bb_js_debug.d.ts +52 -0
  8. package/dest/bb/bb_js_debug.d.ts.map +1 -0
  9. package/dest/bb/bb_js_debug.js +176 -0
  10. package/dest/bb/cli.d.ts +1 -1
  11. package/dest/bb/file_names.d.ts +4 -0
  12. package/dest/bb/file_names.d.ts.map +1 -0
  13. package/dest/bb/file_names.js +5 -0
  14. package/dest/bb/index.d.ts +1 -1
  15. package/dest/config.d.ts +19 -1
  16. package/dest/config.d.ts.map +1 -1
  17. package/dest/honk.d.ts +3 -3
  18. package/dest/honk.d.ts.map +1 -1
  19. package/dest/honk.js +3 -2
  20. package/dest/index.d.ts +4 -2
  21. package/dest/index.d.ts.map +1 -1
  22. package/dest/index.js +3 -1
  23. package/dest/instrumentation.d.ts +3 -3
  24. package/dest/instrumentation.d.ts.map +1 -1
  25. package/dest/instrumentation.js +22 -46
  26. package/dest/prover/client/bb_private_kernel_prover.d.ts +46 -0
  27. package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -0
  28. package/dest/prover/client/bb_private_kernel_prover.js +177 -0
  29. package/dest/prover/client/bundle.d.ts +6 -0
  30. package/dest/prover/client/bundle.d.ts.map +1 -0
  31. package/dest/prover/client/bundle.js +7 -0
  32. package/dest/prover/client/lazy.d.ts +6 -0
  33. package/dest/prover/client/lazy.d.ts.map +1 -0
  34. package/dest/prover/client/lazy.js +7 -0
  35. package/dest/prover/index.d.ts +3 -4
  36. package/dest/prover/index.d.ts.map +1 -1
  37. package/dest/prover/index.js +2 -3
  38. package/dest/prover/proof_utils.d.ts +29 -0
  39. package/dest/prover/proof_utils.d.ts.map +1 -0
  40. package/dest/prover/proof_utils.js +95 -0
  41. package/dest/prover/server/bb_prover.d.ts +96 -0
  42. package/dest/prover/server/bb_prover.d.ts.map +1 -0
  43. package/dest/prover/server/bb_prover.js +841 -0
  44. package/dest/test/delay_values.d.ts +1 -1
  45. package/dest/test/delay_values.d.ts.map +1 -1
  46. package/dest/test/delay_values.js +37 -23
  47. package/dest/test/index.d.ts +2 -1
  48. package/dest/test/index.d.ts.map +1 -1
  49. package/dest/test/index.js +1 -0
  50. package/dest/test/test_circuit_prover.d.ts +27 -36
  51. package/dest/test/test_circuit_prover.d.ts.map +1 -1
  52. package/dest/test/test_circuit_prover.js +517 -88
  53. package/dest/test/test_verifier.d.ts +6 -3
  54. package/dest/test/test_verifier.d.ts.map +1 -1
  55. package/dest/test/test_verifier.js +23 -1
  56. package/dest/verification_key/verification_key_data.d.ts +1 -2
  57. package/dest/verification_key/verification_key_data.d.ts.map +1 -1
  58. package/dest/verification_key/verification_key_data.js +9 -34
  59. package/dest/verifier/batch_chonk_verifier.d.ts +56 -0
  60. package/dest/verifier/batch_chonk_verifier.d.ts.map +1 -0
  61. package/dest/verifier/batch_chonk_verifier.js +384 -0
  62. package/dest/verifier/bb_verifier.d.ts +9 -5
  63. package/dest/verifier/bb_verifier.d.ts.map +1 -1
  64. package/dest/verifier/bb_verifier.js +156 -49
  65. package/dest/verifier/index.d.ts +3 -1
  66. package/dest/verifier/index.d.ts.map +1 -1
  67. package/dest/verifier/index.js +2 -0
  68. package/dest/verifier/queued_chonk_verifier.d.ts +14 -0
  69. package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -0
  70. package/dest/verifier/queued_chonk_verifier.js +102 -0
  71. package/package.json +38 -34
  72. package/src/avm_proving_tests/avm_proving_tester.ts +163 -126
  73. package/src/bb/bb_js_backend.ts +435 -0
  74. package/src/bb/bb_js_debug.ts +227 -0
  75. package/src/bb/file_names.ts +6 -0
  76. package/src/config.ts +18 -0
  77. package/src/honk.ts +3 -2
  78. package/src/index.ts +3 -1
  79. package/src/instrumentation.ts +22 -47
  80. package/src/prover/client/bb_private_kernel_prover.ts +423 -0
  81. package/src/prover/client/bundle.ts +10 -0
  82. package/src/prover/client/lazy.ts +10 -0
  83. package/src/prover/index.ts +2 -3
  84. package/src/prover/proof_utils.ts +155 -0
  85. package/src/prover/server/bb_prover.ts +713 -0
  86. package/src/test/delay_values.ts +38 -22
  87. package/src/test/index.ts +1 -0
  88. package/src/test/test_circuit_prover.ts +264 -154
  89. package/src/test/test_verifier.ts +15 -3
  90. package/src/verification_key/verification_key_data.ts +11 -31
  91. package/src/verifier/batch_chonk_verifier.ts +415 -0
  92. package/src/verifier/bb_verifier.ts +93 -76
  93. package/src/verifier/index.ts +2 -0
  94. package/src/verifier/queued_chonk_verifier.ts +108 -0
  95. package/dest/bb/execute.d.ts +0 -140
  96. package/dest/bb/execute.d.ts.map +0 -1
  97. package/dest/bb/execute.js +0 -780
  98. package/dest/prover/bb_native_private_kernel_prover.d.ts +0 -25
  99. package/dest/prover/bb_native_private_kernel_prover.d.ts.map +0 -1
  100. package/dest/prover/bb_native_private_kernel_prover.js +0 -69
  101. package/dest/prover/bb_private_kernel_prover.d.ts +0 -32
  102. package/dest/prover/bb_private_kernel_prover.d.ts.map +0 -1
  103. package/dest/prover/bb_private_kernel_prover.js +0 -109
  104. package/dest/prover/bb_prover.d.ts +0 -120
  105. package/dest/prover/bb_prover.d.ts.map +0 -1
  106. package/dest/prover/bb_prover.js +0 -423
  107. package/dest/prover/client_ivc_proof_utils.d.ts +0 -25
  108. package/dest/prover/client_ivc_proof_utils.d.ts.map +0 -1
  109. package/dest/prover/client_ivc_proof_utils.js +0 -43
  110. package/dest/stats.d.ts +0 -5
  111. package/dest/stats.d.ts.map +0 -1
  112. package/dest/stats.js +0 -62
  113. package/dest/wasm/bb_wasm_private_kernel_prover.d.ts +0 -17
  114. package/dest/wasm/bb_wasm_private_kernel_prover.d.ts.map +0 -1
  115. package/dest/wasm/bb_wasm_private_kernel_prover.js +0 -46
  116. package/dest/wasm/bundle.d.ts +0 -6
  117. package/dest/wasm/bundle.d.ts.map +0 -1
  118. package/dest/wasm/bundle.js +0 -8
  119. package/dest/wasm/lazy.d.ts +0 -6
  120. package/dest/wasm/lazy.d.ts.map +0 -1
  121. package/dest/wasm/lazy.js +0 -8
  122. package/src/bb/execute.ts +0 -853
  123. package/src/prover/bb_native_private_kernel_prover.ts +0 -119
  124. package/src/prover/bb_private_kernel_prover.ts +0 -249
  125. package/src/prover/bb_prover.ts +0 -781
  126. package/src/prover/client_ivc_proof_utils.ts +0 -42
  127. package/src/stats.ts +0 -64
  128. package/src/wasm/bb_wasm_private_kernel_prover.ts +0 -55
  129. package/src/wasm/bundle.ts +0 -11
  130. package/src/wasm/lazy.ts +0 -11
@@ -1,114 +1,131 @@
1
- import { runInDirectory } from '@aztec/foundation/fs';
2
1
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
- import { ServerCircuitVks } from '@aztec/noir-protocol-circuits-types/server/vks';
4
- import type { ClientProtocolArtifact, ServerProtocolArtifact } from '@aztec/noir-protocol-circuits-types/types';
5
- import type { ClientProtocolCircuitVerifier } from '@aztec/stdlib/interfaces/server';
2
+ import { Timer } from '@aztec/foundation/timer';
3
+ import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types/server/vks';
4
+ import {
5
+ type ClientProtocolArtifact,
6
+ type ProtocolArtifact,
7
+ type ServerProtocolArtifact,
8
+ mapProtocolArtifactNameToCircuitName,
9
+ } from '@aztec/noir-protocol-circuits-types/types';
10
+ import type { ClientProtocolCircuitVerifier, IVCProofVerificationResult } from '@aztec/stdlib/interfaces/server';
6
11
  import type { Proof } from '@aztec/stdlib/proofs';
7
12
  import type { CircuitVerificationStats } from '@aztec/stdlib/stats';
8
13
  import { Tx } from '@aztec/stdlib/tx';
9
14
  import type { VerificationKeyData } from '@aztec/stdlib/vks';
10
15
 
11
16
  import { promises as fs } from 'fs';
12
- import * as path from 'path';
13
17
 
14
- import { BB_RESULT, PROOF_FILENAME, VK_FILENAME, verifyClientIvcProof, verifyProof } from '../bb/execute.js';
18
+ import { BBJsFactory } from '../bb/bb_js_backend.js';
15
19
  import type { BBConfig } from '../config.js';
16
20
  import { getUltraHonkFlavorForCircuit } from '../honk.js';
17
- import { writeToOutputDirectory } from '../prover/client_ivc_proof_utils.js';
18
- import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
19
21
 
20
22
  export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
21
- private constructor(private config: BBConfig, private logger: Logger) {}
23
+ private bbJsFactory: BBJsFactory;
24
+
25
+ private constructor(
26
+ private config: BBConfig,
27
+ private logger: Logger,
28
+ ) {
29
+ // BB_NUM_IVC_VERIFIERS bounds the number of long-lived bb processes the pool keeps alive.
30
+ // If 0, fall back to spawning a fresh bb per verification.
31
+ this.bbJsFactory = new BBJsFactory(config.bbBinaryPath, {
32
+ poolSize: config.numConcurrentIVCVerifiers > 0 ? config.numConcurrentIVCVerifiers : undefined,
33
+ logger,
34
+ debugDir: config.bbDebugOutputDir,
35
+ });
36
+ }
37
+
38
+ public stop(): Promise<void> {
39
+ return this.bbJsFactory.destroy();
40
+ }
22
41
 
23
42
  public static async new(config: BBConfig, logger = createLogger('bb-prover:verifier')) {
43
+ if (!config.bbWorkingDirectory) {
44
+ throw new Error(`Barretenberg working directory (BB_WORKING_DIRECTORY) is not set`);
45
+ }
24
46
  await fs.mkdir(config.bbWorkingDirectory, { recursive: true });
25
47
  return new BBCircuitVerifier(config, logger);
26
48
  }
27
49
 
28
- public getVerificationKeyData(circuitType: ServerProtocolArtifact): VerificationKeyData {
29
- const vk = ServerCircuitVks[circuitType];
50
+ public getVerificationKeyData(circuit: ProtocolArtifact): VerificationKeyData {
51
+ const vk = ProtocolCircuitVks[circuit];
30
52
  if (vk === undefined) {
31
- throw new Error('Could not find VK for server artifact ' + circuitType);
53
+ throw new Error(`Could not find VK for artifact ${circuit}`);
32
54
  }
33
55
  return vk;
34
56
  }
35
57
 
58
+ /** Verify an UltraHonk proof via bb.js API (no temp files). */
36
59
  public async verifyProofForCircuit(circuit: ServerProtocolArtifact, proof: Proof) {
37
- const operation = async (bbWorkingDirectory: string) => {
38
- const proofFileName = path.join(bbWorkingDirectory, PROOF_FILENAME);
39
- const verificationKeyPath = path.join(bbWorkingDirectory, VK_FILENAME);
40
- const verificationKey = this.getVerificationKeyData(circuit);
60
+ const verificationKey = this.getVerificationKeyData(circuit);
61
+ const flavor = getUltraHonkFlavorForCircuit(circuit);
62
+
63
+ this.logger.debug(`${circuit} Verifying with key: ${verificationKey.keyAsFields.hash.toString()}`);
64
+
65
+ // Split proof buffer into public input fields and proof fields (32-byte each)
66
+ const publicInputFields = splitBufferToFieldArrays(proof.buffer.subarray(0, proof.numPublicInputs * 32));
67
+ const proofFields = splitBufferToFieldArrays(proof.buffer.subarray(proof.numPublicInputs * 32));
68
+
69
+ await using instance = await this.bbJsFactory.getInstance();
70
+ const { verified, durationMs } = await instance.verifyProof(
71
+ proofFields,
72
+ verificationKey.keyAsBytes,
73
+ publicInputFields,
74
+ flavor,
75
+ );
76
+
77
+ if (!verified) {
78
+ throw new Error(`Failed to verify ${circuit} proof!`);
79
+ }
41
80
 
42
- this.logger.debug(`${circuit} Verifying with key: ${verificationKey.keyAsFields.hash.toString()}`);
81
+ this.logger.debug(`${circuit} verification successful`, {
82
+ circuitName: mapProtocolArtifactNameToCircuitName(circuit),
83
+ duration: durationMs,
84
+ eventName: 'circuit-verification',
85
+ proofType: 'ultra-honk',
86
+ } satisfies CircuitVerificationStats);
87
+ }
88
+
89
+ /** Verify a Chonk (IVC) proof from a transaction via bb.js API. */
90
+ public async verifyProof(tx: Tx): Promise<IVCProofVerificationResult> {
91
+ const proofType = 'Chonk';
92
+ try {
93
+ const totalTimer = new Timer();
94
+
95
+ const circuit: ClientProtocolArtifact = tx.data.forPublic ? 'HidingKernelToPublic' : 'HidingKernelToRollup';
96
+ const verificationKey = this.getVerificationKeyData(circuit);
43
97
 
44
- await fs.writeFile(proofFileName, proof.buffer);
45
- await fs.writeFile(verificationKeyPath, verificationKey.keyAsBytes);
98
+ // Reconstruct the full proof with public inputs prepended, then convert Fr[] to Uint8Array[]
99
+ const proofWithPubInputs = tx.chonkProof.attachPublicInputs(tx.data.publicInputs().toFields());
100
+ const fieldsAsBuffers = proofWithPubInputs.fieldsWithPublicInputs.map(f => new Uint8Array(f.toBuffer()));
46
101
 
47
- const result = await verifyProof(
48
- this.config.bbBinaryPath,
49
- proofFileName,
50
- verificationKeyPath!,
51
- getUltraHonkFlavorForCircuit(circuit),
52
- this.logger,
53
- );
102
+ await using instance = await this.bbJsFactory.getInstance();
103
+ const { verified, durationMs } = await instance.verifyChonkProof(fieldsAsBuffers, verificationKey.keyAsBytes);
54
104
 
55
- if (result.status === BB_RESULT.FAILURE) {
56
- const errorMessage = `Failed to verify ${circuit} proof!`;
57
- throw new Error(errorMessage);
105
+ if (!verified) {
106
+ throw new Error(`Failed to verify ${proofType} proof for ${circuit}!`);
58
107
  }
59
108
 
60
- this.logger.debug(`${circuit} verification successful`, {
109
+ this.logger.debug(`${proofType} verification successful`, {
61
110
  circuitName: mapProtocolArtifactNameToCircuitName(circuit),
62
- duration: result.durationMs,
111
+ duration: durationMs,
63
112
  eventName: 'circuit-verification',
64
- proofType: 'ultra-honk',
113
+ proofType: 'chonk',
65
114
  } satisfies CircuitVerificationStats);
66
- };
67
- await runInDirectory(this.config.bbWorkingDirectory, operation, this.config.bbSkipCleanup, this.logger);
68
- }
69
115
 
70
- public async verifyProof(tx: Tx): Promise<boolean> {
71
- try {
72
- // TODO(#7370) The verification keys should be supplied separately and based on the expectedCircuit
73
- // rather than read from the tx object itself. We also need the vks for the translator and ecc, which
74
- // are not being saved along the other vks yet. Reuse the 'verifyProofForCircuit' method above once
75
- // we have all the verification keys available.
76
- const expectedCircuit: ClientProtocolArtifact = tx.data.forPublic
77
- ? 'PrivateKernelTailToPublicArtifact'
78
- : 'PrivateKernelTailArtifact';
79
- const circuit = 'ClientIVC';
80
-
81
- // Block below is almost copy-pasted from verifyProofForCircuit
82
- const operation = async (bbWorkingDirectory: string) => {
83
- const logFunction = (message: string) => {
84
- this.logger.debug(`${circuit} BB out - ${message}`);
85
- };
86
-
87
- await writeToOutputDirectory(tx.clientIvcProof, bbWorkingDirectory);
88
- const result = await verifyClientIvcProof(
89
- this.config.bbBinaryPath,
90
- bbWorkingDirectory.concat('/proof'),
91
- bbWorkingDirectory.concat('/vk'),
92
- logFunction,
93
- );
94
-
95
- if (result.status === BB_RESULT.FAILURE) {
96
- const errorMessage = `Failed to verify ${circuit} proof!`;
97
- throw new Error(errorMessage);
98
- }
99
-
100
- this.logger.debug(`${circuit} verification successful`, {
101
- circuitName: mapProtocolArtifactNameToCircuitName(expectedCircuit),
102
- duration: result.durationMs,
103
- eventName: 'circuit-verification',
104
- proofType: 'client-ivc',
105
- } satisfies CircuitVerificationStats);
106
- };
107
- await runInDirectory(this.config.bbWorkingDirectory, operation, this.config.bbSkipCleanup, this.logger);
108
- return true;
116
+ return { valid: true, durationMs, totalDurationMs: totalTimer.ms() };
109
117
  } catch (err) {
110
- this.logger.warn(`Failed to verify ClientIVC proof for tx ${Tx.getHash(tx)}: ${String(err)}`);
111
- return false;
118
+ this.logger.warn(`Failed to verify ${proofType} proof for tx ${tx.getTxHash().toString()}: ${String(err)}`);
119
+ return { valid: false, durationMs: 0, totalDurationMs: 0 };
112
120
  }
113
121
  }
114
122
  }
123
+
124
+ /** Split a buffer into 32-byte Uint8Array field elements. */
125
+ function splitBufferToFieldArrays(buffer: Buffer): Uint8Array[] {
126
+ const fields: Uint8Array[] = [];
127
+ for (let i = 0; i < buffer.length; i += 32) {
128
+ fields.push(new Uint8Array(buffer.subarray(i, i + 32)));
129
+ }
130
+ return fields;
131
+ }
@@ -1 +1,3 @@
1
+ export * from './batch_chonk_verifier.js';
1
2
  export * from './bb_verifier.js';
3
+ export * from './queued_chonk_verifier.js';
@@ -0,0 +1,108 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+ import { SerialQueue } from '@aztec/foundation/queue';
3
+ import type { ClientProtocolCircuitVerifier, IVCProofVerificationResult } from '@aztec/stdlib/interfaces/server';
4
+ import type { Tx } from '@aztec/stdlib/tx';
5
+ import {
6
+ Attributes,
7
+ type BatchObservableResult,
8
+ type Histogram,
9
+ Metrics,
10
+ type ObservableGauge,
11
+ type TelemetryClient,
12
+ type UpDownCounter,
13
+ createUpDownCounterWithDefault,
14
+ getTelemetryClient,
15
+ } from '@aztec/telemetry-client';
16
+
17
+ import { createHistogram } from 'node:perf_hooks';
18
+
19
+ class IVCVerifierMetrics {
20
+ private ivcVerificationHistogram: Histogram;
21
+ private ivcTotalVerificationHistogram: Histogram;
22
+ private ivcFailureCount: UpDownCounter;
23
+ private localHistogramOk = createHistogram({
24
+ min: 1,
25
+ max: 5 * 60 * 1000, // 5 min
26
+ });
27
+ private localHistogramFails = createHistogram({
28
+ min: 1,
29
+ max: 5 * 60 * 1000, // 5 min
30
+ });
31
+
32
+ private aggDurationMetrics: Record<'min' | 'max' | 'p50' | 'p90' | 'avg', ObservableGauge>;
33
+
34
+ constructor(client: TelemetryClient, name = 'QueuedIVCVerifier') {
35
+ const meter = client.getMeter(name);
36
+
37
+ this.ivcVerificationHistogram = meter.createHistogram(Metrics.IVC_VERIFIER_TIME);
38
+
39
+ this.ivcTotalVerificationHistogram = meter.createHistogram(Metrics.IVC_VERIFIER_TOTAL_TIME);
40
+
41
+ this.ivcFailureCount = createUpDownCounterWithDefault(meter, Metrics.IVC_VERIFIER_FAILURE_COUNT);
42
+
43
+ this.aggDurationMetrics = {
44
+ avg: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_AVG),
45
+ max: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_MAX),
46
+ min: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_MIN),
47
+ p50: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_P50),
48
+ p90: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_P90),
49
+ };
50
+
51
+ meter.addBatchObservableCallback(this.aggregate, Object.values(this.aggDurationMetrics));
52
+ }
53
+
54
+ recordIVCVerification(result: IVCProofVerificationResult) {
55
+ this.ivcVerificationHistogram.record(Math.ceil(result.durationMs), { [Attributes.OK]: result.valid });
56
+ this.ivcTotalVerificationHistogram.record(Math.ceil(result.totalDurationMs), { [Attributes.OK]: result.valid });
57
+ if (!result.valid) {
58
+ this.ivcFailureCount.add(1);
59
+ this.localHistogramFails.record(Math.max(Math.ceil(result.durationMs), 1));
60
+ } else {
61
+ this.localHistogramOk.record(Math.max(Math.ceil(result.durationMs), 1));
62
+ }
63
+ }
64
+
65
+ private aggregate = (res: BatchObservableResult) => {
66
+ for (const [histogram, ok] of [
67
+ [this.localHistogramOk, true],
68
+ [this.localHistogramFails, false],
69
+ ] as const) {
70
+ if (histogram.count === 0) {
71
+ continue;
72
+ }
73
+ res.observe(this.aggDurationMetrics.avg, histogram.mean, { [Attributes.OK]: ok });
74
+ res.observe(this.aggDurationMetrics.max, histogram.max, { [Attributes.OK]: ok });
75
+ res.observe(this.aggDurationMetrics.min, histogram.min, { [Attributes.OK]: ok });
76
+ res.observe(this.aggDurationMetrics.p50, histogram.percentile(50), { [Attributes.OK]: ok });
77
+ res.observe(this.aggDurationMetrics.p90, histogram.percentile(90), { [Attributes.OK]: ok });
78
+ }
79
+ };
80
+ }
81
+
82
+ export class QueuedIVCVerifier implements ClientProtocolCircuitVerifier {
83
+ private queue: SerialQueue;
84
+ private metrics: IVCVerifierMetrics;
85
+
86
+ public constructor(
87
+ private verifier: ClientProtocolCircuitVerifier,
88
+ concurrency: number,
89
+ private telemetry: TelemetryClient = getTelemetryClient(),
90
+ private logger = createLogger('bb-prover:queued_chonk_verifier'),
91
+ ) {
92
+ this.metrics = new IVCVerifierMetrics(this.telemetry, 'QueuedIVCVerifier');
93
+ this.queue = new SerialQueue();
94
+ this.logger.info(`Starting QueuedIVCVerifier with ${concurrency} concurrent verifiers`);
95
+ this.queue.start(concurrency);
96
+ }
97
+
98
+ public async verifyProof(tx: Tx): Promise<IVCProofVerificationResult> {
99
+ const result = await this.queue.put(() => this.verifier.verifyProof(tx));
100
+ this.metrics.recordIVCVerification(result);
101
+ return result;
102
+ }
103
+
104
+ async stop(): Promise<void> {
105
+ await this.queue.end();
106
+ await this.verifier.stop();
107
+ }
108
+ }
@@ -1,140 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- import type { LogFn, Logger } from '@aztec/foundation/log';
4
- import type { AvmCircuitInputs, AvmCircuitPublicInputs } from '@aztec/stdlib/avm';
5
- import type { UltraHonkFlavor } from '../honk.js';
6
- export declare const VK_FILENAME = "vk";
7
- export declare const VK_FIELDS_FILENAME = "vk_fields.json";
8
- export declare const PROOF_FILENAME = "proof";
9
- export declare const PROOF_FIELDS_FILENAME = "proof_fields.json";
10
- export declare const AVM_INPUTS_FILENAME = "avm_inputs.bin";
11
- export declare const AVM_BYTECODE_FILENAME = "avm_bytecode.bin";
12
- export declare const AVM_PUBLIC_INPUTS_FILENAME = "avm_public_inputs.bin";
13
- export declare const AVM_HINTS_FILENAME = "avm_hints.bin";
14
- export declare enum BB_RESULT {
15
- SUCCESS = 0,
16
- FAILURE = 1,
17
- ALREADY_PRESENT = 2
18
- }
19
- export type BBSuccess = {
20
- status: BB_RESULT.SUCCESS | BB_RESULT.ALREADY_PRESENT;
21
- durationMs: number;
22
- /** Full path of the public key. */
23
- pkPath?: string;
24
- /** Base directory for the VKs (raw, fields). */
25
- vkPath?: string;
26
- /** Full path of the proof. */
27
- proofPath?: string;
28
- /** Full path of the contract. */
29
- contractPath?: string;
30
- /** The number of gates in the circuit. */
31
- circuitSize?: number;
32
- };
33
- export type BBFailure = {
34
- status: BB_RESULT.FAILURE;
35
- reason: string;
36
- retry?: boolean;
37
- };
38
- export type BBResult = BBSuccess | BBFailure;
39
- export type VerificationFunction = typeof verifyProof | typeof verifyAvmProof;
40
- type BBExecResult = {
41
- status: BB_RESULT;
42
- exitCode: number;
43
- signal: string | undefined;
44
- };
45
- /**
46
- * Invokes the Barretenberg binary with the provided command and args
47
- * @param pathToBB - The path to the BB binary
48
- * @param command - The command to execute
49
- * @param args - The arguments to pass
50
- * @param logger - A log function
51
- * @param resultParser - An optional handler for detecting success or failure
52
- * @returns The completed partial witness outputted from the circuit
53
- */
54
- export declare function executeBB(pathToBB: string, command: string, args: string[], logger: LogFn, resultParser?: (code: number) => boolean): Promise<BBExecResult>;
55
- export declare function executeBbClientIvcProof(pathToBB: string, workingDirectory: string, bytecodeStackPath: string, witnessStackPath: string, log: LogFn): Promise<BBFailure | BBSuccess>;
56
- /**
57
- * Used for generating proofs of noir circuits.
58
- * It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
59
- * @param pathToBB - The full path to the bb binary
60
- * @param workingDirectory - A working directory for use by bb
61
- * @param circuitName - An identifier for the circuit
62
- * @param bytecode - The compiled circuit bytecode
63
- * @param inputWitnessFile - The circuit input witness
64
- * @param log - A logging function
65
- * @returns An object containing a result indication, the location of the proof and the duration taken
66
- */
67
- export declare function generateProof(pathToBB: string, workingDirectory: string, circuitName: string, bytecode: Buffer, recursive: boolean, inputWitnessFile: string, flavor: UltraHonkFlavor, log: LogFn): Promise<BBFailure | BBSuccess>;
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>;
80
- /**
81
- * Used for generating AVM proofs.
82
- * It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
83
- * @param pathToBB - The full path to the bb binary
84
- * @param workingDirectory - A working directory for use by bb
85
- * @param input - The inputs for the public function to be proven
86
- * @param log - A logging function
87
- * @returns An object containing a result indication, the location of the proof and the duration taken
88
- */
89
- export declare function generateAvmProofV2(pathToBB: string, workingDirectory: string, input: AvmCircuitInputs, logger: Logger): Promise<BBFailure | BBSuccess>;
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>;
100
- /**
101
- * Used for verifying proofs of noir circuits
102
- * @param pathToBB - The full path to the bb binary
103
- * @param proofFullPath - The full path to the proof to be verified
104
- * @param verificationKeyPath - The full path to the circuit verification key
105
- * @param log - A logging function
106
- * @returns An object containing a result indication and duration taken
107
- */
108
- export declare function verifyProof(pathToBB: string, proofFullPath: string, verificationKeyPath: string, ultraHonkFlavor: UltraHonkFlavor, log: Logger): Promise<BBFailure | BBSuccess>;
109
- /**
110
- * Used for verifying proofs of the AVM
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
121
- * TODO(#7370) The verification keys should be supplied separately
122
- * @param pathToBB - The full path to the bb binary
123
- * @param targetPath - The path to the folder with the proof, accumulator, and verification keys
124
- * @param log - A logging function
125
- * @returns An object containing a result indication and duration taken
126
- */
127
- export declare function verifyClientIvcProof(pathToBB: string, proofPath: string, keyPath: string, log: LogFn): Promise<BBFailure | BBSuccess>;
128
- export declare function generateContractForVerificationKey(pathToBB: string, vkFilePath: string, contractPath: string, log: LogFn): Promise<BBFailure | BBSuccess>;
129
- /**
130
- * Compute bb gate count for a given circuit
131
- * @param pathToBB - The full path to the bb binary
132
- * @param workingDirectory - A temporary directory for writing the bytecode
133
- * @param circuitName - The name of the circuit
134
- * @param bytecode - The bytecode of the circuit
135
- * @param flavor - The flavor of the backend - mega_honk or ultra_honk variants
136
- * @returns An object containing the status, gate count, and time taken
137
- */
138
- export declare function computeGateCountForCircuit(pathToBB: string, workingDirectory: string, circuitName: string, bytecode: Buffer, flavor: UltraHonkFlavor | 'mega_honk', log: LogFn): Promise<BBFailure | BBSuccess>;
139
- export {};
140
- //# sourceMappingURL=execute.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/bb/execute.ts"],"names":[],"mappings":";;AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAMlF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD,eAAO,MAAM,WAAW,OAAO,CAAC;AAChC,eAAO,MAAM,kBAAkB,mBAAmB,CAAC;AACnD,eAAO,MAAM,cAAc,UAAU,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