@aztec/pxe 0.0.1-commit.f5d02921e → 0.0.1-commit.f7ea82942

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 (162) 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 +13 -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 +6 -4
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  10. package/dest/contract_function_simulator/contract_function_simulator.js +6 -4
  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 +1 -1
  15. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
  16. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
  17. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
  18. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
  19. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -1
  20. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -1
  21. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
  22. package/dest/contract_function_simulator/oracle/interfaces.d.ts +13 -2
  23. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  24. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +1 -1
  25. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +10 -1
  27. package/dest/contract_function_simulator/oracle/oracle.d.ts +13 -2
  28. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/oracle/oracle.js +98 -3
  30. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +4 -4
  31. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +19 -4
  33. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +30 -16
  34. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +106 -37
  36. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  37. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/pick_notes.js +20 -3
  39. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
  40. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
  42. package/dest/contract_sync/contract_sync_service.d.ts +4 -6
  43. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  44. package/dest/contract_sync/contract_sync_service.js +38 -46
  45. package/dest/contract_sync/helpers.d.ts +2 -3
  46. package/dest/contract_sync/helpers.d.ts.map +1 -1
  47. package/dest/debug/pxe_debug_utils.d.ts +3 -3
  48. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  49. package/dest/entrypoints/client/bundle/index.d.ts +1 -2
  50. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  51. package/dest/entrypoints/client/bundle/index.js +0 -1
  52. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  53. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  54. package/dest/entrypoints/client/bundle/utils.js +2 -2
  55. package/dest/entrypoints/client/lazy/index.d.ts +1 -2
  56. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  57. package/dest/entrypoints/client/lazy/index.js +0 -1
  58. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  59. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  60. package/dest/entrypoints/client/lazy/utils.js +2 -2
  61. package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
  62. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  63. package/dest/entrypoints/pxe_creation_options.js +3 -1
  64. package/dest/entrypoints/server/index.d.ts +2 -3
  65. package/dest/entrypoints/server/index.d.ts.map +1 -1
  66. package/dest/entrypoints/server/index.js +1 -2
  67. package/dest/entrypoints/server/utils.d.ts +2 -2
  68. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  69. package/dest/entrypoints/server/utils.js +2 -2
  70. package/dest/events/event_service.d.ts +1 -1
  71. package/dest/events/event_service.d.ts.map +1 -1
  72. package/dest/events/event_service.js +10 -1
  73. package/dest/events/private_event_filter_validator.d.ts +3 -2
  74. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  75. package/dest/events/private_event_filter_validator.js +15 -0
  76. package/dest/logs/log_service.d.ts +6 -6
  77. package/dest/logs/log_service.d.ts.map +1 -1
  78. package/dest/logs/log_service.js +15 -21
  79. package/dest/notes/note_service.d.ts +3 -4
  80. package/dest/notes/note_service.d.ts.map +1 -1
  81. package/dest/notes_filter.d.ts +2 -3
  82. package/dest/notes_filter.d.ts.map +1 -1
  83. package/dest/oracle_version.d.ts +4 -3
  84. package/dest/oracle_version.d.ts.map +1 -1
  85. package/dest/oracle_version.js +20 -10
  86. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  87. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  88. package/dest/private_kernel/private_kernel_execution_prover.js +4 -7
  89. package/dest/private_kernel/private_kernel_oracle.d.ts +5 -5
  90. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  91. package/dest/private_kernel/private_kernel_oracle.js +12 -15
  92. package/dest/pxe.d.ts +5 -5
  93. package/dest/pxe.d.ts.map +1 -1
  94. package/dest/pxe.js +27 -20
  95. package/dest/storage/anchor_block_store/anchor_block_store.js +1 -1
  96. package/dest/storage/capsule_store/capsule_service.d.ts +2 -3
  97. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -1
  98. package/dest/storage/capsule_store/capsule_service.js +1 -1
  99. package/dest/storage/capsule_store/capsule_store.d.ts +1 -1
  100. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  101. package/dest/storage/capsule_store/capsule_store.js +8 -5
  102. package/dest/storage/contract_store/contract_store.d.ts +1 -1
  103. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  104. package/dest/storage/contract_store/contract_store.js +4 -2
  105. package/dest/storage/note_store/note_store.d.ts +1 -1
  106. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  107. package/dest/storage/note_store/note_store.js +2 -2
  108. package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
  109. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  110. package/dest/storage/private_event_store/private_event_store.js +3 -0
  111. package/dest/storage/private_event_store/stored_private_event.js +1 -1
  112. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +2 -2
  113. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  114. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +2 -16
  115. package/package.json +16 -16
  116. package/src/bin/check_oracle_version.ts +4 -4
  117. package/src/block_synchronizer/block_synchronizer.ts +16 -2
  118. package/src/config/index.ts +2 -8
  119. package/src/contract_function_simulator/contract_function_simulator.ts +9 -7
  120. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  121. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  122. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
  123. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -1
  124. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
  125. package/src/contract_function_simulator/oracle/interfaces.ts +20 -1
  126. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +7 -1
  127. package/src/contract_function_simulator/oracle/oracle.ts +143 -3
  128. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +28 -6
  129. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +171 -67
  130. package/src/contract_function_simulator/pick_notes.ts +22 -3
  131. package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
  132. package/src/contract_sync/contract_sync_service.ts +64 -80
  133. package/src/contract_sync/helpers.ts +2 -3
  134. package/src/debug/pxe_debug_utils.ts +3 -3
  135. package/src/entrypoints/client/bundle/index.ts +0 -1
  136. package/src/entrypoints/client/bundle/utils.ts +2 -3
  137. package/src/entrypoints/client/lazy/index.ts +0 -1
  138. package/src/entrypoints/client/lazy/utils.ts +2 -3
  139. package/src/entrypoints/pxe_creation_options.ts +7 -0
  140. package/src/entrypoints/server/index.ts +1 -2
  141. package/src/entrypoints/server/utils.ts +2 -3
  142. package/src/events/event_service.ts +13 -1
  143. package/src/events/private_event_filter_validator.ts +21 -1
  144. package/src/logs/log_service.ts +24 -50
  145. package/src/notes/note_service.ts +2 -3
  146. package/src/notes_filter.ts +1 -3
  147. package/src/oracle_version.ts +20 -10
  148. package/src/private_kernel/private_kernel_execution_prover.ts +4 -9
  149. package/src/private_kernel/private_kernel_oracle.ts +14 -14
  150. package/src/pxe.ts +61 -26
  151. package/src/storage/anchor_block_store/anchor_block_store.ts +1 -1
  152. package/src/storage/capsule_store/capsule_service.ts +5 -6
  153. package/src/storage/capsule_store/capsule_store.ts +15 -5
  154. package/src/storage/contract_store/contract_store.ts +8 -6
  155. package/src/storage/note_store/note_store.ts +2 -5
  156. package/src/storage/private_event_store/private_event_store.ts +4 -0
  157. package/src/storage/private_event_store/stored_private_event.ts +1 -1
  158. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +5 -15
  159. package/dest/access_scopes.d.ts +0 -9
  160. package/dest/access_scopes.d.ts.map +0 -1
  161. package/dest/access_scopes.js +0 -6
  162. package/src/access_scopes.ts +0 -9
