@aztec/txe 0.0.1-commit.9593d84 → 0.0.1-commit.96bb3f7

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 +4 -0
  2. package/dest/constants.d.ts.map +1 -0
  3. package/dest/constants.js +3 -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 +9 -6
  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 +4 -6
  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 +93 -62
  15. package/dest/rpc_translator.d.ts +11 -5
  16. package/dest/rpc_translator.d.ts.map +1 -1
  17. package/dest/rpc_translator.js +57 -15
  18. package/dest/state_machine/archiver.d.ts +29 -11
  19. package/dest/state_machine/archiver.d.ts.map +1 -1
  20. package/dest/state_machine/archiver.js +128 -17
  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 +14 -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 +3 -0
  33. package/dest/state_machine/synchronizer.d.ts +5 -4
  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 +19 -13
  37. package/dest/txe_session.d.ts.map +1 -1
  38. package/dest/txe_session.js +76 -45
  39. package/dest/util/encoding.d.ts +610 -11
  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 +19 -4
  52. package/dest/utils/block_creation.d.ts.map +1 -1
  53. package/dest/utils/block_creation.js +24 -4
  54. package/dest/utils/tx_effect_creation.d.ts +4 -3
  55. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  56. package/dest/utils/tx_effect_creation.js +1 -1
  57. package/package.json +17 -17
  58. package/src/constants.ts +4 -0
  59. package/src/index.ts +15 -12
  60. package/src/oracle/interfaces.ts +8 -5
  61. package/src/oracle/txe_oracle_public_context.ts +6 -11
  62. package/src/oracle/txe_oracle_top_level_context.ts +139 -88
  63. package/src/rpc_translator.ts +82 -12
  64. package/src/state_machine/archiver.ts +168 -26
  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 +19 -18
  68. package/src/state_machine/mock_epoch_cache.ts +4 -0
  69. package/src/state_machine/synchronizer.ts +8 -7
  70. package/src/txe_session.ts +166 -75
  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 +36 -5
  76. package/src/utils/tx_effect_creation.ts +3 -2
  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
@@ -2,8 +2,9 @@ import { type AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
2
2
  import { TestCircuitVerifier } from '@aztec/bb-prover/test';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
5
- import { SyncDataProvider } from '@aztec/pxe/server';
6
- import { type L2Block, PublishedL2Block } from '@aztec/stdlib/block';
5
+ import { AnchorBlockStore } from '@aztec/pxe/server';
6
+ import { L2Block } from '@aztec/stdlib/block';
7
+ import { L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
7
8
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
8
9
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
9
10
 
@@ -21,13 +22,13 @@ export class TXEStateMachine {
21
22
  public node: AztecNode,
22
23
  public synchronizer: TXESynchronizer,
23
24
  public archiver: TXEArchiver,
24
- public syncDataProvider: SyncDataProvider,
25
+ public anchorBlockStore: AnchorBlockStore,
25
26
  ) {}
26
27
 
27
28
  public static async create(db: AztecAsyncKVStore) {
28
29
  const archiver = new TXEArchiver(db);
29
30
  const synchronizer = await TXESynchronizer.create();
30
- const syncDataProvider = new SyncDataProvider(db);
31
+ const anchorBlockStore = new AnchorBlockStore(db);
31
32
 
32
33
  const aztecNodeConfig = {} as AztecNodeConfig;
33
34
 
@@ -54,24 +55,24 @@ export class TXEStateMachine {
54
55
  log,
55
56
  );
56
57
 
57
- return new this(node, synchronizer, archiver, syncDataProvider);
58
+ return new this(node, synchronizer, archiver, anchorBlockStore);
58
59
  }
59
60
 
60
61
  public async handleL2Block(block: L2Block) {
62
+ const checkpoint = block.toCheckpoint();
63
+ const publishedCheckpoint = new PublishedCheckpoint(
64
+ checkpoint,
65
+ new L1PublishedData(
66
+ BigInt(block.header.globalVariables.blockNumber),
67
+ block.header.globalVariables.timestamp,
68
+ block.header.globalVariables.blockNumber.toString(),
69
+ ),
70
+ [],
71
+ );
61
72
  await Promise.all([
62
- this.synchronizer.handleL2Block(block),
63
- this.archiver.addBlocks([
64
- PublishedL2Block.fromFields({
65
- block,
66
- l1: {
67
- blockHash: block.header.globalVariables.blockNumber.toString(),
68
- blockNumber: BigInt(block.header.globalVariables.blockNumber),
69
- timestamp: block.header.globalVariables.timestamp,
70
- },
71
- attestations: [],
72
- }),
73
- ]),
74
- this.syncDataProvider.setHeader(block.getBlockHeader()),
73
+ this.synchronizer.handleL2Block(block.toL2Block()),
74
+ this.archiver.addCheckpoints([publishedCheckpoint], undefined),
75
+ this.anchorBlockStore.setHeader(block.getBlockHeader()),
75
76
  ]);
76
77
  }
77
78
  }
@@ -54,6 +54,10 @@ export class MockEpochCache implements EpochCacheInterface {
54
54
  });
