@aztec/stdlib 0.82.2 → 0.82.3-nightly.20250403

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 (206) hide show
  1. package/dest/avm/avm.d.ts +4648 -1474
  2. package/dest/avm/avm.d.ts.map +1 -1
  3. package/dest/avm/avm.js +182 -109
  4. package/dest/avm/avm_proving_request.d.ts +1867 -498
  5. package/dest/avm/avm_proving_request.d.ts.map +1 -1
  6. package/dest/block/l2_block_downloader/l2_block_stream.d.ts +10 -12
  7. package/dest/block/l2_block_downloader/l2_block_stream.d.ts.map +1 -1
  8. package/dest/block/l2_block_downloader/l2_block_stream.js +45 -11
  9. package/dest/config/config.d.ts +2 -2
  10. package/dest/config/config.d.ts.map +1 -1
  11. package/dest/config/config.js +4 -5
  12. package/dest/contract/interfaces/node-info.d.ts +2 -2
  13. package/dest/contract/interfaces/node-info.d.ts.map +1 -1
  14. package/dest/contract/interfaces/node-info.js +1 -1
  15. package/dest/database-version/version_manager.d.ts +4 -2
  16. package/dest/database-version/version_manager.d.ts.map +1 -1
  17. package/dest/database-version/version_manager.js +13 -9
  18. package/dest/epoch-helpers/index.d.ts +2 -0
  19. package/dest/epoch-helpers/index.d.ts.map +1 -1
  20. package/dest/epoch-helpers/index.js +3 -0
  21. package/dest/file-store/factory.d.ts +7 -0
  22. package/dest/file-store/factory.d.ts.map +1 -0
  23. package/dest/file-store/factory.js +46 -0
  24. package/dest/file-store/gcs.d.ts +22 -0
  25. package/dest/file-store/gcs.d.ts.map +1 -0
  26. package/dest/file-store/gcs.js +115 -0
  27. package/dest/file-store/http.d.ts +15 -0
  28. package/dest/file-store/http.d.ts.map +1 -0
  29. package/dest/file-store/http.js +53 -0
  30. package/dest/file-store/index.d.ts +3 -0
  31. package/dest/file-store/index.d.ts.map +1 -0
  32. package/dest/file-store/index.js +2 -0
  33. package/dest/file-store/interface.d.ts +24 -0
  34. package/dest/file-store/interface.d.ts.map +1 -0
  35. package/dest/file-store/interface.js +1 -0
  36. package/dest/file-store/local.d.ts +16 -0
  37. package/dest/file-store/local.d.ts.map +1 -0
  38. package/dest/file-store/local.js +40 -0
  39. package/dest/interfaces/aztec-node-admin.d.ts +9 -1
  40. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  41. package/dest/interfaces/aztec-node-admin.js +2 -1
  42. package/dest/interfaces/aztec-node.d.ts +3 -0
  43. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  44. package/dest/interfaces/aztec-node.js +2 -0
  45. package/dest/interfaces/p2p.d.ts +2 -0
  46. package/dest/interfaces/p2p.d.ts.map +1 -1
  47. package/dest/interfaces/p2p.js +2 -1
  48. package/dest/interfaces/prover-client.d.ts +3 -3
  49. package/dest/interfaces/prover-client.d.ts.map +1 -1
  50. package/dest/interfaces/prover-client.js +6 -4
  51. package/dest/interfaces/prover-node.d.ts +4 -0
  52. package/dest/interfaces/prover-node.d.ts.map +1 -1
  53. package/dest/interfaces/prover-node.js +5 -1
  54. package/dest/interfaces/proving-job.d.ts +1866 -497
  55. package/dest/interfaces/proving-job.d.ts.map +1 -1
  56. package/dest/interfaces/pxe.d.ts +7 -6
  57. package/dest/interfaces/pxe.d.ts.map +1 -1
  58. package/dest/interfaces/pxe.js +1 -1
  59. package/dest/interfaces/service.d.ts +3 -0
  60. package/dest/interfaces/service.d.ts.map +1 -1
  61. package/dest/interfaces/service.js +7 -0
  62. package/dest/interfaces/world_state.d.ts +13 -15
  63. package/dest/interfaces/world_state.d.ts.map +1 -1
  64. package/dest/keys/derivation.d.ts +1 -1
  65. package/dest/keys/derivation.d.ts.map +1 -1
  66. package/dest/keys/derivation.js +10 -2
  67. package/dest/logs/index.d.ts +2 -1
  68. package/dest/logs/index.d.ts.map +1 -1
  69. package/dest/logs/index.js +2 -1
  70. package/dest/logs/pending_tagged_log.d.ts +17 -0
  71. package/dest/logs/pending_tagged_log.d.ts.map +1 -0
  72. package/dest/logs/pending_tagged_log.js +45 -0
  73. package/dest/logs/{l1_payload/shared_secret_derivation.d.ts → shared_secret_derivation.d.ts} +4 -3
  74. package/dest/logs/shared_secret_derivation.d.ts.map +1 -0
  75. package/dest/logs/{l1_payload/shared_secret_derivation.js → shared_secret_derivation.js} +3 -5
  76. package/dest/logs/tx_scoped_l2_log.d.ts +6 -1
  77. package/dest/logs/tx_scoped_l2_log.d.ts.map +1 -1
  78. package/dest/logs/tx_scoped_l2_log.js +12 -4
  79. package/dest/note/note.d.ts +45 -4
  80. package/dest/note/note.d.ts.map +1 -1
  81. package/dest/note/note.js +51 -4
  82. package/dest/proofs/proof.d.ts.map +1 -1
  83. package/dest/proofs/proof.js +33 -7
  84. package/dest/snapshots/download.d.ts +9 -0
  85. package/dest/snapshots/download.d.ts.map +1 -0
  86. package/dest/snapshots/download.js +37 -0
  87. package/dest/snapshots/index.d.ts +4 -0
  88. package/dest/snapshots/index.d.ts.map +1 -0
  89. package/dest/snapshots/index.js +3 -0
  90. package/dest/snapshots/types.d.ts +97 -0
  91. package/dest/snapshots/types.d.ts.map +1 -0
  92. package/dest/snapshots/types.js +27 -0
  93. package/dest/snapshots/upload.d.ts +5 -0
  94. package/dest/snapshots/upload.d.ts.map +1 -0
  95. package/dest/snapshots/upload.js +37 -0
  96. package/dest/tests/factories.d.ts +21 -7
  97. package/dest/tests/factories.d.ts.map +1 -1
  98. package/dest/tests/factories.js +78 -30
  99. package/dest/tests/mocks.d.ts +2 -1
  100. package/dest/tests/mocks.d.ts.map +1 -1
  101. package/dest/tests/mocks.js +5 -1
  102. package/dest/trees/merkle_tree_id.d.ts +8 -0
  103. package/dest/trees/merkle_tree_id.d.ts.map +1 -1
  104. package/dest/trees/merkle_tree_id.js +10 -0
  105. package/dest/trees/nullifier_leaf.d.ts +49 -15
  106. package/dest/trees/nullifier_leaf.d.ts.map +1 -1
  107. package/dest/trees/nullifier_leaf.js +45 -22
  108. package/dest/trees/nullifier_membership_witness.d.ts +34 -18
  109. package/dest/trees/nullifier_membership_witness.d.ts.map +1 -1
  110. package/dest/trees/protocol_contract_leaf.d.ts +0 -1
  111. package/dest/trees/protocol_contract_leaf.d.ts.map +1 -1
  112. package/dest/trees/protocol_contract_leaf.js +0 -3
  113. package/dest/trees/public_data_leaf.d.ts +59 -25
  114. package/dest/trees/public_data_leaf.d.ts.map +1 -1
  115. package/dest/trees/public_data_leaf.js +41 -30
  116. package/dest/trees/public_data_witness.d.ts +42 -24
  117. package/dest/trees/public_data_witness.d.ts.map +1 -1
  118. package/dest/trees/public_data_witness.js +6 -6
  119. package/dest/validators/index.d.ts +3 -0
  120. package/dest/validators/index.d.ts.map +1 -0
  121. package/dest/validators/index.js +1 -0
  122. package/dest/validators/schemas.d.ts +342 -0
  123. package/dest/validators/schemas.d.ts.map +1 -0
  124. package/dest/validators/schemas.js +40 -0
  125. package/dest/validators/types.d.ts +39 -0
  126. package/dest/validators/types.d.ts.map +1 -0
  127. package/dest/validators/types.js +1 -0
  128. package/dest/versioning/versioning.d.ts +1 -1
  129. package/dest/versioning/versioning.d.ts.map +1 -1
  130. package/dest/versioning/versioning.js +6 -6
  131. package/package.json +11 -8
  132. package/src/avm/avm.ts +183 -104
  133. package/src/block/l2_block_downloader/l2_block_stream.ts +64 -29
  134. package/src/config/config.ts +6 -6
  135. package/src/contract/interfaces/node-info.ts +3 -3
  136. package/src/database-version/version_manager.ts +12 -8
  137. package/src/epoch-helpers/index.ts +8 -0
  138. package/src/file-store/factory.ts +61 -0
  139. package/src/file-store/gcs.ts +121 -0
  140. package/src/file-store/http.ts +58 -0
  141. package/src/file-store/index.ts +2 -0
  142. package/src/file-store/interface.ts +19 -0
  143. package/src/file-store/local.ts +46 -0
  144. package/src/interfaces/aztec-node-admin.ts +11 -1
  145. package/src/interfaces/aztec-node.ts +7 -0
  146. package/src/interfaces/p2p.ts +4 -0
  147. package/src/interfaces/prover-client.ts +9 -7
  148. package/src/interfaces/prover-node.ts +10 -0
  149. package/src/interfaces/pxe.ts +14 -7
  150. package/src/interfaces/service.ts +13 -0
  151. package/src/interfaces/world_state.ts +17 -15
  152. package/src/keys/derivation.ts +12 -6
  153. package/src/logs/index.ts +2 -1
  154. package/src/logs/pending_tagged_log.ts +43 -0
  155. package/src/logs/{l1_payload/shared_secret_derivation.ts → shared_secret_derivation.ts} +4 -11
  156. package/src/logs/tx_scoped_l2_log.ts +13 -4
  157. package/src/note/note.ts +61 -5
  158. package/src/proofs/proof.ts +39 -5
  159. package/src/snapshots/download.ts +60 -0
  160. package/src/snapshots/index.ts +3 -0
  161. package/src/snapshots/types.ts +58 -0
  162. package/src/snapshots/upload.ts +55 -0
  163. package/src/tests/factories.ts +137 -53
  164. package/src/tests/mocks.ts +7 -0
  165. package/src/trees/merkle_tree_id.ts +12 -0
  166. package/src/trees/nullifier_leaf.ts +48 -21
  167. package/src/trees/protocol_contract_leaf.ts +0 -4
  168. package/src/trees/public_data_leaf.ts +40 -29
  169. package/src/trees/public_data_witness.ts +6 -6
  170. package/src/validators/index.ts +3 -0
  171. package/src/validators/schemas.ts +53 -0
  172. package/src/validators/types.ts +37 -0
  173. package/src/versioning/versioning.ts +8 -14
  174. package/dest/event/event.d.ts +0 -24
  175. package/dest/event/event.d.ts.map +0 -1
  176. package/dest/event/event.js +0 -13
  177. package/dest/event/event_metadata.d.ts +0 -38
  178. package/dest/event/event_metadata.d.ts.map +0 -1
  179. package/dest/event/event_metadata.js +0 -45
  180. package/dest/event/index.d.ts +0 -4
  181. package/dest/event/index.d.ts.map +0 -1
  182. package/dest/event/index.js +0 -3
  183. package/dest/event/l1_event_payload.d.ts +0 -52
  184. package/dest/event/l1_event_payload.d.ts.map +0 -1
  185. package/dest/event/l1_event_payload.js +0 -64
  186. package/dest/logs/l1_payload/encrypted_log_payload.d.ts +0 -50
  187. package/dest/logs/l1_payload/encrypted_log_payload.d.ts.map +0 -1
  188. package/dest/logs/l1_payload/encrypted_log_payload.js +0 -140
  189. package/dest/logs/l1_payload/encryption_util.d.ts +0 -24
  190. package/dest/logs/l1_payload/encryption_util.d.ts.map +0 -1
  191. package/dest/logs/l1_payload/encryption_util.js +0 -46
  192. package/dest/logs/l1_payload/index.d.ts +0 -3
  193. package/dest/logs/l1_payload/index.d.ts.map +0 -1
  194. package/dest/logs/l1_payload/index.js +0 -2
  195. package/dest/logs/l1_payload/payload.d.ts +0 -60
  196. package/dest/logs/l1_payload/payload.d.ts.map +0 -1
  197. package/dest/logs/l1_payload/payload.js +0 -61
  198. package/dest/logs/l1_payload/shared_secret_derivation.d.ts.map +0 -1
  199. package/src/event/event.ts +0 -16
  200. package/src/event/event_metadata.ts +0 -56
  201. package/src/event/index.ts +0 -3
  202. package/src/event/l1_event_payload.ts +0 -87
  203. package/src/logs/l1_payload/encrypted_log_payload.ts +0 -202
  204. package/src/logs/l1_payload/encryption_util.ts +0 -54
  205. package/src/logs/l1_payload/index.ts +0 -2
  206. package/src/logs/l1_payload/payload.ts +0 -73
