@aztec/txe 0.0.1-fake-c83136db25 → 0.0.2-commit.217f559981

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 (81) hide show
  1. package/dest/bin/index.d.ts +1 -1
  2. package/dest/constants.d.ts +3 -0
  3. package/dest/constants.d.ts.map +1 -0
  4. package/dest/constants.js +2 -0
  5. package/dest/index.d.ts +1 -1
  6. package/dest/index.d.ts.map +1 -1
  7. package/dest/index.js +85 -52
  8. package/dest/oracle/interfaces.d.ts +12 -9
  9. package/dest/oracle/interfaces.d.ts.map +1 -1
  10. package/dest/oracle/txe_oracle_public_context.d.ts +7 -7
  11. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  12. package/dest/oracle/txe_oracle_public_context.js +10 -12
  13. package/dest/oracle/txe_oracle_top_level_context.d.ts +23 -14
  14. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  15. package/dest/oracle/txe_oracle_top_level_context.js +194 -87
  16. package/dest/rpc_translator.d.ts +35 -20
  17. package/dest/rpc_translator.d.ts.map +1 -1
  18. package/dest/rpc_translator.js +138 -64
  19. package/dest/state_machine/archiver.d.ts +21 -51
  20. package/dest/state_machine/archiver.d.ts.map +1 -1
  21. package/dest/state_machine/archiver.js +63 -94
  22. package/dest/state_machine/dummy_p2p_client.d.ts +20 -13
  23. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  24. package/dest/state_machine/dummy_p2p_client.js +41 -21
  25. package/dest/state_machine/global_variable_builder.d.ts +6 -4
  26. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  27. package/dest/state_machine/global_variable_builder.js +13 -1
  28. package/dest/state_machine/index.d.ts +7 -7
  29. package/dest/state_machine/index.d.ts.map +1 -1
  30. package/dest/state_machine/index.js +40 -23
  31. package/dest/state_machine/mock_epoch_cache.d.ts +14 -10
  32. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  33. package/dest/state_machine/mock_epoch_cache.js +21 -13
  34. package/dest/state_machine/synchronizer.d.ts +3 -2
  35. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  36. package/dest/state_machine/synchronizer.js +5 -4
  37. package/dest/txe_session.d.ts +21 -15
  38. package/dest/txe_session.d.ts.map +1 -1
  39. package/dest/txe_session.js +154 -53
  40. package/dest/util/encoding.d.ts +615 -16
  41. package/dest/util/encoding.d.ts.map +1 -1
  42. package/dest/util/encoding.js +1 -1
  43. package/dest/util/expected_failure_error.d.ts +1 -1
  44. package/dest/util/expected_failure_error.d.ts.map +1 -1
  45. package/dest/util/txe_account_store.d.ts +10 -0
  46. package/dest/util/txe_account_store.d.ts.map +1 -0
  47. package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
  48. package/dest/util/txe_public_contract_data_source.d.ts +8 -8
  49. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  50. package/dest/util/txe_public_contract_data_source.js +12 -29
  51. package/dest/utils/block_creation.d.ts +21 -6
  52. package/dest/utils/block_creation.d.ts.map +1 -1
  53. package/dest/utils/block_creation.js +38 -4
  54. package/dest/utils/tx_effect_creation.d.ts +3 -3
  55. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  56. package/dest/utils/tx_effect_creation.js +4 -7
  57. package/package.json +18 -17
  58. package/src/constants.ts +3 -0
  59. package/src/index.ts +97 -60
  60. package/src/oracle/interfaces.ts +11 -8
  61. package/src/oracle/txe_oracle_public_context.ts +12 -19
  62. package/src/oracle/txe_oracle_top_level_context.ts +229 -131
  63. package/src/rpc_translator.ts +164 -68
  64. package/src/state_machine/archiver.ts +63 -117
  65. package/src/state_machine/dummy_p2p_client.ts +58 -28
  66. package/src/state_machine/global_variable_builder.ts +22 -4
  67. package/src/state_machine/index.ts +60 -21
  68. package/src/state_machine/mock_epoch_cache.ts +25 -20
  69. package/src/state_machine/synchronizer.ts +6 -5
  70. package/src/txe_session.ts +210 -101
  71. package/src/util/encoding.ts +1 -1
  72. package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
  73. package/src/util/txe_public_contract_data_source.ts +20 -45
  74. package/src/utils/block_creation.ts +49 -14
  75. package/src/utils/tx_effect_creation.ts +5 -12
  76. package/dest/util/txe_account_data_provider.d.ts +0 -10
  77. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  78. package/dest/util/txe_contract_data_provider.d.ts +0 -12
  79. package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
  80. package/dest/util/txe_contract_data_provider.js +0 -22
  81. package/src/util/txe_contract_data_provider.ts +0 -36
