@aztec/txe 0.0.1-commit.9b94fc1 → 0.0.1-commit.b468ad8

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 +11 -8
  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 +22 -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 +111 -72
  15. package/dest/rpc_translator.d.ts +25 -13
  16. package/dest/rpc_translator.d.ts.map +1 -1
  17. package/dest/rpc_translator.js +102 -47
  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 +61 -94
  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 +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 +5 -5
  28. package/dest/state_machine/index.d.ts.map +1 -1
  29. package/dest/state_machine/index.js +31 -19
  30. package/dest/state_machine/mock_epoch_cache.d.ts +7 -6
  31. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  32. package/dest/state_machine/mock_epoch_cache.js +10 -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 -13
  37. package/dest/txe_session.d.ts.map +1 -1
  38. package/dest/txe_session.js +94 -47
  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 +7 -6
  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 +21 -6
  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 +3 -3
  55. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  56. package/dest/utils/tx_effect_creation.js +4 -7
  57. package/package.json +18 -18
  58. package/src/constants.ts +3 -0
  59. package/src/index.ts +15 -12
  60. package/src/oracle/interfaces.ts +10 -7
  61. package/src/oracle/txe_oracle_public_context.ts +12 -19
  62. package/src/oracle/txe_oracle_top_level_context.ts +176 -99
  63. package/src/rpc_translator.ts +137 -52
  64. package/src/state_machine/archiver.ts +57 -114
  65. package/src/state_machine/dummy_p2p_client.ts +21 -14
  66. package/src/state_machine/global_variable_builder.ts +21 -4
  67. package/src/state_machine/index.ts +40 -17
  68. package/src/state_machine/mock_epoch_cache.ts +10 -11
  69. package/src/state_machine/synchronizer.ts +6 -5
  70. package/src/txe_session.ts +188 -83
  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 +13 -12
  75. package/src/utils/block_creation.ts +47 -15
  76. package/src/utils/tx_effect_creation.ts +5 -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,15 +1,19 @@
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
6
  import type { ProtocolContract } from '@aztec/protocol-contracts';
6
7
  import {
7
- AddressDataProvider,
8
- CapsuleDataProvider,
9
- NoteDataProvider,
10
- PXEOracleInterface,
11
- PrivateEventDataProvider,
12
- TaggingDataProvider,
8
+ AddressStore,
9
+ CapsuleStore,
10
+ JobCoordinator,
11
+ NoteService,
12
+ NoteStore,
13
+ PrivateEventStore,
14
+ RecipientTaggingStore,
15
+ SenderAddressBookStore,
16
+ SenderTaggingStore,
13
17
  } from '@aztec/pxe/server';
14
18
  import {
15
19
  ExecutionNoteCache,
@@ -17,35 +21,39 @@ import {
17
21
  HashedValuesCache,
18
22
  type IPrivateExecutionOracle,
19
23
  type IUtilityExecutionOracle,
24
+ Oracle,
20
25
  PrivateExecutionOracle,
21
26
  UtilityExecutionOracle,
22
27
  } from '@aztec/pxe/simulator';
23
- 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';
24
37
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
25
38
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
26
- import { Body, L2Block } from '@aztec/stdlib/block';
27
39
  import { GasSettings } from '@aztec/stdlib/gas';
28
40
  import { computeProtocolNullifier } from '@aztec/stdlib/hash';
29
41
  import { PrivateContextInputs } from '@aztec/stdlib/kernel';
30
- import { makeAppendOnlyTreeSnapshot, makeGlobalVariables } from '@aztec/stdlib/testing';
42
+ import { makeGlobalVariables } from '@aztec/stdlib/testing';
31
43
  import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
32
- import type { UInt32 } from '@aztec/stdlib/types';
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
  }
