@aztec/pxe 0.0.1-commit.e6bd8901 → 0.0.1-commit.ec7ac5448

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 (257) hide show
  1. package/dest/bin/check_oracle_version.js +4 -4
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +5 -3
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  4. package/dest/block_synchronizer/block_synchronizer.js +17 -5
  5. package/dest/config/index.d.ts +2 -2
  6. package/dest/config/index.d.ts.map +1 -1
  7. package/dest/config/index.js +1 -1
  8. package/dest/config/package_info.js +1 -1
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts +60 -31
  10. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  11. package/dest/contract_function_simulator/contract_function_simulator.js +201 -74
  12. package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
  13. package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
  14. package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
  15. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  16. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
  18. package/dest/contract_function_simulator/index.d.ts +2 -1
  19. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/index.js +1 -0
  21. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -6
  22. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +8 -10
  24. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
  25. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
  26. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
  27. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +2 -4
  29. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +4 -7
  30. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +6 -11
  32. package/dest/contract_function_simulator/oracle/interfaces.d.ts +62 -46
  33. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  35. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  36. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +47 -0
  37. package/dest/contract_function_simulator/oracle/oracle.d.ts +75 -44
  38. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  39. package/dest/contract_function_simulator/oracle/oracle.js +310 -113
  40. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  41. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +53 -79
  42. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  43. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +109 -89
  44. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +124 -67
  45. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  46. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +326 -140
  47. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  48. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  49. package/dest/contract_function_simulator/pick_notes.js +9 -2
  50. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
  51. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  52. package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
  53. package/dest/contract_logging.d.ts +27 -0
  54. package/dest/contract_logging.d.ts.map +1 -0
  55. package/dest/contract_logging.js +38 -0
  56. package/dest/contract_sync/contract_sync_service.d.ts +44 -0
  57. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  58. package/dest/contract_sync/contract_sync_service.js +104 -0
  59. package/dest/contract_sync/helpers.d.ts +28 -0
  60. package/dest/contract_sync/helpers.d.ts.map +1 -0
  61. package/dest/contract_sync/{index.js → helpers.js} +20 -16
  62. package/dest/debug/pxe_debug_utils.d.ts +24 -10
  63. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  64. package/dest/debug/pxe_debug_utils.js +28 -18
  65. package/dest/entrypoints/client/bundle/index.d.ts +3 -1
  66. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  67. package/dest/entrypoints/client/bundle/index.js +2 -0
  68. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  69. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  70. package/dest/entrypoints/client/bundle/utils.js +23 -9
  71. package/dest/entrypoints/client/lazy/index.d.ts +3 -1
  72. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  73. package/dest/entrypoints/client/lazy/index.js +2 -0
  74. package/dest/entrypoints/client/lazy/utils.d.ts +3 -3
  75. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  76. package/dest/entrypoints/client/lazy/utils.js +24 -10
  77. package/dest/entrypoints/pxe_creation_options.d.ts +5 -2
  78. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  79. package/dest/entrypoints/pxe_creation_options.js +3 -1
  80. package/dest/entrypoints/server/index.d.ts +4 -3
  81. package/dest/entrypoints/server/index.d.ts.map +1 -1
  82. package/dest/entrypoints/server/index.js +3 -2
  83. package/dest/entrypoints/server/utils.d.ts +2 -2
  84. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  85. package/dest/entrypoints/server/utils.js +30 -11
  86. package/dest/events/event_service.d.ts +5 -5
  87. package/dest/events/event_service.d.ts.map +1 -1
  88. package/dest/events/event_service.js +20 -9
  89. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  90. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  91. package/dest/job_coordinator/job_coordinator.js +3 -2
  92. package/dest/logs/log_service.d.ts +8 -9
  93. package/dest/logs/log_service.d.ts.map +1 -1
  94. package/dest/logs/log_service.js +38 -62
  95. package/dest/messages/message_context_service.d.ts +17 -0
  96. package/dest/messages/message_context_service.d.ts.map +1 -0
  97. package/dest/messages/message_context_service.js +36 -0
  98. package/dest/notes/note_service.d.ts +7 -8
  99. package/dest/notes/note_service.d.ts.map +1 -1
  100. package/dest/notes/note_service.js +23 -15
  101. package/dest/notes_filter.d.ts +24 -0
  102. package/dest/notes_filter.d.ts.map +1 -0
  103. package/dest/notes_filter.js +4 -0
  104. package/dest/oracle_version.d.ts +4 -3
  105. package/dest/oracle_version.d.ts.map +1 -1
  106. package/dest/oracle_version.js +20 -10
  107. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  108. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  109. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  110. package/dest/private_kernel/hints/index.d.ts +1 -1
  111. package/dest/private_kernel/hints/index.js +1 -1
  112. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  113. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  114. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  115. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  116. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  117. package/dest/private_kernel/hints/test_utils.js +203 -0
  118. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  119. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  120. package/dest/private_kernel/private_kernel_execution_prover.js +21 -13
  121. package/dest/private_kernel/private_kernel_oracle.d.ts +8 -4
  122. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  123. package/dest/private_kernel/private_kernel_oracle.js +7 -3
  124. package/dest/pxe.d.ts +73 -24
  125. package/dest/pxe.d.ts.map +1 -1
  126. package/dest/pxe.js +131 -78
  127. package/dest/storage/address_store/address_store.d.ts +1 -1
  128. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  129. package/dest/storage/address_store/address_store.js +12 -11
  130. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  131. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  132. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  133. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  134. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  135. package/dest/storage/capsule_store/capsule_service.js +50 -0
  136. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  137. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  138. package/dest/storage/capsule_store/capsule_store.js +39 -36
  139. package/dest/storage/capsule_store/index.d.ts +2 -1
  140. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  141. package/dest/storage/capsule_store/index.js +1 -0
  142. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  143. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  144. package/dest/storage/contract_store/contract_store.js +157 -72
  145. package/dest/storage/metadata.d.ts +1 -1
  146. package/dest/storage/metadata.js +1 -1
  147. package/dest/storage/note_store/note_store.d.ts +13 -3
  148. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  149. package/dest/storage/note_store/note_store.js +147 -107
  150. package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
  151. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  152. package/dest/storage/private_event_store/private_event_store.js +84 -61
  153. package/dest/storage/private_event_store/stored_private_event.d.ts +4 -4
  154. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -1
  155. package/dest/storage/private_event_store/stored_private_event.js +2 -2
  156. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  157. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  158. package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
  159. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  160. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  161. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  162. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  163. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  164. package/dest/storage/tagging_store/sender_tagging_store.js +233 -137
  165. package/dest/tagging/get_all_logs_by_tags.d.ts +4 -4
  166. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  167. package/dest/tagging/get_all_logs_by_tags.js +17 -3
  168. package/dest/tagging/index.d.ts +3 -3
  169. package/dest/tagging/index.d.ts.map +1 -1
  170. package/dest/tagging/index.js +1 -1
  171. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +5 -6
  172. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  173. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
  174. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  175. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +7 -8
  176. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  177. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  178. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -9
  179. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  180. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
  181. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  182. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  183. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  184. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +6 -8
  185. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  186. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
  187. package/package.json +25 -16
  188. package/src/bin/check_oracle_version.ts +4 -4
  189. package/src/block_synchronizer/block_synchronizer.ts +29 -19
  190. package/src/config/index.ts +1 -1
  191. package/src/config/package_info.ts +1 -1
  192. package/src/contract_function_simulator/contract_function_simulator.ts +360 -133
  193. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  194. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  195. package/src/contract_function_simulator/index.ts +1 -0
  196. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +9 -9
  197. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
  198. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
  199. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +4 -10
  200. package/src/contract_function_simulator/oracle/interfaces.ts +90 -62
  201. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
  202. package/src/contract_function_simulator/oracle/oracle.ts +391 -150
  203. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  204. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +136 -187
  205. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +544 -174
  206. package/src/contract_function_simulator/pick_notes.ts +9 -2
  207. package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
  208. package/src/contract_logging.ts +52 -0
  209. package/src/contract_sync/contract_sync_service.ts +170 -0
  210. package/src/contract_sync/{index.ts → helpers.ts} +23 -25
  211. package/src/debug/pxe_debug_utils.ts +63 -19
  212. package/src/entrypoints/client/bundle/index.ts +2 -0
  213. package/src/entrypoints/client/bundle/utils.ts +18 -18
  214. package/src/entrypoints/client/lazy/index.ts +2 -0
  215. package/src/entrypoints/client/lazy/utils.ts +19 -18
  216. package/src/entrypoints/pxe_creation_options.ts +9 -1
  217. package/src/entrypoints/server/index.ts +3 -2
  218. package/src/entrypoints/server/utils.ts +24 -29
  219. package/src/events/event_service.ts +21 -10
  220. package/src/job_coordinator/job_coordinator.ts +4 -3
  221. package/src/logs/log_service.ts +72 -106
  222. package/src/messages/message_context_service.ts +44 -0
  223. package/src/notes/note_service.ts +24 -16
  224. package/src/notes_filter.ts +24 -0
  225. package/src/oracle_version.ts +20 -10
  226. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  227. package/src/private_kernel/hints/index.ts +1 -1
  228. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  229. package/src/private_kernel/hints/test_utils.ts +325 -0
  230. package/src/private_kernel/private_kernel_execution_prover.ts +25 -15
  231. package/src/private_kernel/private_kernel_oracle.ts +9 -9
  232. package/src/pxe.ts +243 -131
  233. package/src/storage/address_store/address_store.ts +15 -15
  234. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  235. package/src/storage/capsule_store/capsule_service.ts +90 -0
  236. package/src/storage/capsule_store/capsule_store.ts +42 -34
  237. package/src/storage/capsule_store/index.ts +1 -0
  238. package/src/storage/contract_store/contract_store.ts +186 -76
  239. package/src/storage/metadata.ts +1 -1
  240. package/src/storage/note_store/note_store.ts +166 -132
  241. package/src/storage/private_event_store/private_event_store.ts +102 -81
  242. package/src/storage/private_event_store/stored_private_event.ts +3 -3
  243. package/src/storage/tagging_store/recipient_tagging_store.ts +38 -24
  244. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  245. package/src/storage/tagging_store/sender_tagging_store.ts +287 -156
  246. package/src/tagging/get_all_logs_by_tags.ts +31 -7
  247. package/src/tagging/index.ts +2 -2
  248. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +9 -12
  249. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  250. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +12 -17
  251. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +25 -12
  252. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  253. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +30 -29
  254. package/dest/contract_sync/index.d.ts +0 -23
  255. package/dest/contract_sync/index.d.ts.map +0 -1
  256. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  257. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
