@aztec/txe 0.0.1-commit.d3ec352c → 0.0.1-commit.d6f2b3f94

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 (80) 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 +3 -2
  7. package/dest/oracle/interfaces.d.ts +7 -5
  8. package/dest/oracle/interfaces.d.ts.map +1 -1
  9. package/dest/oracle/txe_oracle_public_context.d.ts +5 -5
  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 +21 -12
  13. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  14. package/dest/oracle/txe_oracle_top_level_context.js +119 -63
  15. package/dest/rpc_translator.d.ts +27 -15
  16. package/dest/rpc_translator.d.ts.map +1 -1
  17. package/dest/rpc_translator.js +117 -53
  18. package/dest/state_machine/archiver.d.ts +21 -57
  19. package/dest/state_machine/archiver.d.ts.map +1 -1
  20. package/dest/state_machine/archiver.js +63 -107
  21. package/dest/state_machine/dummy_p2p_client.d.ts +14 -12
  22. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  23. package/dest/state_machine/dummy_p2p_client.js +29 -21
  24. package/dest/state_machine/global_variable_builder.d.ts +4 -3
  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 -3
  34. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  35. package/dest/state_machine/synchronizer.js +2 -2
  36. package/dest/txe_session.d.ts +18 -10
  37. package/dest/txe_session.d.ts.map +1 -1
  38. package/dest/txe_session.js +95 -46
  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_contract_store.d.ts +12 -0
  46. package/dest/util/txe_contract_store.d.ts.map +1 -0
  47. package/dest/util/{txe_contract_data_provider.js → txe_contract_store.js} +3 -3
  48. package/dest/util/txe_public_contract_data_source.d.ts +5 -5
  49. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  50. package/dest/util/txe_public_contract_data_source.js +11 -11
  51. package/dest/utils/block_creation.d.ts +19 -5
  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 +2 -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 +16 -16
  58. package/src/constants.ts +3 -0
  59. package/src/index.ts +15 -12
  60. package/src/oracle/interfaces.ts +6 -4
  61. package/src/oracle/txe_oracle_public_context.ts +10 -17
  62. package/src/oracle/txe_oracle_top_level_context.ts +189 -92
  63. package/src/rpc_translator.ts +138 -56
  64. package/src/state_machine/archiver.ts +59 -131
  65. package/src/state_machine/dummy_p2p_client.ts +40 -27
  66. package/src/state_machine/global_variable_builder.ts +19 -2
  67. package/src/state_machine/index.ts +60 -22
  68. package/src/state_machine/mock_epoch_cache.ts +15 -11
  69. package/src/state_machine/synchronizer.ts +3 -4
  70. package/src/txe_session.ts +189 -79
  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_contract_data_provider.ts → txe_contract_store.ts} +3 -3
  74. package/src/util/txe_public_contract_data_source.ts +10 -10
  75. package/src/utils/block_creation.ts +48 -15
  76. package/src/utils/tx_effect_creation.ts +4 -12
  77. package/dest/util/txe_account_data_provider.d.ts +0 -10
  78. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  79. package/dest/util/txe_contract_data_provider.d.ts +0 -12
  80. package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
@@ -1,16 +1,20 @@
1
1
  import { BlockNumber } from '@aztec/foundation/branded-types';
2
- import { Fr } from '@aztec/foundation/fields';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { type Logger, createLogger } from '@aztec/foundation/log';
4
4
  import { KeyStore } from '@aztec/key-store';
5
5
  import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
6
6
  import type { ProtocolContract } from '@aztec/protocol-contracts';
7
7
  import {
8
- AddressDataProvider,
9
- CapsuleDataProvider,
10
- NoteDataProvider,
11
- PXEOracleInterface,
12
- PrivateEventDataProvider,
13
- TaggingDataProvider,
8
+ AddressStore,
9
+ AnchorBlockStore,
10
+ CapsuleStore,
11
+ JobCoordinator,
12
+ NoteService,
13
+ NoteStore,
14
+ PrivateEventStore,
15
+ RecipientTaggingStore,
16
+ SenderAddressBookStore,
17
+ SenderTaggingStore,
14
18
  } from '@aztec/pxe/server';
