@aztec/txe 0.0.1-fake-c83136db25 → 0.0.2-commit.217f559981

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 (81) hide show
  1. package/dest/bin/index.d.ts +1 -1
  2. package/dest/constants.d.ts +3 -0
  3. package/dest/constants.d.ts.map +1 -0
  4. package/dest/constants.js +2 -0
  5. package/dest/index.d.ts +1 -1
  6. package/dest/index.d.ts.map +1 -1
  7. package/dest/index.js +85 -52
  8. package/dest/oracle/interfaces.d.ts +12 -9
  9. package/dest/oracle/interfaces.d.ts.map +1 -1
  10. package/dest/oracle/txe_oracle_public_context.d.ts +7 -7
  11. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  12. package/dest/oracle/txe_oracle_public_context.js +10 -12
  13. package/dest/oracle/txe_oracle_top_level_context.d.ts +23 -14
  14. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  15. package/dest/oracle/txe_oracle_top_level_context.js +194 -87
  16. package/dest/rpc_translator.d.ts +35 -20
  17. package/dest/rpc_translator.d.ts.map +1 -1
  18. package/dest/rpc_translator.js +138 -64
  19. package/dest/state_machine/archiver.d.ts +21 -51
  20. package/dest/state_machine/archiver.d.ts.map +1 -1
  21. package/dest/state_machine/archiver.js +63 -94
  22. package/dest/state_machine/dummy_p2p_client.d.ts +20 -13
  23. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  24. package/dest/state_machine/dummy_p2p_client.js +41 -21
  25. package/dest/state_machine/global_variable_builder.d.ts +6 -4
  26. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  27. package/dest/state_machine/global_variable_builder.js +13 -1
  28. package/dest/state_machine/index.d.ts +7 -7
  29. package/dest/state_machine/index.d.ts.map +1 -1
  30. package/dest/state_machine/index.js +40 -23
  31. package/dest/state_machine/mock_epoch_cache.d.ts +14 -10
  32. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  33. package/dest/state_machine/mock_epoch_cache.js +21 -13
  34. package/dest/state_machine/synchronizer.d.ts +3 -2
  35. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  36. package/dest/state_machine/synchronizer.js +5 -4
  37. package/dest/txe_session.d.ts +21 -15
  38. package/dest/txe_session.d.ts.map +1 -1
  39. package/dest/txe_session.js +154 -53
  40. package/dest/util/encoding.d.ts +615 -16
  41. package/dest/util/encoding.d.ts.map +1 -1
  42. package/dest/util/encoding.js +1 -1
  43. package/dest/util/expected_failure_error.d.ts +1 -1
  44. package/dest/util/expected_failure_error.d.ts.map +1 -1
  45. package/dest/util/txe_account_store.d.ts +10 -0
  46. package/dest/util/txe_account_store.d.ts.map +1 -0
  47. package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
  48. package/dest/util/txe_public_contract_data_source.d.ts +8 -8
  49. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  50. package/dest/util/txe_public_contract_data_source.js +12 -29
  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 +38 -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 -17
  58. package/src/constants.ts +3 -0
  59. package/src/index.ts +97 -60
  60. package/src/oracle/interfaces.ts +11 -8
  61. package/src/oracle/txe_oracle_public_context.ts +12 -19
  62. package/src/oracle/txe_oracle_top_level_context.ts +229 -131
  63. package/src/rpc_translator.ts +164 -68
  64. package/src/state_machine/archiver.ts +63 -117
  65. package/src/state_machine/dummy_p2p_client.ts +58 -28
  66. package/src/state_machine/global_variable_builder.ts +22 -4
  67. package/src/state_machine/index.ts +60 -21
  68. package/src/state_machine/mock_epoch_cache.ts +25 -20
  69. package/src/state_machine/synchronizer.ts +6 -5
  70. package/src/txe_session.ts +210 -101
  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_public_contract_data_source.ts +20 -45
  74. package/src/utils/block_creation.ts +49 -14
  75. package/src/utils/tx_effect_creation.ts +5 -12
  76. package/dest/util/txe_account_data_provider.d.ts +0 -10
  77. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  78. package/dest/util/txe_contract_data_provider.d.ts +0 -12
  79. package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
  80. package/dest/util/txe_contract_data_provider.js +0 -22
  81. package/src/util/txe_contract_data_provider.ts +0 -36
