@aztec/txe 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5d02921e

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 (58) 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 +13 -13
  7. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  8. package/dest/oracle/txe_oracle_public_context.js +12 -12
  9. package/dest/oracle/txe_oracle_top_level_context.d.ts +23 -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 +112 -54
  12. package/dest/rpc_translator.d.ts +87 -82
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +285 -152
  15. package/dest/state_machine/archiver.d.ts +3 -3
  16. package/dest/state_machine/archiver.d.ts.map +1 -1
  17. package/dest/state_machine/archiver.js +7 -8
  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/global_variable_builder.d.ts +3 -3
  22. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  23. package/dest/state_machine/global_variable_builder.js +1 -1
  24. package/dest/state_machine/index.d.ts +6 -3
  25. package/dest/state_machine/index.d.ts.map +1 -1
  26. package/dest/state_machine/index.js +9 -5
  27. package/dest/state_machine/mock_epoch_cache.d.ts +17 -3
  28. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  29. package/dest/state_machine/mock_epoch_cache.js +32 -2
  30. package/dest/state_machine/synchronizer.d.ts +5 -5
  31. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  32. package/dest/state_machine/synchronizer.js +3 -3
  33. package/dest/txe_session.d.ts +10 -6
  34. package/dest/txe_session.d.ts.map +1 -1
  35. package/dest/txe_session.js +90 -25
  36. package/dest/util/encoding.d.ts +69 -1
  37. package/dest/util/encoding.d.ts.map +1 -1
  38. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  39. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  40. package/dest/util/txe_public_contract_data_source.js +6 -25
  41. package/package.json +15 -15
  42. package/src/index.ts +89 -52
  43. package/src/oracle/interfaces.ts +32 -31
  44. package/src/oracle/txe_oracle_public_context.ts +12 -12
  45. package/src/oracle/txe_oracle_top_level_context.ts +118 -92
  46. package/src/rpc_translator.ts +332 -174
  47. package/src/state_machine/archiver.ts +6 -5
  48. package/src/state_machine/dummy_p2p_client.ts +39 -22
  49. package/src/state_machine/global_variable_builder.ts +7 -1
  50. package/src/state_machine/index.ts +10 -1
  51. package/src/state_machine/mock_epoch_cache.ts +42 -3
  52. package/src/state_machine/synchronizer.ts +4 -4
  53. package/src/txe_session.ts +102 -73
  54. package/src/util/txe_public_contract_data_source.ts +10 -38
  55. package/dest/util/txe_contract_store.d.ts +0 -12
  56. package/dest/util/txe_contract_store.d.ts.map +0 -1
  57. package/dest/util/txe_contract_store.js +0 -22
  58. package/src/util/txe_contract_store.ts +0 -36
@@ -17,7 +17,7 @@ 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, { epochDuration: 32 });
20
+ const store = new KVArchiverDataStore(db, 9999);
21
21
  super(store);
22
22
  }
23
23
 
@@ -76,15 +76,16 @@ export class TXEArchiver extends ArchiverDataSourceBase {
76
76
  proven: tipId,
77
77
  finalized: tipId,
78
78
  checkpointed: tipId,
79
+ proposedCheckpoint: tipId,
79
80
  };
80
81
  }
81
82
 
