@aztec/pxe 0.0.1-commit.10bd49492 → 0.0.1-commit.11bf3dd6e

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 (187) hide show
  1. package/dest/bin/check_oracle_version.js +4 -4
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +6 -2
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  4. package/dest/block_synchronizer/block_synchronizer.js +19 -1
  5. package/dest/config/index.d.ts +1 -1
  6. package/dest/config/index.d.ts.map +1 -1
  7. package/dest/config/index.js +7 -14
  8. package/dest/contract_function_simulator/contract_function_simulator.d.ts +10 -5
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  10. package/dest/contract_function_simulator/contract_function_simulator.js +31 -8
  11. package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
  12. package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
  13. package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
  14. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -4
  15. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +3 -6
  17. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
  18. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
  19. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
  20. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -1
  21. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -4
  22. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +3 -6
  24. package/dest/contract_function_simulator/oracle/interfaces.d.ts +32 -20
  25. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +1 -1
  27. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +34 -39
  29. package/dest/contract_function_simulator/oracle/oracle.d.ts +50 -19
  30. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/oracle/oracle.js +178 -41
  32. package/dest/contract_function_simulator/oracle/private_execution.js +4 -2
  33. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +8 -20
  34. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +21 -25
  36. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +71 -43
  37. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +225 -95
  39. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  40. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/pick_notes.js +20 -3
  42. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
  43. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  44. package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
  45. package/dest/contract_logging.d.ts +9 -4
  46. package/dest/contract_logging.d.ts.map +1 -1
  47. package/dest/contract_logging.js +21 -6
  48. package/dest/contract_sync/contract_sync_service.d.ts +6 -5
  49. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  50. package/dest/contract_sync/contract_sync_service.js +62 -43
  51. package/dest/contract_sync/helpers.d.ts +2 -3
  52. package/dest/contract_sync/helpers.d.ts.map +1 -1
  53. package/dest/contract_sync/helpers.js +7 -2
  54. package/dest/debug/pxe_debug_utils.d.ts +3 -3
  55. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  56. package/dest/entrypoints/client/bundle/index.d.ts +1 -2
  57. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  58. package/dest/entrypoints/client/bundle/index.js +0 -1
  59. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  60. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  61. package/dest/entrypoints/client/bundle/utils.js +2 -2
  62. package/dest/entrypoints/client/lazy/index.d.ts +1 -2
  63. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  64. package/dest/entrypoints/client/lazy/index.js +0 -1
  65. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  66. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  67. package/dest/entrypoints/client/lazy/utils.js +2 -2
  68. package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
  69. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  70. package/dest/entrypoints/pxe_creation_options.js +3 -1
  71. package/dest/entrypoints/server/index.d.ts +2 -3
  72. package/dest/entrypoints/server/index.d.ts.map +1 -1
  73. package/dest/entrypoints/server/index.js +1 -2
  74. package/dest/entrypoints/server/utils.d.ts +2 -2
  75. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  76. package/dest/entrypoints/server/utils.js +2 -2
  77. package/dest/events/event_service.d.ts +3 -2
  78. package/dest/events/event_service.d.ts.map +1 -1
  79. package/dest/events/event_service.js +16 -4
  80. package/dest/events/private_event_filter_validator.d.ts +3 -2
  81. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  82. package/dest/events/private_event_filter_validator.js +15 -0
  83. package/dest/logs/log_service.d.ts +7 -8
  84. package/dest/logs/log_service.d.ts.map +1 -1
  85. package/dest/logs/log_service.js +27 -37
  86. package/dest/messages/message_context_service.d.ts +3 -3
  87. package/dest/messages/message_context_service.d.ts.map +1 -1
  88. package/dest/messages/message_context_service.js +3 -3
  89. package/dest/notes/note_service.d.ts +4 -5
  90. package/dest/notes/note_service.d.ts.map +1 -1
  91. package/dest/notes/note_service.js +14 -5
  92. package/dest/notes_filter.d.ts +2 -3
  93. package/dest/notes_filter.d.ts.map +1 -1
  94. package/dest/oracle_version.d.ts +4 -3
  95. package/dest/oracle_version.d.ts.map +1 -1
  96. package/dest/oracle_version.js +20 -10
  97. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  98. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  99. package/dest/private_kernel/private_kernel_execution_prover.js +4 -7
  100. package/dest/private_kernel/private_kernel_oracle.d.ts +5 -5
  101. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  102. package/dest/private_kernel/private_kernel_oracle.js +12 -15
  103. package/dest/pxe.d.ts +9 -7
  104. package/dest/pxe.d.ts.map +1 -1
  105. package/dest/pxe.js +35 -18
  106. package/dest/storage/anchor_block_store/anchor_block_store.js +1 -1
  107. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  108. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  109. package/dest/storage/capsule_store/capsule_service.js +50 -0
  110. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  111. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  112. package/dest/storage/capsule_store/capsule_store.js +36 -28
  113. package/dest/storage/capsule_store/index.d.ts +2 -1
  114. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  115. package/dest/storage/capsule_store/index.js +1 -0
  116. package/dest/storage/contract_store/contract_store.d.ts +1 -1
  117. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  118. package/dest/storage/contract_store/contract_store.js +4 -2
  119. package/dest/storage/metadata.d.ts +1 -1
  120. package/dest/storage/metadata.js +1 -1
  121. package/dest/storage/note_store/note_store.d.ts +1 -1
  122. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  123. package/dest/storage/note_store/note_store.js +2 -2
  124. package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
  125. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  126. package/dest/storage/private_event_store/private_event_store.js +3 -0
  127. package/dest/storage/private_event_store/stored_private_event.js +1 -1
  128. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +2 -2
  129. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  130. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +2 -16
  131. package/package.json +16 -16
  132. package/src/bin/check_oracle_version.ts +4 -4
  133. package/src/block_synchronizer/block_synchronizer.ts +22 -2
  134. package/src/config/index.ts +2 -8
  135. package/src/contract_function_simulator/contract_function_simulator.ts +43 -12
  136. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  137. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -4
  138. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
  139. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -1
  140. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -4
  141. package/src/contract_function_simulator/oracle/interfaces.ts +47 -18
  142. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +84 -57
  143. package/src/contract_function_simulator/oracle/oracle.ts +243 -36
  144. package/src/contract_function_simulator/oracle/private_execution.ts +2 -2
  145. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +28 -30
  146. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +370 -123
  147. package/src/contract_function_simulator/pick_notes.ts +22 -3
  148. package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
  149. package/src/contract_logging.ts +18 -5
  150. package/src/contract_sync/contract_sync_service.ts +99 -75
  151. package/src/contract_sync/helpers.ts +4 -4
  152. package/src/debug/pxe_debug_utils.ts +3 -3
  153. package/src/entrypoints/client/bundle/index.ts +0 -1
  154. package/src/entrypoints/client/bundle/utils.ts +2 -3
  155. package/src/entrypoints/client/lazy/index.ts +0 -1
  156. package/src/entrypoints/client/lazy/utils.ts +2 -3
  157. package/src/entrypoints/pxe_creation_options.ts +7 -0
  158. package/src/entrypoints/server/index.ts +1 -2
  159. package/src/entrypoints/server/utils.ts +2 -3
  160. package/src/events/event_service.ts +17 -4
  161. package/src/events/private_event_filter_validator.ts +21 -1
  162. package/src/logs/log_service.ts +57 -78
  163. package/src/messages/message_context_service.ts +3 -4
  164. package/src/notes/note_service.ts +18 -8
  165. package/src/notes_filter.ts +1 -3
  166. package/src/oracle_version.ts +20 -10
  167. package/src/private_kernel/private_kernel_execution_prover.ts +4 -9
  168. package/src/private_kernel/private_kernel_oracle.ts +14 -14
  169. package/src/pxe.ts +62 -24
  170. package/src/storage/anchor_block_store/anchor_block_store.ts +1 -1
  171. package/src/storage/capsule_store/capsule_service.ts +90 -0
  172. package/src/storage/capsule_store/capsule_store.ts +44 -26
  173. package/src/storage/capsule_store/index.ts +1 -0
  174. package/src/storage/contract_store/contract_store.ts +8 -6
  175. package/src/storage/metadata.ts +1 -1
  176. package/src/storage/note_store/note_store.ts +2 -5
  177. package/src/storage/private_event_store/private_event_store.ts +4 -0
  178. package/src/storage/private_event_store/stored_private_event.ts +1 -1
  179. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +5 -15
  180. package/dest/access_scopes.d.ts +0 -9
  181. package/dest/access_scopes.d.ts.map +0 -1
  182. package/dest/access_scopes.js +0 -6
  183. package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts +0 -16
  184. package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts.map +0 -1
  185. package/dest/contract_function_simulator/noir-structs/message_tx_context.js +0 -57
  186. package/src/access_scopes.ts +0 -9
  187. package/src/contract_function_simulator/noir-structs/message_tx_context.ts +0 -55
