@aztec/sequencer-client 0.69.0-devnet → 0.69.1-devnet

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 (70) 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 +2 -1
  7. package/dest/index.d.ts.map +1 -1
  8. package/dest/index.js +3 -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/index.d.ts +0 -1
  13. package/dest/publisher/index.d.ts.map +1 -1
  14. package/dest/publisher/index.js +1 -2
  15. package/dest/publisher/l1-publisher.d.ts +21 -2
  16. package/dest/publisher/l1-publisher.d.ts.map +1 -1
  17. package/dest/publisher/l1-publisher.js +91 -95
  18. package/dest/sequencer/index.d.ts +1 -0
  19. package/dest/sequencer/index.d.ts.map +1 -1
  20. package/dest/sequencer/index.js +2 -1
  21. package/dest/sequencer/sequencer.d.ts +21 -30
  22. package/dest/sequencer/sequencer.d.ts.map +1 -1
  23. package/dest/sequencer/sequencer.js +60 -130
  24. package/dest/sequencer/utils.d.ts +2 -2
  25. package/dest/sequencer/utils.d.ts.map +1 -1
  26. package/dest/sequencer/utils.js +3 -3
  27. package/dest/test/index.d.ts +18 -0
  28. package/dest/test/index.d.ts.map +1 -0
  29. package/dest/test/index.js +8 -0
  30. package/dest/{publisher → test}/test-l1-publisher.d.ts +1 -1
  31. package/dest/test/test-l1-publisher.d.ts.map +1 -0
  32. package/dest/test/test-l1-publisher.js +11 -0
  33. package/dest/tx_validator/archive_cache.d.ts +14 -0
  34. package/dest/tx_validator/archive_cache.d.ts.map +1 -0
  35. package/dest/tx_validator/archive_cache.js +22 -0
  36. package/dest/tx_validator/gas_validator.d.ts +2 -3
  37. package/dest/tx_validator/gas_validator.d.ts.map +1 -1
  38. package/dest/tx_validator/gas_validator.js +9 -22
  39. package/dest/tx_validator/nullifier_cache.d.ts +16 -0
  40. package/dest/tx_validator/nullifier_cache.d.ts.map +1 -0
  41. package/dest/tx_validator/nullifier_cache.js +24 -0
  42. package/dest/tx_validator/phases_validator.d.ts +2 -3
  43. package/dest/tx_validator/phases_validator.d.ts.map +1 -1
  44. package/dest/tx_validator/phases_validator.js +15 -24
  45. package/dest/tx_validator/tx_validator_factory.d.ts +15 -14
  46. package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -1
  47. package/dest/tx_validator/tx_validator_factory.js +41 -24
  48. package/package.json +23 -20
  49. package/src/client/sequencer-client.ts +5 -3
  50. package/src/config.ts +10 -0
  51. package/src/index.ts +2 -1
  52. package/src/publisher/config.ts +10 -0
  53. package/src/publisher/index.ts +0 -1
  54. package/src/publisher/l1-publisher.ts +119 -93
  55. package/src/sequencer/index.ts +1 -0
  56. package/src/sequencer/sequencer.ts +82 -193
  57. package/src/sequencer/utils.ts +2 -2
  58. package/src/test/index.ts +23 -0
  59. package/src/{publisher → test}/test-l1-publisher.ts +1 -1
  60. package/src/tx_validator/archive_cache.ts +27 -0
  61. package/src/tx_validator/gas_validator.ts +11 -24
  62. package/src/tx_validator/nullifier_cache.ts +29 -0
  63. package/src/tx_validator/phases_validator.ts +22 -33
  64. package/src/tx_validator/tx_validator_factory.ts +89 -40
  65. package/dest/publisher/test-l1-publisher.d.ts.map +0 -1
  66. package/dest/publisher/test-l1-publisher.js +0 -11
  67. package/dest/publisher/utils.d.ts +0 -2
  68. package/dest/publisher/utils.d.ts.map +0 -1
  69. package/dest/publisher/utils.js +0 -13
  70. package/src/publisher/utils.ts +0 -14
@@ -3,6 +3,7 @@ import {
3
3
  type PublicExecutionRequest,
4
4
  Tx,
5
5
  TxExecutionPhase,
6
+ type TxValidationResult,
6
7
  type TxValidator,
7
8
  } from '@aztec/circuit-types';
8
9
  import { type ContractDataSource } from '@aztec/circuits.js';
@@ -17,48 +18,36 @@ export class PhasesTxValidator implements TxValidator<Tx> {
17
18
  this.contractDataSource = new ContractsDataSourcePublicDB(contracts);
18
19
  }
19
20
 
