@aztec/txe 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c

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 (78) hide show
  1. package/dest/constants.d.ts +3 -0
  2. package/dest/constants.d.ts.map +1 -0
  3. package/dest/constants.js +2 -0
  4. package/dest/index.d.ts +1 -1
  5. package/dest/index.d.ts.map +1 -1
  6. package/dest/index.js +85 -52
  7. package/dest/oracle/interfaces.d.ts +12 -9
  8. package/dest/oracle/interfaces.d.ts.map +1 -1
  9. package/dest/oracle/txe_oracle_public_context.d.ts +7 -7
  10. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_public_context.js +10 -12
  12. package/dest/oracle/txe_oracle_top_level_context.d.ts +23 -14
  13. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  14. package/dest/oracle/txe_oracle_top_level_context.js +177 -79
  15. package/dest/rpc_translator.d.ts +30 -18
  16. package/dest/rpc_translator.d.ts.map +1 -1
  17. package/dest/rpc_translator.js +127 -60
  18. package/dest/state_machine/archiver.d.ts +21 -52
  19. package/dest/state_machine/archiver.d.ts.map +1 -1
  20. package/dest/state_machine/archiver.js +63 -94
  21. package/dest/state_machine/dummy_p2p_client.d.ts +19 -14
  22. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  23. package/dest/state_machine/dummy_p2p_client.js +41 -24
  24. package/dest/state_machine/global_variable_builder.d.ts +6 -5
  25. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  26. package/dest/state_machine/global_variable_builder.js +13 -1
  27. package/dest/state_machine/index.d.ts +7 -7
  28. package/dest/state_machine/index.d.ts.map +1 -1
  29. package/dest/state_machine/index.js +40 -23
  30. package/dest/state_machine/mock_epoch_cache.d.ts +9 -6
  31. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  32. package/dest/state_machine/mock_epoch_cache.js +14 -7
  33. package/dest/state_machine/synchronizer.d.ts +3 -2
  34. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  35. package/dest/state_machine/synchronizer.js +5 -4
  36. package/dest/txe_session.d.ts +21 -15
  37. package/dest/txe_session.d.ts.map +1 -1
  38. package/dest/txe_session.js +151 -52
  39. package/dest/util/encoding.d.ts +618 -19
  40. package/dest/util/encoding.d.ts.map +1 -1
  41. package/dest/util/encoding.js +1 -1
  42. package/dest/util/txe_account_store.d.ts +10 -0
  43. package/dest/util/txe_account_store.d.ts.map +1 -0
  44. package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
  45. package/dest/util/txe_public_contract_data_source.d.ts +8 -8
  46. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  47. package/dest/util/txe_public_contract_data_source.js +12 -29
  48. package/dest/utils/block_creation.d.ts +21 -6
  49. package/dest/utils/block_creation.d.ts.map +1 -1
  50. package/dest/utils/block_creation.js +38 -4
  51. package/dest/utils/tx_effect_creation.d.ts +3 -3
  52. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  53. package/dest/utils/tx_effect_creation.js +4 -7
  54. package/package.json +18 -18
  55. package/src/constants.ts +3 -0
  56. package/src/index.ts +97 -60
  57. package/src/oracle/interfaces.ts +11 -8
  58. package/src/oracle/txe_oracle_public_context.ts +12 -19
  59. package/src/oracle/txe_oracle_top_level_context.ts +213 -124
  60. package/src/rpc_translator.ts +156 -60
  61. package/src/state_machine/archiver.ts +59 -114
  62. package/src/state_machine/dummy_p2p_client.ts +57 -32
  63. package/src/state_machine/global_variable_builder.ts +21 -4
  64. package/src/state_machine/index.ts +60 -21
  65. package/src/state_machine/mock_epoch_cache.ts +15 -11
  66. package/src/state_machine/synchronizer.ts +6 -5
  67. package/src/txe_session.ts +207 -100
  68. package/src/util/encoding.ts +1 -1
  69. package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
  70. package/src/util/txe_public_contract_data_source.ts +20 -45
  71. package/src/utils/block_creation.ts +49 -15
  72. package/src/utils/tx_effect_creation.ts +5 -12
  73. package/dest/util/txe_account_data_provider.d.ts +0 -10
  74. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  75. package/dest/util/txe_contract_data_provider.d.ts +0 -12
  76. package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
  77. package/dest/util/txe_contract_data_provider.js +0 -22
  78. package/src/util/txe_contract_data_provider.ts +0 -36
