Skip to content

Conversation

@tomip01
Copy link
Contributor

@tomip01 tomip01 commented Oct 23, 2025

Motivation

This pull request introduces support for a new transaction type, CustomFeeTransaction, we want to be able to pay fees with an ERC20 token instead of ETH.

Description

  • Added FeeTokenTransaction as a new variant to the Transaction enum, and updated the TxType enum and its associated methods to recognize the new type.
  • Modified l2_hook to deduct and refund fees according to the ERC20 tokens desired as the user
  • Added new flag for deployer initial_fee_token that will register one address in advance.

How to test

You can see the test_fee_token in tests.rs to see how to build a tx.
Some useful commands may be:

Register a new fee token:

rex send <BRIDGE_L1> "registerNewFeeToken(address)" <FEE_TOKEN> --rpc-url http://localhost:8545 --private-key 0x941e103320615d394a55708be13e45994c7d93b932b064dbcb2b511fe3254e2e

Check if fee token is allowed

rex call 0x000000000000000000000000000000000000fffc "isFeeToken(address)" <FEE_TOKEN> --rpc-url http://localhost:1729

@github-actions github-actions bot added the L2 Rollup client label Oct 23, 2025
@github-actions
Copy link

github-actions bot commented Oct 23, 2025

Lines of code report

Total lines added: 740
Total lines removed: 0
Total lines changed: 740

Detailed view
+----------------------------------------------------------+-------+------+
| File                                                     | Lines | Diff |
+----------------------------------------------------------+-------+------+
| ethrex/cmd/ethrex/build_l2.rs                            | 412   | +15  |
+----------------------------------------------------------+-------+------+
| ethrex/cmd/ethrex/l2/deployer.rs                         | 1137  | +83  |
+----------------------------------------------------------+-------+------+
| ethrex/crates/blockchain/blockchain.rs                   | 1298  | +1   |
+----------------------------------------------------------+-------+------+
| ethrex/crates/blockchain/metrics/metrics_transactions.rs | 151   | +2   |
+----------------------------------------------------------+-------+------+
| ethrex/crates/common/types/receipt.rs                    | 343   | +2   |
+----------------------------------------------------------+-------+------+
| ethrex/crates/common/types/transaction.rs                | 3168  | +310 |
+----------------------------------------------------------+-------+------+
| ethrex/crates/l2/networking/rpc/signer.rs                | 276   | +11  |
+----------------------------------------------------------+-------+------+
| ethrex/crates/l2/sdk/src/sdk.rs                          | 959   | +41  |
+----------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/clients/eth/mod.rs          | 622   | +1   |
+----------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/eth/fee_market.rs           | 234   | +3   |
+----------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/types/transaction.rs        | 101   | +5   |
+----------------------------------------------------------+-------+------+
| ethrex/crates/vm/backends/levm/mod.rs                    | 632   | +2   |
+----------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/environment.rs                 | 94    | +1   |
+----------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/hooks/l2_hook.rs               | 495   | +261 |
+----------------------------------------------------------+-------+------+
| ethrex/tooling/ef_tests/state/runner/levm_runner.rs      | 441   | +1   |
+----------------------------------------------------------+-------+------+
| ethrex/tooling/ef_tests/state_v2/src/modules/runner.rs   | 207   | +1   |
+----------------------------------------------------------+-------+------+

@github-actions
Copy link

github-actions bot commented Oct 23, 2025

Benchmark Results Comparison

No significant difference was registered for any benchmark run.

Detailed Results

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
main_revm_BubbleSort 2.980 ± 0.010 2.969 2.997 1.00
main_levm_BubbleSort 3.093 ± 0.040 3.062 3.200 1.04 ± 0.01
pr_revm_BubbleSort 3.022 ± 0.034 2.982 3.081 1.01 ± 0.01
pr_levm_BubbleSort 3.104 ± 0.047 3.065 3.191 1.04 ± 0.02

Benchmark Results: ERC20Approval

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Approval 974.9 ± 8.6 960.5 989.3 1.00 ± 0.01
main_levm_ERC20Approval 1100.3 ± 5.4 1092.9 1110.6 1.13 ± 0.01
pr_revm_ERC20Approval 973.3 ± 9.3 964.4 989.8 1.00
pr_levm_ERC20Approval 1094.1 ± 14.9 1082.0 1132.5 1.12 ± 0.02

