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

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 (80) hide show
  1. package/dest/constants.d.ts +3 -0
  2. package/dest/constants.d.ts.map +1 -0
  3. package/dest/constants.js +2 -0
  4. package/dest/index.d.ts +1 -1
  5. package/dest/index.d.ts.map +1 -1
  6. package/dest/index.js +3 -2
  7. package/dest/oracle/interfaces.d.ts +10 -7
  8. package/dest/oracle/interfaces.d.ts.map +1 -1
  9. package/dest/oracle/txe_oracle_public_context.d.ts +6 -6
  10. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_public_context.js +7 -8
  12. package/dest/oracle/txe_oracle_top_level_context.d.ts +22 -12
  13. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  14. package/dest/oracle/txe_oracle_top_level_context.js +108 -71
  15. package/dest/rpc_translator.d.ts +24 -12
  16. package/dest/rpc_translator.d.ts.map +1 -1
  17. package/dest/rpc_translator.js +98 -42
  18. package/dest/state_machine/archiver.d.ts +21 -52
  19. package/dest/state_machine/archiver.d.ts.map +1 -1
  20. package/dest/state_machine/archiver.js +61 -94
  21. package/dest/state_machine/dummy_p2p_client.d.ts +8 -7
  22. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  23. package/dest/state_machine/dummy_p2p_client.js +16 -11
  24. package/dest/state_machine/global_variable_builder.d.ts +6 -5
  25. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  26. package/dest/state_machine/global_variable_builder.js +13 -1
  27. package/dest/state_machine/index.d.ts +5 -5
  28. package/dest/state_machine/index.d.ts.map +1 -1
  29. package/dest/state_machine/index.js +31 -19
  30. package/dest/state_machine/mock_epoch_cache.d.ts +7 -6
  31. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  32. package/dest/state_machine/mock_epoch_cache.js +10 -7
  33. package/dest/state_machine/synchronizer.d.ts +3 -2
  34. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  35. package/dest/state_machine/synchronizer.js +5 -4
  36. package/dest/txe_session.d.ts +21 -13
  37. package/dest/txe_session.d.ts.map +1 -1
  38. package/dest/txe_session.js +94 -47
  39. package/dest/util/encoding.d.ts +618 -19
  40. package/dest/util/encoding.d.ts.map +1 -1
  41. package/dest/util/encoding.js +1 -1
  42. package/dest/util/txe_account_store.d.ts +10 -0
  43. package/dest/util/txe_account_store.d.ts.map +1 -0
  44. package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
  45. package/dest/util/txe_contract_store.d.ts +12 -0
  46. package/dest/util/txe_contract_store.d.ts.map +1 -0
  47. package/dest/util/{txe_contract_data_provider.js → txe_contract_store.js} +3 -3
  48. package/dest/util/txe_public_contract_data_source.d.ts +7 -6
  49. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  50. package/dest/util/txe_public_contract_data_source.js +11 -11
  51. package/dest/utils/block_creation.d.ts +21 -6
  52. package/dest/utils/block_creation.d.ts.map +1 -1
  53. package/dest/utils/block_creation.js +36 -4
  54. package/dest/utils/tx_effect_creation.d.ts +3 -3
  55. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  56. package/dest/utils/tx_effect_creation.js +4 -7
  57. package/package.json +18 -18
  58. package/src/constants.ts +3 -0
  59. package/src/index.ts +15 -12
  60. package/src/oracle/interfaces.ts +9 -6
  61. package/src/oracle/txe_oracle_public_context.ts +9 -14
  62. package/src/oracle/txe_oracle_top_level_context.ts +159 -98
  63. package/src/rpc_translator.ts +128 -50
  64. package/src/state_machine/archiver.ts +57 -114
  65. package/src/state_machine/dummy_p2p_client.ts +21 -14
  66. package/src/state_machine/global_variable_builder.ts +21 -4
  67. package/src/state_machine/index.ts +40 -17
  68. package/src/state_machine/mock_epoch_cache.ts +10 -11
  69. package/src/state_machine/synchronizer.ts +6 -5
  70. package/src/txe_session.ts +192 -81
  71. package/src/util/encoding.ts +1 -1
  72. package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
  73. package/src/util/{txe_contract_data_provider.ts → txe_contract_store.ts} +3 -3
  74. package/src/util/txe_public_contract_data_source.ts +13 -12
  75. package/src/utils/block_creation.ts +47 -15
  76. package/src/utils/tx_effect_creation.ts +5 -12
  77. package/dest/util/txe_account_data_provider.d.ts +0 -10
  78. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  79. package/dest/util/txe_contract_data_provider.d.ts +0 -12
  80. package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
