@aztec/txe 0.0.1-commit.fce3e4f → 0.0.1-commit.ffe5b04ea

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 +36 -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 +206 -98
  15. package/dest/rpc_translator.d.ts +91 -79
  16. package/dest/rpc_translator.d.ts.map +1 -1
  17. package/dest/rpc_translator.js +330 -170
  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 +63 -94
  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 +7 -7
  28. package/dest/state_machine/index.d.ts.map +1 -1
  29. package/dest/state_machine/index.js +40 -23
  30. package/dest/state_machine/mock_epoch_cache.d.ts +9 -6
  31. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  32. package/dest/state_machine/mock_epoch_cache.js +14 -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 +26 -15
  37. package/dest/txe_session.d.ts.map +1 -1
  38. package/dest/txe_session.js +161 -55
  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_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 +12 -29
  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 +251 -138
  60. package/src/rpc_translator.ts +368 -174
  61. package/src/state_machine/archiver.ts +59 -114
  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 +60 -21
  65. package/src/state_machine/mock_epoch_cache.ts +15 -11
  66. package/src/state_machine/synchronizer.ts +6 -5
  67. package/src/txe_session.ts +222 -103
  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 -45
  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,26 +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
12
  import { computeProtocolNullifier } from '@aztec/stdlib/hash';
12
- import { makeAppendOnlyTreeSnapshot, makeGlobalVariables } from '@aztec/stdlib/testing';
13
+ import { makeGlobalVariables } from '@aztec/stdlib/testing';
13
14
  import { CallContext, TxContext } from '@aztec/stdlib/tx';
14
15
  import { z } from 'zod';
16
+ import { DEFAULT_ADDRESS } from './constants.js';
15
17
  import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
16
18
  import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
17
19
  import { RPCTranslator } from './rpc_translator.js';
20
+ import { TXEArchiver } from './state_machine/archiver.js';
18
21
  import { TXEStateMachine } from './state_machine/index.js';
19
- import { TXEAccountDataProvider } from './util/txe_account_data_provider.js';
20
- import { TXEContractDataProvider } from './util/txe_contract_data_provider.js';
21
- 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';
22
24
  import { makeTxEffect } from './utils/tx_effect_creation.js';
23
- const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
24
25
  /**
25
26
  * A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
26
27
  * state, etc., independent of all other tests running in parallel.
@@ -28,56 +29,77 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
28
29
  logger;
29
30
  stateMachine;
30
31
  oracleHandler;
31
- contractDataProvider;
32
+ contractStore;
33
+ noteStore;
32
34
  keyStore;
33
- addressDataProvider;
34
- accountDataProvider;
35
+ addressStore;
36
+ accountStore;
37
+ senderTaggingStore;
38
+ recipientTaggingStore;
39
+ senderAddressBookStore;
40
+ capsuleStore;
41
+ privateEventStore;
42
+ jobCoordinator;
43
+ currentJobId;
35
44
  chainId;
36
45
  version;
37
46
  nextBlockTimestamp;
38
- pxeOracleInterface;
39
47
  state;
40
48
  authwits;
41
- 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){
42
50
  this.logger = logger;
43
51
  this.stateMachine = stateMachine;
44
52
  this.oracleHandler = oracleHandler;
45
- this.contractDataProvider = contractDataProvider;
53
+ this.contractStore = contractStore;
54
+ this.noteStore = noteStore;
46
55
  this.keyStore = keyStore;
47
- this.addressDataProvider = addressDataProvider;
48
- 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;
49
65
  this.chainId = chainId;
50
66
  this.version = version;
51
67
  this.nextBlockTimestamp = nextBlockTimestamp;
52
- this.pxeOracleInterface = pxeOracleInterface;
53
68
  this.state = {
54
69
  name: 'TOP_LEVEL'
55
70
  };
56
71
  this.authwits = new Map();
57
72
  }
58
- static async init(protocolContracts) {
73
+ static async init(contractStore) {
59
74
  const store = await openTmpStore('txe-session');
60
- const addressDataProvider = new AddressDataProvider(store);
61
- const privateEventDataProvider = new PrivateEventDataProvider(store);
62
- const contractDataProvider = new TXEContractDataProvider(store);
63
- const noteDataProvider = await NoteDataProvider.create(store);
64
- const taggingDataProvider = new TaggingDataProvider(store);
65
- 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);
66
82
  const keyStore = new KeyStore(store);
67
- const accountDataProvider = new TXEAccountDataProvider(store);
68
- // Register protocol contracts.
69
- for (const { contractClass, instance, artifact } of protocolContracts){
70
- await contractDataProvider.addContractArtifact(contractClass.id, artifact);
71
- await contractDataProvider.addContractInstance(instance);
72
- }
73
- 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);
74
96
  const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
75
97
  const version = new Fr(await stateMachine.node.getVersion());
76
98
  const chainId = new Fr(await stateMachine.node.getChainId());
77
- const pxeOracleInterface = new PXEOracleInterface(stateMachine.node, keyStore, contractDataProvider, noteDataProvider, capsuleDataProvider, stateMachine.syncDataProvider, taggingDataProvider, addressDataProvider, privateEventDataProvider);
78
- const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine, contractDataProvider, keyStore, addressDataProvider, accountDataProvider, pxeOracleInterface, nextBlockTimestamp, version, chainId, new Map());
79
- await topLevelOracleHandler.txeAdvanceBlocksBy(1);
80
- return new TXESession(createLogger('txe:session'), stateMachine, topLevelOracleHandler, contractDataProvider, keyStore, addressDataProvider, accountDataProvider, version, chainId, nextBlockTimestamp, pxeOracleInterface);
99
+ const initialJobId = jobCoordinator.beginJob();
100
+ const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, nextBlockTimestamp, version, chainId, new Map());
101
+ await topLevelOracleHandler.advanceBlocksBy(1);
102
+ return new TXESession(createLogger('txe:session'), stateMachine, topLevelOracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, initialJobId, version, chainId, nextBlockTimestamp);
81
103
  }
82
104
  /**
83
105
  * Processes an oracle function invoked by the Noir test associated to this session.
@@ -100,6 +122,14 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
100
122
  }
101
123
  }
102
124
  }
125
+ getCurrentJob() {
126
+ return this.currentJobId;
127
+ }
128
+ /** Commits the current job and begins a new one. Returns the new job ID. */ async cycleJob() {
129
+ await this.jobCoordinator.commitJob(this.currentJobId);
130
+ this.currentJobId = this.jobCoordinator.beginJob();
131
+ return this.currentJobId;
132
+ }
103
133
  async enterTopLevelState() {
104
134
  switch(this.state.name){
105
135
  case 'PRIVATE':
@@ -126,7 +156,9 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
126
156
  this.state;
127
157
  }
128
158
  }
