Skip to content

Conversation

@avilagaston9
Copy link
Contributor

@avilagaston9 avilagaston9 commented Oct 6, 2025

Motivation

Implements the L1 fee. For more information about the L1 fee, see transaction_fees.md.

Description

  • Adds L1FeeConfig to FeeConfig.
  • Modifies L2Hook to charge the L1 fee to transaction senders.
  • Updates integration tests to include the new fee type.

Closes #4696

Base automatically changed from feat/l2/operator_fee to main October 23, 2025 18:15
Copilot AI review requested due to automatic review settings October 23, 2025 19:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements L1 fee charging for L2 transactions to account for the cost of posting state diffs to L1. The L1 fee is calculated based on the transaction's state diff size and the L1 blob base fee, then charged as additional gas to the transaction sender.

Key changes:

  • Added L1FeeConfig to track L1 fee vault address and blob base fee per gas
  • Modified L2Hook to calculate and charge L1 fees after transaction execution
  • Integrated L1 blob base fee fetching from L1 at configurable intervals

Reviewed Changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
crates/common/types/l2/fee_config.rs Added L1FeeConfig struct to fee configuration
crates/common/types/l2/account_diff.rs New file with account diff encoding/decoding logic moved from state_diff.rs
crates/vm/levm/src/hooks/l2_hook.rs Implemented L1 fee calculation and charging logic in transaction finalization
crates/vm/levm/src/utils.rs Added get_account_diffs_in_tx utility function
crates/l2/sequencer/block_producer.rs Added periodic L1 blob base fee updates from L1
crates/l2/tests/tests.rs Updated integration tests to verify L1 fee vault balances
crates/blockchain/blockchain.rs Added L2Config with RwLock-wrapped FeeConfig for runtime updates
docs/l2/fundamentals/transaction_fees.md Documented L1 fee mechanism and configuration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

))?;
if params.len() != 1 {
return Err(ethrex_rpc::RpcErr::BadParams(
"Expected 1 params".to_owned(),
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message says 'Expected 1 params' but should be 'Expected 1 param' (singular) for grammatical correctness.

Suggested change
"Expected 1 params".to_owned(),
"Expected 1 param".to_owned(),

Copilot uses AI. Check for mistakes.
);
CastResponse::NoReply
}
InMessage::UpdateL1BlobBaseFee => {
Copy link
Collaborator

@jrchatruc jrchatruc Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this task to a different L2 genserver (maybe watcher?), because the request to get the base fee could take a while (seconds) if network conditions are not ideal or something else happens, which would in the meantime prevent block production from continuing if the block production interval is low enough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to watcher 6c34abb!

@avilagaston9 avilagaston9 added this pull request to the merge queue Oct 24, 2025
Merged via the queue into main with commit c638968 Oct 24, 2025
53 checks passed
@avilagaston9 avilagaston9 deleted the feat/implement_l1_fee branch October 24, 2025 19:22
@github-project-automation github-project-automation bot moved this from In Review to Done in ethrex_l2 Oct 24, 2025
iovoid pushed a commit that referenced this pull request Oct 27, 2025
**Motivation**

Implements the L1 fee. For more information about the L1 fee, see
`transaction_fees.md`.

**Description**

- Adds `L1FeeConfig` to `FeeConfig`.
- Modifies `L2Hook` to charge the L1 fee to transaction senders.
- Updates integration tests to include the new fee type.

Closes #4696

---------

Co-authored-by: Tomás Grüner <47506558+MegaRedHand@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L2 Rollup client

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

L2: implement l1_fee

5 participants