@aztec/pxe 0.0.1-commit.934299a21 → 0.0.1-commit.949a33fd8

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 (223) hide show
  1. package/dest/bin/check_oracle_version.js +4 -4
  2. package/dest/block_synchronizer/block_stream_source.d.ts +10 -0
  3. package/dest/block_synchronizer/block_stream_source.d.ts.map +1 -0
  4. package/dest/block_synchronizer/block_stream_source.js +37 -0
  5. package/dest/block_synchronizer/block_synchronizer.d.ts +6 -2
  6. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  7. package/dest/block_synchronizer/block_synchronizer.js +30 -10
  8. package/dest/config/index.d.ts +2 -2
  9. package/dest/config/index.d.ts.map +1 -1
  10. package/dest/config/index.js +8 -15
  11. package/dest/contract_function_simulator/contract_function_simulator.d.ts +13 -5
  12. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/contract_function_simulator.js +39 -13
  14. package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
  15. package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
  16. package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
  17. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  18. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
  20. package/dest/contract_function_simulator/index.d.ts +2 -1
  21. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/index.js +1 -0
  23. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -6
  24. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +8 -10
  26. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
  27. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
  28. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
  29. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  30. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +2 -4
  31. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +4 -7
  32. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +6 -11
  34. package/dest/contract_function_simulator/oracle/interfaces.d.ts +63 -45
  35. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  37. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  38. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +47 -0
  39. package/dest/contract_function_simulator/oracle/oracle.d.ts +76 -44
  40. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/oracle/oracle.js +288 -96
  42. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  43. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +32 -59
  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 +67 -86
  46. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +100 -60
  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 +326 -111
  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 +9 -4
  56. package/dest/contract_logging.d.ts.map +1 -1
  57. package/dest/contract_logging.js +21 -6
  58. package/dest/contract_sync/contract_sync_service.d.ts +6 -5
  59. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  60. package/dest/contract_sync/contract_sync_service.js +62 -43
  61. package/dest/contract_sync/helpers.d.ts +2 -3
  62. package/dest/contract_sync/helpers.d.ts.map +1 -1
  63. package/dest/contract_sync/helpers.js +7 -2
  64. package/dest/debug/pxe_debug_utils.d.ts +3 -3
  65. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  66. package/dest/entrypoints/client/bundle/index.d.ts +1 -2
  67. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  68. package/dest/entrypoints/client/bundle/index.js +0 -1
  69. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  70. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  71. package/dest/entrypoints/client/bundle/utils.js +2 -2
  72. package/dest/entrypoints/client/lazy/index.d.ts +1 -2
  73. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  74. package/dest/entrypoints/client/lazy/index.js +0 -1
  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 +2 -2
  78. package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
  79. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  80. package/dest/entrypoints/pxe_creation_options.js +3 -1
  81. package/dest/entrypoints/server/index.d.ts +2 -3
  82. package/dest/entrypoints/server/index.d.ts.map +1 -1
  83. package/dest/entrypoints/server/index.js +1 -2
  84. package/dest/entrypoints/server/utils.d.ts +2 -2
  85. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  86. package/dest/entrypoints/server/utils.js +2 -2
  87. package/dest/events/event_service.d.ts +3 -2
  88. package/dest/events/event_service.d.ts.map +1 -1
  89. package/dest/events/event_service.js +26 -5
  90. package/dest/events/private_event_filter_validator.d.ts +3 -2
  91. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  92. package/dest/events/private_event_filter_validator.js +15 -0
  93. package/dest/logs/log_service.d.ts +7 -8
  94. package/dest/logs/log_service.d.ts.map +1 -1
  95. package/dest/logs/log_service.js +29 -39
  96. package/dest/messages/message_context_service.d.ts +17 -0
  97. package/dest/messages/message_context_service.d.ts.map +1 -0
  98. package/dest/messages/message_context_service.js +36 -0
  99. package/dest/notes/note_service.d.ts +4 -5
  100. package/dest/notes/note_service.d.ts.map +1 -1
  101. package/dest/notes/note_service.js +14 -5
  102. package/dest/notes_filter.d.ts +2 -3
  103. package/dest/notes_filter.d.ts.map +1 -1
  104. package/dest/oracle_version.d.ts +4 -3
  105. package/dest/oracle_version.d.ts.map +1 -1
  106. package/dest/oracle_version.js +20 -10
  107. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  108. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  109. package/dest/private_kernel/private_kernel_execution_prover.js +4 -7
  110. package/dest/private_kernel/private_kernel_oracle.d.ts +5 -5
  111. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  112. package/dest/private_kernel/private_kernel_oracle.js +12 -15
  113. package/dest/pxe.d.ts +25 -10
  114. package/dest/pxe.d.ts.map +1 -1
  115. package/dest/pxe.js +91 -42
  116. package/dest/storage/anchor_block_store/anchor_block_store.js +1 -1
  117. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  118. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  119. package/dest/storage/capsule_store/capsule_service.js +50 -0
  120. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  121. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  122. package/dest/storage/capsule_store/capsule_store.js +36 -28
  123. package/dest/storage/capsule_store/index.d.ts +2 -1
  124. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  125. package/dest/storage/capsule_store/index.js +1 -0
  126. package/dest/storage/contract_store/contract_store.d.ts +1 -1
  127. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  128. package/dest/storage/contract_store/contract_store.js +4 -2
  129. package/dest/storage/metadata.d.ts +1 -1
  130. package/dest/storage/metadata.js +1 -1
  131. package/dest/storage/note_store/note_store.d.ts +1 -1
  132. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  133. package/dest/storage/note_store/note_store.js +2 -2
  134. package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
  135. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  136. package/dest/storage/private_event_store/private_event_store.js +3 -0
  137. package/dest/storage/private_event_store/stored_private_event.js +1 -1
  138. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  139. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  140. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  141. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  142. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  143. package/dest/tagging/index.d.ts +3 -3
  144. package/dest/tagging/index.d.ts.map +1 -1
  145. package/dest/tagging/index.js +1 -1
  146. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
  147. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  148. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +4 -18
  149. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
  150. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  151. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  152. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
  153. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  154. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
  155. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  156. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  157. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  158. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
  159. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  160. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
  161. package/package.json +16 -16
  162. package/src/bin/check_oracle_version.ts +4 -4
  163. package/src/block_synchronizer/block_stream_source.ts +52 -0
  164. package/src/block_synchronizer/block_synchronizer.ts +33 -11
  165. package/src/config/index.ts +3 -9
  166. package/src/contract_function_simulator/contract_function_simulator.ts +52 -16
  167. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  168. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  169. package/src/contract_function_simulator/index.ts +1 -0
  170. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +9 -9
  171. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
  172. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
  173. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +4 -10
  174. package/src/contract_function_simulator/oracle/interfaces.ts +91 -53
  175. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
  176. package/src/contract_function_simulator/oracle/oracle.ts +377 -139
  177. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  178. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +87 -109
  179. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +530 -148
  180. package/src/contract_function_simulator/pick_notes.ts +22 -3
  181. package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
  182. package/src/contract_logging.ts +18 -5
  183. package/src/contract_sync/contract_sync_service.ts +99 -75
  184. package/src/contract_sync/helpers.ts +4 -4
  185. package/src/debug/pxe_debug_utils.ts +3 -3
  186. package/src/entrypoints/client/bundle/index.ts +0 -1
  187. package/src/entrypoints/client/bundle/utils.ts +2 -3
  188. package/src/entrypoints/client/lazy/index.ts +0 -1
  189. package/src/entrypoints/client/lazy/utils.ts +2 -3
  190. package/src/entrypoints/pxe_creation_options.ts +7 -0
  191. package/src/entrypoints/server/index.ts +1 -2
  192. package/src/entrypoints/server/utils.ts +2 -3
  193. package/src/events/event_service.ts +30 -5
  194. package/src/events/private_event_filter_validator.ts +21 -1
  195. package/src/logs/log_service.ts +59 -75
  196. package/src/messages/message_context_service.ts +44 -0
  197. package/src/notes/note_service.ts +18 -8
  198. package/src/notes_filter.ts +1 -3
  199. package/src/oracle_version.ts +20 -10
  200. package/src/private_kernel/private_kernel_execution_prover.ts +4 -9
  201. package/src/private_kernel/private_kernel_oracle.ts +14 -14
  202. package/src/pxe.ts +153 -53
  203. package/src/storage/anchor_block_store/anchor_block_store.ts +1 -1
  204. package/src/storage/capsule_store/capsule_service.ts +90 -0
  205. package/src/storage/capsule_store/capsule_store.ts +44 -26
  206. package/src/storage/capsule_store/index.ts +1 -0
  207. package/src/storage/contract_store/contract_store.ts +8 -6
  208. package/src/storage/metadata.ts +1 -1
  209. package/src/storage/note_store/note_store.ts +2 -5
  210. package/src/storage/private_event_store/private_event_store.ts +4 -0
  211. package/src/storage/private_event_store/stored_private_event.ts +1 -1
  212. package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
  213. package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
  214. package/src/tagging/index.ts +2 -2
  215. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +8 -21
  216. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
  217. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
  218. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  219. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
  220. package/dest/access_scopes.d.ts +0 -9
  221. package/dest/access_scopes.d.ts.map +0 -1
  222. package/dest/access_scopes.js +0 -6
  223. package/src/access_scopes.ts +0 -9
