@aztec/sequencer-client 0.0.0-test.1 → 0.0.1-commit.b655e406

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/dest/client/sequencer-client.d.ts +25 -25
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +65 -51
  4. package/dest/config.d.ts +6 -14
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +50 -54
  7. package/dest/global_variable_builder/global_builder.d.ts +11 -6
  8. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.js +39 -34
  10. package/dest/index.d.ts +1 -2
  11. package/dest/index.d.ts.map +1 -1
  12. package/dest/index.js +1 -2
  13. package/dest/publisher/config.d.ts +6 -8
  14. package/dest/publisher/config.d.ts.map +1 -1
  15. package/dest/publisher/config.js +19 -17
  16. package/dest/publisher/index.d.ts +2 -0
  17. package/dest/publisher/index.d.ts.map +1 -1
  18. package/dest/publisher/index.js +3 -0
  19. package/dest/publisher/sequencer-publisher-factory.d.ts +43 -0
  20. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
  21. package/dest/publisher/sequencer-publisher-factory.js +51 -0
  22. package/dest/publisher/sequencer-publisher-metrics.d.ts +2 -1
  23. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  24. package/dest/publisher/sequencer-publisher-metrics.js +37 -2
  25. package/dest/publisher/sequencer-publisher.d.ts +102 -69
  26. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  27. package/dest/publisher/sequencer-publisher.js +606 -212
  28. package/dest/sequencer/block_builder.d.ts +27 -0
  29. package/dest/sequencer/block_builder.d.ts.map +1 -0
  30. package/dest/sequencer/block_builder.js +130 -0
  31. package/dest/sequencer/config.d.ts +5 -0
  32. package/dest/sequencer/config.d.ts.map +1 -1
  33. package/dest/sequencer/errors.d.ts +11 -0
  34. package/dest/sequencer/errors.d.ts.map +1 -0
  35. package/dest/sequencer/errors.js +15 -0
  36. package/dest/sequencer/index.d.ts +1 -1
  37. package/dest/sequencer/index.d.ts.map +1 -1
  38. package/dest/sequencer/index.js +1 -1
  39. package/dest/sequencer/metrics.d.ts +18 -11
  40. package/dest/sequencer/metrics.d.ts.map +1 -1
  41. package/dest/sequencer/metrics.js +84 -50
  42. package/dest/sequencer/sequencer.d.ts +120 -81
  43. package/dest/sequencer/sequencer.d.ts.map +1 -1
  44. package/dest/sequencer/sequencer.js +589 -359
  45. package/dest/sequencer/timetable.d.ts +32 -20
  46. package/dest/sequencer/timetable.d.ts.map +1 -1
  47. package/dest/sequencer/timetable.js +57 -30
  48. package/dest/sequencer/utils.d.ts +11 -35
  49. package/dest/sequencer/utils.d.ts.map +1 -1
  50. package/dest/sequencer/utils.js +9 -47
  51. package/dest/test/index.d.ts +7 -0
  52. package/dest/test/index.d.ts.map +1 -1
  53. package/dest/test/index.js +0 -4
  54. package/dest/tx_validator/nullifier_cache.d.ts +0 -2
  55. package/dest/tx_validator/nullifier_cache.d.ts.map +1 -1
  56. package/dest/tx_validator/tx_validator_factory.d.ts +9 -10
  57. package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -1
  58. package/dest/tx_validator/tx_validator_factory.js +27 -24
  59. package/package.json +42 -43
  60. package/src/client/sequencer-client.ts +94 -84
  61. package/src/config.ts +57 -61
  62. package/src/global_variable_builder/global_builder.ts +44 -23
  63. package/src/index.ts +6 -2
  64. package/src/publisher/config.ts +26 -24
  65. package/src/publisher/index.ts +4 -0
  66. package/src/publisher/sequencer-publisher-factory.ts +90 -0
  67. package/src/publisher/sequencer-publisher-metrics.ts +24 -2
  68. package/src/publisher/sequencer-publisher.ts +729 -235
  69. package/src/sequencer/block_builder.ts +218 -0
  70. package/src/sequencer/config.ts +7 -0
  71. package/src/sequencer/errors.ts +21 -0
  72. package/src/sequencer/index.ts +1 -1
  73. package/src/sequencer/metrics.ts +109 -55
  74. package/src/sequencer/sequencer.ts +766 -415
  75. package/src/sequencer/timetable.ts +98 -33
  76. package/src/sequencer/utils.ts +17 -58
  77. package/src/test/index.ts +11 -4
  78. package/src/tx_validator/tx_validator_factory.ts +44 -32
  79. package/dest/sequencer/allowed.d.ts +0 -3
  80. package/dest/sequencer/allowed.d.ts.map +0 -1
  81. package/dest/sequencer/allowed.js +0 -27
  82. package/dest/slasher/factory.d.ts +0 -7
  83. package/dest/slasher/factory.d.ts.map +0 -1
  84. package/dest/slasher/factory.js +0 -8
  85. package/dest/slasher/index.d.ts +0 -3
  86. package/dest/slasher/index.d.ts.map +0 -1
  87. package/dest/slasher/index.js +0 -2
  88. package/dest/slasher/slasher_client.d.ts +0 -75
  89. package/dest/slasher/slasher_client.d.ts.map +0 -1
  90. package/dest/slasher/slasher_client.js +0 -132
  91. package/dest/tx_validator/archive_cache.d.ts +0 -14
  92. package/dest/tx_validator/archive_cache.d.ts.map +0 -1
  93. package/dest/tx_validator/archive_cache.js +0 -22
  94. package/dest/tx_validator/gas_validator.d.ts +0 -14
  95. package/dest/tx_validator/gas_validator.d.ts.map +0 -1
  96. package/dest/tx_validator/gas_validator.js +0 -78
  97. package/dest/tx_validator/phases_validator.d.ts +0 -12
  98. package/dest/tx_validator/phases_validator.d.ts.map +0 -1
  99. package/dest/tx_validator/phases_validator.js +0 -80
  100. package/dest/tx_validator/test_utils.d.ts +0 -23
  101. package/dest/tx_validator/test_utils.d.ts.map +0 -1
  102. package/dest/tx_validator/test_utils.js +0 -26
  103. package/src/sequencer/allowed.ts +0 -36
  104. package/src/slasher/factory.ts +0 -15
  105. package/src/slasher/index.ts +0 -2
  106. package/src/slasher/slasher_client.ts +0 -193
  107. package/src/tx_validator/archive_cache.ts +0 -28
  108. package/src/tx_validator/gas_validator.ts +0 -101
  109. package/src/tx_validator/phases_validator.ts +0 -98
  110. package/src/tx_validator/test_utils.ts +0 -48
