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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dest/constants.d.ts +3 -0
  2. package/dest/constants.d.ts.map +1 -0
  3. package/dest/constants.js +2 -0
  4. package/dest/index.d.ts +1 -1
  5. package/dest/index.d.ts.map +1 -1
  6. package/dest/index.js +91 -56
  7. package/dest/oracle/interfaces.d.ts +33 -29
  8. package/dest/oracle/interfaces.d.ts.map +1 -1
  9. package/dest/oracle/txe_oracle_public_context.d.ts +16 -16
  10. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_public_context.js +20 -22
  12. package/dest/oracle/txe_oracle_top_level_context.d.ts +37 -27
  13. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  14. package/dest/oracle/txe_oracle_top_level_context.js +211 -98
  15. package/dest/rpc_translator.d.ts +96 -79
  16. package/dest/rpc_translator.d.ts.map +1 -1
  17. package/dest/rpc_translator.js +362 -173
  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 +66 -99
  21. package/dest/state_machine/dummy_p2p_client.d.ts +20 -15
  22. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  23. package/dest/state_machine/dummy_p2p_client.js +42 -25
  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 +9 -7
  28. package/dest/state_machine/index.d.ts.map +1 -1
  29. package/dest/state_machine/index.js +44 -23
  30. package/dest/state_machine/mock_epoch_cache.d.ts +25 -8
  31. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  32. package/dest/state_machine/mock_epoch_cache.js +46 -9
  33. package/dest/state_machine/synchronizer.d.ts +6 -5
  34. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  35. package/dest/state_machine/synchronizer.js +8 -7
  36. package/dest/txe_session.d.ts +27 -15
  37. package/dest/txe_session.d.ts.map +1 -1
  38. package/dest/txe_session.js +170 -55
  39. package/dest/util/encoding.d.ts +686 -19
  40. package/dest/util/encoding.d.ts.map +1 -1
  41. package/dest/util/encoding.js +1 -1
  42. package/dest/util/txe_account_store.d.ts +10 -0
  43. package/dest/util/txe_account_store.d.ts.map +1 -0
  44. package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
  45. package/dest/util/txe_public_contract_data_source.d.ts +8 -8
  46. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  47. package/dest/util/txe_public_contract_data_source.js +13 -32
  48. package/dest/utils/block_creation.d.ts +21 -6
  49. package/dest/utils/block_creation.d.ts.map +1 -1
  50. package/dest/utils/block_creation.js +38 -4
  51. package/dest/utils/tx_effect_creation.d.ts +3 -3
  52. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  53. package/dest/utils/tx_effect_creation.js +4 -7
  54. package/package.json +18 -18
  55. package/src/constants.ts +3 -0
  56. package/src/index.ts +103 -63
  57. package/src/oracle/interfaces.ts +36 -32
  58. package/src/oracle/txe_oracle_public_context.ts +21 -28
  59. package/src/oracle/txe_oracle_top_level_context.ts +256 -138
  60. package/src/rpc_translator.ts +419 -191
  61. package/src/state_machine/archiver.ts +62 -117
  62. package/src/state_machine/dummy_p2p_client.ts +58 -33
  63. package/src/state_machine/global_variable_builder.ts +21 -4
  64. package/src/state_machine/index.ts +65 -21
  65. package/src/state_machine/mock_epoch_cache.ts +57 -14
  66. package/src/state_machine/synchronizer.ts +9 -8
  67. package/src/txe_session.ts +236 -104
  68. package/src/util/encoding.ts +1 -1
  69. package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
  70. package/src/util/txe_public_contract_data_source.ts +20 -47
  71. package/src/utils/block_creation.ts +49 -15
  72. package/src/utils/tx_effect_creation.ts +5 -12
  73. package/dest/util/txe_account_data_provider.d.ts +0 -10
  74. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  75. package/dest/util/txe_contract_data_provider.d.ts +0 -12
  76. package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
  77. package/dest/util/txe_contract_data_provider.js +0 -22
  78. package/src/util/txe_contract_data_provider.ts +0 -36
@@ -1,15 +1,22 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
4
  import { KeyStore } from '@aztec/key-store';
4
5
  import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
