@aztec/pxe 0.0.1-commit.6d3c34e → 0.0.1-commit.72dcdcda8

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 (269) hide show
  1. package/dest/access_scopes.d.ts +9 -0
  2. package/dest/access_scopes.d.ts.map +1 -0
  3. package/dest/access_scopes.js +6 -0
  4. package/dest/bin/check_oracle_version.js +1 -1
  5. package/dest/block_synchronizer/block_synchronizer.d.ts +11 -5
  6. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  7. package/dest/block_synchronizer/block_synchronizer.js +72 -21
  8. package/dest/config/index.d.ts +3 -1
  9. package/dest/config/index.d.ts.map +1 -1
  10. package/dest/config/index.js +17 -0
  11. package/dest/config/package_info.js +1 -1
  12. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  13. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  14. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  15. package/dest/contract_function_simulator/contract_function_simulator.d.ts +57 -35
  16. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/contract_function_simulator.js +198 -84
  18. package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
  19. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/execution_note_cache.js +45 -28
  21. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
  22. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/execution_tagging_index_cache.js +3 -3
  24. package/dest/contract_function_simulator/index.d.ts +2 -2
  25. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/index.js +1 -1
  27. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +1 -1
  28. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +2 -2
  29. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -3
  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 +2 -2
  32. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  33. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  35. package/dest/contract_function_simulator/oracle/interfaces.d.ts +17 -13
  36. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  37. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
  38. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  39. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +6 -6
  40. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/oracle/note_packing_utils.js +8 -8
  42. package/dest/contract_function_simulator/oracle/oracle.d.ts +12 -10
  43. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  44. package/dest/contract_function_simulator/oracle/oracle.js +67 -44
  45. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
  46. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  47. package/dest/contract_function_simulator/oracle/private_execution.js +0 -35
  48. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +44 -35
  49. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  50. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +89 -32
  51. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +66 -33
  52. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  53. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +130 -111
  54. package/dest/contract_logging.d.ts +22 -0
  55. package/dest/contract_logging.d.ts.map +1 -0
  56. package/dest/contract_logging.js +23 -0
  57. package/dest/contract_sync/contract_sync_service.d.ts +43 -0
  58. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  59. package/dest/contract_sync/contract_sync_service.js +97 -0
  60. package/dest/contract_sync/helpers.d.ts +29 -0
  61. package/dest/contract_sync/helpers.d.ts.map +1 -0
  62. package/dest/contract_sync/helpers.js +55 -0
  63. package/dest/debug/pxe_debug_utils.d.ts +24 -10
  64. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  65. package/dest/debug/pxe_debug_utils.js +28 -17
  66. package/dest/entrypoints/client/bundle/index.d.ts +4 -1
  67. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  68. package/dest/entrypoints/client/bundle/index.js +3 -0
  69. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  70. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  71. package/dest/entrypoints/client/bundle/utils.js +21 -7
  72. package/dest/entrypoints/client/lazy/index.d.ts +4 -1
  73. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  74. package/dest/entrypoints/client/lazy/index.js +3 -0
  75. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  76. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  77. package/dest/entrypoints/client/lazy/utils.js +22 -8
  78. package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
  79. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  80. package/dest/entrypoints/server/index.d.ts +5 -1
  81. package/dest/entrypoints/server/index.d.ts.map +1 -1
  82. package/dest/entrypoints/server/index.js +4 -0
  83. package/dest/entrypoints/server/utils.d.ts +1 -1
  84. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  85. package/dest/entrypoints/server/utils.js +28 -9
  86. package/dest/events/event_service.d.ts +6 -6
  87. package/dest/events/event_service.d.ts.map +1 -1
  88. package/dest/events/event_service.js +19 -22
  89. package/dest/events/private_event_filter_validator.d.ts +5 -5
  90. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  91. package/dest/events/private_event_filter_validator.js +5 -6
  92. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  93. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  94. package/dest/job_coordinator/job_coordinator.js +3 -2
  95. package/dest/logs/log_service.d.ts +8 -5
  96. package/dest/logs/log_service.d.ts.map +1 -1
  97. package/dest/logs/log_service.js +31 -33
  98. package/dest/notes/note_service.d.ts +10 -9
  99. package/dest/notes/note_service.d.ts.map +1 -1
  100. package/dest/notes/note_service.js +34 -38
  101. package/dest/notes_filter.d.ts +25 -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 +3 -3
  105. package/dest/oracle_version.d.ts.map +1 -1
  106. package/dest/oracle_version.js +4 -3
  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 +3 -3
  111. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  112. package/dest/private_kernel/hints/index.js +2 -2
  113. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +29 -0
  114. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  115. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +140 -73
  116. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  117. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  118. package/dest/private_kernel/hints/test_utils.js +203 -0
  119. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  120. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  121. package/dest/private_kernel/private_kernel_execution_prover.js +22 -14
  122. package/dest/private_kernel/private_kernel_oracle.d.ts +23 -24
  123. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  124. package/dest/private_kernel/private_kernel_oracle.js +94 -2
  125. package/dest/pxe.d.ts +77 -59
  126. package/dest/pxe.d.ts.map +1 -1
  127. package/dest/pxe.js +132 -136
  128. package/dest/storage/address_store/address_store.d.ts +1 -1
  129. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  130. package/dest/storage/address_store/address_store.js +12 -11
  131. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  132. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  133. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  134. package/dest/storage/capsule_store/capsule_store.d.ts +24 -9
  135. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  136. package/dest/storage/capsule_store/capsule_store.js +130 -23
  137. package/dest/storage/contract_store/contract_store.d.ts +42 -16
  138. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  139. package/dest/storage/contract_store/contract_store.js +157 -84
  140. package/dest/storage/metadata.d.ts +1 -1
  141. package/dest/storage/metadata.js +1 -1
  142. package/dest/storage/note_store/note_store.d.ts +50 -51
  143. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  144. package/dest/storage/note_store/note_store.js +284 -263
  145. package/dest/storage/note_store/stored_note.d.ts +16 -0
  146. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  147. package/dest/storage/note_store/stored_note.js +43 -0
  148. package/dest/storage/private_event_store/private_event_store.d.ts +43 -8
  149. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  150. package/dest/storage/private_event_store/private_event_store.js +226 -111
  151. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  152. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  153. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  154. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +16 -9
  155. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  156. package/dest/storage/tagging_store/recipient_tagging_store.js +88 -19
  157. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  158. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  159. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  160. package/dest/storage/tagging_store/sender_tagging_store.d.ts +20 -10
  161. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  162. package/dest/storage/tagging_store/sender_tagging_store.js +253 -101
  163. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  164. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  165. package/dest/tagging/get_all_logs_by_tags.js +60 -0
  166. package/dest/tagging/index.d.ts +3 -2
  167. package/dest/tagging/index.d.ts.map +1 -1
  168. package/dest/tagging/index.js +2 -1
  169. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +5 -5
  170. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  171. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +11 -11
  172. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  173. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +7 -7
  174. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  175. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +16 -12
  176. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -8
  177. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  178. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +8 -11
  179. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
  180. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  181. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +5 -8
  182. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +7 -7
  183. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  184. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +23 -19
  185. package/package.json +27 -18
  186. package/src/access_scopes.ts +9 -0
  187. package/src/bin/check_oracle_version.ts +1 -0
  188. package/src/block_synchronizer/block_synchronizer.ts +91 -33
  189. package/src/config/index.ts +14 -0
  190. package/src/config/package_info.ts +1 -1
  191. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  192. package/src/contract_function_simulator/contract_function_simulator.ts +349 -148
  193. package/src/contract_function_simulator/execution_note_cache.ts +44 -25
  194. package/src/contract_function_simulator/execution_tagging_index_cache.ts +5 -5
  195. package/src/contract_function_simulator/index.ts +1 -1
  196. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +2 -2
  197. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +2 -2
  198. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  199. package/src/contract_function_simulator/oracle/interfaces.ts +22 -12
  200. package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
  201. package/src/contract_function_simulator/oracle/oracle.ts +79 -47
  202. package/src/contract_function_simulator/oracle/private_execution.ts +1 -67
  203. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +129 -112
  204. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +197 -116
  205. package/src/contract_logging.ts +39 -0
  206. package/src/contract_sync/contract_sync_service.ts +152 -0
  207. package/src/contract_sync/helpers.ts +98 -0
  208. package/src/debug/pxe_debug_utils.ts +63 -18
  209. package/src/entrypoints/client/bundle/index.ts +3 -0
  210. package/src/entrypoints/client/bundle/utils.ts +16 -15
  211. package/src/entrypoints/client/lazy/index.ts +3 -0
  212. package/src/entrypoints/client/lazy/utils.ts +17 -15
  213. package/src/entrypoints/pxe_creation_options.ts +2 -1
  214. package/src/entrypoints/server/index.ts +4 -0
  215. package/src/entrypoints/server/utils.ts +22 -26
  216. package/src/events/event_service.ts +17 -25
  217. package/src/events/private_event_filter_validator.ts +3 -5
  218. package/src/job_coordinator/job_coordinator.ts +4 -3
  219. package/src/logs/log_service.ts +51 -40
  220. package/src/notes/note_service.ts +41 -45
  221. package/src/notes_filter.ts +26 -0
  222. package/src/oracle_version.ts +4 -3
  223. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  224. package/src/private_kernel/hints/index.ts +2 -2
  225. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +195 -136
  226. package/src/private_kernel/hints/test_utils.ts +325 -0
  227. package/src/private_kernel/private_kernel_execution_prover.ts +26 -16
  228. package/src/private_kernel/private_kernel_oracle.ts +116 -37
  229. package/src/pxe.ts +243 -213
  230. package/src/storage/address_store/address_store.ts +15 -15
  231. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  232. package/src/storage/capsule_store/capsule_store.ts +159 -23
  233. package/src/storage/contract_store/contract_store.ts +186 -96
  234. package/src/storage/metadata.ts +1 -1
  235. package/src/storage/note_store/note_store.ts +326 -320
  236. package/src/storage/note_store/stored_note.ts +48 -0
  237. package/src/storage/private_event_store/private_event_store.ts +292 -124
  238. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  239. package/src/storage/tagging_store/recipient_tagging_store.ts +111 -21
  240. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  241. package/src/storage/tagging_store/sender_tagging_store.ts +296 -111
  242. package/src/tagging/get_all_logs_by_tags.ts +92 -0
  243. package/src/tagging/index.ts +2 -1
  244. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +22 -14
  245. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  246. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +17 -16
  247. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +12 -14
  248. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -17
  249. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +26 -23
  250. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  251. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  252. package/dest/contract_function_simulator/proxied_node.js +0 -27
  253. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  254. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  255. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  256. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  257. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
  258. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  259. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -85
  260. package/dest/public_storage/public_storage_service.d.ts +0 -24
  261. package/dest/public_storage/public_storage_service.d.ts.map +0 -1
  262. package/dest/public_storage/public_storage_service.js +0 -26
  263. package/dest/tree_membership/tree_membership_service.d.ts +0 -52
  264. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  265. package/dest/tree_membership/tree_membership_service.js +0 -84
  266. package/src/contract_function_simulator/proxied_node.ts +0 -33
  267. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -127
  268. package/src/public_storage/public_storage_service.ts +0 -33
  269. package/src/tree_membership/tree_membership_service.ts +0 -112
