@aztec/pxe 5.0.0-rc.1 → 5.0.0-rc.2

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 (218) hide show
  1. package/dest/block_synchronizer/block_stream_source.d.ts +5 -5
  2. package/dest/block_synchronizer/block_stream_source.d.ts.map +1 -1
  3. package/dest/block_synchronizer/block_stream_source.js +4 -29
  4. package/dest/block_synchronizer/block_synchronizer.d.ts +13 -11
  5. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  6. package/dest/block_synchronizer/block_synchronizer.js +43 -15
  7. package/dest/config/index.d.ts +2 -1
  8. package/dest/config/index.d.ts.map +1 -1
  9. package/dest/config/index.js +1 -0
  10. package/dest/contract_function_simulator/contract_function_simulator.d.ts +11 -16
  11. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  12. package/dest/contract_function_simulator/contract_function_simulator.js +22 -18
  13. package/dest/contract_function_simulator/index.d.ts +15 -9
  14. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  15. package/dest/contract_function_simulator/index.js +3 -7
  16. package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts +8 -27
  17. package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts.map +1 -1
  18. package/dest/contract_function_simulator/noir-structs/bounded_vec.js +8 -23
  19. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.d.ts +9 -0
  20. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.d.ts.map +1 -0
  21. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.js +1 -0
  22. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.d.ts +7 -0
  23. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.d.ts.map +1 -0
  24. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.js +1 -0
  25. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
  26. package/dest/contract_function_simulator/noir-structs/fact.d.ts +16 -0
  27. package/dest/contract_function_simulator/noir-structs/fact.d.ts.map +1 -0
  28. package/dest/contract_function_simulator/noir-structs/fact.js +6 -0
  29. package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts +27 -0
  30. package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts.map +1 -0
  31. package/dest/contract_function_simulator/noir-structs/fact_collection.js +29 -0
  32. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +11 -12
  33. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +6 -49
  35. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +4 -8
  36. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  37. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -60
  38. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +2 -2
  39. package/dest/contract_function_simulator/noir-structs/option.d.ts +9 -11
  40. package/dest/contract_function_simulator/noir-structs/option.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/noir-structs/option.js +18 -13
  42. package/dest/contract_function_simulator/noir-structs/origin_block.d.ts +11 -0
  43. package/dest/contract_function_simulator/noir-structs/origin_block.d.ts.map +1 -0
  44. package/dest/contract_function_simulator/noir-structs/origin_block.js +5 -0
  45. package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts +5 -8
  46. package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts.map +1 -1
  47. package/dest/contract_function_simulator/noir-structs/provided_secret.js +1 -14
  48. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts +21 -0
  49. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts.map +1 -0
  50. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.js +33 -0
  51. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts +21 -0
  52. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts.map +1 -0
  53. package/dest/contract_function_simulator/noir-structs/resolved_tx.js +50 -0
  54. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts +14 -0
  55. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts.map +1 -0
  56. package/dest/contract_function_simulator/noir-structs/tx_effect_data.js +5 -0
  57. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +6 -11
  58. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  59. package/dest/contract_function_simulator/noir-structs/utility_context.js +1 -20
  60. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -14
  61. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  62. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -24
  63. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +81 -6
  64. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -1
  65. package/dest/contract_function_simulator/oracle/oracle_registry.js +128 -9
  66. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +80 -36
  67. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -1
  68. package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +926 -264
  69. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +13 -8
  70. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  71. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +80 -11
  72. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +46 -20
  73. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  74. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +119 -55
  75. package/dest/contract_sync/helpers.d.ts +7 -6
  76. package/dest/contract_sync/helpers.d.ts.map +1 -1
  77. package/dest/contract_sync/helpers.js +11 -16
  78. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  79. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  80. package/dest/entrypoints/client/bundle/utils.js +1 -0
  81. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  82. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  83. package/dest/entrypoints/client/lazy/utils.js +1 -0
  84. package/dest/entrypoints/pxe_creation_options.d.ts +8 -2
  85. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  86. package/dest/entrypoints/server/index.d.ts +1 -2
  87. package/dest/entrypoints/server/index.d.ts.map +1 -1
  88. package/dest/entrypoints/server/index.js +0 -1
  89. package/dest/entrypoints/server/utils.d.ts +1 -1
  90. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  91. package/dest/entrypoints/server/utils.js +3 -1
  92. package/dest/error_enriching.js +1 -1
  93. package/dest/hooks/execution_hooks.d.ts +16 -7
  94. package/dest/hooks/execution_hooks.d.ts.map +1 -1
  95. package/dest/hooks/execution_hooks.js +3 -3
  96. package/dest/hooks/index.d.ts +3 -3
  97. package/dest/hooks/index.d.ts.map +1 -1
  98. package/dest/hooks/resolve_tagging_secret_strategy.d.ts +41 -0
  99. package/dest/hooks/resolve_tagging_secret_strategy.d.ts.map +1 -0
  100. package/dest/hooks/resolve_tagging_secret_strategy.js +3 -0
  101. package/dest/logs/log_service.d.ts +6 -6
  102. package/dest/logs/log_service.d.ts.map +1 -1
  103. package/dest/logs/log_service.js +62 -28
  104. package/dest/messages/tx_resolver_service.d.ts +17 -0
  105. package/dest/messages/tx_resolver_service.d.ts.map +1 -0
  106. package/dest/messages/{message_context_service.js → tx_resolver_service.js} +8 -8
  107. package/dest/oracle_version.d.ts +2 -2
  108. package/dest/oracle_version.js +2 -2
  109. package/dest/private_kernel/hints/test_utils.js +1 -1
  110. package/dest/pxe.d.ts +46 -19
  111. package/dest/pxe.d.ts.map +1 -1
  112. package/dest/pxe.js +104 -52
  113. package/dest/storage/allowed_scopes.d.ts +6 -0
  114. package/dest/storage/allowed_scopes.d.ts.map +1 -0
  115. package/dest/storage/allowed_scopes.js +7 -0
  116. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts +1 -1
  117. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts.map +1 -1
  118. package/dest/storage/backwards_compatibility_tests/schema_tests.js +86 -33
  119. package/dest/storage/capsule_store/capsule_service.d.ts +1 -1
  120. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -1
  121. package/dest/storage/capsule_store/capsule_service.js +6 -9
  122. package/dest/storage/contract_store/contract_store.js +2 -2
  123. package/dest/storage/fact_store/fact_service.d.ts +20 -0
  124. package/dest/storage/fact_store/fact_service.d.ts.map +1 -0
  125. package/dest/storage/fact_store/fact_service.js +30 -0
  126. package/dest/storage/fact_store/fact_store.d.ts +95 -0
  127. package/dest/storage/fact_store/fact_store.d.ts.map +1 -0
  128. package/dest/storage/fact_store/fact_store.js +408 -0
  129. package/dest/storage/fact_store/fact_store_keys.d.ts +34 -0
  130. package/dest/storage/fact_store/fact_store_keys.d.ts.map +1 -0
  131. package/dest/storage/fact_store/fact_store_keys.js +50 -0
  132. package/dest/storage/fact_store/index.d.ts +5 -0
  133. package/dest/storage/fact_store/index.d.ts.map +1 -0
  134. package/dest/storage/fact_store/index.js +3 -0
  135. package/dest/storage/fact_store/stored_fact.d.ts +32 -0
  136. package/dest/storage/fact_store/stored_fact.d.ts.map +1 -0
  137. package/dest/storage/fact_store/stored_fact.js +64 -0
  138. package/dest/storage/index.d.ts +2 -1
  139. package/dest/storage/index.d.ts.map +1 -1
  140. package/dest/storage/index.js +1 -0
  141. package/dest/storage/metadata.d.ts +1 -1
  142. package/dest/storage/metadata.js +1 -1
  143. package/dest/storage/open_pxe_stores.d.ts +5 -3
  144. package/dest/storage/open_pxe_stores.d.ts.map +1 -1
  145. package/dest/storage/open_pxe_stores.js +5 -3
  146. package/dest/storage/tagging_store/index.d.ts +2 -2
  147. package/dest/storage/tagging_store/index.d.ts.map +1 -1
  148. package/dest/storage/tagging_store/index.js +1 -1
  149. package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts +40 -0
  150. package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts.map +1 -0
  151. package/dest/storage/tagging_store/tagging_secret_sources_store.js +92 -0
  152. package/package.json +17 -17
  153. package/src/block_synchronizer/block_stream_source.ts +6 -45
  154. package/src/block_synchronizer/block_synchronizer.ts +56 -23
  155. package/src/config/index.ts +1 -0
  156. package/src/contract_function_simulator/contract_function_simulator.ts +32 -31
  157. package/src/contract_function_simulator/index.ts +17 -8
  158. package/src/contract_function_simulator/noir-structs/bounded_vec.ts +12 -24
  159. package/src/contract_function_simulator/noir-structs/contract_class_log_data.ts +9 -0
  160. package/src/contract_function_simulator/noir-structs/embedded_curve_point.ts +4 -0
  161. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  162. package/src/contract_function_simulator/noir-structs/fact.ts +13 -0
  163. package/src/contract_function_simulator/noir-structs/fact_collection.ts +59 -0
  164. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +20 -46
  165. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +7 -60
  166. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +2 -2
  167. package/src/contract_function_simulator/noir-structs/option.ts +17 -11
  168. package/src/contract_function_simulator/noir-structs/origin_block.ts +8 -0
  169. package/src/contract_function_simulator/noir-structs/provided_secret.ts +3 -14
  170. package/src/contract_function_simulator/noir-structs/resolved_tagging_strategy.ts +45 -0
  171. package/src/contract_function_simulator/noir-structs/resolved_tx.ts +53 -0
  172. package/src/contract_function_simulator/noir-structs/tx_effect_data.ts +15 -0
  173. package/src/contract_function_simulator/noir-structs/utility_context.ts +5 -17
  174. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +6 -21
  175. package/src/contract_function_simulator/oracle/oracle_registry.ts +87 -79
  176. package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +641 -247
  177. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +94 -14
  178. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +206 -66
  179. package/src/contract_sync/helpers.ts +11 -18
  180. package/src/entrypoints/client/bundle/utils.ts +1 -0
  181. package/src/entrypoints/client/lazy/utils.ts +1 -0
  182. package/src/entrypoints/pxe_creation_options.ts +7 -1
  183. package/src/entrypoints/server/index.ts +0 -1
  184. package/src/entrypoints/server/utils.ts +3 -1
  185. package/src/error_enriching.ts +1 -1
  186. package/src/hooks/execution_hooks.ts +17 -8
  187. package/src/hooks/index.ts +6 -2
  188. package/src/hooks/resolve_tagging_secret_strategy.ts +46 -0
  189. package/src/logs/log_service.ts +71 -37
  190. package/src/messages/{message_context_service.ts → tx_resolver_service.ts} +16 -9
  191. package/src/oracle_version.ts +2 -2
  192. package/src/private_kernel/hints/test_utils.ts +1 -1
  193. package/src/pxe.ts +150 -54
  194. package/src/storage/allowed_scopes.ts +14 -0
  195. package/src/storage/backwards_compatibility_tests/__snapshots__/FactStore.json +40 -0
  196. package/src/storage/backwards_compatibility_tests/__snapshots__/L2TipsKVStore.json +1 -1
  197. package/src/storage/backwards_compatibility_tests/__snapshots__/TaggingSecretSourcesStore.json +30 -0
  198. package/src/storage/backwards_compatibility_tests/__snapshots__/opened_stores.json +21 -5
  199. package/src/storage/backwards_compatibility_tests/schema_tests.ts +88 -33
  200. package/src/storage/capsule_store/capsule_service.ts +8 -13
  201. package/src/storage/contract_store/contract_store.ts +2 -2
  202. package/src/storage/fact_store/fact_service.ts +45 -0
  203. package/src/storage/fact_store/fact_store.ts +487 -0
  204. package/src/storage/fact_store/fact_store_keys.ts +75 -0
  205. package/src/storage/fact_store/index.ts +4 -0
  206. package/src/storage/fact_store/stored_fact.ts +80 -0
  207. package/src/storage/index.ts +1 -0
  208. package/src/storage/metadata.ts +1 -1
  209. package/src/storage/open_pxe_stores.ts +6 -3
  210. package/src/storage/tagging_store/index.ts +1 -1
  211. package/src/storage/tagging_store/tagging_secret_sources_store.ts +117 -0
  212. package/dest/messages/message_context_service.d.ts +0 -17
  213. package/dest/messages/message_context_service.d.ts.map +0 -1
  214. package/dest/storage/tagging_store/sender_address_book_store.d.ts +0 -14
  215. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +0 -1
  216. package/dest/storage/tagging_store/sender_address_book_store.js +0 -36
  217. package/src/storage/backwards_compatibility_tests/__snapshots__/SenderAddressBookStore.json +0 -16
  218. package/src/storage/tagging_store/sender_address_book_store.ts +0 -48
