@aztec/txe 0.0.1-commit.1142ef1 → 0.0.1-commit.11bf3dd6e

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 (72) hide show
  1. package/dest/constants.d.ts +1 -2
  2. package/dest/constants.d.ts.map +1 -1
  3. package/dest/constants.js +0 -1
  4. package/dest/index.d.ts +1 -1
  5. package/dest/index.d.ts.map +1 -1
  6. package/dest/index.js +88 -54
  7. package/dest/oracle/interfaces.d.ts +29 -28
  8. package/dest/oracle/interfaces.d.ts.map +1 -1
  9. package/dest/oracle/txe_oracle_public_context.d.ts +13 -13
  10. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_public_context.js +16 -16
  12. package/dest/oracle/txe_oracle_top_level_context.d.ts +28 -22
  13. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  14. package/dest/oracle/txe_oracle_top_level_context.js +165 -71
  15. package/dest/rpc_translator.d.ts +125 -81
  16. package/dest/rpc_translator.d.ts.map +1 -1
  17. package/dest/rpc_translator.js +426 -179
  18. package/dest/state_machine/archiver.d.ts +20 -69
  19. package/dest/state_machine/archiver.d.ts.map +1 -1
  20. package/dest/state_machine/archiver.js +36 -179
  21. package/dest/state_machine/dummy_p2p_client.d.ts +18 -13
  22. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  23. package/dest/state_machine/dummy_p2p_client.js +33 -18
  24. package/dest/state_machine/global_variable_builder.d.ts +9 -4
  25. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  26. package/dest/state_machine/global_variable_builder.js +9 -3
  27. package/dest/state_machine/index.d.ts +7 -5
  28. package/dest/state_machine/index.d.ts.map +1 -1
  29. package/dest/state_machine/index.js +40 -13
  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 -6
  34. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  35. package/dest/state_machine/synchronizer.js +3 -3
  36. package/dest/txe_session.d.ts +12 -6
  37. package/dest/txe_session.d.ts.map +1 -1
  38. package/dest/txe_session.js +115 -28
  39. package/dest/util/encoding.d.ts +88 -18
  40. package/dest/util/encoding.d.ts.map +1 -1
  41. package/dest/util/encoding.js +4 -0
  42. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  43. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  44. package/dest/util/txe_public_contract_data_source.js +6 -25
  45. package/dest/utils/block_creation.d.ts +4 -4
  46. package/dest/utils/block_creation.d.ts.map +1 -1
  47. package/dest/utils/block_creation.js +18 -4
  48. package/dest/utils/tx_effect_creation.d.ts +2 -3
  49. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  50. package/dest/utils/tx_effect_creation.js +3 -6
  51. package/package.json +16 -16
  52. package/src/constants.ts +0 -1
  53. package/src/index.ts +89 -52
  54. package/src/oracle/interfaces.ts +32 -31
  55. package/src/oracle/txe_oracle_public_context.ts +16 -18
  56. package/src/oracle/txe_oracle_top_level_context.ts +208 -123
  57. package/src/rpc_translator.ts +493 -204
  58. package/src/state_machine/archiver.ts +38 -234
  59. package/src/state_machine/dummy_p2p_client.ts +46 -24
  60. package/src/state_machine/global_variable_builder.ts +18 -3
  61. package/src/state_machine/index.ts +56 -12
  62. package/src/state_machine/mock_epoch_cache.ts +57 -14
  63. package/src/state_machine/synchronizer.ts +5 -5
  64. package/src/txe_session.ts +132 -88
  65. package/src/util/encoding.ts +5 -0
  66. package/src/util/txe_public_contract_data_source.ts +10 -38
  67. package/src/utils/block_creation.ts +19 -16
  68. package/src/utils/tx_effect_creation.ts +3 -11
  69. package/dest/util/txe_contract_store.d.ts +0 -12
  70. package/dest/util/txe_contract_store.d.ts.map +0 -1
  71. package/dest/util/txe_contract_store.js +0 -22
  72. package/src/util/txe_contract_store.ts +0 -36
