@aztec/pxe 0.0.1-commit.d6f2b3f94 → 0.0.1-commit.e2b2873ed

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 (53) hide show
  1. package/dest/contract_function_simulator/contract_function_simulator.d.ts +48 -26
  2. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  3. package/dest/contract_function_simulator/contract_function_simulator.js +63 -29
  4. package/dest/contract_function_simulator/oracle/interfaces.d.ts +2 -2
  5. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  6. package/dest/contract_function_simulator/oracle/oracle.d.ts +2 -2
  7. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  8. package/dest/contract_function_simulator/oracle/oracle.js +2 -2
  9. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +34 -36
  10. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  11. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +71 -18
  12. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +29 -12
  13. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  14. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +31 -28
  15. package/dest/contract_sync/contract_sync_service.d.ts +3 -2
  16. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  17. package/dest/contract_sync/contract_sync_service.js +32 -17
  18. package/dest/debug/pxe_debug_utils.d.ts +1 -1
  19. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  20. package/dest/debug/pxe_debug_utils.js +1 -1
  21. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  22. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  23. package/dest/entrypoints/client/bundle/utils.js +9 -1
  24. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  25. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  26. package/dest/entrypoints/client/lazy/utils.js +9 -1
  27. package/dest/entrypoints/server/utils.js +9 -1
  28. package/dest/logs/log_service.d.ts +1 -1
  29. package/dest/logs/log_service.d.ts.map +1 -1
  30. package/dest/logs/log_service.js +4 -9
  31. package/dest/oracle_version.d.ts +2 -2
  32. package/dest/oracle_version.js +2 -2
  33. package/dest/pxe.d.ts +56 -22
  34. package/dest/pxe.d.ts.map +1 -1
  35. package/dest/pxe.js +37 -32
  36. package/dest/storage/note_store/note_store.d.ts +1 -2
  37. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  38. package/dest/storage/note_store/note_store.js +1 -2
  39. package/package.json +16 -16
  40. package/src/contract_function_simulator/contract_function_simulator.ts +107 -72
  41. package/src/contract_function_simulator/oracle/interfaces.ts +1 -1
  42. package/src/contract_function_simulator/oracle/oracle.ts +2 -2
  43. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +91 -93
  44. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +67 -25
  45. package/src/contract_sync/contract_sync_service.ts +41 -25
  46. package/src/debug/pxe_debug_utils.ts +3 -2
  47. package/src/entrypoints/client/bundle/utils.ts +9 -1
  48. package/src/entrypoints/client/lazy/utils.ts +9 -1
  49. package/src/entrypoints/server/utils.ts +7 -7
  50. package/src/logs/log_service.ts +4 -13
  51. package/src/oracle_version.ts +2 -2
  52. package/src/pxe.ts +98 -70
  53. package/src/storage/note_store/note_store.ts +1 -2
@@ -90,52 +90,89 @@ import { executePrivateFunction } from './oracle/private_execution.js';
90
90
  import { PrivateExecutionOracle } from './oracle/private_execution_oracle.js';
91
91
  import { UtilityExecutionOracle } from './oracle/utility_execution_oracle.js';
92
92
 
93
+ /** Options for ContractFunctionSimulator.run. */
94
+ export type ContractSimulatorRunOpts = {
95
+ /** The address of the contract (should match request.origin). */
96
+ contractAddress: AztecAddress;
97
+ /** The function selector of the entry point. */
98
+ selector: FunctionSelector;
99
+ /** The address calling the function. Can be replaced to simulate a call from another contract or account. */
100
+ msgSender?: AztecAddress;
101
+ /** The block header to use as base state for this run. */
102
+ anchorBlockHeader: BlockHeader;
103
+ /** The address used as a tagging sender when emitting private logs. */
104
+ senderForTags?: AztecAddress;
105
+ /** The accounts whose notes we can access in this call. Defaults to all. */
106
+ scopes?: AztecAddress[];
107
+ /** The job ID for staged writes. */
108
+ jobId: string;
109
+ };
110
+
111
+ /** Args for ContractFunctionSimulator constructor. */
112
+ export type ContractFunctionSimulatorArgs = {
113
+ contractStore: ContractStore;
114
+ noteStore: NoteStore;
115
+ keyStore: KeyStore;
116
+ addressStore: AddressStore;
117
+ aztecNode: AztecNode;
118
+ senderTaggingStore: SenderTaggingStore;
119
+ recipientTaggingStore: RecipientTaggingStore;
120
+ senderAddressBookStore: SenderAddressBookStore;
121
+ capsuleStore: CapsuleStore;
122
+ privateEventStore: PrivateEventStore;
123
+ simulator: CircuitSimulator;
124
+ contractSyncService: ContractSyncService;
125
+ };
126
+
93
127
  /**
94
128
  * The contract function simulator.
95
129
  */
