@aztec/pxe 0.0.1-commit.9ef841308 → 0.0.1-commit.a89ec08

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 (146) hide show
  1. package/dest/bin/check_oracle_version.js +4 -4
  2. package/dest/config/index.d.ts +2 -2
  3. package/dest/config/index.d.ts.map +1 -1
  4. package/dest/config/index.js +1 -1
  5. package/dest/config/package_info.js +1 -1
  6. package/dest/contract_function_simulator/contract_function_simulator.d.ts +6 -4
  7. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  8. package/dest/contract_function_simulator/contract_function_simulator.js +7 -3
  9. package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
  10. package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
  11. package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
  12. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +1 -1
  13. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
  14. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
  15. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
  16. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
  17. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -1
  18. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -1
  19. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
  20. package/dest/contract_function_simulator/oracle/interfaces.d.ts +13 -2
  21. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +1 -1
  23. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -1
  24. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +10 -1
  25. package/dest/contract_function_simulator/oracle/oracle.d.ts +13 -2
  26. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  27. package/dest/contract_function_simulator/oracle/oracle.js +98 -3
  28. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +2 -3
  29. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  30. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +12 -2
  31. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +28 -13
  32. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +104 -34
  34. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  35. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/pick_notes.js +14 -3
  37. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
  38. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  39. package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
  40. package/dest/contract_sync/contract_sync_service.d.ts +4 -6
  41. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  42. package/dest/contract_sync/contract_sync_service.js +38 -46
  43. package/dest/contract_sync/helpers.d.ts +2 -3
  44. package/dest/contract_sync/helpers.d.ts.map +1 -1
  45. package/dest/debug/pxe_debug_utils.d.ts +3 -3
  46. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  47. package/dest/entrypoints/client/bundle/index.d.ts +1 -2
  48. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  49. package/dest/entrypoints/client/bundle/index.js +0 -1
  50. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  51. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  52. package/dest/entrypoints/client/bundle/utils.js +2 -2
  53. package/dest/entrypoints/client/lazy/index.d.ts +1 -2
  54. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  55. package/dest/entrypoints/client/lazy/index.js +0 -1
  56. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  57. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  58. package/dest/entrypoints/client/lazy/utils.js +2 -2
  59. package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
  60. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  61. package/dest/entrypoints/pxe_creation_options.js +3 -1
  62. package/dest/entrypoints/server/index.d.ts +2 -3
  63. package/dest/entrypoints/server/index.d.ts.map +1 -1
  64. package/dest/entrypoints/server/index.js +1 -2
  65. package/dest/entrypoints/server/utils.d.ts +2 -2
  66. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  67. package/dest/entrypoints/server/utils.js +2 -2
  68. package/dest/events/private_event_filter_validator.d.ts +3 -2
  69. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  70. package/dest/events/private_event_filter_validator.js +15 -0
  71. package/dest/logs/log_service.d.ts +6 -6
  72. package/dest/logs/log_service.d.ts.map +1 -1
  73. package/dest/logs/log_service.js +15 -21
  74. package/dest/notes/note_service.d.ts +3 -4
  75. package/dest/notes/note_service.d.ts.map +1 -1
  76. package/dest/notes_filter.d.ts +2 -3
  77. package/dest/notes_filter.d.ts.map +1 -1
  78. package/dest/oracle_version.d.ts +4 -3
  79. package/dest/oracle_version.d.ts.map +1 -1
  80. package/dest/oracle_version.js +20 -10
  81. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  82. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  83. package/dest/private_kernel/private_kernel_execution_prover.js +4 -7
  84. package/dest/pxe.d.ts +6 -7
  85. package/dest/pxe.d.ts.map +1 -1
  86. package/dest/pxe.js +15 -12
  87. package/dest/storage/anchor_block_store/anchor_block_store.js +1 -1
  88. package/dest/storage/capsule_store/capsule_service.d.ts +2 -3
  89. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -1
  90. package/dest/storage/capsule_store/capsule_service.js +1 -1
  91. package/dest/storage/capsule_store/capsule_store.d.ts +1 -1
  92. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  93. package/dest/storage/capsule_store/capsule_store.js +8 -5
  94. package/dest/storage/contract_store/contract_store.d.ts +1 -1
  95. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  96. package/dest/storage/contract_store/contract_store.js +4 -2
  97. package/dest/storage/note_store/note_store.d.ts +1 -1
  98. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  99. package/dest/storage/note_store/note_store.js +2 -2
  100. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +2 -2
  101. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  102. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +1 -15
  103. package/package.json +16 -16
  104. package/src/bin/check_oracle_version.ts +4 -4
  105. package/src/config/index.ts +1 -1
  106. package/src/config/package_info.ts +1 -1
  107. package/src/contract_function_simulator/contract_function_simulator.ts +10 -6
  108. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  109. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  110. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
  111. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -1
  112. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
  113. package/src/contract_function_simulator/oracle/interfaces.ts +20 -1
  114. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +7 -1
  115. package/src/contract_function_simulator/oracle/oracle.ts +143 -3
  116. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +14 -4
  117. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +169 -64
  118. package/src/contract_function_simulator/pick_notes.ts +14 -3
  119. package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
  120. package/src/contract_sync/contract_sync_service.ts +64 -80
  121. package/src/contract_sync/helpers.ts +2 -3
  122. package/src/debug/pxe_debug_utils.ts +3 -3
  123. package/src/entrypoints/client/bundle/index.ts +0 -1
  124. package/src/entrypoints/client/bundle/utils.ts +2 -3
  125. package/src/entrypoints/client/lazy/index.ts +0 -1
  126. package/src/entrypoints/client/lazy/utils.ts +2 -3
  127. package/src/entrypoints/pxe_creation_options.ts +7 -0
  128. package/src/entrypoints/server/index.ts +1 -2
  129. package/src/entrypoints/server/utils.ts +2 -3
  130. package/src/events/private_event_filter_validator.ts +21 -1
  131. package/src/logs/log_service.ts +24 -50
  132. package/src/notes/note_service.ts +2 -3
  133. package/src/notes_filter.ts +1 -3
  134. package/src/oracle_version.ts +20 -10
  135. package/src/private_kernel/private_kernel_execution_prover.ts +4 -9
  136. package/src/pxe.ts +21 -16
  137. package/src/storage/anchor_block_store/anchor_block_store.ts +1 -1
  138. package/src/storage/capsule_store/capsule_service.ts +5 -6
  139. package/src/storage/capsule_store/capsule_store.ts +15 -5
  140. package/src/storage/contract_store/contract_store.ts +8 -6
  141. package/src/storage/note_store/note_store.ts +2 -5
  142. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +2 -14
  143. package/dest/access_scopes.d.ts +0 -9
  144. package/dest/access_scopes.d.ts.map +0 -1
  145. package/dest/access_scopes.js +0 -6
  146. package/src/access_scopes.ts +0 -9
