@aztec/pxe 0.0.1-commit.0c875d939 → 0.0.1-commit.0ec55a70b

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 (249) hide show
  1. package/dest/bin/check_oracle_version.js +4 -4
  2. package/dest/block_synchronizer/block_stream_source.d.ts +10 -0
  3. package/dest/block_synchronizer/block_stream_source.d.ts.map +1 -0
  4. package/dest/block_synchronizer/block_stream_source.js +37 -0
  5. package/dest/block_synchronizer/block_synchronizer.d.ts +6 -2
  6. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  7. package/dest/block_synchronizer/block_synchronizer.js +30 -10
  8. package/dest/config/index.d.ts +2 -2
  9. package/dest/config/index.d.ts.map +1 -1
  10. package/dest/config/index.js +8 -15
  11. package/dest/config/package_info.js +1 -1
  12. package/dest/contract_function_simulator/contract_function_simulator.d.ts +13 -5
  13. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  14. package/dest/contract_function_simulator/contract_function_simulator.js +46 -20
  15. package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
  16. package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
  17. package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
  18. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  19. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
  21. package/dest/contract_function_simulator/index.d.ts +2 -1
  22. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/index.js +1 -0
  24. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -6
  25. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +8 -10
  27. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
  28. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
  29. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
  30. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +2 -4
  32. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +4 -7
  33. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +6 -11
  35. package/dest/contract_function_simulator/oracle/interfaces.d.ts +63 -45
  36. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  37. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  38. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  39. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +47 -0
  40. package/dest/contract_function_simulator/oracle/oracle.d.ts +76 -44
  41. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  42. package/dest/contract_function_simulator/oracle/oracle.js +288 -96
  43. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  44. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +32 -59
  45. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  46. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +69 -96
  47. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +100 -60
  48. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  49. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +327 -115
  50. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  51. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  52. package/dest/contract_function_simulator/pick_notes.js +20 -3
  53. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
  54. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  55. package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
  56. package/dest/contract_logging.d.ts +27 -0
  57. package/dest/contract_logging.d.ts.map +1 -0
  58. package/dest/contract_logging.js +38 -0
  59. package/dest/contract_sync/contract_sync_service.d.ts +6 -5
  60. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  61. package/dest/contract_sync/contract_sync_service.js +62 -43
  62. package/dest/contract_sync/helpers.d.ts +2 -3
  63. package/dest/contract_sync/helpers.d.ts.map +1 -1
  64. package/dest/contract_sync/helpers.js +7 -2
  65. package/dest/debug/pxe_debug_utils.d.ts +3 -3
  66. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  67. package/dest/debug/pxe_debug_utils.js +4 -4
  68. package/dest/entrypoints/client/bundle/index.d.ts +2 -2
  69. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  70. package/dest/entrypoints/client/bundle/index.js +1 -1
  71. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  72. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  73. package/dest/entrypoints/client/bundle/utils.js +2 -2
  74. package/dest/entrypoints/client/lazy/index.d.ts +2 -2
  75. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  76. package/dest/entrypoints/client/lazy/index.js +1 -1
  77. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  78. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  79. package/dest/entrypoints/client/lazy/utils.js +2 -2
  80. package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
  81. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  82. package/dest/entrypoints/pxe_creation_options.js +3 -1
  83. package/dest/entrypoints/server/index.d.ts +2 -3
  84. package/dest/entrypoints/server/index.d.ts.map +1 -1
  85. package/dest/entrypoints/server/index.js +1 -2
  86. package/dest/entrypoints/server/utils.d.ts +2 -2
  87. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  88. package/dest/entrypoints/server/utils.js +2 -2
  89. package/dest/events/event_service.d.ts +3 -2
  90. package/dest/events/event_service.d.ts.map +1 -1
  91. package/dest/events/event_service.js +26 -5
  92. package/dest/events/private_event_filter_validator.d.ts +3 -2
  93. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  94. package/dest/events/private_event_filter_validator.js +15 -0
  95. package/dest/logs/log_service.d.ts +7 -8
  96. package/dest/logs/log_service.d.ts.map +1 -1
  97. package/dest/logs/log_service.js +29 -39
  98. package/dest/messages/message_context_service.d.ts +17 -0
  99. package/dest/messages/message_context_service.d.ts.map +1 -0
  100. package/dest/messages/message_context_service.js +36 -0
  101. package/dest/notes/note_service.d.ts +4 -5
  102. package/dest/notes/note_service.d.ts.map +1 -1
  103. package/dest/notes/note_service.js +14 -5
  104. package/dest/notes_filter.d.ts +2 -3
  105. package/dest/notes_filter.d.ts.map +1 -1
  106. package/dest/oracle_version.d.ts +4 -3
  107. package/dest/oracle_version.d.ts.map +1 -1
  108. package/dest/oracle_version.js +20 -10
  109. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  110. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  111. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  112. package/dest/private_kernel/hints/index.d.ts +1 -1
  113. package/dest/private_kernel/hints/index.js +1 -1
  114. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  115. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  116. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  117. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  118. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  119. package/dest/private_kernel/hints/test_utils.js +203 -0
  120. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  121. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  122. package/dest/private_kernel/private_kernel_execution_prover.js +18 -13
  123. package/dest/private_kernel/private_kernel_oracle.d.ts +10 -6
  124. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  125. package/dest/private_kernel/private_kernel_oracle.js +19 -18
  126. package/dest/pxe.d.ts +30 -15
  127. package/dest/pxe.d.ts.map +1 -1
  128. package/dest/pxe.js +116 -63
  129. package/dest/storage/anchor_block_store/anchor_block_store.js +1 -1
  130. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  131. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  132. package/dest/storage/capsule_store/capsule_service.js +50 -0
  133. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  134. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  135. package/dest/storage/capsule_store/capsule_store.js +36 -28
  136. package/dest/storage/capsule_store/index.d.ts +2 -1
  137. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  138. package/dest/storage/capsule_store/index.js +1 -0
  139. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  140. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  141. package/dest/storage/contract_store/contract_store.js +143 -65
  142. package/dest/storage/metadata.d.ts +1 -1
  143. package/dest/storage/metadata.js +1 -1
  144. package/dest/storage/note_store/note_store.d.ts +1 -1
  145. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  146. package/dest/storage/note_store/note_store.js +2 -2
  147. package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
  148. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  149. package/dest/storage/private_event_store/private_event_store.js +3 -0
  150. package/dest/storage/private_event_store/stored_private_event.js +1 -1
  151. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  152. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  153. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  154. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  155. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  156. package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
  157. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  158. package/dest/tagging/get_all_logs_by_tags.js +17 -3
  159. package/dest/tagging/index.d.ts +3 -3
  160. package/dest/tagging/index.d.ts.map +1 -1
  161. package/dest/tagging/index.js +1 -1
  162. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
  163. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  164. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +8 -22
  165. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  166. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
  167. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  168. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  169. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
  170. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  171. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
  172. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  173. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  174. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  175. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
  176. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  177. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
  178. package/package.json +16 -16
  179. package/src/bin/check_oracle_version.ts +4 -4
  180. package/src/block_synchronizer/block_stream_source.ts +52 -0
  181. package/src/block_synchronizer/block_synchronizer.ts +33 -11
  182. package/src/config/index.ts +3 -9
  183. package/src/config/package_info.ts +1 -1
  184. package/src/contract_function_simulator/contract_function_simulator.ts +67 -33
  185. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  186. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  187. package/src/contract_function_simulator/index.ts +1 -0
  188. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +9 -9
  189. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
  190. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
  191. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +4 -10
  192. package/src/contract_function_simulator/oracle/interfaces.ts +91 -53
  193. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
  194. package/src/contract_function_simulator/oracle/oracle.ts +377 -139
  195. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  196. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +89 -120
  197. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +536 -153
  198. package/src/contract_function_simulator/pick_notes.ts +22 -3
  199. package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
  200. package/src/contract_logging.ts +52 -0
  201. package/src/contract_sync/contract_sync_service.ts +99 -75
  202. package/src/contract_sync/helpers.ts +4 -4
  203. package/src/debug/pxe_debug_utils.ts +7 -7
  204. package/src/entrypoints/client/bundle/index.ts +1 -1
  205. package/src/entrypoints/client/bundle/utils.ts +2 -3
  206. package/src/entrypoints/client/lazy/index.ts +1 -1
  207. package/src/entrypoints/client/lazy/utils.ts +2 -3
  208. package/src/entrypoints/pxe_creation_options.ts +7 -0
  209. package/src/entrypoints/server/index.ts +1 -2
  210. package/src/entrypoints/server/utils.ts +2 -3
  211. package/src/events/event_service.ts +30 -5
  212. package/src/events/private_event_filter_validator.ts +21 -1
  213. package/src/logs/log_service.ts +59 -75
  214. package/src/messages/message_context_service.ts +44 -0
  215. package/src/notes/note_service.ts +18 -8
  216. package/src/notes_filter.ts +1 -3
  217. package/src/oracle_version.ts +20 -10
  218. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  219. package/src/private_kernel/hints/index.ts +1 -1
  220. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  221. package/src/private_kernel/hints/test_utils.ts +325 -0
  222. package/src/private_kernel/private_kernel_execution_prover.ts +18 -16
  223. package/src/private_kernel/private_kernel_oracle.ts +21 -21
  224. package/src/pxe.ts +184 -81
  225. package/src/storage/anchor_block_store/anchor_block_store.ts +1 -1
  226. package/src/storage/capsule_store/capsule_service.ts +90 -0
  227. package/src/storage/capsule_store/capsule_store.ts +44 -26
  228. package/src/storage/capsule_store/index.ts +1 -0
  229. package/src/storage/contract_store/contract_store.ts +177 -76
  230. package/src/storage/metadata.ts +1 -1
  231. package/src/storage/note_store/note_store.ts +2 -5
  232. package/src/storage/private_event_store/private_event_store.ts +4 -0
  233. package/src/storage/private_event_store/stored_private_event.ts +1 -1
  234. package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
  235. package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
  236. package/src/tagging/get_all_logs_by_tags.ts +28 -4
  237. package/src/tagging/index.ts +2 -2
  238. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +12 -25
  239. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  240. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
  241. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
  242. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  243. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
  244. package/dest/access_scopes.d.ts +0 -9
  245. package/dest/access_scopes.d.ts.map +0 -1
  246. package/dest/access_scopes.js +0 -6
  247. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  248. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  249. package/src/access_scopes.ts +0 -9