20
- async validateTxs(txs: Tx[]): Promise<[validTxs: Tx[], invalidTxs: Tx[]]> {
21
- const validTxs: Tx[] = [];
22
- const invalidTxs: Tx[] = [];
23
-
24
- for (const tx of txs) {
21
+ async validateTx(tx: Tx): Promise<TxValidationResult> {
22
+ try {
25
23
  // TODO(@spalladino): We add this just to handle public authwit-check calls during setup
26
24
  // which are needed for public FPC flows, but fail if the account contract hasnt been deployed yet,
27
25
  // which is what we're trying to do as part of the current txs.
28
26
  await this.contractDataSource.addNewContracts(tx);
29
27
 
30
- if (await this.validateTx(tx)) {
31
- validTxs.push(tx);
32
- } else {
33
- invalidTxs.push(tx);
28
+ if (!tx.data.forPublic) {
29
+ this.#log.debug(`Tx ${Tx.getHash(tx)} does not contain enqueued public functions. Skipping phases validation.`);
30
+ return { result: 'valid' };
34
31
  }
35
32
 
36
- await this.contractDataSource.removeNewContracts(tx);
37
- }
38
-
39
- return Promise.resolve([validTxs, invalidTxs]);
40
- }
41
-
42
- async validateTx(tx: Tx): Promise<boolean> {
43
- if (!tx.data.forPublic) {
44
- this.#log.debug(`Tx ${Tx.getHash(tx)} does not contain enqueued public functions. Skipping phases validation.`);
45
- return true;
46
- }
47
-
48
- const setupFns = getExecutionRequestsByPhase(tx, TxExecutionPhase.SETUP);
49
- for (const setupFn of setupFns) {
50
- if (!(await this.isOnAllowList(setupFn, this.setupAllowList))) {
51
- this.#log.warn(
52
- `Rejecting tx ${Tx.getHash(tx)} because it calls setup function not on allow list: ${
53
- setupFn.callContext.contractAddress
54
- }:${setupFn.callContext.functionSelector}`,
55
- );
56
-
57
- return false;
33
+ const setupFns = getExecutionRequestsByPhase(tx, TxExecutionPhase.SETUP);
34
+ for (const setupFn of setupFns) {
35
+ if (!(await this.isOnAllowList(setupFn, this.setupAllowList))) {
36
+ this.#log.warn(
37
+ `Rejecting tx ${Tx.getHash(tx)} because it calls setup function not on allow list: ${
38
+ setupFn.callContext.contractAddress
39
+ }:${setupFn.callContext.functionSelector}`,
40
+ { allowList: this.setupAllowList },
41
+ );
42
+
43
+ return { result: 'invalid', reason: ['Setup function not on allow list'] };
44
+ }
58
45
  }
59
- }
60
46
 
61
- return true;
47
+ return { result: 'valid' };
48
+ } finally {
49
+ await this.contractDataSource.removeNewContracts(tx);
50
+ }
62
51
  }
63
52
 
64
53
  async isOnAllowList(publicCall: PublicExecutionRequest, allowList: AllowedElement[]): Promise<boolean> {
@@ -1,65 +1,114 @@
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
+ BlockHeaderTxValidator,
12
13
  DataTxValidator,
13
14
  DoubleSpendTxValidator,
14
15
  MetadataTxValidator,
15
- type NullifierSource,
16
+ TxProofValidator,
16
17
  } from '@aztec/p2p';
17
18
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
18
19
  import { readPublicState } from '@aztec/simulator';
19
20
 
21
+ import { ArchiveCache } from './archive_cache.js';
20
22
  import { GasTxValidator, type PublicStateSource } from './gas_validator.js';
23
+ import { NullifierCache } from './nullifier_cache.js';
21
24
  import { PhasesTxValidator } from './phases_validator.js';
22
25
 
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
- };
26
+ export function createValidatorForAcceptingTxs(
27
+ db: MerkleTreeReadOperations,
28
+ contractDataSource: ContractDataSource,
29
+ verifier: ClientProtocolCircuitVerifier | undefined,
30
+ data: {
31
+ blockNumber: number;
32
+ l1ChainId: number;
33
+ enforceFees: boolean;
34
+ setupAllowList: AllowedElement[];
35
+ gasFees: GasFees;
36
+ },
37
+ ): TxValidator<Tx> {
38
+ const { blockNumber, l1ChainId, enforceFees, setupAllowList, gasFees } = data;
39
+ const validators: TxValidator<Tx>[] = [
40
+ new DataTxValidator(),
41
+ new MetadataTxValidator(new Fr(l1ChainId), new Fr(blockNumber)),
42
+ new DoubleSpendTxValidator(new NullifierCache(db)),
43
+ new PhasesTxValidator(contractDataSource, setupAllowList),
44
+ new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, enforceFees, gasFees),
45
+ new BlockHeaderTxValidator(new ArchiveCache(db)),
46
+ ];
37
47
 
