@aztec/sequencer-client 0.31.0 → 0.32.1

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 (96) hide show
  1. package/dest/client/sequencer-client.d.ts +8 -8
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +4 -3
  4. package/dest/config.d.ts +3 -3
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +7 -3
  7. package/dest/global_variable_builder/config.d.ts +1 -1
  8. package/dest/global_variable_builder/config.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.d.ts +1 -1
  10. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  11. package/dest/global_variable_builder/global_builder.js +1 -1
  12. package/dest/global_variable_builder/index.d.ts +2 -2
  13. package/dest/global_variable_builder/index.d.ts.map +1 -1
  14. package/dest/global_variable_builder/index.js +1 -1
  15. package/dest/global_variable_builder/viem-reader.d.ts +2 -2
  16. package/dest/global_variable_builder/viem-reader.d.ts.map +1 -1
  17. package/dest/publisher/config.d.ts +1 -1
  18. package/dest/publisher/config.d.ts.map +1 -1
  19. package/dest/publisher/index.d.ts +1 -1
  20. package/dest/publisher/index.d.ts.map +1 -1
  21. package/dest/publisher/l1-publisher.d.ts +3 -3
  22. package/dest/publisher/l1-publisher.d.ts.map +1 -1
  23. package/dest/publisher/viem-tx-sender.d.ts +3 -3
  24. package/dest/publisher/viem-tx-sender.d.ts.map +1 -1
  25. package/dest/publisher/viem-tx-sender.js +1 -1
  26. package/dest/receiver.d.ts +1 -1
  27. package/dest/receiver.d.ts.map +1 -1
  28. package/dest/sequencer/abstract_phase_manager.d.ts +7 -7
  29. package/dest/sequencer/abstract_phase_manager.d.ts.map +1 -1
  30. package/dest/sequencer/abstract_phase_manager.js +1 -1
  31. package/dest/sequencer/app_logic_phase_manager.d.ts +6 -6
  32. package/dest/sequencer/app_logic_phase_manager.d.ts.map +1 -1
  33. package/dest/sequencer/app_logic_phase_manager.js +1 -1
  34. package/dest/sequencer/hints_builder.d.ts +3 -3
  35. package/dest/sequencer/hints_builder.d.ts.map +1 -1
  36. package/dest/sequencer/phase_manager_factory.d.ts +7 -7
  37. package/dest/sequencer/phase_manager_factory.d.ts.map +1 -1
  38. package/dest/sequencer/phase_manager_factory.js +1 -1
  39. package/dest/sequencer/public_processor.d.ts +7 -8
  40. package/dest/sequencer/public_processor.d.ts.map +1 -1
  41. package/dest/sequencer/public_processor.js +5 -5
  42. package/dest/sequencer/sequencer.d.ts +15 -12
  43. package/dest/sequencer/sequencer.d.ts.map +1 -1
  44. package/dest/sequencer/sequencer.js +13 -13
  45. package/dest/sequencer/setup_phase_manager.d.ts +6 -6
  46. package/dest/sequencer/setup_phase_manager.d.ts.map +1 -1
  47. package/dest/sequencer/setup_phase_manager.js +1 -1
  48. package/dest/sequencer/tail_phase_manager.d.ts +6 -6
  49. package/dest/sequencer/tail_phase_manager.d.ts.map +1 -1
  50. package/dest/sequencer/tail_phase_manager.js +1 -1
  51. package/dest/sequencer/teardown_phase_manager.d.ts +6 -6
  52. package/dest/sequencer/teardown_phase_manager.d.ts.map +1 -1
  53. package/dest/sequencer/teardown_phase_manager.js +1 -1
  54. package/dest/sequencer/tx_validator.d.ts +10 -3
  55. package/dest/sequencer/tx_validator.d.ts.map +1 -1
  56. package/dest/sequencer/tx_validator.js +59 -24
  57. package/dest/sequencer/tx_validator_factory.d.ts +12 -0
  58. package/dest/sequencer/tx_validator_factory.d.ts.map +1 -0
  59. package/dest/sequencer/tx_validator_factory.js +17 -0
  60. package/dest/sequencer/utils.d.ts +1 -1
  61. package/dest/sequencer/utils.d.ts.map +1 -1
  62. package/dest/simulator/index.d.ts +1 -1
  63. package/dest/simulator/index.d.ts.map +1 -1
  64. package/dest/simulator/public_executor.d.ts +6 -7
  65. package/dest/simulator/public_executor.d.ts.map +1 -1
  66. package/dest/simulator/public_executor.js +8 -9
  67. package/dest/simulator/public_kernel.d.ts +3 -3
  68. package/dest/simulator/public_kernel.d.ts.map +1 -1
  69. package/dest/simulator/public_kernel.js +1 -1
  70. package/package.json +13 -13
  71. package/src/client/sequencer-client.ts +11 -15
  72. package/src/config.ts +12 -6
  73. package/src/global_variable_builder/config.ts +1 -1
  74. package/src/global_variable_builder/global_builder.ts +1 -1
  75. package/src/global_variable_builder/index.ts +2 -2
  76. package/src/global_variable_builder/viem-reader.ts +6 -6
  77. package/src/publisher/config.ts +1 -1
  78. package/src/publisher/index.ts +1 -1
  79. package/src/publisher/l1-publisher.ts +4 -4
  80. package/src/publisher/viem-tx-sender.ts +12 -12
  81. package/src/receiver.ts +1 -1
  82. package/src/sequencer/abstract_phase_manager.ts +16 -16
  83. package/src/sequencer/app_logic_phase_manager.ts +11 -6
  84. package/src/sequencer/hints_builder.ts +9 -9
  85. package/src/sequencer/phase_manager_factory.ts +7 -7
  86. package/src/sequencer/public_processor.ts +13 -13
  87. package/src/sequencer/sequencer.ts +24 -23
  88. package/src/sequencer/setup_phase_manager.ts +11 -6
  89. package/src/sequencer/tail_phase_manager.ts +11 -6
  90. package/src/sequencer/teardown_phase_manager.ts +11 -6
  91. package/src/sequencer/tx_validator.ts +87 -28
  92. package/src/sequencer/tx_validator_factory.ts +32 -0
  93. package/src/sequencer/utils.ts +1 -1
  94. package/src/simulator/index.ts +3 -3
  95. package/src/simulator/public_executor.ts +25 -26
  96. package/src/simulator/public_kernel.ts +6 -6
