@aztec/sequencer-client 0.69.0 → 0.69.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 (60) hide show
  1. package/dest/client/sequencer-client.d.ts +2 -0
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +3 -4
  4. package/dest/config.d.ts.map +1 -1
  5. package/dest/config.js +11 -1
  6. package/dest/index.d.ts +3 -1
  7. package/dest/index.d.ts.map +1 -1
  8. package/dest/index.js +4 -2
  9. package/dest/publisher/config.d.ts +4 -0
  10. package/dest/publisher/config.d.ts.map +1 -1
  11. package/dest/publisher/config.js +6 -1
  12. package/dest/publisher/l1-publisher.d.ts +36 -11
  13. package/dest/publisher/l1-publisher.d.ts.map +1 -1
  14. package/dest/publisher/l1-publisher.js +154 -88
  15. package/dest/sequencer/index.d.ts +1 -0
  16. package/dest/sequencer/index.d.ts.map +1 -1
  17. package/dest/sequencer/index.js +2 -1
  18. package/dest/sequencer/sequencer.d.ts +9 -16
  19. package/dest/sequencer/sequencer.d.ts.map +1 -1
  20. package/dest/sequencer/sequencer.js +61 -130
  21. package/dest/sequencer/utils.d.ts +2 -2
  22. package/dest/sequencer/utils.d.ts.map +1 -1
  23. package/dest/sequencer/utils.js +3 -3
  24. package/dest/slasher/factory.d.ts +11 -0
  25. package/dest/slasher/factory.d.ts.map +1 -0
  26. package/dest/slasher/factory.js +10 -0
  27. package/dest/slasher/index.d.ts +3 -0
  28. package/dest/slasher/index.d.ts.map +1 -0
  29. package/dest/slasher/index.js +3 -0
  30. package/dest/slasher/slasher_client.d.ts +127 -0
  31. package/dest/slasher/slasher_client.d.ts.map +1 -0
  32. package/dest/slasher/slasher_client.js +305 -0
  33. package/dest/tx_validator/gas_validator.d.ts +2 -3
  34. package/dest/tx_validator/gas_validator.d.ts.map +1 -1
  35. package/dest/tx_validator/gas_validator.js +9 -22
  36. package/dest/tx_validator/nullifier_cache.d.ts +16 -0
  37. package/dest/tx_validator/nullifier_cache.d.ts.map +1 -0
  38. package/dest/tx_validator/nullifier_cache.js +24 -0
  39. package/dest/tx_validator/phases_validator.d.ts +2 -3
  40. package/dest/tx_validator/phases_validator.d.ts.map +1 -1
  41. package/dest/tx_validator/phases_validator.js +15 -24
  42. package/dest/tx_validator/tx_validator_factory.d.ts +15 -14
  43. package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -1
  44. package/dest/tx_validator/tx_validator_factory.js +38 -24
  45. package/package.json +21 -19
  46. package/src/client/sequencer-client.ts +5 -2
  47. package/src/config.ts +10 -0
  48. package/src/index.ts +3 -1
  49. package/src/publisher/config.ts +10 -0
  50. package/src/publisher/l1-publisher.ts +180 -97
  51. package/src/sequencer/index.ts +1 -0
  52. package/src/sequencer/sequencer.ts +70 -180
  53. package/src/sequencer/utils.ts +2 -2
  54. package/src/slasher/factory.ts +22 -0
  55. package/src/slasher/index.ts +2 -0
  56. package/src/slasher/slasher_client.ts +402 -0
  57. package/src/tx_validator/gas_validator.ts +11 -24
  58. package/src/tx_validator/nullifier_cache.ts +29 -0
  59. package/src/tx_validator/phases_validator.ts +22 -33
  60. package/src/tx_validator/tx_validator_factory.ts +82 -40
@@ -1,65 +1,107 @@
1
1
  import {
2
2
  type AllowedElement,
3
- MerkleTreeId,
3
+ type ClientProtocolCircuitVerifier,
4
4
  type MerkleTreeReadOperations,
5
5
  type ProcessedTx,
6
6
  type Tx,
7
7
  type TxValidator,
8
8
  } from '@aztec/circuit-types';
9
- import { type ContractDataSource, type GlobalVariables } from '@aztec/circuits.js';
9
+ import { type AztecAddress, type ContractDataSource, Fr, type GasFees, type GlobalVariables } from '@aztec/circuits.js';
10
10
  import {
11
11
  AggregateTxValidator,
12
12
  DataTxValidator,
13
13
  DoubleSpendTxValidator,
14
14
  MetadataTxValidator,
15
- type NullifierSource,
15
+ TxProofValidator,
16
16
  } from '@aztec/p2p';
17
17
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
18
18
  import { readPublicState } from '@aztec/simulator';
19
19
 
20
20
  import { GasTxValidator, type PublicStateSource } from './gas_validator.js';
21
+ import { NullifierCache } from './nullifier_cache.js';
21
22
  import { PhasesTxValidator } from './phases_validator.js';
22
23
 