@@ -10,6 +10,7 @@ import type { BlockHeader } from '@aztec/stdlib/tx';
10
10
  import type { BlockSynchronizerConfig } from '../config/index.js';
11
11
  import type { ContractSyncService } from '../contract_sync/contract_sync_service.js';
12
12
  import type { AnchorBlockStore } from '../storage/anchor_block_store/index.js';
13
+ import type { FactStore } from '../storage/fact_store/fact_store.js';
13
14
  import type { NoteStore } from '../storage/note_store/index.js';
14
15
  import type { PrivateEventStore } from '../storage/private_event_store/private_event_store.js';
15
16
  import { blockStreamSourceFromAztecNode } from './block_stream_source.js';
@@ -26,32 +27,32 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
26
27
  protected readonly blockStream: L2BlockStream;
27
28
 
28
29
  constructor(
29
- private node: AztecNode,
30
- private store: AztecAsyncKVStore,
31
- private anchorBlockStore: AnchorBlockStore,
32
- private noteStore: NoteStore,
33
- private privateEventStore: PrivateEventStore,
34
- private l2TipsStore: L2TipsKVStore,
35
- private contractSyncService: ContractSyncService,
36
- private config: Partial<BlockSynchronizerConfig> = {},
30
+ private readonly node: AztecNode,
31
+ private readonly store: AztecAsyncKVStore,
32
+ private readonly anchorBlockStore: AnchorBlockStore,
33
+ private readonly noteStore: NoteStore,
34
+ private readonly privateEventStore: PrivateEventStore,
35
+ private readonly factStore: FactStore,
36
+ private readonly l2TipsStore: L2TipsKVStore,
37
+ private readonly contractSyncService: ContractSyncService,
38
+ private readonly config: Partial<BlockSynchronizerConfig> = {},
37
39
  bindings?: LoggerBindings,
38
40
  ) {
39
41
  this.log = createLogger('pxe:block_synchronizer', bindings);
40
- this.blockStream = this.createBlockStream(config);
42
+ this.blockStream = this.createBlockStream();
41
43
  this.eventQueue.start();
42
44
  }