@@ -1,25 +1,27 @@
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 { 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 { AddressDataProvider, CapsuleDataProvider, NoteDataProvider, PXEOracleInterface, PrivateEventDataProvider, TaggingDataProvider } from '@aztec/pxe/server';
6
- import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, PrivateExecutionOracle, UtilityExecutionOracle } from '@aztec/pxe/simulator';
7
- import { FunctionSelector } from '@aztec/stdlib/abi';
6
+ import { AddressStore, AnchorBlockStore, CapsuleStore, JobCoordinator, NoteService, NoteStore, PrivateEventStore, RecipientTaggingStore, SenderAddressBookStore, SenderTaggingStore } from '@aztec/pxe/server';
7
+ import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, Oracle, PrivateExecutionOracle, UtilityExecutionOracle } from '@aztec/pxe/simulator';
8
+ import { ExecutionError, WASMSimulator, createSimulationError, extractCallStack, resolveAssertionMessageFromError, toACVMWitness } from '@aztec/simulator/client';
9
+ import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
8
10
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
9
- import { Body, L2Block } from '@aztec/stdlib/block';
10
11
  import { GasSettings } from '@aztec/stdlib/gas';
11
- import { makeAppendOnlyTreeSnapshot, makeGlobalVariables } from '@aztec/stdlib/testing';
12
+ import { computeProtocolNullifier } from '@aztec/stdlib/hash';
13
+ import { makeGlobalVariables } from '@aztec/stdlib/testing';
12
14
  import { CallContext, TxContext } from '@aztec/stdlib/tx';
13
15
  import { z } from 'zod';
16
+ import { DEFAULT_ADDRESS } from './constants.js';
14
17
  import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
15
18
  import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
16
19
  import { RPCTranslator } from './rpc_translator.js';
20
+ import { TXEArchiver } from './state_machine/archiver.js';
17
21
  import { TXEStateMachine } from './state_machine/index.js';
18
- import { TXEAccountDataProvider } from './util/txe_account_data_provider.js';
19
- import { TXEContractDataProvider } from './util/txe_contract_data_provider.js';
20
- import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlockHeader } from './utils/block_creation.js';
22
+ import { TXEAccountStore } from './util/txe_account_store.js';
23
+ import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
21
24
  import { makeTxEffect } from './utils/tx_effect_creation.js';
