@aztec/txe 0.0.1-commit.d431d1c → 0.0.1-commit.db765a8

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 (55) hide show
  1. package/dest/index.d.ts +1 -1
  2. package/dest/index.d.ts.map +1 -1
  3. package/dest/index.js +88 -54
  4. package/dest/oracle/interfaces.d.ts +29 -28
  5. package/dest/oracle/interfaces.d.ts.map +1 -1
  6. package/dest/oracle/txe_oracle_public_context.d.ts +15 -15
  7. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  8. package/dest/oracle/txe_oracle_public_context.js +16 -16
  9. package/dest/oracle/txe_oracle_top_level_context.d.ts +22 -23
  10. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_top_level_context.js +125 -54
  12. package/dest/rpc_translator.d.ts +87 -81
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +283 -166
  15. package/dest/state_machine/archiver.d.ts +2 -2
  16. package/dest/state_machine/archiver.d.ts.map +1 -1
  17. package/dest/state_machine/archiver.js +7 -6
  18. package/dest/state_machine/dummy_p2p_client.d.ts +16 -12
  19. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  20. package/dest/state_machine/dummy_p2p_client.js +28 -16
  21. package/dest/state_machine/index.d.ts +7 -7
  22. package/dest/state_machine/index.d.ts.map +1 -1
  23. package/dest/state_machine/index.js +31 -17
  24. package/dest/state_machine/mock_epoch_cache.d.ts +6 -2
  25. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  26. package/dest/state_machine/mock_epoch_cache.js +6 -1
  27. package/dest/state_machine/synchronizer.d.ts +3 -3
  28. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  29. package/dest/txe_session.d.ts +9 -6
  30. package/dest/txe_session.d.ts.map +1 -1
  31. package/dest/txe_session.js +86 -26
  32. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  33. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  34. package/dest/util/txe_public_contract_data_source.js +5 -22
  35. package/dest/utils/block_creation.d.ts +5 -5
  36. package/dest/utils/block_creation.d.ts.map +1 -1
  37. package/dest/utils/block_creation.js +7 -5
  38. package/package.json +15 -15
  39. package/src/index.ts +89 -52
  40. package/src/oracle/interfaces.ts +32 -31
  41. package/src/oracle/txe_oracle_public_context.ts +18 -20
  42. package/src/oracle/txe_oracle_top_level_context.ts +155 -102
  43. package/src/rpc_translator.ts +298 -168
  44. package/src/state_machine/archiver.ts +6 -8
  45. package/src/state_machine/dummy_p2p_client.ts +40 -22
  46. package/src/state_machine/index.ts +49 -19
  47. package/src/state_machine/mock_epoch_cache.ts +7 -1
  48. package/src/state_machine/synchronizer.ts +2 -2
  49. package/src/txe_session.ts +101 -85
  50. package/src/util/txe_public_contract_data_source.ts +10 -36
  51. package/src/utils/block_creation.ts +8 -6
  52. package/dest/util/txe_contract_store.d.ts +0 -12
  53. package/dest/util/txe_contract_store.d.ts.map +0 -1
  54. package/dest/util/txe_contract_store.js +0 -22
  55. package/src/util/txe_contract_store.ts +0 -36