@@ -9,7 +9,7 @@ import type { KeyStore } from '@aztec/key-store';
9
9
  import { isProtocolContract } from '@aztec/protocol-contracts';
10
10
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
11
11
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
12
- import { BlockHash } from '@aztec/stdlib/block';
12
+ import { BlockHash, type L2TipsProvider } from '@aztec/stdlib/block';
13
13
  import type { CompleteAddress, ContractInstance, PartialAddress } from '@aztec/stdlib/contract';
14
14
  import { siloNullifier } from '@aztec/stdlib/hash';
15
15
  import type { AztecNode } from '@aztec/stdlib/interfaces/server';
@@ -21,14 +21,13 @@ import type { NoteStatus } from '@aztec/stdlib/note';
21
21
  import { MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
22
22
  import type { BlockHeader, Capsule, OffchainEffect } from '@aztec/stdlib/tx';
23
23
 
24
- import type { AccessScopes } from '../../access_scopes.js';
25
24
  import { createContractLogger, logContractMessage, stripAztecnrLogPrefix } from '../../contract_logging.js';
26
25
  import type { ContractSyncService } from '../../contract_sync/contract_sync_service.js';
27
26
  import { EventService } from '../../events/event_service.js';
28
27
  import { LogService } from '../../logs/log_service.js';
29
28
  import { MessageContextService } from '../../messages/message_context_service.js';
30
29
  import { NoteService } from '../../notes/note_service.js';
31
- import { ORACLE_VERSION } from '../../oracle_version.js';
30
+ import { ORACLE_VERSION_MAJOR } from '../../oracle_version.js';
32
31
  import type { AddressStore } from '../../storage/address_store/address_store.js';
33
32
  import type { CapsuleService } from '../../storage/capsule_store/capsule_service.js';
34
33
  import type { ContractStore } from '../../storage/contract_store/contract_store.js';
@@ -36,6 +35,7 @@ import type { NoteStore } from '../../storage/note_store/note_store.js';
36
35
  import type { PrivateEventStore } from '../../storage/private_event_store/private_event_store.js';
37
36
  import type { RecipientTaggingStore } from '../../storage/tagging_store/recipient_tagging_store.js';
38
37
  import type { SenderAddressBookStore } from '../../storage/tagging_store/sender_address_book_store.js';
38
+ import { EphemeralArrayService } from '../ephemeral_array_service.js';
39
39
  import { EventValidationRequest } from '../noir-structs/event_validation_request.js';
40
40
  import { LogRetrievalRequest } from '../noir-structs/log_retrieval_request.js';
41
41
  import { LogRetrievalResponse } from '../noir-structs/log_retrieval_response.js';
@@ -63,9 +63,10 @@ export type UtilityExecutionOracleArgs = {
63
63
  privateEventStore: PrivateEventStore;
64
64
  messageContextService: MessageContextService;
65
65
  contractSyncService: ContractSyncService;
66
+ l2TipsStore: L2TipsProvider;
66
67
  jobId: string;
67
68
  log?: ReturnType<typeof createLogger>;
68
- scopes: AccessScopes;
69
+ scopes: AztecAddress[];
69
70
  };
70
71
 
71
72
  /**
@@ -78,6 +79,10 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
78
79
  private contractLogger: Logger | undefined;
79
80
  private aztecnrLogger: Logger | undefined;
80
81
  private offchainEffects: OffchainEffect[] = [];
82
+ private readonly ephemeralArrayService = new EphemeralArrayService();
83
+
84
+ // We store oracle version to be able to show a nice error message when an oracle handler is missing.
85
+ private contractOracleVersion: { major: number; minor: number } | undefined;
81
86
 
82
87
  protected readonly contractAddress: AztecAddress;
83
88
  protected readonly authWitnesses: AuthWitness[];
@@ -94,9 +99,10 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
94
99
  protected readonly privateEventStore: PrivateEventStore;
95
100
  protected readonly messageContextService: MessageContextService;
96
101
  protected readonly contractSyncService: ContractSyncService;
102
+ protected readonly l2TipsStore: L2TipsProvider;
97
103
  protected readonly jobId: string;
98
104
  protected logger: ReturnType<typeof createLogger>;
99
- protected readonly scopes: AccessScopes;
105
+ protected readonly scopes: AztecAddress[];
100
106
 
101
107
  constructor(args: UtilityExecutionOracleArgs) {
102
108
  this.contractAddress = args.contractAddress;
@@ -114,12 +120,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
114
120
  this.privateEventStore = args.privateEventStore;
115
121
  this.messageContextService = args.messageContextService;
116
122
  this.contractSyncService = args.contractSyncService;
123
+ this.l2TipsStore = args.l2TipsStore;
117
124
  this.jobId = args.jobId;
118
125
  this.logger = args.log ?? createLogger('simulator:client_view_context');
119
126
  this.scopes = args.scopes;
120
127
  }
121
128
 
122
- public assertCompatibleOracleVersion(version: number): void {
129
+ public assertCompatibleOracleVersion(major: number, minor: number): void {
123
130
  // TODO(F-416): Remove this hack on v5 when protocol contracts are redeployed.
124
131
  // Protocol contracts/canonical contracts shipped with committed bytecode that cannot be changed. Assert they use
125
132
  // the expected pinned version or the current one. We want to allow for both the pinned and the current versions
@@ -127,27 +134,36 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
127
134
  // pinned contracts (like e.g. next)
128
135
  const LEGACY_ORACLE_VERSION = 12;
129
136
  if (isProtocolContract(this.contractAddress)) {
130
- if (version !== LEGACY_ORACLE_VERSION && version !== ORACLE_VERSION) {
137
+ if (major !== LEGACY_ORACLE_VERSION && major !== ORACLE_VERSION_MAJOR) {
131
138
  const hint =
132
- version > ORACLE_VERSION
139
+ major > ORACLE_VERSION_MAJOR
133
140
  ? 'The contract was compiled with a newer version of Aztec.nr than your private environment supports. Upgrade your private environment to a compatible version.'
134
141
  : 'The contract was compiled with an older version of Aztec.nr than your private environment supports. Recompile the contract with a compatible version of Aztec.nr.';
135
142
  throw new Error(
136
- `Incompatible private environment version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle version ${LEGACY_ORACLE_VERSION} or ${ORACLE_VERSION}, got ${version})`,
143
+ `Incompatible private environment version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle major version ${LEGACY_ORACLE_VERSION} or ${ORACLE_VERSION_MAJOR}, got ${major})`,
137
144
  );
138
145
  }
146
+ this.contractOracleVersion = { major, minor };
139
147
  return;
140
148
  }
141
149
 
142
- if (version !== ORACLE_VERSION) {
150
+ if (major !== ORACLE_VERSION_MAJOR) {
143
151
  const hint =
144
- version > ORACLE_VERSION
152
+ major > ORACLE_VERSION_MAJOR
145
153
  ? 'The contract was compiled with a newer version of Aztec.nr than your private environment supports. Upgrade your private environment to a compatible version.'
146
154
  : 'The contract was compiled with an older version of Aztec.nr than your private environment supports. Recompile the contract with a compatible version of Aztec.nr.';
147
155
  throw new Error(
148
- `Incompatible private environment version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle version ${ORACLE_VERSION}, got ${version})`,
156
+ `Incompatible private environment version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle major version ${ORACLE_VERSION_MAJOR}, got ${major})`,
149
157
  );
150
158
  }
159
+
160
+ // Major matches - store both major and minor for later diagnostics (e.g. when an oracle is not found)
161
+ this.contractOracleVersion = { major, minor };
162
+ }
163
+
164
+ // Prefixed with "nonOracleFunction" as it is not used as an oracle handler.
165
+ public nonOracleFunctionGetContractOracleVersion(): { major: number; minor: number } | undefined {
166
+ return this.contractOracleVersion;
151
167
  }
152
168
 
153
169
  public getRandomField(): Fr {
@@ -166,18 +182,15 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
166
182
  * @throws If scopes are defined and the account is not in the scopes.
167
183
  */
168
184
  public async getKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
169
- // If scopes are defined, check that the key belongs to an account in the scopes.
170
- if (this.scopes !== 'ALL_SCOPES' && this.scopes.length > 0) {
171
- let hasAccess = false;
172
- for (let i = 0; i < this.scopes.length && !hasAccess; i++) {
173
- if (await this.keyStore.accountHasKey(this.scopes[i], pkMHash)) {
174
- hasAccess = true;
175
- }
176
- }
177
- if (!hasAccess) {
178
- throw new Error(`Key validation request denied: no scoped account has a key with hash ${pkMHash.toString()}.`);
185
+ let hasAccess = false;
186
+ for (let i = 0; i < this.scopes.length && !hasAccess; i++) {
187
+ if (await this.keyStore.accountHasKey(this.scopes[i], pkMHash)) {
188
+ hasAccess = true;
179
189
  }
180
190
  }
191
+ if (!hasAccess) {
192
+ throw new Error(`Key validation request denied: no scoped account has a key with hash ${pkMHash.toString()}.`);
193
+ }
181
194
  return this.keyStore.getKeyValidationRequest(pkMHash, this.contractAddress);
182
195
  }
183
196
 
@@ -497,31 +510,44 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
497
510
  logContractMessage(logger, LogLevels[level], strippedMessage, fields);
498
511
  }
499
512
 
513
+ // Deprecated, only kept for backwards compatibility until Alpha v5 rolls out.
500
514
  public async getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr, scope: AztecAddress) {
501
- const logService = new LogService(
515
+ const logService = this.#createLogService();
516
+ const logs = await logService.fetchTaggedLogs(this.contractAddress, scope);
517
+ await this.capsuleService.appendToCapsuleArray(
518
+ this.contractAddress,
519
+ pendingTaggedLogArrayBaseSlot,
520
+ logs.map(log => log.toFields()),
521
+ this.jobId,
522
+ scope,
523
+ );
524
+ }
525
+
526
+ /** Fetches pending tagged logs into a freshly allocated ephemeral array and returns its base slot. */
527
+ public async getPendingTaggedLogsV2(scope: AztecAddress): Promise<Fr> {
528
+ const logService = this.#createLogService();
529
+ const logs = await logService.fetchTaggedLogs(this.contractAddress, scope);
530
+ return this.ephemeralArrayService.newArray(logs.map(log => log.toFields()));
531
+ }
532
+
533
+ #createLogService(): LogService {
534
+ return new LogService(
502
535
  this.aztecNode,
503
536
  this.anchorBlockHeader,
537
+ this.l2TipsStore,
504
538
  this.keyStore,
505
- this.capsuleService,
506
539
  this.recipientTaggingStore,
507
540
  this.senderAddressBookStore,
508
541
  this.addressStore,
509
542
  this.jobId,
510
543
  this.logger.getBindings(),
511
544
  );
512
-
513
- await logService.fetchTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, scope);
514
545
  }