@@ -1,5 +1,6 @@
1
1
  import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import type { L2Block } from '@aztec/stdlib/block';
4
5
  import type {
5
6
  MerkleTreeReadOperations,
@@ -12,7 +13,7 @@ import { NativeWorldStateService } from '@aztec/world-state/native';
12
13
 
13
14
  export class TXESynchronizer implements WorldStateSynchronizer {
14
15
  // This works when set to 1 as well.
15
- private blockNumber = 0;
16
+ private blockNumber = BlockNumber.ZERO;
16
17
 
17
18
  constructor(public nativeWorldStateService: NativeWorldStateService) {}
18
19
 
@@ -37,7 +38,7 @@ export class TXESynchronizer implements WorldStateSynchronizer {
37
38
  * @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
38
39
  * @returns A promise that resolves with the block number the world state was synced to
39
40
  */
40
- public syncImmediate(_minBlockNumber?: number, _skipThrowIfTargetNotReached?: boolean): Promise<number> {
41
+ public syncImmediate(_minBlockNumber?: BlockNumber, _skipThrowIfTargetNotReached?: boolean): Promise<BlockNumber> {
41
42
  return Promise.resolve(this.blockNumber);
42
43
  }
43
44
 
@@ -48,12 +49,12 @@ export class TXESynchronizer implements WorldStateSynchronizer {
48
49
 
49
50
  /** Forks the world state at the given block number, defaulting to the latest one. */
50
51
  public fork(block?: number): Promise<MerkleTreeWriteOperations> {
51
- return this.nativeWorldStateService.fork(block);
52
+ return this.nativeWorldStateService.fork(block ? BlockNumber(block) : undefined);
52
53
  }
53
54
 
54
55
  /** Gets a handle that allows reading the state as it was at the given block number. */
55
56
  public getSnapshot(blockNumber: number): MerkleTreeReadOperations {
56
- return this.nativeWorldStateService.getSnapshot(blockNumber);
57
+ return this.nativeWorldStateService.getSnapshot(BlockNumber(blockNumber));
57
58
  }
58
59
 
59
60
  /** Backups the db to the target path. */
@@ -1,15 +1,21 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
4
  import { KeyStore } from '@aztec/key-store';
4
5
  import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
5
- import type { ProtocolContract } from '@aztec/protocol-contracts';
6
+ import type { AccessScopes } from '@aztec/pxe/client/lazy';
6
7
  import {
7
- AddressDataProvider,
8
- CapsuleDataProvider,
9
- NoteDataProvider,
10
- PXEOracleInterface,
11
- PrivateEventDataProvider,
12
- TaggingDataProvider,
8
+ AddressStore,
9
+ AnchorBlockStore,
10
+ CapsuleStore,
11
+ ContractStore,
12
+ JobCoordinator,
13
+ NoteService,
14
+ NoteStore,
15
+ PrivateEventStore,
16
+ RecipientTaggingStore,
17
+ SenderAddressBookStore,
18
+ SenderTaggingStore,
13
19
  } from '@aztec/pxe/server';
14
20
  import {
15
21
  ExecutionNoteCache,
@@ -17,34 +23,39 @@ import {
17
23
  HashedValuesCache,
18
24
  type IPrivateExecutionOracle,
19
25
  type IUtilityExecutionOracle,
26
+ Oracle,
20
27
  PrivateExecutionOracle,
21
28
  UtilityExecutionOracle,
22
29
  } from '@aztec/pxe/simulator';
23
- import { FunctionSelector } from '@aztec/stdlib/abi';
30
+ import {
31
+ ExecutionError,
32
+ WASMSimulator,
33
+ createSimulationError,
34
+ extractCallStack,
35
+ resolveAssertionMessageFromError,
36
+ toACVMWitness,
37
+ } from '@aztec/simulator/client';
38
+ import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
24
39
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
25
40
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
26
- import { Body, L2Block } from '@aztec/stdlib/block';
27
41
  import { GasSettings } from '@aztec/stdlib/gas';
42
+ import { computeProtocolNullifier } from '@aztec/stdlib/hash';
28
43
  import { PrivateContextInputs } from '@aztec/stdlib/kernel';
29
- import { makeAppendOnlyTreeSnapshot, makeGlobalVariables } from '@aztec/stdlib/testing';
44
+ import { makeGlobalVariables } from '@aztec/stdlib/testing';
30
45
  import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
31
- import type { UInt32 } from '@aztec/stdlib/types';
32
46
 
33
47
  import { z } from 'zod';
34
48
 
49
+ import { DEFAULT_ADDRESS } from './constants.js';
35
50
  import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
36
51
  import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
37
52
  import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
38
53
  import { RPCTranslator } from './rpc_translator.js';
54
+ import { TXEArchiver } from './state_machine/archiver.js';
39
55
  import { TXEStateMachine } from './state_machine/index.js';
40
56
  import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
41
- import { TXEAccountDataProvider } from './util/txe_account_data_provider.js';
42
- import { TXEContractDataProvider } from './util/txe_contract_data_provider.js';
43
- import {
44
- getSingleTxBlockRequestHash,
45
- insertTxEffectIntoWorldTrees,
46
- makeTXEBlockHeader,
47
- } from './utils/block_creation.js';
57
+ import { TXEAccountStore } from './util/txe_account_store.js';
58
+ import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
48
59
  import { makeTxEffect } from './utils/tx_effect_creation.js';
49
60
 
50
61
  /**
@@ -66,7 +77,6 @@ type SessionState =
66
77
  | {
67
78
  name: 'PRIVATE';
68
79
  nextBlockGlobalVariables: GlobalVariables;
69
- txRequestHash: Fr;
70
80
  noteCache: ExecutionNoteCache;
71
81
  taggingIndexCache: ExecutionTaggingIndexCache;
72
82
  }
@@ -101,12 +111,10 @@ export type TXEOracleFunctionName = Exclude<
101
111
  export interface TXESessionStateHandler {
102
112
  enterTopLevelState(): Promise<void>;
103
113
  enterPublicState(contractAddress?: AztecAddress): Promise<void>;
104
- enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: UInt32): Promise<PrivateContextInputs>;
114
+ enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
105
115
  enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
106
116
  }
107
117
 
108
- const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
109
-
110
118
  /**
111
119
  * A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
112
120
  * state, etc., independent of all other tests running in parallel.
@@ -123,59 +131,69 @@ export class TXESession implements TXESessionStateHandler {
123
131
  | IPrivateExecutionOracle
124
132
  | IAvmExecutionOracle
125
133
  | ITxeExecutionOracle,
126
- private contractDataProvider: TXEContractDataProvider,
134
+ private contractStore: ContractStore,
135
+ private noteStore: NoteStore,
127
136
  private keyStore: KeyStore,
128
- private addressDataProvider: AddressDataProvider,
129
- private accountDataProvider: TXEAccountDataProvider,
137
+ private addressStore: AddressStore,
138
+ private accountStore: TXEAccountStore,
139
+ private senderTaggingStore: SenderTaggingStore,
140
+ private recipientTaggingStore: RecipientTaggingStore,
141
+ private senderAddressBookStore: SenderAddressBookStore,
142
+ private capsuleStore: CapsuleStore,
143
+ private privateEventStore: PrivateEventStore,
144
+ private jobCoordinator: JobCoordinator,
145
+ private currentJobId: string,
130
146
  private chainId: Fr,
131
147
  private version: Fr,
132
148
  private nextBlockTimestamp: bigint,
133
- private pxeOracleInterface: PXEOracleInterface,
134
149
  ) {}
135
150
 
136
- static async init(protocolContracts: ProtocolContract[]) {
151
+ static async init(contractStore: ContractStore) {
137
152
  const store = await openTmpStore('txe-session');
138
153
 
139
- const addressDataProvider = new AddressDataProvider(store);
140
- const privateEventDataProvider = new PrivateEventDataProvider(store);
141
- const contractDataProvider = new TXEContractDataProvider(store);
142
- const noteDataProvider = await NoteDataProvider.create(store);
143
- const taggingDataProvider = new TaggingDataProvider(store);
144
- const capsuleDataProvider = new CapsuleDataProvider(store);
154
+ const addressStore = new AddressStore(store);
155
+ const privateEventStore = new PrivateEventStore(store);
156
+ const noteStore = new NoteStore(store);
157
+ const senderTaggingStore = new SenderTaggingStore(store);
158
+ const recipientTaggingStore = new RecipientTaggingStore(store);
159
+ const senderAddressBookStore = new SenderAddressBookStore(store);
160
+ const capsuleStore = new CapsuleStore(store);
145
161
  const keyStore = new KeyStore(store);
146
- const accountDataProvider = new TXEAccountDataProvider(store);
147
-
148
- // Register protocol contracts.
149
- for (const { contractClass, instance, artifact } of protocolContracts) {
150
- await contractDataProvider.addContractArtifact(contractClass.id, artifact);
151
- await contractDataProvider.addContractInstance(instance);
152
- }
153
-
154
- const stateMachine = await TXEStateMachine.create(store);
162
+ const accountStore = new TXEAccountStore(store);
163
+
164
+ // Create job coordinator and register staged stores
165
+ const jobCoordinator = new JobCoordinator(store);
166
+ jobCoordinator.registerStores([
167
+ capsuleStore,
168
+ senderTaggingStore,
169
+ recipientTaggingStore,
170
+ privateEventStore,
171
+ noteStore,
172
+ ]);
173
+
174
+ const archiver = new TXEArchiver(store);
175
+ const anchorBlockStore = new AnchorBlockStore(store);
176
+ const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
155
177
 
156
178
  const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
157
179
  const version = new Fr(await stateMachine.node.getVersion());
158
180
  const chainId = new Fr(await stateMachine.node.getChainId());
159
181
 
160
- const pxeOracleInterface = new PXEOracleInterface(
161
- stateMachine.node,
162
- keyStore,
163
- contractDataProvider,
164
- noteDataProvider,
165
- capsuleDataProvider,
166
- stateMachine.syncDataProvider,
167
- taggingDataProvider,
168
- addressDataProvider,
169
- privateEventDataProvider,
170
- );
182
+ const initialJobId = jobCoordinator.beginJob();
171
183
 
172
184
  const topLevelOracleHandler = new TXEOracleTopLevelContext(
173
185
  stateMachine,
174
- contractDataProvider,
186
+ contractStore,
187
+ noteStore,
175
188
  keyStore,
176
- addressDataProvider,
177
- accountDataProvider,
178
- pxeOracleInterface,
189
+ addressStore,
190
+ accountStore,
191
+ senderTaggingStore,
192
+ recipientTaggingStore,
193
+ senderAddressBookStore,
194
+ capsuleStore,
195
+ privateEventStore,
196
+ initialJobId,
179
197
  nextBlockTimestamp,
180
198
  version,
181
199
  chainId,
@@ -187,14 +205,21 @@ export class TXESession implements TXESessionStateHandler {
187
205
  createLogger('txe:session'),
188
206
  stateMachine,
189
207
  topLevelOracleHandler,
190
- contractDataProvider,
208
+ contractStore,
209
+ noteStore,
191
210
  keyStore,
192
- addressDataProvider,
193
- accountDataProvider,
211
+ addressStore,
212
+ accountStore,
213
+ senderTaggingStore,
214
+ recipientTaggingStore,
215
+ senderAddressBookStore,
216
+ capsuleStore,
217
+ privateEventStore,
218
+ jobCoordinator,
219
+ initialJobId,
194
220
  version,
195
221
  chainId,
196
222
  nextBlockTimestamp,
197
- pxeOracleInterface,
198
223
  );
199
224
  }
200
225
 
@@ -251,13 +276,23 @@ export class TXESession implements TXESessionStateHandler {
251
276
  }
252
277
  }
253
278
 
279
+ // Commit all staged stores from the job that was just completed, then begin a new job
280
+ await this.jobCoordinator.commitJob(this.currentJobId);
281
+ this.currentJobId = this.jobCoordinator.beginJob();
282
+
254
283
  this.oracleHandler = new TXEOracleTopLevelContext(
255
284
  this.stateMachine,
256
- this.contractDataProvider,
285
+ this.contractStore,
286
+ this.noteStore,
257
287
  this.keyStore,
258
- this.addressDataProvider,
259
- this.accountDataProvider,
260
- this.pxeOracleInterface,
288
+ this.addressStore,
289
+ this.accountStore,
290
+ this.senderTaggingStore,
291
+ this.recipientTaggingStore,
292
+ this.senderAddressBookStore,
293
+ this.capsuleStore,
294
+ this.privateEventStore,
295
+ this.currentJobId,
261
296
  this.nextBlockTimestamp,
262
297
  this.version,
263
298
  this.chainId,
@@ -270,53 +305,66 @@ export class TXESession implements TXESessionStateHandler {
270
305
 
271
306
  async enterPrivateState(
272
307
  contractAddress: AztecAddress = DEFAULT_ADDRESS,
273
- anchorBlockNumber?: UInt32,
308
+ anchorBlockNumber?: BlockNumber,
274
309
  ): Promise<PrivateContextInputs> {
275
310
  this.exitTopLevelState();
276
311
 
277
- // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
278
- // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
279
- // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
280
- // be removed from the database.
281
- // TODO(#12553): make the synchronizer sync here instead and remove this
282
- await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
283
-
284
312
  // Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
285
313
  // build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
286
314
  // a single transaction with the effects of what was done in the test.
287
315
  const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
316
+
317
+ await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
318
+ contractAddress,
319
+ 'ALL_SCOPES',
320
+ );
288
321
  const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
289
322
 
290
323
  const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
291
- blockNumber: latestBlock!.globalVariables.blockNumber + 1,
324
+ blockNumber: BlockNumber(latestBlock!.globalVariables.blockNumber + 1),
292
325
  timestamp: this.nextBlockTimestamp,
293
326
  version: this.version,
294
327
  chainId: this.chainId,
295
328
  });
296
329
 
297
330
  const txRequestHash = getSingleTxBlockRequestHash(nextBlockGlobalVariables.blockNumber);
298
- const noteCache = new ExecutionNoteCache(txRequestHash);
331
+ const protocolNullifier = await computeProtocolNullifier(txRequestHash);
332
+ const noteCache = new ExecutionNoteCache(protocolNullifier);
299
333
  const taggingIndexCache = new ExecutionTaggingIndexCache();
300
334
 
301
- this.oracleHandler = new PrivateExecutionOracle(
302
- Fr.ZERO,
303
- new TxContext(this.chainId, this.version, GasSettings.empty()),
304
- new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
305
- anchorBlock!,
306
- [],
307
- [],
308
- new HashedValuesCache(),
335
+ const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
336
+ this.oracleHandler = new PrivateExecutionOracle({
337
+ argsHash: Fr.ZERO,
338
+ txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
339
+ callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
340
+ anchorBlockHeader: anchorBlock!,
341
+ utilityExecutor,
342
+ authWitnesses: [],
343
+ capsules: [],
344
+ executionCache: new HashedValuesCache(),
309
345
  noteCache,
310
346
  taggingIndexCache,
311
- this.pxeOracleInterface,
312
- );
347
+ contractStore: this.contractStore,
348
+ noteStore: this.noteStore,
349
+ keyStore: this.keyStore,
350
+ addressStore: this.addressStore,
351
+ aztecNode: this.stateMachine.node,
352
+ senderTaggingStore: this.senderTaggingStore,
353
+ recipientTaggingStore: this.recipientTaggingStore,
354
+ senderAddressBookStore: this.senderAddressBookStore,
355
+ capsuleStore: this.capsuleStore,
356
+ privateEventStore: this.privateEventStore,
357
+ contractSyncService: this.stateMachine.contractSyncService,
358
+ jobId: this.currentJobId,
359
+ scopes: 'ALL_SCOPES',
360
+ });
313
361
 
314
362
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
315
363
  // data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
316
364
  // difference resides in that the simulator has all information needed in order to run the simulation, while ours
317
365
  // will be ongoing as the different oracles will be invoked from the Noir test, until eventually the private
318
366
  // execution finishes.
319
- this.state = { name: 'PRIVATE', nextBlockGlobalVariables, txRequestHash, noteCache, taggingIndexCache };
367
+ this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
320
368
  this.logger.debug(`Entered state ${this.state.name}`);
321
369
 
322
370
  return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
@@ -329,7 +377,7 @@ export class TXESession implements TXESessionStateHandler {
329
377
  // the test. The block therefore gets the *next* block number and timestamp.
330
378
  const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.blockNumber;
331
379
  const globalVariables = makeGlobalVariables(undefined, {
332
- blockNumber: latestBlockNumber + 1,
380
+ blockNumber: BlockNumber(latestBlockNumber + 1),
333
381
  timestamp: this.nextBlockTimestamp,
334
382
  version: this.version,
335
383
  chainId: this.chainId,
@@ -349,14 +397,37 @@ export class TXESession implements TXESessionStateHandler {
349
397
  async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
350
398
  this.exitTopLevelState();
351
399
 
400
+ const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
401
+
352
402
  // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
353
403
  // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
354
404
  // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
355
405
  // be removed from the database.
356
406
  // TODO(#12553): make the synchronizer sync here instead and remove this
357
- await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
358
-
359
- this.oracleHandler = new UtilityExecutionOracle(contractAddress, [], [], this.pxeOracleInterface);
407
+ await new NoteService(
408
+ this.noteStore,
409
+ this.stateMachine.node,
410
+ anchorBlockHeader,
411
+ this.currentJobId,
412
+ ).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
413
+
414
+ this.oracleHandler = new UtilityExecutionOracle({
415
+ contractAddress,
416
+ authWitnesses: [],
417
+ capsules: [],
418
+ anchorBlockHeader,
419
+ contractStore: this.contractStore,
420
+ noteStore: this.noteStore,
421
+ keyStore: this.keyStore,
422
+ addressStore: this.addressStore,
423
+ aztecNode: this.stateMachine.node,
424
+ recipientTaggingStore: this.recipientTaggingStore,
425
+ senderAddressBookStore: this.senderAddressBookStore,
426
+ capsuleStore: this.capsuleStore,
427
+ privateEventStore: this.privateEventStore,
428
+ jobId: this.currentJobId,
429
+ scopes: 'ALL_SCOPES',
430
+ });
360
431
 
361
432
  this.state = { name: 'UTILITY' };
362
433
  this.logger.debug(`Entered state ${this.state.name}`);
@@ -390,21 +461,14 @@ export class TXESession implements TXESessionStateHandler {
390
461
 
391
462
  // We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
392
463
  // logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
393
- const txEffect = await makeTxEffect(
394
- this.state.noteCache,
395
- this.state.txRequestHash,
396
- this.state.nextBlockGlobalVariables.blockNumber,
397
- );
464
+
465
+ const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
398
466
 
399
467
  // We build a block holding just this transaction
400
468
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
401
469
  await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
402
470
 
403
- const block = new L2Block(
404
- makeAppendOnlyTreeSnapshot(),
405
- await makeTXEBlockHeader(forkedWorldTrees, this.state.nextBlockGlobalVariables),
406
- new Body([txEffect]),
407
- );
471
+ const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [txEffect]);
408
472
  await this.stateMachine.handleL2Block(block);
409
473
 
410
474
  await forkedWorldTrees.close();
@@ -429,4 +493,49 @@ export class TXESession implements TXESessionStateHandler {
429
493
  throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
430
494
  }
431
495
  }
496
+
497
+ private utilityExecutorForContractSync(anchorBlock: any) {
498
+ return async (call: FunctionCall, scopes: AccessScopes) => {
499
+ const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
500
+ if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
501
+ throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
502
+ }
503
+
504
+ try {
505
+ const oracle = new UtilityExecutionOracle({
506
+ contractAddress: call.to,
507
+ authWitnesses: [],
508
+ capsules: [],
509
+ anchorBlockHeader: anchorBlock!,
510
+ contractStore: this.contractStore,
511
+ noteStore: this.noteStore,
512
+ keyStore: this.keyStore,
513
+ addressStore: this.addressStore,
514
+ aztecNode: this.stateMachine.node,
515
+ recipientTaggingStore: this.recipientTaggingStore,
516
+ senderAddressBookStore: this.senderAddressBookStore,
517
+ capsuleStore: this.capsuleStore,
518
+ privateEventStore: this.privateEventStore,
519
+ jobId: this.currentJobId,
520
+ scopes,
521
+ });
522
+ await new WASMSimulator()
523
+ .executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
524
+ .catch((err: Error) => {
525
+ err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
526
+ throw new ExecutionError(
527
+ err.message,
528
+ {
529
+ contractAddress: call.to,
530
+ functionSelector: call.selector,
531
+ },
532
+ extractCallStack(err, entryPointArtifact.debug),
533
+ { cause: err },
534
+ );
535
+ });
536
+ } catch (err) {
537
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
538
+ }
539
+ };
540
+ }
432
541
  }
@@ -1,5 +1,5 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
1
2
  import type { EthAddress } from '@aztec/foundation/eth-address';
2
- import { Fr } from '@aztec/foundation/fields';
3
3
  import { hexToBuffer } from '@aztec/foundation/string';
4
4
  import { type ContractArtifact, ContractArtifactSchema } from '@aztec/stdlib/abi';
5
5
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -2,7 +2,7 @@ import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
  import { CompleteAddress } from '@aztec/stdlib/contract';
4
4
 
5
- export class TXEAccountDataProvider {
5
+ export class TXEAccountStore {
6
6
  #accounts: AztecAsyncMap<string, Buffer>;
7
7
 
8
8
  constructor(store: AztecAsyncKVStore) {
@@ -1,68 +1,43 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import type { ContractDataProvider } from '@aztec/pxe/server';
3
- import { type ContractArtifact, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import type { ContractStore } from '@aztec/pxe/server';
4
+ import { type ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
4
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- import {
6
- type ContractClassPublic,
7
- type ContractDataSource,
8
- type ContractInstanceWithAddress,
9
- computePrivateFunctionsRoot,
10
- computePublicBytecodeCommitment,
11
- getContractClassPrivateFunctionFromArtifact,
12
- } from '@aztec/stdlib/contract';
6
+ import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
13
7
 
14
8
  export class TXEPublicContractDataSource implements ContractDataSource {
15
- #privateFunctionsRoot: Map<string, Buffer> = new Map();
16
9
  constructor(
17
- private blockNumber: number,
18
- private contractDataProvider: ContractDataProvider,
10
+ private blockNumber: BlockNumber,
11
+ private contractStore: ContractStore,
19
12
  ) {}
20
13
 
21
- getBlockNumber(): Promise<number> {
14
+ getBlockNumber(): Promise<BlockNumber> {
22
15
  return Promise.resolve(this.blockNumber);
23
16
  }
24
17
 
25
18
  async getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
26
- const contractClass = await this.contractDataProvider.getContractClass(id);
19
+ const contractClass = await this.contractStore.getContractClassWithPreimage(id);
27
20
  if (!contractClass) {
28
21
  return;
29
22
  }
30
- const artifact = await this.contractDataProvider.getContractArtifact(id);
31
- if (!artifact) {
32
- return;
33
- }
34
-
35
- let privateFunctionsRoot;
36
- if (!this.#privateFunctionsRoot.has(id.toString())) {
37
- const privateFunctions = await Promise.all(
38
- artifact.functions
39
- .filter(fn => fn.functionType === FunctionType.PRIVATE)
40
- .map(fn => getContractClassPrivateFunctionFromArtifact(fn)),
41
- );
42
- privateFunctionsRoot = await computePrivateFunctionsRoot(privateFunctions);
43
- this.#privateFunctionsRoot.set(id.toString(), privateFunctionsRoot.toBuffer());
44
- } else {
45
- privateFunctionsRoot = Fr.fromBuffer(this.#privateFunctionsRoot.get(id.toString())!);
46
- }
47
-
48
23
  return {
49
- id,
50
- artifactHash: contractClass!.artifactHash,
51
- packedBytecode: contractClass!.packedBytecode,
52
- privateFunctionsRoot,
53
- version: contractClass!.version,
24
+ id: contractClass.id,
25
+ artifactHash: contractClass.artifactHash,
26
+ packedBytecode: contractClass.packedBytecode,
27
+ privateFunctionsRoot: contractClass.privateFunctionsRoot,
28
+ version: contractClass.version,
54
29
  privateFunctions: [],
55
30
  utilityFunctions: [],
56
31
  };
57
32
  }
58
33
 
59
34
  async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
60
- const contractClass = await this.contractDataProvider.getContractClass(id);
61
- return contractClass && computePublicBytecodeCommitment(contractClass.packedBytecode);
35
+ const contractClass = await this.contractStore.getContractClassWithPreimage(id);
36
+ return contractClass?.publicBytecodeCommitment;
62
37
  }
63
38
 
64
39
  async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
65
- const instance = await this.contractDataProvider.getContractInstance(address);
40
+ const instance = await this.contractStore.getContractInstance(address);
66
41
  return instance && { ...instance, address };
67
42
  }
68
43
 
@@ -71,12 +46,12 @@ export class TXEPublicContractDataSource implements ContractDataSource {
71
46
  }
72
47
 
73
48
  async getContractArtifact(address: AztecAddress): Promise<ContractArtifact | undefined> {
74
- const instance = await this.contractDataProvider.getContractInstance(address);
75
- return instance && this.contractDataProvider.getContractArtifact(instance.currentContractClassId);
49
+ const instance = await this.contractStore.getContractInstance(address);
50
+ return instance && this.contractStore.getContractArtifact(instance.currentContractClassId);
76
51
  }
77
52
 
78
53
  async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
79
- return await this.contractDataProvider.getDebugFunctionName(address, selector);
54
+ return await this.contractStore.getDebugFunctionName(address, selector);
80
55
  }
81
56
 
82
57
  registerContractFunctionSignatures(_signatures: []): Promise<void> {