5
- import type { ProtocolContract } from '@aztec/protocol-contracts';
6
+ import type { AccessScopes } from '@aztec/pxe/client/lazy';
6
7
  import {
7
- AddressDataProvider,
8
- CapsuleDataProvider,
9
- NoteDataProvider,
10
- PXEOracleInterface,
11
- PrivateEventDataProvider,
12
- TaggingDataProvider,
8
+ AddressStore,
9
+ AnchorBlockStore,
10
+ CapsuleStore,
11
+ ContractStore,
12
+ ContractSyncService,
13
+ JobCoordinator,
14
+ NoteService,
15
+ NoteStore,
16
+ PrivateEventStore,
17
+ RecipientTaggingStore,
18
+ SenderAddressBookStore,
19
+ SenderTaggingStore,
13
20
  } from '@aztec/pxe/server';
14
21
  import {
15
22
  ExecutionNoteCache,
@@ -17,35 +24,39 @@ import {
17
24
  HashedValuesCache,
18
25
  type IPrivateExecutionOracle,
19
26
  type IUtilityExecutionOracle,
27
+ Oracle,
20
28
  PrivateExecutionOracle,
21
29
  UtilityExecutionOracle,
22
30
  } from '@aztec/pxe/simulator';
23
- import { FunctionSelector } from '@aztec/stdlib/abi';
31
+ import {
32
+ ExecutionError,
33
+ WASMSimulator,
34
+ createSimulationError,
35
+ extractCallStack,
36
+ resolveAssertionMessageFromError,
37
+ toACVMWitness,
38
+ } from '@aztec/simulator/client';
39
+ import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
24
40
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
25
41
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
26
- import { Body, L2Block } from '@aztec/stdlib/block';
27
42
  import { GasSettings } from '@aztec/stdlib/gas';
28
43
  import { computeProtocolNullifier } from '@aztec/stdlib/hash';
29
44
  import { PrivateContextInputs } from '@aztec/stdlib/kernel';
30
- import { makeAppendOnlyTreeSnapshot, makeGlobalVariables } from '@aztec/stdlib/testing';
45
+ import { makeGlobalVariables } from '@aztec/stdlib/testing';
31
46
  import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
32
- import type { UInt32 } from '@aztec/stdlib/types';
33
47
 
34
48
  import { z } from 'zod';
35
49
 
50
+ import { DEFAULT_ADDRESS } from './constants.js';
36
51
  import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
37
52
  import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
38
53
  import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
39
54
  import { RPCTranslator } from './rpc_translator.js';
55
+ import { TXEArchiver } from './state_machine/archiver.js';
40
56
  import { TXEStateMachine } from './state_machine/index.js';
41
57
  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';
58
+ import { TXEAccountStore } from './util/txe_account_store.js';
59
+ import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
49
60
  import { makeTxEffect } from './utils/tx_effect_creation.js';
50
61
 
51
62
  /**
@@ -67,7 +78,6 @@ type SessionState =
67
78
  | {
68
79
  name: 'PRIVATE';
69
80
  nextBlockGlobalVariables: GlobalVariables;
70
- protocolNullifier: Fr;
71
81
  noteCache: ExecutionNoteCache;
72
82
  taggingIndexCache: ExecutionTaggingIndexCache;
73
83
  }
@@ -102,11 +112,13 @@ export type TXEOracleFunctionName = Exclude<
102
112
  export interface TXESessionStateHandler {
103
113
  enterTopLevelState(): Promise<void>;
104
114
  enterPublicState(contractAddress?: AztecAddress): Promise<void>;
105
- enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: UInt32): Promise<PrivateContextInputs>;
115
+ enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
106
116
  enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
107
- }
108
117
 
109
- const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
118
+ // TODO(F-335): Exposing the job info is abstraction breakage - drop the following 2 functions.
119
+ cycleJob(): Promise<string>;
120
+ getCurrentJob(): string;
121
+ }
110
122
 
111
123
  /**
112
124
  * A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
@@ -124,78 +136,100 @@ export class TXESession implements TXESessionStateHandler {
124
136
  | IPrivateExecutionOracle
125
137
  | IAvmExecutionOracle
126
138
  | ITxeExecutionOracle,
127
- private contractDataProvider: TXEContractDataProvider,
139
+ private contractStore: ContractStore,
140
+ private noteStore: NoteStore,
128
141
  private keyStore: KeyStore,
129
- private addressDataProvider: AddressDataProvider,
130
- private accountDataProvider: TXEAccountDataProvider,
142
+ private addressStore: AddressStore,
143
+ private accountStore: TXEAccountStore,
144
+ private senderTaggingStore: SenderTaggingStore,
145
+ private recipientTaggingStore: RecipientTaggingStore,
146
+ private senderAddressBookStore: SenderAddressBookStore,
147
+ private capsuleStore: CapsuleStore,
148
+ private privateEventStore: PrivateEventStore,
149
+ private jobCoordinator: JobCoordinator,
150
+ private currentJobId: string,
131
151
  private chainId: Fr,
132
152
  private version: Fr,
133
153
  private nextBlockTimestamp: bigint,
134
- private pxeOracleInterface: PXEOracleInterface,
154
+ private contractSyncService: ContractSyncService,
135
155
  ) {}
136
156
 
137
- static async init(protocolContracts: ProtocolContract[]) {
157
+ static async init(contractStore: ContractStore) {
138
158
  const store = await openTmpStore('txe-session');
139
159
 
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);
160
+ const addressStore = new AddressStore(store);
161
+ const privateEventStore = new PrivateEventStore(store);
162
+ const noteStore = new NoteStore(store);
163
+ const senderTaggingStore = new SenderTaggingStore(store);
164
+ const recipientTaggingStore = new RecipientTaggingStore(store);
165
+ const senderAddressBookStore = new SenderAddressBookStore(store);
166
+ const capsuleStore = new CapsuleStore(store);
146
167
  const keyStore = new KeyStore(store);
147
- const accountDataProvider = new TXEAccountDataProvider(store);
148
-
149
- // Register protocol contracts.
150
- for (const { contractClass, instance, artifact } of protocolContracts) {
151
- await contractDataProvider.addContractArtifact(contractClass.id, artifact);
152
- await contractDataProvider.addContractInstance(instance);
153
- }
154
-
155
- const stateMachine = await TXEStateMachine.create(store);
168
+ const accountStore = new TXEAccountStore(store);
169
+
170
+ // Create job coordinator and register staged stores
171
+ const jobCoordinator = new JobCoordinator(store);
172
+ jobCoordinator.registerStores([
173
+ capsuleStore,
174
+ senderTaggingStore,
175
+ recipientTaggingStore,
176
+ privateEventStore,
177
+ noteStore,
178
+ ]);
179
+
180
+ const archiver = new TXEArchiver(store);
181
+ const anchorBlockStore = new AnchorBlockStore(store);
182
+ const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
156
183
 
157
184
  const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
158
185
  const version = new Fr(await stateMachine.node.getVersion());
159
186
  const chainId = new Fr(await stateMachine.node.getChainId());
160
187
 
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
- );
188
+ const initialJobId = jobCoordinator.beginJob();
189
+
190
+ const logger = createLogger('txe:session');
191
+ const contractSyncService = new ContractSyncService(stateMachine.node, contractStore, noteStore, logger);
172
192
 
173
193
  const topLevelOracleHandler = new TXEOracleTopLevelContext(
174
194
  stateMachine,
175
- contractDataProvider,
195
+ contractStore,
196
+ noteStore,
176
197
  keyStore,
177
- addressDataProvider,
178
- accountDataProvider,
179
- pxeOracleInterface,
198
+ addressStore,
199
+ accountStore,
200
+ senderTaggingStore,
201
+ recipientTaggingStore,
202
+ senderAddressBookStore,
203
+ capsuleStore,
204
+ privateEventStore,
180
205
  nextBlockTimestamp,
181
206
  version,
182
207
  chainId,
183
208
  new Map(),
209
+ contractSyncService,
184
210
  );
185
- await topLevelOracleHandler.txeAdvanceBlocksBy(1);
211
+ await topLevelOracleHandler.advanceBlocksBy(1);
186
212
 
187
213
  return new TXESession(
188
- createLogger('txe:session'),
214
+ logger,
189
215
  stateMachine,
190
216
  topLevelOracleHandler,
191
- contractDataProvider,
217
+ contractStore,
218
+ noteStore,
192
219
  keyStore,
193
- addressDataProvider,
194
- accountDataProvider,
220
+ addressStore,
221
+ accountStore,
222
+ senderTaggingStore,
223
+ recipientTaggingStore,
224
+ senderAddressBookStore,
225
+ capsuleStore,
226
+ privateEventStore,
227
+ jobCoordinator,
228
+ initialJobId,
195
229
  version,
196
230
  chainId,
197
231
  nextBlockTimestamp,
198
- pxeOracleInterface,
232
+ contractSyncService,
199
233
  );
200
234
  }
201
235
 
@@ -230,6 +264,17 @@ export class TXESession implements TXESessionStateHandler {
230
264
  }
231
265
  }
232
266
 
267
+ getCurrentJob(): string {
268
+ return this.currentJobId;
269
+ }
270
+
271
+ /** Commits the current job and begins a new one. Returns the new job ID. */
272
+ async cycleJob(): Promise<string> {
273
+ await this.jobCoordinator.commitJob(this.currentJobId);
274
+ this.currentJobId = this.jobCoordinator.beginJob();
275
+ return this.currentJobId;
276
+ }
277
+
233
278
  async enterTopLevelState() {
234
279
  switch (this.state.name) {
235
280
  case 'PRIVATE': {
@@ -252,17 +297,26 @@ export class TXESession implements TXESessionStateHandler {
252
297
  }
253
298
  }
254
299
 
300
+ // Commit all staged stores from the job that was just completed, then begin a new job
301
+ await this.cycleJob();
302
+
255
303
  this.oracleHandler = new TXEOracleTopLevelContext(
256
304
  this.stateMachine,
257
- this.contractDataProvider,
305
+ this.contractStore,
306
+ this.noteStore,
258
307
  this.keyStore,
259
- this.addressDataProvider,
260
- this.accountDataProvider,
261
- this.pxeOracleInterface,
308
+ this.addressStore,
309
+ this.accountStore,
310
+ this.senderTaggingStore,
311
+ this.recipientTaggingStore,
312
+ this.senderAddressBookStore,
313
+ this.capsuleStore,
314
+ this.privateEventStore,
262
315
  this.nextBlockTimestamp,
263
316
  this.version,
264
317
  this.chainId,
265
318
  this.authwits,
319
+ this.contractSyncService,
266
320
  );
267
321
 
268
322
  this.state = { name: 'TOP_LEVEL' };
@@ -271,25 +325,23 @@ export class TXESession implements TXESessionStateHandler {
271
325
 
272
326
  async enterPrivateState(
273
327
  contractAddress: AztecAddress = DEFAULT_ADDRESS,
274
- anchorBlockNumber?: UInt32,
328
+ anchorBlockNumber?: BlockNumber,
275
329
  ): Promise<PrivateContextInputs> {
276
330
  this.exitTopLevelState();
277
331
 
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
332
  // Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
286
333
  // build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
287
334
  // a single transaction with the effects of what was done in the test.
288
335
  const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
336
+
337
+ await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
338
+ contractAddress,
339
+ 'ALL_SCOPES',
340
+ );
289
341
  const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
290
342
 
291
343
  const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
292
- blockNumber: latestBlock!.globalVariables.blockNumber + 1,
344
+ blockNumber: BlockNumber(latestBlock!.globalVariables.blockNumber + 1),
293
345
  timestamp: this.nextBlockTimestamp,
294
346
  version: this.version,
295
347
  chainId: this.chainId,
@@ -300,25 +352,40 @@ export class TXESession implements TXESessionStateHandler {
300
352
  const noteCache = new ExecutionNoteCache(protocolNullifier);
301
353
  const taggingIndexCache = new ExecutionTaggingIndexCache();
302
354
 
303
- this.oracleHandler = new PrivateExecutionOracle(
304
- Fr.ZERO,
305
- new TxContext(this.chainId, this.version, GasSettings.empty()),
306
- new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
307
- anchorBlock!,
308
- [],
309
- [],
310
- new HashedValuesCache(),
355
+ const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
356
+ this.oracleHandler = new PrivateExecutionOracle({
357
+ argsHash: Fr.ZERO,
358
+ txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
359
+ callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
360
+ anchorBlockHeader: anchorBlock!,
361
+ utilityExecutor,
362
+ authWitnesses: [],
363
+ capsules: [],
364
+ executionCache: new HashedValuesCache(),
311
365
  noteCache,
312
366
  taggingIndexCache,
313
- this.pxeOracleInterface,
314
- );
367
+ contractStore: this.contractStore,
368
+ noteStore: this.noteStore,
369
+ keyStore: this.keyStore,
370
+ addressStore: this.addressStore,
371
+ aztecNode: this.stateMachine.node,
372
+ senderTaggingStore: this.senderTaggingStore,
373
+ recipientTaggingStore: this.recipientTaggingStore,
374
+ senderAddressBookStore: this.senderAddressBookStore,
375
+ capsuleStore: this.capsuleStore,
376
+ privateEventStore: this.privateEventStore,
377
+ contractSyncService: this.stateMachine.contractSyncService,
378
+ jobId: this.currentJobId,
379
+ scopes: 'ALL_SCOPES',
380
+ messageContextService: this.stateMachine.messageContextService,
381
+ });
315
382
 
316
383
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
317
384
  // data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
318
385
  // difference resides in that the simulator has all information needed in order to run the simulation, while ours
319
386
  // will be ongoing as the different oracles will be invoked from the Noir test, until eventually the private
320
387
  // execution finishes.
321
- this.state = { name: 'PRIVATE', nextBlockGlobalVariables, protocolNullifier, noteCache, taggingIndexCache };
388
+ this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
322
389
  this.logger.debug(`Entered state ${this.state.name}`);
323
390
 
324
391
  return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
@@ -331,7 +398,7 @@ export class TXESession implements TXESessionStateHandler {
331
398
  // the test. The block therefore gets the *next* block number and timestamp.
332
399
  const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.blockNumber;
333
400
  const globalVariables = makeGlobalVariables(undefined, {
334
- blockNumber: latestBlockNumber + 1,
401
+ blockNumber: BlockNumber(latestBlockNumber + 1),
335
402
  timestamp: this.nextBlockTimestamp,
336
403
  version: this.version,
337
404
  chainId: this.chainId,
@@ -351,14 +418,39 @@ export class TXESession implements TXESessionStateHandler {
351
418
  async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
352
419
  this.exitTopLevelState();
353
420
 
421
+ const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
422
+
354
423
  // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
355
424
  // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
356
425
  // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
357
426
  // be removed from the database.
358
427
  // 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);
428
+ await new NoteService(
429
+ this.noteStore,
430
+ this.stateMachine.node,
431
+ anchorBlockHeader,
432
+ this.currentJobId,
433
+ ).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
434
+
435
+ this.oracleHandler = new UtilityExecutionOracle({
436
+ contractAddress,
437
+ authWitnesses: [],
438
+ capsules: [],
439
+ anchorBlockHeader,
440
+ contractStore: this.contractStore,
441
+ noteStore: this.noteStore,
442
+ keyStore: this.keyStore,
443
+ addressStore: this.addressStore,
444
+ aztecNode: this.stateMachine.node,
445
+ recipientTaggingStore: this.recipientTaggingStore,
446
+ senderAddressBookStore: this.senderAddressBookStore,
447
+ capsuleStore: this.capsuleStore,
448
+ privateEventStore: this.privateEventStore,
449
+ messageContextService: this.stateMachine.messageContextService,
450
+ contractSyncService: this.contractSyncService,
451
+ jobId: this.currentJobId,
452
+ scopes: 'ALL_SCOPES',
453
+ });
362
454
 
363
455
  this.state = { name: 'UTILITY' };
364
456
  this.logger.debug(`Entered state ${this.state.name}`);
@@ -371,8 +463,8 @@ export class TXESession implements TXESessionStateHandler {
371
463
 
372
464
  // Note that while all public and private contexts do is build a single block that we then process when exiting
373
465
  // those, the top level context performs a large number of actions not captured in the following 'close' call. Among
374
- // others, it will create empty blocks (via `txeAdvanceBlocksBy` and `deploy`), create blocks with transactions via
375
- // `txePrivateCallNewFlow` and `txePublicCallNewFlow`, add accounts to PXE via `txeAddAccount`, etc. This is a
466
+ // others, it will create empty blocks (via `advanceBlocksBy` and `deploy`), create blocks with transactions via
467
+ // `privateCallNewFlow` and `publicCallNewFlow`, add accounts to PXE via `addAccount`, etc. This is a
376
468
  // slight inconsistency in the working model of this class, but is not too bad.
377
469
  // TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
378
470
  // level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
@@ -392,21 +484,14 @@ export class TXESession implements TXESessionStateHandler {
392
484
 
393
485
  // We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
394
486
  // 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
- );
487
+
488
+ const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
400
489
 
401
490
  // We build a block holding just this transaction
402
491
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
403
492
  await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
404
493
 
405
- const block = new L2Block(
406
- makeAppendOnlyTreeSnapshot(),
407
- await makeTXEBlockHeader(forkedWorldTrees, this.state.nextBlockGlobalVariables),
408
- new Body([txEffect]),
409
- );
494
+ const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [txEffect]);
410
495
  await this.stateMachine.handleL2Block(block);
411
496
 
412
497
  await forkedWorldTrees.close();
@@ -431,4 +516,51 @@ export class TXESession implements TXESessionStateHandler {
431
516
  throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
432
517
  }
433
518
  }
519
+
520
+ private utilityExecutorForContractSync(anchorBlock: any) {
521
+ return async (call: FunctionCall, scopes: AccessScopes) => {
522
+ const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
523
+ if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
524
+ throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
525
+ }
526
+
527
+ try {
528
+ const oracle = new UtilityExecutionOracle({
529
+ contractAddress: call.to,
530
+ authWitnesses: [],
531
+ capsules: [],
532
+ anchorBlockHeader: anchorBlock!,
533
+ contractStore: this.contractStore,
534
+ noteStore: this.noteStore,
535
+ keyStore: this.keyStore,
536
+ addressStore: this.addressStore,
537
+ aztecNode: this.stateMachine.node,
538
+ recipientTaggingStore: this.recipientTaggingStore,
539
+ senderAddressBookStore: this.senderAddressBookStore,
540
+ capsuleStore: this.capsuleStore,
541
+ privateEventStore: this.privateEventStore,
542
+ messageContextService: this.stateMachine.messageContextService,
543
+ contractSyncService: this.contractSyncService,
544
+ jobId: this.currentJobId,
545
+ scopes,
546
+ });
547
+ await new WASMSimulator()
548
+ .executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
549
+ .catch((err: Error) => {
550
+ err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
551
+ throw new ExecutionError(
552
+ err.message,
553
+ {
554
+ contractAddress: call.to,
555
+ functionSelector: call.selector,
556
+ },
557
+ extractCallStack(err, entryPointArtifact.debug),
558
+ { cause: err },
559
+ );
560
+ });
561
+ } catch (err) {
562
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
563
+ }
564
+ };
565
+ }
434
566
  }
@@ -1,5 +1,5 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
1
2
  import type { EthAddress } from '@aztec/foundation/eth-address';
2
- import { Fr } from '@aztec/foundation/fields';
3
3
  import { hexToBuffer } from '@aztec/foundation/string';
4
4
  import { type ContractArtifact, ContractArtifactSchema } from '@aztec/stdlib/abi';
5
5
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -2,7 +2,7 @@ import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
  import { CompleteAddress } from '@aztec/stdlib/contract';
4
4
 
5
- export class TXEAccountDataProvider {
5
+ export class TXEAccountStore {
6
6
  #accounts: AztecAsyncMap<string, Buffer>;
7
7
 
8
8
  constructor(store: AztecAsyncKVStore) {
@@ -1,68 +1,41 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import type { ContractDataProvider } from '@aztec/pxe/server';
3
- import { type ContractArtifact, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import type { ContractStore } from '@aztec/pxe/server';
4
+ import { type ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
4
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- import {
6
- type ContractClassPublic,
7
- type ContractDataSource,
8
- type ContractInstanceWithAddress,
9
- computePrivateFunctionsRoot,
10
- computePublicBytecodeCommitment,
11
- getContractClassPrivateFunctionFromArtifact,
12
- } from '@aztec/stdlib/contract';
6
+ import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
13
7
 
14
8
  export class TXEPublicContractDataSource implements ContractDataSource {
15
- #privateFunctionsRoot: Map<string, Buffer> = new Map();
16
9
  constructor(
17
- private blockNumber: number,
18
- private contractDataProvider: ContractDataProvider,
10
+ private blockNumber: BlockNumber,
11
+ private contractStore: ContractStore,
19
12
  ) {}
20
13
 
21
- getBlockNumber(): Promise<number> {
14
+ getBlockNumber(): Promise<BlockNumber> {
22
15
  return Promise.resolve(this.blockNumber);
23
16
  }
24
17
 
25
18
  async getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
26
- const contractClass = await this.contractDataProvider.getContractClass(id);
19
+ const contractClass = await this.contractStore.getContractClassWithPreimage(id);
27
20
  if (!contractClass) {
28
21
  return;
29
22
  }
30
- const artifact = await this.contractDataProvider.getContractArtifact(id);
31
- if (!artifact) {
32
- return;
33
- }
34
-
35
- let privateFunctionsRoot;
36
- if (!this.#privateFunctionsRoot.has(id.toString())) {
37
- const privateFunctions = await Promise.all(
38
- artifact.functions
39
- .filter(fn => fn.functionType === FunctionType.PRIVATE)
40
- .map(fn => getContractClassPrivateFunctionFromArtifact(fn)),
41
- );
42
- privateFunctionsRoot = await computePrivateFunctionsRoot(privateFunctions);
43
- this.#privateFunctionsRoot.set(id.toString(), privateFunctionsRoot.toBuffer());
44
- } else {
45
- privateFunctionsRoot = Fr.fromBuffer(this.#privateFunctionsRoot.get(id.toString())!);
46
- }
47
-
48
23
  return {
49
- id,
50
- artifactHash: contractClass!.artifactHash,
51
- packedBytecode: contractClass!.packedBytecode,
52
- privateFunctionsRoot,
53
- version: contractClass!.version,
54
- privateFunctions: [],
55
- utilityFunctions: [],
24
+ id: contractClass.id,
25
+ artifactHash: contractClass.artifactHash,
26
+ packedBytecode: contractClass.packedBytecode,
27
+ privateFunctionsRoot: contractClass.privateFunctionsRoot,
28
+ version: contractClass.version,
56
29
  };
57
30
  }
58
31
 
59
32
  async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
60
- const contractClass = await this.contractDataProvider.getContractClass(id);
61
- return contractClass && computePublicBytecodeCommitment(contractClass.packedBytecode);
33
+ const contractClass = await this.contractStore.getContractClassWithPreimage(id);
34
+ return contractClass?.publicBytecodeCommitment;
62
35
  }
63
36
 
64
37
  async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
65
- const instance = await this.contractDataProvider.getContractInstance(address);
38
+ const instance = await this.contractStore.getContractInstance(address);
66
39
  return instance && { ...instance, address };
67
40
  }
68
41
 
@@ -71,12 +44,12 @@ export class TXEPublicContractDataSource implements ContractDataSource {
71
44
  }
72
45
 
73
46
  async getContractArtifact(address: AztecAddress): Promise<ContractArtifact | undefined> {
74
- const instance = await this.contractDataProvider.getContractInstance(address);
75
- return instance && this.contractDataProvider.getContractArtifact(instance.currentContractClassId);
47
+ const instance = await this.contractStore.getContractInstance(address);
48
+ return instance && this.contractStore.getContractArtifact(instance.currentContractClassId);
76
49
  }
77
50
 
78
51
  async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
79
- return await this.contractDataProvider.getDebugFunctionName(address, selector);
52
+ return await this.contractStore.getDebugFunctionName(address, selector);
80
53
  }
81
54
 
82
55
  registerContractFunctionSignatures(_signatures: []): Promise<void> {