515
546
 
516
547
  /**
517
- * Validates all note and event validation requests enqueued via `enqueue_note_for_validation` and
518
- * `enqueue_event_for_validation`, inserting them into the note database and event store respectively, making them
519
- * queryable via `get_notes` and `getPrivateEvents`.
548
+ * Legacy: validates note/event requests stored in capsule arrays.
520
549
  *
521
- * This automatically clears both validation request queues, so no further work needs to be done by the caller.
522
- * @param contractAddress - The address of the contract that the logs are tagged for.
523
- * @param noteValidationRequestsArrayBaseSlot - The base slot of capsule array containing note validation requests.
524
- * @param eventValidationRequestsArrayBaseSlot - The base slot of capsule array containing event validation requests.
550
+ * Deprecated, only kept for backwards compatibility until Alpha v5 rolls out.
525
551
  */
526
552
  public async validateAndStoreEnqueuedNotesAndEvents(
527
553
  contractAddress: AztecAddress,
@@ -536,8 +562,6 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
536
562
  throw new Error(`Got a note validation request from ${contractAddress}, expected ${this.contractAddress}`);
537
563
  }
538
564
 
539
- // We read all note and event validation requests and process them all concurrently. This makes the process much
540
- // faster as we don't need to wait for the network round-trip.
541
565
  const noteValidationRequests = (
542
566
  await this.capsuleService.readCapsuleArray(
543
567
  contractAddress,
@@ -556,6 +580,53 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
556
580
  )
557
581
  ).map(fields => EventValidationRequest.fromFields(fields, maxEventSerializedLen));