82
- public getL2SlotNumber(): Promise<SlotNumber | undefined> {
83
- throw new Error('TXE Archiver does not implement "getL2SlotNumber"');
83
+ public getSyncedL2SlotNumber(): Promise<SlotNumber | undefined> {
84
+ throw new Error('TXE Archiver does not implement "getSyncedL2SlotNumber"');
84
85
  }
85
86
 
86
- public getL2EpochNumber(): Promise<EpochNumber | undefined> {
87
- throw new Error('TXE Archiver does not implement "getL2EpochNumber"');
87
+ public getSyncedL2EpochNumber(): Promise<EpochNumber | undefined> {
88
+ throw new Error('TXE Archiver does not implement "getSyncedL2EpochNumber"');
88
89
  }
89
90
 
90
91
  public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
@@ -6,6 +6,7 @@ import type {
6
6
  P2PBlockReceivedCallback,
7
7
  P2PCheckpointReceivedCallback,
8
8
  P2PConfig,
9
+ P2PDuplicateAttestationCallback,
9
10
  P2PDuplicateProposalCallback,
10
11
  P2PSyncState,
11
12
  PeerId,
@@ -15,12 +16,12 @@ import type {
15
16
  StatusMessage,
16
17
  } from '@aztec/p2p';
17
18
  import type { EthAddress, L2BlockStreamEvent, L2Tips } from '@aztec/stdlib/block';
18
- import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
19
- import type { BlockProposal, CheckpointAttestation, CheckpointProposal } from '@aztec/stdlib/p2p';
20
- 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';
21
22
 
22
23
  export class DummyP2P implements P2P {
23
- public validate(_txs: Tx[]): Promise<void> {
24
+ public validateTxsReceivedInBlockProposal(_txs: Tx[]): Promise<void> {
24
25
  return Promise.resolve();
25
26
  }
26
27
 
@@ -40,6 +41,10 @@ export class DummyP2P implements P2P {
40
41
  throw new Error('DummyP2P does not implement "getPeers"');
41
42
  }
42
43
 
44
+ public getGossipMeshPeerCount(_topicType: TopicType): Promise<number> {
45
+ return Promise.resolve(0);
46
+ }
47
+
43
48
  public broadcastProposal(_proposal: BlockProposal): Promise<void> {
44
49
  throw new Error('DummyP2P does not implement "broadcastProposal"');
45
50
  }
@@ -56,8 +61,12 @@ export class DummyP2P implements P2P {
56
61
  throw new Error('DummyP2P does not implement "registerBlockProposalHandler"');
57
62
  }
58
63
 
59
- public registerCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
60
- throw new Error('DummyP2P does not implement "registerCheckpointProposalHandler"');
64
+ public registerValidatorCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
65
+ throw new Error('DummyP2P does not implement "registerValidatorCheckpointProposalHandler"');
66
+ }
67
+
68
+ public registerAllNodesCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
69
+ throw new Error('DummyP2P does not implement "registerAllNodesCheckpointProposalHandler"');
61
70
  }
62
71
 
63
72
  public requestTxs(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
@@ -72,8 +81,8 @@ export class DummyP2P implements P2P {
72
81
  throw new Error('DummyP2P does not implement "sendTx"');
73
82
  }
74
83
 
75
- public deleteTxs(_txHashes: TxHash[]): Promise<void> {
76
- throw new Error('DummyP2P does not implement "deleteTxs"');
84
+ public handleFailedExecution(_txHashes: TxHash[]): Promise<void> {
85
+ throw new Error('DummyP2P does not implement "handleFailedExecution"');
77
86
  }
78
87
 
79
88
  public getTxByHashFromPool(_txHash: TxHash): Promise<Tx | undefined> {
@@ -98,6 +107,10 @@ export class DummyP2P implements P2P {
98
107
  throw new Error('DummyP2P does not implement "iteratePendingTxs"');
99
108
  }
100
109
 
110
+ public iterateEligiblePendingTxs(): AsyncIterableIterator<Tx> {
111
+ throw new Error('DummyP2P does not implement "iterateEligiblePendingTxs"');
112
+ }
113
+
101
114
  public getPendingTxCount(): Promise<number> {
102
115
  throw new Error('DummyP2P does not implement "getPendingTxCount"');
103
116
  }
@@ -126,6 +139,10 @@ export class DummyP2P implements P2P {
126
139
  throw new Error('DummyP2P does not implement "isP2PClient"');
127
140
  }
128
141
 
142
+ public getTxProvider(): ITxProvider {
143
+ throw new Error('DummyP2P does not implement "getTxProvider"');
144
+ }
145
+
129
146
  public getTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
130
147
  throw new Error('DummyP2P does not implement "getTxsByHash"');
131
148
  }
@@ -158,14 +175,6 @@ export class DummyP2P implements P2P {
158
175
  throw new Error('DummyP2P does not implement "sync"');
159
176
  }
160
177
 
161
- public requestTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
162
- throw new Error('DummyP2P does not implement "requestTxsByHash"');
163
- }
164
-
165
- public getTxs(_filter: 'all' | 'pending' | 'mined'): Promise<Tx[]> {
166
- throw new Error('DummyP2P does not implement "getTxs"');
167
- }
168
-
169
178
  public getTxsByHashFromPool(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
170
179
  throw new Error('DummyP2P does not implement "getTxsByHashFromPool"');
171
180
  }
@@ -174,10 +183,6 @@ export class DummyP2P implements P2P {
174
183
  throw new Error('DummyP2P does not implement "hasTxsInPool"');
175
184
  }
176
185
 
177
- public addTxsToPool(_txs: Tx[]): Promise<number> {
178
- throw new Error('DummyP2P does not implement "addTxs"');
179
- }
180
-
181
186
  public getSyncedLatestBlockNum(): Promise<number> {
182
187
  throw new Error('DummyP2P does not implement "getSyncedLatestBlockNum"');
183
188
  }
@@ -190,8 +195,12 @@ export class DummyP2P implements P2P {
190
195
  throw new Error('DummyP2P does not implement "getSyncedLatestSlot"');
191
196
  }
192
197
 
193
- markTxsAsNonEvictable(_: TxHash[]): Promise<void> {
194
- throw new Error('DummyP2P does not implement "markTxsAsNonEvictable".');
198
+ protectTxs(_txHashes: TxHash[], _blockHeader: BlockHeader): Promise<TxHash[]> {
199
+ throw new Error('DummyP2P does not implement "protectTxs".');
200
+ }
201
+
202
+ prepareForSlot(_slotNumber: SlotNumber): Promise<void> {
203
+ return Promise.resolve();
195
204
  }
196
205
 
197
206
  addReqRespSubProtocol(
@@ -211,4 +220,12 @@ export class DummyP2P implements P2P {
211
220
  public registerDuplicateProposalCallback(_callback: P2PDuplicateProposalCallback): void {
212
221
  throw new Error('DummyP2P does not implement "registerDuplicateProposalCallback"');
213
222
  }
223
+
224
+ public registerDuplicateAttestationCallback(_callback: P2PDuplicateAttestationCallback): void {
225
+ throw new Error('DummyP2P does not implement "registerDuplicateAttestationCallback"');
226
+ }
227
+
228
+ public hasBlockProposalsForSlot(_slot: SlotNumber): Promise<boolean> {
229
+ throw new Error('DummyP2P does not implement "hasBlockProposalsForSlot"');
230
+ }
214
231
  }
@@ -3,7 +3,12 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import { GasFees } from '@aztec/stdlib/gas';
5
5
  import { makeGlobalVariables } from '@aztec/stdlib/testing';
6
- import { type CheckpointGlobalVariables, type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
6
+ import {
7
+ type BuildCheckpointGlobalVariablesOpts,
8
+ type CheckpointGlobalVariables,
9
+ type GlobalVariableBuilder,
10
+ GlobalVariables,
11
+ } from '@aztec/stdlib/tx';
7
12
 
8
13
  export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
9
14
  public getCurrentMinFees(): Promise<GasFees> {
@@ -23,6 +28,7 @@ export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
23
28
  _coinbase: EthAddress,
24
29
  _feeRecipient: AztecAddress,
25
30
  _slotNumber: SlotNumber,
31
+ _opts?: BuildCheckpointGlobalVariablesOpts,
26
32
  ): Promise<CheckpointGlobalVariables> {
27
33
  const vars = makeGlobalVariables();
28
34
  return Promise.resolve({
@@ -3,7 +3,9 @@ import { TestCircuitVerifier } from '@aztec/bb-prover/test';
3
3
  import { CheckpointNumber } from '@aztec/foundation/branded-types';
4
4
  import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import { createLogger } from '@aztec/foundation/log';
6
+ import type { KeyStore } from '@aztec/key-store';
6
7
  import { type AnchorBlockStore, type ContractStore, ContractSyncService, type NoteStore } from '@aztec/pxe/server';
8
+ import { MessageContextService } from '@aztec/pxe/simulator';
7
9
  import { L2Block } from '@aztec/stdlib/block';
8
10
  import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
9
11
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
@@ -26,6 +28,7 @@ export class TXEStateMachine {
26
28
  public archiver: TXEArchiver,
27
29
  public anchorBlockStore: AnchorBlockStore,
28
30
  public contractSyncService: ContractSyncService,
31
+ public messageContextService: MessageContextService,
29
32
  ) {}
30
33
 
31
34
  public static async create(
@@ -33,6 +36,7 @@ export class TXEStateMachine {
33
36
  anchorBlockStore: AnchorBlockStore,
34
37
  contractStore: ContractStore,
35
38
  noteStore: NoteStore,
39
+ keyStore: KeyStore,
36
40
  ) {
37
41
  const synchronizer = await TXESynchronizer.create();
38
42
  const aztecNodeConfig = {} as AztecNodeConfig;
@@ -50,12 +54,14 @@ export class TXEStateMachine {
50
54
  undefined,
51
55
  undefined,
52
56
  undefined,
57
+ undefined,
53
58
  VERSION,
54
59
  CHAIN_ID,
55
60
  new TXEGlobalVariablesBuilder(),
56
61
  new MockEpochCache(),
57
62
  getPackageVersion() ?? '',
58
63
  new TestCircuitVerifier(),
64
+ new TestCircuitVerifier(),
59
65
  undefined,
60
66
  log,
61
67
  );
@@ -64,10 +70,13 @@ export class TXEStateMachine {
64
70
  node,
65
71
  contractStore,
66
72
  noteStore,
73
+ () => keyStore.getAccounts(),
67
74
  createLogger('txe:contract_sync'),
68
75
  );
69
76
 
70
- return new this(node, synchronizer, archiver, anchorBlockStore, contractSyncService);
77
+ const messageContextService = new MessageContextService(node);
78
+
79
+ return new this(node, synchronizer, archiver, anchorBlockStore, contractSyncService, messageContextService);
71
80
  }
72
81
 
73
82
  public async handleL2Block(block: L2Block) {
@@ -8,7 +8,7 @@ import { EmptyL1RollupConstants, type L1RollupConstants } from '@aztec/stdlib/ep
8
8
  * Since in TXE we don't validate transactions, mock suffices here.
9
9
  */
10
10
  export class MockEpochCache implements EpochCacheInterface {
11
- getCommittee(): Promise<EpochCommitteeInfo> {
11
+ getCommittee(_slot: SlotTag = 'now'): Promise<EpochCommitteeInfo> {
12
12
  return Promise.resolve({
13
13
  committee: undefined,
14
14
  seed: 0n,
@@ -17,6 +17,22 @@ export class MockEpochCache implements EpochCacheInterface {
17
17
  });
18
18
  }
19
19
 
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
+
20
36
  getEpochAndSlotNow(): EpochAndSlot & { nowMs: bigint } {
21
37
  return {
22
38
  epoch: EpochNumber.ZERO,
@@ -26,15 +42,23 @@ export class MockEpochCache implements EpochCacheInterface {
26
42
  };
27
43
  }
28
44
 
29
- getEpochAndSlotInNextL1Slot(): EpochAndSlot & { now: bigint } {
45
+ getEpochAndSlotInNextL1Slot(): EpochAndSlot & { nowSeconds: bigint } {
30
46
  return {
31
47
  epoch: EpochNumber.ZERO,
32
48
  slot: SlotNumber(0),
33
49
  ts: 0n,
34
- now: 0n,
50
+ nowSeconds: 0n,
35
51
  };
36
52
  }
37
53
 
54
+ getTargetEpochAndSlotInNextL1Slot(): EpochAndSlot & { nowSeconds: bigint } {
55
+ return this.getEpochAndSlotInNextL1Slot();
56
+ }
57
+
58
+ isProposerPipeliningEnabled(): boolean {
59
+ return false;
60
+ }
61
+
38
62
  getProposerIndexEncoding(_epoch: EpochNumber, _slot: SlotNumber, _seed: bigint): `0x${string}` {
39
63
  return '0x00';
40
64
  }
@@ -50,6 +74,13 @@ export class MockEpochCache implements EpochCacheInterface {
50
74
  };
51
75
  }
52
76
 
77
+ getTargetAndNextSlot(): { targetSlot: SlotNumber; nextSlot: SlotNumber } {
78
+ return {
79
+ targetSlot: SlotNumber(0),
80
+ nextSlot: SlotNumber(0),
81
+ };
82
+ }
83
+
53
84
  getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined> {
54
85
  return Promise.resolve(undefined);
55
86
  }
@@ -66,6 +97,14 @@ export class MockEpochCache implements EpochCacheInterface {
66
97
  return Promise.resolve([]);
67
98
  }
68
99
 
100
+ isEscapeHatchOpen(_epoch: EpochNumber): Promise<boolean> {
101
+ return Promise.resolve(false);
102
+ }
103
+
104
+ isEscapeHatchOpenAtSlot(_slot: SlotTag): Promise<boolean> {
105
+ return Promise.resolve(false);
106
+ }
107
+
69
108
  getL1Constants(): L1RollupConstants {
70
109
  return EmptyL1RollupConstants;
71
110
  }
@@ -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 { L2Block } from '@aztec/stdlib/block';
4
+ import type { BlockHash, L2Block } from '@aztec/stdlib/block';
5
5
  import type {
6
6
  MerkleTreeReadOperations,
7
7
  MerkleTreeWriteOperations,
@@ -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,11 +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';
6
+ import type { AccessScopes } from '@aztec/pxe/client/lazy';
7
7
  import {
8
8
  AddressStore,
9
9
  AnchorBlockStore,
10
+ CapsuleService,
10
11
  CapsuleStore,
12
+ ContractStore,
13
+ ContractSyncService,
11
14
  JobCoordinator,
12
15
  NoteService,
13
16
  NoteStore,
@@ -54,7 +57,6 @@ import { TXEArchiver } from './state_machine/archiver.js';
54
57
  import { TXEStateMachine } from './state_machine/index.js';
55
58
  import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
56
59
  import { TXEAccountStore } from './util/txe_account_store.js';
57
- import { TXEContractStore } from './util/txe_contract_store.js';
58
60
  import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
59
61
  import { makeTxEffect } from './utils/tx_effect_creation.js';
60
62
 
@@ -113,6 +115,10 @@ export interface TXESessionStateHandler {
113
115
  enterPublicState(contractAddress?: AztecAddress): Promise<void>;
114
116
  enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
115
117
  enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
118
+
119
+ // TODO(F-335): Exposing the job info is abstraction breakage - drop the following 2 functions.
120
+ cycleJob(): Promise<string>;
121
+ getCurrentJob(): string;
116
122
  }
117
123
 
118
124
  /**
@@ -131,7 +137,7 @@ export class TXESession implements TXESessionStateHandler {
131
137
  | IPrivateExecutionOracle
132
138
  | IAvmExecutionOracle
133
139
  | ITxeExecutionOracle,
134
- private contractStore: TXEContractStore,
140
+ private contractStore: ContractStore,
135
141
  private noteStore: NoteStore,
136
142
  private keyStore: KeyStore,
137
143
  private addressStore: AddressStore,
@@ -146,14 +152,14 @@ export class TXESession implements TXESessionStateHandler {
146
152
  private chainId: Fr,
147
153
  private version: Fr,
148
154
  private nextBlockTimestamp: bigint,
155
+ private contractSyncService: ContractSyncService,
149
156
  ) {}
150
157
 
151
- static async init(protocolContracts: ProtocolContract[]) {
158
+ static async init(contractStore: ContractStore) {
152
159
  const store = await openTmpStore('txe-session');
153
160
 
154
161
  const addressStore = new AddressStore(store);
155
162
  const privateEventStore = new PrivateEventStore(store);
156
- const contractStore = new TXEContractStore(store);
157
163
  const noteStore = new NoteStore(store);
158
164
  const senderTaggingStore = new SenderTaggingStore(store);
159
165
  const recipientTaggingStore = new RecipientTaggingStore(store);
@@ -172,15 +178,9 @@ export class TXESession implements TXESessionStateHandler {
172
178
  noteStore,
173
179
  ]);
174
180
 
175
- // Register protocol contracts.
176
- for (const { contractClass, instance, artifact } of protocolContracts) {
177
- await contractStore.addContractArtifact(contractClass.id, artifact);
178
- await contractStore.addContractInstance(instance);
179
- }
180
-
181
181
  const archiver = new TXEArchiver(store);
182
182
  const anchorBlockStore = new AnchorBlockStore(store);
183
- const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
183
+ const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore, keyStore);
184
184
 
185
185
  const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
186
186
  const version = new Fr(await stateMachine.node.getVersion());
@@ -188,6 +188,15 @@ export class TXESession implements TXESessionStateHandler {
188
188
 
189
189
  const initialJobId = jobCoordinator.beginJob();
190
190
 
191
+ const logger = createLogger('txe:session');
192
+ const contractSyncService = new ContractSyncService(
193
+ stateMachine.node,
194
+ contractStore,
195
+ noteStore,
196
+ () => keyStore.getAccounts(),
197
+ logger,
198
+ );
199
+
191
200
  const topLevelOracleHandler = new TXEOracleTopLevelContext(
192
201
  stateMachine,
193
202
  contractStore,
@@ -200,16 +209,16 @@ export class TXESession implements TXESessionStateHandler {
200
209
  senderAddressBookStore,
201
210
  capsuleStore,
202
211
  privateEventStore,
203
- initialJobId,
204
212
  nextBlockTimestamp,
205
213
  version,
206
214
  chainId,
207
215
  new Map(),
216
+ contractSyncService,
208
217
  );
209
- await topLevelOracleHandler.txeAdvanceBlocksBy(1);
218
+ await topLevelOracleHandler.advanceBlocksBy(1);
210
219
 
211
220
  return new TXESession(
212
- createLogger('txe:session'),
221
+ logger,
213
222
  stateMachine,
214
223
  topLevelOracleHandler,
215
224
  contractStore,
@@ -227,6 +236,7 @@ export class TXESession implements TXESessionStateHandler {
227
236
  version,
228
237
  chainId,
229
238
  nextBlockTimestamp,
239
+ contractSyncService,
230
240
  );
231
241
  }
232
242
 
@@ -261,6 +271,17 @@ export class TXESession implements TXESessionStateHandler {
261
271
  }
262
272
  }
263
273
 
274
+ getCurrentJob(): string {
275
+ return this.currentJobId;
276
+ }
277
+
278
+ /** Commits the current job and begins a new one. Returns the new job ID. */
279
+ async cycleJob(): Promise<string> {
280
+ await this.jobCoordinator.commitJob(this.currentJobId);
281
+ this.currentJobId = this.jobCoordinator.beginJob();
282
+ return this.currentJobId;
283
+ }
284
+
264
285
  async enterTopLevelState() {
265
286
  switch (this.state.name) {
266
287
  case 'PRIVATE': {
@@ -284,8 +305,7 @@ export class TXESession implements TXESessionStateHandler {
284
305
  }
285
306
 
286
307
  // Commit all staged stores from the job that was just completed, then begin a new job
287
- await this.jobCoordinator.commitJob(this.currentJobId);
288
- this.currentJobId = this.jobCoordinator.beginJob();
308
+ await this.cycleJob();
289
309
 
290
310
  this.oracleHandler = new TXEOracleTopLevelContext(
291
311
  this.stateMachine,
@@ -299,11 +319,11 @@ export class TXESession implements TXESessionStateHandler {
299
319
  this.senderAddressBookStore,
300
320
  this.capsuleStore,
301
321
  this.privateEventStore,
302
- this.currentJobId,
303
322
  this.nextBlockTimestamp,
304
323
  this.version,
305
324
  this.chainId,
306
325
  this.authwits,
326
+ this.contractSyncService,
307
327
  );
308
328
 
309
329
  this.state = { name: 'TOP_LEVEL' };
@@ -323,6 +343,7 @@ export class TXESession implements TXESessionStateHandler {
323
343
 
324
344
  await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
325
345
  contractAddress,
346
+ 'ALL_SCOPES',
326
347
  );
327
348
  const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
328
349
 
@@ -339,30 +360,32 @@ export class TXESession implements TXESessionStateHandler {
339
360
  const taggingIndexCache = new ExecutionTaggingIndexCache();
340
361
 
341
362
  const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
342
- this.oracleHandler = new PrivateExecutionOracle(
343
- Fr.ZERO,
344
- new TxContext(this.chainId, this.version, GasSettings.empty()),
345
- new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
346
- anchorBlock!,
363
+ this.oracleHandler = new PrivateExecutionOracle({
364
+ argsHash: Fr.ZERO,
365
+ txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
366
+ callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
367
+ anchorBlockHeader: anchorBlock!,
347
368
  utilityExecutor,
348
- [],
349
- [],
350
- new HashedValuesCache(),
369
+ authWitnesses: [],
370
+ capsules: [],
371
+ executionCache: new HashedValuesCache(),
351
372
  noteCache,
352
373
  taggingIndexCache,
353
- this.contractStore,
354
- this.noteStore,
355
- this.keyStore,
356
- this.addressStore,
357
- this.stateMachine.node,
358
- this.senderTaggingStore,
359
- this.recipientTaggingStore,
360
- this.senderAddressBookStore,
361
- this.capsuleStore,
362
- this.privateEventStore,
363
- this.stateMachine.contractSyncService,
364
- this.currentJobId,
365
- );
374
+ contractStore: this.contractStore,
375
+ noteStore: this.noteStore,
376
+ keyStore: this.keyStore,
377
+ addressStore: this.addressStore,
378
+ aztecNode: this.stateMachine.node,
379
+ senderTaggingStore: this.senderTaggingStore,
380
+ recipientTaggingStore: this.recipientTaggingStore,
381
+ senderAddressBookStore: this.senderAddressBookStore,
382
+ capsuleService: new CapsuleService(this.capsuleStore, 'ALL_SCOPES'),
383
+ privateEventStore: this.privateEventStore,
384
+ contractSyncService: this.stateMachine.contractSyncService,
385
+ jobId: this.currentJobId,
386
+ scopes: 'ALL_SCOPES',
387
+ messageContextService: this.stateMachine.messageContextService,
388
+ });
366
389
 
367
390
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
368
391
  // data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
@@ -414,24 +437,27 @@ export class TXESession implements TXESessionStateHandler {
414
437
  this.stateMachine.node,
415
438
  anchorBlockHeader,
416
439
  this.currentJobId,
417
- ).syncNoteNullifiers(contractAddress);
440
+ ).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
418
441
 
419
- this.oracleHandler = new UtilityExecutionOracle(
442
+ this.oracleHandler = new UtilityExecutionOracle({
420
443
  contractAddress,
421
- [],
422
- [],
444
+ authWitnesses: [],
445
+ capsules: [],
423
446
  anchorBlockHeader,
424
- this.contractStore,
425
- this.noteStore,
426
- this.keyStore,
427
- this.addressStore,
428
- this.stateMachine.node,
429
- this.recipientTaggingStore,
430
- this.senderAddressBookStore,
431
- this.capsuleStore,
432
- this.privateEventStore,
433
- this.currentJobId,
434
- );
447
+ contractStore: this.contractStore,
448
+ noteStore: this.noteStore,
449
+ keyStore: this.keyStore,
450
+ addressStore: this.addressStore,
451
+ aztecNode: this.stateMachine.node,
452
+ recipientTaggingStore: this.recipientTaggingStore,
453
+ senderAddressBookStore: this.senderAddressBookStore,
454
+ capsuleService: new CapsuleService(this.capsuleStore, 'ALL_SCOPES'),
455
+ privateEventStore: this.privateEventStore,
456
+ messageContextService: this.stateMachine.messageContextService,
457
+ contractSyncService: this.contractSyncService,
458
+ jobId: this.currentJobId,
459
+ scopes: 'ALL_SCOPES',
460
+ });
435
461
 
436
462
  this.state = { name: 'UTILITY' };
437
463
  this.logger.debug(`Entered state ${this.state.name}`);
@@ -444,8 +470,8 @@ export class TXESession implements TXESessionStateHandler {
444
470
 
445
471
  // Note that while all public and private contexts do is build a single block that we then process when exiting
446
472
  // those, the top level context performs a large number of actions not captured in the following 'close' call. Among
447
- // others, it will create empty blocks (via `txeAdvanceBlocksBy` and `deploy`), create blocks with transactions via
448
- // `txePrivateCallNewFlow` and `txePublicCallNewFlow`, add accounts to PXE via `txeAddAccount`, etc. This is a
473
+ // others, it will create empty blocks (via `advanceBlocksBy` and `deploy`), create blocks with transactions via
474
+ // `privateCallNewFlow` and `publicCallNewFlow`, add accounts to PXE via `addAccount`, etc. This is a
449
475
  // slight inconsistency in the working model of this class, but is not too bad.
450
476
  // TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
451
477
  // level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
@@ -499,29 +525,32 @@ export class TXESession implements TXESessionStateHandler {
499
525
  }
500
526
 
501
527
  private utilityExecutorForContractSync(anchorBlock: any) {
502
- return async (call: FunctionCall) => {
528
+ return async (call: FunctionCall, scopes: AccessScopes) => {
503
529
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
504
530
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
505
531
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
506
532
  }
507
533
 
508
534
  try {
509
- const oracle = new UtilityExecutionOracle(
510
- call.to,
511
- [],
512
- [],
513
- anchorBlock!,
514
- this.contractStore,
515
- this.noteStore,
516
- this.keyStore,
517
- this.addressStore,
518
- this.stateMachine.node,
519
- this.recipientTaggingStore,
520
- this.senderAddressBookStore,
521
- this.capsuleStore,
522
- this.privateEventStore,
523
- this.currentJobId,
524
- );
535
+ const oracle = new UtilityExecutionOracle({
536
+ contractAddress: call.to,
537
+ authWitnesses: [],
538
+ capsules: [],
539
+ anchorBlockHeader: anchorBlock!,
540
+ contractStore: this.contractStore,
541
+ noteStore: this.noteStore,
542
+ keyStore: this.keyStore,
543
+ addressStore: this.addressStore,
544
+ aztecNode: this.stateMachine.node,
545
+ recipientTaggingStore: this.recipientTaggingStore,
546
+ senderAddressBookStore: this.senderAddressBookStore,
547
+ capsuleService: new CapsuleService(this.capsuleStore, scopes),
548
+ privateEventStore: this.privateEventStore,
549
+ messageContextService: this.stateMachine.messageContextService,
550
+ contractSyncService: this.contractSyncService,
551
+ jobId: this.currentJobId,
552
+ scopes,
553
+ });
525
554
  await new WASMSimulator()
526
555
  .executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
527
556
  .catch((err: Error) => {