-
Notifications
You must be signed in to change notification settings - Fork 130
feat(l2): allow paying fees with custom token #5024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This reverts commit f6ccc00.
Lines of code reportTotal lines added: Detailed view |
Benchmark Results ComparisonNo significant difference was registered for any benchmark run. Detailed ResultsBenchmark Results: BubbleSort
Benchmark Results: ERC20Approval
Benchmark Results: ERC20Mint
Benchmark Results: ERC20Transfer
Benchmark Results: Factorial
Benchmark Results: FactorialRecursive
Benchmark Results: Fibonacci
Benchmark Results: FibonacciRecursive
Benchmark Results: ManyHashes
Benchmark Results: MstoreBench
Benchmark Results: Push
Benchmark Results: SstoreBench_no_opt
|
> [!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]>
There was a problem hiding this 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
FeeTokenTransactionas a new transaction type (0x7d) with fee token address field - Implemented
FeeTokenRegistrysystem contract (0xfffc) to manage allowed fee tokens - Modified
l2_hook.rsto 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.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
ManuelBilbao
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nit
Co-authored-by: Manuel Iñaki Bilbao <[email protected]>
**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]>
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
FeeTokenTransactionas a new variant to theTransactionenum, and updated theTxTypeenum and its associated methods to recognize the new type.l2_hookto deduct and refund fees according to the ERC20 tokens desired as the userinitial_fee_tokenthat will register one address in advance.How to test
You can see the
test_fee_tokenintests.rsto see how to build a tx.Some useful commands may be:
Register a new fee token:
Check if fee token is allowed