15
19
  import {
16
20
  ExecutionNoteCache,
@@ -18,34 +22,40 @@ import {
18
22
  HashedValuesCache,
19
23
  type IPrivateExecutionOracle,
20
24
  type IUtilityExecutionOracle,
25
+ Oracle,
21
26
  PrivateExecutionOracle,
22
27
  UtilityExecutionOracle,
23
28
  } from '@aztec/pxe/simulator';
24
- import { FunctionSelector } from '@aztec/stdlib/abi';
29
+ import {
30
+ ExecutionError,
31
+ WASMSimulator,
32
+ createSimulationError,
33
+ extractCallStack,
34
+ resolveAssertionMessageFromError,
35
+ toACVMWitness,
36
+ } from '@aztec/simulator/client';
37
+ import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
25
38
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
26
39
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
27
- import { Body, L2Block } from '@aztec/stdlib/block';
28
40
  import { GasSettings } from '@aztec/stdlib/gas';
29
41
  import { computeProtocolNullifier } from '@aztec/stdlib/hash';
30
42
  import { PrivateContextInputs } from '@aztec/stdlib/kernel';
31
- import { makeAppendOnlyTreeSnapshot, makeGlobalVariables } from '@aztec/stdlib/testing';
43
+ import { makeGlobalVariables } from '@aztec/stdlib/testing';
32
44
  import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
33
45
 
34
46
  import { z } from 'zod';
35
47
 
48
+ import { DEFAULT_ADDRESS } from './constants.js';
36
49
  import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
37
50
  import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
38
51
  import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
39
52
  import { RPCTranslator } from './rpc_translator.js';
53
+ import { TXEArchiver } from './state_machine/archiver.js';
40
54
  import { TXEStateMachine } from './state_machine/index.js';
41
55
  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';
56
+ import { TXEAccountStore } from './util/txe_account_store.js';
57
+ import { TXEContractStore } from './util/txe_contract_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
  }