@@ -1,37 +1,68 @@
1
1
  import type { EpochAndSlot, EpochCacheInterface, EpochCommitteeInfo, SlotTag } from '@aztec/epoch-cache';
2
2
  import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
3
  import { EthAddress } from '@aztec/foundation/eth-address';
4
+ import { EmptyL1RollupConstants, type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
4
5
 
5
6
  /**
6
7
  * Mock implementation of the EpochCacheInterface used to satisfy dependencies of AztecNodeService.
7
8
  * Since in TXE we don't validate transactions, mock suffices here.
8
9
  */
9
10
  export class MockEpochCache implements EpochCacheInterface {
10
- getCommittee(): Promise<EpochCommitteeInfo> {
11
+ getCommittee(_slot: SlotTag = 'now'): Promise<EpochCommitteeInfo> {
11
12
  return Promise.resolve({
12
13
  committee: undefined,
13
14
  seed: 0n,
14
15
  epoch: EpochNumber.ZERO,
16
+ isEscapeHatchOpen: false,
15
17
  });
16
18
  }
17
19
 
18
- getEpochAndSlotNow(): EpochAndSlot {
20
+ getSlotNow(): SlotNumber {
21
+ return SlotNumber(0);
22
+ }
23
+
24
+ getTargetSlot(): SlotNumber {
25
+ return SlotNumber(0);
26
+ }
27
+
28
+ getEpochNow(): EpochNumber {
29
+ return EpochNumber.ZERO;
30
+ }
31
+
32
+ getTargetEpoch(): EpochNumber {
33
+ return EpochNumber.ZERO;
34
+ }
35
+
36
+ getEpochAndSlotNow(): EpochAndSlot & { nowMs: bigint } {
19
37
  return {
20
38
  epoch: EpochNumber.ZERO,
21
39
  slot: SlotNumber(0),
22
40
  ts: 0n,
41
+ nowMs: 0n,
23
42
  };
24
43
  }
25
44
 
26
- getEpochAndSlotInNextL1Slot(): EpochAndSlot & { now: bigint } {
45
+ getEpochAndSlotInNextL1Slot(): EpochAndSlot & { nowSeconds: bigint } {
27
46
  return {
28
47
  epoch: EpochNumber.ZERO,
29
48
  slot: SlotNumber(0),
30
49
  ts: 0n,
31
- now: 0n,
50
+ nowSeconds: 0n,
32
51
  };
33
52
  }
34
53
 
54
+ getTargetEpochAndSlotInNextL1Slot(): EpochAndSlot & { nowSeconds: bigint } {
55
+ return this.getEpochAndSlotInNextL1Slot();
56
+ }
57
+
58
+ isProposerPipeliningEnabled(): boolean {
59
+ return false;
60
+ }
61
+
62
+ pipeliningOffset(): number {
63
+ return 0;
64
+ }
65
+
35
66
  getProposerIndexEncoding(_epoch: EpochNumber, _slot: SlotNumber, _seed: bigint): `0x${string}` {
36
67
  return '0x00';
37
68
  }
@@ -40,18 +71,18 @@ export class MockEpochCache implements EpochCacheInterface {
40
71
  return 0n;
41
72
  }
42
73
 
43
- getProposerAttesterAddressInCurrentOrNextSlot(): Promise<{
44
- currentProposer: EthAddress | undefined;
45
- nextProposer: EthAddress | undefined;
46
- currentSlot: SlotNumber;
47
- nextSlot: SlotNumber;
48
- }> {
49
- return Promise.resolve({
50
- currentProposer: undefined,
51
- nextProposer: undefined,
74
+ getCurrentAndNextSlot(): { currentSlot: SlotNumber; nextSlot: SlotNumber } {
75
+ return {
52
76
  currentSlot: SlotNumber(0),
53
77
  nextSlot: SlotNumber(0),
54
- });
78
+ };
79
+ }
80
+
81
+ getTargetAndNextSlot(): { targetSlot: SlotNumber; nextSlot: SlotNumber } {
82
+ return {
83
+ targetSlot: SlotNumber(0),
84
+ nextSlot: SlotNumber(0),
85
+ };
55
86
  }
56
87
 
57
88
  getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined> {
@@ -69,4 +100,16 @@ export class MockEpochCache implements EpochCacheInterface {
69
100
  filterInCommittee(_slot: SlotTag, _validators: EthAddress[]): Promise<EthAddress[]> {
70
101
  return Promise.resolve([]);
71
102
  }
103
+
104
+ isEscapeHatchOpen(_epoch: EpochNumber): Promise<boolean> {
105
+ return Promise.resolve(false);
106
+ }
107
+
108
+ isEscapeHatchOpenAtSlot(_slot: SlotTag): Promise<boolean> {
109
+ return Promise.resolve(false);
110
+ }
111
+
112
+ getL1Constants(): L1RollupConstants {
113
+ return EmptyL1RollupConstants;
114
+ }
72
115
  }
@@ -1,7 +1,7 @@
1
1
  import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
2
  import { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
- import type { L2BlockNew } from '@aztec/stdlib/block';
4
+ import type { BlockHash, L2Block } from '@aztec/stdlib/block';
5
5
  import type {
6
6
  MerkleTreeReadOperations,
7
7
  MerkleTreeWriteOperations,
@@ -23,7 +23,7 @@ export class TXESynchronizer implements WorldStateSynchronizer {
23
23
  return new this(nativeWorldStateService);
24
24
  }
25
25
 
26
- public async handleL2Block(block: L2BlockNew) {
26
+ public async handleL2Block(block: L2Block) {
27
27
  await this.nativeWorldStateService.handleL2BlockAndMessages(
28
28
  block,
29
29
  Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero),
@@ -33,12 +33,12 @@ export class TXESynchronizer implements WorldStateSynchronizer {
33
33
  }
34
34
 
35
35
  /**
36
- * Forces an immediate sync to an optionally provided minimum block number
36
+ * Forces an immediate sync to an optionally provided minimum block number.
37
37
  * @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
38
- * @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
38
+ * @param blockHash - If provided, verifies the block at targetBlockNumber matches this hash.
39
39
  * @returns A promise that resolves with the block number the world state was synced to
40
40
  */
41
- public syncImmediate(_minBlockNumber?: BlockNumber, _skipThrowIfTargetNotReached?: boolean): Promise<BlockNumber> {
41
+ public syncImmediate(_minBlockNumber?: BlockNumber, _blockHash?: BlockHash): Promise<BlockNumber> {
42
42
  return Promise.resolve(this.blockNumber);
43
43
  }
44
44
 
@@ -3,10 +3,14 @@ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { type Logger, createLogger } from '@aztec/foundation/log';
4
4
  import { KeyStore } from '@aztec/key-store';
5
5
  import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
6
- import type { ProtocolContract } from '@aztec/protocol-contracts';
7
6
  import {
8
7
  AddressStore,
8
+ AnchorBlockStore,
9
+ CapsuleService,
9
10
  CapsuleStore,
11
+ ContractStore,
12
+ ContractSyncService,
13
+ JobCoordinator,
10
14
  NoteService,
11
15
  NoteStore,
12
16
  PrivateEventStore,
@@ -43,15 +47,15 @@ import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
43
47
 
44
48
  import { z } from 'zod';
45
49
 
46
- import { DEFAULT_ADDRESS, TXE_JOB_ID } from './constants.js';
50
+ import { DEFAULT_ADDRESS } from './constants.js';
47
51
  import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
48
52
  import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
49
53
  import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
50
54
  import { RPCTranslator } from './rpc_translator.js';
55
+ import { TXEArchiver } from './state_machine/archiver.js';
51
56
  import { TXEStateMachine } from './state_machine/index.js';
52
57
  import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
53
58
  import { TXEAccountStore } from './util/txe_account_store.js';
54
- import { TXEContractStore } from './util/txe_contract_store.js';
55
59
  import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
56
60
  import { makeTxEffect } from './utils/tx_effect_creation.js';
57
61
 
@@ -74,7 +78,6 @@ type SessionState =
74
78
  | {
75
79
  name: 'PRIVATE';
76
80
  nextBlockGlobalVariables: GlobalVariables;
77
- protocolNullifier: Fr;
78
81
  noteCache: ExecutionNoteCache;
79
82
  taggingIndexCache: ExecutionTaggingIndexCache;
80
83
  }
@@ -111,6 +114,10 @@ export interface TXESessionStateHandler {
111
114
  enterPublicState(contractAddress?: AztecAddress): Promise<void>;
112
115
  enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
113
116
  enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
117
+
118
+ // TODO(F-335): Exposing the job info is abstraction breakage - drop the following 2 functions.
119
+ cycleJob(): Promise<string>;
120
+ getCurrentJob(): string;
114
121
  }
115
122
 
116
123
  /**
@@ -129,7 +136,7 @@ export class TXESession implements TXESessionStateHandler {
129
136
  | IPrivateExecutionOracle
130
137
  | IAvmExecutionOracle
131
138
  | ITxeExecutionOracle,
132
- private contractStore: TXEContractStore,
139
+ private contractStore: ContractStore,
133
140
  private noteStore: NoteStore,
134
141
  private keyStore: KeyStore,
135
142
  private addressStore: AddressStore,
@@ -139,18 +146,20 @@ export class TXESession implements TXESessionStateHandler {
139
146
  private senderAddressBookStore: SenderAddressBookStore,
140
147
  private capsuleStore: CapsuleStore,
141
148
  private privateEventStore: PrivateEventStore,
149
+ private jobCoordinator: JobCoordinator,
150
+ private currentJobId: string,
142
151
  private chainId: Fr,
143
152
  private version: Fr,
144
153
  private nextBlockTimestamp: bigint,
154
+ private contractSyncService: ContractSyncService,
145
155
  ) {}
146
156
 
147
- static async init(protocolContracts: ProtocolContract[]) {
157
+ static async init(contractStore: ContractStore) {
148
158
  const store = await openTmpStore('txe-session');
149
159
 
150
160
  const addressStore = new AddressStore(store);
151
161
  const privateEventStore = new PrivateEventStore(store);
152
- const contractStore = new TXEContractStore(store);
153
- const noteStore = await NoteStore.create(store);
162
+ const noteStore = new NoteStore(store);
154
163
  const senderTaggingStore = new SenderTaggingStore(store);
155
164
  const recipientTaggingStore = new RecipientTaggingStore(store);
156
165
  const senderAddressBookStore = new SenderAddressBookStore(store);
@@ -158,18 +167,29 @@ export class TXESession implements TXESessionStateHandler {
158
167
  const keyStore = new KeyStore(store);
159
168
  const accountStore = new TXEAccountStore(store);
160
169
 
161
- // Register protocol contracts.
162
- for (const { contractClass, instance, artifact } of protocolContracts) {
163
- await contractStore.addContractArtifact(contractClass.id, artifact);
164
- await contractStore.addContractInstance(instance);
165
- }
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
+ ]);
166
179
 
167
- const stateMachine = await TXEStateMachine.create(store);
180
+ const archiver = new TXEArchiver(store);
181
+ const anchorBlockStore = new AnchorBlockStore(store);
182
+ const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
168
183
 
169
184
  const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
170
185
  const version = new Fr(await stateMachine.node.getVersion());
171
186
  const chainId = new Fr(await stateMachine.node.getChainId());
172
187
 
188
+ const initialJobId = jobCoordinator.beginJob();
189
+
190
+ const logger = createLogger('txe:session');
191
+ const contractSyncService = new ContractSyncService(stateMachine.node, contractStore, noteStore, logger);
192
+
173
193
  const topLevelOracleHandler = new TXEOracleTopLevelContext(
174
194
  stateMachine,
175
195
  contractStore,
@@ -186,11 +206,12 @@ export class TXESession implements TXESessionStateHandler {
186
206
  version,
187
207
  chainId,
188
208
  new Map(),
209
+ contractSyncService,
189
210
  );
190
- await topLevelOracleHandler.txeAdvanceBlocksBy(1);
211
+ await topLevelOracleHandler.advanceBlocksBy(1);
191
212
 
192
213
  return new TXESession(
193
- createLogger('txe:session'),
214
+ logger,
194
215
  stateMachine,
195
216
  topLevelOracleHandler,
196
217
  contractStore,
@@ -203,9 +224,12 @@ export class TXESession implements TXESessionStateHandler {
203
224
  senderAddressBookStore,
204
225
  capsuleStore,
205
226
  privateEventStore,
227
+ jobCoordinator,
228
+ initialJobId,
206
229
  version,
207
230
  chainId,
208
231
  nextBlockTimestamp,
232
+ contractSyncService,
209
233
  );
210
234
  }
211
235
 
@@ -240,6 +264,17 @@ export class TXESession implements TXESessionStateHandler {
240
264
  }
241
265
  }
242
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
+
243
278
  async enterTopLevelState() {
244
279
  switch (this.state.name) {
245
280
  case 'PRIVATE': {
@@ -262,6 +297,9 @@ export class TXESession implements TXESessionStateHandler {
262
297
  }
263
298
  }
264
299
 
300
+ // Commit all staged stores from the job that was just completed, then begin a new job
301
+ await this.cycleJob();
302
+
265
303
  this.oracleHandler = new TXEOracleTopLevelContext(
266
304
  this.stateMachine,
267
305
  this.contractStore,
@@ -278,6 +316,7 @@ export class TXESession implements TXESessionStateHandler {
278
316
  this.version,
279
317
  this.chainId,
280
318
  this.authwits,
319
+ this.contractSyncService,
281
320
  );
282
321
 
283
322
  this.state = { name: 'TOP_LEVEL' };
@@ -290,16 +329,15 @@ export class TXESession implements TXESessionStateHandler {
290
329
  ): Promise<PrivateContextInputs> {
291
330
  this.exitTopLevelState();
292
331
 
293
- await new NoteService(
294
- this.noteStore,
295
- this.stateMachine.node,
296
- this.stateMachine.anchorBlockStore,
297
- ).syncNoteNullifiers(contractAddress);
298
-
299
332
  // Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
300
333
  // build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
301
334
  // a single transaction with the effects of what was done in the test.
302
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
+ await this.keyStore.getAccounts(),
340
+ );
303
341
  const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
304
342
 
305
343
  const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
@@ -315,37 +353,40 @@ export class TXESession implements TXESessionStateHandler {
315
353
  const taggingIndexCache = new ExecutionTaggingIndexCache();
316
354
 
317
355
  const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
318
- this.oracleHandler = new PrivateExecutionOracle(
319
- Fr.ZERO,
320
- new TxContext(this.chainId, this.version, GasSettings.empty()),
321
- new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
322
- 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!,
323
361
  utilityExecutor,
324
- [],
325
- [],
326
- new HashedValuesCache(),
362
+ authWitnesses: [],
363
+ capsules: [],
364
+ executionCache: new HashedValuesCache(),
327
365
  noteCache,
328
366
  taggingIndexCache,
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,
341
- );
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
+ capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
376
+ privateEventStore: this.privateEventStore,
377
+ contractSyncService: this.stateMachine.contractSyncService,
378
+ l2TipsStore: this.stateMachine.node,
379
+ jobId: this.currentJobId,
380
+ scopes: await this.keyStore.getAccounts(),
381
+ messageContextService: this.stateMachine.messageContextService,
382
+ });
342
383
 
343
384
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
344
385
  // data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
345
386
  // difference resides in that the simulator has all information needed in order to run the simulation, while ours
346
387
  // will be ongoing as the different oracles will be invoked from the Noir test, until eventually the private
347
388
  // execution finishes.
348
- this.state = { name: 'PRIVATE', nextBlockGlobalVariables, protocolNullifier, noteCache, taggingIndexCache };
389
+ this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
349
390
  this.logger.debug(`Entered state ${this.state.name}`);
350
391
 
351
392
  return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
@@ -378,6 +419,8 @@ export class TXESession implements TXESessionStateHandler {
378
419
  async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
379
420
  this.exitTopLevelState();
380
421
 
422
+ const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
423
+
381
424
  // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
382
425
  // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
383
426
  // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
@@ -386,28 +429,30 @@ export class TXESession implements TXESessionStateHandler {
386
429
  await new NoteService(
387
430
  this.noteStore,
388
431
  this.stateMachine.node,
389
- this.stateMachine.anchorBlockStore,
390
- ).syncNoteNullifiers(contractAddress);
391
-
392
- const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
432
+ anchorBlockHeader,
433
+ this.currentJobId,
434
+ ).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
393
435
 
394
- this.oracleHandler = new UtilityExecutionOracle(
436
+ this.oracleHandler = new UtilityExecutionOracle({
395
437
  contractAddress,
396
- [],
397
- [],
438
+ authWitnesses: [],
439
+ capsules: [],
398
440
  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
- );
441
+ contractStore: this.contractStore,
442
+ noteStore: this.noteStore,
443
+ keyStore: this.keyStore,
444
+ addressStore: this.addressStore,
445
+ aztecNode: this.stateMachine.node,
446
+ recipientTaggingStore: this.recipientTaggingStore,
447
+ senderAddressBookStore: this.senderAddressBookStore,
448
+ capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
449
+ privateEventStore: this.privateEventStore,
450
+ messageContextService: this.stateMachine.messageContextService,
451
+ contractSyncService: this.contractSyncService,
452
+ l2TipsStore: this.stateMachine.node,
453
+ jobId: this.currentJobId,
454
+ scopes: await this.keyStore.getAccounts(),
455
+ });
411
456
 
412
457
  this.state = { name: 'UTILITY' };
413
458
  this.logger.debug(`Entered state ${this.state.name}`);
@@ -420,8 +465,8 @@ export class TXESession implements TXESessionStateHandler {
420
465
 
421
466
  // Note that while all public and private contexts do is build a single block that we then process when exiting
422
467
  // those, the top level context performs a large number of actions not captured in the following 'close' call. Among
423
- // others, it will create empty blocks (via `txeAdvanceBlocksBy` and `deploy`), create blocks with transactions via
424
- // `txePrivateCallNewFlow` and `txePublicCallNewFlow`, add accounts to PXE via `txeAddAccount`, etc. This is a
468
+ // others, it will create empty blocks (via `advanceBlocksBy` and `deploy`), create blocks with transactions via
469
+ // `privateCallNewFlow` and `publicCallNewFlow`, add accounts to PXE via `addAccount`, etc. This is a
425
470
  // slight inconsistency in the working model of this class, but is not too bad.
426
471
  // TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
427
472
  // level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
@@ -442,11 +487,7 @@ export class TXESession implements TXESessionStateHandler {
442
487
  // We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
443
488
  // logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
444
489
 
445
- const txEffect = await makeTxEffect(
446
- this.state.noteCache,
447
- this.state.protocolNullifier,
448
- this.state.nextBlockGlobalVariables.blockNumber,
449
- );
490
+ const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
450
491
 
451
492
  // We build a block holding just this transaction
452
493
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
@@ -479,30 +520,33 @@ export class TXESession implements TXESessionStateHandler {
479
520
  }
480
521
 
481
522
  private utilityExecutorForContractSync(anchorBlock: any) {
482
- return async (call: FunctionCall) => {
523
+ return async (call: FunctionCall, scopes: AztecAddress[]) => {
483
524
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
484
525
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
485
526
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
486
527
  }
487
528
 
488
529
  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
- );
530
+ const oracle = new UtilityExecutionOracle({
531
+ contractAddress: call.to,
532
+ authWitnesses: [],
533
+ capsules: [],
534
+ anchorBlockHeader: anchorBlock!,
535
+ contractStore: this.contractStore,
536
+ noteStore: this.noteStore,
537
+ keyStore: this.keyStore,
538
+ addressStore: this.addressStore,
539
+ aztecNode: this.stateMachine.node,
540
+ recipientTaggingStore: this.recipientTaggingStore,
541
+ senderAddressBookStore: this.senderAddressBookStore,
542
+ capsuleService: new CapsuleService(this.capsuleStore, scopes),
543
+ privateEventStore: this.privateEventStore,
544
+ messageContextService: this.stateMachine.messageContextService,
545
+ contractSyncService: this.contractSyncService,
546
+ l2TipsStore: this.stateMachine.node,
547
+ jobId: this.currentJobId,
548
+ scopes,
549
+ });
506
550
  await new WASMSimulator()
507
551
  .executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
508
552
  .catch((err: Error) => {
@@ -3,6 +3,7 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
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';
6
+ import { BlockHash } from '@aztec/stdlib/block';
6
7
  import { type ContractInstanceWithAddress, ContractInstanceWithAddressSchema } from '@aztec/stdlib/contract';
7
8
 
8
9
  import { z } from 'zod';
@@ -25,6 +26,10 @@ export function addressFromSingle(obj: ForeignCallSingle) {
25
26
  return new AztecAddress(fromSingle(obj));
26
27
  }
27
28
 
29
+ export function blockHashFromSingle(obj: ForeignCallSingle) {
30
+ return new BlockHash(fromSingle(obj));
31
+ }
32
+
28
33
  export function fromArray(obj: ForeignCallArray) {
29
34
  return obj.map(str => Fr.fromBuffer(hexToBuffer(str)));
30
35
  }
@@ -1,19 +1,11 @@
1
1
  import { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import type { ContractStore } from '@aztec/pxe/server';
4
- import { type ContractArtifact, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
4
+ import { type ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
5
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
6
- import {
7
- type ContractClassPublic,
8
- type ContractDataSource,
9
- type ContractInstanceWithAddress,
10
- computePrivateFunctionsRoot,
11
- computePublicBytecodeCommitment,
12
- getContractClassPrivateFunctionFromArtifact,
13
- } from '@aztec/stdlib/contract';
6
+ import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
14
7
 
15
8
  export class TXEPublicContractDataSource implements ContractDataSource {
16
- #privateFunctionsRoot: Map<string, Buffer> = new Map();
17
9
  constructor(
18
10
  private blockNumber: BlockNumber,
19
11
  private contractStore: ContractStore,
@@ -24,42 +16,22 @@ export class TXEPublicContractDataSource implements ContractDataSource {
24
16
  }
25
17
 
26
18
  async getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
27
- const contractClass = await this.contractStore.getContractClass(id);
19
+ const contractClass = await this.contractStore.getContractClassWithPreimage(id);
28
20
  if (!contractClass) {
29
21
  return;
30
22
  }
31
- const artifact = await this.contractStore.getContractArtifact(id);
32
- if (!artifact) {
33
- return;
34
- }
35
-
36
- let privateFunctionsRoot;
37
- if (!this.#privateFunctionsRoot.has(id.toString())) {
38
- const privateFunctions = await Promise.all(
39
- artifact.functions
40
- .filter(fn => fn.functionType === FunctionType.PRIVATE)
41
- .map(fn => getContractClassPrivateFunctionFromArtifact(fn)),
42
- );
43
- privateFunctionsRoot = await computePrivateFunctionsRoot(privateFunctions);
44
- this.#privateFunctionsRoot.set(id.toString(), privateFunctionsRoot.toBuffer());
45
- } else {
46
- privateFunctionsRoot = Fr.fromBuffer(this.#privateFunctionsRoot.get(id.toString())!);
47
- }
48
-
49
23
  return {
50
- id,
51
- artifactHash: contractClass!.artifactHash,
52
- packedBytecode: contractClass!.packedBytecode,
53
- privateFunctionsRoot,
54
- version: contractClass!.version,
55
- privateFunctions: [],
56
- utilityFunctions: [],
24
+ id: contractClass.id,
25
+ artifactHash: contractClass.artifactHash,
26
+ packedBytecode: contractClass.packedBytecode,
27
+ privateFunctionsRoot: contractClass.privateFunctionsRoot,
28
+ version: contractClass.version,
57
29
  };
58
30
  }
59
31
 
60
32
  async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
61
- const contractClass = await this.contractStore.getContractClass(id);
62
- return contractClass && computePublicBytecodeCommitment(contractClass.packedBytecode);
33
+ const contractClass = await this.contractStore.getContractClassWithPreimage(id);
34
+ return contractClass?.publicBytecodeCommitment;
63
35
  }
64
36
 
65
37
  async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {