@aztec/sequencer-client 0.0.0-test.0

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 (110) hide show
  1. package/README.md +45 -0
  2. package/dest/client/index.d.ts +2 -0
  3. package/dest/client/index.d.ts.map +1 -0
  4. package/dest/client/index.js +1 -0
  5. package/dest/client/sequencer-client.d.ts +71 -0
  6. package/dest/client/sequencer-client.d.ts.map +1 -0
  7. package/dest/client/sequencer-client.js +117 -0
  8. package/dest/config.d.ts +29 -0
  9. package/dest/config.d.ts.map +1 -0
  10. package/dest/config.js +143 -0
  11. package/dest/global_variable_builder/global_builder.d.ts +32 -0
  12. package/dest/global_variable_builder/global_builder.d.ts.map +1 -0
  13. package/dest/global_variable_builder/global_builder.js +79 -0
  14. package/dest/global_variable_builder/index.d.ts +2 -0
  15. package/dest/global_variable_builder/index.d.ts.map +1 -0
  16. package/dest/global_variable_builder/index.js +1 -0
  17. package/dest/index.d.ts +8 -0
  18. package/dest/index.d.ts.map +1 -0
  19. package/dest/index.js +9 -0
  20. package/dest/publisher/config.d.ts +31 -0
  21. package/dest/publisher/config.d.ts.map +1 -0
  22. package/dest/publisher/config.js +35 -0
  23. package/dest/publisher/index.d.ts +2 -0
  24. package/dest/publisher/index.d.ts.map +1 -0
  25. package/dest/publisher/index.js +1 -0
  26. package/dest/publisher/sequencer-publisher-metrics.d.ts +25 -0
  27. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -0
  28. package/dest/publisher/sequencer-publisher-metrics.js +129 -0
  29. package/dest/publisher/sequencer-publisher.d.ts +152 -0
  30. package/dest/publisher/sequencer-publisher.d.ts.map +1 -0
  31. package/dest/publisher/sequencer-publisher.js +481 -0
  32. package/dest/sequencer/allowed.d.ts +3 -0
  33. package/dest/sequencer/allowed.d.ts.map +1 -0
  34. package/dest/sequencer/allowed.js +27 -0
  35. package/dest/sequencer/config.d.ts +2 -0
  36. package/dest/sequencer/config.d.ts.map +1 -0
  37. package/dest/sequencer/config.js +1 -0
  38. package/dest/sequencer/index.d.ts +4 -0
  39. package/dest/sequencer/index.d.ts.map +1 -0
  40. package/dest/sequencer/index.js +3 -0
  41. package/dest/sequencer/metrics.d.ts +24 -0
  42. package/dest/sequencer/metrics.d.ts.map +1 -0
  43. package/dest/sequencer/metrics.js +102 -0
  44. package/dest/sequencer/sequencer.d.ts +180 -0
  45. package/dest/sequencer/sequencer.d.ts.map +1 -0
  46. package/dest/sequencer/sequencer.js +623 -0
  47. package/dest/sequencer/timetable.d.ts +38 -0
  48. package/dest/sequencer/timetable.d.ts.map +1 -0
  49. package/dest/sequencer/timetable.js +110 -0
  50. package/dest/sequencer/utils.d.ts +48 -0
  51. package/dest/sequencer/utils.d.ts.map +1 -0
  52. package/dest/sequencer/utils.js +53 -0
  53. package/dest/slasher/factory.d.ts +7 -0
  54. package/dest/slasher/factory.d.ts.map +1 -0
  55. package/dest/slasher/factory.js +8 -0
  56. package/dest/slasher/index.d.ts +3 -0
  57. package/dest/slasher/index.d.ts.map +1 -0
  58. package/dest/slasher/index.js +2 -0
  59. package/dest/slasher/slasher_client.d.ts +75 -0
  60. package/dest/slasher/slasher_client.d.ts.map +1 -0
  61. package/dest/slasher/slasher_client.js +132 -0
  62. package/dest/test/index.d.ts +17 -0
  63. package/dest/test/index.d.ts.map +1 -0
  64. package/dest/test/index.js +10 -0
  65. package/dest/tx_validator/archive_cache.d.ts +14 -0
  66. package/dest/tx_validator/archive_cache.d.ts.map +1 -0
  67. package/dest/tx_validator/archive_cache.js +22 -0
  68. package/dest/tx_validator/gas_validator.d.ts +14 -0
  69. package/dest/tx_validator/gas_validator.d.ts.map +1 -0
  70. package/dest/tx_validator/gas_validator.js +78 -0
  71. package/dest/tx_validator/nullifier_cache.d.ts +16 -0
  72. package/dest/tx_validator/nullifier_cache.d.ts.map +1 -0
  73. package/dest/tx_validator/nullifier_cache.js +24 -0
  74. package/dest/tx_validator/phases_validator.d.ts +12 -0
  75. package/dest/tx_validator/phases_validator.d.ts.map +1 -0
  76. package/dest/tx_validator/phases_validator.js +80 -0
  77. package/dest/tx_validator/test_utils.d.ts +23 -0
  78. package/dest/tx_validator/test_utils.d.ts.map +1 -0
  79. package/dest/tx_validator/test_utils.js +26 -0
  80. package/dest/tx_validator/tx_validator_factory.d.ts +18 -0
  81. package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -0
  82. package/dest/tx_validator/tx_validator_factory.js +50 -0
  83. package/package.json +121 -0
  84. package/src/client/index.ts +1 -0
  85. package/src/client/sequencer-client.ts +219 -0
  86. package/src/config.ts +179 -0
  87. package/src/global_variable_builder/global_builder.ts +108 -0
  88. package/src/global_variable_builder/index.ts +1 -0
  89. package/src/index.ts +10 -0
  90. package/src/publisher/config.ts +75 -0
  91. package/src/publisher/index.ts +1 -0
  92. package/src/publisher/sequencer-publisher-metrics.ts +176 -0
  93. package/src/publisher/sequencer-publisher.ts +625 -0
  94. package/src/sequencer/allowed.ts +36 -0
  95. package/src/sequencer/config.ts +1 -0
  96. package/src/sequencer/index.ts +3 -0
  97. package/src/sequencer/metrics.ts +137 -0
  98. package/src/sequencer/sequencer.ts +759 -0
  99. package/src/sequencer/timetable.ts +123 -0
  100. package/src/sequencer/utils.ts +74 -0
  101. package/src/slasher/factory.ts +15 -0
  102. package/src/slasher/index.ts +2 -0
  103. package/src/slasher/slasher_client.ts +193 -0
  104. package/src/test/index.ts +20 -0
  105. package/src/tx_validator/archive_cache.ts +28 -0
  106. package/src/tx_validator/gas_validator.ts +101 -0
  107. package/src/tx_validator/nullifier_cache.ts +30 -0
  108. package/src/tx_validator/phases_validator.ts +98 -0
  109. package/src/tx_validator/test_utils.ts +48 -0
  110. package/src/tx_validator/tx_validator_factory.ts +120 -0
