@aztec/pxe 0.0.1-commit.d1f2d6c → 0.0.1-commit.d20b825a7

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 (261) hide show
  1. package/dest/bin/check_oracle_version.js +5 -5
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +10 -4
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  4. package/dest/block_synchronizer/block_synchronizer.js +30 -6
  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 +8 -15
  8. package/dest/config/package_info.js +1 -1
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts +63 -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 +206 -77
  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 +5 -7
  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 +9 -11
  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 +5 -8
  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 +7 -12
  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.d.ts +3 -22
  41. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  42. package/dest/contract_function_simulator/oracle/private_execution.js +5 -49
  43. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +60 -84
  44. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  45. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +125 -98
  46. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +128 -70
  47. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  48. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +330 -143
  49. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  50. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  51. package/dest/contract_function_simulator/pick_notes.js +20 -3
  52. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
  53. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  54. package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
  55. package/dest/contract_logging.d.ts +27 -0
  56. package/dest/contract_logging.d.ts.map +1 -0
  57. package/dest/contract_logging.js +38 -0
  58. package/dest/contract_sync/contract_sync_service.d.ts +44 -0
  59. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  60. package/dest/contract_sync/contract_sync_service.js +116 -0
  61. package/dest/contract_sync/helpers.d.ts +28 -0
  62. package/dest/contract_sync/helpers.d.ts.map +1 -0
  63. package/dest/contract_sync/helpers.js +60 -0
  64. package/dest/debug/pxe_debug_utils.d.ts +24 -10
  65. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  66. package/dest/debug/pxe_debug_utils.js +28 -18
  67. package/dest/entrypoints/client/bundle/index.d.ts +3 -1
  68. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  69. package/dest/entrypoints/client/bundle/index.js +2 -0
  70. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  71. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  72. package/dest/entrypoints/client/bundle/utils.js +23 -9
  73. package/dest/entrypoints/client/lazy/index.d.ts +3 -1
  74. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  75. package/dest/entrypoints/client/lazy/index.js +2 -0
  76. package/dest/entrypoints/client/lazy/utils.d.ts +3 -3
  77. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  78. package/dest/entrypoints/client/lazy/utils.js +24 -10
  79. package/dest/entrypoints/pxe_creation_options.d.ts +5 -2
  80. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  81. package/dest/entrypoints/pxe_creation_options.js +3 -1
  82. package/dest/entrypoints/server/index.d.ts +4 -2
  83. package/dest/entrypoints/server/index.d.ts.map +1 -1
  84. package/dest/entrypoints/server/index.js +3 -1
  85. package/dest/entrypoints/server/utils.d.ts +2 -2
  86. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  87. package/dest/entrypoints/server/utils.js +30 -11
  88. package/dest/events/event_service.d.ts +6 -6
  89. package/dest/events/event_service.d.ts.map +1 -1
  90. package/dest/events/event_service.js +31 -11
  91. package/dest/events/private_event_filter_validator.d.ts +3 -2
  92. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  93. package/dest/events/private_event_filter_validator.js +15 -0
  94. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  95. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  96. package/dest/job_coordinator/job_coordinator.js +3 -2
  97. package/dest/logs/log_service.d.ts +10 -9
  98. package/dest/logs/log_service.d.ts.map +1 -1
  99. package/dest/logs/log_service.js +41 -62
  100. package/dest/messages/message_context_service.d.ts +17 -0
  101. package/dest/messages/message_context_service.d.ts.map +1 -0
  102. package/dest/messages/message_context_service.js +36 -0
  103. package/dest/notes/note_service.d.ts +7 -8
  104. package/dest/notes/note_service.d.ts.map +1 -1
  105. package/dest/notes/note_service.js +23 -15
  106. package/dest/notes_filter.d.ts +24 -0
  107. package/dest/notes_filter.d.ts.map +1 -0
  108. package/dest/notes_filter.js +4 -0
  109. package/dest/oracle_version.d.ts +4 -3
  110. package/dest/oracle_version.d.ts.map +1 -1
  111. package/dest/oracle_version.js +20 -10
  112. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  113. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  114. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  115. package/dest/private_kernel/hints/index.d.ts +1 -1
  116. package/dest/private_kernel/hints/index.js +1 -1
  117. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  118. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  119. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  120. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  121. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  122. package/dest/private_kernel/hints/test_utils.js +203 -0
  123. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  124. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  125. package/dest/private_kernel/private_kernel_execution_prover.js +20 -15
  126. package/dest/private_kernel/private_kernel_oracle.d.ts +10 -6
  127. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  128. package/dest/private_kernel/private_kernel_oracle.js +19 -18
  129. package/dest/pxe.d.ts +85 -24
  130. package/dest/pxe.d.ts.map +1 -1
  131. package/dest/pxe.js +169 -87
  132. package/dest/storage/address_store/address_store.d.ts +1 -1
  133. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  134. package/dest/storage/address_store/address_store.js +12 -11
  135. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  136. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  137. package/dest/storage/anchor_block_store/anchor_block_store.js +9 -2
  138. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  139. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  140. package/dest/storage/capsule_store/capsule_service.js +50 -0
  141. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  142. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  143. package/dest/storage/capsule_store/capsule_store.js +42 -36
  144. package/dest/storage/capsule_store/index.d.ts +2 -1
  145. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  146. package/dest/storage/capsule_store/index.js +1 -0
  147. package/dest/storage/contract_store/contract_store.d.ts +42 -16
  148. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  149. package/dest/storage/contract_store/contract_store.js +160 -85
  150. package/dest/storage/metadata.d.ts +1 -1
  151. package/dest/storage/metadata.js +1 -1
  152. package/dest/storage/note_store/note_store.d.ts +14 -4
  153. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  154. package/dest/storage/note_store/note_store.js +149 -109
  155. package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
  156. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  157. package/dest/storage/private_event_store/private_event_store.js +87 -61
  158. package/dest/storage/private_event_store/stored_private_event.d.ts +4 -4
  159. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -1
  160. package/dest/storage/private_event_store/stored_private_event.js +2 -2
  161. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  162. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  163. package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
  164. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  165. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  166. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  167. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  168. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  169. package/dest/storage/tagging_store/sender_tagging_store.js +233 -137
  170. package/dest/tagging/get_all_logs_by_tags.d.ts +4 -4
  171. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  172. package/dest/tagging/get_all_logs_by_tags.js +17 -3
  173. package/dest/tagging/index.d.ts +3 -3
  174. package/dest/tagging/index.d.ts.map +1 -1
  175. package/dest/tagging/index.js +1 -1
  176. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +5 -6
  177. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  178. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +8 -22
  179. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  180. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +7 -8
  181. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  182. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  183. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -9
  184. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  185. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
  186. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  187. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  188. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  189. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +6 -8
  190. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  191. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
  192. package/package.json +25 -16
  193. package/src/bin/check_oracle_version.ts +5 -4
  194. package/src/block_synchronizer/block_synchronizer.ts +45 -21
  195. package/src/config/index.ts +3 -9
  196. package/src/config/package_info.ts +1 -1
  197. package/src/contract_function_simulator/contract_function_simulator.ts +366 -136
  198. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  199. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  200. package/src/contract_function_simulator/index.ts +1 -0
  201. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +10 -10
  202. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
  203. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
  204. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +5 -11
  205. package/src/contract_function_simulator/oracle/interfaces.ts +90 -62
  206. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
  207. package/src/contract_function_simulator/oracle/oracle.ts +391 -150
  208. package/src/contract_function_simulator/oracle/private_execution.ts +5 -83
  209. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +160 -193
  210. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +552 -179
  211. package/src/contract_function_simulator/pick_notes.ts +22 -3
  212. package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
  213. package/src/contract_logging.ts +52 -0
  214. package/src/contract_sync/contract_sync_service.ts +176 -0
  215. package/src/contract_sync/helpers.ts +98 -0
  216. package/src/debug/pxe_debug_utils.ts +63 -19
  217. package/src/entrypoints/client/bundle/index.ts +2 -0
  218. package/src/entrypoints/client/bundle/utils.ts +18 -18
  219. package/src/entrypoints/client/lazy/index.ts +2 -0
  220. package/src/entrypoints/client/lazy/utils.ts +19 -18
  221. package/src/entrypoints/pxe_creation_options.ts +9 -1
  222. package/src/entrypoints/server/index.ts +3 -1
  223. package/src/entrypoints/server/utils.ts +24 -29
  224. package/src/events/event_service.ts +35 -12
  225. package/src/events/private_event_filter_validator.ts +21 -1
  226. package/src/job_coordinator/job_coordinator.ts +4 -3
  227. package/src/logs/log_service.ts +77 -106
  228. package/src/messages/message_context_service.ts +44 -0
  229. package/src/notes/note_service.ts +25 -17
  230. package/src/notes_filter.ts +24 -0
  231. package/src/oracle_version.ts +20 -10
  232. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  233. package/src/private_kernel/hints/index.ts +1 -1
  234. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  235. package/src/private_kernel/hints/test_utils.ts +325 -0
  236. package/src/private_kernel/private_kernel_execution_prover.ts +24 -19
  237. package/src/private_kernel/private_kernel_oracle.ts +21 -21
  238. package/src/pxe.ts +318 -144
  239. package/src/storage/address_store/address_store.ts +15 -15
  240. package/src/storage/anchor_block_store/anchor_block_store.ts +9 -1
  241. package/src/storage/capsule_store/capsule_service.ts +90 -0
  242. package/src/storage/capsule_store/capsule_store.ts +52 -34
  243. package/src/storage/capsule_store/index.ts +1 -0
  244. package/src/storage/contract_store/contract_store.ts +193 -101
  245. package/src/storage/metadata.ts +1 -1
  246. package/src/storage/note_store/note_store.ts +168 -134
  247. package/src/storage/private_event_store/private_event_store.ts +106 -81
  248. package/src/storage/private_event_store/stored_private_event.ts +3 -3
  249. package/src/storage/tagging_store/recipient_tagging_store.ts +38 -24
  250. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  251. package/src/storage/tagging_store/sender_tagging_store.ts +287 -156
  252. package/src/tagging/get_all_logs_by_tags.ts +31 -7
  253. package/src/tagging/index.ts +2 -2
  254. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +14 -27
  255. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  256. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +12 -17
  257. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +25 -12
  258. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  259. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +30 -29
  260. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  261. 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,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 { L2BlockHash } from '@aztec/stdlib/block';
