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

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 +5 -3
  8. package/dest/oracle/interfaces.d.ts.map +1 -1
  9. package/dest/oracle/txe_oracle_public_context.d.ts +4 -4
  10. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_public_context.js +4 -6
  12. package/dest/oracle/txe_oracle_top_level_context.d.ts +20 -11
  13. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  14. package/dest/oracle/txe_oracle_top_level_context.js +99 -62
  15. package/dest/rpc_translator.d.ts +15 -9
  16. package/dest/rpc_translator.d.ts.map +1 -1
  17. package/dest/rpc_translator.js +65 -25
  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 +62 -107
  21. package/dest/state_machine/dummy_p2p_client.d.ts +8 -7
  22. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  23. package/dest/state_machine/dummy_p2p_client.js +16 -11
  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 +6 -6
  28. package/dest/state_machine/index.d.ts.map +1 -1
  29. package/dest/state_machine/index.js +23 -20
  30. package/dest/state_machine/mock_epoch_cache.d.ts +2 -1
  31. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  32. package/dest/state_machine/mock_epoch_cache.js +5 -1
  33. package/dest/state_machine/synchronizer.d.ts +1 -1
  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 +90 -45
  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 +36 -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 +4 -2
  61. package/src/oracle/txe_oracle_public_context.ts +5 -10
  62. package/src/oracle/txe_oracle_top_level_context.ts +148 -88
  63. package/src/rpc_translator.ts +82 -28
  64. package/src/state_machine/archiver.ts +60 -130
  65. package/src/state_machine/dummy_p2p_client.ts +21 -14
  66. package/src/state_machine/global_variable_builder.ts +19 -2
  67. package/src/state_machine/index.ts +28 -19
  68. package/src/state_machine/mock_epoch_cache.ts +5 -0
  69. package/src/state_machine/synchronizer.ts +1 -2
  70. package/src/txe_session.ts +179 -76
  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 +46 -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,6 +1,6 @@
1
1
  import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
2
  import { BlockNumber } from '@aztec/foundation/branded-types';
3
- import { Fr } from '@aztec/foundation/fields';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import type { L2BlockNew } from '@aztec/stdlib/block';
5
5
  import type {
6
6
  MerkleTreeReadOperations,
@@ -27,7 +27,6 @@ export class TXESynchronizer implements WorldStateSynchronizer {
27
27
  await this.nativeWorldStateService.handleL2BlockAndMessages(
28
28
  block,
29
29
  Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero),
30
- true,
31
30
  );
32
31
 
33
32
  this.blockNumber = block.header.globalVariables.blockNumber;
@@ -1,16 +1,19 @@
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
+ CapsuleStore,
10
+ JobCoordinator,
11
+ NoteService,
12
+ NoteStore,
13
+ PrivateEventStore,
14
+ RecipientTaggingStore,
15
+ SenderAddressBookStore,
16
+ SenderTaggingStore,
14
17
  } from '@aztec/pxe/server';