@@ -0,0 +1,98 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+ import { ContractsDataSourcePublicDB, getExecutionRequestsByPhase } from '@aztec/simulator/server';
3
+ import type { ContractDataSource } from '@aztec/stdlib/contract';
4
+ import type { AllowedElement } from '@aztec/stdlib/interfaces/server';
5
+ import {
6
+ type PublicExecutionRequest,
7
+ Tx,
8
+ TxExecutionPhase,
9
+ type TxValidationResult,
10
+ type TxValidator,
11
+ } from '@aztec/stdlib/tx';
12
+
13
+ export class PhasesTxValidator implements TxValidator<Tx> {
14
+ #log = createLogger('sequencer:tx_validator:tx_phases');
15
+ private contractDataSource: ContractsDataSourcePublicDB;
16
+
17
+ constructor(contracts: ContractDataSource, private setupAllowList: AllowedElement[]) {
18
+ this.contractDataSource = new ContractsDataSourcePublicDB(contracts);
19
+ }
20
+
21
+ async validateTx(tx: Tx): Promise<TxValidationResult> {
22
+ try {
23
+ // TODO(@spalladino): We add this just to handle public authwit-check calls during setup
24
+ // which are needed for public FPC flows, but fail if the account contract hasnt been deployed yet,
25
+ // which is what we're trying to do as part of the current txs.
26
+ await this.contractDataSource.addNewContracts(tx);
27
+
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' };
31
+ }
32
+
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
+ }
45
+ }
46
+
47
+ return { result: 'valid' };
48
+ } finally {
49
+ this.contractDataSource.clearContractsForTx();
50
+ }
51
+ }
52
+
53
+ async isOnAllowList(publicCall: PublicExecutionRequest, allowList: AllowedElement[]): Promise<boolean> {
54
+ if (publicCall.isEmpty()) {
55
+ return true;
56
+ }
57
+
58
+ const { contractAddress, functionSelector } = publicCall.callContext;
59
+
60
+ // do these checks first since they don't require the contract class
61
+ for (const entry of allowList) {
62
+ if ('address' in entry && !('selector' in entry)) {
63
+ if (contractAddress.equals(entry.address)) {
64
+ return true;
65
+ }
66
+ }
67
+
68
+ if ('address' in entry && 'selector' in entry) {
69
+ if (contractAddress.equals(entry.address) && entry.selector.equals(functionSelector)) {
70
+ return true;
71
+ }
72
+ }
73
+
74
+ const contractClass = await this.contractDataSource.getContractInstance(contractAddress);
75
+
76
+ if (!contractClass) {
77
+ throw new Error(`Contract not found: ${contractAddress}`);
78
+ }
79
+
80
+ if ('classId' in entry && !('selector' in entry)) {
81
+ if (contractClass.currentContractClassId.equals(entry.classId)) {
82
+ return true;
83
+ }
84
+ }
85
+
86
+ if ('classId' in entry && 'selector' in entry) {
87
+ if (
88
+ contractClass.currentContractClassId.equals(entry.classId) &&
89
+ (entry.selector === undefined || entry.selector.equals(functionSelector))
90
+ ) {
91
+ return true;
92
+ }
93
+ }
94
+ }
95
+
96
+ return false;
97
+ }
98
+ }
@@ -0,0 +1,48 @@
1
+ import type { Fr } from '@aztec/foundation/fields';
2
+ import type { FunctionSelector } from '@aztec/stdlib/abi';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import { computeVarArgsHash } from '@aztec/stdlib/hash';
5
+ import type { Tx } from '@aztec/stdlib/tx';
6
+
7
+ export function patchNonRevertibleFn(
8
+ tx: Tx,
9
+ index: number,
10
+ overrides: { address?: AztecAddress; selector: FunctionSelector; args?: Fr[]; msgSender?: AztecAddress },
11
+ ): Promise<{ address: AztecAddress; selector: FunctionSelector }> {
12
+ return patchFn('nonRevertibleAccumulatedData', tx, index, overrides);
13
+ }
14
+
15
+ export function patchRevertibleFn(
16
+ tx: Tx,
17
+ index: number,
18
+ overrides: { address?: AztecAddress; selector: FunctionSelector; args?: Fr[]; msgSender?: AztecAddress },
19
+ ): Promise<{ address: AztecAddress; selector: FunctionSelector }> {
20
+ return patchFn('revertibleAccumulatedData', tx, index, overrides);
21
+ }
22
+
23
+ async function patchFn(
24
+ where: 'revertibleAccumulatedData' | 'nonRevertibleAccumulatedData',
25
+ tx: Tx,
26
+ index: number,
27
+ overrides: { address?: AztecAddress; selector: FunctionSelector; args?: Fr[]; msgSender?: AztecAddress },
28
+ ): Promise<{ address: AztecAddress; selector: FunctionSelector }> {
29
+ const fn = tx.enqueuedPublicFunctionCalls.at(-1 * index - 1)!;
30
+ fn.callContext.contractAddress = overrides.address ?? fn.callContext.contractAddress;
31
+ fn.callContext.functionSelector = overrides.selector;
32
+ fn.args = overrides.args ?? fn.args;
33
+ fn.callContext.msgSender = overrides.msgSender ?? fn.callContext.msgSender;
34
+ tx.enqueuedPublicFunctionCalls[index] = fn;
35
+
36
+ const request = tx.data.forPublic![where].publicCallRequests[index];
37
+ request.contractAddress = fn.callContext.contractAddress;
38
+ request.msgSender = fn.callContext.msgSender;
39
+ request.functionSelector = fn.callContext.functionSelector;
40
+ request.isStaticCall = fn.callContext.isStaticCall;
41
+ request.argsHash = await computeVarArgsHash(fn.args);
42
+ tx.data.forPublic![where].publicCallRequests[index] = request;
43
+
44
+ return {
45
+ address: fn.callContext.contractAddress,
46
+ selector: fn.callContext.functionSelector,
47
+ };
48
+ }
@@ -0,0 +1,120 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import {
3
+ AggregateTxValidator,
4
+ BlockHeaderTxValidator,
5
+ DataTxValidator,
6
+ DoubleSpendTxValidator,
7
+ MetadataTxValidator,
8
+ TxProofValidator,
9
+ } from '@aztec/p2p';
10
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
11
+ import { readPublicState } from '@aztec/simulator/server';
12
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
13
+ import type { ContractDataSource } from '@aztec/stdlib/contract';
14
+ import type { GasFees } from '@aztec/stdlib/gas';
15
+ import type {
16
+ AllowedElement,
17
+ ClientProtocolCircuitVerifier,
18
+ MerkleTreeReadOperations,
19
+ } from '@aztec/stdlib/interfaces/server';
20
+ import { GlobalVariables, type ProcessedTx, type Tx, type TxValidator } from '@aztec/stdlib/tx';
21
+
22
+ import { ArchiveCache } from './archive_cache.js';
23
+ import { GasTxValidator, type PublicStateSource } from './gas_validator.js';
24
+ import { NullifierCache } from './nullifier_cache.js';
25
+ import { PhasesTxValidator } from './phases_validator.js';
26
+
27
+ export function createValidatorForAcceptingTxs(
28
+ db: MerkleTreeReadOperations,
29
+ contractDataSource: ContractDataSource,
30
+ verifier: ClientProtocolCircuitVerifier | undefined,
31
+ {
32
+ blockNumber,
33
+ l1ChainId,
34
+ setupAllowList,
35
+ gasFees,
36
+ skipFeeEnforcement,
37
+ }: {
38
+ blockNumber: number;
39
+ l1ChainId: number;
40
+ setupAllowList: AllowedElement[];
41
+ gasFees: GasFees;
42
+ skipFeeEnforcement?: boolean;
43
+ },
44
+ ): TxValidator<Tx> {
45
+ const validators: TxValidator<Tx>[] = [
46
+ new DataTxValidator(),
47
+ new MetadataTxValidator(new Fr(l1ChainId), new Fr(blockNumber)),
48
+ new DoubleSpendTxValidator(new NullifierCache(db)),
49
+ new PhasesTxValidator(contractDataSource, setupAllowList),
50
+ new BlockHeaderTxValidator(new ArchiveCache(db)),
51
+ ];
52
+
53
+ if (!skipFeeEnforcement) {
54
+ validators.push(new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, gasFees));
55
+ }
56
+
57
+ if (verifier) {
58
+ validators.push(new TxProofValidator(verifier));
59
+ }
60
+
61
+ return new AggregateTxValidator(...validators);
62
+ }
63
+
64
+ export function createValidatorsForBlockBuilding(
65
+ db: MerkleTreeReadOperations,
66
+ contractDataSource: ContractDataSource,
67
+ globalVariables: GlobalVariables,
68
+ setupAllowList: AllowedElement[],
69
+ ): {
70
+ preprocessValidator: TxValidator<Tx>;
71
+ postprocessValidator: TxValidator<ProcessedTx>;
72
+ nullifierCache: NullifierCache;
73
+ } {
74
+ const nullifierCache = new NullifierCache(db);
75
+ const archiveCache = new ArchiveCache(db);
76
+ const publicStateSource = new DatabasePublicStateSource(db);
77
+
78
+ return {
79
+ preprocessValidator: preprocessValidator(
80
+ nullifierCache,
81
+ archiveCache,
82
+ publicStateSource,
83
+ contractDataSource,
84
+ globalVariables,
85
+ setupAllowList,
86
+ ),
87
+ postprocessValidator: postprocessValidator(nullifierCache),
88
+ nullifierCache,
89
+ };
90
+ }
91
+
92
+ class DatabasePublicStateSource implements PublicStateSource {
93
+ constructor(private db: MerkleTreeReadOperations) {}
94
+
95
+ storageRead(contractAddress: AztecAddress, slot: Fr): Promise<Fr> {
96
+ return readPublicState(this.db, contractAddress, slot);
97
+ }
98
+ }
99
+
100
+ function preprocessValidator(
101
+ nullifierCache: NullifierCache,
102
+ archiveCache: ArchiveCache,
103
+ publicStateSource: PublicStateSource,
104
+ contractDataSource: ContractDataSource,
105
+ globalVariables: GlobalVariables,
106
+ setupAllowList: AllowedElement[],
107
+ ): TxValidator<Tx> {
108
+ // We don't include the TxProofValidator nor the DataTxValidator here because they are already checked by the time we get to block building.
109
+ return new AggregateTxValidator(
110
+ new MetadataTxValidator(globalVariables.chainId, globalVariables.blockNumber),
111
+ new DoubleSpendTxValidator(nullifierCache),
112
+ new PhasesTxValidator(contractDataSource, setupAllowList),
113
+ new GasTxValidator(publicStateSource, ProtocolContractAddress.FeeJuice, globalVariables.gasFees),
114
+ new BlockHeaderTxValidator(archiveCache),
115
+ );
116
+ }
117
+
118
+ function postprocessValidator(nullifierCache: NullifierCache): TxValidator<ProcessedTx> {
119
+ return new DoubleSpendTxValidator(nullifierCache);
120
+ }