43
45
 
44
- protected createBlockStream(config: Partial<BlockSynchronizerConfig>): L2BlockStream {
46
+ protected createBlockStream(): L2BlockStream {
45
47
  return new L2BlockStream(
46
48
  blockStreamSourceFromAztecNode(this.node),
47
49
  this.l2TipsStore,
48
50
  this,
49
51
  createLogger('pxe:block_stream', this.log.getBindings()),
50
52
  {
51
- batchSize: config.l2BlockBatchSize,
52
- // Skipping finalized blocks makes us sync much faster - we only need to download blocks other than the latest one
53
- // in order to detect reorgs, and there can be no reorgs on finalized block, making this safe.
54
- skipFinalized: true,
53
+ // PXE only tracks chain tips (it anchors on tip events and never replays payloads), so the stream runs
54
+ // in tips-only mode: no block downloads, just the tip events that move the anchor and detect reorgs.
55
+ tipsOnly: true,
55
56
  },
56
57
  );
57
58
  }
@@ -62,21 +63,43 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
62
63
  }
63
64
 
64
65
  private async doHandleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void> {
65
- await this.l2TipsStore.handleBlockStreamEvent(event);
66
-
67
66
  switch (event.type) {
68
- case 'blocks-added': {
67
+ case 'chain-proposed': {
69
68
  if (this.config.syncChainTip === undefined || this.config.syncChainTip === 'proposed') {
70
- const lastBlock = event.blocks.at(-1)!;
71
- await this.updateAnchorBlockHeader(lastBlock.header);
69
+ // Fetch the proposed tip header by hash. By-hash is safer than by-number against a same-height reorg.
70
+ const block = await this.node.getBlockData(BlockHash.fromString(event.block.hash));
71
+ if (!block) {
72
+ // The node served a proposed tip whose block data it cannot return — a node inconsistency, since the
73
+ // stream events and the block data come from the same node (same reasoning as the chain-pruned throw
74
+ // below). Throwing here propagates before the tips-store cursor advances, so the cursor stays put and the
75
+ // next sync re-emits chain-proposed (at-least-once). Were we to warn-and-skip, the cursor would advance and
76
+ // a quiet chain would never re-emit, leaving the anchor stale indefinitely.
77
+ throw new Error(
78
+ `Block header for proposed block ${event.block.number} and hash ${event.block.hash} not found. This ` +
79
+ `likely indicates a bug in the node, as we receive block stream events and fetch block headers from ` +
80
+ `the same node.`,
81
+ );
82
+ }
83
+ await this.updateAnchorBlockHeader(block.header);
72
84
  }
73
85
  break;
74
86
  }
87
+ // Never emitted in tips-only mode; PXE anchors on chain-proposed instead. Kept for union exhaustiveness.
88
+ case 'blocks-added':
89
+ break;
75
90
  case 'chain-checkpointed': {
76
91
  if (this.config.syncChainTip === 'checkpointed') {
77
- // Get the last block header from the checkpoint
78
- const lastBlock = event.checkpoint.checkpoint.blocks.at(-1)!;
79
- await this.updateAnchorBlockHeader(lastBlock.header);
92
+ // Fetch the checkpointed tip header by hash. By-hash is safer than by-number against a
93
+ // same-height reorg; a missing result means the block was reorged out between the event
94
+ // and this fetch, so we skip the anchor update and let a later event correct it.
95
+ const block = await this.node.getBlockData(BlockHash.fromString(event.block.hash));
96
+ if (block) {
97
+ await this.updateAnchorBlockHeader(block.header);
98
+ } else {
99
+ this.log.warn(
100
+ `Block header not found for checkpointed block ${event.block.number}, skipping anchor update`,
101
+ );
102
+ }
80
103
  }
81
104
  break;
82
105
  }
@@ -110,7 +133,7 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
110
133
  `Ignoring prune event to block ${event.block.number} greater than current anchor block ${currentAnchorBlockNumber}`,
111
134
  { pruneEvent: event, currentAnchorBlockHeader: currentAnchorBlockHeader.toInspect() },
112
135
  );
113
- return;
136
+ break;
114
137
  }
115
138
 
116
139
  this.log.warn(`Pruning data after block ${event.block.number} due to reorg`, { pruneBlock: event.block });
@@ -131,11 +154,21 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
131
154
  await this.store.transactionAsync(async () => {
132
155
  await this.noteStore.rollback(event.block.number);
133
156
  await this.privateEventStore.rollback(event.block.number);
157
+ await this.factStore.rollback(event.block.number);
134
158
  await this.updateAnchorBlockHeader(newAnchorBlockHeader);
135
159
  });
136
160
  break;
137
161
  }