15
18
  import {
16
19
  ExecutionNoteCache,
@@ -18,34 +21,39 @@ import {
18
21
  HashedValuesCache,
19
22
  type IPrivateExecutionOracle,
20
23
  type IUtilityExecutionOracle,
24
+ Oracle,
21
25
  PrivateExecutionOracle,
22
26
  UtilityExecutionOracle,
23
27
  } from '@aztec/pxe/simulator';
24
- import { FunctionSelector } from '@aztec/stdlib/abi';
28
+ import {
29
+ ExecutionError,
30
+ WASMSimulator,
31
+ createSimulationError,
32
+ extractCallStack,
33
+ resolveAssertionMessageFromError,
34
+ toACVMWitness,
35
+ } from '@aztec/simulator/client';
36
+ import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
25
37
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
26
38
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
27
- import { Body, L2Block } from '@aztec/stdlib/block';
28
39
  import { GasSettings } from '@aztec/stdlib/gas';
29
40
  import { computeProtocolNullifier } from '@aztec/stdlib/hash';
30
41
  import { PrivateContextInputs } from '@aztec/stdlib/kernel';
31
- import { makeAppendOnlyTreeSnapshot, makeGlobalVariables } from '@aztec/stdlib/testing';
42
+ import { makeGlobalVariables } from '@aztec/stdlib/testing';
32
43
  import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
33
44
 
34
45
  import { z } from 'zod';
35
46
 
47
+ import { DEFAULT_ADDRESS } from './constants.js';
36
48
  import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
37
49
  import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
38
50
  import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
39
51
  import { RPCTranslator } from './rpc_translator.js';
40
52
  import { TXEStateMachine } from './state_machine/index.js';
41
53
  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';
54
+ import { TXEAccountStore } from './util/txe_account_store.js';
55
+ import { TXEContractStore } from './util/txe_contract_store.js';
56
+ import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
49
57
  import { makeTxEffect } from './utils/tx_effect_creation.js';
50
58
 
51
59
  /**
@@ -67,7 +75,6 @@ type SessionState =
67
75
  | {
68
76
  name: 'PRIVATE';
69
77
  nextBlockGlobalVariables: GlobalVariables;
70
- protocolNullifier: Fr;
71
78
  noteCache: ExecutionNoteCache;
72
79
  taggingIndexCache: ExecutionTaggingIndexCache;
73
80
  }
@@ -106,8 +113,6 @@ export interface TXESessionStateHandler {
106
113
  enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
107
114
  }
108
115
 
109
- const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
110
-
111
116
  /**
112
117
  * A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
113
118
  * state, etc., independent of all other tests running in parallel.
@@ -124,32 +129,45 @@ export class TXESession implements TXESessionStateHandler {
124
129
  | IPrivateExecutionOracle
125
130
  | IAvmExecutionOracle
126
131
  | ITxeExecutionOracle,
127
- private contractDataProvider: TXEContractDataProvider,
132
+ private contractStore: TXEContractStore,
133
+ private noteStore: NoteStore,
128
134
  private keyStore: KeyStore,
129
- private addressDataProvider: AddressDataProvider,
130
- private accountDataProvider: TXEAccountDataProvider,
135
+ private addressStore: AddressStore,
136
+ private accountStore: TXEAccountStore,
137
+ private senderTaggingStore: SenderTaggingStore,
138
+ private recipientTaggingStore: RecipientTaggingStore,
139
+ private senderAddressBookStore: SenderAddressBookStore,
140
+ private capsuleStore: CapsuleStore,
141
+ private privateEventStore: PrivateEventStore,
142
+ private jobCoordinator: JobCoordinator,
143
+ private currentJobId: string,
131
144
  private chainId: Fr,
132
145
  private version: Fr,
133
146
  private nextBlockTimestamp: bigint,
134
- private pxeOracleInterface: PXEOracleInterface,
135
147
  ) {}
136
148
 
137
149
  static async init(protocolContracts: ProtocolContract[]) {
138
150
  const store = await openTmpStore('txe-session');
139
151
 
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);
152
+ const addressStore = new AddressStore(store);
153
+ const privateEventStore = new PrivateEventStore(store);
154
+ const contractStore = new TXEContractStore(store);
155
+ const noteStore = await NoteStore.create(store);
156
+ const senderTaggingStore = new SenderTaggingStore(store);
157
+ const recipientTaggingStore = new RecipientTaggingStore(store);
158
+ const senderAddressBookStore = new SenderAddressBookStore(store);
159
+ const capsuleStore = new CapsuleStore(store);
146
160
  const keyStore = new KeyStore(store);
147
- const accountDataProvider = new TXEAccountDataProvider(store);
161
+ const accountStore = new TXEAccountStore(store);
162
+
163
+ // Create job coordinator and register staged stores
164
+ const jobCoordinator = new JobCoordinator(store);
165
+ jobCoordinator.registerStores([capsuleStore, senderTaggingStore, recipientTaggingStore, privateEventStore]);
148
166
 
149
167
  // Register protocol contracts.
150
168
  for (const { contractClass, instance, artifact } of protocolContracts) {
151
- await contractDataProvider.addContractArtifact(contractClass.id, artifact);
152
- await contractDataProvider.addContractInstance(instance);
169
+ await contractStore.addContractArtifact(contractClass.id, artifact);
170
+ await contractStore.addContractInstance(instance);
153
171
  }
154
172
 
155
173
  const stateMachine = await TXEStateMachine.create(store);
@@ -158,25 +176,21 @@ export class TXESession implements TXESessionStateHandler {
158
176
  const version = new Fr(await stateMachine.node.getVersion());
159
177
  const chainId = new Fr(await stateMachine.node.getChainId());
160
178
 
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
- );
179
+ const initialJobId = jobCoordinator.beginJob();
172
180
 
173
181
  const topLevelOracleHandler = new TXEOracleTopLevelContext(
174
182
  stateMachine,
175
- contractDataProvider,
183
+ contractStore,
184
+ noteStore,
176
185
  keyStore,
177
- addressDataProvider,
178
- accountDataProvider,
179
- pxeOracleInterface,
186
+ addressStore,
187
+ accountStore,
188
+ senderTaggingStore,
189
+ recipientTaggingStore,
190
+ senderAddressBookStore,
191
+ capsuleStore,
192
+ privateEventStore,
193
+ initialJobId,
180
194
  nextBlockTimestamp,
181
195
  version,
182
196
  chainId,
@@ -188,14 +202,21 @@ export class TXESession implements TXESessionStateHandler {
188
202
  createLogger('txe:session'),
189
203
  stateMachine,
190
204
  topLevelOracleHandler,
191
- contractDataProvider,
205
+ contractStore,
206
+ noteStore,
192
207
  keyStore,
193
- addressDataProvider,
194
- accountDataProvider,
208
+ addressStore,
209
+ accountStore,
210
+ senderTaggingStore,
211
+ recipientTaggingStore,
212
+ senderAddressBookStore,
213
+ capsuleStore,
214
+ privateEventStore,
215
+ jobCoordinator,
216
+ initialJobId,
195
217
  version,
196
218
  chainId,
197
219
  nextBlockTimestamp,
198
- pxeOracleInterface,
199
220
  );
200
221
  }
201
222
 
@@ -252,13 +273,23 @@ export class TXESession implements TXESessionStateHandler {
252
273
  }
253
274
  }
254
275
 
276
+ // Commit all staged stores from the job that was just completed, then begin a new job
277
+ await this.jobCoordinator.commitJob(this.currentJobId);
278
+ this.currentJobId = this.jobCoordinator.beginJob();
279
+
255
280
  this.oracleHandler = new TXEOracleTopLevelContext(
256
281
  this.stateMachine,
257
- this.contractDataProvider,
282
+ this.contractStore,
283
+ this.noteStore,
258
284
  this.keyStore,
259
- this.addressDataProvider,
260
- this.accountDataProvider,
261
- this.pxeOracleInterface,
285
+ this.addressStore,
286
+ this.accountStore,
287
+ this.senderTaggingStore,
288
+ this.recipientTaggingStore,
289
+ this.senderAddressBookStore,
290
+ this.capsuleStore,
291
+ this.privateEventStore,
292
+ this.currentJobId,
262
293
  this.nextBlockTimestamp,
263
294
  this.version,
264
295
  this.chainId,
@@ -275,12 +306,11 @@ export class TXESession implements TXESessionStateHandler {
275
306
  ): Promise<PrivateContextInputs> {
276
307
  this.exitTopLevelState();
277
308
 
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);
309
+ await new NoteService(
310
+ this.noteStore,
311
+ this.stateMachine.node,
312
+ this.stateMachine.anchorBlockStore,
313
+ ).syncNoteNullifiers(contractAddress);
284
314
 
285
315
  // Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
286
316
  // build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
@@ -300,17 +330,30 @@ export class TXESession implements TXESessionStateHandler {
300
330
  const noteCache = new ExecutionNoteCache(protocolNullifier);
301
331
  const taggingIndexCache = new ExecutionTaggingIndexCache();
302
332
 
333
+ const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
303
334
  this.oracleHandler = new PrivateExecutionOracle(
304
335
  Fr.ZERO,
305
336
  new TxContext(this.chainId, this.version, GasSettings.empty()),
306
337
  new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
307
338
  anchorBlock!,
339
+ utilityExecutor,
308
340
  [],
309
341
  [],
310
342
  new HashedValuesCache(),
311
343
  noteCache,
312
344
  taggingIndexCache,
313
- this.pxeOracleInterface,
345
+ this.contractStore,
346
+ this.noteStore,
347
+ this.keyStore,
348
+ this.addressStore,
349
+ this.stateMachine.node,
350
+ this.stateMachine.anchorBlockStore,
351
+ this.senderTaggingStore,
352
+ this.recipientTaggingStore,
353
+ this.senderAddressBookStore,
354
+ this.capsuleStore,
355
+ this.privateEventStore,
356
+ this.currentJobId,
314
357
  );
315
358
 
316
359
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
@@ -318,7 +361,7 @@ export class TXESession implements TXESessionStateHandler {
318
361
  // difference resides in that the simulator has all information needed in order to run the simulation, while ours
319
362
  // will be ongoing as the different oracles will be invoked from the Noir test, until eventually the private
320
363
  // execution finishes.
321
- this.state = { name: 'PRIVATE', nextBlockGlobalVariables, protocolNullifier, noteCache, taggingIndexCache };
364
+ this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
322
365
  this.logger.debug(`Entered state ${this.state.name}`);
323
366
 
324
367
  return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
@@ -356,9 +399,31 @@ export class TXESession implements TXESessionStateHandler {
356
399
  // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
357
400
  // be removed from the database.
358
401
  // TODO(#12553): make the synchronizer sync here instead and remove this
359
- await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
402
+ await new NoteService(
403
+ this.noteStore,
404
+ this.stateMachine.node,
405
+ this.stateMachine.anchorBlockStore,
406
+ ).syncNoteNullifiers(contractAddress);
407
+
408
+ const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
360
409
 
361
- this.oracleHandler = new UtilityExecutionOracle(contractAddress, [], [], this.pxeOracleInterface);
410
+ this.oracleHandler = new UtilityExecutionOracle(
411
+ contractAddress,
412
+ [],
413
+ [],
414
+ anchorBlockHeader,
415
+ this.contractStore,
416
+ this.noteStore,
417
+ this.keyStore,
418
+ this.addressStore,
419
+ this.stateMachine.node,
420
+ this.stateMachine.anchorBlockStore,
421
+ this.recipientTaggingStore,
422
+ this.senderAddressBookStore,
423
+ this.capsuleStore,
424
+ this.privateEventStore,
425
+ this.currentJobId,
426
+ );
362
427
 
363
428
  this.state = { name: 'UTILITY' };
364
429
  this.logger.debug(`Entered state ${this.state.name}`);
@@ -392,21 +457,14 @@ export class TXESession implements TXESessionStateHandler {
392
457
 
393
458
  // We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
394
459
  // 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
- );
460
+
461
+ const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
400
462
 
401
463
  // We build a block holding just this transaction
402
464
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
403
465
  await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
404
466
 
405
- const block = new L2Block(
406
- makeAppendOnlyTreeSnapshot(),
407
- await makeTXEBlockHeader(forkedWorldTrees, this.state.nextBlockGlobalVariables),
408
- new Body([txEffect]),
409
- );
467
+ const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [txEffect]);
410
468
  await this.stateMachine.handleL2Block(block);
411
469
 
412
470
  await forkedWorldTrees.close();
@@ -431,4 +489,49 @@ export class TXESession implements TXESessionStateHandler {
431
489
  throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
432
490
  }
433
491
  }
492
+
493
+ private utilityExecutorForContractSync(anchorBlock: any) {
494
+ return async (call: FunctionCall) => {
495
+ const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
496
+ if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
497
+ throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
498
+ }
499
+
500
+ try {
501
+ const oracle = new UtilityExecutionOracle(
502
+ call.to,
503
+ [],
504
+ [],
505
+ anchorBlock!,
506
+ this.contractStore,
507
+ this.noteStore,
508
+ this.keyStore,
509
+ this.addressStore,
510
+ this.stateMachine.node,
511
+ this.stateMachine.anchorBlockStore,
512
+ this.recipientTaggingStore,
513
+ this.senderAddressBookStore,
514
+ this.capsuleStore,
515
+ this.privateEventStore,
516
+ this.currentJobId,
517
+ );
518
+ await new WASMSimulator()
519
+ .executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
520
+ .catch((err: Error) => {
521
+ err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
522
+ throw new ExecutionError(
523
+ err.message,
524
+ {
525
+ contractAddress: call.to,
526
+ functionSelector: call.selector,
527
+ },
528
+ extractCallStack(err, entryPointArtifact.debug),
529
+ { cause: err },
530
+ );
531
+ });
532
+ } catch (err) {
533
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
534
+ }
535
+ };
536
+ }
434
537
  }
@@ -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, L2BlockNew } 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,50 @@ 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 L2BlockNew 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 L2BlockNew with proper archive chaining
75
+ */
76
+ export async function makeTXEBlock(
77
+ worldTrees: MerkleTreeWriteOperations,
78
+ globalVariables: GlobalVariables,
79
+ txEffects: TxEffect[],
80
+ ): Promise<L2BlockNew> {
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
+ // L2BlockNew requires checkpointNumber and indexWithinCheckpoint
91
+ const checkpointNumber = CheckpointNumber.fromBlockNumber(globalVariables.blockNumber);
92
+ const indexWithinCheckpoint = IndexWithinCheckpoint(0);
93
+
94
+ return new L2BlockNew(newArchive, header, new Body(txEffects), checkpointNumber, indexWithinCheckpoint);
64
95
  }
@@ -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"}