@@ -1,21 +1,38 @@
1
- import type { SlotNumber } from '@aztec/foundation/branded-types';
1
+ import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
2
2
  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 GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
6
+ import { type CheckpointGlobalVariables, type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
7
7
 
8
8
  export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
9
- public getCurrentBaseFees(): Promise<GasFees> {
9
+ public getCurrentMinFees(): Promise<GasFees> {
10
10
  return Promise.resolve(new GasFees(0, 0));
11
11
  }
12
12
 
13
13
  public buildGlobalVariables(
14
- _blockNumber: number,
14
+ _blockNumber: BlockNumber,
15
15
  _coinbase: EthAddress,
16
16
  _feeRecipient: AztecAddress,
17
17
  _slotNumber?: SlotNumber,
18
18
  ): Promise<GlobalVariables> {
19
19
  return Promise.resolve(makeGlobalVariables());
20
20
  }
21
+
22
+ public buildCheckpointGlobalVariables(
23
+ _coinbase: EthAddress,
24
+ _feeRecipient: AztecAddress,
25
+ _slotNumber: SlotNumber,
26
+ ): Promise<CheckpointGlobalVariables> {
27
+ const vars = makeGlobalVariables();
28
+ return Promise.resolve({
29
+ chainId: vars.chainId,
30
+ version: vars.version,
31
+ slotNumber: vars.slotNumber,
32
+ timestamp: vars.timestamp,
33
+ coinbase: vars.coinbase,
34
+ feeRecipient: vars.feeRecipient,
35
+ gasFees: vars.gasFees,
36
+ });
37
+ }
21
38
  }
@@ -1,10 +1,14 @@
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
6
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
5
- import { SyncDataProvider } from '@aztec/pxe/server';
6
- import { type L2Block, PublishedL2Block } from '@aztec/stdlib/block';
7
+ import { AnchorBlockStore } from '@aztec/pxe/server';
8
+ import { L2Block } from '@aztec/stdlib/block';
9
+ import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
7
10
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
11
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
8
12
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
9
13
 
10
14
  import { TXEArchiver } from './archiver.js';
@@ -21,13 +25,13 @@ export class TXEStateMachine {
21
25
  public node: AztecNode,
22
26
  public synchronizer: TXESynchronizer,
23
27
  public archiver: TXEArchiver,
24
- public syncDataProvider: SyncDataProvider,
28
+ public anchorBlockStore: AnchorBlockStore,
25
29
  ) {}
26
30
 
27
31
  public static async create(db: AztecAsyncKVStore) {
28
32
  const archiver = new TXEArchiver(db);
29
33
  const synchronizer = await TXESynchronizer.create();
30
- const syncDataProvider = new SyncDataProvider(db);
34
+ const anchorBlockStore = new AnchorBlockStore(db);
31
35
 
32
36
  const aztecNodeConfig = {} as AztecNodeConfig;
33
37
 
@@ -54,24 +58,43 @@ export class TXEStateMachine {
54
58
  log,
55
59
  );
56
60
 
57
- return new this(node, synchronizer, archiver, syncDataProvider);
61
+ return new this(node, synchronizer, archiver, anchorBlockStore);
58
62
  }
59
63
 
60
64
  public async handleL2Block(block: L2Block) {
65
+ // Create a checkpoint from the block manually
66
+ const checkpoint = new Checkpoint(
67
+ block.archive,
68
+ CheckpointHeader.from({
69
+ lastArchiveRoot: block.header.lastArchive.root,
70
+ inHash: Fr.ZERO,
71
+ blobsHash: Fr.ZERO,
72
+ blockHeadersHash: Fr.ZERO,
73
+ epochOutHash: Fr.ZERO,
74
+ slotNumber: block.header.globalVariables.slotNumber,
75
+ timestamp: block.header.globalVariables.timestamp,
76
+ coinbase: block.header.globalVariables.coinbase,
77
+ feeRecipient: block.header.globalVariables.feeRecipient,
78
+ gasFees: block.header.globalVariables.gasFees,
79
+ totalManaUsed: block.header.totalManaUsed,
80
+ }),
81
+ [block],
82
+ CheckpointNumber.fromBlockNumber(block.number),
83
+ );
84
+
85
+ const publishedCheckpoint = new PublishedCheckpoint(
86
+ checkpoint,
87
+ new L1PublishedData(
88
+ BigInt(block.header.globalVariables.blockNumber),
89
+ block.header.globalVariables.timestamp,
90
+ block.header.globalVariables.blockNumber.toString(),
91
+ ),
92
+ [],
93
+ );
61
94
  await Promise.all([
62
95
  this.synchronizer.handleL2Block(block),
63
- this.archiver.addBlocks([
64
- PublishedL2Block.fromFields({
65
- block,
66
- l1: {
67
- blockHash: block.header.globalVariables.blockNumber.toString(),
68
- blockNumber: BigInt(block.header.globalVariables.blockNumber),
69
- timestamp: block.header.globalVariables.timestamp,
70
- },
71
- attestations: [],
72
- }),
73
- ]),
74
- this.syncDataProvider.setHeader(block.getBlockHeader()),
96
+ this.archiver.addCheckpoints([publishedCheckpoint], undefined),
97
+ this.anchorBlockStore.setHeader(block.header),
75
98
  ]);
76
99
  }
77
100
  }