55
55
  }
56
56
 
57
+ getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined> {
58
+ return Promise.resolve(undefined);
59
+ }
60
+
57
61
  isInCommittee(_slot: SlotTag, _validator: EthAddress): Promise<boolean> {
58
62
  return Promise.resolve(false);
59
63
  }
@@ -1,6 +1,7 @@
1
1
  import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
3
- import type { L2Block } from '@aztec/stdlib/block';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
+ import type { L2BlockNew } from '@aztec/stdlib/block';
4
5
  import type {
5
6
  MerkleTreeReadOperations,
6
7
  MerkleTreeWriteOperations,
@@ -12,7 +13,7 @@ import { NativeWorldStateService } from '@aztec/world-state/native';
12
13
 
13
14
  export class TXESynchronizer implements WorldStateSynchronizer {
14
15
  // This works when set to 1 as well.
15
- private blockNumber = 0;
16
+ private blockNumber = BlockNumber.ZERO;
16
17
 
17
18
  constructor(public nativeWorldStateService: NativeWorldStateService) {}
18
19
 
@@ -22,7 +23,7 @@ export class TXESynchronizer implements WorldStateSynchronizer {
22
23
  return new this(nativeWorldStateService);
23
24
  }
24
25
 
25
- public async handleL2Block(block: L2Block) {
26
+ public async handleL2Block(block: L2BlockNew) {
26
27
  await this.nativeWorldStateService.handleL2BlockAndMessages(
27
28
  block,
28
29
  Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero),
@@ -37,7 +38,7 @@ export class TXESynchronizer implements WorldStateSynchronizer {
37
38
  * @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
38
39
  * @returns A promise that resolves with the block number the world state was synced to
39
40
  */
40
- public syncImmediate(_minBlockNumber?: number, _skipThrowIfTargetNotReached?: boolean): Promise<number> {
41
+ public syncImmediate(_minBlockNumber?: BlockNumber, _skipThrowIfTargetNotReached?: boolean): Promise<BlockNumber> {
41
42
  return Promise.resolve(this.blockNumber);
42
43
  }
43
44
 
@@ -48,12 +49,12 @@ export class TXESynchronizer implements WorldStateSynchronizer {
48
49
 
49
50
  /** Forks the world state at the given block number, defaulting to the latest one. */
50
51
  public fork(block?: number): Promise<MerkleTreeWriteOperations> {
51
- return this.nativeWorldStateService.fork(block);
52
+ return this.nativeWorldStateService.fork(block ? BlockNumber(block) : undefined);
52
53
  }
53
54
 
54
55
  /** Gets a handle that allows reading the state as it was at the given block number. */
55
56
  public getSnapshot(blockNumber: number): MerkleTreeReadOperations {
56
- return this.nativeWorldStateService.getSnapshot(blockNumber);
57
+ return this.nativeWorldStateService.getSnapshot(BlockNumber(blockNumber));
57
58
  }
58
59
 
59
60
  /** Backups the db to the target path. */
@@ -1,15 +1,18 @@
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
+ NoteService,
11
+ NoteStore,
12
+ PrivateEventStore,
13
+ RecipientTaggingStore,
14
+ SenderAddressBookStore,
15
+ SenderTaggingStore,
13
16
  } from '@aztec/pxe/server';
14
17
  import {
15
18
  ExecutionNoteCache,
@@ -17,35 +20,39 @@ import {
17
20
  HashedValuesCache,
18
21
  type IPrivateExecutionOracle,
19
22
  type IUtilityExecutionOracle,
23
+ Oracle,
20
24
  PrivateExecutionOracle,
21
25
  UtilityExecutionOracle,
22
26
  } from '@aztec/pxe/simulator';
23
- import { FunctionSelector } from '@aztec/stdlib/abi';
27
+ import {
28
+ ExecutionError,
29
+ WASMSimulator,
30
+ createSimulationError,
31
+ extractCallStack,
32
+ resolveAssertionMessageFromError,
33
+ toACVMWitness,
34
+ } from '@aztec/simulator/client';
35
+ import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
24
36
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
25
37
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
26
- import { Body, L2Block } from '@aztec/stdlib/block';
27
38
  import { GasSettings } from '@aztec/stdlib/gas';
28
39
  import { computeProtocolNullifier } from '@aztec/stdlib/hash';
29
40
  import { PrivateContextInputs } from '@aztec/stdlib/kernel';
30
- import { makeAppendOnlyTreeSnapshot, makeGlobalVariables } from '@aztec/stdlib/testing';
41
+ import { makeGlobalVariables } from '@aztec/stdlib/testing';
31
42
  import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
32
- import type { UInt32 } from '@aztec/stdlib/types';
33
43
 
34
44
  import { z } from 'zod';
35
45
 
46
+ import { DEFAULT_ADDRESS, TXE_JOB_ID } from './constants.js';
36
47
  import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
37
48
  import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
38
49
  import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
39
50
  import { RPCTranslator } from './rpc_translator.js';
40
51
  import { TXEStateMachine } from './state_machine/index.js';
41
52
  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';
53
+ import { TXEAccountStore } from './util/txe_account_store.js';
54
+ import { TXEContractStore } from './util/txe_contract_store.js';
55
+ import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
49
56
  import { makeTxEffect } from './utils/tx_effect_creation.js';
50
57
 
51
58
  /**
@@ -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,39 @@ 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,
131
142
  private chainId: Fr,
132
143
  private version: Fr,
133
144
  private nextBlockTimestamp: bigint,
134
- private pxeOracleInterface: PXEOracleInterface,
135
145
  ) {}
136
146
 
137
147
  static async init(protocolContracts: ProtocolContract[]) {
138
148
  const store = await openTmpStore('txe-session');
139
149
 
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);
150
+ const addressStore = new AddressStore(store);
151
+ const privateEventStore = new PrivateEventStore(store);
152
+ const contractStore = new TXEContractStore(store);
153
+ const noteStore = await NoteStore.create(store);
154
+ const senderTaggingStore = new SenderTaggingStore(store);
155
+ const recipientTaggingStore = new RecipientTaggingStore(store);
156
+ const senderAddressBookStore = new SenderAddressBookStore(store);
157
+ const capsuleStore = new CapsuleStore(store);
146
158
  const keyStore = new KeyStore(store);
147
- const accountDataProvider = new TXEAccountDataProvider(store);
159
+ const accountStore = new TXEAccountStore(store);
148
160
 
149
161
  // Register protocol contracts.
150
162
  for (const { contractClass, instance, artifact } of protocolContracts) {
151
- await contractDataProvider.addContractArtifact(contractClass.id, artifact);
152
- await contractDataProvider.addContractInstance(instance);
163
+ await contractStore.addContractArtifact(contractClass.id, artifact);
164
+ await contractStore.addContractInstance(instance);
153
165
  }
154
166
 
155
167
  const stateMachine = await TXEStateMachine.create(store);
@@ -158,25 +170,18 @@ export class TXESession implements TXESessionStateHandler {
158
170
  const version = new Fr(await stateMachine.node.getVersion());
159
171
  const chainId = new Fr(await stateMachine.node.getChainId());
160
172
 
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
- );
172
-
173
173
  const topLevelOracleHandler = new TXEOracleTopLevelContext(
174
174
  stateMachine,
175
- contractDataProvider,
175
+ contractStore,
176
+ noteStore,
176
177
  keyStore,
177
- addressDataProvider,
178
- accountDataProvider,
179
- pxeOracleInterface,
178
+ addressStore,
179
+ accountStore,
180
+ senderTaggingStore,
181
+ recipientTaggingStore,
182
+ senderAddressBookStore,
183
+ capsuleStore,
184
+ privateEventStore,
180
185
  nextBlockTimestamp,
181
186
  version,
182
187
  chainId,
@@ -188,14 +193,19 @@ export class TXESession implements TXESessionStateHandler {
188
193
  createLogger('txe:session'),
189
194
  stateMachine,
190
195
  topLevelOracleHandler,
191
- contractDataProvider,
196
+ contractStore,
197
+ noteStore,
192
198
  keyStore,
193
- addressDataProvider,
194
- accountDataProvider,
199
+ addressStore,
200
+ accountStore,
201
+ senderTaggingStore,
202
+ recipientTaggingStore,
203
+ senderAddressBookStore,
204
+ capsuleStore,
205
+ privateEventStore,
195
206
  version,
196
207
  chainId,
197
208
  nextBlockTimestamp,
198
- pxeOracleInterface,
199
209
  );
200
210
  }
201
211
 
@@ -254,11 +264,16 @@ export class TXESession implements TXESessionStateHandler {
254
264
 
255
265
  this.oracleHandler = new TXEOracleTopLevelContext(
256
266
  this.stateMachine,
257
- this.contractDataProvider,
267
+ this.contractStore,
268
+ this.noteStore,
258
269
  this.keyStore,
259
- this.addressDataProvider,
260
- this.accountDataProvider,
261
- this.pxeOracleInterface,
270
+ this.addressStore,
271
+ this.accountStore,
272
+ this.senderTaggingStore,
273
+ this.recipientTaggingStore,
274
+ this.senderAddressBookStore,
275
+ this.capsuleStore,
276
+ this.privateEventStore,
262
277
  this.nextBlockTimestamp,
263
278
  this.version,
264
279
  this.chainId,
@@ -271,16 +286,15 @@ export class TXESession implements TXESessionStateHandler {
271
286
 
272
287
  async enterPrivateState(
273
288
  contractAddress: AztecAddress = DEFAULT_ADDRESS,
274
- anchorBlockNumber?: UInt32,
289
+ anchorBlockNumber?: BlockNumber,
275
290
  ): Promise<PrivateContextInputs> {
276
291
  this.exitTopLevelState();
277
292
 
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);
293
+ await new NoteService(
294
+ this.noteStore,
295
+ this.stateMachine.node,
296
+ this.stateMachine.anchorBlockStore,
297
+ ).syncNoteNullifiers(contractAddress);
284
298
 
285
299
  // Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
286
300
  // build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
@@ -289,7 +303,7 @@ export class TXESession implements TXESessionStateHandler {
289
303
  const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
290
304
 
291
305
  const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
292
- blockNumber: latestBlock!.globalVariables.blockNumber + 1,
306
+ blockNumber: BlockNumber(latestBlock!.globalVariables.blockNumber + 1),
293
307
  timestamp: this.nextBlockTimestamp,
294
308
  version: this.version,
295
309
  chainId: this.chainId,
@@ -300,17 +314,30 @@ export class TXESession implements TXESessionStateHandler {
300
314
  const noteCache = new ExecutionNoteCache(protocolNullifier);
301
315
  const taggingIndexCache = new ExecutionTaggingIndexCache();
302
316
 
317
+ const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
303
318
  this.oracleHandler = new PrivateExecutionOracle(
304
319
  Fr.ZERO,
305
320
  new TxContext(this.chainId, this.version, GasSettings.empty()),
306
321
  new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
307
322
  anchorBlock!,
323
+ utilityExecutor,
308
324
  [],
309
325
  [],
310
326
  new HashedValuesCache(),
311
327
  noteCache,
312
328
  taggingIndexCache,
313
- this.pxeOracleInterface,
329
+ this.contractStore,
330
+ this.noteStore,
331
+ this.keyStore,
332
+ this.addressStore,
333
+ this.stateMachine.node,
334
+ this.stateMachine.anchorBlockStore,
335
+ this.senderTaggingStore,
336
+ this.recipientTaggingStore,
337
+ this.senderAddressBookStore,
338
+ this.capsuleStore,
339
+ this.privateEventStore,
340
+ TXE_JOB_ID,
314
341
  );
315
342
 
316
343
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
@@ -331,7 +358,7 @@ export class TXESession implements TXESessionStateHandler {
331
358
  // the test. The block therefore gets the *next* block number and timestamp.
332
359
  const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.blockNumber;
333
360
  const globalVariables = makeGlobalVariables(undefined, {
334
- blockNumber: latestBlockNumber + 1,
361
+ blockNumber: BlockNumber(latestBlockNumber + 1),
335
362
  timestamp: this.nextBlockTimestamp,
336
363
  version: this.version,
337
364
  chainId: this.chainId,
@@ -356,9 +383,31 @@ export class TXESession implements TXESessionStateHandler {
356
383
  // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
357
384
  // be removed from the database.
358
385
  // TODO(#12553): make the synchronizer sync here instead and remove this
359
- await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
386
+ await new NoteService(
387
+ this.noteStore,
388
+ this.stateMachine.node,
389
+ this.stateMachine.anchorBlockStore,
390
+ ).syncNoteNullifiers(contractAddress);
391
+
392
+ const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
360
393
 
361
- this.oracleHandler = new UtilityExecutionOracle(contractAddress, [], [], this.pxeOracleInterface);
394
+ this.oracleHandler = new UtilityExecutionOracle(
395
+ contractAddress,
396
+ [],
397
+ [],
398
+ anchorBlockHeader,
399
+ this.contractStore,
400
+ this.noteStore,
401
+ this.keyStore,
402
+ this.addressStore,
403
+ this.stateMachine.node,
404
+ this.stateMachine.anchorBlockStore,
405
+ this.recipientTaggingStore,
406
+ this.senderAddressBookStore,
407
+ this.capsuleStore,
408
+ this.privateEventStore,
409
+ TXE_JOB_ID,
410
+ );
362
411
 
363
412
  this.state = { name: 'UTILITY' };
364
413
  this.logger.debug(`Entered state ${this.state.name}`);
@@ -392,6 +441,7 @@ export class TXESession implements TXESessionStateHandler {
392
441
 
393
442
  // We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
394
443
  // logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
444
+
395
445
  const txEffect = await makeTxEffect(
396
446
  this.state.noteCache,
397
447
  this.state.protocolNullifier,
@@ -402,11 +452,7 @@ export class TXESession implements TXESessionStateHandler {
402
452
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
403
453
  await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
404
454
 
405
- const block = new L2Block(
406
- makeAppendOnlyTreeSnapshot(),
407
- await makeTXEBlockHeader(forkedWorldTrees, this.state.nextBlockGlobalVariables),
408
- new Body([txEffect]),
409
- );
455
+ const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [txEffect]);
410
456
  await this.stateMachine.handleL2Block(block);
411
457
 
412
458
  await forkedWorldTrees.close();
@@ -431,4 +477,49 @@ export class TXESession implements TXESessionStateHandler {
431
477
  throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
432
478
  }
433
479
  }
480
+
481
+ private utilityExecutorForContractSync(anchorBlock: any) {
482
+ return async (call: FunctionCall) => {
483
+ const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
484
+ if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
485
+ throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
486
+ }
487
+
488
+ try {
489
+ const oracle = new UtilityExecutionOracle(
490
+ call.to,
491
+ [],
492
+ [],
493
+ anchorBlock!,
494
+ this.contractStore,
495
+ this.noteStore,
496
+ this.keyStore,
497
+ this.addressStore,
498
+ this.stateMachine.node,
499
+ this.stateMachine.anchorBlockStore,
500
+ this.recipientTaggingStore,
501
+ this.senderAddressBookStore,
502
+ this.capsuleStore,
503
+ this.privateEventStore,
504
+ TXE_JOB_ID,
505
+ );
506
+ await new WASMSimulator()
507
+ .executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
508
+ .catch((err: Error) => {
509
+ err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
510
+ throw new ExecutionError(
511
+ err.message,
512
+ {
513
+ contractAddress: call.to,
514
+ functionSelector: call.selector,
515
+ },
516
+ extractCallStack(err, entryPointArtifact.debug),
517
+ { cause: err },
518
+ );
519
+ });
520
+ } catch (err) {
521
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
522
+ }
523
+ };
524
+ }
434
525
  }
@@ -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> {