Skip to content

Commit

Permalink
feat: Add ENFORCE_FEES sequencer config (#6949)
Browse files Browse the repository at this point in the history
Sequencer will reject all txs without a fee payer if set.
  • Loading branch information
spalladino authored Jun 6, 2024
1 parent 48be80c commit 46dcb98
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions yarn-project/circuit-types/src/interfaces/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ export interface SequencerConfig {
allowedFunctionsInTeardown?: AllowedFunction[];
/** Max block size */
maxBlockSizeInBytes?: number;
/** Whether to require every tx to have a fee payer */
enforceFees?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class SequencerClient {
l2BlockSource,
l1ToL2MessageSource,
publicProcessorFactory,
new TxValidatorFactory(merkleTreeDb, contractDataSource),
new TxValidatorFactory(merkleTreeDb, contractDataSource, !!config.enforceFees),
config,
);

Expand Down
2 changes: 2 additions & 0 deletions yarn-project/sequencer-client/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export function getConfigEnvVars(): SequencerClientConfig {
FEE_RECIPIENT,
ACVM_WORKING_DIRECTORY,
ACVM_BINARY_PATH,
ENFORCE_FEES = '',
} = process.env;

const publisherPrivateKey: Hex = SEQ_PUBLISHER_PRIVATE_KEY
Expand All @@ -83,6 +84,7 @@ export function getConfigEnvVars(): SequencerClientConfig {
};

return {
enforceFees: ['1', 'true'].includes(ENFORCE_FEES),
rpcUrl: ETHEREUM_HOST ? ETHEREUM_HOST : '',
chainId: CHAIN_ID ? +CHAIN_ID : 31337, // 31337 is the default chain id for anvil
version: VERSION ? +VERSION : 1, // 1 is our default version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('sequencer', () => {
l2BlockSource,
l1ToL2MessageSource,
publicProcessorFactory,
new TxValidatorFactory(merkleTreeOps, contractSource),
new TxValidatorFactory(merkleTreeOps, contractSource, false),
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('GasTxValidator', () => {
storageRead: mockFn().mockImplementation((_address: AztecAddress, _slot: Fr) => Fr.ZERO),
});

validator = new GasTxValidator(publicStateSource, gasTokenAddress);
validator = new GasTxValidator(publicStateSource, gasTokenAddress, false);
});

let tx: Tx;
Expand Down Expand Up @@ -94,7 +94,13 @@ describe('GasTxValidator', () => {
await expectValidateFail(tx);
});

it.skip('rejects txs with no fee payer', async () => {
it('allows txs with no fee payer if fees are not enforced', async () => {
tx.data.feePayer = AztecAddress.ZERO;
await expectValidateSuccess(tx);
});

it('rejects txs with no fee payer if fees are enforced', async () => {
validator.enforceFees = true;
tx.data.feePayer = AztecAddress.ZERO;
await expectValidateFail(tx);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class GasTxValidator implements TxValidator<Tx> {
#publicDataSource: PublicStateSource;
#gasTokenAddress: AztecAddress;

constructor(publicDataSource: PublicStateSource, gasTokenAddress: AztecAddress) {
constructor(publicDataSource: PublicStateSource, gasTokenAddress: AztecAddress, public enforceFees: boolean) {
this.#publicDataSource = publicDataSource;
this.#gasTokenAddress = gasTokenAddress;
}
Expand All @@ -38,7 +38,11 @@ export class GasTxValidator implements TxValidator<Tx> {
const feePayer = tx.data.feePayer;
// TODO(@spalladino) Eventually remove the is_zero condition as we should always charge fees to every tx
if (feePayer.isZero()) {
return true;
if (this.enforceFees) {
this.#log.warn(`Rejecting transaction ${tx.getTxHash()} due to missing fee payer`);
} else {
return true;
}
}

// Compute the maximum fee that this tx may pay, based on its gasLimits and maxFeePerGas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ import { MetadataTxValidator } from './metadata_validator.js';
import { PhasesTxValidator } from './phases_validator.js';

export class TxValidatorFactory {
constructor(private merkleTreeDb: MerkleTreeOperations, private contractDataSource: ContractDataSource) {}
constructor(
private merkleTreeDb: MerkleTreeOperations,
private contractDataSource: ContractDataSource,
private enforceFees: boolean,
) {}

validatorForNewTxs(globalVariables: GlobalVariables, setupAllowList: AllowedFunction[]): TxValidator<Tx> {
return new AggregateTxValidator(
new MetadataTxValidator(globalVariables),
new DoubleSpendTxValidator(new WorldStateDB(this.merkleTreeDb)),
new PhasesTxValidator(this.contractDataSource, setupAllowList),
new GasTxValidator(new WorldStatePublicDB(this.merkleTreeDb), GasTokenAddress),
new GasTxValidator(new WorldStatePublicDB(this.merkleTreeDb), GasTokenAddress, this.enforceFees),
);
}

Expand Down

0 comments on commit 46dcb98

Please sign in to comment.