129
- this.oracleHandler = new TXEOracleTopLevelContext(this.stateMachine, this.contractDataProvider, this.keyStore, this.addressDataProvider, this.accountDataProvider, this.pxeOracleInterface, this.nextBlockTimestamp, this.version, this.chainId, this.authwits);
159
+ // Commit all staged stores from the job that was just completed, then begin a new job
160
+ await this.cycleJob();
161
+ 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.nextBlockTimestamp, this.version, this.chainId, this.authwits);
130
162
  this.state = {
131
163
  name: 'TOP_LEVEL'
132
164
  };
@@ -134,19 +166,14 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
134
166
  }
135
167
  async enterPrivateState(contractAddress = DEFAULT_ADDRESS, anchorBlockNumber) {
136
168
  this.exitTopLevelState();
137
- // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
138
- // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
139
- // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
140
- // be removed from the database.
141
- // TODO(#12553): make the synchronizer sync here instead and remove this
142
- await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
143
169
  // Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
144
170
  // build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
145
171
  // a single transaction with the effects of what was done in the test.
146
172
  const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
173
+ await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
147
174
  const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
148
175
  const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
149
- blockNumber: latestBlock.globalVariables.blockNumber + 1,
176
+ blockNumber: BlockNumber(latestBlock.globalVariables.blockNumber + 1),
150
177
  timestamp: this.nextBlockTimestamp,
151
178
  version: this.version,
152
179
  chainId: this.chainId
@@ -155,7 +182,32 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
155
182
  const protocolNullifier = await computeProtocolNullifier(txRequestHash);
156
183
  const noteCache = new ExecutionNoteCache(protocolNullifier);
157
184
  const taggingIndexCache = new ExecutionTaggingIndexCache();
158
- 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);
185
+ const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
186
+ this.oracleHandler = new PrivateExecutionOracle({
187
+ argsHash: Fr.ZERO,
188
+ txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
189
+ callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
190
+ anchorBlockHeader: anchorBlock,
191
+ utilityExecutor,
192
+ authWitnesses: [],
193
+ capsules: [],
194
+ executionCache: new HashedValuesCache(),
195
+ noteCache,
196
+ taggingIndexCache,
197
+ contractStore: this.contractStore,
198
+ noteStore: this.noteStore,
199
+ keyStore: this.keyStore,
200
+ addressStore: this.addressStore,
201
+ aztecNode: this.stateMachine.node,
202
+ senderTaggingStore: this.senderTaggingStore,
203
+ recipientTaggingStore: this.recipientTaggingStore,
204
+ senderAddressBookStore: this.senderAddressBookStore,
205
+ capsuleStore: this.capsuleStore,
206
+ privateEventStore: this.privateEventStore,
207
+ contractSyncService: this.stateMachine.contractSyncService,
208
+ jobId: this.currentJobId,
209
+ scopes: 'ALL_SCOPES'
210
+ });
159
211
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
160
212
  // data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
161
213
  // difference resides in that the simulator has all information needed in order to run the simulation, while ours
@@ -164,7 +216,6 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
164
216
  this.state = {
165
217
  name: 'PRIVATE',
166
218
  nextBlockGlobalVariables,
167
- protocolNullifier,
168
219
  noteCache,
169
220
  taggingIndexCache
170
221
  };
