@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.
- package/dest/client/sequencer-client.d.ts +25 -25
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +65 -51
- package/dest/config.d.ts +6 -14
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +50 -54
- package/dest/global_variable_builder/global_builder.d.ts +11 -6
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +39 -34
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/publisher/config.d.ts +6 -8
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +19 -17
- package/dest/publisher/index.d.ts +2 -0
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/index.js +3 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +43 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
- package/dest/publisher/sequencer-publisher-factory.js +51 -0
- package/dest/publisher/sequencer-publisher-metrics.d.ts +2 -1
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +37 -2
- package/dest/publisher/sequencer-publisher.d.ts +102 -69
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +606 -212
- package/dest/sequencer/block_builder.d.ts +27 -0
- package/dest/sequencer/block_builder.d.ts.map +1 -0
- package/dest/sequencer/block_builder.js +130 -0
- package/dest/sequencer/config.d.ts +5 -0
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/errors.d.ts +11 -0
- package/dest/sequencer/errors.d.ts.map +1 -0
- package/dest/sequencer/errors.js +15 -0
- package/dest/sequencer/index.d.ts +1 -1
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +1 -1
- package/dest/sequencer/metrics.d.ts +18 -11
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +84 -50
- package/dest/sequencer/sequencer.d.ts +120 -81
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +589 -359
- package/dest/sequencer/timetable.d.ts +32 -20
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +57 -30
- package/dest/sequencer/utils.d.ts +11 -35
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +9 -47
- package/dest/test/index.d.ts +7 -0
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +0 -4
- package/dest/tx_validator/nullifier_cache.d.ts +0 -2
- package/dest/tx_validator/nullifier_cache.d.ts.map +1 -1
- package/dest/tx_validator/tx_validator_factory.d.ts +9 -10
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -1
- package/dest/tx_validator/tx_validator_factory.js +27 -24
- package/package.json +42 -43
- package/src/client/sequencer-client.ts +94 -84
- package/src/config.ts +57 -61
- package/src/global_variable_builder/global_builder.ts +44 -23
- package/src/index.ts +6 -2
- package/src/publisher/config.ts +26 -24
- package/src/publisher/index.ts +4 -0
- package/src/publisher/sequencer-publisher-factory.ts +90 -0
- package/src/publisher/sequencer-publisher-metrics.ts +24 -2
- package/src/publisher/sequencer-publisher.ts +729 -235
- package/src/sequencer/block_builder.ts +218 -0
- package/src/sequencer/config.ts +7 -0
- package/src/sequencer/errors.ts +21 -0
- package/src/sequencer/index.ts +1 -1
- package/src/sequencer/metrics.ts +109 -55
- package/src/sequencer/sequencer.ts +766 -415
- package/src/sequencer/timetable.ts +98 -33
- package/src/sequencer/utils.ts +17 -58
- package/src/test/index.ts +11 -4
- package/src/tx_validator/tx_validator_factory.ts +44 -32
- package/dest/sequencer/allowed.d.ts +0 -3
- package/dest/sequencer/allowed.d.ts.map +0 -1
- package/dest/sequencer/allowed.js +0 -27
- package/dest/slasher/factory.d.ts +0 -7
- package/dest/slasher/factory.d.ts.map +0 -1
- package/dest/slasher/factory.js +0 -8
- package/dest/slasher/index.d.ts +0 -3
- package/dest/slasher/index.d.ts.map +0 -1
- package/dest/slasher/index.js +0 -2
- package/dest/slasher/slasher_client.d.ts +0 -75
- package/dest/slasher/slasher_client.d.ts.map +0 -1
- package/dest/slasher/slasher_client.js +0 -132
- package/dest/tx_validator/archive_cache.d.ts +0 -14
- package/dest/tx_validator/archive_cache.d.ts.map +0 -1
- package/dest/tx_validator/archive_cache.js +0 -22
- package/dest/tx_validator/gas_validator.d.ts +0 -14
- package/dest/tx_validator/gas_validator.d.ts.map +0 -1
- package/dest/tx_validator/gas_validator.js +0 -78
- package/dest/tx_validator/phases_validator.d.ts +0 -12
- package/dest/tx_validator/phases_validator.d.ts.map +0 -1
- package/dest/tx_validator/phases_validator.js +0 -80
- package/dest/tx_validator/test_utils.d.ts +0 -23
- package/dest/tx_validator/test_utils.d.ts.map +0 -1
- package/dest/tx_validator/test_utils.js +0 -26
- package/src/sequencer/allowed.ts +0 -36
- package/src/slasher/factory.ts +0 -15
- package/src/slasher/index.ts +0 -2
- package/src/slasher/slasher_client.ts +0 -193
- package/src/tx_validator/archive_cache.ts +0 -28
- package/src/tx_validator/gas_validator.ts +0 -101
- package/src/tx_validator/phases_validator.ts +0 -98
- package/src/tx_validator/test_utils.ts +0 -48
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type L1ContractsConfig,
|
|
3
|
-
type L1ReaderConfig,
|
|
4
|
-
type ViemPublicClient,
|
|
5
|
-
createEthereumChain,
|
|
6
|
-
} from '@aztec/ethereum';
|
|
7
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
8
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
9
|
-
import { SlashFactoryAbi } from '@aztec/l1-artifacts';
|
|
10
|
-
import {
|
|
11
|
-
type L2BlockId,
|
|
12
|
-
type L2BlockSourceEvent,
|
|
13
|
-
type L2BlockSourceEventEmitter,
|
|
14
|
-
L2BlockSourceEvents,
|
|
15
|
-
} from '@aztec/stdlib/block';
|
|
16
|
-
import { type TelemetryClient, WithTracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
17
|
-
|
|
18
|
-
import { type GetContractReturnType, createPublicClient, fallback, getAddress, getContract, http } from 'viem';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Enum defining the possible states of the Slasher client.
|
|
22
|
-
*/
|
|
23
|
-
export enum SlasherClientState {
|
|
24
|
-
IDLE,
|
|
25
|
-
RUNNING,
|
|
26
|
-
STOPPED,
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The synchronization status of the Slasher client.
|
|
31
|
-
*/
|
|
32
|
-
export interface SlasherSyncState {
|
|
33
|
-
/**
|
|
34
|
-
* The current state of the slasher client.
|
|
35
|
-
*/
|
|
36
|
-
state: SlasherClientState;
|
|
37
|
-
/**
|
|
38
|
-
* The block number that the slasher client is synced to.
|
|
39
|
-
*/
|
|
40
|
-
syncedToL2Block: L2BlockId;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface SlasherConfig {
|
|
44
|
-
blockCheckIntervalMS: number;
|
|
45
|
-
blockRequestBatchSize: number;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
type SlashEvent = {
|
|
49
|
-
epoch: bigint;
|
|
50
|
-
amount: bigint;
|
|
51
|
-
lifetime: bigint;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @notice A Hypomeiones slasher client implementation
|
|
56
|
-
*
|
|
57
|
-
* Hypomeiones: a class of individuals in ancient Sparta who were considered inferior or lesser citizens compared
|
|
58
|
-
* to the full Spartan citizens.
|
|
59
|
-
*
|
|
60
|
-
* The implementation here is less than ideal. It exists, not to be the end all be all, but to show that
|
|
61
|
-
* slashing can be done with this mechanism.
|
|
62
|
-
*
|
|
63
|
-
* The implementation is VERY brute in the sense that it only looks for pruned blocks and then tries to slash
|
|
64
|
-
* the full committee of that.
|
|
65
|
-
* If it sees a prune, it will mark the full epoch as "to be slashed".
|
|
66
|
-
*
|
|
67
|
-
* Also, it is not particularly smart around what it should if there were to be multiple slashing events.
|
|
68
|
-
*
|
|
69
|
-
* A few improvements:
|
|
70
|
-
* - 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.
|
|
71
|
-
* - Stop voting on a payload once it is processed.
|
|
72
|
-
* - Only vote on the proposal if it have not already been executed
|
|
73
|
-
* - Caveat, we need to fully decide if it is acceptable to have the same payload address multiple times. In the current
|
|
74
|
-
* slash factory that could mean slashing the same committee for the same error multiple times.
|
|
75
|
-
* - Decide how to deal with multiple slashing events in the same round.
|
|
76
|
-
* - This could be that multiple epochs are pruned in the same round, but with the current naive implementation we could end up
|
|
77
|
-
* slashing only the first, because the "lifetime" of the second would have passed after that vote
|
|
78
|
-
*/
|
|
79
|
-
export class SlasherClient extends WithTracer {
|
|
80
|
-
private slashEvents: SlashEvent[] = [];
|
|
81
|
-
|
|
82
|
-
protected slashFactoryContract?: GetContractReturnType<typeof SlashFactoryAbi, ViemPublicClient> = undefined;
|
|
83
|
-
|
|
84
|
-
// The amount to slash for a prune.
|
|
85
|
-
// Note that we set it to 0, such that no actual slashing will happen, but the event will be fired,
|
|
86
|
-
// showing that the slashing mechanism is working.
|
|
87
|
-
private slashingAmount: bigint = 0n;
|
|
88
|
-
|
|
89
|
-
constructor(
|
|
90
|
-
private config: SlasherConfig & L1ContractsConfig & L1ReaderConfig,
|
|
91
|
-
private l2BlockSource: L2BlockSourceEventEmitter,
|
|
92
|
-
telemetry: TelemetryClient = getTelemetryClient(),
|
|
93
|
-
private log = createLogger('slasher'),
|
|
94
|
-
) {
|
|
95
|
-
super(telemetry, 'slasher');
|
|
96
|
-
|
|
97
|
-
if (config.l1Contracts.slashFactoryAddress && config.l1Contracts.slashFactoryAddress !== EthAddress.ZERO) {
|
|
98
|
-
const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
99
|
-
const publicClient = createPublicClient({
|
|
100
|
-
chain: chain.chainInfo,
|
|
101
|
-
transport: fallback(chain.rpcUrls.map(url => http(url))),
|
|
102
|
-
pollingInterval: config.viemPollingIntervalMS,
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
this.slashFactoryContract = getContract({
|
|
106
|
-
address: getAddress(config.l1Contracts.slashFactoryAddress.toString()),
|
|
107
|
-
abi: SlashFactoryAbi,
|
|
108
|
-
client: publicClient,
|
|
109
|
-
});
|
|
110
|
-
} else {
|
|
111
|
-
this.log.warn('No slash factory address found, slashing will not be enabled');
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
this.log.info(`Slasher client initialized`);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
public start() {
|
|
118
|
-
this.log.info('Starting Slasher client...');
|
|
119
|
-
this.l2BlockSource.on(L2BlockSourceEvents.L2PruneDetected, this.handlePruneL2Blocks.bind(this));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// This is where we should put a bunch of the improvements mentioned earlier.
|
|
123
|
-
public async getSlashPayload(slotNumber: bigint): Promise<EthAddress | undefined> {
|
|
124
|
-
if (!this.slashFactoryContract) {
|
|
125
|
-
return undefined;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// As long as the slot is greater than the lifetime, we want to keep deleting the first element
|
|
129
|
-
// since it will not make sense to include anymore.
|
|
130
|
-
while (this.slashEvents.length > 0 && this.slashEvents[0].lifetime < slotNumber) {
|
|
131
|
-
this.slashEvents.shift();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (this.slashEvents.length == 0) {
|
|
135
|
-
return undefined;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const slashEvent = this.slashEvents[0];
|
|
139
|
-
|
|
140
|
-
const [payloadAddress, isDeployed] = await this.slashFactoryContract.read.getAddressAndIsDeployed([
|
|
141
|
-
slashEvent.epoch,
|
|
142
|
-
slashEvent.amount,
|
|
143
|
-
]);
|
|
144
|
-
|
|
145
|
-
if (!isDeployed) {
|
|
146
|
-
// The proposal cannot be executed until it is deployed
|
|
147
|
-
this.log.verbose(`Voting on not yet deployed payload: ${payloadAddress}`);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return EthAddress.fromString(payloadAddress);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
public handleBlockStreamEvent(event: L2BlockSourceEvent): Promise<void> {
|
|
154
|
-
this.log.debug(`Handling block stream event ${event.type}`);
|
|
155
|
-
switch (event.type) {
|
|
156
|
-
case L2BlockSourceEvents.L2PruneDetected:
|
|
157
|
-
this.handlePruneL2Blocks(event);
|
|
158
|
-
break;
|
|
159
|
-
default: {
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return Promise.resolve();
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Allows consumers to stop the instance of the slasher client.
|
|
168
|
-
* 'ready' will now return 'false' and the running promise that keeps the client synced is interrupted.
|
|
169
|
-
*/
|
|
170
|
-
public stop() {
|
|
171
|
-
this.log.debug('Stopping Slasher client...');
|
|
172
|
-
this.l2BlockSource.removeListener(L2BlockSourceEvents.L2PruneDetected, this.handlePruneL2Blocks.bind(this));
|
|
173
|
-
this.log.info('Slasher client stopped.');
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// I need to get the slot number from the block that was just pruned
|
|
177
|
-
private handlePruneL2Blocks(event: L2BlockSourceEvent): void {
|
|
178
|
-
const { slotNumber, epochNumber } = event;
|
|
179
|
-
this.log.info(`Detected chain prune. Punishing the validators at epoch ${epochNumber}`);
|
|
180
|
-
|
|
181
|
-
// Set the lifetime such that we have a full round that we could vote throughout.
|
|
182
|
-
const slotsIntoRound = slotNumber % BigInt(this.config.slashingRoundSize);
|
|
183
|
-
const toNext = slotsIntoRound == 0n ? 0n : BigInt(this.config.slashingRoundSize) - slotsIntoRound;
|
|
184
|
-
|
|
185
|
-
const lifetime = slotNumber + toNext + BigInt(this.config.slashingRoundSize);
|
|
186
|
-
|
|
187
|
-
this.slashEvents.push({
|
|
188
|
-
epoch: epochNumber,
|
|
189
|
-
amount: this.slashingAmount,
|
|
190
|
-
lifetime,
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}
|
|
@@ -1,28 +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
|
-
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Implements an archive source by checking a DB and an in-memory collection.
|
|
8
|
-
* Intended for validating transactions as they are added to a block.
|
|
9
|
-
*/
|
|
10
|
-
export class ArchiveCache implements ArchiveSource {
|
|
11
|
-
archives: Map<string, bigint>;
|
|
12
|
-
|
|
13
|
-
constructor(private db: MerkleTreeReadOperations) {
|
|
14
|
-
this.archives = new Map<string, bigint>();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public async getArchiveIndices(archives: Fr[]): Promise<(bigint | undefined)[]> {
|
|
18
|
-
const toCheckDb = archives.filter(n => !this.archives.has(n.toString()));
|
|
19
|
-
const dbHits = await this.db.findLeafIndices(MerkleTreeId.ARCHIVE, toCheckDb);
|
|
20
|
-
dbHits.forEach((x, index) => {
|
|
21
|
-
if (x !== undefined) {
|
|
22
|
-
this.archives.set(toCheckDb[index].toString(), x);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
return archives.map(n => this.archives.get(n.toString()));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
4
|
-
import { getExecutionRequestsByPhase } from '@aztec/simulator/server';
|
|
5
|
-
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
6
|
-
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
|
-
import type { GasFees } from '@aztec/stdlib/gas';
|
|
8
|
-
import { type Tx, TxExecutionPhase, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
|
|
9
|
-
|
|
10
|
-
/** Provides a view into public contract state */
|
|
11
|
-
export interface PublicStateSource {
|
|
12
|
-
storageRead: (contractAddress: AztecAddress, slot: Fr) => Promise<Fr>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class GasTxValidator implements TxValidator<Tx> {
|
|
16
|
-
#log = createLogger('sequencer:tx_validator:tx_gas');
|
|
17
|
-
#publicDataSource: PublicStateSource;
|
|
18
|
-
#feeJuiceAddress: AztecAddress;
|
|
19
|
-
#gasFees: GasFees;
|
|
20
|
-
|
|
21
|
-
constructor(publicDataSource: PublicStateSource, feeJuiceAddress: AztecAddress, gasFees: GasFees) {
|
|
22
|
-
this.#publicDataSource = publicDataSource;
|
|
23
|
-
this.#feeJuiceAddress = feeJuiceAddress;
|
|
24
|
-
this.#gasFees = gasFees;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async validateTx(tx: Tx): Promise<TxValidationResult> {
|
|
28
|
-
if (await this.#shouldSkip(tx)) {
|
|
29
|
-
return Promise.resolve({ result: 'skipped', reason: ['Insufficient fee per gas'] });
|
|
30
|
-
}
|
|
31
|
-
return this.#validateTxFee(tx);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Check whether the tx's max fees are valid for the current block, and skip if not.
|
|
36
|
-
* We skip instead of invalidating since the tx may become eligible later.
|
|
37
|
-
* Note that circuits check max fees even if fee payer is unset, so we
|
|
38
|
-
* keep this validation even if the tx does not pay fees.
|
|
39
|
-
*/
|
|
40
|
-
async #shouldSkip(tx: Tx): Promise<boolean> {
|
|
41
|
-
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
42
|
-
|
|
43
|
-
// Skip the tx if its max fees are not enough for the current block's gas fees.
|
|
44
|
-
const maxFeesPerGas = gasSettings.maxFeesPerGas;
|
|
45
|
-
const notEnoughMaxFees =
|
|
46
|
-
maxFeesPerGas.feePerDaGas.lt(this.#gasFees.feePerDaGas) ||
|
|
47
|
-
maxFeesPerGas.feePerL2Gas.lt(this.#gasFees.feePerL2Gas);
|
|
48
|
-
|
|
49
|
-
if (notEnoughMaxFees) {
|
|
50
|
-
this.#log.warn(`Skipping transaction ${await tx.getTxHash()} due to insufficient fee per gas`, {
|
|
51
|
-
txMaxFeesPerGas: maxFeesPerGas.toInspect(),
|
|
52
|
-
currentGasFees: this.#gasFees.toInspect(),
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
return notEnoughMaxFees;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async #validateTxFee(tx: Tx): Promise<TxValidationResult> {
|
|
59
|
-
const feePayer = tx.data.feePayer;
|
|
60
|
-
|
|
61
|
-
// Compute the maximum fee that this tx may pay, based on its gasLimits and maxFeePerGas
|
|
62
|
-
const feeLimit = tx.data.constants.txContext.gasSettings.getFeeLimit();
|
|
63
|
-
|
|
64
|
-
// Read current balance of the feePayer
|
|
65
|
-
const initialBalance = await this.#publicDataSource.storageRead(
|
|
66
|
-
this.#feeJuiceAddress,
|
|
67
|
-
await computeFeePayerBalanceStorageSlot(feePayer),
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
// If there is a claim in this tx that increases the fee payer balance in Fee Juice, add it to balance
|
|
71
|
-
const setupFns = getExecutionRequestsByPhase(tx, TxExecutionPhase.SETUP);
|
|
72
|
-
const increasePublicBalanceSelector = await FunctionSelector.fromSignature(
|
|
73
|
-
'_increase_public_balance((Field),u128)',
|
|
74
|
-
);
|
|
75
|
-
const claimFunctionCall = setupFns.find(
|
|
76
|
-
fn =>
|
|
77
|
-
fn.callContext.contractAddress.equals(this.#feeJuiceAddress) &&
|
|
78
|
-
fn.callContext.msgSender.equals(this.#feeJuiceAddress) &&
|
|
79
|
-
fn.args.length > 2 &&
|
|
80
|
-
// Public functions get routed through the dispatch function, whose first argument is the target function selector.
|
|
81
|
-
fn.args[0].equals(increasePublicBalanceSelector.toField()) &&
|
|
82
|
-
fn.args[1].equals(feePayer.toField()) &&
|
|
83
|
-
!fn.callContext.isStaticCall,
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
// The claim amount is at index 2 in the args array because:
|
|
87
|
-
// - Index 0: Target function selector (due to dispatch routing)
|
|
88
|
-
// - Index 1: Amount recipient
|
|
89
|
-
// - Index 2: Amount being claimed
|
|
90
|
-
const balance = claimFunctionCall ? initialBalance.add(claimFunctionCall.args[2]) : initialBalance;
|
|
91
|
-
if (balance.lt(feeLimit)) {
|
|
92
|
-
this.#log.warn(`Rejecting transaction due to not enough fee payer balance`, {
|
|
93
|
-
feePayer,
|
|
94
|
-
balance: balance.toBigInt(),
|
|
95
|
-
feeLimit: feeLimit.toBigInt(),
|
|
96
|
-
});
|
|
97
|
-
return { result: 'invalid', reason: ['Insufficient fee payer balance'] };
|
|
98
|
-
}
|
|
99
|
-
return { result: 'valid' };
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,48 +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 { 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
|
-
}
|