@@ -1,132 +0,0 @@
1
- import { createEthereumChain } from '@aztec/ethereum';
2
- import { EthAddress } from '@aztec/foundation/eth-address';
3
- import { createLogger } from '@aztec/foundation/log';
4
- import { SlashFactoryAbi } from '@aztec/l1-artifacts';
5
- import { L2BlockSourceEvents } from '@aztec/stdlib/block';
6
- import { WithTracer, getTelemetryClient } from '@aztec/telemetry-client';
7
- import { createPublicClient, fallback, getAddress, getContract, http } from 'viem';
8
- /**
9
- * Enum defining the possible states of the Slasher client.
10
- */ export var SlasherClientState = /*#__PURE__*/ function(SlasherClientState) {
11
- SlasherClientState[SlasherClientState["IDLE"] = 0] = "IDLE";
12
- SlasherClientState[SlasherClientState["RUNNING"] = 1] = "RUNNING";
13
- SlasherClientState[SlasherClientState["STOPPED"] = 2] = "STOPPED";
14
- return SlasherClientState;
15
- }({});
16
- /**
17
- * @notice A Hypomeiones slasher client implementation
18
- *
19
- * Hypomeiones: a class of individuals in ancient Sparta who were considered inferior or lesser citizens compared
20
- * to the full Spartan citizens.
21
- *
22
- * The implementation here is less than ideal. It exists, not to be the end all be all, but to show that
23
- * slashing can be done with this mechanism.
24
- *
25
- * The implementation is VERY brute in the sense that it only looks for pruned blocks and then tries to slash
26
- * the full committee of that.
27
- * If it sees a prune, it will mark the full epoch as "to be slashed".
28
- *
29
- * Also, it is not particularly smart around what it should if there were to be multiple slashing events.
30
- *
31
- * A few improvements:
32
- * - Only vote on the proposal if it is possible to reach, e.g., if 6 votes are needed and only 4 slots are left don't vote.
33
- * - Stop voting on a payload once it is processed.
34
- * - Only vote on the proposal if it have not already been executed
35
- * - Caveat, we need to fully decide if it is acceptable to have the same payload address multiple times. In the current
36
- * slash factory that could mean slashing the same committee for the same error multiple times.
37
- * - Decide how to deal with multiple slashing events in the same round.
38
- * - This could be that multiple epochs are pruned in the same round, but with the current naive implementation we could end up
39
- * slashing only the first, because the "lifetime" of the second would have passed after that vote
40
- */ export class SlasherClient extends WithTracer {
41
- config;
42
- l2BlockSource;
43
- log;
44
- slashEvents;
45
- slashFactoryContract;
46
- // The amount to slash for a prune.
47
- // Note that we set it to 0, such that no actual slashing will happen, but the event will be fired,
48
- // showing that the slashing mechanism is working.
49
- slashingAmount;
50
- constructor(config, l2BlockSource, telemetry = getTelemetryClient(), log = createLogger('slasher')){
51
- super(telemetry, 'slasher'), this.config = config, this.l2BlockSource = l2BlockSource, this.log = log, this.slashEvents = [], this.slashFactoryContract = undefined, this.slashingAmount = 0n;
52
- if (config.l1Contracts.slashFactoryAddress && config.l1Contracts.slashFactoryAddress !== EthAddress.ZERO) {
53
- const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
54
- const publicClient = createPublicClient({
55
- chain: chain.chainInfo,
56
- transport: fallback(chain.rpcUrls.map((url)=>http(url))),
57
- pollingInterval: config.viemPollingIntervalMS
58
- });
59
- this.slashFactoryContract = getContract({
60
- address: getAddress(config.l1Contracts.slashFactoryAddress.toString()),
61
- abi: SlashFactoryAbi,
62
- client: publicClient
63
- });
64
- } else {
65
- this.log.warn('No slash factory address found, slashing will not be enabled');
66
- }
67
- this.log.info(`Slasher client initialized`);
68
- }
69
- start() {
70
- this.log.info('Starting Slasher client...');
71
- this.l2BlockSource.on(L2BlockSourceEvents.L2PruneDetected, this.handlePruneL2Blocks.bind(this));
72
- }
73
- // This is where we should put a bunch of the improvements mentioned earlier.
74
- async getSlashPayload(slotNumber) {
75
- if (!this.slashFactoryContract) {
76
- return undefined;
77
- }
78
- // As long as the slot is greater than the lifetime, we want to keep deleting the first element
79
- // since it will not make sense to include anymore.
80
- while(this.slashEvents.length > 0 && this.slashEvents[0].lifetime < slotNumber){
81
- this.slashEvents.shift();
82
- }
83
- if (this.slashEvents.length == 0) {
84
- return undefined;
85
- }
86
- const slashEvent = this.slashEvents[0];
87
- const [payloadAddress, isDeployed] = await this.slashFactoryContract.read.getAddressAndIsDeployed([
88
- slashEvent.epoch,
89
- slashEvent.amount
90
- ]);
91
- if (!isDeployed) {
92
- // The proposal cannot be executed until it is deployed
93
- this.log.verbose(`Voting on not yet deployed payload: ${payloadAddress}`);
94
- }
95
- return EthAddress.fromString(payloadAddress);
96
- }
97
- handleBlockStreamEvent(event) {
98
- this.log.debug(`Handling block stream event ${event.type}`);
99
- switch(event.type){
100
- case L2BlockSourceEvents.L2PruneDetected:
101
- this.handlePruneL2Blocks(event);
102
- break;
103
- default:
104
- {
105
- break;
106
- }
107
- }
108
- return Promise.resolve();
109
- }
110
- /**
111
- * Allows consumers to stop the instance of the slasher client.
112
- * 'ready' will now return 'false' and the running promise that keeps the client synced is interrupted.
113
- */ stop() {
114
- this.log.debug('Stopping Slasher client...');
115
- this.l2BlockSource.removeListener(L2BlockSourceEvents.L2PruneDetected, this.handlePruneL2Blocks.bind(this));
116
- this.log.info('Slasher client stopped.');
117
- }
118
- // I need to get the slot number from the block that was just pruned
119
- handlePruneL2Blocks(event) {
120
- const { slotNumber, epochNumber } = event;
121
- this.log.info(`Detected chain prune. Punishing the validators at epoch ${epochNumber}`);
122
- // Set the lifetime such that we have a full round that we could vote throughout.
123
- const slotsIntoRound = slotNumber % BigInt(this.config.slashingRoundSize);
124
- const toNext = slotsIntoRound == 0n ? 0n : BigInt(this.config.slashingRoundSize) - slotsIntoRound;
125
- const lifetime = slotNumber + toNext + BigInt(this.config.slashingRoundSize);
126
- this.slashEvents.push({
127
- epoch: epochNumber,
128
- amount: this.slashingAmount,
129
- lifetime
130
- });
131
- }
132
- }
@@ -1,14 +0,0 @@
1
- import type { Fr } from '@aztec/foundation/fields';
2
- import type { ArchiveSource } from '@aztec/p2p';
3
- import type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
4
- /**
5
- * Implements an archive source by checking a DB and an in-memory collection.
6
- * Intended for validating transactions as they are added to a block.
7
- */
8
- export declare class ArchiveCache implements ArchiveSource {
9
- private db;
10
- archives: Map<string, bigint>;
11
- constructor(db: MerkleTreeReadOperations);
12
- getArchiveIndices(archives: Fr[]): Promise<(bigint | undefined)[]>;
13
- }
14
- //# sourceMappingURL=archive_cache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"archive_cache.d.ts","sourceRoot":"","sources":["../../src/tx_validator/archive_cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAGhF;;;GAGG;AACH,qBAAa,YAAa,YAAW,aAAa;IAGpC,OAAO,CAAC,EAAE;IAFtB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAEV,EAAE,EAAE,wBAAwB;IAInC,iBAAiB,CAAC,QAAQ,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;CAWhF"}
@@ -1,22 +0,0 @@
1
- import { MerkleTreeId } from '@aztec/stdlib/trees';
2
- /**
3
- * Implements an archive source by checking a DB and an in-memory collection.
4
- * Intended for validating transactions as they are added to a block.
5
- */ export class ArchiveCache {
6
- db;
7
- archives;
8
- constructor(db){
9
- this.db = db;
10
- this.archives = new Map();
11
- }
12
- async getArchiveIndices(archives) {
13
- const toCheckDb = archives.filter((n)=>!this.archives.has(n.toString()));
14
- const dbHits = await this.db.findLeafIndices(MerkleTreeId.ARCHIVE, toCheckDb);
15
- dbHits.forEach((x, index)=>{
16
- if (x !== undefined) {
17
- this.archives.set(toCheckDb[index].toString(), x);
18
- }
19
- });
20
- return archives.map((n)=>this.archives.get(n.toString()));
21
- }
22
- }
@@ -1,14 +0,0 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
- import type { GasFees } from '@aztec/stdlib/gas';
4
- import { type Tx, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
5
- /** Provides a view into public contract state */
6
- export interface PublicStateSource {
7
- storageRead: (contractAddress: AztecAddress, slot: Fr) => Promise<Fr>;
8
- }
9
- export declare class GasTxValidator implements TxValidator<Tx> {
10
- #private;
11
- constructor(publicDataSource: PublicStateSource, feeJuiceAddress: AztecAddress, gasFees: GasFees);
12
- validateTx(tx: Tx): Promise<TxValidationResult>;
13
- }
14
- //# sourceMappingURL=gas_validator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gas_validator.d.ts","sourceRoot":"","sources":["../../src/tx_validator/gas_validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAK9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,EAAoB,KAAK,kBAAkB,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAExG,iDAAiD;AACjD,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,CAAC,eAAe,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,KAAK,OAAO,CAAC,EAAE,CAAC,CAAC;CACvE;AAED,qBAAa,cAAe,YAAW,WAAW,CAAC,EAAE,CAAC;;gBAMxC,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO;IAM1F,UAAU,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC;CA0EtD"}
@@ -1,78 +0,0 @@
1
- import { createLogger } from '@aztec/foundation/log';
2
- import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
3
- import { getExecutionRequestsByPhase } from '@aztec/simulator/server';
4
- import { FunctionSelector } from '@aztec/stdlib/abi';
5
- import { TxExecutionPhase } from '@aztec/stdlib/tx';
6
- export class GasTxValidator {
7
- #log = createLogger('sequencer:tx_validator:tx_gas');
8
- #publicDataSource;
9
- #feeJuiceAddress;
10
- #gasFees;
11
- constructor(publicDataSource, feeJuiceAddress, gasFees){
12
- this.#publicDataSource = publicDataSource;
13
- this.#feeJuiceAddress = feeJuiceAddress;
14
- this.#gasFees = gasFees;
15
- }
16
- async validateTx(tx) {
17
- if (await this.#shouldSkip(tx)) {
18
- return Promise.resolve({
19
- result: 'skipped',
20
- reason: [
21
- 'Insufficient fee per gas'
22
- ]
23
- });
24
- }
25
- return this.#validateTxFee(tx);
26
- }
27
- /**
28
- * Check whether the tx's max fees are valid for the current block, and skip if not.
29
- * We skip instead of invalidating since the tx may become eligible later.
30
- * Note that circuits check max fees even if fee payer is unset, so we
31
- * keep this validation even if the tx does not pay fees.
32
- */ async #shouldSkip(tx) {
33
- const gasSettings = tx.data.constants.txContext.gasSettings;
34
- // Skip the tx if its max fees are not enough for the current block's gas fees.
35
- const maxFeesPerGas = gasSettings.maxFeesPerGas;
36
- const notEnoughMaxFees = maxFeesPerGas.feePerDaGas.lt(this.#gasFees.feePerDaGas) || maxFeesPerGas.feePerL2Gas.lt(this.#gasFees.feePerL2Gas);
37
- if (notEnoughMaxFees) {
38
- this.#log.warn(`Skipping transaction ${await tx.getTxHash()} due to insufficient fee per gas`, {
39
- txMaxFeesPerGas: maxFeesPerGas.toInspect(),
40
- currentGasFees: this.#gasFees.toInspect()
41
- });
42
- }
43
- return notEnoughMaxFees;
44
- }
45
- async #validateTxFee(tx) {
46
- const feePayer = tx.data.feePayer;
47
- // Compute the maximum fee that this tx may pay, based on its gasLimits and maxFeePerGas
48
- const feeLimit = tx.data.constants.txContext.gasSettings.getFeeLimit();
49
- // Read current balance of the feePayer
50
- const initialBalance = await this.#publicDataSource.storageRead(this.#feeJuiceAddress, await computeFeePayerBalanceStorageSlot(feePayer));
51
- // If there is a claim in this tx that increases the fee payer balance in Fee Juice, add it to balance
52
- const setupFns = getExecutionRequestsByPhase(tx, TxExecutionPhase.SETUP);
53
- const increasePublicBalanceSelector = await FunctionSelector.fromSignature('_increase_public_balance((Field),u128)');
54
- const claimFunctionCall = setupFns.find((fn)=>fn.callContext.contractAddress.equals(this.#feeJuiceAddress) && fn.callContext.msgSender.equals(this.#feeJuiceAddress) && fn.args.length > 2 && // Public functions get routed through the dispatch function, whose first argument is the target function selector.
55
- fn.args[0].equals(increasePublicBalanceSelector.toField()) && fn.args[1].equals(feePayer.toField()) && !fn.callContext.isStaticCall);
56
- // The claim amount is at index 2 in the args array because:
57
- // - Index 0: Target function selector (due to dispatch routing)
58
- // - Index 1: Amount recipient
59
- // - Index 2: Amount being claimed
60
- const balance = claimFunctionCall ? initialBalance.add(claimFunctionCall.args[2]) : initialBalance;
61
- if (balance.lt(feeLimit)) {
62
- this.#log.warn(`Rejecting transaction due to not enough fee payer balance`, {
63
- feePayer,
64
- balance: balance.toBigInt(),
65
- feeLimit: feeLimit.toBigInt()
66
- });
67
- return {
68
- result: 'invalid',
69
- reason: [
70
- 'Insufficient fee payer balance'
71
- ]
72
- };
73
- }
74
- return {
75
- result: 'valid'
76
- };
77
- }
78
- }
@@ -1,12 +0,0 @@
1
- import type { ContractDataSource } from '@aztec/stdlib/contract';
2
- import type { AllowedElement } from '@aztec/stdlib/interfaces/server';
3
- import { type PublicExecutionRequest, Tx, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
4
- export declare class PhasesTxValidator implements TxValidator<Tx> {
5
- #private;
6
- private setupAllowList;
7
- private contractDataSource;
8
- constructor(contracts: ContractDataSource, setupAllowList: AllowedElement[]);
9
- validateTx(tx: Tx): Promise<TxValidationResult>;
10
- isOnAllowList(publicCall: PublicExecutionRequest, allowList: AllowedElement[]): Promise<boolean>;
11
- }
12
- //# sourceMappingURL=phases_validator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"phases_validator.d.ts","sourceRoot":"","sources":["../../src/tx_validator/phases_validator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EACL,KAAK,sBAAsB,EAC3B,EAAE,EAEF,KAAK,kBAAkB,EACvB,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAC;AAE1B,qBAAa,iBAAkB,YAAW,WAAW,CAAC,EAAE,CAAC;;IAIZ,OAAO,CAAC,cAAc;IAFjE,OAAO,CAAC,kBAAkB,CAA8B;gBAE5C,SAAS,EAAE,kBAAkB,EAAU,cAAc,EAAE,cAAc,EAAE;IAI7E,UAAU,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAgC/C,aAAa,CAAC,UAAU,EAAE,sBAAsB,EAAE,SAAS,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CA6CvG"}
@@ -1,80 +0,0 @@
1
- import { createLogger } from '@aztec/foundation/log';
2
- import { ContractsDataSourcePublicDB, getExecutionRequestsByPhase } from '@aztec/simulator/server';
3
- import { Tx, TxExecutionPhase } from '@aztec/stdlib/tx';
4
- export class PhasesTxValidator {
5
- setupAllowList;
6
- #log;
7
- contractDataSource;
8
- constructor(contracts, setupAllowList){
9
- this.setupAllowList = setupAllowList;
10
- this.#log = createLogger('sequencer:tx_validator:tx_phases');
11
- this.contractDataSource = new ContractsDataSourcePublicDB(contracts);
12
- }
13
- async validateTx(tx) {
14
- try {
15
- // TODO(@spalladino): We add this just to handle public authwit-check calls during setup
16
- // which are needed for public FPC flows, but fail if the account contract hasnt been deployed yet,
17
- // which is what we're trying to do as part of the current txs.
18
- await this.contractDataSource.addNewContracts(tx);
19
- if (!tx.data.forPublic) {
20
- this.#log.debug(`Tx ${Tx.getHash(tx)} does not contain enqueued public functions. Skipping phases validation.`);
21
- return {
22
- result: 'valid'
23
- };
24
- }
25
- const setupFns = getExecutionRequestsByPhase(tx, TxExecutionPhase.SETUP);
26
- for (const setupFn of setupFns){
27
- if (!await this.isOnAllowList(setupFn, this.setupAllowList)) {
28
- this.#log.warn(`Rejecting tx ${Tx.getHash(tx)} because it calls setup function not on allow list: ${setupFn.callContext.contractAddress}:${setupFn.callContext.functionSelector}`, {
29
- allowList: this.setupAllowList
30
- });
31
- return {
32
- result: 'invalid',
33
- reason: [
34
- 'Setup function not on allow list'
35
- ]
36
- };
37
- }
38
- }
39
- return {
40
- result: 'valid'
41
- };
42
- } finally{
43
- this.contractDataSource.clearContractsForTx();
44
- }
45
- }
46
- async isOnAllowList(publicCall, allowList) {
47
- if (publicCall.isEmpty()) {
48
- return true;
49
- }
50
- const { contractAddress, functionSelector } = publicCall.callContext;
51
- // do these checks first since they don't require the contract class
52
- for (const entry of allowList){
53
- if ('address' in entry && !('selector' in entry)) {
54
- if (contractAddress.equals(entry.address)) {
55
- return true;
56
- }
57
- }
58
- if ('address' in entry && 'selector' in entry) {
59
- if (contractAddress.equals(entry.address) && entry.selector.equals(functionSelector)) {
60
- return true;
61
- }
62
- }
63
- const contractClass = await this.contractDataSource.getContractInstance(contractAddress);
64
- if (!contractClass) {
65
- throw new Error(`Contract not found: ${contractAddress}`);
66
- }
67
- if ('classId' in entry && !('selector' in entry)) {
68
- if (contractClass.currentContractClassId.equals(entry.classId)) {
69
- return true;
70
- }
71
- }
72
- if ('classId' in entry && 'selector' in entry) {
73
- if (contractClass.currentContractClassId.equals(entry.classId) && (entry.selector === undefined || entry.selector.equals(functionSelector))) {
74
- return true;
75
- }
76
- }
77
- }
78
- return false;
79
- }
80
- }
@@ -1,23 +0,0 @@
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 type { Tx } from '@aztec/stdlib/tx';
5
- export declare function patchNonRevertibleFn(tx: Tx, index: number, overrides: {
6
- address?: AztecAddress;
7
- selector: FunctionSelector;
8
- args?: Fr[];
9
- msgSender?: AztecAddress;
10
- }): Promise<{
11
- address: AztecAddress;
12
- selector: FunctionSelector;
13
- }>;
14
- export declare function patchRevertibleFn(tx: Tx, index: number, overrides: {
15
- address?: AztecAddress;
16
- selector: FunctionSelector;
17
- args?: Fr[];
18
- msgSender?: AztecAddress;
19
- }): Promise<{
20
- address: AztecAddress;
21
- selector: FunctionSelector;
22
- }>;
23
- //# sourceMappingURL=test_utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test_utils.d.ts","sourceRoot":"","sources":["../../src/tx_validator/test_utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAE3C,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,EAAE,EACN,KAAK,EAAE,MAAM,EACb,SAAS,EAAE;IAAE,OAAO,CAAC,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,gBAAgB,CAAC;IAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC;IAAC,SAAS,CAAC,EAAE,YAAY,CAAA;CAAE,GACvG,OAAO,CAAC;IAAE,OAAO,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,gBAAgB,CAAA;CAAE,CAAC,CAEhE;AAED,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,EAAE,EACN,KAAK,EAAE,MAAM,EACb,SAAS,EAAE;IAAE,OAAO,CAAC,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,gBAAgB,CAAC;IAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC;IAAC,SAAS,CAAC,EAAE,YAAY,CAAA;CAAE,GACvG,OAAO,CAAC;IAAE,OAAO,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,gBAAgB,CAAA;CAAE,CAAC,CAEhE"}
@@ -1,26 +0,0 @@
1
- import { computeVarArgsHash } from '@aztec/stdlib/hash';
2
- export function patchNonRevertibleFn(tx, index, overrides) {
3
- return patchFn('nonRevertibleAccumulatedData', tx, index, overrides);
4
- }
5
- export function patchRevertibleFn(tx, index, overrides) {
6
- return patchFn('revertibleAccumulatedData', tx, index, overrides);
7
- }
8
- async function patchFn(where, tx, index, overrides) {
9
- const fn = tx.enqueuedPublicFunctionCalls.at(-1 * index - 1);
10
- fn.callContext.contractAddress = overrides.address ?? fn.callContext.contractAddress;
11
- fn.callContext.functionSelector = overrides.selector;
12
- fn.args = overrides.args ?? fn.args;
13
- fn.callContext.msgSender = overrides.msgSender ?? fn.callContext.msgSender;
14
- tx.enqueuedPublicFunctionCalls[index] = fn;
15
- const request = tx.data.forPublic[where].publicCallRequests[index];
16
- request.contractAddress = fn.callContext.contractAddress;
17
- request.msgSender = fn.callContext.msgSender;
18
- request.functionSelector = fn.callContext.functionSelector;
19
- request.isStaticCall = fn.callContext.isStaticCall;
20
- request.argsHash = await computeVarArgsHash(fn.args);
21
- tx.data.forPublic[where].publicCallRequests[index] = request;
22
- return {
23
- address: fn.callContext.contractAddress,
24
- selector: fn.callContext.functionSelector
25
- };
26
- }
@@ -1,36 +0,0 @@
1
- import { FPCContract } from '@aztec/noir-contracts.js/FPC';
2
- import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
3
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
4
- import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
5
- import type { AllowedElement } from '@aztec/stdlib/interfaces/server';
6
-
7
- let defaultAllowedSetupFunctions: AllowedElement[] | undefined = undefined;
8
-
9
- export async function getDefaultAllowedSetupFunctions(): Promise<AllowedElement[]> {
10
- if (defaultAllowedSetupFunctions === undefined) {
11
- defaultAllowedSetupFunctions = [
12
- // needed for authwit support
13
- {
14
- address: ProtocolContractAddress.AuthRegistry,
15
- },
16
- // needed for claiming on the same tx as a spend
17
- {
18
- address: ProtocolContractAddress.FeeJuice,
19
- // We can't restrict the selector because public functions get routed via dispatch.
20
- // selector: FunctionSelector.fromSignature('_increase_public_balance((Field),u128)'),
21
- },
22
- // needed for private transfers via FPC
23
- {
24
- classId: (await getContractClassFromArtifact(TokenContractArtifact)).id,
25
- // We can't restrict the selector because public functions get routed via dispatch.
26
- // selector: FunctionSelector.fromSignature('_increase_public_balance((Field),u128)'),
27
- },
28
- {
29
- classId: (await getContractClassFromArtifact(FPCContract.artifact)).id,
30
- // We can't restrict the selector because public functions get routed via dispatch.
31
- // selector: FunctionSelector.fromSignature('prepare_fee((Field),Field,(Field),Field)'),
32
- },
33
- ];
34
- }
35
- return defaultAllowedSetupFunctions;
36
- }
@@ -1,15 +0,0 @@
1
- import type { L1ContractsConfig, L1ReaderConfig } from '@aztec/ethereum';
2
- import type { L2BlockSourceEventEmitter } from '@aztec/stdlib/block';
3
- import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
4
-
5
- import { SlasherClient } from './slasher_client.js';
6
- import type { SlasherConfig } from './slasher_client.js';
7
-
8
- export const createSlasherClient = (
9
- _config: SlasherConfig & L1ContractsConfig & L1ReaderConfig,
10
- l2BlockSource: L2BlockSourceEventEmitter,
11
- telemetry: TelemetryClient = getTelemetryClient(),
12
- ) => {
13
- const config = { ..._config };
14
- return new SlasherClient(config, l2BlockSource, telemetry);
15
- };
@@ -1,2 +0,0 @@
1
- export * from './slasher_client.js';
2
- export { createSlasherClient } from './factory.js';