162
+ default: {
163
+ const _: never = event;
164
+ break;
165
+ }
138
166
  }
167
+
168
+ // Advance the tips store cursor only after the anchor update / prune rollback above succeeds. If that work
169
+ // throws, the cursor stays put and the stream re-emits this event on the next sync pass (at-least-once),
170
+ // matching the prover-node's handle-first/tips-last ordering. The SerialQueue makes this reorder safe.
171
+ await this.l2TipsStore.handleBlockStreamEvent(event);
139
172
  }
140
173
 
141
174
  /** Updates the anchor block header to the target block */
@@ -10,6 +10,7 @@ import { type ChainConfig, chainConfigMappings } from '@aztec/stdlib/config';
10
10
  import { type DataStoreConfig, dataConfigMappings } from '@aztec/stdlib/kv-store';
11
11
 
12
12
  export { getPackageInfo } from './package_info.js';
13
+ export * from '../hooks/index.js';
13
14
 
14
15
  /**
15
16
  * Configuration settings for the prover factory
@@ -92,16 +92,18 @@ import {
92
92
 
93
93
  import type { ContractSyncService } from '../contract_sync/contract_sync_service.js';
94
94
  import type { ExecutionHooks } from '../hooks/index.js';
95
- import type { MessageContextService } from '../messages/message_context_service.js';
95
+ import type { TxResolverService } from '../messages/tx_resolver_service.js';
96
96
  import type { AddressStore } from '../storage/address_store/address_store.js';
97
97
  import { CapsuleService } from '../storage/capsule_store/capsule_service.js';
98
98
  import type { CapsuleStore } from '../storage/capsule_store/capsule_store.js';
99
99
  import type { ContractStore } from '../storage/contract_store/contract_store.js';
100
+ import { FactService } from '../storage/fact_store/index.js';
101
+ import type { FactStore } from '../storage/fact_store/index.js';
100
102
  import type { NoteStore } from '../storage/note_store/note_store.js';
101
103
  import type { PrivateEventStore } from '../storage/private_event_store/private_event_store.js';
102
104
  import type { RecipientTaggingStore } from '../storage/tagging_store/recipient_tagging_store.js';
103
- import type { SenderAddressBookStore } from '../storage/tagging_store/sender_address_book_store.js';
104
105
  import type { SenderTaggingStore } from '../storage/tagging_store/sender_tagging_store.js';
106
+ import type { TaggingSecretSourcesStore } from '../storage/tagging_store/tagging_secret_sources_store.js';
105
107
  import type { BenchmarkedNode } from './benchmarked_node.js';
106
108
  import { ExecutionNoteCache } from './execution_note_cache.js';
107
109
  import { ExecutionTaggingIndexCache } from './execution_tagging_index_cache.js';
@@ -114,10 +116,6 @@ import { TransientArrayService } from './transient_array_service.js';
114
116
 
115
117
  /** Options for ContractFunctionSimulator.run. */