@@ -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,35 +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';
28
42
  import { computeProtocolNullifier } from '@aztec/stdlib/hash';
29
43
  import { PrivateContextInputs } from '@aztec/stdlib/kernel';
30
- import { makeAppendOnlyTreeSnapshot, makeGlobalVariables } from '@aztec/stdlib/testing';
44
+ import { makeGlobalVariables } from '@aztec/stdlib/testing';
31
45
  import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
32
- import type { UInt32 } from '@aztec/stdlib/types';
33
46
 
34
47
  import { z } from 'zod';
35
48
 
49
+ import { DEFAULT_ADDRESS } from './constants.js';
36
50
  import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
37
51
  import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
38
52
  import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
39
53
  import { RPCTranslator } from './rpc_translator.js';
54
+ import { TXEArchiver } from './state_machine/archiver.js';
40
55
  import { TXEStateMachine } from './state_machine/index.js';
41
56
  import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
42
- import { TXEAccountDataProvider } from './util/txe_account_data_provider.js';
43
- import { TXEContractDataProvider } from './util/txe_contract_data_provider.js';
44
- import {
45
- getSingleTxBlockRequestHash,
46
- insertTxEffectIntoWorldTrees,
47
- makeTXEBlockHeader,
48
- } from './utils/block_creation.js';
57
+ import { TXEAccountStore } from './util/txe_account_store.js';
58
+ import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
49
59
  import { makeTxEffect } from './utils/tx_effect_creation.js';
50
60
 