@@ -106,8 +115,6 @@ export interface TXESessionStateHandler {
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,76 @@ export class TXESession implements TXESessionStateHandler {
124
131
  | IPrivateExecutionOracle
125
132
  | IAvmExecutionOracle
126
133
  | ITxeExecutionOracle,
127
- private contractDataProvider: TXEContractDataProvider,
134
+ private contractStore: TXEContractStore,
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
151
  static async init(protocolContracts: ProtocolContract[]) {
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 contractStore = new TXEContractStore(store);
157
+ const noteStore = new NoteStore(store);
158
+ const senderTaggingStore = new SenderTaggingStore(store);
159
+ const recipientTaggingStore = new RecipientTaggingStore(store);
160
+ const senderAddressBookStore = new SenderAddressBookStore(store);
161
+ const capsuleStore = new CapsuleStore(store);
146
162
  const keyStore = new KeyStore(store);
147
- const accountDataProvider = new TXEAccountDataProvider(store);
163
+ const accountStore = new TXEAccountStore(store);
164
+
165
+ // Create job coordinator and register staged stores
166
+ const jobCoordinator = new JobCoordinator(store);
167
+ jobCoordinator.registerStores([
168
+ capsuleStore,
169
+ senderTaggingStore,
170
+ recipientTaggingStore,
171
+ privateEventStore,
172
+ noteStore,
173
+ ]);
148
174
 
149
175
  // Register protocol contracts.
150
176
  for (const { contractClass, instance, artifact } of protocolContracts) {
151
- await contractDataProvider.addContractArtifact(contractClass.id, artifact);
152
- await contractDataProvider.addContractInstance(instance);
177
+ await contractStore.addContractArtifact(contractClass.id, artifact);
178
+ await contractStore.addContractInstance(instance);
153
179
  }
154
180
 
155
- const stateMachine = await TXEStateMachine.create(store);
181
+ const archiver = new TXEArchiver(store);
182
+ const anchorBlockStore = new AnchorBlockStore(store);
183
+ const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
156
184
 
157
185
  const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
158
186
  const version = new Fr(await stateMachine.node.getVersion());
159
187
  const chainId = new Fr(await stateMachine.node.getChainId());
160
188
 
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
- );
189
+ const initialJobId = jobCoordinator.beginJob();
172
190
 
173
191
  const topLevelOracleHandler = new TXEOracleTopLevelContext(
174
192
  stateMachine,
175
- contractDataProvider,
193
+ contractStore,
194
+ noteStore,
176
195
  keyStore,
177
- addressDataProvider,
178
- accountDataProvider,
179
- pxeOracleInterface,
196
+ addressStore,
197
+ accountStore,
198
+ senderTaggingStore,
199
+ recipientTaggingStore,
200
+ senderAddressBookStore,
201
+ capsuleStore,
202
+ privateEventStore,
203
+ initialJobId,
180
204
  nextBlockTimestamp,
181
205
  version,
182
206
  chainId,
@@ -188,14 +212,21 @@ export class TXESession implements TXESessionStateHandler {
188
212
  createLogger('txe:session'),
189
213
  stateMachine,
190
214
  topLevelOracleHandler,
191
- contractDataProvider,
215
+ contractStore,
216
+ noteStore,
192
217
  keyStore,
193
- addressDataProvider,
194
- accountDataProvider,
218
+ addressStore,
219
+ accountStore,
220
+ senderTaggingStore,
221
+ recipientTaggingStore,
222
+ senderAddressBookStore,
223
+ capsuleStore,
224
+ privateEventStore,
225
+ jobCoordinator,
226
+ initialJobId,
195
227
  version,
196
228
  chainId,
197
229
  nextBlockTimestamp,
198
- pxeOracleInterface,
199
230
  );
200
231
  }
201
232
 
@@ -252,13 +283,23 @@ export class TXESession implements TXESessionStateHandler {
252
283
  }
253
284
  }
254
285
 
286
+ // Commit all staged stores from the job that was just completed, then begin a new job
287
+ await this.jobCoordinator.commitJob(this.currentJobId);
288
+ this.currentJobId = this.jobCoordinator.beginJob();
289
+
255
290
  this.oracleHandler = new TXEOracleTopLevelContext(
256
291
  this.stateMachine,
257
- this.contractDataProvider,
292
+ this.contractStore,
293
+ this.noteStore,
258
294
  this.keyStore,
259
- this.addressDataProvider,
260
- this.accountDataProvider,
261
- this.pxeOracleInterface,
295
+ this.addressStore,
296
+ this.accountStore,
297
+ this.senderTaggingStore,
298
+ this.recipientTaggingStore,
299
+ this.senderAddressBookStore,
300
+ this.capsuleStore,
301
+ this.privateEventStore,
302
+ this.currentJobId,
262
303
  this.nextBlockTimestamp,
263
304
  this.version,
264
305
  this.chainId,
@@ -275,17 +316,14 @@ export class TXESession implements TXESessionStateHandler {
275
316
  ): Promise<PrivateContextInputs> {
276
317
  this.exitTopLevelState();
277
318
 
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
319
  // Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
286
320
  // build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
287
321
  // a single transaction with the effects of what was done in the test.
288
322
  const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
323
+
324
+ await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
325
+ contractAddress,
326
+ );
289
327
  const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
290
328
 
291
329
  const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
@@ -300,17 +338,30 @@ export class TXESession implements TXESessionStateHandler {
300
338
  const noteCache = new ExecutionNoteCache(protocolNullifier);
301
339
  const taggingIndexCache = new ExecutionTaggingIndexCache();
302
340
 
341
+ const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
303
342
  this.oracleHandler = new PrivateExecutionOracle(
304
343
  Fr.ZERO,
305
344
  new TxContext(this.chainId, this.version, GasSettings.empty()),
306
345
  new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
307
346
  anchorBlock!,
347
+ utilityExecutor,
308
348
  [],
309
349
  [],
310
350
  new HashedValuesCache(),
311
351
  noteCache,
312
352
  taggingIndexCache,
313
- this.pxeOracleInterface,
353
+ this.contractStore,
354
+ this.noteStore,
355
+ this.keyStore,
356
+ this.addressStore,
357
+ this.stateMachine.node,
358
+ this.senderTaggingStore,
359
+ this.recipientTaggingStore,
360
+ this.senderAddressBookStore,
361
+ this.capsuleStore,
362
+ this.privateEventStore,
363
+ this.stateMachine.contractSyncService,
364
+ this.currentJobId,
314
365
  );
315
366
 
316
367
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
@@ -318,7 +369,7 @@ export class TXESession implements TXESessionStateHandler {
318
369
  // difference resides in that the simulator has all information needed in order to run the simulation, while ours
319
370
  // will be ongoing as the different oracles will be invoked from the Noir test, until eventually the private
320
371
  // execution finishes.
321
- this.state = { name: 'PRIVATE', nextBlockGlobalVariables, protocolNullifier, noteCache, taggingIndexCache };
372
+ this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
322
373
  this.logger.debug(`Entered state ${this.state.name}`);
323
374
 
324
375
  return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
@@ -351,14 +402,36 @@ export class TXESession implements TXESessionStateHandler {
351
402
  async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
352
403
  this.exitTopLevelState();
353
404
 
405
+ const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
406
+
354
407
  // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
355
408
  // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
356
409
  // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
357
410
  // be removed from the database.
358
411
  // 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);
412
+ await new NoteService(
413
+ this.noteStore,
414
+ this.stateMachine.node,
415
+ anchorBlockHeader,
416
+ this.currentJobId,
417
+ ).syncNoteNullifiers(contractAddress);
418
+
419
+ this.oracleHandler = new UtilityExecutionOracle(
420
+ contractAddress,
421
+ [],
422
+ [],
423
+ anchorBlockHeader,
424
+ this.contractStore,
425
+ this.noteStore,
426
+ this.keyStore,
427
+ this.addressStore,
428
+ this.stateMachine.node,
429
+ this.recipientTaggingStore,
430
+ this.senderAddressBookStore,
431
+ this.capsuleStore,
432
+ this.privateEventStore,
433
+ this.currentJobId,
434
+ );
362
435
 
363
436
  this.state = { name: 'UTILITY' };
364
437
  this.logger.debug(`Entered state ${this.state.name}`);
@@ -392,21 +465,14 @@ export class TXESession implements TXESessionStateHandler {
392
465
 
393
466
  // We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
394
467
  // 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
- );
468
+
469
+ const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
400
470
 
401
471
  // We build a block holding just this transaction
402
472
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
403
473
  await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
404
474
 
405
- const block = new L2Block(
406
- makeAppendOnlyTreeSnapshot(),
407
- await makeTXEBlockHeader(forkedWorldTrees, this.state.nextBlockGlobalVariables),
408
- new Body([txEffect]),
409
- );
475
+ const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [txEffect]);
410
476
  await this.stateMachine.handleL2Block(block);
411
477
 
412
478
  await forkedWorldTrees.close();
@@ -431,4 +497,48 @@ export class TXESession implements TXESessionStateHandler {
431
497
  throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
432
498
  }
433
499
  }
500
+
501
+ private utilityExecutorForContractSync(anchorBlock: any) {
502
+ return async (call: FunctionCall) => {
503
+ const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
504
+ if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
505
+ throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
506
+ }
507
+
508
+ try {
509
+ const oracle = new UtilityExecutionOracle(
510
+ call.to,
511
+ [],
512
+ [],
513
+ anchorBlock!,
514
+ this.contractStore,
515
+ this.noteStore,
516
+ this.keyStore,
517
+ this.addressStore,
518
+ this.stateMachine.node,
519
+ this.recipientTaggingStore,
520
+ this.senderAddressBookStore,
521
+ this.capsuleStore,
522
+ this.privateEventStore,
523
+ this.currentJobId,
524
+ );
525
+ await new WASMSimulator()
526
+ .executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
527
+ .catch((err: Error) => {
528
+ err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
529
+ throw new ExecutionError(
530
+ err.message,
531
+ {
532
+ contractAddress: call.to,
533
+ functionSelector: call.selector,
534
+ },
535
+ extractCallStack(err, entryPointArtifact.debug),
536
+ { cause: err },
537
+ );
538
+ });
539
+ } catch (err) {
540
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
541
+ }
542
+ };
543
+ }
434
544
  }
@@ -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,15 +1,15 @@
1
1
  import type { ContractArtifact } from '@aztec/aztec.js/abi';
2
2
  import { Fr } from '@aztec/aztec.js/fields';
3
- import { ContractDataProvider } from '@aztec/pxe/server';
3
+ import { ContractStore } from '@aztec/pxe/server';
4
4
 
5
5
  export type ContractArtifactWithHash = ContractArtifact & { artifactHash: Fr };
6
6
 
7
7
  /*
8
- * A contract data provider that stores contract artifacts with their hashes. Since
8
+ * A contract store that stores contract artifacts with their hashes. Since
9
9
  * TXE typically deploys the same contract again and again for multiple tests, caching
10
10
  * the *very* expensive artifact hash computation improves testing speed significantly.
11
11
  */
12
- export class TXEContractDataProvider extends ContractDataProvider {
12
+ export class TXEContractStore extends ContractStore {
13
13
  #artifactHashes: Map<string, Buffer> = new Map();
14
14
 
15
15
  public override async addContractArtifact(
@@ -1,6 +1,6 @@
1
1
  import { BlockNumber } from '@aztec/foundation/branded-types';
2
- import { Fr } from '@aztec/foundation/fields';
3
- import type { ContractDataProvider } from '@aztec/pxe/server';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import type { ContractStore } from '@aztec/pxe/server';
4
4
  import { type ContractArtifact, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
5
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
6
6
  import {
@@ -16,7 +16,7 @@ export class TXEPublicContractDataSource implements ContractDataSource {
16
16
  #privateFunctionsRoot: Map<string, Buffer> = new Map();
17
17
  constructor(
18
18
  private blockNumber: BlockNumber,
19
- private contractDataProvider: ContractDataProvider,
19
+ private contractStore: ContractStore,
20
20
  ) {}
21
21
 
22
22
  getBlockNumber(): Promise<BlockNumber> {
@@ -24,11 +24,11 @@ export class TXEPublicContractDataSource implements ContractDataSource {
24
24
  }
25
25
 
26
26
  async getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
27
- const contractClass = await this.contractDataProvider.getContractClass(id);
27
+ const contractClass = await this.contractStore.getContractClass(id);
28
28
  if (!contractClass) {
29
29
  return;
30
30
  }
31
- const artifact = await this.contractDataProvider.getContractArtifact(id);
31
+ const artifact = await this.contractStore.getContractArtifact(id);
32
32
  if (!artifact) {
33
33
  return;
34
34
  }
@@ -58,12 +58,12 @@ export class TXEPublicContractDataSource implements ContractDataSource {
58
58
  }
59
59
 
60
60
  async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
61
- const contractClass = await this.contractDataProvider.getContractClass(id);
61
+ const contractClass = await this.contractStore.getContractClass(id);
62
62
  return contractClass && computePublicBytecodeCommitment(contractClass.packedBytecode);
63
63
  }
64
64
 
65
65
  async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
66
- const instance = await this.contractDataProvider.getContractInstance(address);
66
+ const instance = await this.contractStore.getContractInstance(address);
67
67
  return instance && { ...instance, address };
68
68
  }
69
69
 
@@ -72,12 +72,12 @@ export class TXEPublicContractDataSource implements ContractDataSource {
72
72
  }
73
73
 
74
74
  async getContractArtifact(address: AztecAddress): Promise<ContractArtifact | undefined> {
75
- const instance = await this.contractDataProvider.getContractInstance(address);
76
- return instance && this.contractDataProvider.getContractArtifact(instance.currentContractClassId);
75
+ const instance = await this.contractStore.getContractInstance(address);
76
+ return instance && this.contractStore.getContractArtifact(instance.currentContractClassId);
77
77
  }
78
78
 
79
79
  async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
80
- return await this.contractDataProvider.getDebugFunctionName(address, selector);
80
+ return await this.contractStore.getDebugFunctionName(address, selector);
81
81
  }
82
82
 
83
83
  registerContractFunctionSignatures(_signatures: []): Promise<void> {
@@ -4,13 +4,12 @@ import {
4
4
  NULLIFIER_SUBTREE_HEIGHT,
5
5
  NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
6
6
  } from '@aztec/constants';
7
- import { BlockNumber } from '@aztec/foundation/branded-types';
7
+ import { BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
8
8
  import { padArrayEnd } from '@aztec/foundation/collection';
9
- import { Fr } from '@aztec/foundation/fields';
10
- import { L2BlockHeader } from '@aztec/stdlib/block';
11
- import { makeContentCommitment } from '@aztec/stdlib/testing';
9
+ import { Fr } from '@aztec/foundation/curves/bn254';
10
+ import { Body, L2Block } from '@aztec/stdlib/block';
12
11
  import { AppendOnlyTreeSnapshot, MerkleTreeId, type MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
13
- import { GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
12
+ import { BlockHeader, GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
14
13
 
15
14
  /**
16
15
  * Returns a transaction request hash that is valid for transactions that are the only ones in a block.
@@ -47,18 +46,52 @@ export async function insertTxEffectIntoWorldTrees(
47
46
  export async function makeTXEBlockHeader(
48
47
  worldTrees: MerkleTreeWriteOperations,
49
48
  globalVariables: GlobalVariables,
50
- ): Promise<L2BlockHeader> {
49
+ ): Promise<BlockHeader> {
51
50
  const stateReference = await worldTrees.getStateReference();
52
51
  const archiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
53
52
 
54
- return new L2BlockHeader(
55
- new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)),
56
- makeContentCommitment(),
57
- stateReference,
53
+ return BlockHeader.from({
54
+ lastArchive: new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)),
55
+ spongeBlobHash: Fr.ZERO,
56
+ state: stateReference,
58
57
  globalVariables,
59
- Fr.ZERO,
60
- Fr.ZERO,
61
- Fr.ZERO,
62
- Fr.ZERO,
63
- );
58
+ totalFees: Fr.ZERO,
59
+ totalManaUsed: Fr.ZERO,
60
+ });
61
+ }
62
+
63
+ /**
64
+ * Creates an L2Block with proper archive chaining.
65
+ * This function:
66
+ * 1. Gets the current archive state as lastArchive for the header
67
+ * 2. Creates the block header
68
+ * 3. Updates the archive tree with the header hash
69
+ * 4. Gets the new archive state for the block's archive
70
+ *
71
+ * @param worldTrees - The world trees to read/write from
72
+ * @param globalVariables - Global variables for the block
73
+ * @param txEffects - Transaction effects to include in the block
74
+ * @returns The created L2Block with proper archive chaining
75
+ */
76
+ export async function makeTXEBlock(
77
+ worldTrees: MerkleTreeWriteOperations,
78
+ globalVariables: GlobalVariables,
79
+ txEffects: TxEffect[],
80
+ ): Promise<L2Block> {
81
+ const header = await makeTXEBlockHeader(worldTrees, globalVariables);
82
+
83
+ // Update the archive tree with this block's header hash
84
+ await worldTrees.updateArchive(header);
85
+
86
+ // Get the new archive state after updating
87
+ const newArchiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
88
+ const newArchive = new AppendOnlyTreeSnapshot(new Fr(newArchiveInfo.root), Number(newArchiveInfo.size));
89
+
90
+ // L2Block requires checkpointNumber and indexWithinCheckpoint.
91
+ // TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
92
+ // This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
93
+ const checkpointNumber = CheckpointNumber.fromBlockNumber(globalVariables.blockNumber);
94
+ const indexWithinCheckpoint = IndexWithinCheckpoint(0);
95
+
96
+ return new L2Block(newArchive, header, new Body(txEffects), checkpointNumber, indexWithinCheckpoint);
64
97
  }
@@ -1,19 +1,15 @@
1
1
  import { BlockNumber } from '@aztec/foundation/branded-types';
2
- import { Fr } from '@aztec/foundation/fields';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import type { ExecutionNoteCache } from '@aztec/pxe/simulator';
4
4
  import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash } from '@aztec/stdlib/hash';
5
5
  import { TxEffect, TxHash } from '@aztec/stdlib/tx';
6
6
 
7
- export async function makeTxEffect(
8
- noteCache: ExecutionNoteCache,
9
- protocolNullifier: Fr,
10
- txBlockNumber: BlockNumber,
11
- ): Promise<TxEffect> {
7
+ export async function makeTxEffect(noteCache: ExecutionNoteCache, txBlockNumber: BlockNumber): Promise<TxEffect> {
12
8
  const txEffect = TxEffect.empty();
13
9
 
14
- const { usedProtocolNullifierForNonces } = noteCache.finish();
15
- const nonceGenerator = usedProtocolNullifierForNonces ? protocolNullifier : noteCache.getAllNullifiers()[0];
10
+ noteCache.finish();
16
11
 
12
+ const nonceGenerator = noteCache.getNonceGenerator();
17
13
  txEffect.noteHashes = await Promise.all(
18
14
  noteCache
19
15
  .getAllNotes()
@@ -28,10 +24,6 @@ export async function makeTxEffect(
28
24
  // Nullifiers are already siloed
29
25
  txEffect.nullifiers = noteCache.getAllNullifiers();
30
26
 
31
- if (usedProtocolNullifierForNonces) {
32
- txEffect.nullifiers.unshift(protocolNullifier);
33
- }
34
-
35
27
  txEffect.txHash = new TxHash(new Fr(txBlockNumber));
36
28
 
37
29
  return txEffect;
@@ -1,10 +0,0 @@
1
- import type { AztecAsyncKVStore } from '@aztec/kv-store';
2
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
- import { CompleteAddress } from '@aztec/stdlib/contract';
4
- export declare class TXEAccountDataProvider {
5
- #private;
6
- constructor(store: AztecAsyncKVStore);
7
- getAccount(key: AztecAddress): Promise<CompleteAddress>;
8
- setAccount(key: AztecAddress, value: CompleteAddress): Promise<void>;
9
- }
10
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhlX2FjY291bnRfZGF0YV9wcm92aWRlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWwvdHhlX2FjY291bnRfZGF0YV9wcm92aWRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFFekQscUJBQWEsc0JBQXNCOztJQUdqQyxZQUFZLEtBQUssRUFBRSxpQkFBaUIsRUFFbkM7SUFFSyxVQUFVLENBQUMsR0FBRyxFQUFFLFlBQVksNEJBTWpDO0lBRUssVUFBVSxDQUFDLEdBQUcsRUFBRSxZQUFZLEVBQUUsS0FBSyxFQUFFLGVBQWUsaUJBRXpEO0NBQ0YifQ==
@@ -1 +0,0 @@
1
- {"version":3,"file":"txe_account_data_provider.d.ts","sourceRoot":"","sources":["../../src/util/txe_account_data_provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,sBAAsB;;IAGjC,YAAY,KAAK,EAAE,iBAAiB,EAEnC;IAEK,UAAU,CAAC,GAAG,EAAE,YAAY,4BAMjC;IAEK,UAAU,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,eAAe,iBAEzD;CACF"}