38
- this.publicStateSource = {
39
- storageRead: (contractAddress, slot) => {
40
- return readPublicState(this.committedDb, contractAddress, slot);
41
- },
42
- };
48
+ if (verifier) {
49
+ validators.push(new TxProofValidator(verifier));
43
50
  }
44
51
 
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
- }
52
+ return new AggregateTxValidator(...validators);
53
+ }
54
+
55
+ export function createValidatorsForBlockBuilding(
56
+ db: MerkleTreeReadOperations,
57
+ contractDataSource: ContractDataSource,
58
+ globalVariables: GlobalVariables,
59
+ enforceFees: boolean,
60
+ setupAllowList: AllowedElement[],
61
+ ): {
62
+ preprocessValidator: TxValidator<Tx>;
63
+ postprocessValidator: TxValidator<ProcessedTx>;
64
+ nullifierCache: NullifierCache;
65
+ } {
66
+ const nullifierCache = new NullifierCache(db);
67
+ const archiveCache = new ArchiveCache(db);
68
+ const publicStateSource = new DatabasePublicStateSource(db);
69
+
70
+ return {
71
+ preprocessValidator: preprocessValidator(
72
+ nullifierCache,
73
+ archiveCache,
74
+ publicStateSource,
75
+ contractDataSource,
76
+ enforceFees,
77
+ globalVariables,
78
+ setupAllowList,
79
+ ),
80
+ postprocessValidator: postprocessValidator(nullifierCache),
81
+ nullifierCache,
82
+ };
83
+ }
59
84
 
60
- validatorForProcessedTxs(fork: MerkleTreeReadOperations): TxValidator<ProcessedTx> {
61
- return new DoubleSpendTxValidator({
62
- getNullifierIndices: nullifiers => fork.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers),
63
- });
85
+ class DatabasePublicStateSource implements PublicStateSource {
86
+ constructor(private db: MerkleTreeReadOperations) {}
87
+
88
+ storageRead(contractAddress: AztecAddress, slot: Fr): Promise<Fr> {
89
+ return readPublicState(this.db, contractAddress, slot);
64
90
  }
65
91
  }