558
582
 
583
+ await this.#processValidationRequests(noteValidationRequests, eventValidationRequests, scope);
584
+
585
+ await this.capsuleService.setCapsuleArray(
586
+ contractAddress,
587
+ noteValidationRequestsArrayBaseSlot,
588
+ [],
589
+ this.jobId,
590
+ scope,
591
+ );
592
+ await this.capsuleService.setCapsuleArray(
593
+ contractAddress,
594
+ eventValidationRequestsArrayBaseSlot,
595
+ [],
596
+ this.jobId,
597
+ scope,
598
+ );
599
+ }
600
+
601
+ public async validateAndStoreEnqueuedNotesAndEventsV2(
602
+ noteValidationRequestsArrayBaseSlot: Fr,
603
+ eventValidationRequestsArrayBaseSlot: Fr,
604
+ maxNotePackedLen: number,
605
+ maxEventSerializedLen: number,
606
+ scope: AztecAddress,
607
+ ) {
608
+ const noteValidationRequests = this.ephemeralArrayService
609
+ .readArrayAt(noteValidationRequestsArrayBaseSlot)
610
+ .map(fields => NoteValidationRequest.fromFields(fields, maxNotePackedLen));
611
+
612
+ const eventValidationRequests = this.ephemeralArrayService
613
+ .readArrayAt(eventValidationRequestsArrayBaseSlot)
614
+ .map(fields => EventValidationRequest.fromFields(fields, maxEventSerializedLen));
615
+
616
+ await this.#processValidationRequests(noteValidationRequests, eventValidationRequests, scope);
617
+ }
618
+
619
+ /**
620
+ * Dispatches note and event validation requests to the service layer.
621
+ *
622
+ * This function is an auxiliary to support legacy (capsule backed) and new (ephemeral array backed) versions of the
623
+ * `validateAndStoreEnqueuedNotesAndEvents` oracle.
624
+ */
625
+ async #processValidationRequests(
626
+ noteValidationRequests: NoteValidationRequest[],
627
+ eventValidationRequests: EventValidationRequest[],
628
+ scope: AztecAddress,
629
+ ) {
559
630
  const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
560
631
  const noteStorePromises = noteValidationRequests.map(request =>
561
632
  noteService.validateAndStoreNote(
@@ -586,22 +657,6 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
586
657
  );
587
658
 
588
659
  await Promise.all([...noteStorePromises, ...eventStorePromises]);
589
-
590
- // Requests are cleared once we're done.
591
- await this.capsuleService.setCapsuleArray(
592
- contractAddress,
593
- noteValidationRequestsArrayBaseSlot,
594
- [],
595
- this.jobId,
596
- scope,
597
- );
598
- await this.capsuleService.setCapsuleArray(
599
- contractAddress,
600
- eventValidationRequestsArrayBaseSlot,
601
- [],
602
- this.jobId,
603
- scope,
604
- );
605
660
  }
606
661
 
607
662
  public async getLogsByTag(
@@ -621,18 +676,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
621
676
  await this.capsuleService.readCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, this.jobId, scope)
622
677
  ).map(LogRetrievalRequest.fromFields);
