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 CustomFeeTransaction as a new variant to the Transaction enum, and updated the TxType enum and its associated methods to recognize the new type.
  • Enforced that CustomFeeTransaction is not allowed in P2P transaction processing, returning an error if encountered.
  • Modified l2_hook to deduct and refund fees according to the ERC20 tokens desired as the user

@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: 638
Total lines removed: 0
Total lines changed: 638

Detailed view
+----------------------------------------------------------+-------+------+
| File                                                     | Lines | Diff |
+----------------------------------------------------------+-------+------+
| ethrex/cmd/ethrex/build_l2.rs                            | 412   | +15  |
+----------------------------------------------------------+-------+------+
| ethrex/crates/blockchain/blockchain.rs                   | 1296  | +1   |
+----------------------------------------------------------+-------+------+
| ethrex/crates/blockchain/metrics/metrics_transactions.rs | 151   | +2   |
+----------------------------------------------------------+-------+------+
| ethrex/crates/common/types/receipt.rs                    | 343   | +2   |
+----------------------------------------------------------+-------+------+
| ethrex/crates/common/types/transaction.rs                | 3147  | +310 |
+----------------------------------------------------------+-------+------+
| ethrex/crates/l2/networking/rpc/signer.rs                | 276   | +11  |
+----------------------------------------------------------+-------+------+
| ethrex/crates/l2/sdk/src/sdk.rs                          | 938   | +20  |
+----------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/clients/eth/mod.rs          | 622   | +1   |
+----------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/eth/fee_market.rs           | 232   | +3   |
+----------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/types/transaction.rs        | 101   | +5   |
+----------------------------------------------------------+-------+------+
| ethrex/crates/vm/backends/levm/mod.rs                    | 614   | +2   |
+----------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/environment.rs                 | 94    | +1   |
+----------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/hooks/l2_hook.rs               | 510   | +263 |
+----------------------------------------------------------+-------+------+
| 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

Benchmark Results: Push

Command Mean [s] Min [s] Max [s] Relative
main_revm_Push 355.1 ± 180.0 297.2 867.4 1.19 ± 0.60
main_levm_Push 312.9 ± 1.9 310.7 317.3 1.05 ± 0.01
pr_revm_Push 297.7 ± 1.8 296.1 302.6 1.00
Detailed Results

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
main_revm_BubbleSort 4.770 ± 0.040 4.736 4.863 1.04 ± 0.01
main_levm_BubbleSort 4.581 ± 0.016 4.563 4.604 1.00 ± 0.01
pr_revm_BubbleSort 4.740 ± 0.015 4.716 4.765 1.04 ± 0.01
pr_levm_BubbleSort 4.575 ± 0.018 4.552 4.612 1.00

Benchmark Results: ERC20Approval

Command Mean [s] Min [s] Max [s] Relative
main_revm_ERC20Approval 1.552 ± 0.015 1.540 1.589 1.00 ± 0.01
main_levm_ERC20Approval 1.674 ± 0.014 1.657 1.698 1.08 ± 0.01
pr_revm_ERC20Approval 1.546 ± 0.009 1.537 1.563 1.00
pr_levm_ERC20Approval 1.657 ± 0.007 1.649 1.670 1.07 ± 0.01

Benchmark Results: ERC20Mint

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Mint 184.5 ± 1.8 183.4 189.2 1.00 ± 0.01
main_levm_ERC20Mint 205.4 ± 2.1 202.7 208.6 1.12 ± 0.01
pr_revm_ERC20Mint 183.9 ± 1.1 182.9 185.9 1.00
pr_levm_ERC20Mint 205.8 ± 3.0 202.9 212.8 1.12 ± 0.02

Benchmark Results: ERC20Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Transfer 354.4 ± 2.7 351.3 359.5 1.01 ± 0.01
main_levm_ERC20Transfer 393.5 ± 2.7 389.7 399.9 1.12 ± 0.01
pr_revm_ERC20Transfer 351.9 ± 2.2 348.9 357.1 1.00
pr_levm_ERC20Transfer 390.8 ± 1.3 388.1 392.8 1.11 ± 0.01

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Factorial 236.6 ± 4.4 233.2 244.8 1.01 ± 0.02
main_levm_Factorial 281.6 ± 10.8 276.7 312.1 1.20 ± 0.05
pr_revm_Factorial 234.2 ± 1.6 232.7 237.3 1.00
pr_levm_Factorial 283.2 ± 0.5 282.4 283.7 1.21 ± 0.01

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.655 ± 0.034 1.587 1.702 1.00
main_levm_FactorialRecursive 8.384 ± 0.048 8.299 8.446 5.07 ± 0.11
pr_revm_FactorialRecursive 1.678 ± 0.041 1.599 1.740 1.01 ± 0.03
pr_levm_FactorialRecursive 8.389 ± 0.033 8.336 8.446 5.07 ± 0.11

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Fibonacci 213.5 ± 1.1 212.4 215.3 1.00
main_levm_Fibonacci 262.5 ± 4.3 255.9 269.7 1.23 ± 0.02
pr_revm_Fibonacci 219.0 ± 7.9 210.2 236.8 1.03 ± 0.04
pr_levm_Fibonacci 267.3 ± 3.2 263.5 272.7 1.25 ± 0.02