package/src/avm/avm.ts CHANGED
@@ -6,34 +6,16 @@ import { z } from 'zod';
6
6
 
7
7
  import { AztecAddress } from '../aztec-address/index.js';
8
8
  import { PublicKeys } from '../keys/public_keys.js';
9
+ import { AppendOnlyTreeSnapshot } from '../trees/append_only_tree_snapshot.js';
10
+ import { MerkleTreeId } from '../trees/merkle_tree_id.js';
9
11
  import { NullifierLeafPreimage } from '../trees/nullifier_leaf.js';
10
12
  import { PublicDataTreeLeafPreimage } from '../trees/public_data_leaf.js';
11
13
  import { AvmCircuitPublicInputs } from './avm_circuit_public_inputs.js';
12
14
  import { serializeWithMessagePack } from './message_pack.js';
13
15
 
14
- export class AvmEnqueuedCallHint {
15
- constructor(
16
- public readonly msgSender: AztecAddress,
17
- public readonly contractAddress: AztecAddress,
18
- public readonly calldata: Fr[],
19
- public isStaticCall: boolean,
20
- ) {}
21
-
22
- static get schema() {
23
- return z
24
- .object({
25
- msgSender: AztecAddress.schema,
26
- contractAddress: AztecAddress.schema,
27
- calldata: schemas.Fr.array(),
28
- isStaticCall: z.boolean(),
29
- })
30
- .transform(
31
- ({ msgSender, contractAddress, calldata, isStaticCall }) =>
32
- new AvmEnqueuedCallHint(msgSender, contractAddress, calldata, isStaticCall),
33
- );
34
- }
35
- }
36
-
16
+ ////////////////////////////////////////////////////////////////////////////
17
+ // Hints (contracts)
18
+ ////////////////////////////////////////////////////////////////////////////
37
19
  export class AvmContractClassHint {
38
20
  constructor(
39
21
  public readonly classId: Fr,
@@ -115,97 +97,192 @@ export class AvmContractInstanceHint {
115
97
  }
116
98
  }
117
99
 
118
- export class AvmAppendTreeHint {
119
- constructor(public readonly leafIndex: Fr, public readonly value: Fr, public readonly siblingPath: Fr[]) {}
120
-
121
- static get schema() {
122
- return z
123
- .object({
124
- leafIndex: schemas.Fr,
125
- value: schemas.Fr,
126
- siblingPath: schemas.Fr.array(),
127
- })
128
- .transform(({ leafIndex, value, siblingPath }) => new AvmAppendTreeHint(leafIndex, value, siblingPath));
129
- }
130
- }
131
-
132
- export class AvmNullifierWriteTreeHint {
133
- constructor(public lowLeafRead: AvmNullifierReadTreeHint, public readonly insertionPath: Fr[]) {}
100
+ ////////////////////////////////////////////////////////////////////////////
101
+ // Hints (merkle db)
102
+ ////////////////////////////////////////////////////////////////////////////
103
+ // Hint for MerkleTreeDB.getSiblingPath.
104
+ export class AvmGetSiblingPathHint {
105
+ constructor(
106
+ public readonly hintKey: AppendOnlyTreeSnapshot,
107
+ // params
108
+ public readonly treeId: MerkleTreeId,
109
+ public readonly index: bigint,
110
+ // return
111
+ public readonly path: Fr[],
112
+ ) {}
134
113
 
135
114
  static get schema() {
136
115
  return z
137
116
  .object({
138
- lowLeafRead: AvmNullifierReadTreeHint.schema,
139
- insertionPath: schemas.Fr.array(),
117
+ hintKey: AppendOnlyTreeSnapshot.schema,
118
+ treeId: z.number().int().nonnegative(),
119
+ index: schemas.BigInt,
120
+ path: schemas.Fr.array(),
140
121
  })
141
- .transform(({ lowLeafRead, insertionPath }) => new AvmNullifierWriteTreeHint(lowLeafRead, insertionPath));
122
+ .transform(({ hintKey, treeId, index, path }) => new AvmGetSiblingPathHint(hintKey, treeId, index, path));
142
123
  }
143
124
  }
144
125
 
145
- export class AvmNullifierReadTreeHint {
126
+ // Hint for MerkleTreeDB.getPreviousValueIndex.
127
+ export class AvmGetPreviousValueIndexHint {
146
128
  constructor(
147
- public readonly lowLeafPreimage: NullifierLeafPreimage,
148
- public readonly lowLeafIndex: Fr,
149
- public readonly lowLeafSiblingPath: Fr[],
129
+ public readonly hintKey: AppendOnlyTreeSnapshot,
130
+ // params
131
+ public readonly treeId: MerkleTreeId,
132
+ public readonly value: Fr,
133
+ // return
134
+ public readonly index: bigint,
135
+ public readonly alreadyPresent: boolean,
150
136
  ) {}
151
137
 
152
138
  static get schema() {
153
139
  return z
154
140
  .object({
155
- lowLeafPreimage: NullifierLeafPreimage.schema,
156
- lowLeafIndex: schemas.Fr,
157
- lowLeafSiblingPath: schemas.Fr.array(),
141
+ hintKey: AppendOnlyTreeSnapshot.schema,
142
+ treeId: z.number().int().nonnegative(),
143
+ value: schemas.Fr,
144
+ index: schemas.BigInt,
145
+ alreadyPresent: z.boolean(),
158
146
  })
159
147
  .transform(
160
- ({ lowLeafPreimage, lowLeafIndex, lowLeafSiblingPath }) =>
161
- new AvmNullifierReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafSiblingPath),
148
+ ({ hintKey, treeId, value, index, alreadyPresent }) =>
149
+ new AvmGetPreviousValueIndexHint(hintKey, treeId, value, index, alreadyPresent),
162
150
  );
163
151
  }
164
152
  }
165
153
 
166
- export class AvmPublicDataReadTreeHint {
154
+ type IndexedTreeLeafPreimages = NullifierLeafPreimage | PublicDataTreeLeafPreimage;
155
+ type IndexedTreeLeafPreimagesClasses = typeof NullifierLeafPreimage | typeof PublicDataTreeLeafPreimage;
156
+
157
+ // Hint for MerkleTreeDB.getLeafPreimage.
158
+ // NOTE: I need this factory because in order to get hold of the schema, I need an actual instance of the class,
159
+ // having the type doesn't suffice since TS does type erasure in the end.
160
+ function AvmGetLeafPreimageHintFactory(klass: IndexedTreeLeafPreimagesClasses) {
161
+ return class AvmGetLeafPreimageHint {
162
+ constructor(
163
+ public readonly hintKey: AppendOnlyTreeSnapshot,
164
+ // params (tree id will be implicit)
165
+ public readonly index: bigint,
166
+ // return
167
+ public readonly leafPreimage: IndexedTreeLeafPreimages,
168
+ ) {}
169
+
170
+ static get schema() {
171
+ return z
172
+ .object({
173
+ hintKey: AppendOnlyTreeSnapshot.schema,
174
+ index: schemas.BigInt,
175
+ leafPreimage: klass.schema,
176
+ })
177
+ .transform(({ hintKey, index, leafPreimage }) => new AvmGetLeafPreimageHint(hintKey, index, leafPreimage));
178
+ }
179
+ };
180
+ }
181
+
182
+ // Note: only supported for PUBLIC_DATA_TREE and NULLIFIER_TREE.
183
+ export class AvmGetLeafPreimageHintPublicDataTree extends AvmGetLeafPreimageHintFactory(PublicDataTreeLeafPreimage) {}
184
+ export class AvmGetLeafPreimageHintNullifierTree extends AvmGetLeafPreimageHintFactory(NullifierLeafPreimage) {}
185
+
186
+ // Hint for MerkleTreeDB.getLeafValue.
187
+ // Note: only supported for NOTE_HASH_TREE and L1_TO_L2_MESSAGE_TREE.
188
+ export class AvmGetLeafValueHint {
167
189
  constructor(
168
- public readonly leafPreimage: PublicDataTreeLeafPreimage,
169
- public readonly leafIndex: Fr,
170
- public readonly siblingPath: Fr[],
190
+ public readonly hintKey: AppendOnlyTreeSnapshot,
191
+ // params
192
+ public readonly treeId: MerkleTreeId,
193
+ public readonly index: bigint,
194
+ // return
195
+ public readonly value: Fr,
171
196
  ) {}
172
197
 
173
- static empty() {
174
- return new AvmPublicDataReadTreeHint(PublicDataTreeLeafPreimage.empty(), Fr.ZERO, []);
175
- }
176
-
177
198
  static get schema() {
178
199
  return z
179
200
  .object({
180
- leafPreimage: PublicDataTreeLeafPreimage.schema,
181
- leafIndex: schemas.Fr,
182
- siblingPath: schemas.Fr.array(),
201
+ hintKey: AppendOnlyTreeSnapshot.schema,
202
+ treeId: z.number().int().nonnegative(),
203
+ index: schemas.BigInt,
204
+ value: schemas.Fr,
183
205
  })
184
- .transform(
185
- ({ leafPreimage, leafIndex, siblingPath }) =>
186
- new AvmPublicDataReadTreeHint(leafPreimage, leafIndex, siblingPath),
187
- );
206
+ .transform(({ hintKey, treeId, index, value }) => new AvmGetLeafValueHint(hintKey, treeId, index, value));
188
207
  }
189
208
  }
190
209
 
191
- export class AvmPublicDataWriteTreeHint {
210
+ // Hint for MerkleTreeDB.sequentialInsert.
211
+ // NOTE: I need this factory because in order to get hold of the schema, I need an actual instance of the class,
212
+ // having the type doesn't suffice since TS does type erasure in the end.
213
+ function AvmSequentialInsertHintFactory(klass: IndexedTreeLeafPreimagesClasses) {
214
+ return class AvmSequentialInsertHint {
215
+ constructor(
216
+ public readonly hintKey: AppendOnlyTreeSnapshot,
217
+ public readonly stateAfter: AppendOnlyTreeSnapshot,
218
+ // params
219
+ public readonly treeId: MerkleTreeId,
220
+ public readonly leaf: InstanceType<IndexedTreeLeafPreimagesClasses>['leaf'],
221
+ // return
222
+ public readonly lowLeavesWitnessData: {
223
+ leaf: IndexedTreeLeafPreimages;
224
+ index: bigint;
225
+ path: Fr[];
226
+ },
227
+ public readonly insertionWitnessData: {
228
+ leaf: IndexedTreeLeafPreimages;
229
+ index: bigint;
230
+ path: Fr[];
231
+ },
232
+ ) {}
233
+
234
+ static get schema() {
235
+ return z
236
+ .object({
237
+ hintKey: AppendOnlyTreeSnapshot.schema,
238
+ stateAfter: AppendOnlyTreeSnapshot.schema,
239
+ treeId: z.number().int().nonnegative(),
240
+ leaf: klass.leafSchema,
241
+ lowLeavesWitnessData: z.object({
242
+ leaf: klass.schema,
243
+ index: schemas.BigInt,
244
+ path: schemas.Fr.array(),
245
+ }),
246
+ insertionWitnessData: z.object({
247
+ leaf: klass.schema,
248
+ index: schemas.BigInt,
249
+ path: schemas.Fr.array(),
250
+ }),
251
+ })
252
+ .transform(
253
+ ({ hintKey, stateAfter, treeId, leaf, lowLeavesWitnessData, insertionWitnessData }) =>
254
+ new AvmSequentialInsertHint(hintKey, stateAfter, treeId, leaf, lowLeavesWitnessData, insertionWitnessData),
255
+ );
256
+ }
257
+ };
258
+ }
259
+
260
+ // Note: only supported for PUBLIC_DATA_TREE and NULLIFIER_TREE.
261
+ export class AvmSequentialInsertHintPublicDataTree extends AvmSequentialInsertHintFactory(PublicDataTreeLeafPreimage) {}
262
+ export class AvmSequentialInsertHintNullifierTree extends AvmSequentialInsertHintFactory(NullifierLeafPreimage) {}
263
+
264
+ ////////////////////////////////////////////////////////////////////////////
265
+ // Hints (other)
266
+ ////////////////////////////////////////////////////////////////////////////
267
+ export class AvmEnqueuedCallHint {
192
268
  constructor(
193
- // To check the current slot has been written to
194
- public readonly lowLeafRead: AvmPublicDataReadTreeHint,
195
- public readonly newLeafPreimage: PublicDataTreeLeafPreimage,
196
- public readonly insertionPath: Fr[],
269
+ public readonly msgSender: AztecAddress,
270
+ public readonly contractAddress: AztecAddress,
271
+ public readonly calldata: Fr[],
272
+ public isStaticCall: boolean,
197
273
  ) {}
198
274
 
199
275
  static get schema() {
200
276
  return z
201
277
  .object({
202
- lowLeafRead: AvmPublicDataReadTreeHint.schema,
203
- newLeafPreimage: PublicDataTreeLeafPreimage.schema,
204
- insertionPath: schemas.Fr.array(),
278
+ msgSender: AztecAddress.schema,
279
+ contractAddress: AztecAddress.schema,
280
+ calldata: schemas.Fr.array(),
281
+ isStaticCall: z.boolean(),
205
282
  })
206
283
  .transform(
207
- ({ lowLeafRead, newLeafPreimage, insertionPath }) =>
208
- new AvmPublicDataWriteTreeHint(lowLeafRead, newLeafPreimage, insertionPath),
284
+ ({ msgSender, contractAddress, calldata, isStaticCall }) =>
285
+ new AvmEnqueuedCallHint(msgSender, contractAddress, calldata, isStaticCall),
209
286
  );
210
287
  }
211
288
  }
@@ -213,16 +290,18 @@ export class AvmPublicDataWriteTreeHint {
213
290
  export class AvmExecutionHints {
214
291
  constructor(
215
292
  public readonly enqueuedCalls: AvmEnqueuedCallHint[] = [],
293
+ // Contract hints.
216
294
  public readonly contractInstances: AvmContractInstanceHint[] = [],
217
295
  public readonly contractClasses: AvmContractClassHint[] = [],
218
296
  public readonly bytecodeCommitments: AvmBytecodeCommitmentHint[] = [],
219
- public readonly publicDataReads: AvmPublicDataReadTreeHint[] = [],
220
- public readonly publicDataWrites: AvmPublicDataWriteTreeHint[] = [],
221
- public readonly nullifierReads: AvmNullifierReadTreeHint[] = [],
222
- public readonly nullifierWrites: AvmNullifierWriteTreeHint[] = [],
223
- public readonly noteHashReads: AvmAppendTreeHint[] = [],
224
- public readonly noteHashWrites: AvmAppendTreeHint[] = [],
225
- public readonly l1ToL2MessageReads: AvmAppendTreeHint[] = [],
297
+ // Merkle DB hints.
298
+ public readonly getSiblingPathHints: AvmGetSiblingPathHint[] = [],
299
+ public readonly getPreviousValueIndexHints: AvmGetPreviousValueIndexHint[] = [],
300
+ public readonly getLeafPreimageHintsPublicDataTree: AvmGetLeafPreimageHintPublicDataTree[] = [],
301
+ public readonly getLeafPreimageHintsNullifierTree: AvmGetLeafPreimageHintNullifierTree[] = [],
302
+ public readonly getLeafValueHints: AvmGetLeafValueHint[] = [],
303
+ public readonly sequentialInsertHintsPublicDataTree: AvmSequentialInsertHintPublicDataTree[] = [],
304
+ public readonly sequentialInsertHintsNullifierTree: AvmSequentialInsertHintNullifierTree[] = [],
226
305
  ) {}
227
306
 
228
307
  static empty() {
@@ -236,13 +315,13 @@ export class AvmExecutionHints {
236
315
  contractInstances: AvmContractInstanceHint.schema.array(),
237
316
  contractClasses: AvmContractClassHint.schema.array(),
238
317
  bytecodeCommitments: AvmBytecodeCommitmentHint.schema.array(),
239
- publicDataReads: AvmPublicDataReadTreeHint.schema.array(),
240
- publicDataWrites: AvmPublicDataWriteTreeHint.schema.array(),
241
- nullifierReads: AvmNullifierReadTreeHint.schema.array(),
242
- nullifierWrites: AvmNullifierWriteTreeHint.schema.array(),
243
- noteHashReads: AvmAppendTreeHint.schema.array(),
244
- noteHashWrites: AvmAppendTreeHint.schema.array(),
245
- l1ToL2MessageReads: AvmAppendTreeHint.schema.array(),
318
+ getSiblingPathHints: AvmGetSiblingPathHint.schema.array(),
319
+ getPreviousValueIndexHints: AvmGetPreviousValueIndexHint.schema.array(),
320
+ getLeafPreimageHintsPublicDataTree: AvmGetLeafPreimageHintPublicDataTree.schema.array(),
321
+ getLeafPreimageHintsNullifierTree: AvmGetLeafPreimageHintNullifierTree.schema.array(),
322
+ getLeafValueHints: AvmGetLeafValueHint.schema.array(),
323
+ sequentialInsertHintsPublicDataTree: AvmSequentialInsertHintPublicDataTree.schema.array(),
324
+ sequentialInsertHintsNullifierTree: AvmSequentialInsertHintNullifierTree.schema.array(),
246
325
  })
247
326
  .transform(
248
327
  ({
@@ -250,26 +329,26 @@ export class AvmExecutionHints {
250
329
  contractInstances,
251
330
  contractClasses,
252
331
  bytecodeCommitments,
253
- publicDataReads,
254
- publicDataWrites,
255
- nullifierReads,
256
- nullifierWrites,
257
- noteHashReads,
258
- noteHashWrites,
259
- l1ToL2MessageReads,
332
+ getSiblingPathHints,
333
+ getPreviousValueIndexHints,
334
+ getLeafPreimageHintsPublicDataTree,
335
+ getLeafPreimageHintsNullifierTree,
336
+ getLeafValueHints,
337
+ sequentialInsertHintsPublicDataTree,
338
+ sequentialInsertHintsNullifierTree,
260
339
  }) =>
261
340
  new AvmExecutionHints(
262
341
  enqueuedCalls,
263
342
  contractInstances,
264
343
  contractClasses,
265
344
  bytecodeCommitments,
266
- publicDataReads,
267
- publicDataWrites,
268
- nullifierReads,
269
- nullifierWrites,
270
- noteHashReads,
271
- noteHashWrites,
272
- l1ToL2MessageReads,
345
+ getSiblingPathHints,
346
+ getPreviousValueIndexHints,
347
+ getLeafPreimageHintsPublicDataTree,
348
+ getLeafPreimageHintsNullifierTree,
349
+ getLeafValueHints,
350
+ sequentialInsertHintsPublicDataTree,
351
+ sequentialInsertHintsNullifierTree,
273
352
  ),
274
353
  );
275
354
  }
@@ -9,6 +9,7 @@ import type { PublishedL2Block } from '../published_l2_block.js';
9
9
  export class L2BlockStream {
10
10
  private readonly runningPromise: RunningPromise;
11
11
  private isSyncing = false;
12
+ private hasStarted = false;
12
13
 
13
14
  constructor(
14
15
  private l2BlockSource: Pick<L2BlockSource, 'getPublishedBlocks' | 'getBlockHeader' | 'getL2Tips'>,
@@ -65,18 +66,31 @@ export class L2BlockStream {
65
66
 
66
67
  // Check if there was a reorg and emit a chain-pruned event if so.
67
68
  let latestBlockNumber = localTips.latest.number;
68
- while (!(await this.areBlockHashesEqualAt(latestBlockNumber, { sourceCache: [sourceTips.latest] }))) {
69
+ const sourceCache = new BlockHashCache([sourceTips.latest]);
70
+ while (!(await this.areBlockHashesEqualAt(latestBlockNumber, { sourceCache }))) {
69
71
  latestBlockNumber--;
70
72
  }
73
+
71
74
  if (latestBlockNumber < localTips.latest.number) {
72
75
  this.log.verbose(`Reorg detected. Pruning blocks from ${latestBlockNumber + 1} to ${localTips.latest.number}.`);
73
- await this.emitEvent({ type: 'chain-pruned', blockNumber: latestBlockNumber });
76
+ await this.emitEvent({
77
+ type: 'chain-pruned',
78
+ block: {
79
+ number: latestBlockNumber,
80
+ hash: sourceCache.get(latestBlockNumber) ?? (await this.getBlockHashFromSource(latestBlockNumber))!,
81
+ },
82
+ });
74
83
  }
75
84
 
76
85
  // If we are just starting, use the starting block number from the options.
77
86
  if (latestBlockNumber === 0 && this.opts.startingBlock !== undefined) {
78
87
  latestBlockNumber = Math.max(this.opts.startingBlock - 1, 0);
88
+ }
89
+
90
+ // Only log this entry once (for sanity)
91
+ if (!this.hasStarted) {
79
92
  this.log.verbose(`Starting sync from block number ${latestBlockNumber}`);
93
+ this.hasStarted = true;
80
94
  }
81
95
 
82
96
  // Request new blocks from the source.
@@ -94,10 +108,13 @@ export class L2BlockStream {
94
108
 
95
109
  // Update the proven and finalized tips.
96
110
  if (localTips.proven !== undefined && sourceTips.proven.number !== localTips.proven.number) {
97
- await this.emitEvent({ type: 'chain-proven', blockNumber: sourceTips.proven.number });
111
+ await this.emitEvent({
112
+ type: 'chain-proven',
113
+ block: sourceTips.proven,
114
+ });
98
115
  }
99
116
  if (localTips.finalized !== undefined && sourceTips.finalized.number !== localTips.finalized.number) {
100
- await this.emitEvent({ type: 'chain-finalized', blockNumber: sourceTips.finalized.number });
117
+ await this.emitEvent({ type: 'chain-finalized', block: sourceTips.finalized });
101
118
  }
102
119
  } catch (err: any) {
103
120
  if (err.name === 'AbortError') {
@@ -112,29 +129,31 @@ export class L2BlockStream {
112
129
  * @param blockNumber - The block number to test.
113
130
  * @param args - A cache of data already requested from source, to avoid re-requesting it.
114
131
  */
115
- private async areBlockHashesEqualAt(blockNumber: number, args: { sourceCache: L2BlockId[] }) {
132
+ private async areBlockHashesEqualAt(blockNumber: number, args: { sourceCache: BlockHashCache }) {
116
133
  if (blockNumber === 0) {
117
134
  return true;
118
135
  }
119
136
  const localBlockHash = await this.localData.getL2BlockHash(blockNumber);
120
- const sourceBlockHash =
121
- args.sourceCache.find(id => id.number === blockNumber && id.hash)?.hash ??
122
- (await this.l2BlockSource
123
- .getBlockHeader(blockNumber)
124
- .then(h => h?.hash())
125
- .then(hash => hash?.toString()));
126
- this.log.trace(`Comparing block hashes for block ${blockNumber}`, {
127
- localBlockHash,
128
- sourceBlockHash,
129
- sourceCacheNumber: args.sourceCache[0]?.number,
130
- sourceCacheHash: args.sourceCache[0]?.hash,
131
- });
137
+ const sourceBlockHashFromCache = args.sourceCache.get(blockNumber);
138
+ const sourceBlockHash = args.sourceCache.get(blockNumber) ?? (await this.getBlockHashFromSource(blockNumber));
139
+ if (!sourceBlockHashFromCache && sourceBlockHash) {
140
+ args.sourceCache.add({ number: blockNumber, hash: sourceBlockHash });
141
+ }
142
+
143
+ this.log.trace(`Comparing block hashes for block ${blockNumber}`, { localBlockHash, sourceBlockHash });
132
144
  return localBlockHash === sourceBlockHash;
133
145
  }
134
146
 
147
+ private getBlockHashFromSource(blockNumber: number) {
148
+ return this.l2BlockSource
149
+ .getBlockHeader(blockNumber)
150
+ .then(h => h?.hash())
151
+ .then(hash => hash?.toString());
152
+ }
153
+
135
154
  private async emitEvent(event: L2BlockStreamEvent) {
136
155
  this.log.debug(
137
- `Emitting ${event.type} (${event.type === 'blocks-added' ? event.blocks.length : event.blockNumber})`,
156
+ `Emitting ${event.type} (${event.type === 'blocks-added' ? event.blocks.length : event.block.number})`,
138
157
  );
139
158
  await this.handler.handleBlockStreamEvent(event);
140
159
  if (!this.isRunning() && !this.isSyncing) {
@@ -143,6 +162,26 @@ export class L2BlockStream {
143
162
  }
144
163
  }
145
164
 
165
+ class BlockHashCache {
166
+ private readonly cache: Map<number, string> = new Map();
167
+
168
+ constructor(initial: L2BlockId[] = []) {
169
+ for (const block of initial) {
170
+ this.add(block);
171
+ }
172
+ }
173
+
174
+ public add(block: L2BlockId) {
175
+ if (block.hash) {
176
+ this.cache.set(block.number, block.hash);
177
+ }
178
+ }
179
+
180
+ public get(blockNumber: number) {
181
+ return this.cache.get(blockNumber);
182
+ }
183
+ }
184
+
146
185
  /** Interface to the local view of the chain. Implemented by world-state and l2-tips-store. */
147
186
  export interface L2BlockStreamLocalDataProvider {
148
187
  getL2BlockHash(number: number): Promise<string | undefined>;
@@ -155,23 +194,19 @@ export interface L2BlockStreamEventHandler {
155
194
  }
156
195
 
157
196
  export type L2BlockStreamEvent =
158
- | {
197
+ | /** Emits blocks added to the chain. */ {
159
198
  type: 'blocks-added';
160
- /** New blocks added to the chain. */
161
199
  blocks: PublishedL2Block[];
162
200
  }
163
- | {
201
+ | /** Reports last correct block (new tip of the unproven chain). */ {
164
202
  type: 'chain-pruned';
165
- /** Last correct block number (new tip of the unproven chain). */
166
- blockNumber: number;
203
+ block: L2BlockId;
167
204
  }
168
- | {
205
+ | /** Reports new proven block. */ {
169
206
  type: 'chain-proven';
170
- /** New proven block number */
171
- blockNumber: number;
207
+ block: L2BlockId;
172
208
  }
173
- | {
209
+ | /** Reports new finalized block (proven and finalized on L1). */ {
174
210
  type: 'chain-finalized';
175
- /** New finalized block number */
176
- blockNumber: number;
211
+ block: L2BlockId;
177
212
  };
@@ -1,5 +1,5 @@
1
1
  import { l1ContractAddressesMapping } from '@aztec/ethereum/l1-contract-addresses';
2
- import { type ConfigMappingsType, numberConfigHelper } from '@aztec/foundation/config';
2
+ import type { ConfigMappingsType } from '@aztec/foundation/config';
3
3
  import { EthAddress } from '@aztec/foundation/eth-address';
4
4
 
5
5
  export { type AllowedElement, type SequencerConfig, SequencerConfigSchema } from '../interfaces/configs.js';
@@ -7,7 +7,7 @@ export { type AllowedElement, type SequencerConfig, SequencerConfigSchema } from
7
7
  export const emptyChainConfig: ChainConfig = {
8
8
  l1ChainId: 0,
9
9
  l1Contracts: { rollupAddress: EthAddress.ZERO },
10
- version: 0,
10
+ rollupVersion: 0,
11
11
  };
12
12
 
13
13
  export const chainConfigMappings: ConfigMappingsType<ChainConfig> = {
@@ -17,10 +17,10 @@ export const chainConfigMappings: ConfigMappingsType<ChainConfig> = {
17
17
  defaultValue: 31337,
18
18
  description: 'The chain ID of the ethereum host.',
19
19
  },
20
- version: {
21
- env: 'VERSION',
20
+ rollupVersion: {
21
+ env: 'ROLLUP_VERSION',
22
22
  description: 'The version of the rollup.',
23
- ...numberConfigHelper(1),
23
+ parseEnv: (val: string) => (Number.isSafeInteger(parseInt(val, 10)) ? parseInt(val, 10) : undefined),
24
24
  },
25
25
  l1Contracts: {
26
26
  description: 'The deployed L1 contract addresses',
@@ -33,7 +33,7 @@ export type ChainConfig = {
33
33
  /** The chain id of the ethereum host. */
34
34
  l1ChainId: number;
35
35
  /** The version of the rollup. */
36
- version: number;
36
+ rollupVersion: number;
37
37
  /** The address to the L1 contracts. */
38
38
  l1Contracts: {
39
39
  /** The address to rollup */
@@ -11,8 +11,8 @@ export interface NodeInfo {
11
11
  nodeVersion: string;
12
12
  /** L1 chain id. */
13
13
  l1ChainId: number;
14
- /** Protocol version. */
15
- protocolVersion: number;
14
+ /** Rollup version. */
15
+ rollupVersion: number;
16
16
  /** The node's ENR. */
17
17
  enr: string | undefined;
18
18
  /** The deployed l1 contract addresses */
@@ -25,7 +25,7 @@ export const NodeInfoSchema: ZodFor<NodeInfo> = z
25
25
  .object({
26
26
  nodeVersion: z.string(),
27
27
  l1ChainId: z.number().int().nonnegative(),
28
- protocolVersion: z.number().int().nonnegative(),
28
+ rollupVersion: z.number().int().nonnegative(),
29
29
  enr: z.string().optional(),
30
30
  l1ContractAddresses: L1ContractAddressesSchema,
31
31
  protocolContractAddresses: ProtocolContractAddressesSchema,
@@ -79,13 +79,15 @@ export class DatabaseVersion {
79
79
 
80
80
  export type DatabaseVersionManagerFs = Pick<typeof fs, 'readFile' | 'writeFile' | 'rm' | 'mkdir'>;
81
81
 
82
+ export const DATABASE_VERSION_FILE_NAME = 'db_version';
83
+
82
84
  /**
83
85
  * A manager for handling database versioning and migrations.
84
86
  * This class will check the version of data in a directory and either
85
87
  * reset or upgrade based on version compatibility.
86
88
  */
87
89
  export class DatabaseVersionManager<T> {
88
- public static readonly VERSION_FILE = 'db_version';
90
+ public static readonly VERSION_FILE = DATABASE_VERSION_FILE_NAME;
89
91
 
90
92
  private readonly versionFile: string;
91
93
  private readonly currentVersion: DatabaseVersion;
@@ -119,6 +121,11 @@ export class DatabaseVersionManager<T> {
119
121
  this.currentVersion = new DatabaseVersion(schemaVersion, rollupAddress);
120
122
  }
121
123
 
124
+ static async writeVersion(version: DatabaseVersion, dataDir: string, fileSystem: DatabaseVersionManagerFs = fs) {
125
+ await fileSystem.mkdir(dataDir, { recursive: true });
126
+ return fileSystem.writeFile(join(dataDir, DatabaseVersionManager.VERSION_FILE), version.toBuffer());
127
+ }
128
+
122
129
  /**
123
130
  * Checks the stored version against the current version and handles the outcome
124
131
  * by either resetting the data directory or calling an upgrade function
@@ -163,7 +170,7 @@ export class DatabaseVersionManager<T> {
163
170
  needsReset = true;
164
171
  }
165
172
  } else {
166
- this.log.warn('Rollup address changed, resetting data directory');
173
+ this.log.warn('Rollup address changed, resetting data directory', { versionFile: this.versionFile });
167
174
  needsReset = true;
168
175
  }
169
176
 
@@ -181,17 +188,14 @@ export class DatabaseVersionManager<T> {
181
188
  /**
182
189
  * Writes the current version to the version file
183
190
  */
184
- private async writeVersion(): Promise<void> {
185
- // Ensure the directory exists
186
- await this.fileSystem.mkdir(this.dataDirectory, { recursive: true });
187
- // Write the version file
188
- await this.fileSystem.writeFile(this.versionFile, this.currentVersion.toBuffer());
191
+ public writeVersion(dir?: string): Promise<void> {
192
+ return DatabaseVersionManager.writeVersion(this.currentVersion, dir ?? this.dataDirectory, this.fileSystem);
189
193
  }
190
194
 
191
195
  /**
192
196
  * Resets the data directory by deleting it and recreating it
193
197
  */
194
- private async resetDataDirectory(): Promise<void> {
198
+ public async resetDataDirectory(): Promise<void> {
195
199
  try {
196
200
  await this.fileSystem.rm(this.dataDirectory, { recursive: true, force: true, maxRetries: 3 });
197
201
  await this.fileSystem.mkdir(this.dataDirectory, { recursive: true });