@@ -25,7 +25,6 @@ import {
25
25
  type TxContext,
26
26
  } from '@aztec/stdlib/tx';
27
27
 
28
- import type { AccessScopes } from '../../access_scopes.js';
29
28
  import { NoteService } from '../../notes/note_service.js';
30
29
  import type { SenderTaggingStore } from '../../storage/tagging_store/sender_tagging_store.js';
31
30
  import { syncSenderTaggingIndexes } from '../../tagging/index.js';
@@ -43,7 +42,7 @@ export type PrivateExecutionOracleArgs = Omit<UtilityExecutionOracleArgs, 'contr
43
42
  txContext: TxContext;
44
43
  callContext: CallContext;
45
44
  /** Needed to trigger contract synchronization before nested calls */
46
- utilityExecutor: (call: FunctionCall, scopes: AccessScopes) => Promise<void>;
45
+ utilityExecutor: (call: FunctionCall, scopes: AztecAddress[]) => Promise<void>;
47
46
  executionCache: HashedValuesCache;
48
47
  noteCache: ExecutionNoteCache;
49
48
  taggingIndexCache: ExecutionTaggingIndexCache;
@@ -76,13 +75,13 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
76
75
  private readonly argsHash: Fr;
77
76
  private readonly txContext: TxContext;