package/src/pxe.ts CHANGED
@@ -18,6 +18,7 @@ import {
18
18
  } from '@aztec/stdlib/abi';
19
19
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
20
20
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
21
+ import type { L2TipsProvider } from '@aztec/stdlib/block';
21
22
  import {
22
23
  CompleteAddress,
23
24
  type ContractInstanceWithAddress,
@@ -47,12 +48,11 @@ import {
47
48
  TxProfileResult,
48
49
  TxProvingResult,
49
50
  TxSimulationResult,
50
- UtilitySimulationResult,
51
+ UtilityExecutionResult,
51
52
  } from '@aztec/stdlib/tx';
52
53
 
53
54
  import { inspect } from 'util';
54
55
 
55
- import type { AccessScopes } from './access_scopes.js';
56
56
  import { BlockSynchronizer } from './block_synchronizer/index.js';
57
57
  import type { PXEConfig } from './config/index.js';
58
58
  import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
@@ -61,12 +61,14 @@ import {
61
61
  generateSimulatedProvingResult,
62
62
  } from './contract_function_simulator/contract_function_simulator.js';
63
63
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
64
+ import { displayDebugLogs } from './contract_logging.js';
64
65
  import { ContractSyncService } from './contract_sync/contract_sync_service.js';
65
66
  import { readCurrentClassId } from './contract_sync/helpers.js';
66
67
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
67
68
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
68
69
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
69
70
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
71
+ import { MessageContextService } from './messages/message_context_service.js';
70
72
  import {
71
73
  PrivateKernelExecutionProver,
72
74
  type PrivateKernelExecutionProverConfig,
@@ -87,6 +89,14 @@ export type PackedPrivateEvent = InTx & {
87
89
  eventSelector: EventSelector;
88
90
  };
89
91
 
92
+ /** Options for PXE.proveTx. */
93
+ export type ProveTxOpts = {
94
+ /** Addresses whose private state and keys are accessible during private execution. */
95
+ scopes: AztecAddress[];
96
+ /** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
97
+ senderForTags?: AztecAddress;
98
+ };
99
+
90
100
  /** Options for PXE.profileTx. */
91
101
  export type ProfileTxOpts = {
92
102
  /** The profiling mode to use. */
@@ -94,7 +104,9 @@ export type ProfileTxOpts = {
94
104
  /** If true, proof generation is skipped during profiling. Defaults to true. */
95
105
  skipProofGeneration?: boolean;
96
106
  /** Addresses whose private state and keys are accessible during private execution. */
97
- scopes: AccessScopes;
107
+ scopes: AztecAddress[];
108
+ /** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
109
+ senderForTags?: AztecAddress;
98
110
  };
99
111
 
100
112
  /** Options for PXE.simulateTx. */
@@ -105,18 +117,22 @@ export type SimulateTxOpts = {
105
117
  skipTxValidation?: boolean;
106
118
  /** If false, fees are enforced. */
107
119
  skipFeeEnforcement?: boolean;
108
- /** State overrides for the simulation, such as contract instances and artifacts. */
120
+ /** If true, kernel logic is emulated in TS for simulation */
121
+ skipKernels?: boolean;
122
+ /** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
109
123
  overrides?: SimulationOverrides;
110
124
  /** Addresses whose private state and keys are accessible during private execution */
111
- scopes: AccessScopes;
125
+ scopes: AztecAddress[];
126
+ /** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
127
+ senderForTags?: AztecAddress;
112
128
  };
113
129
 
114
- /** Options for PXE.simulateUtility. */
115
- export type SimulateUtilityOpts = {
130
+ /** Options for PXE.executeUtility. */
131
+ export type ExecuteUtilityOpts = {
116
132
  /** The authentication witnesses required for the function call. */
117
133
  authwits?: AuthWitness[];
118
134
  /** The accounts whose notes we can access in this call */
119
- scopes: AccessScopes;
135
+ scopes: AztecAddress[];
120
136
  };
121
137
 
122
138
  /** Args for PXE.create. */
@@ -144,6 +160,7 @@ export type PXECreateArgs = {
144
160
  export class PXE {
145
161
  private constructor(
146
162
  private node: AztecNode,
163
+ private db: AztecAsyncKVStore,
147
164
  private blockStateSynchronizer: BlockSynchronizer,
148
165
  private keyStore: KeyStore,
149
166
  private contractStore: ContractStore,
@@ -156,6 +173,8 @@ export class PXE {
156
173
  private addressStore: AddressStore,
157
174
  private privateEventStore: PrivateEventStore,
158
175
  private contractSyncService: ContractSyncService,
176
+ private messageContextService: MessageContextService,
177
+ private l2TipsStore: L2TipsProvider,
159
178
  private simulator: CircuitSimulator,
160
179
  private proverEnabled: boolean,
161
180
  private proofCreator: PrivateKernelProver,
@@ -211,6 +230,8 @@ export class PXE {
211
230
  noteStore,
212
231
  createLogger('pxe:contract_sync', bindings),
213
232
  );
233
+ const messageContextService = new MessageContextService(node);
234
+
214
235
  const synchronizer = new BlockSynchronizer(
215
236
  node,
216
237
  store,
@@ -239,6 +260,7 @@ export class PXE {
239
260
 
240
261
  const pxe = new PXE(
241
262
  node,
263
+ store,
242
264
  synchronizer,
243
265
  keyStore,
244
266
  contractStore,
@@ -251,6 +273,8 @@ export class PXE {
251
273
  addressStore,
252
274
  privateEventStore,
253
275
  contractSyncService,
276
+ messageContextService,
277
+ tipsStore,
254
278
  simulator,
255
279
  proverEnabled,
256
280
  proofCreator,
@@ -264,7 +288,7 @@ export class PXE {
264
288
  debugUtils.setPXEHelpers(
265
289
  pxe.#putInJobQueue.bind(pxe),
266
290
  pxe.#getSimulatorForTx.bind(pxe),
267
- pxe.#simulateUtility.bind(pxe),
291
+ pxe.#executeUtility.bind(pxe),
268
292
  );
269
293
 
270
294
  pxe.jobQueue.start();
@@ -285,6 +309,7 @@ export class PXE {
285
309
  keyStore: this.keyStore,
286
310
  addressStore: this.addressStore,
287
311
  aztecNode: BenchmarkedNodeFactory.create(this.node),
312
+ l2TipsStore: this.l2TipsStore,
288
313
  senderTaggingStore: this.senderTaggingStore,
289
314
  recipientTaggingStore: this.recipientTaggingStore,
290
315
  senderAddressBookStore: this.senderAddressBookStore,
@@ -292,6 +317,7 @@ export class PXE {
292
317
  privateEventStore: this.privateEventStore,
293
318
  simulator: this.simulator,
294
319
  contractSyncService: this.contractSyncService,
320
+ messageContextService: this.messageContextService,
295
321
  });
296
322
  }
297
323
 
@@ -344,9 +370,8 @@ export class PXE {
344
370
  async #registerProtocolContracts() {
345
371
  const registered: Record<string, string> = {};
346
372
  for (const name of protocolContractNames) {
347
- const { address, contractClass, instance, artifact } =
348
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
349
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
373
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
374
+ await this.contractStore.addContractArtifact(artifact);
350
375
  await this.contractStore.addContractInstance(instance);
351
376
  registered[name] = address.toString();
352
377
  }
@@ -355,22 +380,29 @@ export class PXE {
355
380
 
356
381
  // Executes the entrypoint private function, as well as all nested private
357
382
  // functions that might arise.
358
- async #executePrivate(
359
- contractFunctionSimulator: ContractFunctionSimulator,
360
- txRequest: TxExecutionRequest,
361
- scopes: AccessScopes,
362
- jobId: string,
363
- ): Promise<PrivateExecutionResult> {
383
+ async #executePrivate({
384
+ contractFunctionSimulator,
385
+ txRequest,
386
+ anchorBlockHeader,
387
+ scopes,
388
+ jobId,
389
+ senderForTags,
390
+ }: {
391
+ contractFunctionSimulator: ContractFunctionSimulator;
392
+ txRequest: TxExecutionRequest;
393
+ anchorBlockHeader: BlockHeader;
394
+ scopes: AztecAddress[];
395
+ jobId: string;
396
+ senderForTags?: AztecAddress;
397
+ }): Promise<PrivateExecutionResult> {
364
398
  const { origin: contractAddress, functionSelector } = txRequest;
365
399
 
366
400
  try {
367
- const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
368
-
369
401
  await this.contractSyncService.ensureContractSynced(
370
402
  contractAddress,
371
403
  functionSelector,
372
404
  (privateSyncCall, execScopes) =>
373
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
405
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
374
406
  anchorBlockHeader,
375
407
  jobId,
376
408
  scopes,
@@ -382,6 +414,7 @@ export class PXE {
382
414
  anchorBlockHeader,
383
415
  scopes,
384
416
  jobId,
417
+ senderForTags,
385
418
  });
386
419
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
387
420
  return result;
@@ -394,25 +427,32 @@ export class PXE {
394
427
  }
395
428
 
396
429
  /**
397
- * Simulate a utility function call on the given contract.
430
+ * Execute a utility function call on the given contract.
398
431
  * @param contractFunctionSimulator - The simulator to use for the function call.
399
432
  * @param call - The function call to execute.
400
433
  * @param authWitnesses - Authentication witnesses required for the function call.
401
434
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
402
435
  * accounts if not specified.
403
436
  * @param jobId - The job ID for staged writes.
404
- * @returns The simulation result containing the outputs of the utility function.
437
+ * @returns The execution result containing the outputs of the utility function.
405
438
  */
406
- async #simulateUtility(
439
+ async #executeUtility(
407
440
  contractFunctionSimulator: ContractFunctionSimulator,
408
441
  call: FunctionCall,
409
442
  authWitnesses: AuthWitness[] | undefined,
410
- scopes: AccessScopes,
443
+ scopes: AztecAddress[],
411
444
  jobId: string,
412
445
  ) {
413
446
  try {
414
447
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
415
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
448
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
449
+ call,
450
+ authWitnesses ?? [],
451
+ anchorBlockHeader,
452
+ scopes,
453
+ jobId,
454
+ );
455
+ return { result, offchainEffects };
416
456
  } catch (err) {
417
457
  if (err instanceof SimulationError) {
418
458
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -463,11 +503,10 @@ export class PXE {
463
503
  txExecutionRequest: TxExecutionRequest,
464
504
  proofCreator: PrivateKernelProver,
465
505
  privateExecutionResult: PrivateExecutionResult,
506
+ anchorBlockHeader: BlockHeader,
466
507
  config: PrivateKernelExecutionProverConfig,
467
508
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
468
- const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
469
- const anchorBlockHash = await anchorBlockHeader.hash();
470
- const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
509
+ const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHeader);
471
510
  const kernelTraceProver = new PrivateKernelExecutionProver(
472
511
  kernelOracle,
473
512
  proofCreator,
@@ -485,7 +524,9 @@ export class PXE {
485
524
  * @returns The synced block header
486
525
  */
487
526
  public getSyncedBlockHeader(): Promise<BlockHeader> {
488
- return this.anchorBlockStore.getBlockHeader();
527
+ return this.#putInJobQueue(() => {
528
+ return this.anchorBlockStore.getBlockHeader();
529
+ });
489
530
  }
490
531
 
491
532
  /**
@@ -542,6 +583,12 @@ export class PXE {
542
583
  * TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
543
584
  */
544
585
  public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
586
+ if (!(await sender.isValid())) {
587
+ throw new Error(
588
+ `Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
589
+ );
590
+ }
591
+
545
592
  const accounts = await this.keyStore.getAccounts();
546
593
  if (accounts.includes(sender)) {
547
594
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
@@ -552,6 +599,9 @@ export class PXE {
552
599
 
553
600
  if (wasAdded) {
554
601
  this.log.info(`Added sender:\n ${sender.toString()}`);
602
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
603
+ // all contracts must re-sync to discover them. Queued to avoid wiping while a job is in flight.
604
+ await this.#putInJobQueue(() => Promise.resolve(this.contractSyncService.wipe()));
555
605
  } else {
556
606
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
557
607
  }
@@ -601,8 +651,7 @@ export class PXE {
601
651
  * @param artifact - The build artifact for the contract class.
602
652
  */
603
653
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
604
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
605
- await this.contractStore.addContractArtifact(contractClassId, artifact);
654
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
606
655
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
607
656
  }
608
657
 
@@ -621,17 +670,17 @@ export class PXE {
621
670
  if (artifact) {
622
671
  // If the user provides an artifact, validate it against the expected class id and register it
623
672
  const contractClass = await getContractClassFromArtifact(artifact);
624
- const contractClassId = contractClass.id;
625
- if (!contractClassId.equals(instance.currentContractClassId)) {
673
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
626
674
  throw new Error(
627
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
675
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
628
676
  );
629
677
  }
630
678
  const computedAddress = await computeContractAddressFromInstance(instance);
631
679
  if (!computedAddress.equals(instance.address)) {
632
680
  throw new Error('Added a contract in which the address does not match the contract instance.');
633
681
  }
634
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
682
+
683
+ await this.contractStore.addContractArtifact(artifact, contractClass);
635
684
 
636
685
  const publicFunctionSignatures = artifact.functions
637
686
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -680,15 +729,16 @@ export class PXE {
680
729
  throw new Error('Could not update contract to a class different from the current one.');
681
730
  }
682
731
 
683
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
684
-
685
732
  const publicFunctionSignatures = artifact.functions
686
733
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
687
734
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
688
735
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
689
736
 
690
737
  currentInstance.currentContractClassId = contractClass.id;
691
- await this.contractStore.addContractInstance(currentInstance);
738
+ await Promise.all([
739
+ this.contractStore.addContractArtifact(artifact, contractClass),
740
+ this.contractStore.addContractInstance(currentInstance),
741
+ ]);
692
742
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
693
743
  });
694
744
  }
@@ -711,7 +761,7 @@ export class PXE {
711
761
  * @throws If contract code not found, or public simulation reverts.
712
762
  * Also throws if simulatePublic is true and public simulation reverts.
713
763
  */
714
- public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
764
+ public proveTx(txRequest: TxExecutionRequest, { scopes, senderForTags }: ProveTxOpts): Promise<TxProvingResult> {
715
765
  let privateExecutionResult: PrivateExecutionResult;
716
766
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
717
767
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -720,16 +770,24 @@ export class PXE {
720
770
  try {
721
771
  const syncTimer = new Timer();
722
772
  await this.blockStateSynchronizer.sync();
773
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
723
774
  const syncTime = syncTimer.ms();
724
775
  const contractFunctionSimulator = this.#getSimulatorForTx();
725
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
776
+ privateExecutionResult = await this.#executePrivate({
777
+ contractFunctionSimulator,
778
+ txRequest,
779
+ anchorBlockHeader,
780
+ scopes,
781
+ jobId,
782
+ senderForTags,
783
+ });
726
784
 
727
785
  const {
728
786
  publicInputs,
729
787
  chonkProof,
730
788
  executionSteps,
731
789
  timings: { proving } = {},
732
- } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
790
+ } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, anchorBlockHeader, {
733
791
  simulate: false,
734
792
  skipFeeEnforcement: false,
735
793
  profileMode: 'none',
@@ -764,17 +822,17 @@ export class PXE {
764
822
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
765
823
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
766
824
  // storing the tags here prevents linkage of txs sent from the same PXE.
767
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
768
- if (preTagsUsedInTheTx.length > 0) {
825
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
826
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
769
827
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
770
828
  const txHash = (await txProvingResult.toTx()).txHash;
771
829
 
772
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
773
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
774
- preTagsUsedInTheTx,
830
+ await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
831
+ this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
832
+ taggingIndexRangesUsedInTheTx,
775
833
  });
776
834
  } else {
777
- this.log.debug(`No pre-tags used in the tx`);
835
+ this.log.debug(`No tagging index ranges used in the tx`);
778
836
  }
779
837
 
780
838
  return txProvingResult;
@@ -792,7 +850,7 @@ export class PXE {
792
850
  */
793
851
  public profileTx(
794
852
  txRequest: TxExecutionRequest,
795
- { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
853
+ { profileMode, skipProofGeneration = true, scopes, senderForTags }: ProfileTxOpts,
796
854
  ): Promise<TxProfileResult> {
797
855
  // We disable concurrent profiles for consistency with simulateTx.
798
856
  return this.#putInJobQueue(async jobId => {
@@ -812,15 +870,24 @@ export class PXE {
812
870
  );
813
871
  const syncTimer = new Timer();
814
872
  await this.blockStateSynchronizer.sync();
873
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
815
874
  const syncTime = syncTimer.ms();
816
875
 
817
876
  const contractFunctionSimulator = this.#getSimulatorForTx();
818
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
877
+ const privateExecutionResult = await this.#executePrivate({
878
+ contractFunctionSimulator,
879
+ txRequest,
880
+ anchorBlockHeader,
881
+ scopes,
882
+ jobId,
883
+ senderForTags,
884
+ });
819
885
 
820
886
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
821
887
  txRequest,
822
888
  this.proofCreator,
823
889
  privateExecutionResult,
890
+ anchorBlockHeader,
824
891
  {
825
892
  simulate: skipProofGeneration,
826
893
  skipFeeEnforcement: false,
@@ -881,7 +948,15 @@ export class PXE {
881
948
  */
882
949
  public simulateTx(
883
950
  txRequest: TxExecutionRequest,
884
- { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
951
+ {
952
+ simulatePublic,
953
+ skipTxValidation = false,
954
+ skipFeeEnforcement = false,
955
+ skipKernels = true,
956
+ overrides,
957
+ scopes,
958
+ senderForTags,
959
+ }: SimulateTxOpts,
885
960
  ): Promise<TxSimulationResult> {
886
961
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
887
962
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -903,23 +978,34 @@ export class PXE {
903
978
  );
904
979
  const syncTimer = new Timer();
905
980
  await this.blockStateSynchronizer.sync();
981
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
906
982
  const syncTime = syncTimer.ms();
907
983
 
908
- const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
909
- // Temporary: in case there are overrides, we have to skip the kernels or validations
910
- // will fail. Consider handing control to the user/wallet on whether they want to run them
911
- // or not.
912
984
  const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
913
985
  const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
914
- const skipKernels = hasOverriddenContracts;
915
986
 
916
- // Set overridden contracts on the sync service so it knows to skip syncing them
987
+ if (hasOverriddenContracts && !skipKernels) {
988
+ throw new Error(
989
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
990
+ );
991
+ }
992
+ const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
993
+
917
994
  if (hasOverriddenContracts) {
918
- this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
995
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
996
+ // We exclude them so the sync service skips them entirely.
997
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
919
998
  }
920
999
 
921
1000
  // Execution of private functions only; no proving, and no kernel logic.
922
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
1001
+ const privateExecutionResult = await this.#executePrivate({
1002
+ contractFunctionSimulator,
1003
+ txRequest,
1004
+ anchorBlockHeader,
1005
+ scopes,
1006
+ jobId,
1007
+ senderForTags,
1008
+ });
923
1009
 
924
1010
  let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
925
1011
  let executionSteps: PrivateExecutionStep[] = [];
@@ -932,11 +1018,17 @@ export class PXE {
932
1018
  ));
933
1019
  } else {
934
1020
  // Kernel logic, plus proving of all private functions and kernels.
935
- ({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
936
- simulate: true,
937
- skipFeeEnforcement,
938
- profileMode: 'none',
939
- }));
1021
+ ({ publicInputs, executionSteps } = await this.#prove(
1022
+ txRequest,
1023
+ this.proofCreator,
1024
+ privateExecutionResult,
1025
+ anchorBlockHeader,
1026
+ {
1027
+ simulate: true,
1028
+ skipFeeEnforcement,
1029
+ profileMode: 'none',
1030
+ },
1031
+ ));
940
1032
  }
941
1033
 
942
1034
  const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
@@ -947,6 +1039,9 @@ export class PXE {
947
1039
  const publicSimulationTimer = new Timer();
948
1040
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
949
1041
  publicSimulationTime = publicSimulationTimer.ms();
1042
+ if (publicOutput?.debugLogs?.length) {
1043
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
1044
+ }
950
1045
  }
951
1046
 
952
1047
  let validationTime: number | undefined;
@@ -955,7 +1050,8 @@ export class PXE {
955
1050
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
956
1051
  validationTime = validationTimer.ms();
957
1052
  if (validationResult.result === 'invalid') {
958
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
1053
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
1054
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
959
1055
  }
960
1056
  }
961
1057
 
@@ -1006,23 +1102,23 @@ export class PXE {
1006
1102
  inspect(txRequest),
1007
1103
  `simulatePublic=${simulatePublic}`,
1008
1104
  `skipTxValidation=${skipTxValidation}`,
1009
- `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1105
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1010
1106
  );
1011
1107
  }
1012
1108
  });
1013
1109
  }
1014
1110
 
1015
1111
  /**
1016
- * Simulates the execution of a contract utility function.
1112
+ * Executes a contract utility function.
1017
1113
  * @param call - The function call containing the function details, arguments, and target contract address.
1018
1114
  */
1019
- public simulateUtility(
1115
+ public executeUtility(
1020
1116
  call: FunctionCall,
1021
- { authwits, scopes }: SimulateUtilityOpts = { scopes: 'ALL_SCOPES' },
1022
- ): Promise<UtilitySimulationResult> {
1023
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1117
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
1118
+ ): Promise<UtilityExecutionResult> {
1119
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
1024
1120
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
1025
- // delete the same read value, or reading values that another simulation is currently modifying).
1121
+ // delete the same read value, or reading values that another execution is currently modifying).
1026
1122
  return this.#putInJobQueue(async jobId => {
1027
1123
  try {
1028
1124
  const totalTimer = new Timer();
@@ -1037,13 +1133,13 @@ export class PXE {
1037
1133
  call.to,
1038
1134
  call.selector,
1039
1135
  (privateSyncCall, execScopes) =>
1040
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1136
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1041
1137
  anchorBlockHeader,
1042
1138
  jobId,
1043
1139
  scopes,
1044
1140
  );
1045
1141
 
1046
- const executionResult = await this.#simulateUtility(
1142
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
1047
1143
  contractFunctionSimulator,
1048
1144
  call,
1049
1145
  authwits ?? [],
@@ -1064,14 +1160,19 @@ export class PXE {
1064
1160
  };
1065
1161
 
1066
1162
  const simulationStats = contractFunctionSimulator.getStats();
1067
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1163
+ return {
1164
+ result: executionResult,
1165
+ offchainEffects,
1166
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1167
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1168
+ };
1068
1169
  } catch (err: any) {
1069
1170
  const { to, name, args } = call;
1070
1171
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1071
1172
  throw this.#contextualizeError(
1072
1173
  err,
1073
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1074
- `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1174
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1175
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1075
1176
  );
1076
1177
  }
1077
1178
  });
@@ -1108,7 +1209,7 @@ export class PXE {
1108
1209
  filter.contractAddress,
1109
1210
  null,
1110
1211
  async (privateSyncCall, execScopes) =>
1111
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1212
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1112
1213
  anchorBlockHeader,
1113
1214
  jobId,
1114
1215
  filter.scopes,
@@ -1126,9 +1227,11 @@ export class PXE {
1126
1227
  }
1127
1228
 
1128
1229
  /**
1129
- * Stops the PXE's job queue.
1230
+ * Stops the PXE's job queue and closes the backing store.
1130
1231
  */
1131
- public stop(): Promise<void> {
1132
- return this.jobQueue.end();
1232
+ public async stop(): Promise<void> {
1233
+ await this.jobQueue.end();
1234
+ await this.blockStateSynchronizer.stop();
1235
+ await this.db.close();
1133
1236
  }
1134
1237
  }
@@ -23,7 +23,7 @@ export class AnchorBlockStore {
23
23
  }
24
24
 
25
25
  async getBlockHeader(): Promise<BlockHeader> {
26
- const headerBuffer = await this.#synchronizedHeader.getAsync();
26
+ const headerBuffer = await this.#store.transactionAsync(() => this.#synchronizedHeader.getAsync());
27
27
  if (!headerBuffer) {
28
28
  throw new Error(`Trying to get block header with a not-yet-synchronized PXE - this should never happen`);
29
29
  }