package/src/pxe.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
3
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { type Logger, createLogger } from '@aztec/foundation/log';
4
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
4
5
  import { SerialQueue } from '@aztec/foundation/queue';
5
6
  import { Timer } from '@aztec/foundation/timer';
6
7
  import { KeyStore } from '@aztec/key-store';
@@ -19,14 +20,12 @@ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
19
20
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
20
21
  import {
21
22
  CompleteAddress,
22
- type ContractClassWithId,
23
23
  type ContractInstanceWithAddress,
24
24
  type PartialAddress,
25
25
  computeContractAddressFromInstance,
26
26
  getContractClassFromArtifact,
27
27
  } from '@aztec/stdlib/contract';
28
28
  import { SimulationError } from '@aztec/stdlib/errors';
29
- import { computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
30
29
  import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
31
30
  import type {
32
31
  PrivateExecutionStep,
@@ -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,20 +47,23 @@ 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';
54
54
 
55
+ import type { AccessScopes } from './access_scopes.js';
55
56
  import { BlockSynchronizer } from './block_synchronizer/index.js';
56
57
  import type { PXEConfig } from './config/index.js';
58
+ import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
57
59
  import {
58
60
  ContractFunctionSimulator,
59
61
  generateSimulatedProvingResult,
60
62
  } from './contract_function_simulator/contract_function_simulator.js';
61
- import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
62
63
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
63
- import { ProxiedNodeFactory } from './contract_function_simulator/proxied_node.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';
@@ -69,7 +72,7 @@ import {
69
72
  PrivateKernelExecutionProver,
70
73
  type PrivateKernelExecutionProverConfig,
71
74
  } from './private_kernel/private_kernel_execution_prover.js';
72
- import { PrivateKernelOracleImpl } from './private_kernel/private_kernel_oracle_impl.js';
75
+ import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
73
76
  import { AddressStore } from './storage/address_store/address_store.js';
74
77
  import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
75
78
  import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
@@ -85,6 +88,56 @@ 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: AccessScopes;
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
+ /** State overrides for the simulation, such as contract instances and artifacts. */
110
+ overrides?: SimulationOverrides;
111
+ /** Addresses whose private state and keys are accessible during private execution */
112
+ scopes: AccessScopes;
113
+ };
114
+
115
+ /** Options for PXE.executeUtility. */
116
+ export type ExecuteUtilityOpts = {
117
+ /** The authentication witnesses required for the function call. */
118
+ authwits?: AuthWitness[];
119
+ /** The accounts whose notes we can access in this call */
120
+ scopes: AccessScopes;
121
+ };
122
+
123
+ /** Args for PXE.create. */
124
+ export type PXECreateArgs = {
125
+ /** The Aztec node to connect to. */
126
+ node: AztecNode;
127
+ /** The key-value store for persisting PXE state. */
128
+ store: AztecAsyncKVStore;
129
+ /** The prover for generating private kernel proofs. */
130
+ proofCreator: PrivateKernelProver;
131
+ /** The circuit simulator for executing ACIR circuits. */
132
+ simulator: CircuitSimulator;
133
+ /** Provider for protocol contract artifacts and instances. */
134
+ protocolContractsProvider: ProtocolContractsProvider;
135
+ /** PXE configuration options. */
136
+ config: PXEConfig;
137
+ /** Optional logger instance or string suffix for the logger name. */
138
+ loggerOrSuffix?: string | Logger;
139
+ };
140
+
88
141
  /**
89
142
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
90
143
  * manage private state of users.
@@ -92,6 +145,7 @@ export type PackedPrivateEvent = InTx & {
92
145
  export class PXE {
93
146
  private constructor(
94
147
  private node: AztecNode,
148
+ private db: AztecAsyncKVStore,
95
149
  private blockStateSynchronizer: BlockSynchronizer,
96
150
  private keyStore: KeyStore,
97
151
  private contractStore: ContractStore,
@@ -103,6 +157,7 @@ export class PXE {
103
157
  private recipientTaggingStore: RecipientTaggingStore,
104
158
  private addressStore: AddressStore,
105
159
  private privateEventStore: PrivateEventStore,
160
+ private contractSyncService: ContractSyncService,
106
161
  private simulator: CircuitSimulator,
107
162
  private proverEnabled: boolean,
108
163
  private proofCreator: PrivateKernelProver,
@@ -120,25 +175,31 @@ export class PXE {
120
175
  *
121
176
  * @returns A promise that resolves PXE is ready to be used.
122
177
  */
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
- ) {
178
+ public static async create({
179
+ node,
180
+ store,
181
+ proofCreator,
182
+ simulator,
183
+ protocolContractsProvider,
184
+ config,
185
+ loggerOrSuffix,
186
+ }: PXECreateArgs) {
187
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
188
+ const bindings: LoggerBindings | undefined =
189
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
190
+
132
191
  const log =
133
192
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
134
193
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
135
194
  : loggerOrSuffix;
136
195
 
137
- const proverEnabled = !!config.proverEnabled;
196
+ const info = await node.getNodeInfo();
197
+
198
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
138
199
  const addressStore = new AddressStore(store);
139
200
  const privateEventStore = new PrivateEventStore(store);
140
201
  const contractStore = new ContractStore(store);
141
- const noteStore = await NoteStore.create(store);
202
+ const noteStore = new NoteStore(store);
142
203
  const anchorBlockStore = new AnchorBlockStore(store);
143
204
  const senderTaggingStore = new SenderTaggingStore(store);
144
205
  const senderAddressBookStore = new SenderAddressBookStore(store);
@@ -146,24 +207,41 @@ export class PXE {
146
207
  const capsuleStore = new CapsuleStore(store);
147
208
  const keyStore = new KeyStore(store);
148
209
  const tipsStore = new L2TipsKVStore(store, 'pxe');
210
+ const contractSyncService = new ContractSyncService(
211
+ node,
212
+ contractStore,
213
+ noteStore,
214
+ createLogger('pxe:contract_sync', bindings),
215
+ );
149
216
  const synchronizer = new BlockSynchronizer(
150
217
  node,
218
+ store,
151
219
  anchorBlockStore,
152
220
  noteStore,
153
221
  privateEventStore,
154
222
  tipsStore,
223
+ contractSyncService,
155
224
  config,
156
- loggerOrSuffix,
225
+ bindings,
157
226
  );
158
227
 
159
- const jobCoordinator = new JobCoordinator(store);
228
+ const jobCoordinator = new JobCoordinator(store, bindings);
229
+ jobCoordinator.registerStores([
230
+ capsuleStore,
231
+ senderTaggingStore,
232
+ recipientTaggingStore,
233
+ privateEventStore,
234
+ noteStore,
235
+ contractSyncService,
236
+ ]);
160
237
 
161
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
238
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
162
239
 
163
240
  const jobQueue = new SerialQueue();
164
241
 
165
242
  const pxe = new PXE(
166
243
  node,
244
+ store,
167
245
  synchronizer,
168
246
  keyStore,
169
247
  contractStore,
@@ -175,6 +253,7 @@ export class PXE {
175
253
  recipientTaggingStore,
176
254
  addressStore,
177
255
  privateEventStore,
256
+ contractSyncService,
178
257
  simulator,
179
258
  proverEnabled,
180
259
  proofCreator,
@@ -185,12 +264,15 @@ export class PXE {
185
264
  debugUtils,
186
265
  );
187
266
 
188
- debugUtils.setPXE(pxe);
267
+ debugUtils.setPXEHelpers(
268
+ pxe.#putInJobQueue.bind(pxe),
269
+ pxe.#getSimulatorForTx.bind(pxe),
270
+ pxe.#executeUtility.bind(pxe),
271
+ );
189
272
 
190
273
  pxe.jobQueue.start();
191
274
 
192
275
  await pxe.#registerProtocolContracts();
193
- const info = await node.getNodeInfo();
194
276
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
195
277
  return pxe;
196
278
  }
@@ -200,20 +282,20 @@ export class PXE {
200
282
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
201
283
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
202
284
 
203
- return new ContractFunctionSimulator(
204
- proxyContractStore,
205
- this.noteStore,
206
- this.keyStore,
207
- this.addressStore,
208
- ProxiedNodeFactory.create(this.node),
209
- this.anchorBlockStore,
210
- this.senderTaggingStore,
211
- this.recipientTaggingStore,
212
- this.senderAddressBookStore,
213
- this.capsuleStore,
214
- this.privateEventStore,
215
- this.simulator,
216
- );
285
+ return new ContractFunctionSimulator({
286
+ contractStore: proxyContractStore,
287
+ noteStore: this.noteStore,
288
+ keyStore: this.keyStore,
289
+ addressStore: this.addressStore,
290
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
291
+ senderTaggingStore: this.senderTaggingStore,
292
+ recipientTaggingStore: this.recipientTaggingStore,
293
+ senderAddressBookStore: this.senderAddressBookStore,
294
+ capsuleStore: this.capsuleStore,
295
+ privateEventStore: this.privateEventStore,
296
+ simulator: this.simulator,
297
+ contractSyncService: this.contractSyncService,
298
+ });
217
299
  }
218
300
 
219
301
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -265,34 +347,20 @@ export class PXE {
265
347
  async #registerProtocolContracts() {
266
348
  const registered: Record<string, string> = {};
267
349
  for (const name of protocolContractNames) {
268
- const { address, contractClass, instance, artifact } =
269
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
270
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
350
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
351
+ await this.contractStore.addContractArtifact(artifact);
271
352
  await this.contractStore.addContractInstance(instance);
272
353
  registered[name] = address.toString();
273
354
  }
274
355
  this.log.verbose(`Registered protocol contracts in pxe`, registered);
275
356
  }
276
357
 
277
- async #isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
278
- return !!(await this.node.getContractClass(id));
279
- }
280
-
281
- async #isContractPublished(address: AztecAddress): Promise<boolean> {
282
- return !!(await this.node.getContract(address));
283
- }
284
-
285
- async #isContractInitialized(address: AztecAddress): Promise<boolean> {
286
- const initNullifier = await siloNullifier(address, address.toField());
287
- return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
288
- }
289
-
290
358
  // Executes the entrypoint private function, as well as all nested private
291
359
  // functions that might arise.
292
360
  async #executePrivate(
293
361
  contractFunctionSimulator: ContractFunctionSimulator,
294
362
  txRequest: TxExecutionRequest,
295
- scopes: AztecAddress[] | undefined,
363
+ scopes: AccessScopes,
296
364
  jobId: string,
297
365
  ): Promise<PrivateExecutionResult> {
298
366
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -300,18 +368,23 @@ export class PXE {
300
368
  try {
301
369
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
302
370
 
303
- const result = await contractFunctionSimulator.run(
304
- txRequest,
371
+ await this.contractSyncService.ensureContractSynced(
305
372
  contractAddress,
306
373
  functionSelector,
307
- undefined,
374
+ (privateSyncCall, execScopes) =>
375
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
308
376
  anchorBlockHeader,
309
- // The sender for tags is set by contracts, typically by an account
310
- // contract entrypoint
311
- undefined, // senderForTags
312
- scopes,
313
377
  jobId,
378
+ scopes,
314
379
  );
380
+
381
+ const result = await contractFunctionSimulator.run(txRequest, {
382
+ contractAddress,
383
+ selector: functionSelector,
384
+ anchorBlockHeader,
385
+ scopes,
386
+ jobId,
387
+ });
315
388
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
316
389
  return result;
317
390
  } catch (err) {
@@ -323,20 +396,20 @@ export class PXE {
323
396
  }
324
397
 
325
398
  /**
326
- * Simulate a utility function call on the given contract.
399
+ * Execute a utility function call on the given contract.
327
400
  * @param contractFunctionSimulator - The simulator to use for the function call.
328
401
  * @param call - The function call to execute.
329
402
  * @param authWitnesses - Authentication witnesses required for the function call.
330
403
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
331
404
  * accounts if not specified.
332
405
  * @param jobId - The job ID for staged writes.
333
- * @returns The simulation result containing the outputs of the utility function.
406
+ * @returns The execution result containing the outputs of the utility function.
334
407
  */
335
- async #simulateUtility(
408
+ async #executeUtility(
336
409
  contractFunctionSimulator: ContractFunctionSimulator,
337
410
  call: FunctionCall,
338
411
  authWitnesses: AuthWitness[] | undefined,
339
- scopes: AztecAddress[] | undefined,
412
+ scopes: AccessScopes,
340
413
  jobId: string,
341
414
  ) {
342
415
  try {
@@ -394,85 +467,45 @@ export class PXE {
394
467
  privateExecutionResult: PrivateExecutionResult,
395
468
  config: PrivateKernelExecutionProverConfig,
396
469
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
397
- const simulationAnchorBlock = privateExecutionResult.getSimulationAnchorBlockNumber();
398
- const kernelOracle = new PrivateKernelOracleImpl(
399
- this.contractStore,
400
- this.keyStore,
401
- this.node,
402
- simulationAnchorBlock,
470
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
471
+ const anchorBlockHash = await anchorBlockHeader.hash();
472
+ const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
473
+ const kernelTraceProver = new PrivateKernelExecutionProver(
474
+ kernelOracle,
475
+ proofCreator,
476
+ !this.proverEnabled,
477
+ this.log.getBindings(),
403
478
  );
404
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
405
479
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
406
480
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
407
481
  }
408
482
 
409
483
  // Public API
410
484
 
411
- public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
412
- return this.contractStore.getContractInstance(address);
485
+ /**
486
+ * Returns the block header up to which the PXE has synced.
487
+ * @returns The synced block header
488
+ */
489
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
490
+ return this.anchorBlockStore.getBlockHeader();
413
491
  }
414
492
 
415
493
  /**
416
- * Returns the contract class metadata given a contract class id.
417
- * The metadata consists of its contract class, whether it has been publicly registered, and its artifact.
418
- * @remark - it queries the node to check whether the contract class with the given id has been publicly registered.
419
- * @param id - Identifier of the class.
420
- * @param includeArtifact - Identifier of the class.
421
- * @returns - It returns the contract class metadata, with the artifact field being optional, and will only be returned if true is passed in
422
- * for `includeArtifact`
423
- * TODO(@spalladino): The PXE actually holds artifacts and not classes, what should we return? Also,
424
- * should the pxe query the node for contract public info, and merge it with its own definitions?
425
- * TODO(@spalladino): This method is strictly needed to decide whether to publicly register a class or not
426
- * during a public deployment. We probably want a nicer and more general API for this, but it'll have to
427
- * do for the time being.
494
+ * Returns the contract instance for a given address, if it's registered in the PXE.
495
+ * @param address - The contract address.
496
+ * @returns The contract instance if found, undefined otherwise.
428
497
  */
429
- public async getContractClassMetadata(
430
- id: Fr,
431
- includeArtifact: boolean = false,
432
- ): Promise<{
433
- contractClass: ContractClassWithId | undefined;
434
- isContractClassPubliclyRegistered: boolean;
435
- artifact: ContractArtifact | undefined;
436
- }> {
437
- const artifact = await this.contractStore.getContractArtifact(id);
438
- if (!artifact) {
439
- this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
440
- }
441
-
442
- return {
443
- contractClass: artifact && (await getContractClassFromArtifact(artifact)),
444
- isContractClassPubliclyRegistered: await this.#isContractClassPubliclyRegistered(id),
445
- artifact: includeArtifact ? artifact : undefined,
446
- };
498
+ public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
499
+ return this.contractStore.getContractInstance(address);
447
500
  }
448
501
 
449
502
  /**
450
- * Returns the contract metadata given an address.
451
- * The metadata consists of its contract instance, which includes the contract class identifier,
452
- * initialization hash, deployment salt, and public keys hash; whether the contract instance has been initialized;
453
- * and whether the contract instance with the given address has been publicly deployed.
454
- * @remark - it queries the node to check whether the contract instance has been initialized / publicly deployed through a node.
455
- * This query is not dependent on the PXE.
456
- * @param address - The address that the contract instance resides at.
457
- * @returns - It returns the contract metadata
458
- * TODO(@spalladino): Should we return the public keys in plain as well here?
503
+ * Returns the contract artifact for a given contract class id, if it's registered in the PXE.
504
+ * @param id - Identifier of the contract class.
505
+ * @returns The contract artifact if found, undefined otherwise.
459
506
  */
460
- public async getContractMetadata(address: AztecAddress): Promise<{
461
- contractInstance: ContractInstanceWithAddress | undefined;
462
- isContractInitialized: boolean;
463
- isContractPublished: boolean;
464
- }> {
465
- let instance;
466
- try {
467
- instance = await this.contractStore.getContractInstance(address);
468
- } catch {
469
- this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
470
- }
471
- return {
472
- contractInstance: instance,
473
- isContractInitialized: await this.#isContractInitialized(address),
474
- isContractPublished: await this.#isContractPublished(address),
475
- };
507
+ public async getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
508
+ return await this.contractStore.getContractArtifact(id);
476
509
  }
477
510
 
478
511
  /**
@@ -497,7 +530,6 @@ export class PXE {
497
530
  }
498
531
 
499
532
  await this.addressStore.addCompleteAddress(accountCompleteAddress);
500
- await this.noteStore.addScope(accountCompleteAddress.address);
501
533
  return accountCompleteAddress;
502
534
  }
503
535
 
@@ -571,8 +603,7 @@ export class PXE {
571
603
  * @param artifact - The build artifact for the contract class.
572
604
  */
573
605
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
574
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
575
- await this.contractStore.addContractArtifact(contractClassId, artifact);
606
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
576
607
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
577
608
  }
578
609
 
@@ -591,17 +622,17 @@ export class PXE {
591
622
  if (artifact) {
592
623
  // If the user provides an artifact, validate it against the expected class id and register it
593
624
  const contractClass = await getContractClassFromArtifact(artifact);
594
- const contractClassId = contractClass.id;
595
- if (!contractClassId.equals(instance.currentContractClassId)) {
625
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
596
626
  throw new Error(
597
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
627
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
598
628
  );
599
629
  }
600
630
  const computedAddress = await computeContractAddressFromInstance(instance);
601
631
  if (!computedAddress.equals(instance.address)) {
602
632
  throw new Error('Added a contract in which the address does not match the contract instance.');
603
633
  }
604
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
634
+
635
+ await this.contractStore.addContractArtifact(artifact, contractClass);
605
636
 
606
637
  const publicFunctionSignatures = artifact.functions
607
638
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -645,26 +676,21 @@ export class PXE {
645
676
 
646
677
  const header = await this.anchorBlockStore.getBlockHeader();
647
678
 
648
- const currentClassId = await readCurrentClassId(
649
- contractAddress,
650
- currentInstance,
651
- this.node,
652
- header.globalVariables.blockNumber,
653
- header.globalVariables.timestamp,
654
- );
679
+ const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
655
680
  if (!contractClass.id.equals(currentClassId)) {
656
681
  throw new Error('Could not update contract to a class different from the current one.');
657
682
  }
658
683
 
659
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
660
-
661
684
  const publicFunctionSignatures = artifact.functions
662
685
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
663
686
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
664
687
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
665
688
 
666
689
  currentInstance.currentContractClassId = contractClass.id;
667
- await this.contractStore.addContractInstance(currentInstance);
690
+ await Promise.all([
691
+ this.contractStore.addContractArtifact(artifact, contractClass),
692
+ this.contractStore.addContractInstance(currentInstance),
693
+ ]);
668
694
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
669
695
  });
670
696
  }
@@ -682,11 +708,12 @@ export class PXE {
682
708
  * (where validators prove the public portion).
683
709
  *
684
710
  * @param txRequest - An authenticated tx request ready for proving
711
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
685
712
  * @returns A result containing the proof and public inputs of the tail circuit.
686
713
  * @throws If contract code not found, or public simulation reverts.
687
714
  * Also throws if simulatePublic is true and public simulation reverts.
688
715
  */
689
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
716
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
690
717
  let privateExecutionResult: PrivateExecutionResult;
691
718
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
692
719
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -697,7 +724,7 @@ export class PXE {
697
724
  await this.blockStateSynchronizer.sync();
698
725
  const syncTime = syncTimer.ms();
699
726
  const contractFunctionSimulator = this.#getSimulatorForTx();
700
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
727
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
701
728
 
702
729
  const {
703
730
  publicInputs,
@@ -744,7 +771,7 @@ export class PXE {
744
771
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
745
772
  const txHash = (await txProvingResult.toTx()).txHash;
746
773
 
747
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash);
774
+ await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
748
775
  this.log.debug(`Stored used pre-tags as sender for the tx`, {
749
776
  preTagsUsedInTheTx,
750
777
  });
@@ -761,17 +788,13 @@ export class PXE {
761
788
 
762
789
  /**
763
790
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
764
- *
765
- * @param txRequest - An authenticated tx request ready for simulation
766
- * @param msgSender - (Optional) The message sender to use for the simulation.
767
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
791
+ * @param txRequest - An authenticated tx request ready for simulation.
768
792
  * @returns A trace of the program execution with gate counts.
769
793
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
770
794
  */
771
795
  public profileTx(
772
796
  txRequest: TxExecutionRequest,
773
- profileMode: 'full' | 'execution-steps' | 'gates',
774
- skipProofGeneration: boolean = true,
797
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
775
798
  ): Promise<TxProfileResult> {
776
799
  // We disable concurrent profiles for consistency with simulateTx.
777
800
  return this.#putInJobQueue(async jobId => {
@@ -794,12 +817,7 @@ export class PXE {
794
817
  const syncTime = syncTimer.ms();
795
818
 
796
819
  const contractFunctionSimulator = this.#getSimulatorForTx();
797
- const privateExecutionResult = await this.#executePrivate(
798
- contractFunctionSimulator,
799
- txRequest,
800
- undefined,
801
- jobId,
802
- );
820
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
803
821
 
804
822
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
805
823
  txRequest,
@@ -856,12 +874,7 @@ export class PXE {
856
874
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
857
875
  *
858
876
  *
859
- * @param txRequest - An authenticated tx request ready for simulation
860
- * @param simulatePublic - Whether to simulate the public part of the transaction.
861
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
862
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
863
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
864
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
877
+ * @param txRequest - An authenticated tx request ready for simulation.
865
878
  * @returns A simulated transaction result object that includes public and private return values.
866
879
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
867
880
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -870,11 +883,7 @@ export class PXE {
870
883
  */
871
884
  public simulateTx(
872
885
  txRequest: TxExecutionRequest,
873
- simulatePublic: boolean,
874
- skipTxValidation: boolean = false,
875
- skipFeeEnforcement: boolean = false,
876
- overrides?: SimulationOverrides,
877
- scopes?: AztecAddress[],
886
+ { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
878
887
  ): Promise<TxSimulationResult> {
879
888
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
880
889
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -902,7 +911,14 @@ export class PXE {
902
911
  // Temporary: in case there are overrides, we have to skip the kernels or validations
903
912
  // will fail. Consider handing control to the user/wallet on whether they want to run them
904
913
  // or not.
905
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
914
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
915
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
916
+ const skipKernels = hasOverriddenContracts;
917
+
918
+ // Set overridden contracts on the sync service so it knows to skip syncing them
919
+ if (hasOverriddenContracts) {
920
+ this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
921
+ }
906
922
 
907
923
  // Execution of private functions only; no proving, and no kernel logic.
908
924
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
@@ -911,15 +927,10 @@ export class PXE {
911
927
  let executionSteps: PrivateExecutionStep[] = [];
912
928
 
913
929
  if (skipKernels) {
914
- // According to the protocol rules, the nonce generator for the note hashes
915
- // can either be the first nullifier in the tx or the protocol nullifier if there are none.
916
- const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO)
917
- ? await computeProtocolNullifier(await txRequest.toTxRequest().hash())
918
- : privateExecutionResult.firstNullifier;
919
930
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
920
931
  privateExecutionResult,
921
- nonceGenerator,
922
- this.contractStore,
932
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
933
+ this.node,
923
934
  ));
924
935
  } else {
925
936
  // Kernel logic, plus proving of all private functions and kernels.
@@ -938,6 +949,9 @@ export class PXE {
938
949
  const publicSimulationTimer = new Timer();
939
950
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
940
951
  publicSimulationTime = publicSimulationTimer.ms();
952
+ if (publicOutput?.debugLogs?.length) {
953
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
954
+ }
941
955
  }
942
956
 
943
957
  let validationTime: number | undefined;
@@ -946,7 +960,8 @@ export class PXE {
946
960
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
947
961
  validationTime = validationTimer.ms();
948
962
  if (validationResult.result === 'invalid') {
949
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
963
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
964
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
950
965
  }
951
966
  }
952
967
 
@@ -997,29 +1012,23 @@ export class PXE {
997
1012
  inspect(txRequest),
998
1013
  `simulatePublic=${simulatePublic}`,
999
1014
  `skipTxValidation=${skipTxValidation}`,
1000
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1015
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1001
1016
  );
1002
1017
  }
1003
1018
  });
1004
1019
  }
1005
1020
 
1006
1021
  /**
1007
- * Simulate the execution of a contract utility function.
1008
- *
1022
+ * Executes a contract utility function.
1009
1023
  * @param call - The function call containing the function details, arguments, and target contract address.
1010
- * @param authwits - (Optional) The authentication witnesses required for the function call.
1011
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
1012
- * default to all.
1013
- * @returns The result of the utility function call, structured based on the function ABI.
1014
1024
  */
1015
- public simulateUtility(
1025
+ public executeUtility(
1016
1026
  call: FunctionCall,
1017
- authwits?: AuthWitness[],
1018
- scopes?: AztecAddress[],
1019
- ): Promise<UtilitySimulationResult> {
1020
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1027
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
1028
+ ): Promise<UtilityExecutionResult> {
1029
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
1021
1030
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
1022
- // delete the same read value, or reading values that another simulation is currently modifying).
1031
+ // delete the same read value, or reading values that another execution is currently modifying).
1023
1032
  return this.#putInJobQueue(async jobId => {
1024
1033
  try {
1025
1034
  const totalTimer = new Timer();
@@ -1029,11 +1038,18 @@ export class PXE {
1029
1038
  const functionTimer = new Timer();
1030
1039
  const contractFunctionSimulator = this.#getSimulatorForTx();
1031
1040
 
1032
- await this.contractStore.syncPrivateState(call.to, call.selector, privateSyncCall =>
1033
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1041
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1042
+ await this.contractSyncService.ensureContractSynced(
1043
+ call.to,
1044
+ call.selector,
1045
+ (privateSyncCall, execScopes) =>
1046
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1047
+ anchorBlockHeader,
1048
+ jobId,
1049
+ scopes,
1034
1050
  );
1035
1051
 
1036
- const executionResult = await this.#simulateUtility(
1052
+ const executionResult = await this.#executeUtility(
1037
1053
  contractFunctionSimulator,
1038
1054
  call,
1039
1055
  authwits ?? [],
@@ -1060,8 +1076,8 @@ export class PXE {
1060
1076
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1061
1077
  throw this.#contextualizeError(
1062
1078
  err,
1063
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1064
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1079
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1080
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1065
1081
  );
1066
1082
  }
1067
1083
  });
@@ -1080,32 +1096,46 @@ export class PXE {
1080
1096
  * Defaults to the latest known block to PXE + 1.
1081
1097
  * @returns - The packed events with block and tx metadata.
1082
1098
  */
1083
- public getPrivateEvents(eventSelector: EventSelector, filter: PrivateEventFilter): Promise<PackedPrivateEvent[]> {
1084
- return this.#putInJobQueue(async jobId => {
1099
+ public async getPrivateEvents(
1100
+ eventSelector: EventSelector,
1101
+ filter: PrivateEventFilter,
1102
+ ): Promise<PackedPrivateEvent[]> {
1103
+ let anchorBlockNumber: BlockNumber;
1104
+
1105
+ await this.#putInJobQueue(async jobId => {
1085
1106
  await this.blockStateSynchronizer.sync();
1107
+
1108
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1109
+ anchorBlockNumber = anchorBlockHeader.getBlockNumber();
1110
+
1086
1111
  const contractFunctionSimulator = this.#getSimulatorForTx();
1087
1112
 
1088
- await this.contractStore.syncPrivateState(
1113
+ await this.contractSyncService.ensureContractSynced(
1089
1114
  filter.contractAddress,
1090
1115
  null,
1091
- async privateSyncCall =>
1092
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1116
+ async (privateSyncCall, execScopes) =>
1117
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1118
+ anchorBlockHeader,
1119
+ jobId,
1120
+ filter.scopes,
1093
1121
  );
1122
+ });
1094
1123
 
1095
- const sanitizedFilter = await new PrivateEventFilterValidator(this.anchorBlockStore).validate(filter);
1124
+ // anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
1125
+ const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber!).validate(filter);
1096
1126
 
1097
- this.log.debug(
1098
- `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
1099
- );
1127
+ this.log.debug(
1128
+ `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
1129
+ );
1100
1130
 
1101
- return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
1102
- });
1131
+ return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
1103
1132
  }
1104
1133
 
1105
1134
  /**
1106
- * Stops the PXE's job queue.
1135
+ * Stops the PXE's job queue and closes the backing store.
1107
1136
  */
1108
- public stop(): Promise<void> {
1109
- return this.jobQueue.end();
1137
+ public async stop(): Promise<void> {
1138
+ await this.jobQueue.end();
1139
+ await this.db.close();
1110
1140
  }
1111
1141
  }