78
77
  private readonly callContext: CallContext;
79
- private readonly utilityExecutor: (call: FunctionCall, scopes: AccessScopes) => Promise<void>;
78
+ private readonly utilityExecutor: (call: FunctionCall, scopes: AztecAddress[]) => Promise<void>;
80
79
  private readonly executionCache: HashedValuesCache;
81
80
  private readonly noteCache: ExecutionNoteCache;
82
81
  private readonly taggingIndexCache: ExecutionTaggingIndexCache;
83
82
  private readonly senderTaggingStore: SenderTaggingStore;
84
83
  private totalPublicCalldataCount: number;
85
- protected sideEffectCounter: number;
84
+ private readonly initialSideEffectCounter: number;
86
85
  private senderForTags?: AztecAddress;
87
86
  private readonly simulator?: CircuitSimulator;
88
87
 
@@ -101,13 +100,18 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
101
100
  this.taggingIndexCache = args.taggingIndexCache;
102
101
  this.senderTaggingStore = args.senderTaggingStore;
103
102
  this.totalPublicCalldataCount = args.totalPublicCalldataCount ?? 0;
104
- this.sideEffectCounter = args.sideEffectCounter ?? 0;
103
+ this.initialSideEffectCounter = args.sideEffectCounter ?? 0;
105
104
  this.senderForTags = args.senderForTags;
106
105
  this.simulator = args.simulator;
107
106
  }
108
107
 
109
108
  public getPrivateContextInputs(): PrivateContextInputs {
110
- return new PrivateContextInputs(this.callContext, this.anchorBlockHeader, this.txContext, this.sideEffectCounter);
109
+ return new PrivateContextInputs(
110
+ this.callContext,
111
+ this.anchorBlockHeader,
112
+ this.txContext,
113
+ this.initialSideEffectCounter,
114
+ );
111
115
  }
112
116
 
113
117
  // We still need this function until we can get user-defined ordering of structs for fn arguments
@@ -210,6 +214,16 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
210
214
  recipient,
211
215
  );
212
216
 
217
+ if (!extendedSecret) {
218
+ // We'd only fail to compute an extended secret if the recipient is an invalid address. To prevent
219
+ // king-of-the-hill attacks, instead of failing we use a random tag. By including a correct-looking tag in the
220
+ // log, the transaction shape is preserved and no privacy is leaked, even if the tag is bogus.
221
+ this.logger.warn(`Computing a tag for invalid recipient ${recipient} - returning a random tag instead`, {
222
+ contractAddress: this.contractAddress,
223
+ });
224
+ return Tag.random();
225
+ }
226
+
213
227
  const index = await this.#getIndexToUseForSecret(extendedSecret);
214
228
  this.logger.debug(
215
229
  `Incrementing tagging index for sender: ${sender}, recipient: ${recipient}, contract: ${this.contractAddress} to ${index}`,
@@ -566,6 +580,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
566
580
  scopes: this.scopes,
567
581
  senderForTags: this.senderForTags,
568
582
  simulator: this.simulator!,
583
+ l2TipsStore: this.l2TipsStore,
569
584
  });
570
585
 
571
586
  const setupTime = simulatorSetupTimer.ms();
@@ -578,6 +593,9 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
578
593
  functionSelector,
579
594
  );
580
595
 
596
+ // Propagate the nested call's calldata count so the parent sees its increments on subsequent enqueues.
597
+ this.totalPublicCalldataCount = privateExecutionOracle.getTotalPublicCalldataCount();
598
+
581
599
  if (isStaticCall) {
582
600
  this.#checkValidStaticCall(childExecutionResult);
583
601
  }
@@ -611,6 +629,10 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
611
629
  return Promise.resolve();
612
630
  }
613
631
 
632
+ public getTotalPublicCalldataCount(): number {
633
+ return this.totalPublicCalldataCount;
634
+ }
635
+
614
636
  public notifyRevertiblePhaseStart(minRevertibleSideEffectCounter: number): Promise<void> {
615
637
  return this.noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
616
638
  }
@@ -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
 
@@ -320,10 +333,9 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
320
333
  }
321
334
 
