@aztec/txe 0.0.1-commit.ee80a48 → 0.0.1-commit.ef17749e1

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 (52) 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 +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 +118 -50
  12. package/dest/rpc_translator.d.ts +83 -83
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +259 -154
  15. package/dest/state_machine/archiver.d.ts +1 -1
  16. package/dest/state_machine/archiver.d.ts.map +1 -1
  17. package/dest/state_machine/archiver.js +2 -0
  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 +5 -5
  22. package/dest/state_machine/index.d.ts.map +1 -1
  23. package/dest/state_machine/index.js +15 -10
  24. package/dest/state_machine/mock_epoch_cache.d.ts +3 -1
  25. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  26. package/dest/state_machine/mock_epoch_cache.js +4 -0
  27. package/dest/txe_session.d.ts +9 -6
  28. package/dest/txe_session.d.ts.map +1 -1
  29. package/dest/txe_session.js +82 -23
  30. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  31. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  32. package/dest/util/txe_public_contract_data_source.js +5 -22
  33. package/dest/utils/block_creation.d.ts +1 -1
  34. package/dest/utils/block_creation.d.ts.map +1 -1
  35. package/dest/utils/block_creation.js +3 -1
  36. package/package.json +15 -15
  37. package/src/index.ts +89 -52
  38. package/src/oracle/interfaces.ts +32 -31
  39. package/src/oracle/txe_oracle_public_context.ts +12 -12
  40. package/src/oracle/txe_oracle_top_level_context.ts +121 -103
  41. package/src/rpc_translator.ts +266 -157
  42. package/src/state_machine/archiver.ts +2 -0
  43. package/src/state_machine/dummy_p2p_client.ts +40 -22
  44. package/src/state_machine/index.ts +25 -9
  45. package/src/state_machine/mock_epoch_cache.ts +5 -0
  46. package/src/txe_session.ts +85 -71
  47. package/src/util/txe_public_contract_data_source.ts +10 -36
  48. package/src/utils/block_creation.ts +3 -1
  49. package/dest/util/txe_contract_store.d.ts +0 -12
  50. package/dest/util/txe_contract_store.d.ts.map +0 -1
  51. package/dest/util/txe_contract_store.js +0 -22
  52. package/src/util/txe_contract_store.ts +0 -36