116
118
  export type ContractSimulatorRunOpts = {
117
- /** The address of the contract (should match request.origin). */
118
- contractAddress: AztecAddress;
119
- /** The function selector of the entry point. */
120
- selector: FunctionSelector;
121
119
  /** The address calling the function. Can be replaced to simulate a call from another contract or account. */
122
120
  msgSender?: AztecAddress;
123
121
  /** The block header to use as base state for this run. */
@@ -140,12 +138,13 @@ export type ContractFunctionSimulatorArgs = {
140
138
  l2TipsStore: L2TipsProvider;
141
139
  senderTaggingStore: SenderTaggingStore;
142
140
  recipientTaggingStore: RecipientTaggingStore;
143
- senderAddressBookStore: SenderAddressBookStore;
141
+ taggingSecretSourcesStore: TaggingSecretSourcesStore;
144
142
  capsuleStore: CapsuleStore;
143
+ factStore: FactStore;
145
144
  privateEventStore: PrivateEventStore;
146
145
  simulator: CircuitSimulator;
147
146
  contractSyncService: ContractSyncService;
148
- messageContextService: MessageContextService;
147
+ txResolver: TxResolverService;
149
148
  hooks?: ExecutionHooks;
150
149
  };
151
150
 
@@ -162,12 +161,13 @@ export class ContractFunctionSimulator {
162
161
  private readonly l2TipsStore: L2TipsProvider;
163
162
  private readonly senderTaggingStore: SenderTaggingStore;
164
163
  private readonly recipientTaggingStore: RecipientTaggingStore;
165
- private readonly senderAddressBookStore: SenderAddressBookStore;
164
+ private readonly taggingSecretSourcesStore: TaggingSecretSourcesStore;
166
165
  private readonly capsuleStore: CapsuleStore;
166
+ private readonly factStore: FactStore;
167
167
  private readonly privateEventStore: PrivateEventStore;
168
168
  private readonly simulator: CircuitSimulator;
169
169
  private readonly contractSyncService: ContractSyncService;
170
- private readonly messageContextService: MessageContextService;
170
+ private readonly txResolver: TxResolverService;
171
171
  private readonly hooks: ExecutionHooks | undefined;
172
172
 
173
173
  constructor(args: ContractFunctionSimulatorArgs) {
@@ -179,12 +179,13 @@ export class ContractFunctionSimulator {
179
179
  this.l2TipsStore = args.l2TipsStore;
180
180
  this.senderTaggingStore = args.senderTaggingStore;
181
181
  this.recipientTaggingStore = args.recipientTaggingStore;
182
- this.senderAddressBookStore = args.senderAddressBookStore;
182
+ this.taggingSecretSourcesStore = args.taggingSecretSourcesStore;
183
183
  this.capsuleStore = args.capsuleStore;
184
+ this.factStore = args.factStore;
184
185
  this.privateEventStore = args.privateEventStore;
185
186
  this.simulator = args.simulator;
186
187
  this.contractSyncService = args.contractSyncService;
187
- this.messageContextService = args.messageContextService;
188
+ this.txResolver = args.txResolver;
188
189
  this.hooks = args.hooks;
189
190
  this.log = createLogger('simulator');
190
191
  }
@@ -196,9 +197,7 @@ export class ContractFunctionSimulator {
196
197
  public async run(
197
198
  request: TxExecutionRequest,
198
199
  {
199
- contractAddress,
200
- selector,
201
- msgSender = AztecAddress.fromField(Fr.MAX_FIELD_VALUE),
200
+ msgSender = AztecAddress.NULL_MSG_SENDER,
202
201
  anchorBlockHeader,
203
202
  senderForTags,
204
203
  scopes,
@@ -207,18 +206,17 @@ export class ContractFunctionSimulator {
207
206
  ): Promise<PrivateExecutionResult> {
208
207
  const simulatorSetupTimer = new Timer();
209
208
 
210
- const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(contractAddress, selector);
209
+ const contractAddress = request.origin;
210
+
211
+ const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(
212
+ contractAddress,
213
+ request.functionSelector,
214
+ );
211
215
 
212
216
  if (entryPointArtifact.functionType !== FunctionType.PRIVATE) {
213
217
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as private`);
214
218
  }
215
219
 
216
- if (request.origin !== contractAddress) {
217
- throw new Error(
218
- `Request origin does not match contract address in simulation. Request origin: ${request.origin}, contract address: ${contractAddress}`,
219
- );
220
- }
221
-
222
220
  // reserve the first side effect for the tx hash (inserted by the private kernel)
223
221
  const startSideEffectCounter = 2;
224
222
 
@@ -258,10 +256,11 @@ export class ContractFunctionSimulator {
258
256
  aztecNode: this.aztecNode,
259
257
  senderTaggingStore: this.senderTaggingStore,
260
258
  recipientTaggingStore: this.recipientTaggingStore,
261
- senderAddressBookStore: this.senderAddressBookStore,
259
+ taggingSecretSourcesStore: this.taggingSecretSourcesStore,
262
260
  capsuleService: new CapsuleService(this.capsuleStore, scopes),
261
+ factService: new FactService(this.factStore, scopes),
263
262
  privateEventStore: this.privateEventStore,
264
- messageContextService: this.messageContextService,
263
+ txResolver: this.txResolver,
265
264
  contractSyncService: this.contractSyncService,
266
265
  jobId,
267
266
  totalPublicCalldataCount: 0,
@@ -325,10 +324,6 @@ export class ContractFunctionSimulator {
325
324
  /**
326
325
  * Runs a utility function.
327
326
  * @param call - The function call to execute.
328
- * @param authwits - Authentication witnesses required for the function call.
329
- * @param anchorBlockHeader - The block header to use as base state for this run.
330
- * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
331
- * accounts if not specified.
332
327
  * @returns A return value of the utility function in a form as returned by the simulator (Noir fields)
333
328
  */
334
329
  public async runUtility(
@@ -349,7 +344,12 @@ export class ContractFunctionSimulator {
349
344
  };
350
345
 
351
346
  const oracle = new UtilityExecutionOracle({
352
- contractAddress: call.to,
347
+ callContext: CallContext.from({
348
+ msgSender: AztecAddress.NULL_MSG_SENDER,
349
+ contractAddress: call.to,
350
+ functionSelector: call.selector,
351
+ isStaticCall: true,
352
+ }),
353
353
  authWitnesses: authwits,
354
354
  capsules: [],
355
355
  anchorBlockHeader,
@@ -359,10 +359,11 @@ export class ContractFunctionSimulator {
359
359
  addressStore: this.addressStore,
360
360
  aztecNode: this.aztecNode,
361
361
  recipientTaggingStore: this.recipientTaggingStore,
362
- senderAddressBookStore: this.senderAddressBookStore,
362
+ taggingSecretSourcesStore: this.taggingSecretSourcesStore,
363
363
  capsuleService: new CapsuleService(this.capsuleStore, scopes),
364
+ factService: new FactService(this.factStore, scopes),
364
365
  privateEventStore: this.privateEventStore,
365
- messageContextService: this.messageContextService,
366
+ txResolver: this.txResolver,
366
367
  contractSyncService: this.contractSyncService,
367
368
  l2TipsStore: this.l2TipsStore,
368
369
  jobId,
@@ -1,23 +1,24 @@
1
1
  export {
2
2
  ORACLE_REGISTRY,
3
3
  makeEntry,
4
- type HandlersForPrefix,
5
4
  type NamedValue,
6
5
  type OracleRegistryEntry,
7
6
  type ParamTypes,
8
- type StripOraclePrefix,
9
7
  } from './oracle/oracle_registry.js';
10
8
  export {
11
9
  ARRAY,
12
10
  AZTEC_ADDRESS,
13
11
  BIGINT,
12
+ BLOCK_HASH,
14
13
  BLOCK_NUMBER,
15
14
  BOOL,
16
15
  BOUNDED_VEC,
17
16
  BUFFER,
18
17
  BYTE,
18
+ CONTRACT_INSTANCE,
19
19
  DELIVERY_MODE,
20
20
  EPHEMERAL_ARRAY,
21
+ ETH_ADDRESS,
21
22
  EVENT_VALIDATION_REQUEST,
22
23
  FIELD,
23
24
  FUNCTION_SELECTOR,
@@ -25,6 +26,7 @@ export {
25
26
  LOG_RETRIEVAL_RESPONSE,
26
27
  MEMBERSHIP_WITNESS,
27
28
  MESSAGE_CONTEXT,
29
+ NOTE_SELECTOR,
28
30
  NOTE_VALIDATION_REQUEST,
29
31
  OPTION,
30
32
  PENDING_TAGGED_LOG,
@@ -35,6 +37,7 @@ export {
35
37
  type InputSlot,
36
38
  type MaybePromise,
37
39
  type OutputSlot,
40
+ type SlotShape,
38
41
  type TypeMapping,
39
42
  } from './oracle/oracle_type_mappings.js';
40
43
  export { ExecutionNoteCache } from './execution_note_cache.js';
@@ -42,9 +45,11 @@ export { ExecutionTaggingIndexCache } from './execution_tagging_index_cache.js';
42
45
  export { HashedValuesCache } from './hashed_values_cache.js';
43
46
  export { pickNotes } from './pick_notes.js';
44
47
  export type { IMiscOracle, IUtilityExecutionOracle, IPrivateExecutionOracle } from './oracle/interfaces.js';
48
+ export type { FactCollection } from './noir-structs/fact_collection.js';
45
49
  export type { NoteData } from './noir-structs/note_data.js';
46
- export { MessageLoadOracleInputs } from './oracle/message_load_oracle_inputs.js';
47
- export { MessageContextService } from '../messages/message_context_service.js';
50
+ export type { ResolvedTaggingStrategy } from './noir-structs/resolved_tagging_strategy.js';
51
+ export type { MessageLoadOracleInputs } from './oracle/message_load_oracle_inputs.js';
52
+ export { TxResolverService } from '../messages/tx_resolver_service.js';
48
53
  export { UtilityExecutionOracle } from './oracle/utility_execution_oracle.js';
49
54
  export { PrivateExecutionOracle } from './oracle/private_execution_oracle.js';
50
55
  export { buildACIRCallback, UnavailableOracleError } from './oracle/acir_callback.js';
@@ -52,12 +57,16 @@ export { executePrivateFunction, extractPrivateCircuitPublicInputs } from './ora
52
57
  export { generateSimulatedProvingResult } from './contract_function_simulator.js';
53
58
  export { packAsHintedNote } from './oracle/note_packing_utils.js';
54
59
  export { BoundedVec } from './noir-structs/bounded_vec.js';
60
+ export type { ContractClassLogData } from './noir-structs/contract_class_log_data.js';
61
+ export type { EmbeddedCurvePoint } from './noir-structs/embedded_curve_point.js';
55
62
  export { EphemeralArray } from './noir-structs/ephemeral_array.js';
56
63
  export { Option } from './noir-structs/option.js';
57
- export { UtilityContext } from './noir-structs/utility_context.js';
64
+ export type { UtilityContext } from './noir-structs/utility_context.js';
58
65
  export { EventValidationRequest } from './noir-structs/event_validation_request.js';
59
- export { LogRetrievalRequest } from './noir-structs/log_retrieval_request.js';
60
- export { LogRetrievalResponse } from './noir-structs/log_retrieval_response.js';
66
+ export type { LogRetrievalRequest } from './noir-structs/log_retrieval_request.js';
67
+ export type { LogRetrievalResponse } from './noir-structs/log_retrieval_response.js';
61
68
  export { NoteValidationRequest } from './noir-structs/note_validation_request.js';
62
- export { ProvidedSecret } from './noir-structs/provided_secret.js';
69
+ export type { TxEffectData } from './noir-structs/tx_effect_data.js';
70
+ export type { ProvidedSecret } from './noir-structs/provided_secret.js';
71
+ export { ResolvedTx } from './noir-structs/resolved_tx.js';
63
72
  export { TransientArrayService } from './transient_array_service.js';
@@ -1,9 +1,4 @@
1
- /**
2
- * TypeScript counterpart of Noir's `BoundedVec<T, MaxLen>`.
3
- *
4
- * Carries the actual `data` plus wire-format metadata (`maxLength`, `elementSize`) so the ACVM
5
- * serializer can pad the storage slot to exactly `maxLength * elementSize` fields.
6
- */
1
+ /** TypeScript counterpart of Noir's `BoundedVec<T, MaxLen>`. */
7
2
  export class BoundedVec<T> {
8
3
  private constructor(
9
4
  public readonly data: T[],
@@ -15,16 +10,11 @@ export class BoundedVec<T> {
15
10
  * Construct a BoundedVec with data.
16
11
  *
17
12
  * @param data - Actual elements. Length must be `<= maxLength`.
18
- * @param maxLength - Maximum capacity declared at the Noir call site.
19
- * The storage slot is padded to this many elements.
20
- * @param elementSize - Number of Fr fields each element contributes when serialized.
21
- * `1` for scalar elements (u8, Field) this is the default.
22
- * `> 1` for compound elements (e.g. a packed note that spans multiple fields).
23
- *
24
- * @example A bounded vec of bytes (elementSize defaults to 1):
25
- * ```ts
26
- * BoundedVec.from({ data: plaintext, maxLength: ciphertext.maxLength })
27
- * ```
13
+ * @param maxLength - Maximum capacity declared at the Noir call site. The storage slot is padded to this many
14
+ * elements.
15
+ * @param elementSize - Number of Fr fields each element contributes when serialized. Only consulted for
16
+ * variable-width elements whose width isn't statically known from their shape (e.g. a packed note spanning
17
+ * `packedHintedNoteLength` fields); fixed-width elements derive it from the shape, so it can be omitted.
28
18
  *
29
19
  * @example A bounded vec of packed notes, each spanning `packedHintedNoteLength` fields:
30
20
  * ```ts
@@ -43,13 +33,11 @@ export class BoundedVec<T> {
43
33
  return new BoundedVec<T>(data, maxLength, elementSize);
44
34
  }
45
35
 
46
- /**
47
- * Construct an empty BoundedVec, typically used as a shape template for `Option.empty(...)`.
48
- *
49
- * @param maxLength - Maximum capacity declared at the Noir call site.
50
- * @param elementSize - Number of Fr fields each element contributes when serialized (default 1).
51
- */
52
- static empty<T>({ maxLength, elementSize = 1 }: { maxLength: number; elementSize?: number }): BoundedVec<T> {
53
- return new BoundedVec<T>([], maxLength, elementSize);
36
+ equals(other: BoundedVec<T>, innerEquals: (a: T, b: T) => boolean): boolean {
37
+ return (
38
+ this.maxLength === other.maxLength &&
39
+ this.data.length === other.data.length &&
40
+ this.data.every((value, i) => innerEquals(value, other.data[i]))
41
+ );
54
42
  }
55
43
  }
@@ -0,0 +1,9 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+
4
+ /** Wire form of a contract class log. */
5
+ export type ContractClassLogData = {
6
+ contractAddress: AztecAddress;
7
+ fields: Fr[];
8
+ emittedLength: number;
9
+ };
@@ -0,0 +1,4 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+
3
+ /** Wire form of a Grumpkin point crossing the oracle boundary: Noir's `EmbeddedCurvePoint` serializes to `[x, y]`. */
4
+ export type EmbeddedCurvePoint = { x: Fr; y: Fr };
@@ -21,7 +21,7 @@ export class EventValidationRequest {
21
21
  static fromFields(fields: Fr[] | FieldReader): EventValidationRequest {
22
22
  const reader = FieldReader.asReader(fields);
23
23
 
24
- const contractAddress = AztecAddress.fromField(reader.readField());
24
+ const contractAddress = AztecAddress.fromFieldUnsafe(reader.readField());
25
25
  const eventTypeId = EventSelector.fromField(reader.readField());
26
26
 
27
27
  const randomness = reader.readField();
@@ -0,0 +1,13 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+
3
+ import type { EphemeralArray } from './ephemeral_array.js';
4
+ import type { Option } from './option.js';
5
+ import type { OriginBlock } from './origin_block.js';
6
+
7
+ /**
8
+ * A single fact returned within a fact collection by the fact store oracles.
9
+ *
10
+ * A TS version of the `Fact` struct in `facts/mod.nr`. `originBlock` is `Some` for a retractable fact (pruned on
11
+ * reorg of that block) and `None` for a non-retractable one.
12
+ */
13
+ export type Fact = { factTypeId: Fr; payload: EphemeralArray<Fr>; originBlock: Option<OriginBlock> };
@@ -0,0 +1,59 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+
4
+ import type { Fact as FactFromStore, OriginBlock } from '../../storage/fact_store/index.js';
5
+ import type { EphemeralArrayService } from '../ephemeral_array_service.js';
6
+ import { EphemeralArray } from './ephemeral_array.js';
7
+ import type { Fact } from './fact.js';
8
+ import { Option } from './option.js';
9
+
10
+ /**
11
+ * A fact collection.
12
+ */
13
+ export type FactCollection = {
14
+ contractAddress: AztecAddress;
15
+ scope: AztecAddress;
16
+ factCollectionTypeId: Fr;
17
+ factCollectionId: Fr;
18
+ facts: EphemeralArray<Fact>;
19
+ };
20
+
21
+ /**
22
+ * Builds the Noir-facing `FactCollection` from stored facts.
23
+ */
24
+ export function toNoirFactCollection(
25
+ service: EphemeralArrayService,
26
+ contractAddress: AztecAddress,
27
+ scope: AztecAddress,
28
+ factCollectionTypeId: Fr,
29
+ factCollectionId: Fr,
30
+ facts: FactFromStore[],
31
+ ): FactCollection {
32
+ return {
33
+ contractAddress,
34
+ scope,
35
+ factCollectionTypeId,
36
+ factCollectionId,
37
+ facts: EphemeralArray.fromValues(
38
+ service,
39
+ facts.map(
40
+ (fact: FactFromStore): Fact => ({
41
+ factTypeId: fact.factTypeId,
42
+ payload: EphemeralArray.fromValues(service, fact.payload),
43
+ originBlock: fact.originBlock
44
+ ? Option.some(fact.originBlock)
45
+ : Option.none<OriginBlock>({ blockNumber: 0, blockHash: Fr.ZERO }),
46
+ }),
47
+ ),
48
+ ),
49
+ };
50
+ }
51
+
52
+ /**
53
+ * A zeroed `FactCollection` used only as a serialization shape template for the `None` case of
54
+ * `Option<FactCollection>`. Noir's `Option<T>` is fixed-width on the wire, so `None` must emit the same number of
55
+ * (zeroed) field slots as `Some`.
56
+ **/
57
+ export function emptyFactCollection(service: EphemeralArrayService): FactCollection {
58
+ return toNoirFactCollection(service, AztecAddress.ZERO, AztecAddress.ZERO, Fr.ZERO, Fr.ZERO, []);
59
+ }
@@ -1,8 +1,9 @@
1
- import { BlockNumber } from '@aztec/foundation/branded-types';
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { FieldReader } from '@aztec/foundation/serialize';
4
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- import { Tag } from '@aztec/stdlib/logs';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import type { Tag } from '@aztec/stdlib/logs';
5
+
6
+ import type { Option } from './option.js';
6
7
 
7
8
  /** Discriminant for which log source to query. */
8
9
  export enum LogSource {
@@ -15,47 +16,20 @@ export enum LogSource {
15
16
  * Intermediate struct used to perform batch log retrieval by PXE. The `utilityBulkRetrieveLogs` oracle expects values of this
16
17
  * type to be stored in a `EphemeralArray`.
17
18
  */
18
- export class LogRetrievalRequest {
19
- constructor(
20
- public contractAddress: AztecAddress,
21
- public tag: Tag,
22
- public source: LogSource = LogSource.PUBLIC_AND_PRIVATE,
23
- public fromBlock?: BlockNumber,
24
- public toBlock?: BlockNumber,
25
- ) {}
26
-
27
- toFields(): Fr[] {
28
- return [
29
- this.contractAddress.toField(),
30
- this.tag.value,
31
- new Fr(this.source),
32
- new Fr(this.fromBlock !== undefined ? 1 : 0),
33
- new Fr(this.fromBlock ?? 0),
34
- new Fr(this.toBlock !== undefined ? 1 : 0),
35
- new Fr(this.toBlock ?? 0),
36
- ];
37
- }
38
-
39
- static fromFields(fields: Fr[] | FieldReader): LogRetrievalRequest {
40
- const reader = FieldReader.asReader(fields);
41
-
42
- const contractAddress = AztecAddress.fromField(reader.readField());
43
- const tag = new Tag(reader.readField());
44
- const sourceNum = reader.readField().toNumber();
45
- if (!(sourceNum in LogSource)) {
46
- const validNames = Object.keys(LogSource).filter(k => isNaN(Number(k)));
47
- throw new Error(`Invalid LogSource value ${sourceNum}, expected one of ${validNames.join(', ')}`);
48
- }
49
- const source = sourceNum as LogSource;
50
-
51
- const fromBlockIsSome = reader.readBoolean();
52
- const fromBlockValue = reader.readField();
53
- const fromBlock = fromBlockIsSome ? BlockNumber(fromBlockValue.toNumber()) : undefined;
54
-
55
- const toBlockIsSome = reader.readBoolean();
56
- const toBlockValue = reader.readField();
57
- const toBlock = toBlockIsSome ? BlockNumber(toBlockValue.toNumber()) : undefined;
58
-
59
- return new LogRetrievalRequest(contractAddress, tag, source, fromBlock, toBlock);
19
+ export type LogRetrievalRequest = {
20
+ contractAddress: AztecAddress;
21
+ tag: Tag;
22
+ source: LogSource;
23
+ fromBlock: Option<BlockNumber>;
24
+ toBlock: Option<BlockNumber>;
25
+ };
26
+
27
+ /** Parses a `LogSource` from its wire field, throwing on an out-of-range value. */
28
+ export function logSourceFromField(field: Fr): LogSource {
29
+ const sourceNum = field.toNumber();
30
+ if (!(sourceNum in LogSource)) {
31
+ const validNames = Object.keys(LogSource).filter(k => isNaN(Number(k)));
32
+ throw new Error(`Invalid LogSource value ${sourceNum}, expected one of ${validNames.join(', ')}`);
60
33
  }
34
+ return sourceNum as LogSource;
61
35
  }