322
335
  /**
323
- * Returns an auth witness for the given message hash. Checks on the list of transient witnesses
324
- * for this transaction first, and falls back to the local database if not found.
336
+ * Returns an auth witness for the given message hash from the list of transient witnesses for this transaction.
325
337
  * @param messageHash - Hash of the message to authenticate.
326
- * @returns Authentication witness for the requested message hash.
338
+ * @returns Authentication witness for the requested message hash, or undefined if not found.
327
339
  */
328
340
  public getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined> {
329
341
  return Promise.resolve(this.authWitnesses.find(w => w.requestHash.equals(messageHash))?.witness);
@@ -497,31 +509,44 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
497
509
  logContractMessage(logger, LogLevels[level], strippedMessage, fields);
498
510
  }
499
511
 
512
+ // Deprecated, only kept for backwards compatibility until Alpha v5 rolls out.
500
513
  public async getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr, scope: AztecAddress) {
501
- const logService = new LogService(
514
+ const logService = this.#createLogService();
515
+ const logs = await logService.fetchTaggedLogs(this.contractAddress, scope);
516
+ await this.capsuleService.appendToCapsuleArray(
517
+ this.contractAddress,
518
+ pendingTaggedLogArrayBaseSlot,
519
+ logs.map(log => log.toFields()),
520
+ this.jobId,
521
+ scope,
522
+ );
523
+ }
524
+
525
+ /** Fetches pending tagged logs into a freshly allocated ephemeral array and returns its base slot. */
526
+ public async getPendingTaggedLogsV2(scope: AztecAddress): Promise<Fr> {
527
+ const logService = this.#createLogService();
528
+ const logs = await logService.fetchTaggedLogs(this.contractAddress, scope);
529
+ return this.ephemeralArrayService.newArray(logs.map(log => log.toFields()));
530
+ }
531
+
532
+ #createLogService(): LogService {
533
+ return new LogService(
502
534
  this.aztecNode,
503
535
  this.anchorBlockHeader,
536
+ this.l2TipsStore,
504
537
  this.keyStore,
505
- this.capsuleService,
506
538
  this.recipientTaggingStore,
507
539
  this.senderAddressBookStore,
508
540
  this.addressStore,
509
541
  this.jobId,
510
542
  this.logger.getBindings(),
511
543
  );
512
-
513
- await logService.fetchTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, scope);
514
544
  }
515
545
 
516
546
  /**
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`.
547
+ * Legacy: validates note/event requests stored in capsule arrays.
520
548
  *
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.
549
+ * Deprecated, only kept for backwards compatibility until Alpha v5 rolls out.
525
550
  */
526
551
  public async validateAndStoreEnqueuedNotesAndEvents(
527
552
  contractAddress: AztecAddress,
@@ -536,8 +561,6 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
536
561
  throw new Error(`Got a note validation request from ${contractAddress}, expected ${this.contractAddress}`);
537
562
  }
538
563
 
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
564
  const noteValidationRequests = (
542
565
  await this.capsuleService.readCapsuleArray(
543
566
  contractAddress,
@@ -556,6 +579,53 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
556
579
  )
557
580
  ).map(fields => EventValidationRequest.fromFields(fields, maxEventSerializedLen));
558
581
 