96
130
  export class ContractFunctionSimulator {
97
- private log: Logger;
98
-
99
- constructor(
100
- private contractStore: ContractStore,
101
- private noteStore: NoteStore,
102
- private keyStore: KeyStore,
103
- private addressStore: AddressStore,
104
- private aztecNode: AztecNode,
105
- private senderTaggingStore: SenderTaggingStore,
106
- private recipientTaggingStore: RecipientTaggingStore,
107
- private senderAddressBookStore: SenderAddressBookStore,
108
- private capsuleStore: CapsuleStore,
109
- private privateEventStore: PrivateEventStore,
110
- private simulator: CircuitSimulator,
111
- private contractSyncService: ContractSyncService,
112
- ) {
131
+ private readonly log: Logger;
132
+ private readonly contractStore: ContractStore;
133
+ private readonly noteStore: NoteStore;
134
+ private readonly keyStore: KeyStore;
135
+ private readonly addressStore: AddressStore;
136
+ private readonly aztecNode: AztecNode;
137
+ private readonly senderTaggingStore: SenderTaggingStore;
138
+ private readonly recipientTaggingStore: RecipientTaggingStore;
139
+ private readonly senderAddressBookStore: SenderAddressBookStore;
140
+ private readonly capsuleStore: CapsuleStore;
141
+ private readonly privateEventStore: PrivateEventStore;
142
+ private readonly simulator: CircuitSimulator;
143
+ private readonly contractSyncService: ContractSyncService;
144
+
145
+ constructor(args: ContractFunctionSimulatorArgs) {
146
+ this.contractStore = args.contractStore;
147
+ this.noteStore = args.noteStore;
148
+ this.keyStore = args.keyStore;
149
+ this.addressStore = args.addressStore;
150
+ this.aztecNode = args.aztecNode;
151
+ this.senderTaggingStore = args.senderTaggingStore;
152
+ this.recipientTaggingStore = args.recipientTaggingStore;
153
+ this.senderAddressBookStore = args.senderAddressBookStore;
154
+ this.capsuleStore = args.capsuleStore;
155
+ this.privateEventStore = args.privateEventStore;
156
+ this.simulator = args.simulator;
157
+ this.contractSyncService = args.contractSyncService;
113
158
  this.log = createLogger('simulator');
114
159
  }
115
160
 
116
161
  /**
117
162
  * Runs a private function.
118
163
  * @param request - The transaction request.
119
- * @param entryPointArtifact - The artifact of the entry point function.
120
- * @param contractAddress - The address of the contract (should match request.origin)
121
- * @param msgSender - The address calling the function. This can be replaced to simulate a call from another contract
122
- * or a specific account.
123
- * @param anchorBlockHeader - The block header to use as base state for this run.
124
- * @param senderForTags - The address that is used as a tagging sender when emitting private logs. Returned from
125
- * the `privateGetSenderForTags` oracle.
126
- * @param scopes - The accounts whose notes we can access in this call. Currently optional and will default to all.
127
- * @param jobId - The job ID for staged writes.
128
- * @returns The result of the execution.
129
164
  */
130
165
  public async run(
131
166
  request: TxExecutionRequest,
132
- contractAddress: AztecAddress,
133
- selector: FunctionSelector,
134
- msgSender = AztecAddress.fromField(Fr.MAX_FIELD_VALUE),
135
- anchorBlockHeader: BlockHeader,
136
- senderForTags: AztecAddress | undefined,
137
- scopes: AztecAddress[] | undefined,
138
- jobId: string,
167
+ {
168
+ contractAddress,
169
+ selector,
170
+ msgSender = AztecAddress.fromField(Fr.MAX_FIELD_VALUE),
171
+ anchorBlockHeader,
172
+ senderForTags,
173
+ scopes,
174
+ jobId,
175
+ }: ContractSimulatorRunOpts,
139
176
  ): Promise<PrivateExecutionResult> {
140
177
  const simulatorSetupTimer = new Timer();
141
178
 
@@ -165,38 +202,37 @@ export class ContractFunctionSimulator {
165
202
  const noteCache = new ExecutionNoteCache(protocolNullifier);
166
203
  const taggingIndexCache = new ExecutionTaggingIndexCache();
167
204
 
168
- const privateExecutionOracle = new PrivateExecutionOracle(
169
- request.firstCallArgsHash,
170
- request.txContext,
205
+ const privateExecutionOracle = new PrivateExecutionOracle({
206
+ argsHash: request.firstCallArgsHash,
207
+ txContext: request.txContext,
171
208
  callContext,
172
209
  anchorBlockHeader,
173
- async call => {
174
- await this.runUtility(call, [], anchorBlockHeader, scopes, jobId);
210
+ utilityExecutor: async (call, execScopes) => {
211
+ await this.runUtility(call, [], anchorBlockHeader, execScopes, jobId);
175
212
  },
176
- request.authWitnesses,
177
- request.capsules,
178
- HashedValuesCache.create(request.argsOfCalls),
213
+ authWitnesses: request.authWitnesses,
214
+ capsules: request.capsules,
215
+ executionCache: HashedValuesCache.create(request.argsOfCalls),
179
216
  noteCache,
180
217
  taggingIndexCache,
181
- this.contractStore,
182
- this.noteStore,
183
- this.keyStore,
184
- this.addressStore,
185
- this.aztecNode,
186
- this.senderTaggingStore,
187
- this.recipientTaggingStore,
188
- this.senderAddressBookStore,
189
- this.capsuleStore,
190
- this.privateEventStore,
191
- this.contractSyncService,
218
+ contractStore: this.contractStore,
219
+ noteStore: this.noteStore,
220
+ keyStore: this.keyStore,
221
+ addressStore: this.addressStore,
222
+ aztecNode: this.aztecNode,
223
+ senderTaggingStore: this.senderTaggingStore,
224
+ recipientTaggingStore: this.recipientTaggingStore,
225
+ senderAddressBookStore: this.senderAddressBookStore,
226
+ capsuleStore: this.capsuleStore,
227
+ privateEventStore: this.privateEventStore,
228
+ contractSyncService: this.contractSyncService,
192
229
  jobId,
193
- 0, // totalPublicArgsCount
194
- startSideEffectCounter,
195
- undefined, // log
230
+ totalPublicCalldataCount: 0,
231
+ sideEffectCounter: startSideEffectCounter,
196
232
  scopes,
197
233
  senderForTags,
198
- this.simulator,
199
- );
234
+ simulator: this.simulator,
235
+ });
200
236
 
201
237
  const setupTime = simulatorSetupTimer.ms();
202
238
 
@@ -269,24 +305,23 @@ export class ContractFunctionSimulator {
269
305
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
270
306
  }
271
307
 
272
- const oracle = new UtilityExecutionOracle(
273
- call.to,
274
- authwits,
275
- [],
308
+ const oracle = new UtilityExecutionOracle({
309
+ contractAddress: call.to,
310
+ authWitnesses: authwits,
311
+ capsules: [],
276
312
  anchorBlockHeader,
277
- this.contractStore,
278
- this.noteStore,
279
- this.keyStore,
280
- this.addressStore,
281
- this.aztecNode,
282
- this.recipientTaggingStore,
283
- this.senderAddressBookStore,
284
- this.capsuleStore,
285
- this.privateEventStore,
313
+ contractStore: this.contractStore,
314
+ noteStore: this.noteStore,
315
+ keyStore: this.keyStore,
316
+ addressStore: this.addressStore,
317
+ aztecNode: this.aztecNode,
318
+ recipientTaggingStore: this.recipientTaggingStore,
319
+ senderAddressBookStore: this.senderAddressBookStore,
320
+ capsuleStore: this.capsuleStore,
321
+ privateEventStore: this.privateEventStore,
286
322
  jobId,
287
- undefined,
288
323
  scopes,
289
- );
324
+ });
290
325
 
291
326
  try {
292
327
  this.log.verbose(`Executing utility function ${entryPointArtifact.name}`, {
@@ -54,7 +54,7 @@ export interface IMiscOracle {
54
54
 
55
55
  utilityGetRandomField(): Fr;
56
56
  utilityAssertCompatibleOracleVersion(version: number): void;
57
- utilityDebugLog(level: number, message: string, fields: Fr[]): Promise<void>;
57
+ utilityLog(level: number, message: string, fields: Fr[]): Promise<void>;
58
58
  }
59
59
 
60
60
  /**
@@ -417,7 +417,7 @@ export class Oracle {
417
417
  return Promise.resolve([]);
418
418
  }
419
419
 
420
- async utilityDebugLog(
420
+ async utilityLog(
421
421
  level: ACVMField[],
422
422
  message: ACVMField[],
423
423
  _ignoredFieldsSize: ACVMField[],
@@ -426,7 +426,7 @@ export class Oracle {
426
426
  const levelFr = Fr.fromString(level[0]);
427
427
  const messageStr = message.map(acvmField => String.fromCharCode(Fr.fromString(acvmField).toNumber())).join('');
428
428
  const fieldsFr = fields.map(Fr.fromString);
429
- await this.handlerAsMisc().utilityDebugLog(levelFr.toNumber(), messageStr, fieldsFr);
429
+ await this.handlerAsMisc().utilityLog(levelFr.toNumber(), messageStr, fieldsFr);
430
430
  return [];
431
431
  }
432
432
 
@@ -2,7 +2,6 @@ import { MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS, PRIVATE_CONTEXT_INPUTS_LENGTH }
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import { Timer } from '@aztec/foundation/timer';
5
- import type { KeyStore } from '@aztec/key-store';
6
5
  import { type CircuitSimulator, toACVMWitness } from '@aztec/simulator/client';
7
6
  import {
8
7
  type FunctionAbi,
@@ -12,18 +11,14 @@ import {
12
11
  type NoteSelector,
13
12
  countArgumentsSize,
14
13
  } from '@aztec/stdlib/abi';
15
- import type { AuthWitness } from '@aztec/stdlib/auth-witness';
16
14
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
17
15
  import { siloNullifier } from '@aztec/stdlib/hash';
18
- import type { AztecNode } from '@aztec/stdlib/interfaces/client';
19
16
  import { PrivateContextInputs } from '@aztec/stdlib/kernel';
20
17
  import { type ContractClassLog, DirectionalAppTaggingSecret, type PreTag } from '@aztec/stdlib/logs';
21
18
  import { Tag } from '@aztec/stdlib/logs';
22
19
  import { Note, type NoteStatus } from '@aztec/stdlib/note';
23
20
  import {
24
- type BlockHeader,
25
21
  CallContext,
26
- Capsule,
27
22
  CountedContractClassLog,
28
23
  NoteAndSlot,
29
24
  PrivateCallExecutionResult,
@@ -32,13 +27,6 @@ import {
32
27
 
33
28
  import type { ContractSyncService } from '../../contract_sync/contract_sync_service.js';
34
29
  import { NoteService } from '../../notes/note_service.js';
35
- import type { AddressStore } from '../../storage/address_store/address_store.js';
36
- import type { CapsuleStore } from '../../storage/capsule_store/capsule_store.js';
37
- import type { ContractStore } from '../../storage/contract_store/contract_store.js';
38
- import type { NoteStore } from '../../storage/note_store/note_store.js';
39
- import type { PrivateEventStore } from '../../storage/private_event_store/private_event_store.js';
40
- import type { RecipientTaggingStore } from '../../storage/tagging_store/recipient_tagging_store.js';
41
- import type { SenderAddressBookStore } from '../../storage/tagging_store/sender_address_book_store.js';
42
30
  import type { SenderTaggingStore } from '../../storage/tagging_store/sender_tagging_store.js';
43
31
  import { syncSenderTaggingIndexes } from '../../tagging/index.js';
44
32
  import type { ExecutionNoteCache } from '../execution_note_cache.js';
@@ -47,7 +35,25 @@ import type { HashedValuesCache } from '../hashed_values_cache.js';
47
35
  import { pickNotes } from '../pick_notes.js';
48
36
  import type { IPrivateExecutionOracle, NoteData } from './interfaces.js';
49
37
  import { executePrivateFunction } from './private_execution.js';
50
- import { UtilityExecutionOracle } from './utility_execution_oracle.js';
38
+ import { UtilityExecutionOracle, type UtilityExecutionOracleArgs } from './utility_execution_oracle.js';
39
+
40
+ /** Args for PrivateExecutionOracle constructor. */
41
+ export type PrivateExecutionOracleArgs = Omit<UtilityExecutionOracleArgs, 'contractAddress'> & {
42
+ argsHash: Fr;
43
+ txContext: TxContext;
44
+ callContext: CallContext;
45
+ /** Needed to trigger contract synchronization before nested calls */
46
+ utilityExecutor: (call: FunctionCall, scopes: undefined | AztecAddress[]) => Promise<void>;
47
+ executionCache: HashedValuesCache;
48
+ noteCache: ExecutionNoteCache;
49
+ taggingIndexCache: ExecutionTaggingIndexCache;
50
+ senderTaggingStore: SenderTaggingStore;
51
+ contractSyncService: ContractSyncService;
52
+ totalPublicCalldataCount?: number;
53
+ sideEffectCounter?: number;
54
+ senderForTags?: AztecAddress;
55
+ simulator?: CircuitSimulator;
56
+ };
51
57
 
52
58
  /**
53
59
  * The execution oracle for the private part of a transaction.
@@ -69,57 +75,39 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
69
75
  private offchainEffects: { data: Fr[] }[] = [];
70
76
  private nestedExecutionResults: PrivateCallExecutionResult[] = [];
71
77
 
72
- constructor(
73
- private readonly argsHash: Fr,
74
- private readonly txContext: TxContext,
75
- private readonly callContext: CallContext,
76
- /** Header of a block whose state is used during private execution (not the block the transaction is included in). */
77
- protected override readonly anchorBlockHeader: BlockHeader,
78
- /** Needed to trigger contract synchronization before nested calls */
79
- private readonly utilityExecutor: (call: FunctionCall) => Promise<void>,
80
- /** List of transient auth witnesses to be used during this simulation */
81
- authWitnesses: AuthWitness[],
82
- capsules: Capsule[],
83
- private readonly executionCache: HashedValuesCache,
84
- private readonly noteCache: ExecutionNoteCache,
85
- private readonly taggingIndexCache: ExecutionTaggingIndexCache,
86
- contractStore: ContractStore,
87
- noteStore: NoteStore,
88
- keyStore: KeyStore,
89
- addressStore: AddressStore,
90
- aztecNode: AztecNode,
91
- private readonly senderTaggingStore: SenderTaggingStore,
92
- recipientTaggingStore: RecipientTaggingStore,
93
- senderAddressBookStore: SenderAddressBookStore,
94
- capsuleStore: CapsuleStore,
95
- privateEventStore: PrivateEventStore,
96
- private readonly contractSyncService: ContractSyncService,
97
- jobId: string,
98
- private totalPublicCalldataCount: number = 0,
99
- protected sideEffectCounter: number = 0,
100
- log = createLogger('simulator:client_execution_context'),
101
- scopes?: AztecAddress[],
102
- private senderForTags?: AztecAddress,
103
- private simulator?: CircuitSimulator,
104
- ) {
105
- super(
106
- callContext.contractAddress,
107
- authWitnesses,
108
- capsules,
109
- anchorBlockHeader,
110
- contractStore,
111
- noteStore,
112
- keyStore,
113
- addressStore,
114
- aztecNode,
115
- recipientTaggingStore,
116
- senderAddressBookStore,
117
- capsuleStore,
118
- privateEventStore,
119
- jobId,
120
- log,
121
- scopes,
122
- );
78
+ private readonly argsHash: Fr;
79
+ private readonly txContext: TxContext;
80
+ private readonly callContext: CallContext;
81
+ private readonly utilityExecutor: (call: FunctionCall, scopes: undefined | AztecAddress[]) => Promise<void>;
82
+ private readonly executionCache: HashedValuesCache;
83
+ private readonly noteCache: ExecutionNoteCache;
84
+ private readonly taggingIndexCache: ExecutionTaggingIndexCache;
85
+ private readonly senderTaggingStore: SenderTaggingStore;
86
+ private readonly contractSyncService: ContractSyncService;
87
+ private totalPublicCalldataCount: number;
88
+ protected sideEffectCounter: number;
89
+ private senderForTags?: AztecAddress;
90
+ private readonly simulator?: CircuitSimulator;
91
+
92
+ constructor(args: PrivateExecutionOracleArgs) {
93
+ super({
94
+ ...args,
95
+ contractAddress: args.callContext.contractAddress,
96
+ log: args.log ?? createLogger('simulator:client_execution_context'),
97
+ });
98
+ this.argsHash = args.argsHash;
99
+ this.txContext = args.txContext;
100
+ this.callContext = args.callContext;
101
+ this.utilityExecutor = args.utilityExecutor;
102
+ this.executionCache = args.executionCache;
103
+ this.noteCache = args.noteCache;
104
+ this.taggingIndexCache = args.taggingIndexCache;
105
+ this.senderTaggingStore = args.senderTaggingStore;
106
+ this.contractSyncService = args.contractSyncService;
107
+ this.totalPublicCalldataCount = args.totalPublicCalldataCount ?? 0;
108
+ this.sideEffectCounter = args.sideEffectCounter ?? 0;
109
+ this.senderForTags = args.senderForTags;
110
+ this.simulator = args.simulator;
123
111
  }
124
112
 
125
113
  public getPrivateContextInputs(): PrivateContextInputs {
@@ -538,12 +526,22 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
538
526
 
539
527
  isStaticCall = isStaticCall || this.callContext.isStaticCall;
540
528
 
529
+ // When scopes are set and the target contract is a registered account (has keys in the keyStore),
530
+ // expand scopes to include it so nested private calls can sync and read the contract's own notes.
531
+ // We only expand for registered accounts because the log service needs the recipient's keys to derive
532
+ // tagging secrets, which are only available for registered accounts.
533
+ const expandedScopes =
534
+ this.scopes && (await this.keyStore.hasAccount(targetContractAddress))
535
+ ? [...this.scopes, targetContractAddress]
536
+ : this.scopes;
537
+
541
538
  await this.contractSyncService.ensureContractSynced(
542
539
  targetContractAddress,
543
540
  functionSelector,
544
541
  this.utilityExecutor,
545
542
  this.anchorBlockHeader,
546
543
  this.jobId,
544
+ expandedScopes,
547
545
  );
548
546
 
549
547
  const targetArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(
@@ -555,41 +553,41 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
555
553
 
556
554
  const derivedCallContext = await this.deriveCallContext(targetContractAddress, targetArtifact, isStaticCall);
557
555
 
558
- const privateExecutionOracle = new PrivateExecutionOracle(
556
+ const privateExecutionOracle = new PrivateExecutionOracle({
559
557
  argsHash,
560
- derivedTxContext,
561
- derivedCallContext,
562
- this.anchorBlockHeader,
563
- this.utilityExecutor,
564
- this.authWitnesses,
565
- this.capsules,
566
- this.executionCache,
567
- this.noteCache,
568
- this.taggingIndexCache,
569
- this.contractStore,
570
- this.noteStore,
571
- this.keyStore,
572
- this.addressStore,
573
- this.aztecNode,
574
- this.senderTaggingStore,
575
- this.recipientTaggingStore,
576
- this.senderAddressBookStore,
577
- this.capsuleStore,
578
- this.privateEventStore,
579
- this.contractSyncService,
580
- this.jobId,
581
- this.totalPublicCalldataCount,
558
+ txContext: derivedTxContext,
559
+ callContext: derivedCallContext,
560
+ anchorBlockHeader: this.anchorBlockHeader,
561
+ utilityExecutor: this.utilityExecutor,
562
+ authWitnesses: this.authWitnesses,
563
+ capsules: this.capsules,
564
+ executionCache: this.executionCache,
565
+ noteCache: this.noteCache,
566
+ taggingIndexCache: this.taggingIndexCache,
567
+ contractStore: this.contractStore,
568
+ noteStore: this.noteStore,
569
+ keyStore: this.keyStore,
570
+ addressStore: this.addressStore,
571
+ aztecNode: this.aztecNode,
572
+ senderTaggingStore: this.senderTaggingStore,
573
+ recipientTaggingStore: this.recipientTaggingStore,
574
+ senderAddressBookStore: this.senderAddressBookStore,
575
+ capsuleStore: this.capsuleStore,
576
+ privateEventStore: this.privateEventStore,
577
+ contractSyncService: this.contractSyncService,
578
+ jobId: this.jobId,
579
+ totalPublicCalldataCount: this.totalPublicCalldataCount,
582
580
  sideEffectCounter,
583
- this.log,
584
- this.scopes,
585
- this.senderForTags,
586
- this.simulator,
587
- );
581
+ log: this.log,
582
+ scopes: expandedScopes,
583
+ senderForTags: this.senderForTags,
584
+ simulator: this.simulator!,
585
+ });
588
586
 
589
587
  const setupTime = simulatorSetupTimer.ms();
590
588
 
591
589
  const childExecutionResult = await executePrivateFunction(
592
- this.simulator,
590
+ this.simulator!,
593
591
  privateExecutionOracle,
594
592
  targetArtifact,
595
593
  targetContractAddress,
@@ -40,6 +40,27 @@ import { pickNotes } from '../pick_notes.js';
40
40
  import type { IMiscOracle, IUtilityExecutionOracle, NoteData } from './interfaces.js';
41
41
  import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
42
42
 
43
+ /** Args for UtilityExecutionOracle constructor. */
44
+ export type UtilityExecutionOracleArgs = {
45
+ contractAddress: AztecAddress;
46
+ /** List of transient auth witnesses to be used during this simulation */
47
+ authWitnesses: AuthWitness[];
48
+ capsules: Capsule[]; // TODO(#12425): Rename to transientCapsules
49
+ anchorBlockHeader: BlockHeader;
50
+ contractStore: ContractStore;
51
+ noteStore: NoteStore;
52
+ keyStore: KeyStore;
53
+ addressStore: AddressStore;
54
+ aztecNode: AztecNode;
55
+ recipientTaggingStore: RecipientTaggingStore;
56
+ senderAddressBookStore: SenderAddressBookStore;
57
+ capsuleStore: CapsuleStore;
58
+ privateEventStore: PrivateEventStore;
59
+ jobId: string;
60
+ log?: ReturnType<typeof createLogger>;
61
+ scopes?: AztecAddress[];
62
+ };
63
+
43
64
  /**
44
65
  * The oracle for an execution of utility contract functions.
45
66
  */
@@ -49,25 +70,41 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
49
70
 
50
71
  private contractLogger: Logger | undefined;
51
72
 
52
- constructor(
53
- protected readonly contractAddress: AztecAddress,
54
- /** List of transient auth witnesses to be used during this simulation */
55
- protected readonly authWitnesses: AuthWitness[],
56
- protected readonly capsules: Capsule[], // TODO(#12425): Rename to transientCapsules
57
- protected readonly anchorBlockHeader: BlockHeader,
58
- protected readonly contractStore: ContractStore,
59
- protected readonly noteStore: NoteStore,
60
- protected readonly keyStore: KeyStore,
61
- protected readonly addressStore: AddressStore,
62
- protected readonly aztecNode: AztecNode,
63
- protected readonly recipientTaggingStore: RecipientTaggingStore,
64
- protected readonly senderAddressBookStore: SenderAddressBookStore,
65
- protected readonly capsuleStore: CapsuleStore,
66
- protected readonly privateEventStore: PrivateEventStore,
67
- protected readonly jobId: string,
68
- protected log = createLogger('simulator:client_view_context'),
69
- protected readonly scopes?: AztecAddress[],
70
- ) {}
73
+ protected readonly contractAddress: AztecAddress;
74
+ protected readonly authWitnesses: AuthWitness[];
75
+ protected readonly capsules: Capsule[];
76
+ protected readonly anchorBlockHeader: BlockHeader;
77
+ protected readonly contractStore: ContractStore;
78
+ protected readonly noteStore: NoteStore;
79
+ protected readonly keyStore: KeyStore;
80
+ protected readonly addressStore: AddressStore;
81
+ protected readonly aztecNode: AztecNode;
82
+ protected readonly recipientTaggingStore: RecipientTaggingStore;
83
+ protected readonly senderAddressBookStore: SenderAddressBookStore;
84
+ protected readonly capsuleStore: CapsuleStore;
85
+ protected readonly privateEventStore: PrivateEventStore;
86
+ protected readonly jobId: string;
87
+ protected log: ReturnType<typeof createLogger>;
88
+ protected readonly scopes?: AztecAddress[];
89
+
90
+ constructor(args: UtilityExecutionOracleArgs) {
91
+ this.contractAddress = args.contractAddress;
92
+ this.authWitnesses = args.authWitnesses;
93
+ this.capsules = args.capsules;
94
+ this.anchorBlockHeader = args.anchorBlockHeader;
95
+ this.contractStore = args.contractStore;
96
+ this.noteStore = args.noteStore;
97
+ this.keyStore = args.keyStore;
98
+ this.addressStore = args.addressStore;
99
+ this.aztecNode = args.aztecNode;
100
+ this.recipientTaggingStore = args.recipientTaggingStore;
101
+ this.senderAddressBookStore = args.senderAddressBookStore;
102
+ this.capsuleStore = args.capsuleStore;
103
+ this.privateEventStore = args.privateEventStore;
104
+ this.jobId = args.jobId;
105
+ this.log = args.log ?? createLogger('simulator:client_view_context');
106
+ this.scopes = args.scopes;
107
+ }
71
108
 
72
109
  public utilityAssertCompatibleOracleVersion(version: number): void {
73
110
  if (version !== ORACLE_VERSION) {
@@ -91,11 +128,16 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
91
128
  * @throws If scopes are defined and the account is not in the scopes.
92
129
  */
93
130
  public async utilityGetKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
94
- // If scopes are defined, check that the key belongs to an account in the scopes
131
+ // If scopes are defined, check that the key belongs to an account in the scopes.
95
132
  if (this.scopes && this.scopes.length > 0) {
96
- const [, account] = await this.keyStore.getKeyPrefixAndAccount(pkMHash);
97
- if (!this.scopes.some(scope => scope.equals(account))) {
98
- throw new Error(`Key validation request denied: account ${account.toString()} is not in the allowed scopes.`);
133
+ let hasAccess = false;
134
+ for (let i = 0; i < this.scopes.length && !hasAccess; i++) {
135
+ if (await this.keyStore.accountHasKey(this.scopes[i], pkMHash)) {
136
+ hasAccess = true;
137
+ }
138
+ }
139
+ if (!hasAccess) {
140
+ throw new Error(`Key validation request denied: no scoped account has a key with hash ${pkMHash.toString()}.`);
99
141
  }
100
142
  }
101
143
  return this.keyStore.getKeyValidationRequest(pkMHash, this.contractAddress);
@@ -369,9 +411,9 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
369
411
  return this.contractLogger;
370
412
  }
371
413
 
372
- public async utilityDebugLog(level: number, message: string, fields: Fr[]): Promise<void> {
414
+ public async utilityLog(level: number, message: string, fields: Fr[]): Promise<void> {
373
415
  if (!LogLevels[level]) {
374
- throw new Error(`Invalid debug log level: ${level}`);
416
+ throw new Error(`Invalid log level: ${level}`);
375
417
  }
376
418
  const levelName = LogLevels[level];
377
419
  const logger = await this.#getContractLogger();