@@ -1,12 +1,12 @@
1
- import { L2Block } from '@aztec/circuit-types';
2
- import { L1PublishStats } from '@aztec/circuit-types/stats';
1
+ import { type L2Block } from '@aztec/circuit-types';
2
+ import { type L1PublishStats } from '@aztec/circuit-types/stats';
3
3
  import { createDebugLogger } from '@aztec/foundation/log';
4
4
  import { InterruptibleSleep } from '@aztec/foundation/sleep';
5
5
 
6
6
  import pick from 'lodash.pick';
7
7
 
8
- import { L2BlockReceiver } from '../receiver.js';
9
- import { PublisherConfig } from './config.js';
8
+ import { type L2BlockReceiver } from '../receiver.js';
9
+ import { type PublisherConfig } from './config.js';
10
10
 
11
11
  /**
12
12
  * Stats for a sent transaction.
@@ -1,14 +1,14 @@
1
- import { L2Block } from '@aztec/circuit-types';
1
+ import { type L2Block } from '@aztec/circuit-types';
2
2
  import { createEthereumChain } from '@aztec/ethereum';
3
3
  import { createDebugLogger } from '@aztec/foundation/log';
4
4
  import { AvailabilityOracleAbi, RollupAbi } from '@aztec/l1-artifacts';
5
5
 
6
6
  import {
7
- GetContractReturnType,
8
- Hex,
9
- HttpTransport,
10
- PublicClient,
11
- WalletClient,
7
+ type GetContractReturnType,
8
+ type Hex,
9
+ type HttpTransport,
10
+ type PublicClient,
11
+ type WalletClient,
12
12
  createPublicClient,
13
13
  createWalletClient,
14
14
  getAddress,
@@ -16,15 +16,15 @@ import {
16
16
  hexToBytes,
17
17
  http,
18
18
  } from 'viem';
19
- import { PrivateKeyAccount, privateKeyToAccount } from 'viem/accounts';
19
+ import { type PrivateKeyAccount, privateKeyToAccount } from 'viem/accounts';
20
20
  import * as chains from 'viem/chains';
21
21
 
22
- import { TxSenderConfig } from './config.js';
22
+ import { type TxSenderConfig } from './config.js';
23
23
  import {
24
- L1PublisherTxSender,
25
- MinimalTransactionReceipt,
26
- L1ProcessArgs as ProcessTxArgs,
27
- TransactionStats,
24
+ type L1PublisherTxSender,
25
+ type MinimalTransactionReceipt,
26
+ type L1ProcessArgs as ProcessTxArgs,
27
+ type TransactionStats,
28
28
  } from './l1-publisher.js';
29
29
 
30
30
  /**
package/src/receiver.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { L2Block } from '@aztec/circuit-types';
1
+ import { type L2Block } from '@aztec/circuit-types';
2
2
 
3
3
  /**
4
4
  * Given the necessary rollup data, verifies it, and updates the underlying state accordingly to advance the state of the system.
@@ -1,12 +1,12 @@
1
- import { FunctionL2Logs, MerkleTreeId, SimulationError, Tx } from '@aztec/circuit-types';
1
+ import { MerkleTreeId, type SimulationError, type Tx, type UnencryptedFunctionL2Logs } from '@aztec/circuit-types';
2
2
  import {
3
3
  AztecAddress,
4
4
  CallRequest,
5
5
  ContractStorageRead,
6
6
  ContractStorageUpdateRequest,
7
7
  Fr,
8
- GlobalVariables,
9
- Header,
8
+ type GlobalVariables,
9
+ type Header,
10
10
  L2ToL1Message,
11
11
  MAX_NEW_L2_TO_L1_MSGS_PER_CALL,
12
12
  MAX_NEW_NOTE_HASHES_PER_CALL,
@@ -20,16 +20,16 @@ import {
20
20
  MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
21
21
  MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
22
22
  MembershipWitness,
23
- PrivateKernelTailCircuitPublicInputs,
24
- Proof,
23
+ type PrivateKernelTailCircuitPublicInputs,
24
+ type Proof,
25
25
  PublicCallData,
26
- PublicCallRequest,
26
+ type PublicCallRequest,
27
27
  PublicCallStackItem,
28
28
  PublicCircuitPublicInputs,
29
29
  PublicDataRead,
30
30
  PublicDataUpdateRequest,
31
31
  PublicKernelCircuitPrivateInputs,
32
- PublicKernelCircuitPublicInputs,
32
+ type PublicKernelCircuitPublicInputs,
33
33
  PublicKernelData,
34
34
  PublicKernelTailCircuitPrivateInputs,
35
35
  RETURN_VALUES_LENGTH,
@@ -43,19 +43,19 @@ import {
43
43
  } from '@aztec/circuits.js';
44
44
  import { computeVarArgsHash } from '@aztec/circuits.js/hash';
45
45
  import { arrayNonEmptyLength, padArrayEnd } from '@aztec/foundation/collection';
46
- import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';
47
- import { Tuple } from '@aztec/foundation/serialize';
46
+ import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
47
+ import { type Tuple } from '@aztec/foundation/serialize';
48
48
  import {
49
- PublicExecution,
50
- PublicExecutionResult,
51
- PublicExecutor,
49
+ type PublicExecution,
50
+ type PublicExecutionResult,
51
+ type PublicExecutor,
52
52
  collectPublicDataReads,
53
53
  collectPublicDataUpdateRequests,
54
54
  isPublicExecutionResult,
55
55
  } from '@aztec/simulator';
56
- import { MerkleTreeOperations } from '@aztec/world-state';
56
+ import { type MerkleTreeOperations } from '@aztec/world-state';
57
57
 
58
- import { PublicKernelCircuitSimulator } from '../simulator/index.js';
58
+ import { type PublicKernelCircuitSimulator } from '../simulator/index.js';
59
59
  import { HintsBuilder } from './hints_builder.js';
60
60
  import { lastSideEffectCounter } from './utils.js';
61
61
 
@@ -180,7 +180,7 @@ export abstract class AbstractPhaseManager {
180
180
  tx: Tx,
181
181
  previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
182
182
  previousPublicKernelProof: Proof,
183
- ): Promise<[PublicKernelCircuitPublicInputs, Proof, FunctionL2Logs[], SimulationError | undefined]> {
183
+ ): Promise<[PublicKernelCircuitPublicInputs, Proof, UnencryptedFunctionL2Logs[], SimulationError | undefined]> {
184
184
  let kernelOutput = previousPublicKernelOutput;
185
185
  let kernelProof = previousPublicKernelProof;
186
186
 
@@ -190,7 +190,7 @@ export abstract class AbstractPhaseManager {
190
190
  return [kernelOutput, kernelProof, [], undefined];
191
191
  }
192
192
 
193
- const newUnencryptedFunctionLogs: FunctionL2Logs[] = [];
193
+ const newUnencryptedFunctionLogs: UnencryptedFunctionL2Logs[] = [];
194
194
 
195
195
  // TODO(#1684): Should multiple separately enqueued public calls be treated as
196
196
  // separate public callstacks to be proven by separate public kernel sequences
@@ -1,10 +1,15 @@
1
- import { Tx } from '@aztec/circuit-types';
2
- import { GlobalVariables, Header, Proof, PublicKernelCircuitPublicInputs } from '@aztec/circuits.js';
3
- import { PublicExecutor, PublicStateDB } from '@aztec/simulator';
4
- import { MerkleTreeOperations } from '@aztec/world-state';
1
+ import { type Tx } from '@aztec/circuit-types';
2
+ import {
3
+ type GlobalVariables,
4
+ type Header,
5
+ type Proof,
6
+ type PublicKernelCircuitPublicInputs,
7
+ } from '@aztec/circuits.js';
8
+ import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
9
+ import { type MerkleTreeOperations } from '@aztec/world-state';
5
10
 
6
- import { PublicKernelCircuitSimulator } from '../simulator/index.js';
7
- import { ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
11
+ import { type PublicKernelCircuitSimulator } from '../simulator/index.js';
12
+ import { type ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
8
13
  import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
9
14
 
10
15
  /**
@@ -1,21 +1,21 @@
1
1
  import { MerkleTreeId } from '@aztec/circuit-types';
2
2
  import {
3
- Fr,
3
+ type Fr,
4
4
  MAX_NEW_NULLIFIERS_PER_TX,
5
- MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX,
6
- MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX,
7
- MAX_NULLIFIER_READ_REQUESTS_PER_TX,
8
- MAX_REVERTIBLE_NULLIFIERS_PER_TX,
5
+ type MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX,
6
+ type MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX,
7
+ type MAX_NULLIFIER_READ_REQUESTS_PER_TX,
8
+ type MAX_REVERTIBLE_NULLIFIERS_PER_TX,
9
9
  MembershipWitness,
10
10
  NULLIFIER_TREE_HEIGHT,
11
- ReadRequestContext,
12
- SideEffectLinkedToNoteHash,
11
+ type ReadRequestContext,
12
+ type SideEffectLinkedToNoteHash,
13
13
  buildNullifierNonExistentReadRequestHints,
14
14
  buildNullifierReadRequestHints,
15
15
  concatAccumulatedData,
16
16
  } from '@aztec/circuits.js';
17
- import { Tuple } from '@aztec/foundation/serialize';
18
- import { MerkleTreeOperations } from '@aztec/world-state';
17
+ import { type Tuple } from '@aztec/foundation/serialize';
18
+ import { type MerkleTreeOperations } from '@aztec/world-state';
19
19
 
20
20
  export class HintsBuilder {
21
21
  constructor(private db: MerkleTreeOperations) {}
@@ -1,11 +1,11 @@
1
- import { Tx } from '@aztec/circuit-types';
2
- import { GlobalVariables, Header, PublicKernelCircuitPublicInputs } from '@aztec/circuits.js';
3
- import { PublicExecutor, PublicStateDB } from '@aztec/simulator';
4
- import { MerkleTreeOperations } from '@aztec/world-state';
1
+ import { type Tx } from '@aztec/circuit-types';
2
+ import { type GlobalVariables, type Header, type PublicKernelCircuitPublicInputs } from '@aztec/circuits.js';
3
+ import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
4
+ import { type MerkleTreeOperations } from '@aztec/world-state';
5
5
 
6
- import { PublicKernelCircuitSimulator } from '../simulator/index.js';
7
- import { ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
8
- import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
6
+ import { type PublicKernelCircuitSimulator } from '../simulator/index.js';
7
+ import { type ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
8
+ import { type AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
9
9
  import { AppLogicPhaseManager } from './app_logic_phase_manager.js';
10
10
  import { SetupPhaseManager } from './setup_phase_manager.js';
11
11
  import { TailPhaseManager } from './tail_phase_manager.js';
@@ -1,26 +1,26 @@
1
1
  import {
2
- FailedTx,
3
- L1ToL2MessageSource,
4
- ProcessedTx,
5
- SimulationError,
2
+ type FailedTx,
3
+ type ProcessedTx,
4
+ type SimulationError,
6
5
  Tx,
7
6
  getPreviousOutputAndProof,
8
7
  makeEmptyProcessedTx,
9
8
  makeProcessedTx,
9
+ toTxEffect,
10
10
  validateProcessedTx,
11
11
  } from '@aztec/circuit-types';
12
- import { TxSequencerProcessingStats } from '@aztec/circuit-types/stats';
13
- import { GlobalVariables, Header } from '@aztec/circuits.js';
12
+ import { type TxSequencerProcessingStats } from '@aztec/circuit-types/stats';
13
+ import { type GlobalVariables, type Header } from '@aztec/circuits.js';
14
14
  import { createDebugLogger } from '@aztec/foundation/log';
15
15
  import { Timer } from '@aztec/foundation/timer';
16
- import { PublicExecutor, PublicStateDB, SimulationProvider } from '@aztec/simulator';
17
- import { ContractDataSource } from '@aztec/types/contracts';
18
- import { MerkleTreeOperations } from '@aztec/world-state';
16
+ import { PublicExecutor, type PublicStateDB, type SimulationProvider } from '@aztec/simulator';
17
+ import { type ContractDataSource } from '@aztec/types/contracts';
18
+ import { type MerkleTreeOperations } from '@aztec/world-state';
19
19
 
20
- import { PublicKernelCircuitSimulator } from '../simulator/index.js';
20
+ import { type PublicKernelCircuitSimulator } from '../simulator/index.js';
21
21
  import { ContractsDataSourcePublicDB, WorldStateDB, WorldStatePublicDB } from '../simulator/public_executor.js';
22
22
  import { RealPublicKernelCircuitSimulator } from '../simulator/public_kernel.js';
23
- import { AbstractPhaseManager } from './abstract_phase_manager.js';
23
+ import { type AbstractPhaseManager } from './abstract_phase_manager.js';
24
24
  import { PhaseManagerFactory } from './phase_manager_factory.js';
25
25
 
26
26
  /**
@@ -30,7 +30,6 @@ export class PublicProcessorFactory {
30
30
  constructor(
31
31
  private merkleTree: MerkleTreeOperations,
32
32
  private contractDataSource: ContractDataSource,
33
- private l1Tol2MessagesDataSource: L1ToL2MessageSource,
34
33
  private simulator: SimulationProvider,
35
34
  ) {}
36
35
 
@@ -49,7 +48,7 @@ export class PublicProcessorFactory {
49
48
 
50
49
  const publicContractsDB = new ContractsDataSourcePublicDB(this.contractDataSource);
51
50
  const worldStatePublicDB = new WorldStatePublicDB(this.merkleTree);
52
- const worldStateDB = new WorldStateDB(this.merkleTree, this.l1Tol2MessagesDataSource);
51
+ const worldStateDB = new WorldStateDB(this.merkleTree);
53
52
  const publicExecutor = new PublicExecutor(worldStatePublicDB, publicContractsDB, worldStateDB, historicalHeader);
54
53
  return new PublicProcessor(
55
54
  this.merkleTree,
@@ -133,6 +132,7 @@ export class PublicProcessor {
133
132
  this.log(`Processed public part of ${tx.data.endNonRevertibleData.newNullifiers[0].value}`, {
134
133
  eventName: 'tx-sequencer-processing',
135
134
  duration: timer.ms(),
135
+ effectsSize: toTxEffect(processedTransaction).toBuffer().length,
136
136
  publicDataUpdateRequests:
137
137
  processedTransaction.data.combinedData.publicDataUpdateRequests.filter(x => !x.leafSlot.isZero()).length ??
138
138
  0,
@@ -1,20 +1,20 @@
1
- import { L1ToL2MessageSource, L2Block, L2BlockSource, MerkleTreeId, ProcessedTx, Tx } from '@aztec/circuit-types';
2
- import { BlockProver, PROVING_STATUS } from '@aztec/circuit-types/interfaces';
3
- import { L2BlockBuiltStats } from '@aztec/circuit-types/stats';
4
- import { AztecAddress, EthAddress, GlobalVariables } from '@aztec/circuits.js';
1
+ import { type L1ToL2MessageSource, type L2Block, type L2BlockSource, type ProcessedTx, Tx } from '@aztec/circuit-types';
2
+ import { type BlockProver, PROVING_STATUS } from '@aztec/circuit-types/interfaces';
3
+ import { type L2BlockBuiltStats } from '@aztec/circuit-types/stats';
4
+ import { AztecAddress, EthAddress, type GlobalVariables } from '@aztec/circuits.js';
5
5
  import { Fr } from '@aztec/foundation/fields';
6
6
  import { createDebugLogger } from '@aztec/foundation/log';
7
7
  import { RunningPromise } from '@aztec/foundation/running-promise';
8
8
  import { Timer, elapsed } from '@aztec/foundation/timer';
9
- import { P2P } from '@aztec/p2p';
10
- import { WorldStateStatus, WorldStateSynchronizer } from '@aztec/world-state';
9
+ import { type P2P } from '@aztec/p2p';
10
+ import { type WorldStateStatus, type WorldStateSynchronizer } from '@aztec/world-state';
11
11
 
12
- import { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
13
- import { L1Publisher } from '../publisher/l1-publisher.js';
14
- import { WorldStatePublicDB } from '../simulator/public_executor.js';
15
- import { SequencerConfig } from './config.js';
16
- import { PublicProcessorFactory } from './public_processor.js';
17
- import { TxValidator } from './tx_validator.js';
12
+ import { type GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
13
+ import { type L1Publisher } from '../publisher/l1-publisher.js';
14
+ import { type SequencerConfig } from './config.js';
15
+ import { type PublicProcessorFactory } from './public_processor.js';
16
+ import { type TxValidator } from './tx_validator.js';
17
+ import { type TxValidatorFactory } from './tx_validator_factory.js';
18
18
 
19
19
  /**
20
20
  * Sequencer client
@@ -35,6 +35,8 @@ export class Sequencer {
35
35
  private _feeRecipient = AztecAddress.ZERO;
36
36
  private lastPublishedBlock = 0;
37
37
  private state = SequencerState.STOPPED;
38
+ private allowedFeePaymentContractClasses: Fr[] = [];
39
+ private allowedFeePaymentContractInstances: AztecAddress[] = [];
38
40
 
39
41
  constructor(
40
42
  private publisher: L1Publisher,
@@ -45,8 +47,8 @@ export class Sequencer {
45
47
  private l2BlockSource: L2BlockSource,
46
48
  private l1ToL2MessageSource: L1ToL2MessageSource,
47
49
  private publicProcessorFactory: PublicProcessorFactory,
50
+ private txValidatorFactory: TxValidatorFactory,
48
51
  config: SequencerConfig = {},
49
- private gasPortalAddress = EthAddress.ZERO,
50
52
  private log = createDebugLogger('aztec:sequencer'),
51
53
  ) {
52
54
  this.updateConfig(config);
@@ -73,6 +75,12 @@ export class Sequencer {
73
75
  if (config.feeRecipient) {
74
76
  this._feeRecipient = config.feeRecipient;
75
77
  }
78
+ if (config.allowedFeePaymentContractClasses) {
79
+ this.allowedFeePaymentContractClasses = config.allowedFeePaymentContractClasses;
80
+ }
81
+ if (config.allowedFeePaymentContractInstances) {
82
+ this.allowedFeePaymentContractInstances = config.allowedFeePaymentContractInstances;
83
+ }
76
84
  }
77
85
 
78
86
  /**
@@ -170,17 +178,10 @@ export class Sequencer {
170
178
  this._feeRecipient,
171
179
  );
172
180
 
173
- // Filter out invalid txs
174
- const trees = this.worldState.getLatest();
175
- const txValidator = new TxValidator(
176
- {
177
- getNullifierIndex(nullifier: Fr): Promise<bigint | undefined> {
178
- return trees.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer());
179
- },
180
- },
181
- new WorldStatePublicDB(trees),
182
- this.gasPortalAddress,
181
+ const txValidator = this.txValidatorFactory.buildTxValidator(
183
182
  newGlobalVariables,
183
+ this.allowedFeePaymentContractClasses,
184
+ this.allowedFeePaymentContractInstances,
184
185
  );
185
186
 
186
187
  // TODO: It should be responsibility of the P2P layer to validate txs before passing them on here
@@ -1,10 +1,15 @@
1
- import { Tx } from '@aztec/circuit-types';
2
- import { GlobalVariables, Header, Proof, PublicKernelCircuitPublicInputs } from '@aztec/circuits.js';
3
- import { PublicExecutor, PublicStateDB } from '@aztec/simulator';
4
- import { MerkleTreeOperations } from '@aztec/world-state';
1
+ import { type Tx } from '@aztec/circuit-types';
2
+ import {
3
+ type GlobalVariables,
4
+ type Header,
5
+ type Proof,
6
+ type PublicKernelCircuitPublicInputs,
7
+ } from '@aztec/circuits.js';
8
+ import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
9
+ import { type MerkleTreeOperations } from '@aztec/world-state';
5
10
 
6
- import { PublicKernelCircuitSimulator } from '../simulator/index.js';
7
- import { ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
11
+ import { type PublicKernelCircuitSimulator } from '../simulator/index.js';
12
+ import { type ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
8
13
  import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
9
14
 
10
15
  /**
@@ -1,10 +1,15 @@
1
- import { Tx } from '@aztec/circuit-types';
2
- import { GlobalVariables, Header, Proof, PublicKernelCircuitPublicInputs } from '@aztec/circuits.js';
3
- import { PublicExecutor, PublicStateDB } from '@aztec/simulator';
4
- import { MerkleTreeOperations } from '@aztec/world-state';
1
+ import { type Tx } from '@aztec/circuit-types';
2
+ import {
3
+ type GlobalVariables,
4
+ type Header,
5
+ type Proof,
6
+ type PublicKernelCircuitPublicInputs,
7
+ } from '@aztec/circuits.js';
8
+ import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
9
+ import { type MerkleTreeOperations } from '@aztec/world-state';
5
10
 
6
- import { PublicKernelCircuitSimulator } from '../simulator/index.js';
7
- import { ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
11
+ import { type PublicKernelCircuitSimulator } from '../simulator/index.js';
12
+ import { type ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
8
13
  import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
9
14
 
10
15
  export class TailPhaseManager extends AbstractPhaseManager {
@@ -1,10 +1,15 @@
1
- import { Tx } from '@aztec/circuit-types';
2
- import { GlobalVariables, Header, Proof, PublicKernelCircuitPublicInputs } from '@aztec/circuits.js';
3
- import { PublicExecutor, PublicStateDB } from '@aztec/simulator';
4
- import { MerkleTreeOperations } from '@aztec/world-state';
1
+ import { type Tx } from '@aztec/circuit-types';
2
+ import {
3
+ type GlobalVariables,
4
+ type Header,
5
+ type Proof,
6
+ type PublicKernelCircuitPublicInputs,
7
+ } from '@aztec/circuits.js';
8
+ import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
9
+ import { type MerkleTreeOperations } from '@aztec/world-state';
5
10
 
6
- import { PublicKernelCircuitSimulator } from '../simulator/index.js';
7
- import { ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
11
+ import { type PublicKernelCircuitSimulator } from '../simulator/index.js';
12
+ import { type ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
8
13
  import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
9
14
 
10
15
  /**
@@ -1,8 +1,15 @@
1
- import { ProcessedTx, Tx } from '@aztec/circuit-types';
2
- import { AztecAddress, EthAddress, Fr, GlobalVariables } from '@aztec/circuits.js';
1
+ import { type ProcessedTx, Tx } from '@aztec/circuit-types';
2
+ import {
3
+ type AztecAddress,
4
+ type EthAddress,
5
+ Fr,
6
+ type GlobalVariables,
7
+ type PublicCallRequest,
8
+ } from '@aztec/circuits.js';
3
9
  import { pedersenHash } from '@aztec/foundation/crypto';
4
- import { Logger, createDebugLogger } from '@aztec/foundation/log';
10
+ import { type Logger, createDebugLogger } from '@aztec/foundation/log';
5
11
  import { getCanonicalGasTokenAddress } from '@aztec/protocol-contracts/gas-token';
12
+ import { type ContractDataSource } from '@aztec/types/contracts';
6
13
 
7
14
  import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
8
15
 
@@ -27,25 +34,33 @@ type TxValidationStatus = typeof VALID_TX | typeof INVALID_TX;
27
34
  // the storage slot associated with "storage.balances"
28
35
  const GAS_TOKEN_BALANCES_SLOT = new Fr(1);
29
36
 
37
+ type FeeValidationConfig = {
38
+ gasPortalAddress: EthAddress;
39
+ allowedFeePaymentContractClasses: Fr[];
40
+ allowedFeePaymentContractInstances: AztecAddress[];
41
+ };
42
+
30
43
  export class TxValidator {
31
44
  #log: Logger;
32
45
  #globalVariables: GlobalVariables;
33
46
  #nullifierSource: NullifierSource;
34
47
  #publicStateSource: PublicStateSource;
35
- #gasPortalAddress: EthAddress;
48
+ #contractDataSource: ContractDataSource;
49
+ #feeValidationConfig: FeeValidationConfig;
36
50
 
37
51
  constructor(
38
52
  nullifierSource: NullifierSource,
39
53
  publicStateSource: PublicStateSource,
40
- gasPortalAddress: EthAddress,
54
+ contractDataSource: ContractDataSource,
41
55
  globalVariables: GlobalVariables,
56
+ feeValidationConfig: FeeValidationConfig,
42
57
  log = createDebugLogger('aztec:sequencer:tx_validator'),
43
58
  ) {
44
59
  this.#nullifierSource = nullifierSource;
45
- this.#globalVariables = globalVariables;
46
60
  this.#publicStateSource = publicStateSource;
47
- this.#gasPortalAddress = gasPortalAddress;
48
-
61
+ this.#contractDataSource = contractDataSource;
62
+ this.#globalVariables = globalVariables;
63
+ this.#feeValidationConfig = feeValidationConfig;
49
64
  this.#log = log;
50
65
  }
51
66
 
@@ -71,9 +86,15 @@ export class TxValidator {
71
86
  }
72
87
 
73
88
  // skip already processed transactions
74
- if (tx instanceof Tx && (await this.#validateFee(tx)) === INVALID_TX) {
75
- invalidTxs.push(tx);
76
- continue;
89
+ if (tx instanceof Tx) {
90
+ if ((await this.#validateFee(tx)) === INVALID_TX) {
91
+ invalidTxs.push(tx);
92
+ continue;
93
+ }
94
+ if ((await this.#validateGasBalance(tx)) === INVALID_TX) {
95
+ invalidTxs.push(tx);
96
+ continue;
97
+ }
77
98
  }
78
99
 
79
100
  if (this.#validateMaxBlockNumber(tx) === INVALID_TX) {
@@ -150,30 +171,17 @@ export class TxValidator {
150
171
  return VALID_TX;
151
172
  }
152
173
 
153
- async #validateFee(tx: Tx): Promise<TxValidationStatus> {
174
+ async #validateGasBalance(tx: Tx): Promise<TxValidationStatus> {
154
175
  if (!tx.data.needsTeardown) {
155
- // TODO check if fees are mandatory and reject this tx
156
- this.#log.debug(`Tx ${Tx.getHash(tx)} doesn't pay for gas`);
157
176
  return VALID_TX;
158
177
  }
159
178
 
160
- const {
161
- // TODO what if there's more than one function call?
162
- // if we're to enshrine that teardown = 1 function call, then we should turn this into a single function call
163
- [PublicKernelPhase.TEARDOWN]: [teardownFn],
164
- } = AbstractPhaseManager.extractEnqueuedPublicCallsByPhase(tx.data, tx.enqueuedPublicFunctionCalls);
165
-
166
- if (!teardownFn) {
167
- this.#log.warn(
168
- `Rejecting tx ${Tx.getHash(tx)} because it should pay for gas but has no enqueued teardown function call`,
169
- );
170
- return INVALID_TX;
171
- }
179
+ const teardownFn = TxValidator.#extractFeeExecutionCall(tx)!;
172
180
 
173
181
  // TODO(#1204) if a generator index is used for the derived storage slot of a map, update it here as well
174
- const slot = pedersenHash([GAS_TOKEN_BALANCES_SLOT.toBuffer(), teardownFn.callContext.msgSender.toBuffer()]);
182
+ const slot = pedersenHash([GAS_TOKEN_BALANCES_SLOT, teardownFn.callContext.msgSender]);
175
183
  const gasBalance = await this.#publicStateSource.storageRead(
176
- getCanonicalGasTokenAddress(this.#gasPortalAddress),
184
+ getCanonicalGasTokenAddress(this.#feeValidationConfig.gasPortalAddress),
177
185
  slot,
178
186
  );
179
187
 
@@ -201,4 +209,55 @@ export class TxValidator {
201
209
  return VALID_TX;
202
210
  }
203
211
  }
212
+
213
+ async #validateFee(tx: Tx): Promise<TxValidationStatus> {
214
+ if (!tx.data.needsTeardown) {
215
+ // TODO check if fees are mandatory and reject this tx
216
+ this.#log.debug(`Tx ${Tx.getHash(tx)} doesn't pay for gas`);
217
+ return VALID_TX;
218
+ }
219
+
220
+ const teardownFn = TxValidator.#extractFeeExecutionCall(tx);
221
+ if (!teardownFn) {
222
+ this.#log.warn(
223
+ `Rejecting tx ${Tx.getHash(tx)} because it should pay for gas but has no enqueued teardown function call`,
224
+ );
225
+ return INVALID_TX;
226
+ }
227
+
228
+ const fpcAddress = teardownFn.contractAddress;
229
+ const contractClass = await this.#contractDataSource.getContract(fpcAddress);
230
+
231
+ if (!contractClass) {
232
+ return INVALID_TX;
233
+ }
234
+
235
+ if (fpcAddress.equals(getCanonicalGasTokenAddress(this.#feeValidationConfig.gasPortalAddress))) {
236
+ return VALID_TX;
237
+ }
238
+
239
+ for (const allowedContract of this.#feeValidationConfig.allowedFeePaymentContractInstances) {
240
+ if (fpcAddress.equals(allowedContract)) {
241
+ return VALID_TX;
242
+ }
243
+ }
244
+
245
+ for (const allowedContractClass of this.#feeValidationConfig.allowedFeePaymentContractClasses) {
246
+ if (contractClass.contractClassId.equals(allowedContractClass)) {
247
+ return VALID_TX;
248
+ }
249
+ }
250
+
251
+ return INVALID_TX;
252
+ }
253
+
254
+ static #extractFeeExecutionCall(tx: Tx): PublicCallRequest | undefined {
255
+ const {
256
+ // TODO what if there's more than one function call?
257
+ // if we're to enshrine that teardown = 1 function call, then we should turn this into a single function call
258
+ [PublicKernelPhase.TEARDOWN]: [teardownFn],
259
+ } = AbstractPhaseManager.extractEnqueuedPublicCallsByPhase(tx.data, tx.enqueuedPublicFunctionCalls);
260
+
261
+ return teardownFn;
262
+ }
204
263
  }
@@ -0,0 +1,32 @@
1
+ import { type AztecAddress, type EthAddress, type Fr, type GlobalVariables } from '@aztec/circuits.js';
2
+ import { type ContractDataSource } from '@aztec/types/contracts';
3
+ import { type MerkleTreeOperations } from '@aztec/world-state';
4
+
5
+ import { WorldStateDB, WorldStatePublicDB } from '../simulator/public_executor.js';
6
+ import { TxValidator } from './tx_validator.js';
7
+
8
+ export class TxValidatorFactory {
9
+ constructor(
10
+ private merkleTreeDb: MerkleTreeOperations,
11
+ private contractDataSource: ContractDataSource,
12
+ private gasPortalAddress: EthAddress,
13
+ ) {}
14
+
15
+ buildTxValidator(
16
+ globalVariables: GlobalVariables,
17
+ allowedFeePaymentContractClasses: Fr[],
18
+ allowedFeePaymentContractInstances: AztecAddress[],
19
+ ): TxValidator {
20
+ return new TxValidator(
21
+ new WorldStateDB(this.merkleTreeDb),
22
+ new WorldStatePublicDB(this.merkleTreeDb),
23
+ this.contractDataSource,
24
+ globalVariables,
25
+ {
26
+ allowedFeePaymentContractClasses,
27
+ allowedFeePaymentContractInstances,
28
+ gasPortalAddress: this.gasPortalAddress,
29
+ },
30
+ );
31
+ }
32
+ }
@@ -1,4 +1,4 @@
1
- import { Tx } from '@aztec/circuit-types';
1
+ import { type Tx } from '@aztec/circuit-types';
2
2
  import { CallRequest } from '@aztec/circuits.js';
3
3
 
4
4
  /**
@@ -1,7 +1,7 @@
1
1
  import {
2
- PublicKernelCircuitPrivateInputs,
3
- PublicKernelCircuitPublicInputs,
4
- PublicKernelTailCircuitPrivateInputs,
2
+ type PublicKernelCircuitPrivateInputs,
3
+ type PublicKernelCircuitPublicInputs,
4
+ type PublicKernelTailCircuitPrivateInputs,
5
5
  } from '@aztec/circuits.js';
6
6
 
7
7
  /**