@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
package/src/honk.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { ServerProtocolArtifact } from '@aztec/noir-protocol-circuits-types/server';
2
2
 
3
- export type UltraHonkFlavor = 'ultra_honk' | 'ultra_keccak_honk' | 'ultra_rollup_honk';
3
+ export type UltraHonkFlavor = 'ultra_honk' | 'ultra_keccak_honk' | 'ultra_starknet_honk' | 'ultra_rollup_honk';
4
4
 
5
5
  const UltraKeccakHonkCircuits = ['RootRollupArtifact'] as const satisfies ServerProtocolArtifact[];
6
- const UltraHonkCircuits = ['BaseParityArtifact', 'RootParityArtifact'] as const satisfies ServerProtocolArtifact[];
6
+ const UltraHonkCircuits = ['ParityBaseArtifact', 'ParityRootArtifact'] as const satisfies ServerProtocolArtifact[];
7
7
 
8
8
  export type UltraKeccakHonkServerProtocolArtifact = (typeof UltraKeccakHonkCircuits)[number];
9
9
  export type UltraHonkServerProtocolArtifact = (typeof UltraHonkCircuits)[number];
@@ -17,6 +17,7 @@ export function getUltraHonkFlavorForCircuit(artifact: UltraHonkServerProtocolAr
17
17
  export function getUltraHonkFlavorForCircuit(artifact: UltraRollupHonkServerProtocolArtifact): 'ultra_rollup_honk';
18
18
  export function getUltraHonkFlavorForCircuit(artifact: ServerProtocolArtifact): UltraHonkFlavor;
19
19
  export function getUltraHonkFlavorForCircuit(artifact: ServerProtocolArtifact): UltraHonkFlavor {
20
+ // STARKNET: how to allow for the distinction between keccak/starknet? ultra_keccak_honk is returned in both cases
20
21
  if (isUltraKeccakHonkCircuit(artifact)) {
21
22
  return 'ultra_keccak_honk';
22
23
  } else if (UltraHonkCircuits.includes(artifact as UltraHonkServerProtocolArtifact)) {
package/src/index.ts CHANGED
@@ -2,7 +2,9 @@ export * from './prover/index.js';
2
2
  export * from './test/index.js';
3
3
  export * from './verifier/index.js';
4
4
  export * from './config.js';
5
- export * from './bb/execute.js';
5
+ export * from './bb/file_names.js';
6
+ export * from './bb/bb_js_backend.js';
6
7
  export * from './honk.js';
8
+ export * from './verification_key/verification_key_data.js';
7
9
 
8
10
  export { type ClientProtocolCircuitVerifier } from '@aztec/stdlib/interfaces/server';
@@ -7,7 +7,6 @@ import {
7
7
  Metrics,
8
8
  type TelemetryClient,
9
9
  type Tracer,
10
- ValueType,
11
10
  } from '@aztec/telemetry-client';
12
11
 
13
12
  /**
@@ -31,51 +30,21 @@ export class ProverInstrumentation {
31
30
  this.tracer = telemetry.getTracer(name);
32
31
  const meter = telemetry.getMeter(name);
33
32
 
34
- this.simulationDuration = meter.createHistogram(Metrics.CIRCUIT_SIMULATION_DURATION, {
35
- description: 'Records how long it takes to simulate a circuit',
36
- unit: 'ms',
37
- valueType: ValueType.INT,
38
- });
33
+ this.simulationDuration = meter.createHistogram(Metrics.CIRCUIT_SIMULATION_DURATION);
39
34
 
40
- this.witGenDuration = meter.createHistogram(Metrics.CIRCUIT_WITNESS_GEN_DURATION, {
41
- description: 'Records how long it takes to generate the partial witness for a circuit',
42
- unit: 's',
43
- valueType: ValueType.DOUBLE,
44
- });
35
+ this.witGenDuration = meter.createHistogram(Metrics.CIRCUIT_WITNESS_GEN_DURATION);
45
36
 
46
- this.provingDuration = meter.createHistogram(Metrics.CIRCUIT_PROVING_DURATION, {
47
- unit: 's',
48
- description: 'Records how long it takes to prove a circuit',
49
- valueType: ValueType.DOUBLE,
50
- });
37
+ this.provingDuration = meter.createHistogram(Metrics.CIRCUIT_PROVING_DURATION);
51
38
 
52
- this.witGenInputSize = meter.createGauge(Metrics.CIRCUIT_WITNESS_GEN_INPUT_SIZE, {
53
- unit: 'By',
54
- description: 'Records the size of the input to the witness generation',
55
- valueType: ValueType.INT,
56
- });
39
+ this.witGenInputSize = meter.createGauge(Metrics.CIRCUIT_WITNESS_GEN_INPUT_SIZE);
57
40
 
58
- this.witGenOutputSize = meter.createGauge(Metrics.CIRCUIT_WITNESS_GEN_OUTPUT_SIZE, {
59
- unit: 'By',
60
- description: 'Records the size of the output of the witness generation',
61
- valueType: ValueType.INT,
62
- });
41
+ this.witGenOutputSize = meter.createGauge(Metrics.CIRCUIT_WITNESS_GEN_OUTPUT_SIZE);
63
42
 
64
- this.proofSize = meter.createGauge(Metrics.CIRCUIT_PROVING_PROOF_SIZE, {
65
- unit: 'By',
66
- description: 'Records the size of the proof generated for a circuit',
67
- valueType: ValueType.INT,
68
- });
43
+ this.proofSize = meter.createGauge(Metrics.CIRCUIT_PROVING_PROOF_SIZE);
69
44
 
70
- this.circuitPublicInputCount = meter.createGauge(Metrics.CIRCUIT_PUBLIC_INPUTS_COUNT, {
71
- description: 'Records the number of public inputs in a circuit',
72
- valueType: ValueType.INT,
73
- });
45
+ this.circuitPublicInputCount = meter.createGauge(Metrics.CIRCUIT_PUBLIC_INPUTS_COUNT);
74
46
 
75
- this.circuitSize = meter.createGauge(Metrics.CIRCUIT_SIZE, {
76
- description: 'Records the size of the circuit in gates',
77
- valueType: ValueType.INT,
78
- });
47
+ this.circuitSize = meter.createGauge(Metrics.CIRCUIT_SIZE);
79
48
  }
80
49
 
81
50
  /**
@@ -86,14 +55,21 @@ export class ProverInstrumentation {
86
55
  */
87
56
  recordDuration(
88
57
  metric: 'simulationDuration' | 'witGenDuration' | 'provingDuration',
89
- circuitName: CircuitName | 'tubeCircuit',
58
+ circuitName: CircuitName,
90
59
  timerOrMS: Timer | number,
91
60
  ) {
92
- const s = typeof timerOrMS === 'number' ? timerOrMS / 1000 : timerOrMS.s();
93
- this[metric].record(s, {
94
- [Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
95
- [Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
96
- });
61
+ // Simulation duration is stored in ms, while the others are stored in seconds
62
+ if (metric === 'simulationDuration') {
63
+ const ms = typeof timerOrMS === 'number' ? timerOrMS : timerOrMS.ms();
64
+ this[metric].record(Math.trunc(ms), {
65
+ [Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
66
+ });
67
+ } else {
68
+ const s = typeof timerOrMS === 'number' ? timerOrMS / 1000 : timerOrMS.s();
69
+ this[metric].record(s, {
70
+ [Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
71
+ });
72
+ }
97
73
  }
98
74
 
99
75
  /**
@@ -117,12 +93,11 @@ export class ProverInstrumentation {
117
93
  */
118
94
  recordSize(
119
95
  metric: 'witGenInputSize' | 'witGenOutputSize' | 'proofSize' | 'circuitSize' | 'circuitPublicInputCount',
120
- circuitName: CircuitName | 'tubeCircuit',
96
+ circuitName: CircuitName,
121
97
  size: number,
122
98
  ) {
123
99
  this[metric].record(Math.ceil(size), {
124
100
  [Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
125
- [Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
126
101
  });
127
102
  }
128
103
 
@@ -0,0 +1,423 @@
1
+ import { AztecClientBackend, type BackendOptions, Barretenberg } from '@aztec/bb.js';
2
+ import { type LogLevel, type Logger, createLogger } from '@aztec/foundation/log';
3
+ import { Timer } from '@aztec/foundation/timer';
4
+ import { serializeWitness } from '@aztec/noir-noirc_abi';
5
+ import {
6
+ convertHidingKernelPublicInputsToWitnessMapWithAbi,
7
+ convertHidingKernelToRollupInputsToWitnessMapWithAbi,
8
+ convertPrivateKernelInit2InputsToWitnessMapWithAbi,
9
+ convertPrivateKernelInit2OutputsFromWitnessMapWithAbi,
10
+ convertPrivateKernelInit3InputsToWitnessMapWithAbi,
11
+ convertPrivateKernelInit3OutputsFromWitnessMapWithAbi,
12
+ convertPrivateKernelInitInputsToWitnessMapWithAbi,
13
+ convertPrivateKernelInitOutputsFromWitnessMapWithAbi,
14
+ convertPrivateKernelInner2InputsToWitnessMapWithAbi,
15
+ convertPrivateKernelInner2OutputsFromWitnessMapWithAbi,
16
+ convertPrivateKernelInner3InputsToWitnessMapWithAbi,
17
+ convertPrivateKernelInner3OutputsFromWitnessMapWithAbi,
18
+ convertPrivateKernelInnerInputsToWitnessMapWithAbi,
19
+ convertPrivateKernelInnerOutputsFromWitnessMapWithAbi,
20
+ convertPrivateKernelResetInputsToWitnessMapWithAbi,
21
+ convertPrivateKernelResetOutputsFromWitnessMapWithAbi,
22
+ convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
23
+ convertPrivateKernelTailInputsToWitnessMapWithAbi,
24
+ convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
25
+ convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
26
+ foreignCallHandler,
27
+ getPrivateKernelResetArtifactName,
28
+ updateResetCircuitSampleInputs,
29
+ } from '@aztec/noir-protocol-circuits-types/client';
30
+ import {
31
+ type ArtifactProvider,
32
+ type ClientProtocolArtifact,
33
+ mapProtocolArtifactNameToCircuitName,
34
+ } from '@aztec/noir-protocol-circuits-types/types';
35
+ import type { Abi, WitnessMap } from '@aztec/noir-types';
36
+ import type { CircuitSimulator } from '@aztec/simulator/client';
37
+ import type { PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
38
+ import type {
39
+ HidingKernelToPublicPrivateInputs,
40
+ HidingKernelToRollupPrivateInputs,
41
+ PrivateExecutionStep,
42
+ PrivateKernelCircuitPublicInputs,
43
+ PrivateKernelInit2CircuitPrivateInputs,
44
+ PrivateKernelInit3CircuitPrivateInputs,
45
+ PrivateKernelInitCircuitPrivateInputs,
46
+ PrivateKernelInner2CircuitPrivateInputs,
47
+ PrivateKernelInner3CircuitPrivateInputs,
48
+ PrivateKernelInnerCircuitPrivateInputs,
49
+ PrivateKernelResetCircuitPrivateInputs,
50
+ PrivateKernelSimulateOutput,
51
+ PrivateKernelTailCircuitPrivateInputs,
52
+ PrivateKernelTailCircuitPublicInputs,
53
+ } from '@aztec/stdlib/kernel';
54
+ import type { NoirCompiledCircuitWithName } from '@aztec/stdlib/noir';
55
+ import { ChonkProofWithPublicInputs } from '@aztec/stdlib/proofs';
56
+ import type { CircuitSimulationStats, CircuitWitnessGenerationStats } from '@aztec/stdlib/stats';
57
+
58
+ import { ungzip } from 'pako';
59
+
60
+ export type BBPrivateKernelProverOptions = Omit<BackendOptions, 'logger'> & { logger?: Logger };
61
+ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
62
+ private log: Logger;
63
+
64
+ constructor(
65
+ protected artifactProvider: ArtifactProvider,
66
+ protected simulator: CircuitSimulator,
67
+ protected options: BBPrivateKernelProverOptions = {},
68
+ ) {
69
+ this.log = options.logger || createLogger('bb-prover:private-kernel');
70
+ }
71
+
72
+ public async generateInitOutput(
73
+ inputs: PrivateKernelInitCircuitPrivateInputs,
74
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
75
+ return await this.generateCircuitOutput(
76
+ inputs,
77
+ 'PrivateKernelInitArtifact',
78
+ convertPrivateKernelInitInputsToWitnessMapWithAbi,
79
+ convertPrivateKernelInitOutputsFromWitnessMapWithAbi,
80
+ );
81
+ }
82
+
83
+ public async simulateInit(
84
+ inputs: PrivateKernelInitCircuitPrivateInputs,
85
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
86
+ return await this.simulateCircuitOutput(
87
+ inputs,
88
+ 'PrivateKernelInitArtifact',
89
+ convertPrivateKernelInitInputsToWitnessMapWithAbi,
90
+ convertPrivateKernelInitOutputsFromWitnessMapWithAbi,
91
+ );
92
+ }
93
+
94
+ public async generateInit2Output(
95
+ inputs: PrivateKernelInit2CircuitPrivateInputs,
96
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
97
+ return await this.generateCircuitOutput(
98
+ inputs,
99
+ 'PrivateKernelInit2Artifact',
100
+ convertPrivateKernelInit2InputsToWitnessMapWithAbi,
101
+ convertPrivateKernelInit2OutputsFromWitnessMapWithAbi,
102
+ );
103
+ }
104
+
105
+ public async simulateInit2(
106
+ inputs: PrivateKernelInit2CircuitPrivateInputs,
107
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
108
+ return await this.simulateCircuitOutput(
109
+ inputs,
110
+ 'PrivateKernelInit2Artifact',
111
+ convertPrivateKernelInit2InputsToWitnessMapWithAbi,
112
+ convertPrivateKernelInit2OutputsFromWitnessMapWithAbi,
113
+ );
114
+ }
115
+
116
+ public async generateInit3Output(
117
+ inputs: PrivateKernelInit3CircuitPrivateInputs,
118
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
119
+ return await this.generateCircuitOutput(
120
+ inputs,
121
+ 'PrivateKernelInit3Artifact',
122
+ convertPrivateKernelInit3InputsToWitnessMapWithAbi,
123
+ convertPrivateKernelInit3OutputsFromWitnessMapWithAbi,
124
+ );
125
+ }
126
+
127
+ public async simulateInit3(
128
+ inputs: PrivateKernelInit3CircuitPrivateInputs,
129
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
130
+ return await this.simulateCircuitOutput(
131
+ inputs,
132
+ 'PrivateKernelInit3Artifact',
133
+ convertPrivateKernelInit3InputsToWitnessMapWithAbi,
134
+ convertPrivateKernelInit3OutputsFromWitnessMapWithAbi,
135
+ );
136
+ }
137
+
138
+ public async generateInnerOutput(
139
+ inputs: PrivateKernelInnerCircuitPrivateInputs,
140
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
141
+ return await this.generateCircuitOutput(
142
+ inputs,
143
+ 'PrivateKernelInnerArtifact',
144
+ convertPrivateKernelInnerInputsToWitnessMapWithAbi,
145
+ convertPrivateKernelInnerOutputsFromWitnessMapWithAbi,
146
+ );
147
+ }
148
+
149
+ public async simulateInner(
150
+ inputs: PrivateKernelInnerCircuitPrivateInputs,
151
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
152
+ return await this.simulateCircuitOutput(
153
+ inputs,
154
+ 'PrivateKernelInnerArtifact',
155
+ convertPrivateKernelInnerInputsToWitnessMapWithAbi,
156
+ convertPrivateKernelInnerOutputsFromWitnessMapWithAbi,
157
+ );
158
+ }
159
+
160
+ public async generateInner2Output(
161
+ inputs: PrivateKernelInner2CircuitPrivateInputs,
162
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
163
+ return await this.generateCircuitOutput(
164
+ inputs,
165
+ 'PrivateKernelInner2Artifact',
166
+ convertPrivateKernelInner2InputsToWitnessMapWithAbi,
167
+ convertPrivateKernelInner2OutputsFromWitnessMapWithAbi,
168
+ );
169
+ }
170
+
171
+ public async simulateInner2(
172
+ inputs: PrivateKernelInner2CircuitPrivateInputs,
173
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
174
+ return await this.simulateCircuitOutput(
175
+ inputs,
176
+ 'PrivateKernelInner2Artifact',
177
+ convertPrivateKernelInner2InputsToWitnessMapWithAbi,
178
+ convertPrivateKernelInner2OutputsFromWitnessMapWithAbi,
179
+ );
180
+ }
181
+
182
+ public async generateInner3Output(
183
+ inputs: PrivateKernelInner3CircuitPrivateInputs,
184
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
185
+ return await this.generateCircuitOutput(
186
+ inputs,
187
+ 'PrivateKernelInner3Artifact',
188
+ convertPrivateKernelInner3InputsToWitnessMapWithAbi,
189
+ convertPrivateKernelInner3OutputsFromWitnessMapWithAbi,
190
+ );
191
+ }
192
+
193
+ public async simulateInner3(
194
+ inputs: PrivateKernelInner3CircuitPrivateInputs,
195
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
196
+ return await this.simulateCircuitOutput(
197
+ inputs,
198
+ 'PrivateKernelInner3Artifact',
199
+ convertPrivateKernelInner3InputsToWitnessMapWithAbi,
200
+ convertPrivateKernelInner3OutputsFromWitnessMapWithAbi,
201
+ );
202
+ }
203
+
204
+ public async generateResetOutput(
205
+ inputs: PrivateKernelResetCircuitPrivateInputs,
206
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
207
+ const variantInputs = inputs.trimToSizes();
208
+ const artifactName = getPrivateKernelResetArtifactName(inputs.dimensions);
209
+ return await this.generateCircuitOutput(
210
+ variantInputs,
211
+ artifactName,
212
+ convertPrivateKernelResetInputsToWitnessMapWithAbi,
213
+ convertPrivateKernelResetOutputsFromWitnessMapWithAbi,
214
+ );
215
+ }
216
+
217
+ public async simulateReset(
218
+ inputs: PrivateKernelResetCircuitPrivateInputs,
219
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
220
+ updateResetCircuitSampleInputs(inputs);
221
+ const variantInputs = inputs.trimToSizes();
222
+ const artifactName = getPrivateKernelResetArtifactName(inputs.dimensions);
223
+ return await this.simulateCircuitOutput(
224
+ variantInputs,
225
+ artifactName,
226
+ convertPrivateKernelResetInputsToWitnessMapWithAbi,
227
+ convertPrivateKernelResetOutputsFromWitnessMapWithAbi,
228
+ );
229
+ }
230
+
231
+ public async generateTailOutput(
232
+ inputs: PrivateKernelTailCircuitPrivateInputs,
233
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
234
+ if (!inputs.isForPublic()) {
235
+ return await this.generateCircuitOutput(
236
+ inputs,
237
+ 'PrivateKernelTailArtifact',
238
+ convertPrivateKernelTailInputsToWitnessMapWithAbi,
239
+ convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
240
+ );
241
+ }
242
+ return await this.generateCircuitOutput(
243
+ inputs,
244
+ 'PrivateKernelTailToPublicArtifact',
245
+ convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
246
+ convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
247
+ );
248
+ }
249
+
250
+ public async simulateTail(
251
+ inputs: PrivateKernelTailCircuitPrivateInputs,
252
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
253
+ if (!inputs.isForPublic()) {
254
+ return await this.simulateCircuitOutput(
255
+ inputs,
256
+ 'PrivateKernelTailArtifact',
257
+ convertPrivateKernelTailInputsToWitnessMapWithAbi,
258
+ convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
259
+ );
260
+ }
261
+ return await this.simulateCircuitOutput(
262
+ inputs,
263
+ 'PrivateKernelTailToPublicArtifact',
264
+ convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
265
+ convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
266
+ );
267
+ }
268
+
269
+ public async generateHidingToRollupOutput(
270
+ inputs: HidingKernelToRollupPrivateInputs,
271
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
272
+ return await this.generateCircuitOutput(
273
+ inputs,
274
+ 'HidingKernelToRollup',
275
+ convertHidingKernelToRollupInputsToWitnessMapWithAbi,
276
+ convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
277
+ );
278
+ }
279
+
280
+ public async generateHidingToPublicOutput(
281
+ inputs: HidingKernelToPublicPrivateInputs,
282
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
283
+ return await this.generateCircuitOutput(
284
+ inputs,
285
+ 'HidingKernelToPublic',
286
+ convertHidingKernelPublicInputsToWitnessMapWithAbi,
287
+ convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
288
+ );
289
+ }
290
+
291
+ public async simulateCircuitOutput<
292
+ I extends { toBuffer: () => Buffer },
293
+ O extends PrivateKernelCircuitPublicInputs | PrivateKernelTailCircuitPublicInputs,
294
+ >(
295
+ inputs: I,
296
+ circuitType: ClientProtocolArtifact,
297
+ convertInputs: (inputs: I, abi: Abi) => WitnessMap,
298
+ convertOutputs: (outputs: WitnessMap, abi: Abi) => O,
299
+ ): Promise<PrivateKernelSimulateOutput<O>> {
300
+ const compiledCircuit: NoirCompiledCircuitWithName =
301
+ await this.artifactProvider.getSimulatedClientCircuitArtifactByName(circuitType);
302
+
303
+ const witnessMap = convertInputs(inputs, compiledCircuit.abi);
304
+
305
+ const outputWitness = await this.simulator
306
+ .executeProtocolCircuit(witnessMap, compiledCircuit, foreignCallHandler)
307
+ .catch((err: Error) => {
308
+ this.log.debug(`Failed to simulate ${circuitType}`, {
309
+ circuitName: mapProtocolArtifactNameToCircuitName(circuitType),
310
+ error: err,
311
+ });
312
+ throw err;
313
+ });
314
+ const output = convertOutputs(outputWitness.witness, compiledCircuit.abi);
315
+
316
+ this.log.debug(`Simulated ${circuitType}`, {
317
+ eventName: 'circuit-simulation',
318
+ circuitName: mapProtocolArtifactNameToCircuitName(circuitType),
319
+ duration: outputWitness.duration,
320
+ inputSize: inputs.toBuffer().length,
321
+ outputSize: output.toBuffer().length,
322
+ } satisfies CircuitSimulationStats);
323
+
324
+ return this.makeEmptyKernelSimulateOutput<O>(output, circuitType);
325
+ }
326
+
327
+ public async generateCircuitOutput<
328
+ I extends { toBuffer: () => Buffer },
329
+ O extends PrivateKernelCircuitPublicInputs | PrivateKernelTailCircuitPublicInputs,
330
+ >(
331
+ inputs: I,
332
+ circuitType: ClientProtocolArtifact,
333
+ convertInputs: (inputs: I, abi: Abi) => WitnessMap,
334
+ convertOutputs: (outputs: WitnessMap, abi: Abi) => O,
335
+ ): Promise<PrivateKernelSimulateOutput<O>> {
336
+ this.log.debug(`Generating witness for ${circuitType}`);
337
+ const compiledCircuit: NoirCompiledCircuitWithName =
338
+ await this.artifactProvider.getClientCircuitArtifactByName(circuitType);
339
+
340
+ const witnessMap = convertInputs(inputs, compiledCircuit.abi);
341
+ const outputWitness = await this.simulator.executeProtocolCircuit(witnessMap, compiledCircuit, foreignCallHandler);
342
+ const output = convertOutputs(outputWitness.witness, compiledCircuit.abi);
343
+
344
+ this.log.debug(`Generated witness for ${circuitType}`, {
345
+ eventName: 'circuit-witness-generation',
346
+ circuitName: mapProtocolArtifactNameToCircuitName(circuitType),
347
+ duration: outputWitness.duration,
348
+ inputSize: inputs.toBuffer().length,
349
+ outputSize: output.toBuffer().length,
350
+ } satisfies CircuitWitnessGenerationStats);
351
+
352
+ const verificationKey = await this.artifactProvider.getCircuitVkByName(circuitType);
353
+ const bytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
354
+
355
+ const kernelOutput: PrivateKernelSimulateOutput<O> = {
356
+ publicInputs: output,
357
+ verificationKey,
358
+ outputWitness: outputWitness.witness,
359
+ bytecode,
360
+ };
361
+ return kernelOutput;
362
+ }
363
+
364
+ public async makeEmptyKernelSimulateOutput<
365
+ PublicInputsType extends PrivateKernelTailCircuitPublicInputs | PrivateKernelCircuitPublicInputs,
366
+ >(publicInputs: PublicInputsType, circuitType: ClientProtocolArtifact) {
367
+ const kernelProofOutput: PrivateKernelSimulateOutput<PublicInputsType> = {
368
+ publicInputs,
369
+ verificationKey: await this.artifactProvider.getCircuitVkByName(circuitType),
370
+ outputWitness: new Map(),
371
+ bytecode: Buffer.from([]),
372
+ };
373
+ return kernelProofOutput;
374
+ }
375
+
376
+ public async createChonkProof(executionSteps: PrivateExecutionStep[]): Promise<ChonkProofWithPublicInputs> {
377
+ const timer = new Timer();
378
+ this.log.info(`Generating ClientIVC proof...`);
379
+ const barretenberg = await Barretenberg.initSingleton({
380
+ ...this.options,
381
+ logger: this.options.logger?.verbose,
382
+ });
383
+ const backend = new AztecClientBackend(
384
+ executionSteps.map(step => ungzip(step.bytecode)),
385
+ barretenberg,
386
+ executionSteps.map(step => step.functionName),
387
+ );
388
+
389
+ // Use compressed prove path to get both proof fields and compressed proof bytes
390
+ const result = await backend.prove(
391
+ executionSteps.map(step => ungzip(serializeWitness(step.witness))),
392
+ executionSteps.map(step => step.vk),
393
+ { compress: true },
394
+ );
395
+ this.log.info(`Generated ClientIVC proof`, {
396
+ eventName: 'client-ivc-proof-generation',
397
+ duration: timer.ms(),
398
+ proofSize: result.proofFields.length,
399
+ compressedSize: result.compressedProof?.length,
400
+ });
401
+
402
+ // Create ChonkProofWithPublicInputs from the flat field elements
403
+ const proofWithPubInputs = ChonkProofWithPublicInputs.fromBufferArray(result.proofFields);
404
+
405
+ // Attach compressed proof bytes to the ChonkProof (without public inputs).
406
+ // The compressed bytes are for the full proof WITH public inputs from bb;
407
+ // when deserializing, the decompressor will strip them to match CHONK_PROOF_LENGTH.
408
+ proofWithPubInputs.compressedProof = result.compressedProof ? Buffer.from(result.compressedProof) : undefined;
409
+
410
+ return proofWithPubInputs;
411
+ }
412
+
413
+ public async computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise<number> {
414
+ // Note we do not pass the vk to the backend. This is unneeded for gate counts.
415
+ const barretenberg = await Barretenberg.initSingleton({
416
+ ...this.options,
417
+ logger: this.options.logger?.[(process.env.LOG_LEVEL as LogLevel) || 'verbose'],
418
+ });
419
+ const backend = new AztecClientBackend([ungzip(_bytecode)], barretenberg, [_circuitName]);
420
+ const gateCount = await backend.gates();
421
+ return gateCount[0];
422
+ }
423
+ }
@@ -0,0 +1,10 @@
1
+ import { BundleArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/bundle';
2
+ import type { CircuitSimulator } from '@aztec/simulator/client';
3
+
4
+ import { BBPrivateKernelProver, type BBPrivateKernelProverOptions } from './bb_private_kernel_prover.js';
5
+
6
+ export class BBBundlePrivateKernelProver extends BBPrivateKernelProver {
7
+ constructor(simulator: CircuitSimulator, options: BBPrivateKernelProverOptions = {}) {
8
+ super(new BundleArtifactProvider(), simulator, options);
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ import { LazyArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/lazy';
2
+ import type { CircuitSimulator } from '@aztec/simulator/client';
3
+
4
+ import { BBPrivateKernelProver, type BBPrivateKernelProverOptions } from './bb_private_kernel_prover.js';
5
+
6
+ export class BBLazyPrivateKernelProver extends BBPrivateKernelProver {
7
+ constructor(simulator: CircuitSimulator, options: BBPrivateKernelProverOptions = {}) {
8
+ super(new LazyArtifactProvider(), simulator, options);
9
+ }
10
+ }
@@ -1,3 +1,2 @@
1
- export * from './bb_prover.js';
2
- export * from './bb_native_private_kernel_prover.js';
3
- export * from './client_ivc_proof_utils.js';
1
+ export * from './server/bb_prover.js';
2
+ export * from './proof_utils.js';