623
678
 
624
- const logService = new LogService(
625
- this.aztecNode,
626
- this.anchorBlockHeader,
627
- this.keyStore,
628
- this.capsuleService,
629
- this.recipientTaggingStore,
630
- this.senderAddressBookStore,
631
- this.addressStore,
632
- this.jobId,
633
- this.logger.getBindings(),
634
- );
635
-
679
+ const logService = this.#createLogService();
636
680
  const maybeLogRetrievalResponses = await logService.fetchLogsByTag(contractAddress, logRetrievalRequests);
637
681
 
638
682
  // Requests are cleared once we're done.
@@ -654,6 +698,18 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
654
698
  );
655
699
  }
656
700
 
701
+ public async getLogsByTagV2(requestArrayBaseSlot: Fr): Promise<Fr> {
702
+ const logRetrievalRequests = this.ephemeralArrayService
703
+ .readArrayAt(requestArrayBaseSlot)
704
+ .map(LogRetrievalRequest.fromFields);
705
+ const logService = this.#createLogService();
706
+
707
+ const maybeLogRetrievalResponses = await logService.fetchLogsByTag(this.contractAddress, logRetrievalRequests);
708
+
709
+ return this.ephemeralArrayService.newArray(maybeLogRetrievalResponses.map(LogRetrievalResponse.toSerializedOption));
710
+ }
711
+
712
+ // Deprecated, only kept for backwards compatibility until Alpha v5 rolls out.
657
713
  public async getMessageContextsByTxHash(
658
714
  contractAddress: AztecAddress,
659
715
  messageContextRequestsArrayBaseSlot: Fr,
@@ -665,7 +721,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
665
721
  throw new Error(`Got a message context request from ${contractAddress}, expected ${this.contractAddress}`);
666
722
  }