package/src/pxe.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
2
  import { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
- import { type Logger, createLogger } from '@aztec/foundation/log';
4
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
5
5
  import { SerialQueue } from '@aztec/foundation/queue';
6
6
  import { Timer } from '@aztec/foundation/timer';
7
7
  import { KeyStore } from '@aztec/key-store';
@@ -18,7 +18,6 @@ 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 { L2BlockHash } from '@aztec/stdlib/block';
22
21
  import {
23
22
  CompleteAddress,
24
23
  type ContractInstanceWithAddress,
@@ -34,6 +33,7 @@ import type {
34
33
  PrivateKernelTailCircuitPublicInputs,
35
34
  } from '@aztec/stdlib/kernel';
36
35
  import {
36
+ BlockHeader,
37
37
  type ContractOverrides,
38
38
  type InTx,
39
39
  PrivateExecutionResult,
@@ -47,7 +47,7 @@ import {
47
47
  TxProfileResult,
48
48
  TxProvingResult,
49
49
  TxSimulationResult,
50
- UtilitySimulationResult,
50
+ UtilityExecutionResult,
51
51
  } from '@aztec/stdlib/tx';
52
52
 
53
53
  import { inspect } from 'util';
@@ -60,11 +60,14 @@ import {
60
60
  generateSimulatedProvingResult,
61
61
  } from './contract_function_simulator/contract_function_simulator.js';
62
62
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
63
- import { ensureContractSynced, readCurrentClassId } from './contract_sync/index.js';
63
+ import { displayDebugLogs } from './contract_logging.js';
64
+ import { ContractSyncService } from './contract_sync/contract_sync_service.js';
65
+ import { readCurrentClassId } from './contract_sync/helpers.js';
64
66
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
65
67
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
66
68
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
67
69
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
70
+ import { MessageContextService } from './messages/message_context_service.js';
68
71
  import {
69
72
  PrivateKernelExecutionProver,
70
73
  type PrivateKernelExecutionProverConfig,
@@ -85,6 +88,58 @@ export type PackedPrivateEvent = InTx & {
85
88
  eventSelector: EventSelector;
86
89
  };
87
90
 
91
+ /** Options for PXE.profileTx. */
92
+ export type ProfileTxOpts = {
93
+ /** The profiling mode to use. */
94
+ profileMode: 'full' | 'execution-steps' | 'gates';
95
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
96
+ skipProofGeneration?: boolean;
97
+ /** Addresses whose private state and keys are accessible during private execution. */
98
+ scopes: AztecAddress[];
99
+ };
100
+
101
+ /** Options for PXE.simulateTx. */
102
+ export type SimulateTxOpts = {
103
+ /** Whether to simulate the public part of the transaction. */
104
+ simulatePublic: boolean;
105
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
106
+ skipTxValidation?: boolean;
107
+ /** If false, fees are enforced. */
108
+ skipFeeEnforcement?: boolean;
109
+ /** If true, kernel logic is emulated in TS for simulation */
110
+ skipKernels?: boolean;
111
+ /** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
112
+ overrides?: SimulationOverrides;
113
+ /** Addresses whose private state and keys are accessible during private execution */
114
+ scopes: AztecAddress[];
115
+ };
116
+
117
+ /** Options for PXE.executeUtility. */
118
+ export type ExecuteUtilityOpts = {
119
+ /** The authentication witnesses required for the function call. */
120
+ authwits?: AuthWitness[];
121
+ /** The accounts whose notes we can access in this call */
122
+ scopes: AztecAddress[];
123
+ };
124
+
125
+ /** Args for PXE.create. */
126
+ export type PXECreateArgs = {
127
+ /** The Aztec node to connect to. */
128
+ node: AztecNode;
129
+ /** The key-value store for persisting PXE state. */
130
+ store: AztecAsyncKVStore;
131
+ /** The prover for generating private kernel proofs. */
132
+ proofCreator: PrivateKernelProver;
133
+ /** The circuit simulator for executing ACIR circuits. */
134
+ simulator: CircuitSimulator;
135
+ /** Provider for protocol contract artifacts and instances. */
136
+ protocolContractsProvider: ProtocolContractsProvider;
137
+ /** PXE configuration options. */
138
+ config: PXEConfig;
139
+ /** Optional logger instance or string suffix for the logger name. */
140
+ loggerOrSuffix?: string | Logger;
141
+ };
142
+
88
143
  /**
89
144
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
90
145
  * manage private state of users.
@@ -92,6 +147,7 @@ export type PackedPrivateEvent = InTx & {
92
147
  export class PXE {
93
148
  private constructor(
94
149
  private node: AztecNode,
150
+ private db: AztecAsyncKVStore,
95
151
  private blockStateSynchronizer: BlockSynchronizer,
96
152
  private keyStore: KeyStore,
97
153
  private contractStore: ContractStore,
@@ -103,6 +159,8 @@ export class PXE {
103
159
  private recipientTaggingStore: RecipientTaggingStore,
104
160
  private addressStore: AddressStore,
105
161
  private privateEventStore: PrivateEventStore,
162
+ private contractSyncService: ContractSyncService,
163
+ private messageContextService: MessageContextService,
106
164
  private simulator: CircuitSimulator,
107
165
  private proverEnabled: boolean,
108
166
  private proofCreator: PrivateKernelProver,
@@ -120,21 +178,27 @@ export class PXE {
120
178
  *
121
179
  * @returns A promise that resolves PXE is ready to be used.
122
180
  */
123
- public static async create(
124
- node: AztecNode,
125
- store: AztecAsyncKVStore,
126
- proofCreator: PrivateKernelProver,
127
- simulator: CircuitSimulator,
128
- protocolContractsProvider: ProtocolContractsProvider,
129
- config: PXEConfig,
130
- loggerOrSuffix?: string | Logger,
131
- ) {
181
+ public static async create({
182
+ node,
183
+ store,
184
+ proofCreator,
185
+ simulator,
186
+ protocolContractsProvider,
187
+ config,
188
+ loggerOrSuffix,
189
+ }: PXECreateArgs) {
190
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
191
+ const bindings: LoggerBindings | undefined =
192
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
193
+
132
194
  const log =
133
195
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
134
196
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
135
197
  : loggerOrSuffix;
136
198
 
137
- const proverEnabled = !!config.proverEnabled;
199
+ const info = await node.getNodeInfo();
200
+
201
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
138
202
  const addressStore = new AddressStore(store);
139
203
  const privateEventStore = new PrivateEventStore(store);
140
204
  const contractStore = new ContractStore(store);
@@ -146,6 +210,14 @@ export class PXE {
146
210
  const capsuleStore = new CapsuleStore(store);
147
211
  const keyStore = new KeyStore(store);
148
212
  const tipsStore = new L2TipsKVStore(store, 'pxe');
213
+ const contractSyncService = new ContractSyncService(
214
+ node,
215
+ contractStore,
216
+ noteStore,
217
+ createLogger('pxe:contract_sync', bindings),
218
+ );
219
+ const messageContextService = new MessageContextService(node);
220
+
149
221
  const synchronizer = new BlockSynchronizer(
150
222
  node,
151
223
  store,
@@ -153,25 +225,28 @@ export class PXE {
153
225
  noteStore,
154
226
  privateEventStore,
155
227
  tipsStore,
228
+ contractSyncService,
156
229
  config,
157
- loggerOrSuffix,
230
+ bindings,
158
231
  );
159
232
 
160
- const jobCoordinator = new JobCoordinator(store);
233
+ const jobCoordinator = new JobCoordinator(store, bindings);
161
234
  jobCoordinator.registerStores([
162
235
  capsuleStore,
163
236
  senderTaggingStore,
164
237
  recipientTaggingStore,
165
238
  privateEventStore,
166
239
  noteStore,
240
+ contractSyncService,
167
241
  ]);
168
242
 
169
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
243
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
170
244
 
171
245
  const jobQueue = new SerialQueue();
172
246
 
173
247
  const pxe = new PXE(
174
248
  node,
249
+ store,
175
250
  synchronizer,
176
251
  keyStore,
177
252
  contractStore,
@@ -183,6 +258,8 @@ export class PXE {
183
258
  recipientTaggingStore,
184
259
  addressStore,
185
260
  privateEventStore,
261
+ contractSyncService,
262
+ messageContextService,
186
263
  simulator,
187
264
  proverEnabled,
188
265
  proofCreator,
@@ -193,12 +270,15 @@ export class PXE {
193
270
  debugUtils,
194
271
  );
195
272
 
196
- debugUtils.setPXE(pxe);
273
+ debugUtils.setPXEHelpers(
274
+ pxe.#putInJobQueue.bind(pxe),
275
+ pxe.#getSimulatorForTx.bind(pxe),
276
+ pxe.#executeUtility.bind(pxe),
277
+ );
197
278
 
198
279
  pxe.jobQueue.start();
199
280
 
200
281
  await pxe.#registerProtocolContracts();
201
- const info = await node.getNodeInfo();
202
282
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
203
283
  return pxe;
204
284
  }
@@ -208,20 +288,21 @@ export class PXE {
208
288
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
209
289
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
210
290
 
211
- return new ContractFunctionSimulator(
212
- proxyContractStore,
213
- this.noteStore,
214
- this.keyStore,
215
- this.addressStore,
216
- BenchmarkedNodeFactory.create(this.node),
217
- this.anchorBlockStore,
218
- this.senderTaggingStore,
219
- this.recipientTaggingStore,
220
- this.senderAddressBookStore,
221
- this.capsuleStore,
222
- this.privateEventStore,
223
- this.simulator,
224
- );
291
+ return new ContractFunctionSimulator({
292
+ contractStore: proxyContractStore,
293
+ noteStore: this.noteStore,
294
+ keyStore: this.keyStore,
295
+ addressStore: this.addressStore,
296
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
297
+ senderTaggingStore: this.senderTaggingStore,
298
+ recipientTaggingStore: this.recipientTaggingStore,
299
+ senderAddressBookStore: this.senderAddressBookStore,
300
+ capsuleStore: this.capsuleStore,
301
+ privateEventStore: this.privateEventStore,
302
+ simulator: this.simulator,
303
+ contractSyncService: this.contractSyncService,
304
+ messageContextService: this.messageContextService,
305
+ });
225
306
  }
226
307
 
227
308
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -273,9 +354,8 @@ export class PXE {
273
354
  async #registerProtocolContracts() {
274
355
  const registered: Record<string, string> = {};
275
356
  for (const name of protocolContractNames) {
276
- const { address, contractClass, instance, artifact } =
277
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
278
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
357
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
358
+ await this.contractStore.addContractArtifact(artifact);
279
359
  await this.contractStore.addContractInstance(instance);
280
360
  registered[name] = address.toString();
281
361
  }
@@ -287,7 +367,7 @@ export class PXE {
287
367
  async #executePrivate(
288
368
  contractFunctionSimulator: ContractFunctionSimulator,
289
369
  txRequest: TxExecutionRequest,
290
- scopes: AztecAddress[] | undefined,
370
+ scopes: AztecAddress[],
291
371
  jobId: string,
292
372
  ): Promise<PrivateExecutionResult> {
293
373
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -295,27 +375,23 @@ export class PXE {
295
375
  try {
296
376
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
297
377
 
298
- await ensureContractSynced(
378
+ await this.contractSyncService.ensureContractSynced(
299
379
  contractAddress,
300
380
  functionSelector,
301
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
302
- this.node,
303
- this.contractStore,
381
+ (privateSyncCall, execScopes) =>
382
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
304
383
  anchorBlockHeader,
384
+ jobId,
385
+ scopes,
305
386
  );
306
387
 
307
- const result = await contractFunctionSimulator.run(
308
- txRequest,
388
+ const result = await contractFunctionSimulator.run(txRequest, {
309
389
  contractAddress,
310
- functionSelector,
311
- undefined,
390
+ selector: functionSelector,
312
391
  anchorBlockHeader,
313
- // The sender for tags is set by contracts, typically by an account
314
- // contract entrypoint
315
- undefined, // senderForTags
316
392
  scopes,
317
393
  jobId,
318
- );
394
+ });
319
395
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
320
396
  return result;
321
397
  } catch (err) {
@@ -327,25 +403,32 @@ export class PXE {
327
403
  }
328
404
 
329
405
  /**
330
- * Simulate a utility function call on the given contract.
406
+ * Execute a utility function call on the given contract.
331
407
  * @param contractFunctionSimulator - The simulator to use for the function call.
332
408
  * @param call - The function call to execute.
333
409
  * @param authWitnesses - Authentication witnesses required for the function call.
334
410
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
335
411
  * accounts if not specified.
336
412
  * @param jobId - The job ID for staged writes.
337
- * @returns The simulation result containing the outputs of the utility function.
413
+ * @returns The execution result containing the outputs of the utility function.
338
414
  */
339
- async #simulateUtility(
415
+ async #executeUtility(
340
416
  contractFunctionSimulator: ContractFunctionSimulator,
341
417
  call: FunctionCall,
342
418
  authWitnesses: AuthWitness[] | undefined,
343
- scopes: AztecAddress[] | undefined,
419
+ scopes: AztecAddress[],
344
420
  jobId: string,
345
421
  ) {
346
422
  try {
347
423
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
348
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
424
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
425
+ call,
426
+ authWitnesses ?? [],
427
+ anchorBlockHeader,
428
+ scopes,
429
+ jobId,
430
+ );
431
+ return { result, offchainEffects };
349
432
  } catch (err) {
350
433
  if (err instanceof SimulationError) {
351
434
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -399,15 +482,35 @@ export class PXE {
399
482
  config: PrivateKernelExecutionProverConfig,
400
483
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
401
484
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
402
- const anchorBlockHash = L2BlockHash.fromField(await anchorBlockHeader.hash());
485
+ const anchorBlockHash = await anchorBlockHeader.hash();
403
486
  const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
404
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
487
+ const kernelTraceProver = new PrivateKernelExecutionProver(
488
+ kernelOracle,
489
+ proofCreator,
490
+ !this.proverEnabled,
491
+ this.log.getBindings(),
492
+ );
405
493
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
406
494
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
407
495
  }
408
496
 
409
497
  // Public API
410
498
 
499
+ /**
500
+ * Returns the block header up to which the PXE has synced.
501
+ * @returns The synced block header
502
+ */
503
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
504
+ return this.#putInJobQueue(() => {
505
+ return this.anchorBlockStore.getBlockHeader();
506
+ });
507
+ }
508
+
509
+ /**
510
+ * Returns the contract instance for a given address, if it's registered in the PXE.
511
+ * @param address - The contract address.
512
+ * @returns The contract instance if found, undefined otherwise.
513
+ */
411
514
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
412
515
  return this.contractStore.getContractInstance(address);
413
516
  }
@@ -467,6 +570,9 @@ export class PXE {
467
570
 
468
571
  if (wasAdded) {
469
572
  this.log.info(`Added sender:\n ${sender.toString()}`);
573
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
574
+ // all contracts must re-sync to discover them.
575
+ this.contractSyncService.wipe();
470
576
  } else {
471
577
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
472
578
  }
@@ -516,8 +622,7 @@ export class PXE {
516
622
  * @param artifact - The build artifact for the contract class.
517
623
  */
518
624
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
519
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
520
- await this.contractStore.addContractArtifact(contractClassId, artifact);
625
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
521
626
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
522
627
  }
523
628
 
@@ -536,17 +641,17 @@ export class PXE {
536
641
  if (artifact) {
537
642
  // If the user provides an artifact, validate it against the expected class id and register it
538
643
  const contractClass = await getContractClassFromArtifact(artifact);
539
- const contractClassId = contractClass.id;
540
- if (!contractClassId.equals(instance.currentContractClassId)) {
644
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
541
645
  throw new Error(
542
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
646
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
543
647
  );
544
648
  }
545
649
  const computedAddress = await computeContractAddressFromInstance(instance);
546
650
  if (!computedAddress.equals(instance.address)) {
547
651
  throw new Error('Added a contract in which the address does not match the contract instance.');
548
652
  }
549
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
653
+
654
+ await this.contractStore.addContractArtifact(artifact, contractClass);
550
655
 
551
656
  const publicFunctionSignatures = artifact.functions
552
657
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -595,15 +700,16 @@ export class PXE {
595
700
  throw new Error('Could not update contract to a class different from the current one.');
596
701
  }
597
702
 
598
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
599
-
600
703
  const publicFunctionSignatures = artifact.functions
601
704
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
602
705
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
603
706
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
604
707
 
605
708
  currentInstance.currentContractClassId = contractClass.id;
606
- await this.contractStore.addContractInstance(currentInstance);
709
+ await Promise.all([
710
+ this.contractStore.addContractArtifact(artifact, contractClass),
711
+ this.contractStore.addContractInstance(currentInstance),
712
+ ]);
607
713
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
608
714
  });
609
715
  }
@@ -621,11 +727,12 @@ export class PXE {
621
727
  * (where validators prove the public portion).
622
728
  *
623
729
  * @param txRequest - An authenticated tx request ready for proving
730
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
624
731
  * @returns A result containing the proof and public inputs of the tail circuit.
625
732
  * @throws If contract code not found, or public simulation reverts.
626
733
  * Also throws if simulatePublic is true and public simulation reverts.
627
734
  */
628
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
735
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
629
736
  let privateExecutionResult: PrivateExecutionResult;
630
737
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
631
738
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -636,7 +743,7 @@ export class PXE {
636
743
  await this.blockStateSynchronizer.sync();
637
744
  const syncTime = syncTimer.ms();
638
745
  const contractFunctionSimulator = this.#getSimulatorForTx();
639
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
746
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
640
747
 
641
748
  const {
642
749
  publicInputs,
@@ -678,17 +785,17 @@ export class PXE {
678
785
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
679
786
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
680
787
  // storing the tags here prevents linkage of txs sent from the same PXE.
681
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
682
- if (preTagsUsedInTheTx.length > 0) {
788
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
789
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
683
790
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
684
791
  const txHash = (await txProvingResult.toTx()).txHash;
685
792
 
686
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
687
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
688
- preTagsUsedInTheTx,
793
+ await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
794
+ this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
795
+ taggingIndexRangesUsedInTheTx,
689
796
  });
690
797
  } else {
691
- this.log.debug(`No pre-tags used in the tx`);
798
+ this.log.debug(`No tagging index ranges used in the tx`);
692
799
  }
693
800
 
694
801
  return txProvingResult;
@@ -700,17 +807,13 @@ export class PXE {
700
807
 
701
808
  /**
702
809
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
703
- *
704
- * @param txRequest - An authenticated tx request ready for simulation
705
- * @param msgSender - (Optional) The message sender to use for the simulation.
706
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
810
+ * @param txRequest - An authenticated tx request ready for simulation.
707
811
  * @returns A trace of the program execution with gate counts.
708
812
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
709
813
  */
710
814
  public profileTx(
711
815
  txRequest: TxExecutionRequest,
712
- profileMode: 'full' | 'execution-steps' | 'gates',
713
- skipProofGeneration: boolean = true,
816
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
714
817
  ): Promise<TxProfileResult> {
715
818
  // We disable concurrent profiles for consistency with simulateTx.
716
819
  return this.#putInJobQueue(async jobId => {
@@ -733,12 +836,7 @@ export class PXE {
733
836
  const syncTime = syncTimer.ms();
734
837
 
735
838
  const contractFunctionSimulator = this.#getSimulatorForTx();
736
- const privateExecutionResult = await this.#executePrivate(
737
- contractFunctionSimulator,
738
- txRequest,
739
- undefined,
740
- jobId,
741
- );
839
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
742
840
 
743
841
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
744
842
  txRequest,
@@ -795,12 +893,7 @@ export class PXE {
795
893
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
796
894
  *
797
895
  *
798
- * @param txRequest - An authenticated tx request ready for simulation
799
- * @param simulatePublic - Whether to simulate the public part of the transaction.
800
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
801
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
802
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
803
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
896
+ * @param txRequest - An authenticated tx request ready for simulation.
804
897
  * @returns A simulated transaction result object that includes public and private return values.
805
898
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
806
899
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -809,11 +902,14 @@ export class PXE {
809
902
  */
810
903
  public simulateTx(
811
904
  txRequest: TxExecutionRequest,
812
- simulatePublic: boolean,
813
- skipTxValidation: boolean = false,
814
- skipFeeEnforcement: boolean = false,
815
- overrides?: SimulationOverrides,
816
- scopes?: AztecAddress[],
905
+ {
906
+ simulatePublic,
907
+ skipTxValidation = false,
908
+ skipFeeEnforcement = false,
909
+ skipKernels = true,
910
+ overrides,
911
+ scopes,
912
+ }: SimulateTxOpts,
817
913
  ): Promise<TxSimulationResult> {
818
914
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
819
915
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -837,11 +933,21 @@ export class PXE {
837
933
  await this.blockStateSynchronizer.sync();
838
934
  const syncTime = syncTimer.ms();
839
935
 
936
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
937
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
938
+
939
+ if (hasOverriddenContracts && !skipKernels) {
940
+ throw new Error(
941
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
942
+ );
943
+ }
840
944
  const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
841
- // Temporary: in case there are overrides, we have to skip the kernels or validations
842
- // will fail. Consider handing control to the user/wallet on whether they want to run them
843
- // or not.
844
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
945
+
946
+ if (hasOverriddenContracts) {
947
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
948
+ // We exclude them so the sync service skips them entirely.
949
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
950
+ }
845
951
 
846
952
  // Execution of private functions only; no proving, and no kernel logic.
847
953
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
@@ -852,7 +958,8 @@ export class PXE {
852
958
  if (skipKernels) {
853
959
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
854
960
  privateExecutionResult,
855
- this.contractStore,
961
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
962
+ this.node,
856
963
  ));
857
964
  } else {
858
965
  // Kernel logic, plus proving of all private functions and kernels.
@@ -871,6 +978,9 @@ export class PXE {
871
978
  const publicSimulationTimer = new Timer();
872
979
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
873
980
  publicSimulationTime = publicSimulationTimer.ms();
981
+ if (publicOutput?.debugLogs?.length) {
982
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
983
+ }
874
984
  }
875
985
 
876
986
  let validationTime: number | undefined;
@@ -879,7 +989,8 @@ export class PXE {
879
989
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
880
990
  validationTime = validationTimer.ms();
881
991
  if (validationResult.result === 'invalid') {
882
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
992
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
993
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
883
994
  }
884
995
  }
885
996
 
@@ -930,29 +1041,23 @@ export class PXE {
930
1041
  inspect(txRequest),
931
1042
  `simulatePublic=${simulatePublic}`,
932
1043
  `skipTxValidation=${skipTxValidation}`,
933
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1044
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
934
1045
  );
935
1046
  }
936
1047
  });
937
1048
  }
938
1049
 
939
1050
  /**
940
- * Simulate the execution of a contract utility function.
941
- *
1051
+ * Executes a contract utility function.
942
1052
  * @param call - The function call containing the function details, arguments, and target contract address.
943
- * @param authwits - (Optional) The authentication witnesses required for the function call.
944
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
945
- * default to all.
946
- * @returns The result of the utility function call, structured based on the function ABI.
947
1053
  */
948
- public simulateUtility(
1054
+ public executeUtility(
949
1055
  call: FunctionCall,
950
- authwits?: AuthWitness[],
951
- scopes?: AztecAddress[],
952
- ): Promise<UtilitySimulationResult> {
953
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1056
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
1057
+ ): Promise<UtilityExecutionResult> {
1058
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
954
1059
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
955
- // delete the same read value, or reading values that another simulation is currently modifying).
1060
+ // delete the same read value, or reading values that another execution is currently modifying).
956
1061
  return this.#putInJobQueue(async jobId => {
957
1062
  try {
958
1063
  const totalTimer = new Timer();
@@ -963,16 +1068,17 @@ export class PXE {
963
1068
  const contractFunctionSimulator = this.#getSimulatorForTx();
964
1069
 
965
1070
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
966
- await ensureContractSynced(
1071
+ await this.contractSyncService.ensureContractSynced(
967
1072
  call.to,
968
1073
  call.selector,
969
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
970
- this.node,
971
- this.contractStore,
1074
+ (privateSyncCall, execScopes) =>
1075
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
972
1076
  anchorBlockHeader,
1077
+ jobId,
1078
+ scopes,
973
1079
  );
974
1080
 
975
- const executionResult = await this.#simulateUtility(
1081
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
976
1082
  contractFunctionSimulator,
977
1083
  call,
978
1084
  authwits ?? [],
@@ -993,14 +1099,19 @@ export class PXE {
993
1099
  };
994
1100
 
995
1101
  const simulationStats = contractFunctionSimulator.getStats();
996
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1102
+ return {
1103
+ result: executionResult,
1104
+ offchainEffects,
1105
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1106
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1107
+ };
997
1108
  } catch (err: any) {
998
1109
  const { to, name, args } = call;
999
1110
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1000
1111
  throw this.#contextualizeError(
1001
1112
  err,
1002
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1003
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1113
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1114
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1004
1115
  );
1005
1116
  }
1006
1117
  });
@@ -1033,14 +1144,14 @@ export class PXE {
1033
1144
 
1034
1145
  const contractFunctionSimulator = this.#getSimulatorForTx();
1035
1146
 
1036
- await ensureContractSynced(
1147
+ await this.contractSyncService.ensureContractSynced(
1037
1148
  filter.contractAddress,
1038
1149
  null,
1039
- async privateSyncCall =>
1040
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1041
- this.node,
1042
- this.contractStore,
1150
+ async (privateSyncCall, execScopes) =>
1151
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1043
1152
  anchorBlockHeader,
1153
+ jobId,
1154
+ filter.scopes,
1044
1155
  );
1045
1156
  });
1046
1157
 
@@ -1055,9 +1166,10 @@ export class PXE {
1055
1166
  }
1056
1167
 
1057
1168
  /**
1058
- * Stops the PXE's job queue.
1169
+ * Stops the PXE's job queue and closes the backing store.
1059
1170
  */
1060
- public stop(): Promise<void> {
1061
- return this.jobQueue.end();
1171
+ public async stop(): Promise<void> {
1172
+ await this.jobQueue.end();
1173
+ await this.db.close();
1062
1174
  }
1063
1175
  }