@@ -1,5 +1,6 @@
1
1
  import { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
3
+ import { SerialQueue } from '@aztec/foundation/queue';
3
4
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
4
5
  import type { L2TipsKVStore } from '@aztec/kv-store/stores';
5
6
  import { BlockHash, L2BlockStream, type L2BlockStreamEvent, type L2BlockStreamEventHandler } from '@aztec/stdlib/block';
@@ -20,6 +21,7 @@ import type { PrivateEventStore } from '../storage/private_event_store/private_e
20
21
  export class BlockSynchronizer implements L2BlockStreamEventHandler {
21
22
  private log: Logger;
22
23
  private isSyncing: Promise<void> | undefined;
24
+ private readonly eventQueue = new SerialQueue();
23
25
  protected readonly blockStream: L2BlockStream;
24
26
 
25
27
  constructor(
@@ -35,6 +37,7 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
35
37
  ) {
36
38
  this.log = createLogger('pxe:block_synchronizer', bindings);
37
39
  this.blockStream = this.createBlockStream(config);
40
+ this.eventQueue.start();
38
41
  }
39
42
 
40
43
  protected createBlockStream(config: Partial<BlockSynchronizerConfig>): L2BlockStream {
@@ -52,8 +55,12 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
52
55
  );
53
56
  }
54
57
 
55
- /** Handle events emitted by the block stream. */
56
- public async handleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void> {
58
+ /** Handle events emitted by the block stream. Serialized to prevent concurrent mutations to anchor state. */
59
+ public handleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void> {
60
+ return this.eventQueue.put(() => this.doHandleBlockStreamEvent(event));
61
+ }
62
+
63
+ private async doHandleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void> {
57
64
  await this.l2TipsStore.handleBlockStreamEvent(event);
58
65
 
59
66
  switch (event.type) {
@@ -77,6 +84,8 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
77
84
  const blockHeader = await this.node.getBlockHeader(BlockNumber(event.block.number));
78
85
  if (blockHeader) {
79
86
  await this.updateAnchorBlockHeader(blockHeader);
87
+ } else {
88
+ this.log.warn(`Block header not found for proven block ${event.block.number}, skipping anchor update`);
80
89
  }
81
90
  }
82
91
  break;
@@ -86,6 +95,8 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
86
95
  const blockHeader = await this.node.getBlockHeader(BlockNumber(event.block.number));
87
96
  if (blockHeader) {
88
97
  await this.updateAnchorBlockHeader(blockHeader);
98
+ } else {
99
+ this.log.warn(`Block header not found for finalized block ${event.block.number}, skipping anchor update`);
89
100
  }
90
101
  }
91
102
  break;
@@ -152,6 +163,8 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
152
163
  }
153
164
 
154
165
  this.log.debug(`Syncing PXE with the node`);
166
+ // Capture the promise locally so we always await the exact promise we created, even if this.isSyncing is modified
167
+ // between assignment and await (e.g. due to future refactors introducing a yield point).
155
168
  const isSyncing = this.doSync();
156
169
  this.isSyncing = isSyncing;
157
170
  try {
@@ -161,6 +174,13 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
161
174
  }
162
175
  }