582
+ await this.#processValidationRequests(noteValidationRequests, eventValidationRequests, scope);
583
+
584
+ await this.capsuleService.setCapsuleArray(
585
+ contractAddress,
586
+ noteValidationRequestsArrayBaseSlot,
587
+ [],
588
+ this.jobId,
589
+ scope,
590
+ );
591
+ await this.capsuleService.setCapsuleArray(
592
+ contractAddress,
593
+ eventValidationRequestsArrayBaseSlot,
594
+ [],
595
+ this.jobId,
596
+ scope,
597
+ );
598
+ }
599
+
600
+ public async validateAndStoreEnqueuedNotesAndEventsV2(
601
+ noteValidationRequestsArrayBaseSlot: Fr,
602
+ eventValidationRequestsArrayBaseSlot: Fr,
603
+ maxNotePackedLen: number,
604
+ maxEventSerializedLen: number,
605
+ scope: AztecAddress,
606
+ ) {
607
+ const noteValidationRequests = this.ephemeralArrayService
608
+ .readArrayAt(noteValidationRequestsArrayBaseSlot)
609
+ .map(fields => NoteValidationRequest.fromFields(fields, maxNotePackedLen));
610
+
611
+ const eventValidationRequests = this.ephemeralArrayService
612
+ .readArrayAt(eventValidationRequestsArrayBaseSlot)
613
+ .map(fields => EventValidationRequest.fromFields(fields, maxEventSerializedLen));
614
+
615
+ await this.#processValidationRequests(noteValidationRequests, eventValidationRequests, scope);
616
+ }
617
+
618
+ /**
619
+ * Dispatches note and event validation requests to the service layer.
620
+ *
621
+ * This function is an auxiliary to support legacy (capsule backed) and new (ephemeral array backed) versions of the
622
+ * `validateAndStoreEnqueuedNotesAndEvents` oracle.
623
+ */
624
+ async #processValidationRequests(
625
+ noteValidationRequests: NoteValidationRequest[],
626
+ eventValidationRequests: EventValidationRequest[],
627
+ scope: AztecAddress,
628
+ ) {
559
629
  const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
560
630
  const noteStorePromises = noteValidationRequests.map(request =>
561
631
  noteService.validateAndStoreNote(
@@ -586,22 +656,6 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
586
656
  );
587
657
 
588
658
  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
659
  }
606
660
 
607
661
  public async getLogsByTag(
@@ -621,18 +675,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
621
675
  await this.capsuleService.readCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, this.jobId, scope)
622
676
  ).map(LogRetrievalRequest.fromFields);
623
677
 
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
-
678
+ const logService = this.#createLogService();
636
679
  const maybeLogRetrievalResponses = await logService.fetchLogsByTag(contractAddress, logRetrievalRequests);
637
680
 
638
681
  // Requests are cleared once we're done.
@@ -654,6 +697,18 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
654
697
  );
655
698
  }
656
699
 
700
+ public async getLogsByTagV2(requestArrayBaseSlot: Fr): Promise<Fr> {
701
+ const logRetrievalRequests = this.ephemeralArrayService
702
+ .readArrayAt(requestArrayBaseSlot)
703
+ .map(LogRetrievalRequest.fromFields);
704
+ const logService = this.#createLogService();
705
+
706
+ const maybeLogRetrievalResponses = await logService.fetchLogsByTag(this.contractAddress, logRetrievalRequests);
707
+
708
+ return this.ephemeralArrayService.newArray(maybeLogRetrievalResponses.map(LogRetrievalResponse.toSerializedOption));
709
+ }
710
+
711
+ // Deprecated, only kept for backwards compatibility until Alpha v5 rolls out.
657
712
  public async getMessageContextsByTxHash(
658
713
  contractAddress: AztecAddress,
659
714
  messageContextRequestsArrayBaseSlot: Fr,
@@ -665,7 +720,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
665
720
  throw new Error(`Got a message context request from ${contractAddress}, expected ${this.contractAddress}`);
666
721
  }
667
722
 
668
- // TODO(@mverzilli): this is a prime example of where using a volatile array would make much more sense, we don't
723
+ // TODO(@mverzilli): this is a prime example of where using an ephemeral array would make much more sense, we don't
669
724
  // need scopes here, we just need a bit of shared memory to cross boundaries between Noir and TS.
670
725
  // At the same time, we don't want to allow any global scope access other than where backwards compatibility
671
726
  // forces us to. Hence we need the scope here to be artificial.
@@ -709,6 +764,27 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
709
764
  }
710
765
  }
711
766
 