@@ -59,6 +59,8 @@ export class TXEArchiver extends ArchiverDataSourceBase {
59
59
  if (!checkpointedBlock) {
60
60
  throw new Error(`L2Tips requested from TXE Archiver but no checkpointed block found for block number ${number}`);
61
61
  }
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.
62
64
  const checkpoint = await this.store.getRangeOfCheckpoints(CheckpointNumber.fromBlockNumber(number), 1);
63
65
  if (checkpoint.length === 0) {
64
66
  throw new Error(`L2Tips requested from TXE Archiver but no checkpoint found for block number ${number}`);
@@ -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
  }
@@ -3,8 +3,7 @@ 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 { AztecAsyncKVStore } from '@aztec/kv-store';
7
- import { AnchorBlockStore } from '@aztec/pxe/server';
6
+ import { type AnchorBlockStore, type ContractStore, ContractSyncService, type NoteStore } from '@aztec/pxe/server';
8
7
  import { L2Block } from '@aztec/stdlib/block';
9
8
  import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
10
9
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
@@ -26,13 +25,16 @@ export class TXEStateMachine {
26
25
  public synchronizer: TXESynchronizer,
27
26
  public archiver: TXEArchiver,
28
27
  public anchorBlockStore: AnchorBlockStore,
28
+ public contractSyncService: ContractSyncService,
29
29
  ) {}
30
30
 
31
- public static async create(db: AztecAsyncKVStore) {
32
- const archiver = new TXEArchiver(db);
31
+ public static async create(
32
+ archiver: TXEArchiver,
33
+ anchorBlockStore: AnchorBlockStore,
34
+ contractStore: ContractStore,
35
+ noteStore: NoteStore,
36
+ ) {
33
37
  const synchronizer = await TXESynchronizer.create();
34
- const anchorBlockStore = new AnchorBlockStore(db);
35
-
36
38
  const aztecNodeConfig = {} as AztecNodeConfig;
37
39
 
38
40
  const log = createLogger('txe_node');
@@ -48,6 +50,7 @@ export class TXEStateMachine {
48
50
  undefined,
49
51
  undefined,
50
52
  undefined,
53
+ undefined,
51
54
  VERSION,
52
55
  CHAIN_ID,
53
56
  new TXEGlobalVariablesBuilder(),
@@ -58,11 +61,21 @@ export class TXEStateMachine {
58
61
  log,
59
62
  );
60
63
 
61
- 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);
62
72
  }
63
73
 
64
74
  public async handleL2Block(block: L2Block) {
65
- // Create a checkpoint from the block manually
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);
66
79
  const checkpoint = new Checkpoint(
67
80
  block.archive,
68
81
  CheckpointHeader.from({
@@ -79,7 +92,7 @@ export class TXEStateMachine {
79
92
  totalManaUsed: block.header.totalManaUsed,
80
93
  }),
81
94
  [block],
82
- CheckpointNumber.fromBlockNumber(block.number),
95
+ checkpointNumber,
83
96
  );
84
97
 
85
98
  const publishedCheckpoint = new PublishedCheckpoint(
@@ -91,6 +104,9 @@ export class TXEStateMachine {
91
104
  ),
92
105
  [],
93
106
  );
107
+ // Wipe contract sync cache when anchor block changes (mirrors BlockSynchronizer behavior)
108
+ this.contractSyncService.wipe();
109
+
94
110
  await Promise.all([
95
111
  this.synchronizer.handleL2Block(block),
96
112
  this.archiver.addCheckpoints([publishedCheckpoint], undefined),
@@ -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.
@@ -64,4 +65,8 @@ export class MockEpochCache implements EpochCacheInterface {
64
65
  filterInCommittee(_slot: SlotTag, _validators: EthAddress[]): Promise<EthAddress[]> {
65
66
  return Promise.resolve([]);
66
67
  }
68
+
69
+ getL1Constants(): L1RollupConstants {
70
+ return EmptyL1RollupConstants;
71
+ }
67
72
  }
@@ -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,12 +152,11 @@ 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
160
  const noteStore = new NoteStore(store);
156
161
  const senderTaggingStore = new SenderTaggingStore(store);
157
162
  const recipientTaggingStore = new RecipientTaggingStore(store);
@@ -170,13 +175,9 @@ export class TXESession implements TXESessionStateHandler {
170
175
  noteStore,
171
176
  ]);
172
177
 
173
- // Register protocol contracts.
174
- for (const { contractClass, instance, artifact } of protocolContracts) {
175
- await contractStore.addContractArtifact(contractClass.id, artifact);
176
- await contractStore.addContractInstance(instance);
177
- }
178
-
179
- 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);
180
181
 
181
182
  const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
182
183
  const version = new Fr(await stateMachine.node.getVersion());
@@ -196,13 +197,12 @@ export class TXESession implements TXESessionStateHandler {
196
197
  senderAddressBookStore,
197
198
  capsuleStore,
198
199
  privateEventStore,
199
- initialJobId,
200
200
  nextBlockTimestamp,
201
201
  version,
202
202
  chainId,
203
203
  new Map(),
204
204
  );
205
- await topLevelOracleHandler.txeAdvanceBlocksBy(1);
205
+ await topLevelOracleHandler.advanceBlocksBy(1);
206
206
 
207
207
  return new TXESession(
208
208
  createLogger('txe:session'),
@@ -257,6 +257,17 @@ export class TXESession implements TXESessionStateHandler {
257
257
  }
258
258
  }
259
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
+
260
271
  async enterTopLevelState() {
261
272
  switch (this.state.name) {
262
273
  case 'PRIVATE': {
@@ -280,8 +291,7 @@ export class TXESession implements TXESessionStateHandler {
280
291
  }
281
292
 
282
293
  // Commit all staged stores from the job that was just completed, then begin a new job
283
- await this.jobCoordinator.commitJob(this.currentJobId);
284
- this.currentJobId = this.jobCoordinator.beginJob();
294
+ await this.cycleJob();
285
295
 
286
296
  this.oracleHandler = new TXEOracleTopLevelContext(
287
297
  this.stateMachine,
@@ -295,7 +305,6 @@ export class TXESession implements TXESessionStateHandler {
295
305
  this.senderAddressBookStore,
296
306
  this.capsuleStore,
297
307
  this.privateEventStore,
298
- this.currentJobId,
299
308
  this.nextBlockTimestamp,
300
309
  this.version,
301
310
  this.chainId,
@@ -319,6 +328,7 @@ export class TXESession implements TXESessionStateHandler {
319
328
 
320
329
  await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
321
330
  contractAddress,
331
+ 'ALL_SCOPES',
322
332
  );
323
333
  const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
324
334
 
@@ -335,29 +345,31 @@ export class TXESession implements TXESessionStateHandler {
335
345
  const taggingIndexCache = new ExecutionTaggingIndexCache();
336
346
 
337
347
  const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
338
- this.oracleHandler = new PrivateExecutionOracle(
339
- Fr.ZERO,
340
- new TxContext(this.chainId, this.version, GasSettings.empty()),
341
- new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
342
- 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!,
343
353
  utilityExecutor,
344
- [],
345
- [],
346
- new HashedValuesCache(),
354
+ authWitnesses: [],
355
+ capsules: [],
356
+ executionCache: new HashedValuesCache(),
347
357
  noteCache,
348
358
  taggingIndexCache,
349
- this.contractStore,
350
- this.noteStore,
351
- this.keyStore,
352
- this.addressStore,
353
- this.stateMachine.node,
354
- this.senderTaggingStore,
355
- this.recipientTaggingStore,
356
- this.senderAddressBookStore,
357
- this.capsuleStore,
358
- this.privateEventStore,
359
- this.currentJobId,
360
- );
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
+ });
361
373
 
362
374
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
363
375
  // data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
@@ -409,24 +421,25 @@ export class TXESession implements TXESessionStateHandler {
409
421
  this.stateMachine.node,
410
422
  anchorBlockHeader,
411
423
  this.currentJobId,
412
- ).syncNoteNullifiers(contractAddress);
424
+ ).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
413
425
 
414
- this.oracleHandler = new UtilityExecutionOracle(
426
+ this.oracleHandler = new UtilityExecutionOracle({
415
427
  contractAddress,
416
- [],
417
- [],
428
+ authWitnesses: [],
429
+ capsules: [],
418
430
  anchorBlockHeader,
419
- this.contractStore,
420
- this.noteStore,
421
- this.keyStore,
422
- this.addressStore,
423
- this.stateMachine.node,
424
- this.recipientTaggingStore,
425
- this.senderAddressBookStore,
426
- this.capsuleStore,
427
- this.privateEventStore,
428
- this.currentJobId,
429
- );
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
+ });
430
443
 
431
444
  this.state = { name: 'UTILITY' };
432
445
  this.logger.debug(`Entered state ${this.state.name}`);
@@ -439,8 +452,8 @@ export class TXESession implements TXESessionStateHandler {
439
452
 
440
453
  // Note that while all public and private contexts do is build a single block that we then process when exiting
441
454
  // those, the top level context performs a large number of actions not captured in the following 'close' call. Among
442
- // others, it will create empty blocks (via `txeAdvanceBlocksBy` and `deploy`), create blocks with transactions via
443
- // `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
444
457
  // slight inconsistency in the working model of this class, but is not too bad.
445
458
  // TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
446
459
  // level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
@@ -494,29 +507,30 @@ export class TXESession implements TXESessionStateHandler {
494
507
  }
495
508
 
496
509
  private utilityExecutorForContractSync(anchorBlock: any) {
497
- return async (call: FunctionCall) => {
510
+ return async (call: FunctionCall, scopes: AccessScopes) => {
498
511
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
499
512
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
500
513
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
501
514
  }
502
515
 
503
516
  try {
504
- const oracle = new UtilityExecutionOracle(
505
- call.to,
506
- [],
507
- [],
508
- anchorBlock!,
509
- this.contractStore,
510
- this.noteStore,
511
- this.keyStore,
512
- this.addressStore,
513
- this.stateMachine.node,
514
- this.recipientTaggingStore,
515
- this.senderAddressBookStore,
516
- this.capsuleStore,
517
- this.privateEventStore,
518
- this.currentJobId,
519
- );
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
+ });
520
534
  await new WASMSimulator()
521
535
  .executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
522
536
  .catch((err: Error) => {
@@ -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,24 @@ 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,
24
+ id: contractClass.id,
25
+ artifactHash: contractClass.artifactHash,
26
+ packedBytecode: contractClass.packedBytecode,
27
+ privateFunctionsRoot: contractClass.privateFunctionsRoot,
28
+ version: contractClass.version,
55
29
  privateFunctions: [],
56
30
  utilityFunctions: [],
57
31
  };
58
32
  }
59
33
 
60
34
  async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
61
- const contractClass = await this.contractStore.getContractClass(id);
62
- return contractClass && computePublicBytecodeCommitment(contractClass.packedBytecode);
35
+ const contractClass = await this.contractStore.getContractClassWithPreimage(id);
36
+ return contractClass?.publicBytecodeCommitment;
63
37
  }
64
38
 
65
39
  async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
@@ -87,7 +87,9 @@ export async function makeTXEBlock(
87
87
  const newArchiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
88
88
  const newArchive = new AppendOnlyTreeSnapshot(new Fr(newArchiveInfo.root), Number(newArchiveInfo.size));
89
89
 
90
- // L2Block requires checkpointNumber and indexWithinCheckpoint
90
+ // L2Block requires checkpointNumber and indexWithinCheckpoint.
91
+ // TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
92
+ // This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
91
93
  const checkpointNumber = CheckpointNumber.fromBlockNumber(globalVariables.blockNumber);
92
94
  const indexWithinCheckpoint = IndexWithinCheckpoint(0);
93
95
 
@@ -1,12 +0,0 @@
1
- import type { ContractArtifact } from '@aztec/aztec.js/abi';
2
- import { Fr } from '@aztec/aztec.js/fields';
3
- import { ContractStore } from '@aztec/pxe/server';
4
- export type ContractArtifactWithHash = ContractArtifact & {
5
- artifactHash: Fr;
6
- };
7
- export declare class TXEContractStore extends ContractStore {
8
- #private;
9
- addContractArtifact(id: Fr, artifact: ContractArtifact | ContractArtifactWithHash): Promise<void>;
10
- getContractArtifact(contractClassId: Fr): Promise<ContractArtifact | ContractArtifactWithHash | undefined>;
11
- }
12
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhlX2NvbnRyYWN0X3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbC90eGVfY29udHJhY3Rfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUM1RCxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFDNUMsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBRWxELE1BQU0sTUFBTSx3QkFBd0IsR0FBRyxnQkFBZ0IsR0FBRztJQUFFLFlBQVksRUFBRSxFQUFFLENBQUE7Q0FBRSxDQUFDO0FBTy9FLHFCQUFhLGdCQUFpQixTQUFRLGFBQWE7O0lBRzNCLG1CQUFtQixDQUN2QyxFQUFFLEVBQUUsRUFBRSxFQUNOLFFBQVEsRUFBRSxnQkFBZ0IsR0FBRyx3QkFBd0IsR0FDcEQsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUtmO0lBRXFCLG1CQUFtQixDQUN2QyxlQUFlLEVBQUUsRUFBRSxHQUNsQixPQUFPLENBQUMsZ0JBQWdCLEdBQUcsd0JBQXdCLEdBQUcsU0FBUyxDQUFDLENBUWxFO0NBQ0YifQ==
@@ -1 +0,0 @@
1
- {"version":3,"file":"txe_contract_store.d.ts","sourceRoot":"","sources":["../../src/util/txe_contract_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,MAAM,wBAAwB,GAAG,gBAAgB,GAAG;IAAE,YAAY,EAAE,EAAE,CAAA;CAAE,CAAC;AAO/E,qBAAa,gBAAiB,SAAQ,aAAa;;IAG3B,mBAAmB,CACvC,EAAE,EAAE,EAAE,EACN,QAAQ,EAAE,gBAAgB,GAAG,wBAAwB,GACpD,OAAO,CAAC,IAAI,CAAC,CAKf;IAEqB,mBAAmB,CACvC,eAAe,EAAE,EAAE,GAClB,OAAO,CAAC,gBAAgB,GAAG,wBAAwB,GAAG,SAAS,CAAC,CAQlE;CACF"}
@@ -1,22 +0,0 @@
1
- import { Fr } from '@aztec/aztec.js/fields';
2
- import { ContractStore } from '@aztec/pxe/server';
3
- /*
4
- * A contract store that stores contract artifacts with their hashes. Since
5
- * TXE typically deploys the same contract again and again for multiple tests, caching
6
- * the *very* expensive artifact hash computation improves testing speed significantly.
7
- */ export class TXEContractStore extends ContractStore {
8
- #artifactHashes = new Map();
9
- async addContractArtifact(id, artifact) {
10
- if ('artifactHash' in artifact) {
11
- this.#artifactHashes.set(id.toString(), artifact.artifactHash.toBuffer());
12
- }
13
- await super.addContractArtifact(id, artifact);
14
- }
15
- async getContractArtifact(contractClassId) {
16
- const artifact = await super.getContractArtifact(contractClassId);
17
- if (artifact && this.#artifactHashes.has(contractClassId.toString())) {
18
- artifact.artifactHash = Fr.fromBuffer(this.#artifactHashes.get(contractClassId.toString()));
19
- }
20
- return artifact;
21
- }
22
- }