667
723
 
668
- // TODO(@mverzilli): this is a prime example of where using a volatile array would make much more sense, we don't
724
+ // TODO(@mverzilli): this is a prime example of where using an ephemeral array would make much more sense, we don't
669
725
  // need scopes here, we just need a bit of shared memory to cross boundaries between Noir and TS.
670
726
  // At the same time, we don't want to allow any global scope access other than where backwards compatibility
671
727
  // forces us to. Hence we need the scope here to be artificial.
@@ -709,6 +765,27 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
709
765
  }
710
766
  }
711
767
 
768
+ /** Reads tx hash requests from an ephemeral array, resolves their contexts, and returns the response slot. */
769
+ public async getMessageContextsByTxHashV2(requestArrayBaseSlot: Fr): Promise<Fr> {
770
+ const requestFields = this.ephemeralArrayService.readArrayAt(requestArrayBaseSlot);
771
+
772
+ const txHashes = requestFields.map((fields, i) => {
773
+ if (fields.length !== 1) {
774
+ throw new Error(
775
+ `Malformed message context request at index ${i}: expected 1 field (tx hash), got ${fields.length}`,
776
+ );
777
+ }
778
+ return fields[0];
779
+ });
780
+
781
+ const maybeMessageContexts = await this.messageContextService.getMessageContextsByTxHash(
782
+ txHashes,
783
+ this.anchorBlockHeader.getBlockNumber(),
784
+ );
785
+
786
+ return this.ephemeralArrayService.newArray(maybeMessageContexts.map(MessageContext.toSerializedOption));
787
+ }
788
+
712
789
  public setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], scope: AztecAddress): void {
713
790
  if (!contractAddress.equals(this.contractAddress)) {
714
791
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
@@ -785,6 +862,34 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
785
862
  return deriveAppSiloedSharedSecret(addressSecret, ephPk, this.contractAddress);
786
863
  }
787
864
 
865
+ public pushEphemeral(slot: Fr, elements: Fr[]): number {
866
+ return this.ephemeralArrayService.push(slot, elements);
867
+ }
868
+
869
+ public popEphemeral(slot: Fr): Fr[] {
870
+ return this.ephemeralArrayService.pop(slot);
871
+ }
872
+
873
+ public getEphemeral(slot: Fr, index: number): Fr[] {
874
+ return this.ephemeralArrayService.get(slot, index);
875
+ }
876
+
877
+ public setEphemeral(slot: Fr, index: number, elements: Fr[]): void {
878
+ this.ephemeralArrayService.set(slot, index, elements);
879
+ }
880
+
881
+ public getEphemeralLen(slot: Fr): number {
882
+ return this.ephemeralArrayService.len(slot);
883
+ }
884
+
885
+ public removeEphemeral(slot: Fr, index: number): void {
886
+ this.ephemeralArrayService.remove(slot, index);
887
+ }
888
+
889
+ public clearEphemeral(slot: Fr): void {
890
+ this.ephemeralArrayService.clear(slot);
891
+ }
892
+
788
893
  public emitOffchainEffect(data: Fr[]): Promise<void> {
789
894
  this.offchainEffects.push({ data, contractAddress: this.contractAddress });
790
895
  return Promise.resolve();
@@ -86,8 +86,15 @@ interface ContainsNote {
86
86
 
87
87
  const selectPropertyFromPackedNoteContent = (noteData: Fr[], selector: PropertySelector): Fr => {
88
88
  const noteValueBuffer = noteData[selector.index].toBuffer();
89
- const noteValue = noteValueBuffer.subarray(selector.offset, selector.offset + selector.length);
90
- return Fr.fromBuffer(noteValue);
89
+ // Noir's PropertySelector counts offset from the LSB (last byte of the big-endian buffer),
90
+ // so offset=0,length=Fr.SIZE_IN_BYTES reads the entire field, and offset=0,length=1 reads the last byte.
91
+ const start = Fr.SIZE_IN_BYTES - selector.offset - selector.length;
92
+ const end = Fr.SIZE_IN_BYTES - selector.offset;
93
+ const noteValue = noteValueBuffer.subarray(start, end);
94
+ // Left-pad to Fr.SIZE_IN_BYTES so Fr.fromBuffer interprets the value correctly.
95
+ const padded = Buffer.alloc(Fr.SIZE_IN_BYTES);
96
+ noteValue.copy(padded, Fr.SIZE_IN_BYTES - noteValue.length);
97
+ return Fr.fromBuffer(padded);
91
98
  };
92
99
 
93
100
  const selectNotes = <T extends ContainsNote>(noteDatas: T[], selects: Select[]): T[] =>
@@ -103,7 +110,11 @@ const selectNotes = <T extends ContainsNote>(noteDatas: T[], selects: Select[]):
103
110
  [Comparator.GTE]: () => !noteValueFr.lt(value),
104
111
  };
105
112
 
106
- return comparatorSelector[comparator]();
113
+ const fn = comparatorSelector[comparator];
114
+ if (!fn) {
115
+ throw new Error(`Invalid comparator value: ${comparator}`);
116
+ }
117
+ return fn();
107
118
  }),