21
+ import type { L2TipsProvider } from '@aztec/stdlib/block';
22
22
  import {
23
23
  CompleteAddress,
24
24
  type ContractInstanceWithAddress,
@@ -34,6 +34,7 @@ import type {
34
34
  PrivateKernelTailCircuitPublicInputs,
35
35
  } from '@aztec/stdlib/kernel';
36
36
  import {
37
+ BlockHeader,
37
38
  type ContractOverrides,
38
39
  type InTx,
39
40
  PrivateExecutionResult,
@@ -47,7 +48,7 @@ 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';
@@ -59,12 +60,15 @@ import {
59
60
  ContractFunctionSimulator,
60
61
  generateSimulatedProvingResult,
61
62
  } from './contract_function_simulator/contract_function_simulator.js';
62
- import { ensureContractSynced, readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
63
63
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
64
+ import { displayDebugLogs } from './contract_logging.js';
65
+ import { ContractSyncService } from './contract_sync/contract_sync_service.js';
66
+ import { readCurrentClassId } from './contract_sync/helpers.js';
64
67
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
65
68
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
66
69
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
67
70
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
71
+ import { MessageContextService } from './messages/message_context_service.js';
68
72
  import {
69
73
  PrivateKernelExecutionProver,
70
74
  type PrivateKernelExecutionProverConfig,
@@ -85,6 +89,70 @@ export type PackedPrivateEvent = InTx & {
85
89
  eventSelector: EventSelector;
86
90
  };
87
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
+
100
+ /** Options for PXE.profileTx. */
101
+ export type ProfileTxOpts = {
102
+ /** The profiling mode to use. */
103
+ profileMode: 'full' | 'execution-steps' | 'gates';
104
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
105
+ skipProofGeneration?: boolean;
106
+ /** Addresses whose private state and keys are accessible during private execution. */
107
+ scopes: AztecAddress[];
108
+ /** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
109
+ senderForTags?: AztecAddress;
110
+ };
111
+
112
+ /** Options for PXE.simulateTx. */
113
+ export type SimulateTxOpts = {
114
+ /** Whether to simulate the public part of the transaction. */
115
+ simulatePublic: boolean;
116
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
117
+ skipTxValidation?: boolean;
118
+ /** If false, fees are enforced. */
119
+ skipFeeEnforcement?: boolean;
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 */
123
+ overrides?: SimulationOverrides;
124
+ /** Addresses whose private state and keys are accessible during private execution */
125
+ scopes: AztecAddress[];
126
+ /** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
127
+ senderForTags?: AztecAddress;
128
+ };
129
+
130
+ /** Options for PXE.executeUtility. */
131
+ export type ExecuteUtilityOpts = {
132
+ /** The authentication witnesses required for the function call. */
133
+ authwits?: AuthWitness[];
134
+ /** The accounts whose notes we can access in this call */
135
+ scopes: AztecAddress[];
136
+ };
137
+
138
+ /** Args for PXE.create. */
139
+ export type PXECreateArgs = {
140
+ /** The Aztec node to connect to. */
141
+ node: AztecNode;
142
+ /** The key-value store for persisting PXE state. */
143
+ store: AztecAsyncKVStore;
144
+ /** The prover for generating private kernel proofs. */
145
+ proofCreator: PrivateKernelProver;
146
+ /** The circuit simulator for executing ACIR circuits. */
147
+ simulator: CircuitSimulator;
148
+ /** Provider for protocol contract artifacts and instances. */
149
+ protocolContractsProvider: ProtocolContractsProvider;
150
+ /** PXE configuration options. */
151
+ config: PXEConfig;
152
+ /** Optional logger instance or string suffix for the logger name. */
153
+ loggerOrSuffix?: string | Logger;
154
+ };
155
+
88
156
  /**
89
157
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
90
158
  * manage private state of users.
@@ -92,6 +160,7 @@ export type PackedPrivateEvent = InTx & {
92
160
  export class PXE {
93
161
  private constructor(
94
162
  private node: AztecNode,
163
+ private db: AztecAsyncKVStore,
95
164
  private blockStateSynchronizer: BlockSynchronizer,
96
165
  private keyStore: KeyStore,
97
166
  private contractStore: ContractStore,
@@ -103,6 +172,9 @@ export class PXE {
103
172
  private recipientTaggingStore: RecipientTaggingStore,
104
173
  private addressStore: AddressStore,
105
174
  private privateEventStore: PrivateEventStore,
175
+ private contractSyncService: ContractSyncService,
176
+ private messageContextService: MessageContextService,
177
+ private l2TipsStore: L2TipsProvider,
106
178
  private simulator: CircuitSimulator,
107
179
  private proverEnabled: boolean,
108
180
  private proofCreator: PrivateKernelProver,
@@ -120,21 +192,27 @@ export class PXE {
120
192
  *
121
193
  * @returns A promise that resolves PXE is ready to be used.
122
194
  */
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
- ) {
195
+ public static async create({
196
+ node,
197
+ store,
198
+ proofCreator,
199
+ simulator,
200
+ protocolContractsProvider,
201
+ config,
202
+ loggerOrSuffix,
203
+ }: PXECreateArgs) {
204
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
205
+ const bindings: LoggerBindings | undefined =
206
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
207
+
132
208
  const log =
133
209
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
134
210
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
135
211
  : loggerOrSuffix;
136
212
 
137
- const proverEnabled = !!config.proverEnabled;
213
+ const info = await node.getNodeInfo();
214
+
215
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
138
216
  const addressStore = new AddressStore(store);
139
217
  const privateEventStore = new PrivateEventStore(store);
140
218
  const contractStore = new ContractStore(store);
@@ -146,6 +224,14 @@ export class PXE {
146
224
  const capsuleStore = new CapsuleStore(store);
147
225
  const keyStore = new KeyStore(store);
148
226
  const tipsStore = new L2TipsKVStore(store, 'pxe');
227
+ const contractSyncService = new ContractSyncService(
228
+ node,
229
+ contractStore,
230
+ noteStore,
231
+ createLogger('pxe:contract_sync', bindings),
232
+ );
233
+ const messageContextService = new MessageContextService(node);
234
+
149
235
  const synchronizer = new BlockSynchronizer(
150
236
  node,
151
237
  store,
@@ -153,25 +239,28 @@ export class PXE {
153
239
  noteStore,
154
240
  privateEventStore,
155
241
  tipsStore,
242
+ contractSyncService,
156
243
  config,
157
- loggerOrSuffix,
244
+ bindings,
158
245
  );
159
246
 
160
- const jobCoordinator = new JobCoordinator(store);
247
+ const jobCoordinator = new JobCoordinator(store, bindings);
161
248
  jobCoordinator.registerStores([
162
249
  capsuleStore,
163
250
  senderTaggingStore,
164
251
  recipientTaggingStore,
165
252
  privateEventStore,
166
253
  noteStore,
254
+ contractSyncService,
167
255
  ]);
168
256
 
169
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
257
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
170
258
 
171
259
  const jobQueue = new SerialQueue();
172
260
 
173
261
  const pxe = new PXE(
174
262
  node,
263
+ store,
175
264
  synchronizer,
176
265
  keyStore,
177
266
  contractStore,
@@ -183,6 +272,9 @@ export class PXE {
183
272
  recipientTaggingStore,
184
273
  addressStore,
185
274
  privateEventStore,
275
+ contractSyncService,
276
+ messageContextService,
277
+ tipsStore,
186
278
  simulator,
187
279
  proverEnabled,
188
280
  proofCreator,
@@ -193,12 +285,15 @@ export class PXE {
193
285
  debugUtils,
194
286
  );
195
287
 
196
- debugUtils.setPXE(pxe);
288
+ debugUtils.setPXEHelpers(
289
+ pxe.#putInJobQueue.bind(pxe),
290
+ pxe.#getSimulatorForTx.bind(pxe),
291
+ pxe.#executeUtility.bind(pxe),
292
+ );
197
293
 
198
294
  pxe.jobQueue.start();
199
295
 
200
296
  await pxe.#registerProtocolContracts();
201
- const info = await node.getNodeInfo();
202
297
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
203
298
  return pxe;
204
299
  }
@@ -208,20 +303,22 @@ export class PXE {
208
303
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
209
304
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
210
305
 
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
- );
306
+ return new ContractFunctionSimulator({
307
+ contractStore: proxyContractStore,
308
+ noteStore: this.noteStore,
309
+ keyStore: this.keyStore,
310
+ addressStore: this.addressStore,
311
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
312
+ l2TipsStore: this.l2TipsStore,
313
+ senderTaggingStore: this.senderTaggingStore,
314
+ recipientTaggingStore: this.recipientTaggingStore,
315
+ senderAddressBookStore: this.senderAddressBookStore,
316
+ capsuleStore: this.capsuleStore,
317
+ privateEventStore: this.privateEventStore,
318
+ simulator: this.simulator,
319
+ contractSyncService: this.contractSyncService,
320
+ messageContextService: this.messageContextService,
321
+ });
225
322
  }
226
323
 
227
324
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -273,9 +370,8 @@ export class PXE {
273
370
  async #registerProtocolContracts() {
274
371
  const registered: Record<string, string> = {};
275
372
  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);
373
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
374
+ await this.contractStore.addContractArtifact(artifact);
279
375
  await this.contractStore.addContractInstance(instance);
280
376
  registered[name] = address.toString();
281
377
  }
@@ -284,38 +380,42 @@ export class PXE {
284
380
 
285
381
  // Executes the entrypoint private function, as well as all nested private
286
382
  // functions that might arise.
287
- async #executePrivate(
288
- contractFunctionSimulator: ContractFunctionSimulator,
289
- txRequest: TxExecutionRequest,
290
- scopes: AztecAddress[] | undefined,
291
- jobId: string,
292
- ): 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> {
293
398
  const { origin: contractAddress, functionSelector } = txRequest;
294
399
 
295
400
  try {
296
- const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
297
-
298
- await ensureContractSynced(
401
+ await this.contractSyncService.ensureContractSynced(
299
402
  contractAddress,
300
403
  functionSelector,
301
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
302
- this.node,
303
- this.contractStore,
404
+ (privateSyncCall, execScopes) =>
405
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
304
406
  anchorBlockHeader,
407
+ jobId,
408
+ scopes,
305
409
  );
306
410
 
307
- const result = await contractFunctionSimulator.run(
308
- txRequest,
411
+ const result = await contractFunctionSimulator.run(txRequest, {
309
412
  contractAddress,
310
- functionSelector,
311
- undefined,
413
+ selector: functionSelector,
312
414
  anchorBlockHeader,
313
- // The sender for tags is set by contracts, typically by an account
314
- // contract entrypoint
315
- undefined, // senderForTags
316
415
  scopes,
317
416
  jobId,
318
- );
417
+ senderForTags,
418
+ });
319
419
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
320
420
  return result;
321
421
  } catch (err) {
@@ -327,25 +427,32 @@ export class PXE {
327
427
  }
328
428
 
329
429
  /**
330
- * Simulate a utility function call on the given contract.
430
+ * Execute a utility function call on the given contract.
331
431
  * @param contractFunctionSimulator - The simulator to use for the function call.
332
432
  * @param call - The function call to execute.
333
433
  * @param authWitnesses - Authentication witnesses required for the function call.
334
434
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
335
435
  * accounts if not specified.
336
436
  * @param jobId - The job ID for staged writes.
337
- * @returns The simulation result containing the outputs of the utility function.
437
+ * @returns The execution result containing the outputs of the utility function.
338
438
  */
339
- async #simulateUtility(
439
+ async #executeUtility(
340
440
  contractFunctionSimulator: ContractFunctionSimulator,
341
441
  call: FunctionCall,
342
442
  authWitnesses: AuthWitness[] | undefined,
343
- scopes: AztecAddress[] | undefined,
443
+ scopes: AztecAddress[],
344
444
  jobId: string,
345
445
  ) {
346
446
  try {
347
447
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
348
- 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 };
349
456
  } catch (err) {
350
457
  if (err instanceof SimulationError) {
351
458
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -396,18 +503,37 @@ export class PXE {
396
503
  txExecutionRequest: TxExecutionRequest,
397
504
  proofCreator: PrivateKernelProver,
398
505
  privateExecutionResult: PrivateExecutionResult,
506
+ anchorBlockHeader: BlockHeader,
399
507
  config: PrivateKernelExecutionProverConfig,
400
508
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
401
- const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
402
- const anchorBlockHash = L2BlockHash.fromField(await anchorBlockHeader.hash());
403
- const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
404
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
509
+ const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHeader);
510
+ const kernelTraceProver = new PrivateKernelExecutionProver(
511
+ kernelOracle,
512
+ proofCreator,
513
+ !this.proverEnabled,
514
+ this.log.getBindings(),
515
+ );
405
516
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
406
517
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
407
518
  }
408
519
 
409
520
  // Public API
410
521
 
522
+ /**
523
+ * Returns the block header up to which the PXE has synced.
524
+ * @returns The synced block header
525
+ */
526
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
527
+ return this.#putInJobQueue(() => {
528
+ return this.anchorBlockStore.getBlockHeader();
529
+ });
530
+ }
531
+
532
+ /**
533
+ * Returns the contract instance for a given address, if it's registered in the PXE.
534
+ * @param address - The contract address.
535
+ * @returns The contract instance if found, undefined otherwise.
536
+ */
411
537
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
412
538
  return this.contractStore.getContractInstance(address);
413
539
  }
@@ -457,6 +583,12 @@ export class PXE {
457
583
  * TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
458
584
  */
459
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
+
460
592
  const accounts = await this.keyStore.getAccounts();
461
593
  if (accounts.includes(sender)) {
462
594
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
@@ -467,6 +599,9 @@ export class PXE {
467
599
 
468
600
  if (wasAdded) {
469
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()));
470
605
  } else {
471
606
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
472
607
  }
@@ -516,8 +651,7 @@ export class PXE {
516
651
  * @param artifact - The build artifact for the contract class.
517
652
  */
518
653
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
519
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
520
- await this.contractStore.addContractArtifact(contractClassId, artifact);
654
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
521
655
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
522
656
  }
523
657
 
@@ -536,17 +670,17 @@ export class PXE {
536
670
  if (artifact) {
537
671
  // If the user provides an artifact, validate it against the expected class id and register it
538
672
  const contractClass = await getContractClassFromArtifact(artifact);
539
- const contractClassId = contractClass.id;
540
- if (!contractClassId.equals(instance.currentContractClassId)) {
673
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
541
674
  throw new Error(
542
- `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})`,
543
676
  );
544
677
  }
545
678
  const computedAddress = await computeContractAddressFromInstance(instance);
546
679
  if (!computedAddress.equals(instance.address)) {
547
680
  throw new Error('Added a contract in which the address does not match the contract instance.');
548
681
  }
549
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
682
+
683
+ await this.contractStore.addContractArtifact(artifact, contractClass);
550
684
 
551
685
  const publicFunctionSignatures = artifact.functions
552
686
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -595,15 +729,16 @@ export class PXE {
595
729
  throw new Error('Could not update contract to a class different from the current one.');
596
730
  }
597
731
 
598
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
599
-
600
732
  const publicFunctionSignatures = artifact.functions
601
733
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
602
734
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
603
735
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
604
736
 
605
737
  currentInstance.currentContractClassId = contractClass.id;
606
- await this.contractStore.addContractInstance(currentInstance);
738
+ await Promise.all([
739
+ this.contractStore.addContractArtifact(artifact, contractClass),
740
+ this.contractStore.addContractInstance(currentInstance),
741
+ ]);
607
742
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
608
743
  });
609
744
  }
@@ -621,11 +756,12 @@ export class PXE {
621
756
  * (where validators prove the public portion).
622
757
  *
623
758
  * @param txRequest - An authenticated tx request ready for proving
759
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
624
760
  * @returns A result containing the proof and public inputs of the tail circuit.
625
761
  * @throws If contract code not found, or public simulation reverts.
626
762
  * Also throws if simulatePublic is true and public simulation reverts.
627
763
  */
628
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
764
+ public proveTx(txRequest: TxExecutionRequest, { scopes, senderForTags }: ProveTxOpts): Promise<TxProvingResult> {
629
765
  let privateExecutionResult: PrivateExecutionResult;
630
766
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
631
767
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -634,16 +770,24 @@ export class PXE {
634
770
  try {
635
771
  const syncTimer = new Timer();
636
772
  await this.blockStateSynchronizer.sync();
773
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
637
774
  const syncTime = syncTimer.ms();
638
775
  const contractFunctionSimulator = this.#getSimulatorForTx();
639
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
776
+ privateExecutionResult = await this.#executePrivate({
777
+ contractFunctionSimulator,
778
+ txRequest,
779
+ anchorBlockHeader,
780
+ scopes,
781
+ jobId,
782
+ senderForTags,
783
+ });
640
784
 
641
785
  const {
642
786
  publicInputs,
643
787
  chonkProof,
644
788
  executionSteps,
645
789
  timings: { proving } = {},
646
- } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
790
+ } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, anchorBlockHeader, {
647
791
  simulate: false,
648
792
  skipFeeEnforcement: false,
649
793
  profileMode: 'none',
@@ -678,17 +822,17 @@ export class PXE {
678
822
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
679
823
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
680
824
  // storing the tags here prevents linkage of txs sent from the same PXE.
681
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
682
- if (preTagsUsedInTheTx.length > 0) {
825
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
826
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
683
827
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
684
828
  const txHash = (await txProvingResult.toTx()).txHash;
685
829
 
686
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
687
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
688
- 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,
689
833
  });
690
834
  } else {
691
- this.log.debug(`No pre-tags used in the tx`);
835
+ this.log.debug(`No tagging index ranges used in the tx`);
692
836
  }
693
837
 
694
838
  return txProvingResult;
@@ -700,17 +844,13 @@ export class PXE {
700
844
 
701
845
  /**
702
846
  * 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.
847
+ * @param txRequest - An authenticated tx request ready for simulation.
707
848
  * @returns A trace of the program execution with gate counts.
708
849
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
709
850
  */
710
851
  public profileTx(
711
852
  txRequest: TxExecutionRequest,
712
- profileMode: 'full' | 'execution-steps' | 'gates',
713
- skipProofGeneration: boolean = true,
853
+ { profileMode, skipProofGeneration = true, scopes, senderForTags }: ProfileTxOpts,
714
854
  ): Promise<TxProfileResult> {
715
855
  // We disable concurrent profiles for consistency with simulateTx.
716
856
  return this.#putInJobQueue(async jobId => {
@@ -730,20 +870,24 @@ export class PXE {
730
870
  );
731
871
  const syncTimer = new Timer();
732
872
  await this.blockStateSynchronizer.sync();
873
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
733
874
  const syncTime = syncTimer.ms();
734
875
 
735
876
  const contractFunctionSimulator = this.#getSimulatorForTx();
736
- const privateExecutionResult = await this.#executePrivate(
877
+ const privateExecutionResult = await this.#executePrivate({
737
878
  contractFunctionSimulator,
738
879
  txRequest,
739
- undefined,
880
+ anchorBlockHeader,
881
+ scopes,
740
882
  jobId,
741
- );
883
+ senderForTags,
884
+ });
742
885
 
743
886
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
744
887
  txRequest,
745
888
  this.proofCreator,
746
889
  privateExecutionResult,
890
+ anchorBlockHeader,
747
891
  {
748
892
  simulate: skipProofGeneration,
749
893
  skipFeeEnforcement: false,
@@ -795,12 +939,7 @@ export class PXE {
795
939
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
796
940
  *
797
941
  *
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.
942
+ * @param txRequest - An authenticated tx request ready for simulation.
804
943
  * @returns A simulated transaction result object that includes public and private return values.
805
944
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
806
945
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -809,11 +948,15 @@ export class PXE {
809
948
  */
810
949
  public simulateTx(
811
950
  txRequest: TxExecutionRequest,
812
- simulatePublic: boolean,
813
- skipTxValidation: boolean = false,
814
- skipFeeEnforcement: boolean = false,
815
- overrides?: SimulationOverrides,
816
- scopes?: AztecAddress[],
951
+ {
952
+ simulatePublic,
953
+ skipTxValidation = false,
954
+ skipFeeEnforcement = false,
955
+ skipKernels = true,
956
+ overrides,
957
+ scopes,
958
+ senderForTags,
959
+ }: SimulateTxOpts,
817
960
  ): Promise<TxSimulationResult> {
818
961
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
819
962
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -835,16 +978,34 @@ export class PXE {
835
978
  );
836
979
  const syncTimer = new Timer();
837
980
  await this.blockStateSynchronizer.sync();
981
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
838
982
  const syncTime = syncTimer.ms();
839
983
 
984
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
985
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
986
+
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
+ }
840
992
  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;
993
+
994
+ if (hasOverriddenContracts) {
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);
998
+ }
845
999
 
846
1000
  // Execution of private functions only; no proving, and no kernel logic.
847
- 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
+ });
848
1009
 
849
1010
  let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
850
1011
  let executionSteps: PrivateExecutionStep[] = [];
@@ -852,15 +1013,22 @@ export class PXE {
852
1013
  if (skipKernels) {
853
1014
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
854
1015
  privateExecutionResult,
855
- this.contractStore,
1016
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
1017
+ this.node,
856
1018
  ));
857
1019
  } else {
858
1020
  // Kernel logic, plus proving of all private functions and kernels.
859
- ({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
860
- simulate: true,
861
- skipFeeEnforcement,
862
- profileMode: 'none',
863
- }));
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
+ ));
864
1032
  }
865
1033
 
866
1034
  const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
@@ -871,6 +1039,9 @@ export class PXE {
871
1039
  const publicSimulationTimer = new Timer();
872
1040
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
873
1041
  publicSimulationTime = publicSimulationTimer.ms();
1042
+ if (publicOutput?.debugLogs?.length) {
1043
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
1044
+ }
874
1045
  }
875
1046
 
876
1047
  let validationTime: number | undefined;
@@ -879,7 +1050,8 @@ export class PXE {
879
1050
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
880
1051
  validationTime = validationTimer.ms();
881
1052
  if (validationResult.result === 'invalid') {
882
- 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}`);
883
1055
  }
884
1056
  }
885
1057
 
@@ -930,29 +1102,23 @@ export class PXE {
930
1102
  inspect(txRequest),
931
1103
  `simulatePublic=${simulatePublic}`,
932
1104
  `skipTxValidation=${skipTxValidation}`,
933
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1105
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
934
1106
  );
935
1107
  }
936
1108
  });
937
1109
  }
938
1110
 
939
1111
  /**
940
- * Simulate the execution of a contract utility function.
941
- *
1112
+ * Executes a contract utility function.
942
1113
  * @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
1114
  */
948
- public simulateUtility(
1115
+ public executeUtility(
949
1116
  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.
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.
954
1120
  // 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).
1121
+ // delete the same read value, or reading values that another execution is currently modifying).
956
1122
  return this.#putInJobQueue(async jobId => {
957
1123
  try {
958
1124
  const totalTimer = new Timer();
@@ -963,16 +1129,17 @@ export class PXE {
963
1129
  const contractFunctionSimulator = this.#getSimulatorForTx();
964
1130
 
965
1131
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
966
- await ensureContractSynced(
1132
+ await this.contractSyncService.ensureContractSynced(
967
1133
  call.to,
968
1134
  call.selector,
969
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
970
- this.node,
971
- this.contractStore,
1135
+ (privateSyncCall, execScopes) =>
1136
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
972
1137
  anchorBlockHeader,
1138
+ jobId,
1139
+ scopes,
973
1140
  );
974
1141
 
975
- const executionResult = await this.#simulateUtility(
1142
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
976
1143
  contractFunctionSimulator,
977
1144
  call,
978
1145
  authwits ?? [],
@@ -993,14 +1160,19 @@ export class PXE {
993
1160
  };
994
1161
 
995
1162
  const simulationStats = contractFunctionSimulator.getStats();
996
- 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
+ };
997
1169
  } catch (err: any) {
998
1170
  const { to, name, args } = call;
999
1171
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1000
1172
  throw this.#contextualizeError(
1001
1173
  err,
1002
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1003
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1174
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1175
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1004
1176
  );
1005
1177
  }
1006
1178
  });
@@ -1033,14 +1205,14 @@ export class PXE {
1033
1205
 
1034
1206
  const contractFunctionSimulator = this.#getSimulatorForTx();
1035
1207
 
1036
- await ensureContractSynced(
1208
+ await this.contractSyncService.ensureContractSynced(
1037
1209
  filter.contractAddress,
1038
1210
  null,
1039
- async privateSyncCall =>
1040
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1041
- this.node,
1042
- this.contractStore,
1211
+ async (privateSyncCall, execScopes) =>
1212
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1043
1213
  anchorBlockHeader,
1214
+ jobId,
1215
+ filter.scopes,
1044
1216
  );
1045
1217
  });
1046
1218
 
@@ -1055,9 +1227,11 @@ export class PXE {
1055
1227
  }
1056
1228
 
1057
1229
  /**
1058
- * Stops the PXE's job queue.
1230
+ * Stops the PXE's job queue and closes the backing store.
1059
1231
  */
1060
- public stop(): Promise<void> {
1061
- 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();
1062
1236
  }
1063
1237
  }