@aztec/pxe 0.0.1-commit.6d63667d → 0.0.1-commit.858058eac

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 (47) hide show
  1. package/dest/contract_function_simulator/contract_function_simulator.d.ts +49 -27
  2. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  3. package/dest/contract_function_simulator/contract_function_simulator.js +65 -31
  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 +3 -3
  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 +62 -17
  12. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +30 -11
  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 +44 -28
  15. package/dest/debug/pxe_debug_utils.d.ts +2 -4
  16. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  17. package/dest/debug/pxe_debug_utils.js +0 -3
  18. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  19. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  20. package/dest/entrypoints/client/bundle/utils.js +9 -1
  21. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  22. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  23. package/dest/entrypoints/client/lazy/utils.js +9 -1
  24. package/dest/entrypoints/server/utils.js +9 -1
  25. package/dest/oracle_version.d.ts +2 -2
  26. package/dest/oracle_version.js +2 -2
  27. package/dest/pxe.d.ts +63 -22
  28. package/dest/pxe.d.ts.map +1 -1
  29. package/dest/pxe.js +42 -28
  30. package/dest/storage/contract_store/contract_store.js +5 -5
  31. package/dest/storage/note_store/note_store.d.ts +1 -1
  32. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  33. package/dest/storage/note_store/note_store.js +3 -0
  34. package/package.json +16 -16
  35. package/src/contract_function_simulator/contract_function_simulator.ts +108 -73
  36. package/src/contract_function_simulator/oracle/interfaces.ts +1 -1
  37. package/src/contract_function_simulator/oracle/oracle.ts +3 -3
  38. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +81 -93
  39. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +85 -27
  40. package/src/debug/pxe_debug_utils.ts +1 -6
  41. package/src/entrypoints/client/bundle/utils.ts +9 -1
  42. package/src/entrypoints/client/lazy/utils.ts +9 -1
  43. package/src/entrypoints/server/utils.ts +7 -7
  44. package/src/oracle_version.ts +2 -2
  45. package/src/pxe.ts +98 -59
  46. package/src/storage/contract_store/contract_store.ts +4 -4
  47. package/src/storage/note_store/note_store.ts +4 -0
