-
Notifications
You must be signed in to change notification settings - Fork 26
feat: zone fee manager #680
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
Draft
0xKitsune
wants to merge
8
commits into
main
Choose a base branch
from
kit/fee-manager-impl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
300c30e
feat: add zone-native fee manager
0xKitsune 3faa8c5
fix: use canonical fee manager address
0xKitsune 9b9c437
Merge remote-tracking branch 'origin/main' into kit/fee-manager-impl
0xKitsune 3a8f8d9
fmt: forge fmt
0xKitsune dd12d87
Merge remote-tracking branch 'origin/main' into kit/fee-manager-impl
0xKitsune d555931
fix: harden zone fee token handling
0xKitsune 158d488
fix: align zone fee token pool validation
0xKitsune 50ef816
chore: refresh portal storage layout
0xKitsune File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| //! `ZoneFeeManager` — Zone L2 protocol fee manager. | ||
|
|
||
| crate::sol! { | ||
| #[derive(Debug)] | ||
| contract IZoneFeeManager { | ||
| event UserTokenSet(address indexed user, address indexed token); | ||
| event FeesDistributed(address indexed sequencer, address indexed token, uint256 amount); | ||
|
|
||
| function userTokens(address user) external view returns (address); | ||
| function collectedFees(address sequencer, address token) external view returns (uint256); | ||
| function setUserToken(address token) external; | ||
| function distributeFees(address sequencer, address token) external; | ||
| function isEnabledToken(address token) external view returns (bool); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| //! Adapter between Tempo's protocol fee hooks and the zone fee-manager precompile. | ||
|
|
||
| use alloy_primitives::{Address, U256}; | ||
| use alloy_sol_types::SolCall; | ||
| use revm::{Database, context::Journal}; | ||
| use tempo_chainspec::hardfork::TempoHardfork; | ||
| use tempo_precompiles::{ | ||
| DEFAULT_FEE_TOKEN, | ||
| error::Result, | ||
| storage::{Handler, StorageActions}, | ||
| }; | ||
| use tempo_revm::{ProtocolFeeManager, TempoStateAccess, TempoTx, TempoTxEnv}; | ||
| use tempo_zone_contracts::{IZoneFeeManager, ZONE_FEE_MANAGER_ADDRESS}; | ||
| use zone_l1::state::L1StateProvider; | ||
| use zone_precompiles::ZoneFeeManager; | ||
|
|
||
| /// Zone implementation of Tempo's internal protocol fee hooks. | ||
| #[derive(Debug, Clone)] | ||
| pub(crate) struct ZoneProtocolFeeManager { | ||
| provider: L1StateProvider, | ||
| } | ||
|
|
||
| impl ZoneProtocolFeeManager { | ||
| pub(crate) const fn new(provider: L1StateProvider) -> Self { | ||
| Self { provider } | ||
| } | ||
| } | ||
|
|
||
| impl<DB: Database> ProtocolFeeManager<DB> for ZoneProtocolFeeManager { | ||
| fn get_fee_token( | ||
| &self, | ||
| journal: &mut Journal<DB>, | ||
| tx: &TempoTxEnv, | ||
| fee_payer: Address, | ||
| spec: TempoHardfork, | ||
| actions: StorageActions, | ||
| ) -> Result<Address> { | ||
| if let Some(token) = tx.fee_token() { | ||
| return Ok(token); | ||
| } | ||
|
|
||
| // A direct preference update pays in the newly selected token, matching | ||
| // the behavior of Tempo's public fee manager. | ||
| if !tx.is_aa() | ||
| && fee_payer == tx.caller() | ||
| && let Some((kind, input)) = tx.calls().next() | ||
| && kind.to() == Some(&ZONE_FEE_MANAGER_ADDRESS) | ||
| && let Ok(call) = IZoneFeeManager::setUserTokenCall::abi_decode(input) | ||
| { | ||
| return Ok(call.token); | ||
| } | ||
|
|
||
| let preferred = journal.with_read_only_storage_ctx(spec, actions.clone(), || { | ||
| ZoneFeeManager::new().user_tokens[fee_payer].read() | ||
| })?; | ||
| if !preferred.is_zero() { | ||
| return Ok(preferred); | ||
| } | ||
|
|
||
| // Preserve Tempo's TIP-20 call inference and default-token behavior for | ||
| // users that have not selected a zone preference. | ||
| journal.get_fee_token(tx, fee_payer, spec, actions) | ||
| } | ||
|
|
||
| fn get_validator_token( | ||
| &self, | ||
| _journal: &mut Journal<DB>, | ||
| _beneficiary: Address, | ||
| _spec: TempoHardfork, | ||
| _actions: StorageActions, | ||
| ) -> Result<Address> { | ||
| // Zones never negotiate a validator token or enter an AMM route. | ||
| Ok(DEFAULT_FEE_TOKEN) | ||
| } | ||
|
|
||
| fn collect_fee_pre_tx( | ||
| &self, | ||
| fee_payer: Address, | ||
| user_token: Address, | ||
| max_amount: U256, | ||
| _beneficiary: Address, | ||
| _skip_liquidity_check: bool, | ||
| ) -> Result<Address> { | ||
| ZoneFeeManager::new().collect_fee_pre_tx(&self.provider, fee_payer, user_token, max_amount) | ||
| } | ||
|
|
||
| fn collect_fee_post_tx( | ||
| &self, | ||
| fee_payer: Address, | ||
| actual_spending: U256, | ||
| refund_amount: U256, | ||
| fee_token: Address, | ||
| beneficiary: Address, | ||
| ) -> Result<U256> { | ||
| ZoneFeeManager::new().collect_fee_post_tx( | ||
| fee_payer, | ||
| actual_spending, | ||
| refund_amount, | ||
| fee_token, | ||
| beneficiary, | ||
| ) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🚨 [SECURITY] Default pathUSD fees are rejected on zones created with a custom initial token
This preserves Tempo's fallback to
DEFAULT_FEE_TOKEN/pathUSD for users without an explicit or stored preference, butZoneFeeManager::collect_fee_pre_txnow requires the resolved token to be enabled in the L1ZonePortalregistry. The custom-initial-token creation flow enables only the operator-selectedinitialTokenon the portal, while zone genesis still always creates pathUSD as the default fee token. On a zone initialized with a non-pathUSD token, ordinary transactions that fall back to pathUSD failensure_enabled(pathUSD)and are rejected until pathUSD is separately enabled on L1.Recommended Fix: Keep genesis/default fee-token setup and the portal-enabled token set consistent: enable pathUSD on the portal in addition to a custom initial token, make genesis default to the chosen initial token, or explicitly special-case/document the genesis default token with tests for the custom-initial-token flow.