163
176
 
177
+ /** Stops the block synchronizer, waiting for any in-progress sync and queued events to complete. */
178
+ public async stop() {
179
+ await this.isSyncing;
180
+ await this.blockStream.stop();
181
+ await this.eventQueue.end();
182
+ }
183
+
164
184
  private async doSync() {
165
185
  let currentHeader;
166
186
 
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  type ConfigMappingsType,
3
3
  booleanConfigHelper,
4
+ enumConfigHelper,
4
5
  getConfigFromMappings,
5
6
  numberConfigHelper,
6
7
  parseBooleanEnv,
@@ -58,14 +59,7 @@ export const pxeConfigMappings: ConfigMappingsType<PXEConfig> = {
58
59
  syncChainTip: {
59
60
  env: 'PXE_SYNC_CHAIN_TIP',
60
61
  description: 'Which chain tip to sync to (proposed, checkpointed, proven, finalized)',
61
- defaultValue: 'proposed',
62
- parseEnv: (val: string) => {
63
- const allowedValues = ['proposed', 'checkpointed', 'proven', 'finalized'];
64
- if (allowedValues.includes(val)) {
65
- return val;
66
- }
67
- throw new Error(`Invalid value for PXE_SYNC_CHAIN_TIP: ${val}. Allowed values are: ${allowedValues.join(', ')}`);
68
- },
62
+ ...enumConfigHelper(['proposed', 'checkpointed', 'proven', 'finalized'], 'proposed'),
69
63
  },
70
64
  };
71
65
 
@@ -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,10 +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';
92
93
  import type { MessageContextService } from '../messages/message_context_service.js';
93
94
  import type { AddressStore } from '../storage/address_store/address_store.js';
95
+ import { CapsuleService } from '../storage/capsule_store/capsule_service.js';
94
96
  import type { CapsuleStore } from '../storage/capsule_store/capsule_store.js';
95
97
  import type { ContractStore } from '../storage/contract_store/contract_store.js';
96
98
  import type { NoteStore } from '../storage/note_store/note_store.js';
@@ -120,7 +122,7 @@ export type ContractSimulatorRunOpts = {
120
122
  /** The address used as a tagging sender when emitting private logs. */
121
123
  senderForTags?: AztecAddress;
122
124
  /** The accounts whose notes we can access in this call. */
123
- scopes: AccessScopes;
125
+ scopes: AztecAddress[];
124
126
  /** The job ID for staged writes. */
125
127
  jobId: string;
126
128
  };
@@ -132,6 +134,7 @@ export type ContractFunctionSimulatorArgs = {
132
134
  keyStore: KeyStore;
133
135
  addressStore: AddressStore;
134
136
  aztecNode: AztecNode;
137
+ l2TipsStore: L2TipsProvider;
135
138
  senderTaggingStore: SenderTaggingStore;
136
139
  recipientTaggingStore: RecipientTaggingStore;
137
140
  senderAddressBookStore: SenderAddressBookStore;
@@ -152,6 +155,7 @@ export class ContractFunctionSimulator {
152
155
  private readonly keyStore: KeyStore;
153
156
  private readonly addressStore: AddressStore;
154
157
  private readonly aztecNode: AztecNode;
158
+ private readonly l2TipsStore: L2TipsProvider;
155
159
  private readonly senderTaggingStore: SenderTaggingStore;
156
160
  private readonly recipientTaggingStore: RecipientTaggingStore;
157
161
  private readonly senderAddressBookStore: SenderAddressBookStore;
@@ -167,6 +171,7 @@ export class ContractFunctionSimulator {
167
171
  this.keyStore = args.keyStore;
168
172
  this.addressStore = args.addressStore;
169
173
  this.aztecNode = args.aztecNode;
174
+ this.l2TipsStore = args.l2TipsStore;
170
175
  this.senderTaggingStore = args.senderTaggingStore;
171
176
  this.recipientTaggingStore = args.recipientTaggingStore;
172
177
  this.senderAddressBookStore = args.senderAddressBookStore;
@@ -203,7 +208,7 @@ export class ContractFunctionSimulator {
203
208
  }
204
209
 
205
210
  if (request.origin !== contractAddress) {
206
- this.log.warn(
211
+ throw new Error(
207
212
  `Request origin does not match contract address in simulation. Request origin: ${request.origin}, contract address: ${contractAddress}`,
208
213
  );
209
214
  }
@@ -243,7 +248,7 @@ export class ContractFunctionSimulator {
243
248
  senderTaggingStore: this.senderTaggingStore,
244
249
  recipientTaggingStore: this.recipientTaggingStore,
245
250
  senderAddressBookStore: this.senderAddressBookStore,
246
- capsuleStore: this.capsuleStore,
251
+ capsuleService: new CapsuleService(this.capsuleStore, scopes),
247
252
  privateEventStore: this.privateEventStore,
248
253
  messageContextService: this.messageContextService,
249
254
  contractSyncService: this.contractSyncService,
@@ -253,6 +258,7 @@ export class ContractFunctionSimulator {
253
258
  scopes,
254
259
  senderForTags,
255
260
  simulator: this.simulator,
261
+ l2TipsStore: this.l2TipsStore,
256
262
  });
257
263
 
258
264
  const setupTime = simulatorSetupTimer.ms();
@@ -282,7 +288,7 @@ export class ContractFunctionSimulator {
282
288
  );
283
289
  const publicFunctionsCalldata = await Promise.all(
284
290
  publicCallRequests.map(async r => {
285
- const calldata = await privateExecutionOracle.loadFromExecutionCache(r.calldataHash);
291
+ const calldata = await privateExecutionOracle.getHashPreimage(r.calldataHash);
286
292
  return new HashedValues(calldata, r.calldataHash);
287
293
  }),
288
294
  );
@@ -317,9 +323,9 @@ export class ContractFunctionSimulator {
317
323
  call: FunctionCall,
318
324
  authwits: AuthWitness[],
319
325
  anchorBlockHeader: BlockHeader,
320
- scopes: AccessScopes,
326
+ scopes: AztecAddress[],
321
327
  jobId: string,
322
- ): Promise<Fr[]> {
328
+ ): Promise<{ result: Fr[]; offchainEffects: OffchainEffect[] }> {
323
329
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
324
330
 
325
331
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
@@ -338,9 +344,11 @@ export class ContractFunctionSimulator {
338
344
  aztecNode: this.aztecNode,
339
345
  recipientTaggingStore: this.recipientTaggingStore,
340
346
  senderAddressBookStore: this.senderAddressBookStore,
341
- capsuleStore: this.capsuleStore,
347
+ capsuleService: new CapsuleService(this.capsuleStore, scopes),
342
348
  privateEventStore: this.privateEventStore,
343
349
  messageContextService: this.messageContextService,
350
+ contractSyncService: this.contractSyncService,
351
+ l2TipsStore: this.l2TipsStore,
344
352
  jobId,
345
353
  scopes,
346
354
  });
@@ -368,7 +376,10 @@ export class ContractFunctionSimulator {
368
376
  });
369
377
 
370
378
  this.log.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
371
- return witnessMapToFields(acirExecutionResult.returnWitness);
379
+ return {
380
+ result: witnessMapToFields(acirExecutionResult.returnWitness),
381
+ offchainEffects: oracle.getOffchainEffects(),
382
+ };
372
383
  } catch (err) {
373
384
  throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during private execution'));
374
385
  }
@@ -438,14 +449,34 @@ export async function generateSimulatedProvingResult(
438
449
 
439
450
  let publicTeardownCallRequest;
440
451
 
452
+ // We set expiration timestamp to anchor_block_timestamp + MAX_TX_LIFETIME (24h) just like kernels do
453
+ let expirationTimestamp =
454
+ privateExecutionResult.entrypoint.publicInputs.anchorBlockHeader.globalVariables.timestamp +
455
+ BigInt(MAX_TX_LIFETIME);
456
+
457
+ let feePayer = AztecAddress.zero();
458
+
441
459
  const executions = [privateExecutionResult.entrypoint];
442
460
 
443
461
  while (executions.length !== 0) {
444
462
  const execution = executions.shift()!;
445
463
  executions.unshift(...execution!.nestedExecutionResults);
446
464
 
465
+ // Just like kernels we overwrite the default value if the call sets it.
466
+ const callExpirationTimestamp = execution.publicInputs.expirationTimestamp;
467
+ if (callExpirationTimestamp !== 0n && callExpirationTimestamp < expirationTimestamp) {
468
+ expirationTimestamp = callExpirationTimestamp;
469
+ }
470
+
447
471
  const { contractAddress } = execution.publicInputs.callContext;
448
472
 
473
+ if (execution.publicInputs.isFeePayer) {
474
+ if (!feePayer.isZero()) {
475
+ throw new Error('Multiple fee payers found in private execution result');
476
+ }
477
+ feePayer = contractAddress;
478
+ }
479
+
449
480
  scopedNoteHashes.push(
450
481
  ...execution.publicInputs.noteHashes
451
482
  .getActiveItems()
@@ -666,8 +697,8 @@ export async function generateSimulatedProvingResult(
666
697
  daGas: TX_DA_GAS_OVERHEAD,
667
698
  }),
668
699
  ),
669
- /*feePayer=*/ AztecAddress.zero(),
670
- /*expirationTimestamp=*/ 0n,
700
+ /*feePayer=*/ feePayer,
701
+ /*expirationTimestamp=*/ expirationTimestamp,
671
702
  hasPublicCalls ? inputsForPublic : undefined,
672
703
  !hasPublicCalls ? inputsForRollup : undefined,
673
704
  );
@@ -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
+ }
@@ -6,7 +6,7 @@ import { TxHash } from '@aztec/stdlib/tx';
6
6
 
7
7
  /**
8
8
  * Intermediate struct used to perform batch event validation by PXE. The `utilityValidateAndStoreEnqueuedNotesAndEvents` oracle
9
- * 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`.
10
10
  */
11
11
  export class EventValidationRequest {
12
12
  constructor(
@@ -16,7 +16,6 @@ export class EventValidationRequest {
16
16
  public serializedEvent: Fr[],
17
17
  public eventCommitment: Fr,
18
18
  public txHash: TxHash,
19
- public recipient: AztecAddress,
20
19
  ) {}
21
20
 
22
21
  static fromFields(fields: Fr[], maxEventSerializedLen: number): EventValidationRequest {
@@ -33,7 +32,6 @@ export class EventValidationRequest {
33
32
 
34
33
  const eventCommitment = reader.readField();
35
34
  const txHash = TxHash.fromField(reader.readField());
36
- const recipient = AztecAddress.fromField(reader.readField());
37
35
 
38
36
  if (reader.remainingFields() !== 0) {
39
37
  throw new Error(
@@ -48,7 +46,6 @@ export class EventValidationRequest {
48
46
  serializedEvent,
49
47
  eventCommitment,
50
48
  txHash,
51
- recipient,
52
49
  );
53
50
  }
54
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(
@@ -7,7 +7,7 @@ const MAX_LOG_CONTENT_LEN = PRIVATE_LOG_CIPHERTEXT_LEN;
7
7
 
8
8
  /**
9
9
  * Intermediate struct used to perform batch log retrieval by PXE. The `utilityBulkRetrieveLogs` oracle stores values of this
10
- * type in a `CapsuleArray`.
10
+ * type in a `EphemeralArray`.
11
11
  */
12
12
  export class LogRetrievalResponse {
13
13
  constructor(
@@ -5,7 +5,7 @@ import { TxHash } from '@aztec/stdlib/tx';
5
5
 
6
6
  /**
7
7
  * Intermediate struct used to perform batch note validation by PXE. The `utilityValidateAndStoreEnqueuedNotesAndEvents` oracle
8
- * 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`.
9
9
  */
10
10
  export class NoteValidationRequest {
11
11
  constructor(
@@ -18,7 +18,6 @@ export class NoteValidationRequest {
18
18
  public noteHash: Fr,
19
19
  public nullifier: Fr,
20
20
  public txHash: TxHash,
21
- public recipient: AztecAddress,
22
21
  ) {}
23
22
 
24
23
  static fromFields(fields: Fr[], maxNotePackedLen: number): NoteValidationRequest {
@@ -37,7 +36,6 @@ export class NoteValidationRequest {
37
36
  const noteHash = reader.readField();
38
37
  const nullifier = reader.readField();
39
38
  const txHash = TxHash.fromField(reader.readField());
40
- const recipient = AztecAddress.fromField(reader.readField());
41
39
 
42
40
  if (reader.remainingFields() !== 0) {
43
41
  throw new Error(
@@ -55,7 +53,6 @@ export class NoteValidationRequest {
55
53
  noteHash,
56
54
  nullifier,
57
55
  txHash,
58
- recipient,
59
56
  );
60
57
  }
61
58
  }
@@ -54,7 +54,7 @@ export interface IMiscOracle {
54
54
  isMisc: true;
55
55
 
56
56
  getRandomField(): Fr;
57
- assertCompatibleOracleVersion(version: number): void;
57
+ assertCompatibleOracleVersion(major: number, minor: number): void;
58
58
  log(level: number, message: string, fields: Fr[]): Promise<void>;
59
59
  }
60
60
 
@@ -86,7 +86,7 @@ export interface IUtilityExecutionOracle {
86
86
  nullifier: Fr,
87
87
  ): Promise<NullifierMembershipWitness | undefined>;
88
88
  getBlockHeader(blockNumber: BlockNumber): Promise<BlockHeader | undefined>;
89
- tryGetPublicKeysAndPartialAddress(
89
+ getPublicKeysAndPartialAddress(
90
90
  account: AztecAddress,
91
91
  ): Promise<{ publicKeys: PublicKeys; partialAddress: PartialAddress } | undefined>;
92
92
  getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined>;
@@ -107,42 +107,72 @@ export interface IUtilityExecutionOracle {
107
107
  offset: number,
108
108
  status: NoteStatus,
109
109
  ): Promise<NoteData[]>;
110
- checkNullifierExists(innerNullifier: Fr): Promise<boolean>;
110
+ doesNullifierExist(innerNullifier: Fr): Promise<boolean>;
111
111
  getL1ToL2MembershipWitness(
112
112
  contractAddress: AztecAddress,
113
113
  messageHash: Fr,
114
114
  secret: Fr,
115
115
  ): Promise<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>>;
116
- storageRead(
116
+ getFromPublicStorage(
117
117
  anchorBlockHash: BlockHash,
118
118
  contractAddress: AztecAddress,
119
119
  startStorageSlot: Fr,
120
120
  numberOfElements: number,
121
121
  ): Promise<Fr[]>;
122
- fetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr): Promise<void>;
122
+ getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr, scope: AztecAddress): Promise<void>;
123
+ getPendingTaggedLogsV2(scope: AztecAddress): Promise<Fr>;
123
124
  validateAndStoreEnqueuedNotesAndEvents(
124
125
  contractAddress: AztecAddress,
125
126
  noteValidationRequestsArrayBaseSlot: Fr,
126
127
  eventValidationRequestsArrayBaseSlot: Fr,
127
128
  maxNotePackedLen: number,
128
129
  maxEventSerializedLen: number,
130
+ scope: AztecAddress,
129
131
  ): Promise<void>;
130
- bulkRetrieveLogs(
132
+ getLogsByTag(
131
133
  contractAddress: AztecAddress,
132
134
  logRetrievalRequestsArrayBaseSlot: Fr,
133
135
  logRetrievalResponsesArrayBaseSlot: Fr,
136
+ scope: AztecAddress,
134
137
  ): Promise<void>;
135
- utilityResolveMessageContexts(
138
+ validateAndStoreEnqueuedNotesAndEventsV2(
139
+ noteValidationRequestsArrayBaseSlot: Fr,
140
+ eventValidationRequestsArrayBaseSlot: Fr,
141
+ maxNotePackedLen: number,
142
+ maxEventSerializedLen: number,
143
+ scope: AztecAddress,
144
+ ): Promise<void>;
145
+ getLogsByTagV2(requestArrayBaseSlot: Fr): Promise<Fr>;
146
+ getMessageContextsByTxHashV2(requestArrayBaseSlot: Fr): Promise<Fr>;
147
+ getMessageContextsByTxHash(
136
148
  contractAddress: AztecAddress,
137
149
  messageContextRequestsArrayBaseSlot: Fr,
138
150
  messageContextResponsesArrayBaseSlot: Fr,
151
+ scope: AztecAddress,
139
152
  ): Promise<void>;
140
- storeCapsule(contractAddress: AztecAddress, key: Fr, capsule: Fr[]): Promise<void>;
141
- loadCapsule(contractAddress: AztecAddress, key: Fr): Promise<Fr[] | null>;
142
- deleteCapsule(contractAddress: AztecAddress, key: Fr): Promise<void>;
143
- copyCapsule(contractAddress: AztecAddress, srcKey: Fr, dstKey: Fr, numEntries: number): Promise<void>;
144
- aes128Decrypt(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer>;
145
- getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point>;
153
+ setCapsule(contractAddress: AztecAddress, key: Fr, capsule: Fr[], scope: AztecAddress): void;
154
+ getCapsule(contractAddress: AztecAddress, key: Fr, scope: AztecAddress): Promise<Fr[] | null>;
155
+ deleteCapsule(contractAddress: AztecAddress, key: Fr, scope: AztecAddress): void;
156
+ copyCapsule(
157
+ contractAddress: AztecAddress,
158
+ srcKey: Fr,
159
+ dstKey: Fr,
160
+ numEntries: number,
161
+ scope: AztecAddress,
162
+ ): Promise<void>;
163
+ decryptAes128(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer>;
164
+ getSharedSecret(address: AztecAddress, ephPk: Point, contractAddress: AztecAddress): Promise<Fr>;
165
+ setContractSyncCacheInvalid(contractAddress: AztecAddress, scopes: AztecAddress[]): void;
166
+ emitOffchainEffect(data: Fr[]): Promise<void>;
167
+
168
+ // Ephemeral array methods
169
+ pushEphemeral(slot: Fr, elements: Fr[]): number;
170
+ popEphemeral(slot: Fr): Fr[];
171
+ getEphemeral(slot: Fr, index: number): Fr[];
172
+ setEphemeral(slot: Fr, index: number, elements: Fr[]): void;
173
+ getEphemeralLen(slot: Fr): number;
174
+ removeEphemeral(slot: Fr, index: number): void;
175
+ clearEphemeral(slot: Fr): void;
146
176
  }
147
177
 
148
178
  /**
@@ -152,8 +182,8 @@ export interface IUtilityExecutionOracle {
152
182
  export interface IPrivateExecutionOracle {
153
183
  isPrivate: true;
154
184
 
155
- storeInExecutionCache(values: Fr[], hash: Fr): void;
156
- loadFromExecutionCache(hash: Fr): Promise<Fr[]>;
185
+ setHashPreimage(values: Fr[], hash: Fr): void;
186
+ getHashPreimage(hash: Fr): Promise<Fr[]>;
157
187
  notifyCreatedNote(
158
188
  owner: AztecAddress,
159
189
  storageSlot: Fr,
@@ -174,11 +204,10 @@ export interface IPrivateExecutionOracle {
174
204
  sideEffectCounter: number,
175
205
  isStaticCall: boolean,
176
206
  ): Promise<{ endSideEffectCounter: Fr; returnsHash: Fr }>;
177
- validatePublicCalldata(calldataHash: Fr): Promise<void>;
207
+ assertValidPublicCalldata(calldataHash: Fr): Promise<void>;
178
208
  notifyRevertiblePhaseStart(minRevertibleSideEffectCounter: number): Promise<void>;
179
- inRevertiblePhase(sideEffectCounter: number): Promise<boolean>;
209
+ isExecutionInRevertiblePhase(sideEffectCounter: number): Promise<boolean>;
180
210
  getSenderForTags(): Promise<AztecAddress | undefined>;
181
211
  setSenderForTags(senderForTags: AztecAddress): Promise<void>;
182
212
  getNextAppTagAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<Tag>;
183
- emitOffchainEffect(data: Fr[]): Promise<void>;
184
213
  }