22
- const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
23
25
  /**
24
26
  * A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
25
27
  * state, etc., independent of all other tests running in parallel.
@@ -27,56 +29,77 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
27
29
  logger;
28
30
  stateMachine;
29
31
  oracleHandler;
30
- contractDataProvider;
32
+ contractStore;
33
+ noteStore;
31
34
  keyStore;
32
- addressDataProvider;
33
- accountDataProvider;
35
+ addressStore;
36
+ accountStore;
37
+ senderTaggingStore;
38
+ recipientTaggingStore;
39
+ senderAddressBookStore;
40
+ capsuleStore;
41
+ privateEventStore;
42
+ jobCoordinator;
43
+ currentJobId;
34
44
  chainId;
35
45
  version;
36
46
  nextBlockTimestamp;
37
- pxeOracleInterface;
38
47
  state;
39
48
  authwits;
40
- constructor(logger, stateMachine, oracleHandler, contractDataProvider, keyStore, addressDataProvider, accountDataProvider, chainId, version, nextBlockTimestamp, pxeOracleInterface){
49
+ constructor(logger, stateMachine, oracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, currentJobId, chainId, version, nextBlockTimestamp){
41
50
  this.logger = logger;
42
51
  this.stateMachine = stateMachine;
43
52
  this.oracleHandler = oracleHandler;
44
- this.contractDataProvider = contractDataProvider;
53
+ this.contractStore = contractStore;
54
+ this.noteStore = noteStore;
45
55
  this.keyStore = keyStore;
46
- this.addressDataProvider = addressDataProvider;
47
- this.accountDataProvider = accountDataProvider;
56
+ this.addressStore = addressStore;
57
+ this.accountStore = accountStore;
58
+ this.senderTaggingStore = senderTaggingStore;
59
+ this.recipientTaggingStore = recipientTaggingStore;
60
+ this.senderAddressBookStore = senderAddressBookStore;
61
+ this.capsuleStore = capsuleStore;
62
+ this.privateEventStore = privateEventStore;
63
+ this.jobCoordinator = jobCoordinator;
64
+ this.currentJobId = currentJobId;
48
65
  this.chainId = chainId;
49
66
  this.version = version;
50
67
  this.nextBlockTimestamp = nextBlockTimestamp;
51
- this.pxeOracleInterface = pxeOracleInterface;
52
68
  this.state = {
53
69
  name: 'TOP_LEVEL'
54
70
  };
55
71
  this.authwits = new Map();
56
72
  }
57
- static async init(protocolContracts) {
73
+ static async init(contractStore) {
58
74
  const store = await openTmpStore('txe-session');
59
- const addressDataProvider = new AddressDataProvider(store);
60
- const privateEventDataProvider = new PrivateEventDataProvider(store);
61
- const contractDataProvider = new TXEContractDataProvider(store);
62
- const noteDataProvider = await NoteDataProvider.create(store);
63
- const taggingDataProvider = new TaggingDataProvider(store);
64
- const capsuleDataProvider = new CapsuleDataProvider(store);
75
+ const addressStore = new AddressStore(store);
76
+ const privateEventStore = new PrivateEventStore(store);
77
+ const noteStore = new NoteStore(store);
78
+ const senderTaggingStore = new SenderTaggingStore(store);
79
+ const recipientTaggingStore = new RecipientTaggingStore(store);
80
+ const senderAddressBookStore = new SenderAddressBookStore(store);
81
+ const capsuleStore = new CapsuleStore(store);
65
82
  const keyStore = new KeyStore(store);
66
- const accountDataProvider = new TXEAccountDataProvider(store);
67
- // Register protocol contracts.
68
- for (const { contractClass, instance, artifact } of protocolContracts){
69
- await contractDataProvider.addContractArtifact(contractClass.id, artifact);
70
- await contractDataProvider.addContractInstance(instance);
71
- }
72
- const stateMachine = await TXEStateMachine.create(store);
83
+ const accountStore = new TXEAccountStore(store);
84
+ // Create job coordinator and register staged stores
85
+ const jobCoordinator = new JobCoordinator(store);
86
+ jobCoordinator.registerStores([
87
+ capsuleStore,
88
+ senderTaggingStore,
89
+ recipientTaggingStore,
90
+ privateEventStore,
91
+ noteStore
92
+ ]);
93
+ const archiver = new TXEArchiver(store);
94
+ const anchorBlockStore = new AnchorBlockStore(store);
95
+ const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
73
96
  const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
74
97
  const version = new Fr(await stateMachine.node.getVersion());
75
98
  const chainId = new Fr(await stateMachine.node.getChainId());
76
- const pxeOracleInterface = new PXEOracleInterface(stateMachine.node, keyStore, contractDataProvider, noteDataProvider, capsuleDataProvider, stateMachine.syncDataProvider, taggingDataProvider, addressDataProvider, privateEventDataProvider);
77
- const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine, contractDataProvider, keyStore, addressDataProvider, accountDataProvider, pxeOracleInterface, nextBlockTimestamp, version, chainId, new Map());
99
+ const initialJobId = jobCoordinator.beginJob();
100
+ const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, initialJobId, nextBlockTimestamp, version, chainId, new Map());
78
101
  await topLevelOracleHandler.txeAdvanceBlocksBy(1);
79
- return new TXESession(createLogger('txe:session'), stateMachine, topLevelOracleHandler, contractDataProvider, keyStore, addressDataProvider, accountDataProvider, version, chainId, nextBlockTimestamp, pxeOracleInterface);
102
+ return new TXESession(createLogger('txe:session'), stateMachine, topLevelOracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, initialJobId, version, chainId, nextBlockTimestamp);
80
103
  }
81
104
  /**
82
105
  * Processes an oracle function invoked by the Noir test associated to this session.
@@ -125,7 +148,10 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
125
148
  this.state;
126
149
  }
127
150
  }
128
- this.oracleHandler = new TXEOracleTopLevelContext(this.stateMachine, this.contractDataProvider, this.keyStore, this.addressDataProvider, this.accountDataProvider, this.pxeOracleInterface, this.nextBlockTimestamp, this.version, this.chainId, this.authwits);
151
+ // Commit all staged stores from the job that was just completed, then begin a new job
152
+ await this.jobCoordinator.commitJob(this.currentJobId);
153
+ this.currentJobId = this.jobCoordinator.beginJob();
154
+ this.oracleHandler = new TXEOracleTopLevelContext(this.stateMachine, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.accountStore, this.senderTaggingStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.currentJobId, this.nextBlockTimestamp, this.version, this.chainId, this.authwits);
129
155
  this.state = {
130
156
  name: 'TOP_LEVEL'
131
157
  };
@@ -133,27 +159,48 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
133
159
  }
134
160
  async enterPrivateState(contractAddress = DEFAULT_ADDRESS, anchorBlockNumber) {
135
161
  this.exitTopLevelState();
136
- // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
137
- // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
138
- // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
139
- // be removed from the database.
140
- // TODO(#12553): make the synchronizer sync here instead and remove this
141
- await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
142
162
  // Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
143
163
  // build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
144
164
  // a single transaction with the effects of what was done in the test.
145
165
  const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
166
+ await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
146
167
  const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
147
168
  const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
148
- blockNumber: latestBlock.globalVariables.blockNumber + 1,
169
+ blockNumber: BlockNumber(latestBlock.globalVariables.blockNumber + 1),
149
170
  timestamp: this.nextBlockTimestamp,
150
171
  version: this.version,
151
172
  chainId: this.chainId
152
173
  });
153
174
  const txRequestHash = getSingleTxBlockRequestHash(nextBlockGlobalVariables.blockNumber);
154
- const noteCache = new ExecutionNoteCache(txRequestHash);
175
+ const protocolNullifier = await computeProtocolNullifier(txRequestHash);
176
+ const noteCache = new ExecutionNoteCache(protocolNullifier);
155
177
  const taggingIndexCache = new ExecutionTaggingIndexCache();
156
- this.oracleHandler = new PrivateExecutionOracle(Fr.ZERO, new TxContext(this.chainId, this.version, GasSettings.empty()), new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false), anchorBlock, [], [], new HashedValuesCache(), noteCache, taggingIndexCache, this.pxeOracleInterface);
178
+ const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
179
+ this.oracleHandler = new PrivateExecutionOracle({
180
+ argsHash: Fr.ZERO,
181
+ txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
182
+ callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
183
+ anchorBlockHeader: anchorBlock,
184
+ utilityExecutor,
185
+ authWitnesses: [],
186
+ capsules: [],
187
+ executionCache: new HashedValuesCache(),
188
+ noteCache,
189
+ taggingIndexCache,
190
+ contractStore: this.contractStore,
191
+ noteStore: this.noteStore,
192
+ keyStore: this.keyStore,
193
+ addressStore: this.addressStore,
194
+ aztecNode: this.stateMachine.node,
195
+ senderTaggingStore: this.senderTaggingStore,
196
+ recipientTaggingStore: this.recipientTaggingStore,
197
+ senderAddressBookStore: this.senderAddressBookStore,
198
+ capsuleStore: this.capsuleStore,
199
+ privateEventStore: this.privateEventStore,
200
+ contractSyncService: this.stateMachine.contractSyncService,
201
+ jobId: this.currentJobId,
202
+ scopes: 'ALL_SCOPES'
203
+ });
157
204
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
158
205
  // data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
159
206
  // difference resides in that the simulator has all information needed in order to run the simulation, while ours
@@ -162,7 +209,6 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
162
209
  this.state = {
163
210
  name: 'PRIVATE',
164
211
  nextBlockGlobalVariables,
165
- txRequestHash,
166
212
  noteCache,
167
213
  taggingIndexCache
168
214
  };
@@ -175,7 +221,7 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
175
221
  // the test. The block therefore gets the *next* block number and timestamp.
176
222
  const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.blockNumber;
177
223
  const globalVariables = makeGlobalVariables(undefined, {
178
- blockNumber: latestBlockNumber + 1,
224
+ blockNumber: BlockNumber(latestBlockNumber + 1),
179
225
  timestamp: this.nextBlockTimestamp,
180
226
  version: this.version,
181
227
  chainId: this.chainId
@@ -188,13 +234,30 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
188
234
  }
189
235
  async enterUtilityState(contractAddress = DEFAULT_ADDRESS) {
190
236
  this.exitTopLevelState();
237
+ const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
191
238
  // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
192
239
  // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
193
240
  // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
194
241
  // be removed from the database.
195
242
  // TODO(#12553): make the synchronizer sync here instead and remove this
196
- await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
197
- this.oracleHandler = new UtilityExecutionOracle(contractAddress, [], [], this.pxeOracleInterface);
243
+ await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
244
+ this.oracleHandler = new UtilityExecutionOracle({
245
+ contractAddress,
246
+ authWitnesses: [],
247
+ capsules: [],
248
+ anchorBlockHeader,
249
+ contractStore: this.contractStore,
250
+ noteStore: this.noteStore,
251
+ keyStore: this.keyStore,
252
+ addressStore: this.addressStore,
253
+ aztecNode: this.stateMachine.node,
254
+ recipientTaggingStore: this.recipientTaggingStore,
255
+ senderAddressBookStore: this.senderAddressBookStore,
256
+ capsuleStore: this.capsuleStore,
257
+ privateEventStore: this.privateEventStore,
258
+ jobId: this.currentJobId,
259
+ scopes: 'ALL_SCOPES'
260
+ });
198
261
  this.state = {
199
262
  name: 'UTILITY'
200
263
  };
@@ -224,13 +287,13 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
224
287
  });
225
288
  // We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
226
289
  // logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
227
- const txEffect = await makeTxEffect(this.state.noteCache, this.state.txRequestHash, this.state.nextBlockGlobalVariables.blockNumber);
290
+ const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
228
291
  // We build a block holding just this transaction
229
292
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
230
293
  await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
231
- const block = new L2Block(makeAppendOnlyTreeSnapshot(), await makeTXEBlockHeader(forkedWorldTrees, this.state.nextBlockGlobalVariables), new Body([
294
+ const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [
232
295
  txEffect
233
- ]));
296
+ ]);
234
297
  await this.stateMachine.handleL2Block(block);
235
298
  await forkedWorldTrees.close();
236
299
  this.logger.debug('Exited PublicContext with built block', {
@@ -250,4 +313,42 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
250
313
  throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
251
314
  }
252
315
  }
316
+ utilityExecutorForContractSync(anchorBlock) {
317
+ return async (call, scopes)=>{
318
+ const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
319
+ if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
320
+ throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
321
+ }
322
+ try {
323
+ const oracle = new UtilityExecutionOracle({
324
+ contractAddress: call.to,
325
+ authWitnesses: [],
326
+ capsules: [],
327
+ anchorBlockHeader: anchorBlock,
328
+ contractStore: this.contractStore,
329
+ noteStore: this.noteStore,
330
+ keyStore: this.keyStore,
331
+ addressStore: this.addressStore,
332
+ aztecNode: this.stateMachine.node,
333
+ recipientTaggingStore: this.recipientTaggingStore,
334
+ senderAddressBookStore: this.senderAddressBookStore,
335
+ capsuleStore: this.capsuleStore,
336
+ privateEventStore: this.privateEventStore,
337
+ jobId: this.currentJobId,
338
+ scopes
339
+ });
340
+ await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
341
+ err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
342
+ throw new ExecutionError(err.message, {
343
+ contractAddress: call.to,
344
+ functionSelector: call.selector
345
+ }, extractCallStack(err, entryPointArtifact.debug), {
346
+ cause: err
347
+ });
348
+ });
349
+ } catch (err) {
350
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
351
+ }
352
+ };
353
+ }
253
354
  }