Benchmark Results: FibonacciRecursive

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_FibonacciRecursive 878.1 ± 6.4 867.9 890.3 1.11 ± 0.01
main_levm_FibonacciRecursive 788.5 ± 10.4 781.9 817.4 1.00 ± 0.02
pr_revm_FibonacciRecursive 885.9 ± 7.5 875.7 901.9 1.12 ± 0.01
pr_levm_FibonacciRecursive 787.6 ± 6.0 778.7 797.6 1.00

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ManyHashes 12.5 ± 0.2 12.4 12.8 1.01 ± 0.02
main_levm_ManyHashes 13.7 ± 0.1 13.6 13.8 1.10 ± 0.01
pr_revm_ManyHashes 12.4 ± 0.1 12.4 12.7 1.00
pr_levm_ManyHashes 13.9 ± 0.4 13.6 14.8 1.12 ± 0.03

Benchmark Results: MstoreBench

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_MstoreBench 269.4 ± 3.4 266.3 277.1 1.06 ± 0.01
main_levm_MstoreBench 253.5 ± 0.9 252.1 254.9 1.00
pr_revm_MstoreBench 271.2 ± 8.5 265.7 292.6 1.07 ± 0.03
pr_levm_MstoreBench 255.6 ± 3.1 252.7 261.4 1.01 ± 0.01

Benchmark Results: Push

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Push 355.1 ± 180.0 297.2 867.4 1.19 ± 0.60
main_levm_Push 312.9 ± 1.9 310.7 317.3 1.05 ± 0.01
pr_revm_Push 297.7 ± 1.8 296.1 302.6 1.00
pr_levm_Push 311.9 ± 9.3 307.3 338.4 1.05 ± 0.03

Benchmark Results: SstoreBench_no_opt

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_SstoreBench_no_opt 223.3 ± 1.0 222.2 225.8 2.64 ± 0.04
main_levm_SstoreBench_no_opt 84.7 ± 2.1 81.9 88.2 1.00 ± 0.03
pr_revm_SstoreBench_no_opt 224.6 ± 3.7 222.7 234.8 2.65 ± 0.06
pr_levm_SstoreBench_no_opt 84.7 ± 1.2 83.1 87.1 1.00

@tomip01 tomip01 requested a review from jrchatruc as a code owner October 28, 2025 04:54
@tomip01
Copy link
Contributor Author

tomip01 commented Oct 28, 2025

Requested some changes in the code, and finally, include official documentation for:

  • An overview of the feature
  • Operator documentation on how to launch a network with a fee token

I see that we are missing an IFeeToken interface for IERC20, IERC20L2 contracts to implement to be a valid fee token. Is there a reason this was not done that way?

Comment on lines 20 to 41
```rust
use ethrex_l2_sdk::{build_generic_tx, send_generic_transaction};
use ethrex_rpc::clients::eth::Overrides;
use ethrex_common::types::TxType;
let mut tx = build_generic_tx(
l2_client,
TxType::FeeToken,
recipient,
origin,
ethrex_common::Bytes::default(),
Overrides {
fee_token: Some(fee_token),
value: Some(value),
..Default::default()
},
)
.await;

let tx_hash = send_generic_transaction(l2_client, tx, signer)
.await;

```
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a complete example on how to do this.
It doesn't specify how to create l2_client and signer.
Maybe even deploying the fee_token if possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right! Let me know what you think about this a6b20e3

"{test}: Priority fee mismatch"
);

if std::env::var("INTEGRATION_TEST_SKIP_FEE_VAULTS_CHECK").is_err() {
Copy link
Contributor

Choose a reason for hiding this comment

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

The Operator and L1 vault balances must always be balance_before - balance_after = fee, as the fee will be 0 if it is not active. The only vault that should be under the env var is the base fee vault as it can be burn depending on the network configuration, but for that we have the INTEGRATION_TEST_SKIP_BASE_FEE_VAULT_CHECK already.

Copy link
Contributor Author

@tomip01 tomip01 Oct 30, 2025

Choose a reason for hiding this comment

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

Done 4c67d94

## Operator Workflow

1. Deploy or reuse an `IFeeToken` implementation and note its L2 address.
2. Instantiate an `EthClient` and a signer (local or remote) that will send the transaction.
Copy link
Contributor

Choose a reason for hiding this comment

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

Sending a transaction is not part of the Operator Workflow.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a warning explaining what is missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L2 Rollup client

Projects

Status: Requires Changes

Development

Successfully merging this pull request may close these issues.

6 participants