@@ -17,18 +17,14 @@ export class TXEArchiver extends ArchiverDataSourceBase {
17
17
  private readonly updater = new ArchiverDataStoreUpdater(this.store);
18
18
 
19
19
  constructor(db: AztecAsyncKVStore) {
20
- const store = new KVArchiverDataStore(db, 9999);
20
+ const store = new KVArchiverDataStore(db, 9999, { epochDuration: 32 });
21
21
  super(store);
22
22
  }
23
23
 
24
- // TXE-specific method for adding checkpoints
25
- public async addCheckpoints(checkpoints: PublishedCheckpoint[], result?: ValidateCheckpointResult): Promise<boolean> {
26
- await this.updater.setNewCheckpointData(checkpoints, result);
27
- return true;
24
+ public async addCheckpoints(checkpoints: PublishedCheckpoint[], result?: ValidateCheckpointResult): Promise<void> {
25
+ await this.updater.addCheckpoints(checkpoints, result);
28
26
  }
29
27
 
30
- // Abstract method implementations
31
-
32
28
  public getRollupAddress(): Promise<EthAddress> {
33
29
  throw new Error('TXE Archiver does not implement "getRollupAddress"');
34
30
  }
@@ -63,7 +59,9 @@ export class TXEArchiver extends ArchiverDataSourceBase {
63
59
  if (!checkpointedBlock) {
64
60
  throw new Error(`L2Tips requested from TXE Archiver but no checkpointed block found for block number ${number}`);
65
61
  }
66
- const checkpoint = await this.store.getRangeOfCheckpoints(CheckpointNumber(number), 1);
62
+ // TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
63
+ // This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
64
+ const checkpoint = await this.store.getRangeOfCheckpoints(CheckpointNumber.fromBlockNumber(number), 1);
67
65
  if (checkpoint.length === 0) {
68
66
  throw new Error(`L2Tips requested from TXE Archiver but no checkpoint found for block number ${number}`);
69
67
  }
@@ -6,6 +6,8 @@ import type {
6
6
  P2PBlockReceivedCallback,
7
7
  P2PCheckpointReceivedCallback,
8
8
  P2PConfig,
9
+ P2PDuplicateAttestationCallback,
10
+ P2PDuplicateProposalCallback,
9
11
  P2PSyncState,
10
12
  PeerId,
11
13
  ReqRespSubProtocol,
@@ -14,12 +16,12 @@ import type {
14
16
  StatusMessage,
15
17
  } from '@aztec/p2p';
16
18
  import type { EthAddress, L2BlockStreamEvent, L2Tips } from '@aztec/stdlib/block';
17
- import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
18
- import type { BlockProposal, CheckpointAttestation, CheckpointProposal } from '@aztec/stdlib/p2p';
19
- import type { Tx, TxHash } from '@aztec/stdlib/tx';
19
+ import type { ITxProvider, PeerInfo } from '@aztec/stdlib/interfaces/server';
20
+ import type { BlockProposal, CheckpointAttestation, CheckpointProposal, TopicType } from '@aztec/stdlib/p2p';
21
+ import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
20
22
 
21
23
  export class DummyP2P implements P2P {
22
- public validate(_txs: Tx[]): Promise<void> {
24
+ public validateTxsReceivedInBlockProposal(_txs: Tx[]): Promise<void> {
23
25
  return Promise.resolve();
24
26
  }
25
27
 
@@ -39,6 +41,10 @@ export class DummyP2P implements P2P {
39
41
  throw new Error('DummyP2P does not implement "getPeers"');
40
42
  }
41
43
 
44
+ public getGossipMeshPeerCount(_topicType: TopicType): Promise<number> {
45
+ return Promise.resolve(0);
46
+ }
47
+
42
48
  public broadcastProposal(_proposal: BlockProposal): Promise<void> {
43
49
  throw new Error('DummyP2P does not implement "broadcastProposal"');
44
50
  }
@@ -71,8 +77,8 @@ export class DummyP2P implements P2P {
71
77
  throw new Error('DummyP2P does not implement "sendTx"');
72
78
  }
73
79
 
74
- public deleteTxs(_txHashes: TxHash[]): Promise<void> {
75
- throw new Error('DummyP2P does not implement "deleteTxs"');
80
+ public handleFailedExecution(_txHashes: TxHash[]): Promise<void> {
81
+ throw new Error('DummyP2P does not implement "handleFailedExecution"');
76
82
  }
77
83
 
78
84
  public getTxByHashFromPool(_txHash: TxHash): Promise<Tx | undefined> {
@@ -97,6 +103,10 @@ export class DummyP2P implements P2P {
97
103
  throw new Error('DummyP2P does not implement "iteratePendingTxs"');
98
104
  }
99
105
 
106
+ public iterateEligiblePendingTxs(): AsyncIterableIterator<Tx> {
107
+ throw new Error('DummyP2P does not implement "iterateEligiblePendingTxs"');
108
+ }
109
+
100
110
  public getPendingTxCount(): Promise<number> {
101
111
  throw new Error('DummyP2P does not implement "getPendingTxCount"');
102
112
  }
@@ -125,6 +135,10 @@ export class DummyP2P implements P2P {
125
135
  throw new Error('DummyP2P does not implement "isP2PClient"');
126
136
  }
127
137
 
138
+ public getTxProvider(): ITxProvider {
139
+ throw new Error('DummyP2P does not implement "getTxProvider"');
140
+ }
141
+
128
142
  public getTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
129
143
  throw new Error('DummyP2P does not implement "getTxsByHash"');
130
144
  }
@@ -133,8 +147,8 @@ export class DummyP2P implements P2P {
133
147
  throw new Error('DummyP2P does not implement "getCheckpointAttestationsForSlot"');
134
148
  }
135
149
 
136
- public addCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
137
- throw new Error('DummyP2P does not implement "addCheckpointAttestations"');
150
+ public addOwnCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
151
+ throw new Error('DummyP2P does not implement "addOwnCheckpointAttestations"');
138
152
  }
139
153
 
140
154
  public getL2BlockHash(_number: number): Promise<string | undefined> {
@@ -157,14 +171,6 @@ export class DummyP2P implements P2P {
157
171
  throw new Error('DummyP2P does not implement "sync"');
158
172
  }
159
173
 
160
- public requestTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
161
- throw new Error('DummyP2P does not implement "requestTxsByHash"');
162
- }
163
-
164
- public getTxs(_filter: 'all' | 'pending' | 'mined'): Promise<Tx[]> {
165
- throw new Error('DummyP2P does not implement "getTxs"');
166
- }
167
-
168
174
  public getTxsByHashFromPool(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
169
175
  throw new Error('DummyP2P does not implement "getTxsByHashFromPool"');
170
176
  }
@@ -173,10 +179,6 @@ export class DummyP2P implements P2P {
173
179
  throw new Error('DummyP2P does not implement "hasTxsInPool"');
174
180
  }
175
181
 
176
- public addTxsToPool(_txs: Tx[]): Promise<number> {
177
- throw new Error('DummyP2P does not implement "addTxs"');
178
- }
179
-
180
182
  public getSyncedLatestBlockNum(): Promise<number> {
181
183
  throw new Error('DummyP2P does not implement "getSyncedLatestBlockNum"');
182
184
  }
@@ -189,8 +191,12 @@ export class DummyP2P implements P2P {
189
191
  throw new Error('DummyP2P does not implement "getSyncedLatestSlot"');
190
192
  }
191
193
 
192
- markTxsAsNonEvictable(_: TxHash[]): Promise<void> {
193
- throw new Error('DummyP2P does not implement "markTxsAsNonEvictable".');
194
+ protectTxs(_txHashes: TxHash[], _blockHeader: BlockHeader): Promise<TxHash[]> {
195
+ throw new Error('DummyP2P does not implement "protectTxs".');
196
+ }
197
+
198
+ prepareForSlot(_slotNumber: SlotNumber): Promise<void> {
199
+ return Promise.resolve();
194
200
  }
195
201
 
196
202
  addReqRespSubProtocol(
@@ -206,4 +212,16 @@ export class DummyP2P implements P2P {
206
212
 
207
213
  //This is no-op
208
214
  public registerThisValidatorAddresses(_address: EthAddress[]): void {}
215
+
216
+ public registerDuplicateProposalCallback(_callback: P2PDuplicateProposalCallback): void {
217
+ throw new Error('DummyP2P does not implement "registerDuplicateProposalCallback"');
218
+ }
219
+
220
+ public registerDuplicateAttestationCallback(_callback: P2PDuplicateAttestationCallback): void {
221
+ throw new Error('DummyP2P does not implement "registerDuplicateAttestationCallback"');
222
+ }
223
+
224
+ public hasBlockProposalsForSlot(_slot: SlotNumber): Promise<boolean> {
225
+ throw new Error('DummyP2P does not implement "hasBlockProposalsForSlot"');
226
+ }
209
227
  }
@@ -1,11 +1,13 @@
1
1
  import { type AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
2
2
  import { TestCircuitVerifier } from '@aztec/bb-prover/test';
3
+ import { CheckpointNumber } from '@aztec/foundation/branded-types';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
5
  import { createLogger } from '@aztec/foundation/log';
4
- import type { AztecAsyncKVStore } from '@aztec/kv-store';
5
- import { AnchorBlockStore } from '@aztec/pxe/server';
6
- import { L2BlockNew } from '@aztec/stdlib/block';
6
+ import { type AnchorBlockStore, type ContractStore, ContractSyncService, type NoteStore } from '@aztec/pxe/server';
7
+ import { L2Block } from '@aztec/stdlib/block';
7
8
  import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
8
9
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
10
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
9
11
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
10
12
 
11
13
  import { TXEArchiver } from './archiver.js';
@@ -23,13 +25,16 @@ export class TXEStateMachine {
23
25
  public synchronizer: TXESynchronizer,
24
26
  public archiver: TXEArchiver,
25
27
  public anchorBlockStore: AnchorBlockStore,
28
+ public contractSyncService: ContractSyncService,
26
29
  ) {}
27
30
 
28
- public static async create(db: AztecAsyncKVStore) {
29
- const archiver = new TXEArchiver(db);
31
+ public static async create(
32
+ archiver: TXEArchiver,
33
+ anchorBlockStore: AnchorBlockStore,
34
+ contractStore: ContractStore,
35
+ noteStore: NoteStore,
36
+ ) {
30
37
  const synchronizer = await TXESynchronizer.create();
31
- const anchorBlockStore = new AnchorBlockStore(db);
32
-
33
38
  const aztecNodeConfig = {} as AztecNodeConfig;
34
39
 
35
40
  const log = createLogger('txe_node');
@@ -45,6 +50,7 @@ export class TXEStateMachine {
45
50
  undefined,
46
51
  undefined,
47
52
  undefined,
53
+ undefined,
48
54
  VERSION,
49
55
  CHAIN_ID,
50
56
  new TXEGlobalVariablesBuilder(),
@@ -55,18 +61,39 @@ export class TXEStateMachine {
55
61
  log,
56
62
  );
57
63
 
58
- return new this(node, synchronizer, archiver, anchorBlockStore);
64
+ const contractSyncService = new ContractSyncService(
65
+ node,
66
+ contractStore,
67
+ noteStore,
68
+ createLogger('txe:contract_sync'),
69
+ );
70
+
71
+ return new this(node, synchronizer, archiver, anchorBlockStore, contractSyncService);
59
72
  }
60
73
 
61
- public async handleL2Block(block: L2BlockNew) {
62
- // Create a checkpoint from the block - L2BlockNew doesn't have toCheckpoint() method
63
- // We need to construct the Checkpoint manually
64
- const checkpoint = await Checkpoint.random(block.checkpointNumber, {
65
- numBlocks: 1,
66
- startBlockNumber: Number(block.number),
67
- });
68
- // Replace the random block with our actual block
69
- checkpoint.blocks = [block];
74
+ public async handleL2Block(block: L2Block) {
75
+ // Create a checkpoint from the block manually.
76
+ // TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
77
+ // This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
78
+ const checkpointNumber = CheckpointNumber.fromBlockNumber(block.number);
79
+ const checkpoint = new Checkpoint(
80
+ block.archive,
81
+ CheckpointHeader.from({
82
+ lastArchiveRoot: block.header.lastArchive.root,
83
+ inHash: Fr.ZERO,
84
+ blobsHash: Fr.ZERO,
85
+ blockHeadersHash: Fr.ZERO,
86
+ epochOutHash: Fr.ZERO,
87
+ slotNumber: block.header.globalVariables.slotNumber,
88
+ timestamp: block.header.globalVariables.timestamp,
89
+ coinbase: block.header.globalVariables.coinbase,
90
+ feeRecipient: block.header.globalVariables.feeRecipient,
91
+ gasFees: block.header.globalVariables.gasFees,
92
+ totalManaUsed: block.header.totalManaUsed,
93
+ }),
94
+ [block],
95
+ checkpointNumber,
96
+ );
70
97
 
71
98
  const publishedCheckpoint = new PublishedCheckpoint(
72
99
  checkpoint,
@@ -77,10 +104,13 @@ export class TXEStateMachine {
77
104
  ),
78
105
  [],
79
106
  );
107
+ // Wipe contract sync cache when anchor block changes (mirrors BlockSynchronizer behavior)
108
+ this.contractSyncService.wipe();
109
+
80
110
  await Promise.all([
81
- this.synchronizer.handleL2Block(block), // L2BlockNew doesn't need toL2Block() conversion
111
+ this.synchronizer.handleL2Block(block),
82
112
  this.archiver.addCheckpoints([publishedCheckpoint], undefined),
83
- this.anchorBlockStore.setHeader(block.header), // Use .header property directly
113
+ this.anchorBlockStore.setHeader(block.header),
84
114
  ]);
85
115
  }
86
116
  }
@@ -1,6 +1,7 @@
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.
@@ -16,11 +17,12 @@ export class MockEpochCache implements EpochCacheInterface {
16
17
  });
17
18
  }
18
19
 
19
- getEpochAndSlotNow(): EpochAndSlot {
20
+ getEpochAndSlotNow(): EpochAndSlot & { nowMs: bigint } {
20
21
  return {
21
22
  epoch: EpochNumber.ZERO,
22
23
  slot: SlotNumber(0),
23
24
  ts: 0n,
25
+ nowMs: 0n,
24
26
  };
25
27
  }
26
28
 
@@ -63,4 +65,8 @@ export class MockEpochCache implements EpochCacheInterface {
63
65
  filterInCommittee(_slot: SlotTag, _validators: EthAddress[]): Promise<EthAddress[]> {
64
66
  return Promise.resolve([]);
65
67
  }
68
+
69
+ getL1Constants(): L1RollupConstants {
70
+ return EmptyL1RollupConstants;
71
+ }
66
72
  }
@@ -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 { 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),
@@ -3,10 +3,12 @@ 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';
6
+ import type { AccessScopes } from '@aztec/pxe/client/lazy';
7
7
  import {
8
8
  AddressStore,
9
+ AnchorBlockStore,
9
10
  CapsuleStore,
11
+ ContractStore,
10
12
  JobCoordinator,
11
13
  NoteService,
12
14
  NoteStore,
@@ -49,10 +51,10 @@ import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfac
49
51
  import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
50
52
  import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
51
53
  import { RPCTranslator } from './rpc_translator.js';
54
+ import { TXEArchiver } from './state_machine/archiver.js';
52
55
  import { TXEStateMachine } from './state_machine/index.js';
53
56
  import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
54
57
  import { TXEAccountStore } from './util/txe_account_store.js';
55
- import { TXEContractStore } from './util/txe_contract_store.js';
56
58
  import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
57
59
  import { makeTxEffect } from './utils/tx_effect_creation.js';
58
60
 
@@ -111,6 +113,10 @@ export interface TXESessionStateHandler {
111
113
  enterPublicState(contractAddress?: AztecAddress): Promise<void>;
112
114
  enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
113
115
  enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
116
+
117
+ // TODO(F-335): Exposing the job info is abstraction breakage - drop the following 2 functions.
118
+ cycleJob(): Promise<string>;
119
+ getCurrentJob(): string;
114
120
  }
115
121
 
116
122
  /**
@@ -129,7 +135,7 @@ export class TXESession implements TXESessionStateHandler {
129
135
  | IPrivateExecutionOracle
130
136
  | IAvmExecutionOracle
131
137
  | ITxeExecutionOracle,
132
- private contractStore: TXEContractStore,
138
+ private contractStore: ContractStore,
133
139
  private noteStore: NoteStore,
134
140
  private keyStore: KeyStore,
135
141
  private addressStore: AddressStore,
@@ -146,13 +152,12 @@ export class TXESession implements TXESessionStateHandler {
146
152
  private nextBlockTimestamp: bigint,
147
153
  ) {}
148
154
 
149
- static async init(protocolContracts: ProtocolContract[]) {
155
+ static async init(contractStore: ContractStore) {
150
156
  const store = await openTmpStore('txe-session');
151
157
 
152
158
  const addressStore = new AddressStore(store);
153
159
  const privateEventStore = new PrivateEventStore(store);
154
- const contractStore = new TXEContractStore(store);
155
- const noteStore = await NoteStore.create(store);
160
+ const noteStore = new NoteStore(store);
156
161
  const senderTaggingStore = new SenderTaggingStore(store);
157
162
  const recipientTaggingStore = new RecipientTaggingStore(store);
158
163
  const senderAddressBookStore = new SenderAddressBookStore(store);
@@ -162,15 +167,17 @@ export class TXESession implements TXESessionStateHandler {
162
167
 
163
168
  // Create job coordinator and register staged stores
164
169
  const jobCoordinator = new JobCoordinator(store);
165
- jobCoordinator.registerStores([capsuleStore, senderTaggingStore, recipientTaggingStore, privateEventStore]);
166
-
167
- // Register protocol contracts.
168
- for (const { contractClass, instance, artifact } of protocolContracts) {
169
- await contractStore.addContractArtifact(contractClass.id, artifact);
170
- await contractStore.addContractInstance(instance);
171
- }
170
+ jobCoordinator.registerStores([
171
+ capsuleStore,
172
+ senderTaggingStore,
173
+ recipientTaggingStore,
174
+ privateEventStore,
175
+ noteStore,
176
+ ]);
172
177
 
173
- const stateMachine = await TXEStateMachine.create(store);
178
+ const archiver = new TXEArchiver(store);
179
+ const anchorBlockStore = new AnchorBlockStore(store);
180
+ const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
174
181
 
175
182
  const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
176
183
  const version = new Fr(await stateMachine.node.getVersion());
@@ -190,13 +197,12 @@ export class TXESession implements TXESessionStateHandler {
190
197
  senderAddressBookStore,
191
198
  capsuleStore,
192
199
  privateEventStore,
193
- initialJobId,
194
200
  nextBlockTimestamp,
195
201
  version,
196
202
  chainId,
197
203
  new Map(),
198
204
  );
199
- await topLevelOracleHandler.txeAdvanceBlocksBy(1);
205
+ await topLevelOracleHandler.advanceBlocksBy(1);
200
206
 
201
207
  return new TXESession(
202
208
  createLogger('txe:session'),
@@ -251,6 +257,17 @@ export class TXESession implements TXESessionStateHandler {
251
257
  }
252
258
  }
253
259
 
260
+ getCurrentJob(): string {
261
+ return this.currentJobId;
262
+ }
263
+
264
+ /** Commits the current job and begins a new one. Returns the new job ID. */
265
+ async cycleJob(): Promise<string> {
266
+ await this.jobCoordinator.commitJob(this.currentJobId);
267
+ this.currentJobId = this.jobCoordinator.beginJob();
268
+ return this.currentJobId;
269
+ }
270
+
254
271
  async enterTopLevelState() {
255
272
  switch (this.state.name) {
256
273
  case 'PRIVATE': {
@@ -274,8 +291,7 @@ export class TXESession implements TXESessionStateHandler {
274
291
  }
275
292
 
276
293
  // Commit all staged stores from the job that was just completed, then begin a new job
277
- await this.jobCoordinator.commitJob(this.currentJobId);
278
- this.currentJobId = this.jobCoordinator.beginJob();
294
+ await this.cycleJob();
279
295
 
280
296
  this.oracleHandler = new TXEOracleTopLevelContext(
281
297
  this.stateMachine,
@@ -289,7 +305,6 @@ export class TXESession implements TXESessionStateHandler {
289
305
  this.senderAddressBookStore,
290
306
  this.capsuleStore,
291
307
  this.privateEventStore,
292
- this.currentJobId,
293
308
  this.nextBlockTimestamp,
294
309
  this.version,
295
310
  this.chainId,
@@ -306,16 +321,15 @@ export class TXESession implements TXESessionStateHandler {
306
321
  ): Promise<PrivateContextInputs> {
307
322
  this.exitTopLevelState();
308
323
 
309
- await new NoteService(
310
- this.noteStore,
311
- this.stateMachine.node,
312
- this.stateMachine.anchorBlockStore,
313
- ).syncNoteNullifiers(contractAddress);
314
-
315
324
  // Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
316
325
  // build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
317
326
  // a single transaction with the effects of what was done in the test.
318
327
  const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
328
+
329
+ await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
330
+ contractAddress,
331
+ 'ALL_SCOPES',
332
+ );
319
333
  const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
320
334
 
321
335
  const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
@@ -331,30 +345,31 @@ export class TXESession implements TXESessionStateHandler {
331
345
  const taggingIndexCache = new ExecutionTaggingIndexCache();
332
346
 
333
347
  const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
334
- this.oracleHandler = new PrivateExecutionOracle(
335
- Fr.ZERO,
336
- new TxContext(this.chainId, this.version, GasSettings.empty()),
337
- new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
338
- anchorBlock!,
348
+ this.oracleHandler = new PrivateExecutionOracle({
349
+ argsHash: Fr.ZERO,
350
+ txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
351
+ callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
352
+ anchorBlockHeader: anchorBlock!,
339
353
  utilityExecutor,
340
- [],
341
- [],
342
- new HashedValuesCache(),
354
+ authWitnesses: [],
355
+ capsules: [],
356
+ executionCache: new HashedValuesCache(),
343
357
  noteCache,
344
358
  taggingIndexCache,
345
- this.contractStore,
346
- this.noteStore,
347
- this.keyStore,
348
- this.addressStore,
349
- this.stateMachine.node,
350
- this.stateMachine.anchorBlockStore,
351
- this.senderTaggingStore,
352
- this.recipientTaggingStore,
353
- this.senderAddressBookStore,
354
- this.capsuleStore,
355
- this.privateEventStore,
356
- this.currentJobId,
357
- );
359
+ contractStore: this.contractStore,
360
+ noteStore: this.noteStore,
361
+ keyStore: this.keyStore,
362
+ addressStore: this.addressStore,
363
+ aztecNode: this.stateMachine.node,
364
+ senderTaggingStore: this.senderTaggingStore,
365
+ recipientTaggingStore: this.recipientTaggingStore,
366
+ senderAddressBookStore: this.senderAddressBookStore,
367
+ capsuleStore: this.capsuleStore,
368
+ privateEventStore: this.privateEventStore,
369
+ contractSyncService: this.stateMachine.contractSyncService,
370
+ jobId: this.currentJobId,
371
+ scopes: 'ALL_SCOPES',
372
+ });
358
373
 
359
374
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
360
375
  // data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
@@ -394,6 +409,8 @@ export class TXESession implements TXESessionStateHandler {
394
409
  async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
395
410
  this.exitTopLevelState();
396
411
 
412
+ const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
413
+
397
414
  // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
398
415
  // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
399
416
  // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
@@ -402,28 +419,27 @@ export class TXESession implements TXESessionStateHandler {
402
419
  await new NoteService(
403
420
  this.noteStore,
404
421
  this.stateMachine.node,
405
- this.stateMachine.anchorBlockStore,
406
- ).syncNoteNullifiers(contractAddress);
407
-
408
- const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
422
+ anchorBlockHeader,
423
+ this.currentJobId,
424
+ ).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
409
425
 
410
- this.oracleHandler = new UtilityExecutionOracle(
426
+ this.oracleHandler = new UtilityExecutionOracle({
411
427
  contractAddress,
412
- [],
413
- [],
428
+ authWitnesses: [],
429
+ capsules: [],
414
430
  anchorBlockHeader,
415
- this.contractStore,
416
- this.noteStore,
417
- this.keyStore,
418
- this.addressStore,
419
- this.stateMachine.node,
420
- this.stateMachine.anchorBlockStore,
421
- this.recipientTaggingStore,
422
- this.senderAddressBookStore,
423
- this.capsuleStore,
424
- this.privateEventStore,
425
- this.currentJobId,
426
- );
431
+ contractStore: this.contractStore,
432
+ noteStore: this.noteStore,
433
+ keyStore: this.keyStore,
434
+ addressStore: this.addressStore,
435
+ aztecNode: this.stateMachine.node,
436
+ recipientTaggingStore: this.recipientTaggingStore,
437
+ senderAddressBookStore: this.senderAddressBookStore,
438
+ capsuleStore: this.capsuleStore,
439
+ privateEventStore: this.privateEventStore,
440
+ jobId: this.currentJobId,
441
+ scopes: 'ALL_SCOPES',
442
+ });
427
443
 
428
444
  this.state = { name: 'UTILITY' };
429
445
  this.logger.debug(`Entered state ${this.state.name}`);
@@ -436,8 +452,8 @@ export class TXESession implements TXESessionStateHandler {
436
452
 
437
453
  // Note that while all public and private contexts do is build a single block that we then process when exiting
438
454
  // those, the top level context performs a large number of actions not captured in the following 'close' call. Among
439
- // others, it will create empty blocks (via `txeAdvanceBlocksBy` and `deploy`), create blocks with transactions via
440
- // `txePrivateCallNewFlow` and `txePublicCallNewFlow`, add accounts to PXE via `txeAddAccount`, etc. This is a
455
+ // others, it will create empty blocks (via `advanceBlocksBy` and `deploy`), create blocks with transactions via
456
+ // `privateCallNewFlow` and `publicCallNewFlow`, add accounts to PXE via `addAccount`, etc. This is a
441
457
  // slight inconsistency in the working model of this class, but is not too bad.
442
458
  // TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
443
459
  // level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
@@ -491,30 +507,30 @@ export class TXESession implements TXESessionStateHandler {
491
507
  }
492
508
 
493
509
  private utilityExecutorForContractSync(anchorBlock: any) {
494
- return async (call: FunctionCall) => {
510
+ return async (call: FunctionCall, scopes: AccessScopes) => {
495
511
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
496
512
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
497
513
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
498
514
  }
499
515
 
500
516
  try {
501
- const oracle = new UtilityExecutionOracle(
502
- call.to,
503
- [],
504
- [],
505
- anchorBlock!,
506
- this.contractStore,
507
- this.noteStore,
508
- this.keyStore,
509
- this.addressStore,
510
- this.stateMachine.node,
511
- this.stateMachine.anchorBlockStore,
512
- this.recipientTaggingStore,
513
- this.senderAddressBookStore,
514
- this.capsuleStore,
515
- this.privateEventStore,
516
- this.currentJobId,
517
- );
517
+ const oracle = new UtilityExecutionOracle({
518
+ contractAddress: call.to,
519
+ authWitnesses: [],
520
+ capsules: [],
521
+ anchorBlockHeader: anchorBlock!,
522
+ contractStore: this.contractStore,
523
+ noteStore: this.noteStore,
524
+ keyStore: this.keyStore,
525
+ addressStore: this.addressStore,
526
+ aztecNode: this.stateMachine.node,
527
+ recipientTaggingStore: this.recipientTaggingStore,
528
+ senderAddressBookStore: this.senderAddressBookStore,
529
+ capsuleStore: this.capsuleStore,
530
+ privateEventStore: this.privateEventStore,
531
+ jobId: this.currentJobId,
532
+ scopes,
533
+ });
518
534
  await new WASMSimulator()
519
535
  .executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
520
536
  .catch((err: Error) => {