@@ -102,12 +109,10 @@ export type TXEOracleFunctionName = Exclude<
102
109
  export interface TXESessionStateHandler {
103
110
  enterTopLevelState(): Promise<void>;
104
111
  enterPublicState(contractAddress?: AztecAddress): Promise<void>;
105
- enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: UInt32): Promise<PrivateContextInputs>;
112
+ enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
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,51 @@ 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 = new NoteStore(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([
166
+ capsuleStore,
167
+ senderTaggingStore,
168
+ recipientTaggingStore,
169
+ privateEventStore,
170
+ noteStore,
171
+ ]);
148
172
 
149
173
  // Register protocol contracts.
150
174
  for (const { contractClass, instance, artifact } of protocolContracts) {
151
- await contractDataProvider.addContractArtifact(contractClass.id, artifact);
152
- await contractDataProvider.addContractInstance(instance);
175
+ await contractStore.addContractArtifact(contractClass.id, artifact);
176
+ await contractStore.addContractInstance(instance);
153
177
  }
154
178
 
155
179
  const stateMachine = await TXEStateMachine.create(store);
@@ -158,25 +182,21 @@ export class TXESession implements TXESessionStateHandler {
158
182
  const version = new Fr(await stateMachine.node.getVersion());
159
183
  const chainId = new Fr(await stateMachine.node.getChainId());
160
184
 
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
- );
185
+ const initialJobId = jobCoordinator.beginJob();
172
186
 
173
187
  const topLevelOracleHandler = new TXEOracleTopLevelContext(
174
188
  stateMachine,
175
- contractDataProvider,
189
+ contractStore,
190
+ noteStore,
176
191
  keyStore,
177
- addressDataProvider,
178
- accountDataProvider,
179
- pxeOracleInterface,
192
+ addressStore,
193
+ accountStore,
194
+ senderTaggingStore,
195
+ recipientTaggingStore,
196
+ senderAddressBookStore,
197
+ capsuleStore,
198
+ privateEventStore,
199
+ initialJobId,
180
200
  nextBlockTimestamp,
181
201
  version,
182
202
  chainId,
@@ -188,14 +208,21 @@ export class TXESession implements TXESessionStateHandler {
188
208
  createLogger('txe:session'),
189
209
  stateMachine,
190
210
  topLevelOracleHandler,
191
- contractDataProvider,
211
+ contractStore,
212
+ noteStore,
192
213
  keyStore,
193
- addressDataProvider,
194
- accountDataProvider,
214
+ addressStore,
215
+ accountStore,
216
+ senderTaggingStore,
217
+ recipientTaggingStore,
218
+ senderAddressBookStore,
219
+ capsuleStore,
220
+ privateEventStore,
221
+ jobCoordinator,
222
+ initialJobId,
195
223
  version,
196
224
  chainId,
197
225
  nextBlockTimestamp,
198
- pxeOracleInterface,
199
226
  );
200
227
  }
201
228
 
@@ -252,13 +279,23 @@ export class TXESession implements TXESessionStateHandler {
252
279
  }
253
280
  }
254
281
 
282
+ // Commit all staged stores from the job that was just completed, then begin a new job
283
+ await this.jobCoordinator.commitJob(this.currentJobId);
284
+ this.currentJobId = this.jobCoordinator.beginJob();
285
+
255
286
  this.oracleHandler = new TXEOracleTopLevelContext(
256
287
  this.stateMachine,
257
- this.contractDataProvider,
288
+ this.contractStore,
289
+ this.noteStore,
258
290
  this.keyStore,
259
- this.addressDataProvider,
260
- this.accountDataProvider,
261
- this.pxeOracleInterface,
291
+ this.addressStore,
292
+ this.accountStore,
293
+ this.senderTaggingStore,
294
+ this.recipientTaggingStore,
295
+ this.senderAddressBookStore,
296
+ this.capsuleStore,
297
+ this.privateEventStore,
298
+ this.currentJobId,
262
299
  this.nextBlockTimestamp,
263
300
  this.version,
264
301
  this.chainId,
@@ -271,25 +308,22 @@ export class TXESession implements TXESessionStateHandler {
271
308
 
272
309
  async enterPrivateState(
273
310
  contractAddress: AztecAddress = DEFAULT_ADDRESS,
274
- anchorBlockNumber?: UInt32,
311
+ anchorBlockNumber?: BlockNumber,
275
312
  ): Promise<PrivateContextInputs> {
276
313
  this.exitTopLevelState();
277
314
 
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
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
287
317
  // a single transaction with the effects of what was done in the test.
288
318
  const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
319
+
320
+ await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
321
+ contractAddress,
322
+ );
289
323
  const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
290
324
 
291
325
  const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
292
- blockNumber: latestBlock!.globalVariables.blockNumber + 1,
326
+ blockNumber: BlockNumber(latestBlock!.globalVariables.blockNumber + 1),
293
327
  timestamp: this.nextBlockTimestamp,
294
328
  version: this.version,
295
329
  chainId: this.chainId,
@@ -300,17 +334,29 @@ export class TXESession implements TXESessionStateHandler {
300
334
  const noteCache = new ExecutionNoteCache(protocolNullifier);
301
335
  const taggingIndexCache = new ExecutionTaggingIndexCache();
302
336
 
337
+ const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
303
338
  this.oracleHandler = new PrivateExecutionOracle(
304
339
  Fr.ZERO,
305
340
  new TxContext(this.chainId, this.version, GasSettings.empty()),
306
341
  new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
307
342
  anchorBlock!,
343
+ utilityExecutor,
308
344
  [],
309
345
  [],
310
346
  new HashedValuesCache(),
311
347
  noteCache,
312
348
  taggingIndexCache,
313
- this.pxeOracleInterface,
349
+ this.contractStore,
350
+ this.noteStore,
351
+ this.keyStore,
352
+ this.addressStore,
353
+ this.stateMachine.node,
354
+ this.senderTaggingStore,
355
+ this.recipientTaggingStore,
356
+ this.senderAddressBookStore,
357
+ this.capsuleStore,
358
+ this.privateEventStore,
359
+ this.currentJobId,
314
360
  );
315
361
 
316
362
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
@@ -318,7 +364,7 @@ export class TXESession implements TXESessionStateHandler {
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,36 @@ 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);
413
+
414
+ this.oracleHandler = new UtilityExecutionOracle(
415
+ contractAddress,
416
+ [],
417
+ [],
418
+ anchorBlockHeader,
419
+ this.contractStore,
420
+ this.noteStore,
421
+ this.keyStore,
422
+ this.addressStore,
423
+ this.stateMachine.node,
424
+ this.recipientTaggingStore,
425
+ this.senderAddressBookStore,
426
+ this.capsuleStore,
427
+ this.privateEventStore,
428
+ this.currentJobId,
429
+ );
362
430
 
363
431
  this.state = { name: 'UTILITY' };
364
432
  this.logger.debug(`Entered state ${this.state.name}`);
@@ -392,21 +460,14 @@ export class TXESession implements TXESessionStateHandler {
392
460
 
393
461
  // We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
394
462
  // 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
- );
463
+
464
+ const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
400
465
 
401
466
  // We build a block holding just this transaction
402
467
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
403
468
  await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
404
469
 
405
- const block = new L2Block(
406
- makeAppendOnlyTreeSnapshot(),
407
- await makeTXEBlockHeader(forkedWorldTrees, this.state.nextBlockGlobalVariables),
408
- new Body([txEffect]),
409
- );
470
+ const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [txEffect]);
410
471
  await this.stateMachine.handleL2Block(block);
411
472
 
412
473
  await forkedWorldTrees.close();
@@ -431,4 +492,48 @@ export class TXESession implements TXESessionStateHandler {
431
492
  throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
432
493
  }
433
494
  }
495
+
496
+ private utilityExecutorForContractSync(anchorBlock: any) {
497
+ return async (call: FunctionCall) => {
498
+ const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
499
+ if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
500
+ throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
501
+ }
502
+
503
+ try {
504
+ const oracle = new UtilityExecutionOracle(
505
+ call.to,
506
+ [],
507
+ [],
508
+ anchorBlock!,
509
+ this.contractStore,
510
+ this.noteStore,
511
+ this.keyStore,
512
+ this.addressStore,
513
+ this.stateMachine.node,
514
+ this.recipientTaggingStore,
515
+ this.senderAddressBookStore,
516
+ this.capsuleStore,
517
+ this.privateEventStore,
518
+ this.currentJobId,
519
+ );
520
+ await new WASMSimulator()
521
+ .executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
522
+ .catch((err: Error) => {
523
+ err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
524
+ throw new ExecutionError(
525
+ err.message,
526
+ {
527
+ contractAddress: call.to,
528
+ functionSelector: call.selector,
529
+ },
530
+ extractCallStack(err, entryPointArtifact.debug),
531
+ { cause: err },
532
+ );
533
+ });
534
+ } catch (err) {
535
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
536
+ }
537
+ };
538
+ }
434
539
  }