Benchmark Results: ERC20Mint

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Mint 133.9 ± 1.1 132.6 135.8 1.00
main_levm_ERC20Mint 167.2 ± 3.3 163.3 173.3 1.25 ± 0.03
pr_revm_ERC20Mint 135.9 ± 1.9 133.4 140.3 1.01 ± 0.02
pr_levm_ERC20Mint 168.7 ± 7.2 162.8 182.8 1.26 ± 0.05

Benchmark Results: ERC20Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Transfer 229.7 ± 1.8 228.4 234.6 1.00
main_levm_ERC20Transfer 282.0 ± 2.4 279.2 285.7 1.23 ± 0.01
pr_revm_ERC20Transfer 231.6 ± 1.7 228.9 234.7 1.01 ± 0.01
pr_levm_ERC20Transfer 279.7 ± 3.1 275.4 286.8 1.22 ± 0.02

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Factorial 229.2 ± 1.4 227.7 232.3 1.01 ± 0.01
main_levm_Factorial 267.9 ± 12.8 262.0 303.7 1.18 ± 0.06
pr_revm_Factorial 226.9 ± 0.9 225.3 228.2 1.00
pr_levm_Factorial 266.6 ± 1.4 264.9 270.1 1.18 ± 0.01

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.663 ± 0.027 1.627 1.708 1.01 ± 0.02
main_levm_FactorialRecursive 8.379 ± 0.016 8.346 8.399 5.10 ± 0.09
pr_revm_FactorialRecursive 1.644 ± 0.029 1.610 1.695 1.00
pr_levm_FactorialRecursive 8.345 ± 0.045 8.281 8.420 5.08 ± 0.09

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Fibonacci 207.9 ± 0.5 207.2 208.9 1.01 ± 0.01
main_levm_Fibonacci 256.6 ± 7.1 249.2 272.6 1.24 ± 0.04
pr_revm_Fibonacci 206.4 ± 1.8 201.8 208.1 1.00
pr_levm_Fibonacci 254.9 ± 5.1 249.5 263.2 1.23 ± 0.03

Benchmark Results: FibonacciRecursive

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_FibonacciRecursive 856.1 ± 13.3 837.7 883.5 1.12 ± 0.02
main_levm_FibonacciRecursive 767.3 ± 16.5 756.4 810.0 1.01 ± 0.02
pr_revm_FibonacciRecursive 834.3 ± 6.2 826.3 847.8 1.10 ± 0.01
pr_levm_FibonacciRecursive 761.2 ± 4.4 752.9 769.5 1.00

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ManyHashes 8.3 ± 0.1 8.1 8.4 1.00 ± 0.01
main_levm_ManyHashes 9.3 ± 0.2 9.1 9.7 1.13 ± 0.02
pr_revm_ManyHashes 8.3 ± 0.1 8.2 8.4 1.00
pr_levm_ManyHashes 9.3 ± 0.4 9.0 10.2 1.13 ± 0.05

Benchmark Results: MstoreBench

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_MstoreBench 267.9 ± 5.2 265.1 282.5 1.11 ± 0.02
main_levm_MstoreBench 244.8 ± 3.8 241.5 253.7 1.01 ± 0.02
pr_revm_MstoreBench 267.1 ± 2.9 264.9 274.5 1.11 ± 0.01
pr_levm_MstoreBench 241.4 ± 1.6 238.9 244.9 1.00

Benchmark Results: Push

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Push 296.0 ± 0.4 295.3 296.7 1.00 ± 0.01
main_levm_Push 295.3 ± 2.0 293.1 300.1 1.00
pr_revm_Push 296.1 ± 1.2 294.6 298.1 1.00 ± 0.01
pr_levm_Push 300.3 ± 10.2 295.0 327.1 1.02 ± 0.04

Benchmark Results: SstoreBench_no_opt

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_SstoreBench_no_opt 174.2 ± 4.4 167.8 179.4 1.94 ± 0.08
main_levm_SstoreBench_no_opt 90.6 ± 2.7 88.7 97.4 1.01 ± 0.04
pr_revm_SstoreBench_no_opt 176.8 ± 7.9 167.8 195.1 1.96 ± 0.11
pr_levm_SstoreBench_no_opt 90.0 ± 2.9 87.9 97.1 1.00