@@ -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 => {
210
+ utilityExecutor: async call => {
174
211
  await this.runUtility(call, [], anchorBlockHeader, scopes, 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}`, {
@@ -359,7 +394,7 @@ class OrderedSideEffect<T> {
359
394
  */
360
395
  export async function generateSimulatedProvingResult(
361
396
  privateExecutionResult: PrivateExecutionResult,
362
- contractStore: ContractStore,
397
+ debugFunctionNameGetter: (contractAddress: AztecAddress, functionSelector: FunctionSelector) => Promise<string>,
363
398
  minRevertibleSideEffectCounterOverride?: number,
364
399
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
365
400
  const siloedNoteHashes: OrderedSideEffect<Fr>[] = [];
@@ -440,7 +475,7 @@ export async function generateSimulatedProvingResult(
440
475
  : execution.publicInputs.publicTeardownCallRequest;
441
476
 
442
477
  executionSteps.push({
443
- functionName: await contractStore.getDebugFunctionName(
478
+ functionName: await debugFunctionNameGetter(
444
479
  execution.publicInputs.callContext.contractAddress,
445
480
  execution.publicInputs.callContext.functionSelector,
446
481
  ),
@@ -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[]): 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
- utilityDebugLog(
420
+ async utilityLog(
421
421
  level: ACVMField[],
422
422
  message: ACVMField[],
423
423
  _ignoredFieldsSize: ACVMField[],
@@ -426,8 +426,8 @@ 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
- this.handlerAsMisc().utilityDebugLog(levelFr.toNumber(), messageStr, fieldsFr);
430
- return Promise.resolve([]);
429
+ await this.handlerAsMisc().utilityLog(levelFr.toNumber(), messageStr, fieldsFr);
430
+ return [];
431
431
  }
432
432
 
433
433
  // This function's name is directly hardcoded in `circuit_recorder.ts`. Don't forget to update it there if you
@@ -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) => 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) => 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 {
@@ -555,41 +543,41 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
555
543
 
556
544
  const derivedCallContext = await this.deriveCallContext(targetContractAddress, targetArtifact, isStaticCall);
557
545
 
558
- const privateExecutionOracle = new PrivateExecutionOracle(
546
+ const privateExecutionOracle = new PrivateExecutionOracle({
559
547
  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,
548
+ txContext: derivedTxContext,
549
+ callContext: derivedCallContext,
550
+ anchorBlockHeader: this.anchorBlockHeader,
551
+ utilityExecutor: this.utilityExecutor,
552
+ authWitnesses: this.authWitnesses,
553
+ capsules: this.capsules,
554
+ executionCache: this.executionCache,
555
+ noteCache: this.noteCache,
556
+ taggingIndexCache: this.taggingIndexCache,
557
+ contractStore: this.contractStore,
558
+ noteStore: this.noteStore,
559
+ keyStore: this.keyStore,
560
+ addressStore: this.addressStore,
561
+ aztecNode: this.aztecNode,
562
+ senderTaggingStore: this.senderTaggingStore,
563
+ recipientTaggingStore: this.recipientTaggingStore,
564
+ senderAddressBookStore: this.senderAddressBookStore,
565
+ capsuleStore: this.capsuleStore,
566
+ privateEventStore: this.privateEventStore,
567
+ contractSyncService: this.contractSyncService,
568
+ jobId: this.jobId,
569
+ totalPublicCalldataCount: this.totalPublicCalldataCount,
582
570
  sideEffectCounter,
583
- this.log,
584
- this.scopes,
585
- this.senderForTags,
586
- this.simulator,
587
- );
571
+ log: this.log,
572
+ scopes: this.scopes,
573
+ senderForTags: this.senderForTags,
574
+ simulator: this.simulator!,
575
+ });
588
576
 
589
577
  const setupTime = simulatorSetupTimer.ms();
590
578
 
591
579
  const childExecutionResult = await executePrivateFunction(
592
- this.simulator,
580
+ this.simulator!,
593
581
  privateExecutionOracle,
594
582
  targetArtifact,
595
583
  targetContractAddress,
@@ -3,7 +3,7 @@ import type { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  import { Aes128 } from '@aztec/foundation/crypto/aes128';
4
4
  import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import { Point } from '@aztec/foundation/curves/grumpkin';
6
- import { LogLevels, applyStringFormatting, createLogger } from '@aztec/foundation/log';
6
+ import { LogLevels, type Logger, applyStringFormatting, createLogger } from '@aztec/foundation/log';
7
7
  import type { MembershipWitness } from '@aztec/foundation/trees';
8
8
  import type { KeyStore } from '@aztec/key-store';
9
9
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
@@ -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
  */
@@ -47,27 +68,43 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
47
68
  isMisc = true as const;
48
69
  isUtility = true as const;
49
70
 
50
- private aztecNrDebugLog = createLogger('aztec-nr:debug_log');
51
-
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
- ) {}
71
+ private contractLogger: Logger | undefined;
72
+
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) {
@@ -297,8 +334,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
297
334
  * @returns A boolean indicating whether the nullifier exists in the tree or not.
298
335
  */
299
336
  public async utilityCheckNullifierExists(innerNullifier: Fr) {
300
- const nullifier = await siloNullifier(this.contractAddress, innerNullifier!);
301
- const [leafIndex] = await this.aztecNode.findLeavesIndexes('latest', MerkleTreeId.NULLIFIER_TREE, [nullifier]);
337
+ const [nullifier, anchorBlockHash] = await Promise.all([
338
+ siloNullifier(this.contractAddress, innerNullifier!),
339
+ this.anchorBlockHeader.hash(),
340
+ ]);
341
+ const [leafIndex] = await this.aztecNode.findLeavesIndexes(anchorBlockHash, MerkleTreeId.NULLIFIER_TREE, [
342
+ nullifier,
343
+ ]);
302
344
  return leafIndex?.data !== undefined;
303
345
  }
304
346
 
@@ -349,12 +391,28 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
349
391
  return values;
350
392
  }
351
393
 
352
- public utilityDebugLog(level: number, message: string, fields: Fr[]): void {
394
+ /**
395
+ * Returns a per-contract logger whose output is prefixed with `contract_log::<name>(<addrAbbrev>)`.
396
+ */
397
+ async #getContractLogger(): Promise<Logger> {
398
+ if (!this.contractLogger) {
399
+ const addrAbbrev = this.contractAddress.toString().slice(0, 10);
400
+ const name = await this.contractStore.getDebugContractName(this.contractAddress);
401
+ const module = name ? `contract_log::${name}(${addrAbbrev})` : `contract_log::${addrAbbrev}`;
402
+ // Purpose of instanceId is to distinguish logs from different instances of the same component. It makes sense
403
+ // to re-use jobId as instanceId here as executions of different PXE jobs are isolated.
404
+ this.contractLogger = createLogger(module, { instanceId: this.jobId });
405
+ }
406
+ return this.contractLogger;
407
+ }
408
+
409
+ public async utilityLog(level: number, message: string, fields: Fr[]): Promise<void> {
353
410
  if (!LogLevels[level]) {
354
- throw new Error(`Invalid debug log level: ${level}`);
411
+ throw new Error(`Invalid log level: ${level}`);
355
412
  }
356
413
  const levelName = LogLevels[level];
357
- this.aztecNrDebugLog[levelName](`${applyStringFormatting(message, fields)}`);
414
+ const logger = await this.#getContractLogger();
415
+ logger[levelName](`${applyStringFormatting(message, fields)}`);
358
416
  }
359
417
 
360
418
  public async utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr) {