92
+
93
+ function preprocessValidator(
94
+ nullifierCache: NullifierCache,
95
+ archiveCache: ArchiveCache,
96
+ publicStateSource: PublicStateSource,
97
+ contractDataSource: ContractDataSource,
98
+ enforceFees: boolean,
99
+ globalVariables: GlobalVariables,
100
+ setupAllowList: AllowedElement[],
101
+ ): TxValidator<Tx> {
102
+ // We don't include the TxProofValidator nor the DataTxValidator here because they are already checked by the time we get to block building.
103
+ return new AggregateTxValidator(
104
+ new MetadataTxValidator(globalVariables.chainId, globalVariables.blockNumber),
105
+ new DoubleSpendTxValidator(nullifierCache),
106
+ new PhasesTxValidator(contractDataSource, setupAllowList),
107
+ new GasTxValidator(publicStateSource, ProtocolContractAddress.FeeJuice, enforceFees, globalVariables.gasFees),
108
+ new BlockHeaderTxValidator(archiveCache),
109
+ );
110
+ }
111
+
112
+ function postprocessValidator(nullifierCache: NullifierCache): TxValidator<ProcessedTx> {
113
+ return new DoubleSpendTxValidator(nullifierCache);
114
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-l1-publisher.d.ts","sourceRoot":"","sources":["../../src/publisher/test-l1-publisher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,KAAK,OAAO,EAAe,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,aAAa,EAAE,KAAK,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,MAAM,CAAC;AAEjG,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,eAAgB,SAAQ,WAAW;IACvC,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;cAEjB,kBAAkB,CACnC,OAAO,EAAE,iBAAiB,EAC1B,KAAK,EAAE,aAAa,GACnB,YAAY,CAAC,aAAa,EAAE,KAAK,EAAE,iBAAiB,CAAC;CAMzD"}
@@ -1,11 +0,0 @@
1
- import { withDelayer } from '@aztec/ethereum/test';
2
- import { L1Publisher } from './l1-publisher.js';
3
- export class TestL1Publisher extends L1Publisher {
4
- createWalletClient(account, chain) {
5
- const baseClient = super.createWalletClient(account, chain);
6
- const { client, delayer } = withDelayer(baseClient, { ethereumSlotDuration: this.ethereumSlotDuration });
7
- this.delayer = delayer;
8
- return client;
9
- }
10
- }
11
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC1sMS1wdWJsaXNoZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcHVibGlzaGVyL3Rlc3QtbDEtcHVibGlzaGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBZ0IsV0FBVyxFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFJakUsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBRWhELE1BQU0sT0FBTyxlQUFnQixTQUFRLFdBQVc7SUFHM0Isa0JBQWtCLENBQ25DLE9BQTBCLEVBQzFCLEtBQW9CO1FBRXBCLE1BQU0sVUFBVSxHQUFHLEtBQUssQ0FBQyxrQkFBa0IsQ0FBQyxPQUFPLEVBQUUsS0FBSyxDQUFDLENBQUM7UUFDNUQsTUFBTSxFQUFFLE1BQU0sRUFBRSxPQUFPLEVBQUUsR0FBRyxXQUFXLENBQUMsVUFBVSxFQUFFLEVBQUUsb0JBQW9CLEVBQUUsSUFBSSxDQUFDLG9CQUFvQixFQUFFLENBQUMsQ0FBQztRQUN6RyxJQUFJLENBQUMsT0FBTyxHQUFHLE9BQU8sQ0FBQztRQUN2QixPQUFPLE1BQU0sQ0FBQztJQUNoQixDQUFDO0NBQ0YifQ==
@@ -1,2 +0,0 @@
1
- export declare function prettyLogViemErrorMsg(err: any): any;
2
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/publisher/utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,OAW7C"}
@@ -1,13 +0,0 @@
1
- import { BaseError, ContractFunctionRevertedError } from 'viem';
2
- export function prettyLogViemErrorMsg(err) {
3
- if (err instanceof BaseError) {
4
- const revertError = err.walk(err => err instanceof ContractFunctionRevertedError);
5
- if (revertError instanceof ContractFunctionRevertedError) {
6
- const errorName = revertError.data?.errorName ?? '';
7
- const args = revertError.metaMessages && revertError.metaMessages?.length > 1 ? revertError.metaMessages[1].trimStart() : '';
8
- return `${errorName}${args}`;
9
- }
10
- }
11
- return err?.message ?? err;
12
- }
13
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcHVibGlzaGVyL3V0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxTQUFTLEVBQUUsNkJBQTZCLEVBQUUsTUFBTSxNQUFNLENBQUM7QUFFaEUsTUFBTSxVQUFVLHFCQUFxQixDQUFDLEdBQVE7SUFDNUMsSUFBSSxHQUFHLFlBQVksU0FBUyxFQUFFLENBQUM7UUFDN0IsTUFBTSxXQUFXLEdBQUcsR0FBRyxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsRUFBRSxDQUFDLEdBQUcsWUFBWSw2QkFBNkIsQ0FBQyxDQUFDO1FBQ2xGLElBQUksV0FBVyxZQUFZLDZCQUE2QixFQUFFLENBQUM7WUFDekQsTUFBTSxTQUFTLEdBQUcsV0FBVyxDQUFDLElBQUksRUFBRSxTQUFTLElBQUksRUFBRSxDQUFDO1lBQ3BELE1BQU0sSUFBSSxHQUNSLFdBQVcsQ0FBQyxZQUFZLElBQUksV0FBVyxDQUFDLFlBQVksRUFBRSxNQUFNLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxXQUFXLENBQUMsWUFBWSxDQUFDLENBQUMsQ0FBQyxDQUFDLFNBQVMsRUFBRSxDQUFDLENBQUMsQ0FBQyxFQUFFLENBQUM7WUFDbEgsT0FBTyxHQUFHLFNBQVMsR0FBRyxJQUFJLEVBQUUsQ0FBQztRQUMvQixDQUFDO0lBQ0gsQ0FBQztJQUNELE9BQU8sR0FBRyxFQUFFLE9BQU8sSUFBSSxHQUFHLENBQUM7QUFDN0IsQ0FBQyJ9
@@ -1,14 +0,0 @@
1
- import { BaseError, ContractFunctionRevertedError } from 'viem';
2
-
3
- export function prettyLogViemErrorMsg(err: any) {
4
- if (err instanceof BaseError) {
5
- const revertError = err.walk(err => err instanceof ContractFunctionRevertedError);
6
- if (revertError instanceof ContractFunctionRevertedError) {
7
- const errorName = revertError.data?.errorName ?? '';
8
- const args =
9
- revertError.metaMessages && revertError.metaMessages?.length > 1 ? revertError.metaMessages[1].trimStart() : '';
10
- return `${errorName}${args}`;
11
- }
12
- }
13
- return err?.message ?? err;
14
- }