@@ -177,7 +228,7 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
177
228
  // the test. The block therefore gets the *next* block number and timestamp.
178
229
  const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.blockNumber;
179
230
  const globalVariables = makeGlobalVariables(undefined, {
180
- blockNumber: latestBlockNumber + 1,
231
+ blockNumber: BlockNumber(latestBlockNumber + 1),
181
232
  timestamp: this.nextBlockTimestamp,
182
233
  version: this.version,
183
234
  chainId: this.chainId
@@ -190,13 +241,30 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
190
241
  }
191
242
  async enterUtilityState(contractAddress = DEFAULT_ADDRESS) {
192
243
  this.exitTopLevelState();
244
+ const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
193
245
  // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
194
246
  // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
195
247
  // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
196
248
  // be removed from the database.
197
249
  // TODO(#12553): make the synchronizer sync here instead and remove this
198
- await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
199
- this.oracleHandler = new UtilityExecutionOracle(contractAddress, [], [], this.pxeOracleInterface);
250
+ await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
251
+ this.oracleHandler = new UtilityExecutionOracle({
252
+ contractAddress,
253
+ authWitnesses: [],
254
+ capsules: [],
255
+ anchorBlockHeader,
256
+ contractStore: this.contractStore,
257
+ noteStore: this.noteStore,
258
+ keyStore: this.keyStore,
259
+ addressStore: this.addressStore,
260
+ aztecNode: this.stateMachine.node,
261
+ recipientTaggingStore: this.recipientTaggingStore,
262
+ senderAddressBookStore: this.senderAddressBookStore,
263
+ capsuleStore: this.capsuleStore,
264
+ privateEventStore: this.privateEventStore,
265
+ jobId: this.currentJobId,
266
+ scopes: 'ALL_SCOPES'
267
+ });
200
268
  this.state = {
201
269
  name: 'UTILITY'
202
270
  };
@@ -208,8 +276,8 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
208
276
  }
209
277
  // Note that while all public and private contexts do is build a single block that we then process when exiting
210
278
  // those, the top level context performs a large number of actions not captured in the following 'close' call. Among
211
- // others, it will create empty blocks (via `txeAdvanceBlocksBy` and `deploy`), create blocks with transactions via
212
- // `txePrivateCallNewFlow` and `txePublicCallNewFlow`, add accounts to PXE via `txeAddAccount`, etc. This is a
279
+ // others, it will create empty blocks (via `advanceBlocksBy` and `deploy`), create blocks with transactions via
280
+ // `privateCallNewFlow` and `publicCallNewFlow`, add accounts to PXE via `addAccount`, etc. This is a
213
281
  // slight inconsistency in the working model of this class, but is not too bad.
214
282
  // TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
215
283
  // level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
@@ -226,13 +294,13 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
226
294
  });
227
295
  // We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
228
296
  // logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
229
- const txEffect = await makeTxEffect(this.state.noteCache, this.state.protocolNullifier, this.state.nextBlockGlobalVariables.blockNumber);
297
+ const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
230
298
  // We build a block holding just this transaction
231
299
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
232
300
  await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
233
- const block = new L2Block(makeAppendOnlyTreeSnapshot(), await makeTXEBlockHeader(forkedWorldTrees, this.state.nextBlockGlobalVariables), new Body([
301
+ const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [
234
302
  txEffect
235
- ]));
303
+ ]);
236
304
  await this.stateMachine.handleL2Block(block);
237
305
  await forkedWorldTrees.close();
238
306
  this.logger.debug('Exited PublicContext with built block', {
@@ -252,4 +320,42 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
252
320
  throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
253
321
  }
254
322
  }
323
+ utilityExecutorForContractSync(anchorBlock) {
324
+ return async (call, scopes)=>{
325
+ const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
326
+ if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
327
+ throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
328
+ }
329
+ try {
330
+ const oracle = new UtilityExecutionOracle({
331
+ contractAddress: call.to,
332
+ authWitnesses: [],
333
+ capsules: [],
334
+ anchorBlockHeader: anchorBlock,
335
+ contractStore: this.contractStore,
336
+ noteStore: this.noteStore,
337
+ keyStore: this.keyStore,
338
+ addressStore: this.addressStore,
339
+ aztecNode: this.stateMachine.node,
340
+ recipientTaggingStore: this.recipientTaggingStore,
341
+ senderAddressBookStore: this.senderAddressBookStore,
342
+ capsuleStore: this.capsuleStore,
343
+ privateEventStore: this.privateEventStore,
344
+ jobId: this.currentJobId,
345
+ scopes
346
+ });
347
+ await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
348
+ err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
349
+ throw new ExecutionError(err.message, {
350
+ contractAddress: call.to,
351
+ functionSelector: call.selector
352
+ }, extractCallStack(err, entryPointArtifact.debug), {
353
+ cause: err
354
+ });
355
+ });
356
+ } catch (err) {
357
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
358
+ }
359
+ };
360
+ }
255
361
  }