108
119
  );
109
120
 
@@ -29,6 +29,7 @@ export class ProxiedContractStoreFactory {
29
29
  }
30
30
  instance.currentContractClassId = realInstance.currentContractClassId;
31
31
  instance.originalContractClassId = realInstance.originalContractClassId;
32
+ instance.initializationHash = realInstance.initializationHash;
32
33
  return instance;
33
34
  } else {
34
35
  return target.getContractInstance(address);
@@ -47,6 +48,9 @@ export class ProxiedContractStoreFactory {
47
48
  return fn;
48
49
  }
49
50
  }
51
+ throw new Error(
52
+ `Function with selector ${selector} not found in stub artifact for overridden contract at ${contractAddress}. The stub does not implement this function.`,
53
+ );
50
54
  } else {
51
55
  return target.getFunctionArtifact(contractAddress, selector);
52
56
  }
@@ -64,6 +68,9 @@ export class ProxiedContractStoreFactory {
64
68
  return fn;
65
69
  }
66
70
  }
71
+ throw new Error(
72
+ `Function with selector ${selector} not found in stub artifact for overridden contract at ${contractAddress}. The stub does not implement this function.`,
73
+ );
67
74
  } else {
68
75
  return target.getFunctionArtifactWithDebugMetadata(contractAddress, selector);
69
76
  }
@@ -78,6 +85,6 @@ export class ProxiedContractStoreFactory {
78
85
  }
79
86
  }
80
87
  },
81
- });
88
+ }) satisfies ContractStore;
82
89
  }
83
90
  }