@@ -12,14 +12,16 @@ export class MockEpochCache implements EpochCacheInterface {
12
12
  committee: undefined,
13
13
  seed: 0n,
14
14
  epoch: EpochNumber.ZERO,
15
+ isEscapeHatchOpen: false,
15
16
  });
16
17
  }
17
18
 
18
- getEpochAndSlotNow(): EpochAndSlot {
19
+ getEpochAndSlotNow(): EpochAndSlot & { nowMs: bigint } {
19
20
  return {
20
21
  epoch: EpochNumber.ZERO,
21
22
  slot: SlotNumber(0),
22
23
  ts: 0n,
24
+ nowMs: 0n,
23
25
  };
24
26
  }
25
27
 
@@ -40,18 +42,15 @@ export class MockEpochCache implements EpochCacheInterface {
40
42
  return 0n;
41
43
  }
42
44
 
43
- getProposerAttesterAddressInCurrentOrNextSlot(): Promise<{
44
- currentProposer: EthAddress | undefined;
45
- nextProposer: EthAddress | undefined;
46
- currentSlot: SlotNumber;
47
- nextSlot: SlotNumber;
48
- }> {
49
- return Promise.resolve({
50
- currentProposer: undefined,
51
- nextProposer: undefined,
45
+ getCurrentAndNextSlot(): { currentSlot: SlotNumber; nextSlot: SlotNumber } {
46
+ return {
52
47
  currentSlot: SlotNumber(0),
53
48
  nextSlot: SlotNumber(0),
54
- });
49
+ };
50
+ }
51
+
52
+ getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined> {
53
+ return Promise.resolve(undefined);
55
54
  }
56
55
 
57
56
  isInCommittee(_slot: SlotTag, _validator: EthAddress): Promise<boolean> {
@@ -1,5 +1,6 @@
1
1
  import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import type { L2Block } from '@aztec/stdlib/block';
4
5
  import type {
5
6
  MerkleTreeReadOperations,
@@ -12,7 +13,7 @@ import { NativeWorldStateService } from '@aztec/world-state/native';
12
13
 
13
14
  export class TXESynchronizer implements WorldStateSynchronizer {
14
15
  // This works when set to 1 as well.
15
- private blockNumber = 0;
16
+ private blockNumber = BlockNumber.ZERO;
16
17
 
17
18
  constructor(public nativeWorldStateService: NativeWorldStateService) {}
18
19
 
@@ -37,7 +38,7 @@ export class TXESynchronizer implements WorldStateSynchronizer {
37
38
  * @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
38
39
  * @returns A promise that resolves with the block number the world state was synced to
39
40
  */
40
- public syncImmediate(_minBlockNumber?: number, _skipThrowIfTargetNotReached?: boolean): Promise<number> {
41
+ public syncImmediate(_minBlockNumber?: BlockNumber, _skipThrowIfTargetNotReached?: boolean): Promise<BlockNumber> {
41
42
  return Promise.resolve(this.blockNumber);
42
43
  }
43
44
 
@@ -48,12 +49,12 @@ export class TXESynchronizer implements WorldStateSynchronizer {
48
49
 
49
50
  /** Forks the world state at the given block number, defaulting to the latest one. */
50
51
  public fork(block?: number): Promise<MerkleTreeWriteOperations> {
51
- return this.nativeWorldStateService.fork(block);
52
+ return this.nativeWorldStateService.fork(block ? BlockNumber(block) : undefined);
52
53
  }
53
54
 
54
55
  /** Gets a handle that allows reading the state as it was at the given block number. */
55
56
  public getSnapshot(blockNumber: number): MerkleTreeReadOperations {
56
- return this.nativeWorldStateService.getSnapshot(blockNumber);
57
+ return this.nativeWorldStateService.getSnapshot(BlockNumber(blockNumber));
57
58
  }
58
59
 
59
60
  /** Backups the db to the target path. */
@@ -1,15 +1,19 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
4
  import { KeyStore } from '@aztec/key-store';
4
5
  import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
5
6
  import type { ProtocolContract } from '@aztec/protocol-contracts';
6
7
  import {
7
- AddressDataProvider,
8
- CapsuleDataProvider,
9
- NoteDataProvider,
10
- PXEOracleInterface,
11
- PrivateEventDataProvider,
12
- TaggingDataProvider,
8
+ AddressStore,
9
+ CapsuleStore,
10
+ JobCoordinator,
11
+ NoteService,
12
+ NoteStore,
13
+ PrivateEventStore,
14
+ RecipientTaggingStore,
15
+ SenderAddressBookStore,
16
+ SenderTaggingStore,
13
17
  } from '@aztec/pxe/server';
14
18
  import {
15
19
  ExecutionNoteCache,
@@ -17,35 +21,39 @@ import {
17
21
  HashedValuesCache,
18
22
  type IPrivateExecutionOracle,
19
23
  type IUtilityExecutionOracle,
24
+ Oracle,
20
25
  PrivateExecutionOracle,
21
26
  UtilityExecutionOracle,
22
27
  } from '@aztec/pxe/simulator';
23
- import { FunctionSelector } from '@aztec/stdlib/abi';
28
+ import {
29
+ ExecutionError,
30
+ WASMSimulator,
31
+ createSimulationError,
32
+ extractCallStack,
33
+ resolveAssertionMessageFromError,
34
+ toACVMWitness,
35
+ } from '@aztec/simulator/client';
36
+ import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
24
37
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
25
38
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
26
- import { Body, L2Block } from '@aztec/stdlib/block';
27
39
  import { GasSettings } from '@aztec/stdlib/gas';
28
40
  import { computeProtocolNullifier } from '@aztec/stdlib/hash';
29
41
  import { PrivateContextInputs } from '@aztec/stdlib/kernel';
30
- import { makeAppendOnlyTreeSnapshot, makeGlobalVariables } from '@aztec/stdlib/testing';
42
+ import { makeGlobalVariables } from '@aztec/stdlib/testing';
31
43
  import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
32
- import type { UInt32 } from '@aztec/stdlib/types';
33
44
 
34
45
  import { z } from 'zod';
35
46
 
47
+ import { DEFAULT_ADDRESS } from './constants.js';
36
48
  import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
37
49
  import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
38
50
  import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
39
51
  import { RPCTranslator } from './rpc_translator.js';
40
52
  import { TXEStateMachine } from './state_machine/index.js';
41
53
  import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
42
- import { TXEAccountDataProvider } from './util/txe_account_data_provider.js';
43
- import { TXEContractDataProvider } from './util/txe_contract_data_provider.js';
44
- import {
45
- getSingleTxBlockRequestHash,
46
- insertTxEffectIntoWorldTrees,
47
- makeTXEBlockHeader,
48
- } from './utils/block_creation.js';
54
+ import { TXEAccountStore } from './util/txe_account_store.js';
55
+ import { TXEContractStore } from './util/txe_contract_store.js';
56
+ import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
49
57
  import { makeTxEffect } from './utils/tx_effect_creation.js';
50
58
 
51
59
  /**
@@ -67,7 +75,6 @@ type SessionState =
67
75
  | {
68
76
  name: 'PRIVATE';
69
77
  nextBlockGlobalVariables: GlobalVariables;
70
- protocolNullifier: Fr;
71
78
  noteCache: ExecutionNoteCache;
72
79
  taggingIndexCache: ExecutionTaggingIndexCache;
73
80
  }
@@ -102,12 +109,10 @@ export type TXEOracleFunctionName = Exclude<
102
109
  export interface TXESessionStateHandler {
103
110
  enterTopLevelState(): Promise<void>;
104
111
  enterPublicState(contractAddress?: AztecAddress): Promise<void>;
105
- enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: UInt32): Promise<PrivateContextInputs>;
112
+ enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
106
113
  enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
107
114
  }
108
115
 
109
- const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
110
-
111
116
  /**
112
117
  * A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
113
118
  * state, etc., independent of all other tests running in parallel.
@@ -124,32 +129,51 @@ export class TXESession implements TXESessionStateHandler {
124
129
  | IPrivateExecutionOracle
125
130
  | IAvmExecutionOracle
126
131
  | ITxeExecutionOracle,
127
- private contractDataProvider: TXEContractDataProvider,
132
+ private contractStore: TXEContractStore,
133
+ private noteStore: NoteStore,
128
134
  private keyStore: KeyStore,
129
- private addressDataProvider: AddressDataProvider,
130
- private accountDataProvider: TXEAccountDataProvider,
135
+ private addressStore: AddressStore,
136
+ private accountStore: TXEAccountStore,
137
+ private senderTaggingStore: SenderTaggingStore,
138
+ private recipientTaggingStore: RecipientTaggingStore,
139
+ private senderAddressBookStore: SenderAddressBookStore,
140
+ private capsuleStore: CapsuleStore,
141
+ private privateEventStore: PrivateEventStore,
142
+ private jobCoordinator: JobCoordinator,
143
+ private currentJobId: string,
131
144
  private chainId: Fr,
132
145
  private version: Fr,
133
146
  private nextBlockTimestamp: bigint,
134
- private pxeOracleInterface: PXEOracleInterface,
135
147
  ) {}
136
148
 
137
149
  static async init(protocolContracts: ProtocolContract[]) {
138
150
  const store = await openTmpStore('txe-session');
139
151
 
140
- const addressDataProvider = new AddressDataProvider(store);
141
- const privateEventDataProvider = new PrivateEventDataProvider(store);
142
- const contractDataProvider = new TXEContractDataProvider(store);
143
- const noteDataProvider = await NoteDataProvider.create(store);
144
- const taggingDataProvider = new TaggingDataProvider(store);
145
- const capsuleDataProvider = new CapsuleDataProvider(store);
152
+ const addressStore = new AddressStore(store);
153
+ const privateEventStore = new PrivateEventStore(store);
154
+ const contractStore = new TXEContractStore(store);
155
+ const noteStore = new NoteStore(store);
156
+ const senderTaggingStore = new SenderTaggingStore(store);
157
+ const recipientTaggingStore = new RecipientTaggingStore(store);
158
+ const senderAddressBookStore = new SenderAddressBookStore(store);
159
+ const capsuleStore = new CapsuleStore(store);
146
160
  const keyStore = new KeyStore(store);
147
- const accountDataProvider = new TXEAccountDataProvider(store);
161
+ const accountStore = new TXEAccountStore(store);
162
+
163
+ // Create job coordinator and register staged stores
164
+ const jobCoordinator = new JobCoordinator(store);
165
+ jobCoordinator.registerStores([
166
+ capsuleStore,
167
+ senderTaggingStore,
168
+ recipientTaggingStore,
169
+ privateEventStore,
170
+ noteStore,
171
+ ]);
148
172
 
149
173
  // Register protocol contracts.
150
174
  for (const { contractClass, instance, artifact } of protocolContracts) {
151
- await contractDataProvider.addContractArtifact(contractClass.id, artifact);
152
- await contractDataProvider.addContractInstance(instance);
175
+ await contractStore.addContractArtifact(contractClass.id, artifact);
176
+ await contractStore.addContractInstance(instance);
153
177
  }
154
178
 
155
179
  const stateMachine = await TXEStateMachine.create(store);
@@ -158,25 +182,21 @@ export class TXESession implements TXESessionStateHandler {
158
182
  const version = new Fr(await stateMachine.node.getVersion());
159
183
  const chainId = new Fr(await stateMachine.node.getChainId());
160
184
 
161
- const pxeOracleInterface = new PXEOracleInterface(
162
- stateMachine.node,
163
- keyStore,
164
- contractDataProvider,
165
- noteDataProvider,
166
- capsuleDataProvider,
167
- stateMachine.syncDataProvider,
168
- taggingDataProvider,
169
- addressDataProvider,
170
- privateEventDataProvider,
171
- );
185
+ const initialJobId = jobCoordinator.beginJob();
172
186
 
173
187
  const topLevelOracleHandler = new TXEOracleTopLevelContext(
174
188
  stateMachine,
175
- contractDataProvider,
189
+ contractStore,
190
+ noteStore,
176
191
  keyStore,
177
- addressDataProvider,
178
- accountDataProvider,
179
- pxeOracleInterface,
192
+ addressStore,
193
+ accountStore,
194
+ senderTaggingStore,
195
+ recipientTaggingStore,
196
+ senderAddressBookStore,
197
+ capsuleStore,
198
+ privateEventStore,
199
+ initialJobId,
180
200
  nextBlockTimestamp,
181
201
  version,
182
202
  chainId,
@@ -188,14 +208,21 @@ export class TXESession implements TXESessionStateHandler {
188
208
  createLogger('txe:session'),
189
209
  stateMachine,
190
210
  topLevelOracleHandler,
191
- contractDataProvider,
211
+ contractStore,
212
+ noteStore,
192
213
  keyStore,
193
- addressDataProvider,
194
- accountDataProvider,
214
+ addressStore,
215
+ accountStore,
216
+ senderTaggingStore,
217
+ recipientTaggingStore,
218
+ senderAddressBookStore,
219
+ capsuleStore,
220
+ privateEventStore,
221
+ jobCoordinator,
222
+ initialJobId,
195
223
  version,
196
224
  chainId,
197
225
  nextBlockTimestamp,
198
- pxeOracleInterface,
199
226
  );
200
227
  }
201
228
 
@@ -252,13 +279,23 @@ export class TXESession implements TXESessionStateHandler {
252
279
  }
253
280
  }
254
281
 
282
+ // 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();
285
+
255
286
  this.oracleHandler = new TXEOracleTopLevelContext(
256
287
  this.stateMachine,
257
- this.contractDataProvider,
288
+ this.contractStore,
289
+ this.noteStore,
258
290
  this.keyStore,
259
- this.addressDataProvider,
260
- this.accountDataProvider,
261
- this.pxeOracleInterface,
291
+ this.addressStore,
292
+ this.accountStore,
293
+ this.senderTaggingStore,
294
+ this.recipientTaggingStore,
295
+ this.senderAddressBookStore,
296
+ this.capsuleStore,
297
+ this.privateEventStore,
298
+ this.currentJobId,
262
299
  this.nextBlockTimestamp,
263
300
  this.version,
264
301
  this.chainId,
@@ -271,16 +308,16 @@ export class TXESession implements TXESessionStateHandler {
271
308
 
272
309
  async enterPrivateState(
273
310
  contractAddress: AztecAddress = DEFAULT_ADDRESS,
274
- anchorBlockNumber?: UInt32,
311
+ anchorBlockNumber?: BlockNumber,
275
312
  ): Promise<PrivateContextInputs> {
276
313
  this.exitTopLevelState();
277
314
 
278
- // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
279
- // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
280
- // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
281
- // be removed from the database.
282
- // TODO(#12553): make the synchronizer sync here instead and remove this
283
- await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
315
+ await new NoteService(
316
+ this.noteStore,
317
+ this.stateMachine.node,
318
+ this.stateMachine.anchorBlockStore,
319
+ this.currentJobId,
320
+ ).syncNoteNullifiers(contractAddress);
284
321
 
285
322
  // Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
286
323
  // build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
@@ -289,7 +326,7 @@ export class TXESession implements TXESessionStateHandler {
289
326
  const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
290
327
 
291
328
  const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
292
- blockNumber: latestBlock!.globalVariables.blockNumber + 1,
329
+ blockNumber: BlockNumber(latestBlock!.globalVariables.blockNumber + 1),
293
330
  timestamp: this.nextBlockTimestamp,
294
331
  version: this.version,
295
332
  chainId: this.chainId,
@@ -300,17 +337,30 @@ export class TXESession implements TXESessionStateHandler {
300
337
  const noteCache = new ExecutionNoteCache(protocolNullifier);
301
338
  const taggingIndexCache = new ExecutionTaggingIndexCache();
302
339
 
340
+ const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
303
341
  this.oracleHandler = new PrivateExecutionOracle(
304
342
  Fr.ZERO,
305
343
  new TxContext(this.chainId, this.version, GasSettings.empty()),
306
344
  new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
307
345
  anchorBlock!,
346
+ utilityExecutor,
308
347
  [],
309
348
  [],
310
349
  new HashedValuesCache(),
311
350
  noteCache,
312
351
  taggingIndexCache,
313
- this.pxeOracleInterface,
352
+ this.contractStore,
353
+ this.noteStore,
354
+ this.keyStore,
355
+ this.addressStore,
356
+ this.stateMachine.node,
357
+ this.stateMachine.anchorBlockStore,
358
+ this.senderTaggingStore,
359
+ this.recipientTaggingStore,
360
+ this.senderAddressBookStore,
361
+ this.capsuleStore,
362
+ this.privateEventStore,
363
+ this.currentJobId,
314
364
  );
315
365
 
316
366
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
@@ -318,7 +368,7 @@ export class TXESession implements TXESessionStateHandler {
318
368
  // difference resides in that the simulator has all information needed in order to run the simulation, while ours
319
369
  // will be ongoing as the different oracles will be invoked from the Noir test, until eventually the private
320
370
  // execution finishes.
321
- this.state = { name: 'PRIVATE', nextBlockGlobalVariables, protocolNullifier, noteCache, taggingIndexCache };
371
+ this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
322
372
  this.logger.debug(`Entered state ${this.state.name}`);
323
373
 
324
374
  return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
@@ -331,7 +381,7 @@ export class TXESession implements TXESessionStateHandler {
331
381
  // the test. The block therefore gets the *next* block number and timestamp.
332
382
  const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.blockNumber;
333
383
  const globalVariables = makeGlobalVariables(undefined, {
334
- blockNumber: latestBlockNumber + 1,
384
+ blockNumber: BlockNumber(latestBlockNumber + 1),
335
385
  timestamp: this.nextBlockTimestamp,
336
386
  version: this.version,
337
387
  chainId: this.chainId,
@@ -356,9 +406,32 @@ export class TXESession implements TXESessionStateHandler {
356
406
  // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
357
407
  // be removed from the database.
358
408
  // TODO(#12553): make the synchronizer sync here instead and remove this
359
- await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
409
+ await new NoteService(
410
+ this.noteStore,
411
+ this.stateMachine.node,
412
+ this.stateMachine.anchorBlockStore,
413
+ this.currentJobId,
414
+ ).syncNoteNullifiers(contractAddress);
360
415
 
361
- this.oracleHandler = new UtilityExecutionOracle(contractAddress, [], [], this.pxeOracleInterface);
416
+ const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
417
+
418
+ this.oracleHandler = new UtilityExecutionOracle(
419
+ contractAddress,
420
+ [],
421
+ [],
422
+ anchorBlockHeader,
423
+ this.contractStore,
424
+ this.noteStore,
425
+ this.keyStore,
426
+ this.addressStore,
427
+ this.stateMachine.node,
428
+ this.stateMachine.anchorBlockStore,
429
+ this.recipientTaggingStore,
430
+ this.senderAddressBookStore,
431
+ this.capsuleStore,
432
+ this.privateEventStore,
433
+ this.currentJobId,
434
+ );
362
435
 
363
436
  this.state = { name: 'UTILITY' };
364
437
  this.logger.debug(`Entered state ${this.state.name}`);
@@ -392,21 +465,14 @@ export class TXESession implements TXESessionStateHandler {
392
465
 
393
466
  // We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
394
467
  // logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
395
- const txEffect = await makeTxEffect(
396
- this.state.noteCache,
397
- this.state.protocolNullifier,
398
- this.state.nextBlockGlobalVariables.blockNumber,
399
- );
468
+
469
+ const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
400
470
 
401
471
  // We build a block holding just this transaction
402
472
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
403
473
  await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
404
474
 
405
- const block = new L2Block(
406
- makeAppendOnlyTreeSnapshot(),
407
- await makeTXEBlockHeader(forkedWorldTrees, this.state.nextBlockGlobalVariables),
408
- new Body([txEffect]),
409
- );
475
+ const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [txEffect]);
410
476
  await this.stateMachine.handleL2Block(block);
411
477
 
412
478
  await forkedWorldTrees.close();
@@ -431,4 +497,49 @@ export class TXESession implements TXESessionStateHandler {
431
497
  throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
432
498
  }
433
499
  }
500
+
501
+ private utilityExecutorForContractSync(anchorBlock: any) {
502
+ return async (call: FunctionCall) => {
503
+ const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
504
+ if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
505
+ throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
506
+ }
507
+
508
+ 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.stateMachine.anchorBlockStore,
520
+ this.recipientTaggingStore,
521
+ this.senderAddressBookStore,
522
+ this.capsuleStore,
523
+ this.privateEventStore,
524
+ this.currentJobId,
525
+ );
526
+ await new WASMSimulator()
527
+ .executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
528
+ .catch((err: Error) => {
529
+ err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
530
+ throw new ExecutionError(
531
+ err.message,
532
+ {
533
+ contractAddress: call.to,
534
+ functionSelector: call.selector,
535
+ },
536
+ extractCallStack(err, entryPointArtifact.debug),
537
+ { cause: err },
538
+ );
539
+ });
540
+ } catch (err) {
541
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
542
+ }
543
+ };
544
+ }
434
545
  }
@@ -1,5 +1,5 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
1
2
  import type { EthAddress } from '@aztec/foundation/eth-address';
2
- import { Fr } from '@aztec/foundation/fields';
3
3
  import { hexToBuffer } from '@aztec/foundation/string';
4
4
  import { type ContractArtifact, ContractArtifactSchema } from '@aztec/stdlib/abi';
5
5
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -2,7 +2,7 @@ import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
  import { CompleteAddress } from '@aztec/stdlib/contract';
4
4
 
5
- export class TXEAccountDataProvider {
5
+ export class TXEAccountStore {
6
6
  #accounts: AztecAsyncMap<string, Buffer>;
7
7
 
8
8
  constructor(store: AztecAsyncKVStore) {