23
- export class TxValidatorFactory {
24
- nullifierSource: NullifierSource;
25
- publicStateSource: PublicStateSource;
26
- constructor(
27
- private committedDb: MerkleTreeReadOperations,
28
- private contractDataSource: ContractDataSource,
29
- private enforceFees: boolean,
30
- ) {
31
- this.nullifierSource = {
32
- getNullifierIndices: nullifiers =>
33
- this.committedDb
34
- .findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers)
35
- .then(x => x.filter(index => index !== undefined) as bigint[]),
36
- };
24
+ export function createValidatorForAcceptingTxs(
25
+ db: MerkleTreeReadOperations,
26
+ contractDataSource: ContractDataSource,
27
+ verifier: ClientProtocolCircuitVerifier | undefined,
28
+ data: {
29
+ blockNumber: number;
30
+ l1ChainId: number;
31
+ enforceFees: boolean;
32
+ setupAllowList: AllowedElement[];
33
+ gasFees: GasFees;
34
+ },
35
+ ): TxValidator<Tx> {
36
+ const { blockNumber, l1ChainId, enforceFees, setupAllowList, gasFees } = data;
37
+ const validators: TxValidator<Tx>[] = [
38
+ new DataTxValidator(),
39
+ new MetadataTxValidator(new Fr(l1ChainId), new Fr(blockNumber)),
40
+ new DoubleSpendTxValidator(new NullifierCache(db)),
41
+ new PhasesTxValidator(contractDataSource, setupAllowList),
42
+ new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, enforceFees, gasFees),
43
+ ];
37
44
 
38
- this.publicStateSource = {
39
- storageRead: (contractAddress, slot) => {
40
- return readPublicState(this.committedDb, contractAddress, slot);
41
- },
42
- };
45
+ if (verifier) {
46
+ validators.push(new TxProofValidator(verifier));
43
47
  }
44
48
 
45
- validatorForNewTxs(globalVariables: GlobalVariables, setupAllowList: AllowedElement[]): TxValidator<Tx> {
46
- return new AggregateTxValidator(
47
- new DataTxValidator(),
48
- new MetadataTxValidator(globalVariables.chainId, globalVariables.blockNumber),
49
- new DoubleSpendTxValidator(this.nullifierSource),
50
- new PhasesTxValidator(this.contractDataSource, setupAllowList),
51
- new GasTxValidator(
52
- this.publicStateSource,
53
- ProtocolContractAddress.FeeJuice,
54
- this.enforceFees,
55
- globalVariables.gasFees,
56
- ),
57
- );
58
- }
49
+ return new AggregateTxValidator(...validators);
50
+ }
51
+
52
+ export function createValidatorsForBlockBuilding(
53
+ db: MerkleTreeReadOperations,
54
+ contractDataSource: ContractDataSource,
55
+ globalVariables: GlobalVariables,
56
+ enforceFees: boolean,
57
+ setupAllowList: AllowedElement[],
58
+ ): {
59
+ preprocessValidator: TxValidator<Tx>;
60
+ postprocessValidator: TxValidator<ProcessedTx>;
61
+ nullifierCache: NullifierCache;
62
+ } {
63
+ const nullifierCache = new NullifierCache(db);
64
+ const publicStateSource = new DatabasePublicStateSource(db);
65
+
66
+ return {
67
+ preprocessValidator: preprocessValidator(
68
+ nullifierCache,
69
+ publicStateSource,
70
+ contractDataSource,
71
+ enforceFees,
72
+ globalVariables,
73
+ setupAllowList,
74
+ ),
75
+ postprocessValidator: postprocessValidator(nullifierCache),
76
+ nullifierCache,
77
+ };
78
+ }
59
79
 
60
- validatorForProcessedTxs(fork: MerkleTreeReadOperations): TxValidator<ProcessedTx> {
61
- return new DoubleSpendTxValidator({
62
- getNullifierIndices: nullifiers => fork.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers),
63
- });
80
+ class DatabasePublicStateSource implements PublicStateSource {
81
+ constructor(private db: MerkleTreeReadOperations) {}
82
+
83
+ storageRead(contractAddress: AztecAddress, slot: Fr): Promise<Fr> {
84
+ return readPublicState(this.db, contractAddress, slot);
64
85
  }
65
86
  }
87
+
88
+ function preprocessValidator(
89
+ nullifierCache: NullifierCache,
90
+ publicStateSource: PublicStateSource,
91
+ contractDataSource: ContractDataSource,
92
+ enforceFees: boolean,
93
+ globalVariables: GlobalVariables,
94
+ setupAllowList: AllowedElement[],
95
+ ): TxValidator<Tx> {
96
+ // We don't include the TxProofValidator nor the DataTxValidator here because they are already checked by the time we get to block building.
97
+ return new AggregateTxValidator(
98
+ new MetadataTxValidator(globalVariables.chainId, globalVariables.blockNumber),
99
+ new DoubleSpendTxValidator(nullifierCache),
100
+ new PhasesTxValidator(contractDataSource, setupAllowList),
101
+ new GasTxValidator(publicStateSource, ProtocolContractAddress.FeeJuice, enforceFees, globalVariables.gasFees),
102
+ );
103
+ }
104
+
105
+ function postprocessValidator(nullifierCache: NullifierCache): TxValidator<ProcessedTx> {
106
+ return new DoubleSpendTxValidator(nullifierCache);
107
+ }