51
61
  /**
@@ -67,7 +77,6 @@ type SessionState =
67
77
  | {
68
78
  name: 'PRIVATE';
69
79
  nextBlockGlobalVariables: GlobalVariables;
70
- protocolNullifier: Fr;
71
80
  noteCache: ExecutionNoteCache;
72
81
  taggingIndexCache: ExecutionTaggingIndexCache;
73
82
  }
@@ -102,12 +111,10 @@ export type TXEOracleFunctionName = Exclude<
102
111
  export interface TXESessionStateHandler {
103
112
  enterTopLevelState(): Promise<void>;
104
113
  enterPublicState(contractAddress?: AztecAddress): Promise<void>;
105
- enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: UInt32): Promise<PrivateContextInputs>;
114
+ enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
106
115
  enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
107
116
  }
108
117
 
109
- const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
110
-
111
118
  /**
112
119
  * A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
113
120
  * state, etc., independent of all other tests running in parallel.
@@ -124,59 +131,69 @@ export class TXESession implements TXESessionStateHandler {
124
131
  | IPrivateExecutionOracle
125
132
  | IAvmExecutionOracle
126
133
  | ITxeExecutionOracle,
127
- private contractDataProvider: TXEContractDataProvider,
134
+ private contractStore: ContractStore,
135
+ private noteStore: NoteStore,
128
136
  private keyStore: KeyStore,
129
- private addressDataProvider: AddressDataProvider,
130
- 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,
131
146
  private chainId: Fr,
132
147
  private version: Fr,
133
148
  private nextBlockTimestamp: bigint,
134
- private pxeOracleInterface: PXEOracleInterface,
135
149
  ) {}
136
150
 
137
- static async init(protocolContracts: ProtocolContract[]) {
151
+ static async init(contractStore: ContractStore) {
138
152
  const store = await openTmpStore('txe-session');
139
153
 
140
- const addressDataProvider = new AddressDataProvider(store);
141
- const privateEventDataProvider = new PrivateEventDataProvider(store);
142
- const contractDataProvider = new TXEContractDataProvider(store);
143
- const noteDataProvider = await NoteDataProvider.create(store);
144
- const taggingDataProvider = new TaggingDataProvider(store);
145
- 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);
146
161
  const keyStore = new KeyStore(store);
147
- const accountDataProvider = new TXEAccountDataProvider(store);
148
-
149
- // Register protocol contracts.
150
- for (const { contractClass, instance, artifact } of protocolContracts) {
151
- await contractDataProvider.addContractArtifact(contractClass.id, artifact);
152
- await contractDataProvider.addContractInstance(instance);
153
- }
154
-
155
- 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);
156
177
 
157
178
  const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
158
179
  const version = new Fr(await stateMachine.node.getVersion());
159
180
  const chainId = new Fr(await stateMachine.node.getChainId());
160
181
 
161
- const pxeOracleInterface = new PXEOracleInterface(
162
- stateMachine.node,
163
- keyStore,
164
- contractDataProvider,
165
- noteDataProvider,
166
- capsuleDataProvider,
167
- stateMachine.syncDataProvider,
168
- taggingDataProvider,
169
- addressDataProvider,
170
- privateEventDataProvider,
171
- );
182
+ const initialJobId = jobCoordinator.beginJob();
172
183
 
173
184
  const topLevelOracleHandler = new TXEOracleTopLevelContext(
174
185
  stateMachine,
175
- contractDataProvider,
186
+ contractStore,
187
+ noteStore,
176
188
  keyStore,
177
- addressDataProvider,
178
- accountDataProvider,
179
- pxeOracleInterface,
189
+ addressStore,
190
+ accountStore,
191
+ senderTaggingStore,
192
+ recipientTaggingStore,
193
+ senderAddressBookStore,
194
+ capsuleStore,
195
+ privateEventStore,
196
+ initialJobId,
180
197
  nextBlockTimestamp,
181
198
  version,
182
199
  chainId,
@@ -188,14 +205,21 @@ export class TXESession implements TXESessionStateHandler {
188
205
  createLogger('txe:session'),
189
206
  stateMachine,
190
207
  topLevelOracleHandler,
191
- contractDataProvider,
208
+ contractStore,
209
+ noteStore,
192
210
  keyStore,
193
- addressDataProvider,
194
- accountDataProvider,
211
+ addressStore,
212
+ accountStore,
213
+ senderTaggingStore,
214
+ recipientTaggingStore,
215
+ senderAddressBookStore,
216
+ capsuleStore,
217
+ privateEventStore,
218
+ jobCoordinator,
219
+ initialJobId,
195
220
  version,
196
221
  chainId,
197
222
  nextBlockTimestamp,
198
- pxeOracleInterface,
199
223
  );
200
224
  }
201
225
 
@@ -252,13 +276,23 @@ export class TXESession implements TXESessionStateHandler {
252
276
  }
253
277
  }
254
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
+
255
283
  this.oracleHandler = new TXEOracleTopLevelContext(
256
284
  this.stateMachine,
257
- this.contractDataProvider,
285
+ this.contractStore,
286
+ this.noteStore,
258
287
  this.keyStore,
259
- this.addressDataProvider,
260
- this.accountDataProvider,
261
- 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,
262
296
  this.nextBlockTimestamp,
263
297
  this.version,
264
298
  this.chainId,
@@ -271,25 +305,23 @@ export class TXESession implements TXESessionStateHandler {
271
305
 
272
306
  async enterPrivateState(
273
307
  contractAddress: AztecAddress = DEFAULT_ADDRESS,
274
- anchorBlockNumber?: UInt32,
308
+ anchorBlockNumber?: BlockNumber,
275
309
  ): Promise<PrivateContextInputs> {
276
310
  this.exitTopLevelState();
277
311
 
278
- // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
279
- // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
280
- // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
281
- // be removed from the database.
282
- // TODO(#12553): make the synchronizer sync here instead and remove this
283
- await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
284
-
285
312
  // Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
286
313
  // build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
287
314
  // a single transaction with the effects of what was done in the test.
288
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
+ );
289
321
  const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
290
322
 
291
323
  const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
292
- blockNumber: latestBlock!.globalVariables.blockNumber + 1,
324
+ blockNumber: BlockNumber(latestBlock!.globalVariables.blockNumber + 1),
293
325
  timestamp: this.nextBlockTimestamp,
294
326
  version: this.version,
295
327
  chainId: this.chainId,
@@ -300,25 +332,39 @@ export class TXESession implements TXESessionStateHandler {
300
332
  const noteCache = new ExecutionNoteCache(protocolNullifier);
301
333
  const taggingIndexCache = new ExecutionTaggingIndexCache();
302
334
 
303
- this.oracleHandler = new PrivateExecutionOracle(
304
- Fr.ZERO,
305
- new TxContext(this.chainId, this.version, GasSettings.empty()),
306
- new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
307
- anchorBlock!,
308
- [],
309
- [],
310
- 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(),
311
345
  noteCache,
312
346
  taggingIndexCache,
313
- this.pxeOracleInterface,
314
- );
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
+ });
315
361
 
316
362
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
317
363
  // data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
318
364
  // difference resides in that the simulator has all information needed in order to run the simulation, while ours
319
365
  // will be ongoing as the different oracles will be invoked from the Noir test, until eventually the private
320
366
  // execution finishes.
321
- this.state = { name: 'PRIVATE', nextBlockGlobalVariables, protocolNullifier, noteCache, taggingIndexCache };
367
+ this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
322
368
  this.logger.debug(`Entered state ${this.state.name}`);
323
369
 
324
370
  return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
@@ -331,7 +377,7 @@ export class TXESession implements TXESessionStateHandler {
331
377
  // the test. The block therefore gets the *next* block number and timestamp.
332
378
  const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.blockNumber;
333
379
  const globalVariables = makeGlobalVariables(undefined, {
334
- blockNumber: latestBlockNumber + 1,
380
+ blockNumber: BlockNumber(latestBlockNumber + 1),
335
381
  timestamp: this.nextBlockTimestamp,
336
382
  version: this.version,
337
383
  chainId: this.chainId,
@@ -351,14 +397,37 @@ export class TXESession implements TXESessionStateHandler {
351
397
  async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
352
398
  this.exitTopLevelState();
353
399
 
400
+ const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
401
+
354
402
  // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
355
403
  // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
356
404
  // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
357
405
  // be removed from the database.
358
406
  // TODO(#12553): make the synchronizer sync here instead and remove this
359
- await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
360
-
361
- 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
+ });
362
431
 
363
432
  this.state = { name: 'UTILITY' };
364
433
  this.logger.debug(`Entered state ${this.state.name}`);
@@ -392,21 +461,14 @@ export class TXESession implements TXESessionStateHandler {
392
461
 
393
462
  // We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
394
463
  // logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
395
- const txEffect = await makeTxEffect(
396
- this.state.noteCache,
397
- this.state.protocolNullifier,
398
- this.state.nextBlockGlobalVariables.blockNumber,
399
- );
464
+
465
+ const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
400
466
 
401
467
  // We build a block holding just this transaction
402
468
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
403
469
  await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
404
470
 
405
- const block = new L2Block(
406
- makeAppendOnlyTreeSnapshot(),
407
- await makeTXEBlockHeader(forkedWorldTrees, this.state.nextBlockGlobalVariables),
408
- new Body([txEffect]),
409
- );
471
+ const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [txEffect]);
410
472
  await this.stateMachine.handleL2Block(block);
411
473
 
412
474
  await forkedWorldTrees.close();
@@ -431,4 +493,49 @@ export class TXESession implements TXESessionStateHandler {
431
493
  throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
432
494
  }
433
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
+ }
434
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> {