github-merge-queue bot pushed a commit that referenced this pull request Nov 12, 2025
> [!NOTE]
> #5024 re-introduces the feature with a different approach

**Motivation**

We want a new approach for having native tokens in the L2. We want to
keep the balance of the accounts to remain being ETH but allow the fees
of the transactions to be paid with an ERC20.

**Description**

- Reverted commit f6ccc00.

---------

Co-authored-by: Manuel Iñaki Bilbao <[email protected]>
Base automatically changed from fee_token_2 to main November 12, 2025 02:06
Copilot AI review requested due to automatic review settings November 12, 2025 03:56
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 introduces support for a new FeeTokenTransaction type that allows L2 users to pay transaction fees using ERC-20 tokens instead of ETH. The implementation includes a new transaction variant, fee token registry system contract, and comprehensive modifications to fee distribution logic.

Key Changes

  • Added FeeTokenTransaction as a new transaction type (0x7d) with fee token address field
  • Implemented FeeTokenRegistry system contract (0xfffc) to manage allowed fee tokens
  • Modified l2_hook.rs to lock/refund fees via ERC-20 token contract calls (lockFee/payFee)

Reviewed Changes

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

Show a summary per file
File Description
crates/common/types/transaction.rs Added FeeTokenTransaction variant with RLP encoding/decoding and serialization support
crates/vm/levm/src/hooks/l2_hook.rs Implemented fee token execution preparation, deduction, and distribution logic via ERC-20 calls
crates/vm/levm/src/environment.rs Added optional fee_token field to Environment struct
crates/l2/contracts/src/l2/FeeTokenRegistry.sol New system contract to register/unregister allowed fee tokens
crates/l2/contracts/src/l1/CommonBridge.sol Added registerNewFeeToken/unregisterFeeToken L1 bridge functions
crates/l2/sdk/src/sdk.rs Added SDK helpers for building and sending fee token transactions
crates/networking/rpc/types/transaction.rs Updated RPC transaction decoding to support fee token type (0x7d)
crates/l2/tests/tests.rs Added comprehensive test_fee_token integration test
cmd/ethrex/l2/deployer.rs Added --initial-fee-token and --bridge-owner-pk deployment flags

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@ManuelBilbao ManuelBilbao left a comment

Choose a reason for hiding this comment

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

Just a nit

@tomip01 tomip01 enabled auto-merge November 13, 2025 18:59
@tomip01 tomip01 added this pull request to the merge queue Nov 13, 2025
Merged via the queue into main with commit cea9f0c Nov 13, 2025
53 checks passed
@tomip01 tomip01 deleted the fee_token_3 branch November 13, 2025 19:38
@github-project-automation github-project-automation bot moved this from Requires Changes to Done in ethrex_l2 Nov 13, 2025
lakshya-sky pushed a commit to lakshya-sky/ethrex that referenced this pull request Nov 17, 2025
**Motivation**

This pull request introduces support for a new transaction type,
`CustomFeeTransaction`, we want to be able to pay fees with an ERC20
token instead of ETH.

**Description**

* Added `FeeTokenTransaction` as a new variant to the `Transaction`
enum, and updated the `TxType` enum and its associated methods to
recognize the new type.
* Modified `l2_hook` to deduct and refund fees according to the ERC20
tokens desired as the user
* Added new flag for deployer `initial_fee_token` that will register one
address in advance.

**How to test**

You can see the `test_fee_token` in `tests.rs` to see how to build a tx.
Some useful commands may be:

Register a new fee token:
```bash
rex send <BRIDGE_L1> "registerNewFeeToken(address)" <FEE_TOKEN> --rpc-url http://localhost:8545 --private-key 0x941e103320615d394a55708be13e45994c7d93b932b064dbcb2b511fe3254e2e
```

Check if fee token is allowed
```bash
rex call 0x000000000000000000000000000000000000fffc "isFeeToken(address)" <FEE_TOKEN> --rpc-url http://localhost:1729
```

---------

Co-authored-by: Avila Gastón <[email protected]>
Co-authored-by: Manuel Iñaki Bilbao <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Ivan Litteri <[email protected]>
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.

6 participants