767
+ /** Reads tx hash requests from an ephemeral array, resolves their contexts, and returns the response slot. */
768
+ public async getMessageContextsByTxHashV2(requestArrayBaseSlot: Fr): Promise<Fr> {
769
+ const requestFields = this.ephemeralArrayService.readArrayAt(requestArrayBaseSlot);
770
+
771
+ const txHashes = requestFields.map((fields, i) => {
772
+ if (fields.length !== 1) {
773
+ throw new Error(
774
+ `Malformed message context request at index ${i}: expected 1 field (tx hash), got ${fields.length}`,
775
+ );
776
+ }
777
+ return fields[0];
778
+ });
779
+
780
+ const maybeMessageContexts = await this.messageContextService.getMessageContextsByTxHash(
781
+ txHashes,
782
+ this.anchorBlockHeader.getBlockNumber(),
783
+ );
784
+
785
+ return this.ephemeralArrayService.newArray(maybeMessageContexts.map(MessageContext.toSerializedOption));
786
+ }
787
+
712
788
  public setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], scope: AztecAddress): void {
713
789
  if (!contractAddress.equals(this.contractAddress)) {
714
790
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
@@ -785,6 +861,34 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
785
861
  return deriveAppSiloedSharedSecret(addressSecret, ephPk, this.contractAddress);
786
862
  }
787
863
 
864
+ public pushEphemeral(slot: Fr, elements: Fr[]): number {
865
+ return this.ephemeralArrayService.push(slot, elements);
866
+ }
867
+
868
+ public popEphemeral(slot: Fr): Fr[] {
869
+ return this.ephemeralArrayService.pop(slot);
870
+ }
871
+
872
+ public getEphemeral(slot: Fr, index: number): Fr[] {
873
+ return this.ephemeralArrayService.get(slot, index);
874
+ }
875
+
876
+ public setEphemeral(slot: Fr, index: number, elements: Fr[]): void {
877
+ this.ephemeralArrayService.set(slot, index, elements);
878
+ }
879
+
880
+ public getEphemeralLen(slot: Fr): number {
881
+ return this.ephemeralArrayService.len(slot);
882
+ }
883
+
884
+ public removeEphemeral(slot: Fr, index: number): void {
885
+ this.ephemeralArrayService.remove(slot, index);
886
+ }
887
+
888
+ public clearEphemeral(slot: Fr): void {
889
+ this.ephemeralArrayService.clear(slot);
890
+ }
891
+
788
892
  public emitOffchainEffect(data: Fr[]): Promise<void> {
789
893
  this.offchainEffects.push({ data, contractAddress: this.contractAddress });
790
894
  return Promise.resolve();
@@ -85,9 +85,24 @@ interface ContainsNote {
85
85
  }
86
86
 
87
87
  const selectPropertyFromPackedNoteContent = (noteData: Fr[], selector: PropertySelector): Fr => {
88
+ if (selector.index >= noteData.length) {
89
+ throw new Error(`Property selector index ${selector.index} out of bounds for note with ${noteData.length} fields`);
90
+ }
91
+ if (selector.offset + selector.length > Fr.SIZE_IN_BYTES) {
92
+ throw new Error(
93
+ `Property selector range (offset=${selector.offset}, length=${selector.length}) exceeds Fr buffer size of ${Fr.SIZE_IN_BYTES} bytes`,
94
+ );
95
+ }
88
96
  const noteValueBuffer = noteData[selector.index].toBuffer();
89
- const noteValue = noteValueBuffer.subarray(selector.offset, selector.offset + selector.length);
90
- return Fr.fromBuffer(noteValue);
97
+ // Noir's PropertySelector counts offset from the LSB (last byte of the big-endian buffer),
98
+ // so offset=0,length=Fr.SIZE_IN_BYTES reads the entire field, and offset=0,length=1 reads the last byte.
99
+ const start = Fr.SIZE_IN_BYTES - selector.offset - selector.length;
100
+ const end = Fr.SIZE_IN_BYTES - selector.offset;
101
+ const noteValue = noteValueBuffer.subarray(start, end);
102
+ // Left-pad to Fr.SIZE_IN_BYTES so Fr.fromBuffer interprets the value correctly.
103
+ const padded = Buffer.alloc(Fr.SIZE_IN_BYTES);
104
+ noteValue.copy(padded, Fr.SIZE_IN_BYTES - noteValue.length);
105
+ return Fr.fromBuffer(padded);
91
106
  };
92
107
 
93
108
  const selectNotes = <T extends ContainsNote>(noteDatas: T[], selects: Select[]): T[] =>
@@ -103,7 +118,11 @@ const selectNotes = <T extends ContainsNote>(noteDatas: T[], selects: Select[]):
103
118
  [Comparator.GTE]: () => !noteValueFr.lt(value),
104
119
  };
105
120
 
106
- return comparatorSelector[comparator]();
121
+ const fn = comparatorSelector[comparator];
122
+ if (!fn) {
123
+ throw new Error(`Invalid comparator value: ${comparator}`);
124
+ }
125
+ return fn();
107
126
  }),
108
127
  );
109
128
 
@@ -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
  }