@@ -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,5 +1,6 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import type { ContractDataProvider } from '@aztec/pxe/server';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import type { ContractStore } from '@aztec/pxe/server';
3
4
  import { type ContractArtifact, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
4
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
6
  import {
@@ -14,20 +15,20 @@ import {
14
15
  export class TXEPublicContractDataSource implements ContractDataSource {
15
16
  #privateFunctionsRoot: Map<string, Buffer> = new Map();
16
17
  constructor(
17
- private blockNumber: number,
18
- private contractDataProvider: ContractDataProvider,
18
+ private blockNumber: BlockNumber,
19
+ private contractStore: ContractStore,
19
20
  ) {}
20
21
 
21
- getBlockNumber(): Promise<number> {
22
+ getBlockNumber(): Promise<BlockNumber> {
22
23
  return Promise.resolve(this.blockNumber);
23
24
  }
24
25
 
25
26
  async getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
26
- const contractClass = await this.contractDataProvider.getContractClass(id);
27
+ const contractClass = await this.contractStore.getContractClass(id);
27
28
  if (!contractClass) {
28
29
  return;
29
30
  }
30
- const artifact = await this.contractDataProvider.getContractArtifact(id);
31
+ const artifact = await this.contractStore.getContractArtifact(id);
31
32
  if (!artifact) {
32
33
  return;
33
34
  }
@@ -57,12 +58,12 @@ export class TXEPublicContractDataSource implements ContractDataSource {
57
58
  }
58
59
 
59
60
  async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
60
- const contractClass = await this.contractDataProvider.getContractClass(id);
61
+ const contractClass = await this.contractStore.getContractClass(id);
61
62
  return contractClass && computePublicBytecodeCommitment(contractClass.packedBytecode);
62
63
  }
63
64
 
64
65
  async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
65
- const instance = await this.contractDataProvider.getContractInstance(address);
66
+ const instance = await this.contractStore.getContractInstance(address);
66
67
  return instance && { ...instance, address };
67
68
  }
68
69
 
@@ -71,12 +72,12 @@ export class TXEPublicContractDataSource implements ContractDataSource {
71
72
  }
72
73
 
73
74
  async getContractArtifact(address: AztecAddress): Promise<ContractArtifact | undefined> {
74
- const instance = await this.contractDataProvider.getContractInstance(address);
75
- return instance && this.contractDataProvider.getContractArtifact(instance.currentContractClassId);
75
+ const instance = await this.contractStore.getContractInstance(address);
76
+ return instance && this.contractStore.getContractArtifact(instance.currentContractClassId);
76
77
  }
77
78
 
78
79
  async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
79
- return await this.contractDataProvider.getDebugFunctionName(address, selector);
80
+ return await this.contractStore.getDebugFunctionName(address, selector);
80
81
  }
81
82
 
82
83
  registerContractFunctionSignatures(_signatures: []): Promise<void> {
@@ -4,19 +4,19 @@ import {
4
4
  NULLIFIER_SUBTREE_HEIGHT,
5
5
  NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
6
6
  } from '@aztec/constants';
7
+ import { BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
7
8
  import { padArrayEnd } from '@aztec/foundation/collection';
8
- import { Fr } from '@aztec/foundation/fields';
9
- import { L2BlockHeader } from '@aztec/stdlib/block';
10
- import { makeContentCommitment } from '@aztec/stdlib/testing';
9
+ import { Fr } from '@aztec/foundation/curves/bn254';
10
+ import { Body, L2Block } from '@aztec/stdlib/block';
11
11
  import { AppendOnlyTreeSnapshot, MerkleTreeId, type MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
12
- import { GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
12
+ import { BlockHeader, GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
13
13
 
14
14
  /**
15
15
  * Returns a transaction request hash that is valid for transactions that are the only ones in a block.
16
16
  * @param blockNumber The number for the block in which there is a single transaction.
17
17
  * @returns The transaction request hash.
18
18
  */
19
- export function getSingleTxBlockRequestHash(blockNumber: number): Fr {
19
+ export function getSingleTxBlockRequestHash(blockNumber: BlockNumber): Fr {
20
20
  return new Fr(blockNumber + 9999); // Why does this need to be a high number? Why do small numbered nullifiers already exist?
21
21
  }
22
22
 
@@ -46,18 +46,50 @@ export async function insertTxEffectIntoWorldTrees(
46
46
  export async function makeTXEBlockHeader(
47
47
  worldTrees: MerkleTreeWriteOperations,
48
48
  globalVariables: GlobalVariables,
49
- ): Promise<L2BlockHeader> {
49
+ ): Promise<BlockHeader> {
50
50
  const stateReference = await worldTrees.getStateReference();
51
51
  const archiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
52
52
 
53
- return new L2BlockHeader(
54
- new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)),
55
- makeContentCommitment(),
56
- stateReference,
53
+ return BlockHeader.from({
54
+ lastArchive: new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)),
55
+ spongeBlobHash: Fr.ZERO,
56
+ state: stateReference,
57
57
  globalVariables,
58
- Fr.ZERO,
59
- Fr.ZERO,
60
- Fr.ZERO,
61
- Fr.ZERO,
62
- );
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
+ const checkpointNumber = CheckpointNumber.fromBlockNumber(globalVariables.blockNumber);
92
+ const indexWithinCheckpoint = IndexWithinCheckpoint(0);
93
+
94
+ return new L2Block(newArchive, header, new Body(txEffects), checkpointNumber, indexWithinCheckpoint);
63
95
  }
@@ -1,18 +1,15 @@
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 { ExecutionNoteCache } from '@aztec/pxe/simulator';
3
4
  import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash } from '@aztec/stdlib/hash';
4
5
  import { TxEffect, TxHash } from '@aztec/stdlib/tx';
5
6
 
6
- export async function makeTxEffect(
7
- noteCache: ExecutionNoteCache,
8
- protocolNullifier: Fr,
9
- txBlockNumber: number,
10
- ): Promise<TxEffect> {
7
+ export async function makeTxEffect(noteCache: ExecutionNoteCache, txBlockNumber: BlockNumber): Promise<TxEffect> {
11
8
  const txEffect = TxEffect.empty();
12
9
 
13
- const { usedProtocolNullifierForNonces } = noteCache.finish();
14
- const nonceGenerator = usedProtocolNullifierForNonces ? protocolNullifier : noteCache.getAllNullifiers()[0];
10
+ noteCache.finish();
15
11
 
12
+ const nonceGenerator = noteCache.getNonceGenerator();
16
13
  txEffect.noteHashes = await Promise.all(
17
14
  noteCache
18
15
  .getAllNotes()
@@ -27,10 +24,6 @@ export async function makeTxEffect(
27
24
  // Nullifiers are already siloed
28
25
  txEffect.nullifiers = noteCache.getAllNullifiers();
29
26
 
30
- if (usedProtocolNullifierForNonces) {
31
- txEffect.nullifiers.unshift(protocolNullifier);
32
- }
33
-
34
27
  txEffect.txHash = new TxHash(new Fr(txBlockNumber));
35
28
 
36
29
  return txEffect;