@@ -17,6 +17,7 @@ import {
17
17
  MAX_NULLIFIERS_PER_TX,
18
18
  MAX_NULLIFIER_READ_REQUESTS_PER_TX,
19
19
  MAX_PRIVATE_LOGS_PER_TX,
20
+ MAX_TX_LIFETIME,
20
21
  PRIVATE_TX_L2_GAS_OVERHEAD,
21
22
  PUBLIC_TX_L2_GAS_OVERHEAD,
22
23
  TX_DA_GAS_OVERHEAD,
@@ -41,7 +42,7 @@ import type { FunctionCall } from '@aztec/stdlib/abi';
41
42
  import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
42
43
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
43
44
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
44
- import type { BlockParameter } from '@aztec/stdlib/block';
45
+ import type { BlockParameter, L2TipsProvider } from '@aztec/stdlib/block';
45
46
  import { Gas } from '@aztec/stdlib/gas';
46
47
  import {
47
48
  computeNoteHashNonce,
@@ -79,6 +80,7 @@ import {
79
80
  BlockHeader,
80
81
  CallContext,
81
82
  HashedValues,
83
+ type OffchainEffect,
82
84
  PrivateExecutionResult,
83
85
  TxConstantData,
84
86
  TxExecutionRequest,
@@ -87,9 +89,10 @@ import {
87
89
  getFinalMinRevertibleSideEffectCounter,
88
90
  } from '@aztec/stdlib/tx';
89
91
 
90
- import type { AccessScopes } from '../access_scopes.js';
91
92
  import type { ContractSyncService } from '../contract_sync/contract_sync_service.js';
93
+ import type { MessageContextService } from '../messages/message_context_service.js';
92
94
  import type { AddressStore } from '../storage/address_store/address_store.js';
95
+ import { CapsuleService } from '../storage/capsule_store/capsule_service.js';
93
96
  import type { CapsuleStore } from '../storage/capsule_store/capsule_store.js';
94
97
  import type { ContractStore } from '../storage/contract_store/contract_store.js';
95
98
  import type { NoteStore } from '../storage/note_store/note_store.js';
@@ -119,7 +122,7 @@ export type ContractSimulatorRunOpts = {
119
122
  /** The address used as a tagging sender when emitting private logs. */
120
123
  senderForTags?: AztecAddress;
121
124
  /** The accounts whose notes we can access in this call. */
122
- scopes: AccessScopes;
125
+ scopes: AztecAddress[];
123
126
  /** The job ID for staged writes. */
124
127
  jobId: string;
125
128
  };
@@ -131,6 +134,7 @@ export type ContractFunctionSimulatorArgs = {
131
134
  keyStore: KeyStore;
132
135
  addressStore: AddressStore;
133
136
  aztecNode: AztecNode;
137
+ l2TipsStore: L2TipsProvider;
134
138
  senderTaggingStore: SenderTaggingStore;
135
139
  recipientTaggingStore: RecipientTaggingStore;
136
140
  senderAddressBookStore: SenderAddressBookStore;
@@ -138,6 +142,7 @@ export type ContractFunctionSimulatorArgs = {
138
142
  privateEventStore: PrivateEventStore;
139
143
  simulator: CircuitSimulator;
140
144
  contractSyncService: ContractSyncService;
145
+ messageContextService: MessageContextService;
141
146
  };
142
147
 
143
148
  /**
@@ -150,6 +155,7 @@ export class ContractFunctionSimulator {
150
155
  private readonly keyStore: KeyStore;
151
156
  private readonly addressStore: AddressStore;
152
157
  private readonly aztecNode: AztecNode;
158
+ private readonly l2TipsStore: L2TipsProvider;
153
159
  private readonly senderTaggingStore: SenderTaggingStore;
154
160
  private readonly recipientTaggingStore: RecipientTaggingStore;
155
161
  private readonly senderAddressBookStore: SenderAddressBookStore;
@@ -157,6 +163,7 @@ export class ContractFunctionSimulator {
157
163
  private readonly privateEventStore: PrivateEventStore;
158
164
  private readonly simulator: CircuitSimulator;
159
165
  private readonly contractSyncService: ContractSyncService;
166
+ private readonly messageContextService: MessageContextService;
160
167
 
161
168
  constructor(args: ContractFunctionSimulatorArgs) {
162
169
  this.contractStore = args.contractStore;
@@ -164,6 +171,7 @@ export class ContractFunctionSimulator {
164
171
  this.keyStore = args.keyStore;
165
172
  this.addressStore = args.addressStore;
166
173
  this.aztecNode = args.aztecNode;
174
+ this.l2TipsStore = args.l2TipsStore;
167
175
  this.senderTaggingStore = args.senderTaggingStore;
168
176
  this.recipientTaggingStore = args.recipientTaggingStore;
169
177
  this.senderAddressBookStore = args.senderAddressBookStore;
@@ -171,6 +179,7 @@ export class ContractFunctionSimulator {
171
179
  this.privateEventStore = args.privateEventStore;
172
180
  this.simulator = args.simulator;
173
181
  this.contractSyncService = args.contractSyncService;
182
+ this.messageContextService = args.messageContextService;
174
183
  this.log = createLogger('simulator');
175
184
  }
176
185
 
@@ -199,7 +208,7 @@ export class ContractFunctionSimulator {
199
208
  }
200
209
 
201
210
  if (request.origin !== contractAddress) {
202
- this.log.warn(
211
+ throw new Error(
203
212
  `Request origin does not match contract address in simulation. Request origin: ${request.origin}, contract address: ${contractAddress}`,
204
213
  );
205
214
  }
@@ -239,8 +248,9 @@ export class ContractFunctionSimulator {
239
248
  senderTaggingStore: this.senderTaggingStore,
240
249
  recipientTaggingStore: this.recipientTaggingStore,
241
250
  senderAddressBookStore: this.senderAddressBookStore,
242
- capsuleStore: this.capsuleStore,
251
+ capsuleService: new CapsuleService(this.capsuleStore, scopes),
243
252
  privateEventStore: this.privateEventStore,
253
+ messageContextService: this.messageContextService,
244
254
  contractSyncService: this.contractSyncService,
245
255
  jobId,
246
256
  totalPublicCalldataCount: 0,
@@ -248,6 +258,7 @@ export class ContractFunctionSimulator {
248
258
  scopes,
249
259
  senderForTags,
250
260
  simulator: this.simulator,
261
+ l2TipsStore: this.l2TipsStore,
251
262
  });
252
263
 
253
264
  const setupTime = simulatorSetupTimer.ms();
@@ -277,7 +288,7 @@ export class ContractFunctionSimulator {
277
288
  );
278
289
  const publicFunctionsCalldata = await Promise.all(
279
290
  publicCallRequests.map(async r => {
280
- const calldata = await privateExecutionOracle.privateLoadFromExecutionCache(r.calldataHash);
291
+ const calldata = await privateExecutionOracle.getHashPreimage(r.calldataHash);
281
292
  return new HashedValues(calldata, r.calldataHash);
282
293
  }),
283
294
  );
@@ -298,7 +309,6 @@ export class ContractFunctionSimulator {
298
309
  }
299
310
  }
300
311
 
301
- // docs:start:execute_utility_function
302
312
  /**
303
313
  * Runs a utility function.
304
314
  * @param call - The function call to execute.
@@ -312,9 +322,9 @@ export class ContractFunctionSimulator {
312
322
  call: FunctionCall,
313
323
  authwits: AuthWitness[],
314
324
  anchorBlockHeader: BlockHeader,
315
- scopes: AccessScopes,
325
+ scopes: AztecAddress[],
316
326
  jobId: string,
317
- ): Promise<Fr[]> {
327
+ ): Promise<{ result: Fr[]; offchainEffects: OffchainEffect[] }> {
318
328
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
319
329
 
320
330
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
@@ -333,10 +343,14 @@ export class ContractFunctionSimulator {
333
343
  aztecNode: this.aztecNode,
334
344
  recipientTaggingStore: this.recipientTaggingStore,
335
345
  senderAddressBookStore: this.senderAddressBookStore,
336
- capsuleStore: this.capsuleStore,
346
+ capsuleService: new CapsuleService(this.capsuleStore, scopes),
337
347
  privateEventStore: this.privateEventStore,
348
+ messageContextService: this.messageContextService,
349
+ contractSyncService: this.contractSyncService,
350
+ l2TipsStore: this.l2TipsStore,
338
351
  jobId,
339
352
  scopes,
353
+ simulator: this.simulator,
340
354
  });
341
355
 
342
356
  try {
@@ -362,12 +376,14 @@ export class ContractFunctionSimulator {
362
376
  });
363
377
 
364
378
  this.log.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
365
- return witnessMapToFields(acirExecutionResult.returnWitness);
379
+ return {
380
+ result: witnessMapToFields(acirExecutionResult.returnWitness),
381
+ offchainEffects: oracle.getOffchainEffects(),
382
+ };
366
383
  } catch (err) {
367
384
  throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during private execution'));
368
385
  }
369
386
  }
370
- // docs:end:execute_utility_function
371
387
 
372
388
  /**
373
389
  * Returns the execution statistics collected during the simulator run.
@@ -432,14 +448,34 @@ export async function generateSimulatedProvingResult(
432
448
 
433
449
  let publicTeardownCallRequest;
434
450
 
451
+ // We set expiration timestamp to anchor_block_timestamp + MAX_TX_LIFETIME (24h) just like kernels do
452
+ let expirationTimestamp =
453
+ privateExecutionResult.entrypoint.publicInputs.anchorBlockHeader.globalVariables.timestamp +
454
+ BigInt(MAX_TX_LIFETIME);
455
+
456
+ let feePayer = AztecAddress.zero();
457
+
435
458
  const executions = [privateExecutionResult.entrypoint];
436
459
 
437
460
  while (executions.length !== 0) {
438
461
  const execution = executions.shift()!;
439
462
  executions.unshift(...execution!.nestedExecutionResults);
440
463
 
464
+ // Just like kernels we overwrite the default value if the call sets it.
465
+ const callExpirationTimestamp = execution.publicInputs.expirationTimestamp;
466
+ if (callExpirationTimestamp !== 0n && callExpirationTimestamp < expirationTimestamp) {
467
+ expirationTimestamp = callExpirationTimestamp;
468
+ }
469
+
441
470
  const { contractAddress } = execution.publicInputs.callContext;
442
471
 
472
+ if (execution.publicInputs.isFeePayer) {
473
+ if (!feePayer.isZero()) {
474
+ throw new Error('Multiple fee payers found in private execution result');
475
+ }
476
+ feePayer = contractAddress;
477
+ }
478
+
443
479
  scopedNoteHashes.push(
444
480
  ...execution.publicInputs.noteHashes
445
481
  .getActiveItems()
@@ -660,8 +696,8 @@ export async function generateSimulatedProvingResult(
660
696
  daGas: TX_DA_GAS_OVERHEAD,
661
697
  }),
662
698
  ),
663
- /*feePayer=*/ AztecAddress.zero(),
664
- /*expirationTimestamp=*/ 0n,
699
+ /*feePayer=*/ feePayer,
700
+ /*expirationTimestamp=*/ expirationTimestamp,
665
701
  hasPublicCalls ? inputsForPublic : undefined,
666
702
  !hasPublicCalls ? inputsForRollup : undefined,
667
703
  );
@@ -809,9 +845,9 @@ function meterGasUsed(data: PrivateToRollupAccumulatedData | PrivateToPublicAccu
809
845
  meteredL2Gas += numPrivatelogs * L2_GAS_PER_PRIVATE_LOG;
810
846
 
811
847
  const numContractClassLogs = arrayNonEmptyLength(data.contractClassLogsHashes, log => log.isEmpty());
812
- // Every contract class log emits its length and contract address as additional fields
848
+ // Every contract class log emits its contract address as an additional field
813
849
  meteredDAFields += data.contractClassLogsHashes.reduce(
814
- (acc, log) => (!log.isEmpty() ? acc + log.logHash.length + 2 : acc),
850
+ (acc, log) => (!log.isEmpty() ? acc + log.logHash.length + 1 : acc),
815
851
  0,
816
852
  );
817
853
  meteredL2Gas += numContractClassLogs * L2_GAS_PER_CONTRACT_CLASS_LOG;
@@ -0,0 +1,110 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+
3
+ /** In-memory store for ephemeral arrays scoped to a single contract call frame. */
4
+ export class EphemeralArrayService {
5
+ /**
6
+ * Maps a slot to the elements of the array stored at that slot. Each element is a serialized representation of
7
+ * the original type.
8
+ */
9
+ #arrays: Map<string, Fr[][]> = new Map();
10
+
11
+ /** Returns all elements in the array, or an empty array if uninitialized. */
12
+ readArrayAt(slot: Fr): Fr[][] {
13
+ return this.#arrays.get(slot.toString()) ?? [];
14
+ }
15
+
16
+ #setArray(slot: Fr, array: Fr[][]): void {
17
+ this.#arrays.set(slot.toString(), array);
18
+ }
19
+
20
+ /** Returns the number of elements in the array at the given slot. */
21
+ len(slot: Fr): number {
22
+ return this.readArrayAt(slot).length;
23
+ }
24
+
25
+ /** Appends an element to the array and returns the new length. */
26
+ push(slot: Fr, elements: Fr[]): number {
27
+ const array = this.readArrayAt(slot);
28
+ array.push(elements);
29
+ this.#setArray(slot, array);
30
+ return array.length;
31
+ }
32
+
33
+ /** Removes and returns the last element. Throws if empty. */
34
+ pop(slot: Fr): Fr[] {
35
+ const array = this.readArrayAt(slot);
36
+ if (array.length === 0) {
37
+ throw new Error(`Ephemeral array at slot ${slot} is empty`);
38
+ }
39
+ const element = array.pop()!;
40
+ this.#setArray(slot, array);
41
+ return element;
42
+ }
43
+
44
+ /** Returns the element at the given index. Throws if out of bounds. */
45
+ get(slot: Fr, index: number): Fr[] {
46
+ const array = this.readArrayAt(slot);
47
+ if (index < 0 || index >= array.length) {
48
+ throw new Error(
49
+ `Ephemeral array index ${index} out of bounds for array of length ${array.length} at slot ${slot}`,
50
+ );
51
+ }
52
+ return array[index];
53
+ }
54
+
55
+ /** Overwrites the element at the given index. Throws if out of bounds. */
56
+ set(slot: Fr, index: number, value: Fr[]): void {
57
+ const array = this.readArrayAt(slot);
58
+ if (index < 0 || index >= array.length) {
59
+ throw new Error(
60
+ `Ephemeral array index ${index} out of bounds for array of length ${array.length} at slot ${slot}`,
61
+ );
62
+ }
63
+ array[index] = value;
64
+ }
65
+
66
+ /** Removes the element at the given index, shifting subsequent elements backward. Throws if out of bounds. */
67
+ remove(slot: Fr, index: number): void {
68
+ const array = this.readArrayAt(slot);
69
+ if (index < 0 || index >= array.length) {
70
+ throw new Error(
71
+ `Ephemeral array index ${index} out of bounds for array of length ${array.length} at slot ${slot}`,
72
+ );
73
+ }
74
+ array.splice(index, 1);
75
+ }
76
+
77
+ /** Removes all elements from the array. */
78
+ clear(slot: Fr): void {
79
+ this.#arrays.delete(slot.toString());
80
+ }
81
+
82
+ /** Allocates a fresh, unused slot for a new ephemeral array. */
83
+ allocateSlot(): Fr {
84
+ let slot: Fr;
85
+ do {
86
+ slot = Fr.random();
87
+ } while (this.#arrays.has(slot.toString()));
88
+ return slot;
89
+ }
90
+
91
+ /** Creates a new ephemeral array pre-populated with the given elements and returns its slot. */
92
+ newArray(elements: Fr[][]): Fr {
93
+ const slot = this.allocateSlot();
94
+ this.#setArray(slot, elements);
95
+ return slot;
96
+ }
97
+
98
+ /** Copies `count` elements from the source array to the destination array (overwrites destination). */
99
+ copy(srcSlot: Fr, dstSlot: Fr, count: number): void {
100
+ const srcArray = this.readArrayAt(srcSlot);
101
+ if (count > srcArray.length) {
102
+ throw new Error(
103
+ `Cannot copy ${count} elements from ephemeral array of length ${srcArray.length} at slot ${srcSlot}`,
104
+ );
105
+ }
106
+ // Deep copy the elements to avoid aliasing
107
+ const copied = srcArray.slice(0, count).map(el => [...el]);
108
+ this.#setArray(dstSlot, copied);
109
+ }
110
+ }
@@ -1,32 +1,37 @@
1
- import { DirectionalAppTaggingSecret, type PreTag } from '@aztec/stdlib/logs';
1
+ import { ExtendedDirectionalAppTaggingSecret, type TaggingIndexRange } from '@aztec/stdlib/logs';
2
2
 
3
3
  /**
4
- * A map that stores the tagging index for a given directional app tagging secret.
4
+ * A map that stores the tagging index range for a given extended directional app tagging secret.
5
5
  * Note: The directional app tagging secret is unique for a (sender, recipient, contract) tuple while the direction
6
6
  * of sender -> recipient matters.
7
7
  */
8
8
  export class ExecutionTaggingIndexCache {
9
- private taggingIndexMap: Map<string, number> = new Map();
9
+ private taggingIndexMap: Map<string, { lowestIndex: number; highestIndex: number }> = new Map();
10
10
 
11
- public getLastUsedIndex(secret: DirectionalAppTaggingSecret): number | undefined {
12
- return this.taggingIndexMap.get(secret.toString());
11
+ public getLastUsedIndex(secret: ExtendedDirectionalAppTaggingSecret): number | undefined {
12
+ return this.taggingIndexMap.get(secret.toString())?.highestIndex;
13
13
  }
14
14
 
15
- public setLastUsedIndex(secret: DirectionalAppTaggingSecret, index: number) {
15
+ public setLastUsedIndex(secret: ExtendedDirectionalAppTaggingSecret, index: number) {
16
16
  const currentValue = this.taggingIndexMap.get(secret.toString());
17
- if (currentValue !== undefined && currentValue !== index - 1) {
18
- throw new Error(`Invalid tagging index update. Current value: ${currentValue}, new value: ${index}`);
17
+ if (currentValue !== undefined && currentValue.highestIndex !== index - 1) {
18
+ throw new Error(`Invalid tagging index update. Current value: ${currentValue.highestIndex}, new value: ${index}`);
19
+ }
20
+ if (currentValue !== undefined) {
21
+ currentValue.highestIndex = index;
22
+ } else {
23
+ this.taggingIndexMap.set(secret.toString(), { lowestIndex: index, highestIndex: index });
19
24
  }
20
- this.taggingIndexMap.set(secret.toString(), index);
21
25
  }
22
26
 
23
27
  /**
24
- * Returns the pre-tags that were used in this execution (and that need to be stored in the db).
28
+ * Returns the tagging index ranges that were used in this execution (and that need to be stored in the db).
25
29
  */
26
- public getUsedPreTags(): PreTag[] {
27
- return Array.from(this.taggingIndexMap.entries()).map(([secret, index]) => ({
28
- secret: DirectionalAppTaggingSecret.fromString(secret),
29
- index,
30
+ public getUsedTaggingIndexRanges(): TaggingIndexRange[] {
31
+ return Array.from(this.taggingIndexMap.entries()).map(([secret, { lowestIndex, highestIndex }]) => ({
32
+ extendedSecret: ExtendedDirectionalAppTaggingSecret.fromString(secret),
33
+ lowestIndex,
34
+ highestIndex,
30
35
  }));
31
36
  }
32
37
  }
@@ -4,6 +4,7 @@ export { HashedValuesCache } from './hashed_values_cache.js';
4
4
  export { pickNotes } from './pick_notes.js';
5
5
  export type { NoteData, IMiscOracle, IUtilityExecutionOracle, IPrivateExecutionOracle } from './oracle/interfaces.js';
6
6
  export { MessageLoadOracleInputs } from './oracle/message_load_oracle_inputs.js';
7
+ export { MessageContextService } from '../messages/message_context_service.js';
7
8
  export { UtilityExecutionOracle } from './oracle/utility_execution_oracle.js';
8
9
  export { PrivateExecutionOracle } from './oracle/private_execution_oracle.js';
9
10
  export { Oracle } from './oracle/oracle.js';
@@ -4,12 +4,9 @@ import { EventSelector } from '@aztec/stdlib/abi';
4
4
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
5
  import { TxHash } from '@aztec/stdlib/tx';
6
6
 
7
- // TODO(#14617): should we compute this from constants? This value is aztec-nr specific.
8
- const MAX_EVENT_SERIALIZED_LEN = 11;
9
-
10
7
  /**
11
8
  * Intermediate struct used to perform batch event validation by PXE. The `utilityValidateAndStoreEnqueuedNotesAndEvents` oracle
12
- * expects for values of this type to be stored in a `CapsuleArray`.
9
+ * expects for values of this type to be stored in a `EphemeralArray`.
13
10
  */
14
11
  export class EventValidationRequest {
15
12
  constructor(
@@ -19,10 +16,9 @@ export class EventValidationRequest {
19
16
  public serializedEvent: Fr[],
20
17
  public eventCommitment: Fr,
21
18
  public txHash: TxHash,
22
- public recipient: AztecAddress,
23
19
  ) {}
24
20
 
25
- static fromFields(fields: Fr[] | FieldReader): EventValidationRequest {
21
+ static fromFields(fields: Fr[], maxEventSerializedLen: number): EventValidationRequest {
26
22
  const reader = FieldReader.asReader(fields);
27
23
 
28
24
  const contractAddress = AztecAddress.fromField(reader.readField());
@@ -30,13 +26,18 @@ export class EventValidationRequest {
30
26
 
31
27
  const randomness = reader.readField();
32
28
 
33
- const eventStorage = reader.readFieldArray(MAX_EVENT_SERIALIZED_LEN);
29
+ const eventStorage = reader.readFieldArray(maxEventSerializedLen);
34
30
  const eventLen = reader.readField().toNumber();
35
31
  const serializedEvent = eventStorage.slice(0, eventLen);
36
32
 
37
33
  const eventCommitment = reader.readField();
38
34
  const txHash = TxHash.fromField(reader.readField());
39
- const recipient = AztecAddress.fromField(reader.readField());
35
+
36
+ if (reader.remainingFields() !== 0) {
37
+ throw new Error(
38
+ `Error converting array of fields to EventValidationRequest: expected ${reader.cursor} fields but received ${fields.length} (maxEventSerializedLen=${maxEventSerializedLen}).`,
39
+ );
40
+ }
40
41
 
41
42
  return new EventValidationRequest(
42
43
  contractAddress,
@@ -45,7 +46,6 @@ export class EventValidationRequest {
45
46
  serializedEvent,
46
47
  eventCommitment,
47
48
  txHash,
48
- recipient,
49
49
  );
50
50
  }
51
51
  }
@@ -5,7 +5,7 @@ import { Tag } from '@aztec/stdlib/logs';
5
5
 
6
6
  /**
7
7
  * Intermediate struct used to perform batch log retrieval by PXE. The `utilityBulkRetrieveLogs` oracle expects values of this
8
- * type to be stored in a `CapsuleArray`.
8
+ * type to be stored in a `EphemeralArray`.
9
9
  */
10
10
  export class LogRetrievalRequest {
11
11
  constructor(
@@ -3,14 +3,11 @@ import { range } from '@aztec/foundation/array';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import type { TxHash } from '@aztec/stdlib/tx';
5
5
 
6
- import { MAX_NOTE_PACKED_LEN } from './note_validation_request.js';
7
-
8
- const MAX_PUBLIC_LOG_LEN_FOR_NOTE_COMPLETION = MAX_NOTE_PACKED_LEN;
9
- const MAX_LOG_CONTENT_LEN = Math.max(MAX_PUBLIC_LOG_LEN_FOR_NOTE_COMPLETION, PRIVATE_LOG_CIPHERTEXT_LEN);
6
+ const MAX_LOG_CONTENT_LEN = PRIVATE_LOG_CIPHERTEXT_LEN;
10
7
 
11
8
  /**
12
9
  * Intermediate struct used to perform batch log retrieval by PXE. The `utilityBulkRetrieveLogs` oracle stores values of this
13
- * type in a `CapsuleArray`.
10
+ * type in a `EphemeralArray`.
14
11
  */
15
12
  export class LogRetrievalResponse {
16
13
  constructor(
@@ -3,12 +3,9 @@ import { FieldReader } from '@aztec/foundation/serialize';
3
3
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import { TxHash } from '@aztec/stdlib/tx';
5
5
 
6
- // TODO(#14617): should we compute this from constants? This value is aztec-nr specific.
7
- export const MAX_NOTE_PACKED_LEN = 9;
8
-
9
6
  /**
10
7
  * Intermediate struct used to perform batch note validation by PXE. The `utilityValidateAndStoreEnqueuedNotesAndEvents` oracle
11
- * expects for values of this type to be stored in a `CapsuleArray`.
8
+ * expects for values of this type to be stored in a `EphemeralArray`.
12
9
  */
13
10
  export class NoteValidationRequest {
14
11
  constructor(
@@ -21,10 +18,9 @@ export class NoteValidationRequest {
21
18
  public noteHash: Fr,
22
19
  public nullifier: Fr,
23
20
  public txHash: TxHash,
24
- public recipient: AztecAddress,
25
21
  ) {}
26
22
 
27
- static fromFields(fields: Fr[] | FieldReader): NoteValidationRequest {
23
+ static fromFields(fields: Fr[], maxNotePackedLen: number): NoteValidationRequest {
28
24
  const reader = FieldReader.asReader(fields);
29
25
 
30
26
  const contractAddress = AztecAddress.fromField(reader.readField());
@@ -33,18 +29,17 @@ export class NoteValidationRequest {
33
29
  const randomness = reader.readField();
34
30
  const noteNonce = reader.readField();
35
31
 
36
- const contentStorage = reader.readFieldArray(MAX_NOTE_PACKED_LEN);
32
+ const contentStorage = reader.readFieldArray(maxNotePackedLen);
37
33
  const contentLen = reader.readField().toNumber();
38
34
  const content = contentStorage.slice(0, contentLen);
39
35
 
40
36
  const noteHash = reader.readField();
41
37
  const nullifier = reader.readField();
42
38
  const txHash = TxHash.fromField(reader.readField());
43
- const recipient = AztecAddress.fromField(reader.readField());
44
39
 
45
40
  if (reader.remainingFields() !== 0) {
46
41
  throw new Error(
47
- `Error converting array of fields to NoteValidationRequest. Hint: check that MAX_NOTE_PACKED_LEN is consistent with private_notes::MAX_NOTE_PACKED_LEN in Aztec-nr.`,
42
+ `Error converting array of fields to NoteValidationRequest: expected ${reader.cursor} fields but received ${fields.length} (maxNotePackedLen=${maxNotePackedLen}).`,
48
43
  );
49
44
  }
50
45
 
@@ -58,7 +53,6 @@ export class NoteValidationRequest {
58
53
  noteHash,
59
54
  nullifier,
60
55
  txHash,
61
- recipient,
62
56
  );
63
57
  }
64
58
  }