Add upper bound validation for integrator_fee_amount_bps in swap_exact_token_to#12
Open
RogerZoe wants to merge 11 commits into
Open
Add upper bound validation for integrator_fee_amount_bps in swap_exact_token_to#12RogerZoe wants to merge 11 commits into
RogerZoe wants to merge 11 commits into
Conversation
Documented a vulnerability related to unbounded integrator fee amounts in the swap process, outlining the root cause, impact, and recommended mitigation strategies.
Add test for unbounded integrator fee causing transaction revert due to excessive fee input.
Add test for unbounded integrator fee causing revert in swap.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR introduces validation for
integrator_fee_amount_bpsinswap_exact_token_to.Currently,
integrator_fee_amount_bpsis not bounded. UnderFeeOnBuypolicy, large values can inflateinternal_buy_token_amount, causing_swap_exact_token_toto revert due to exceedingsell_token_max_amount.While this does not lead to fund loss, it degrades swap liveness and introduces a griefing vector if the fee parameter is externally controlled (e.g., via integrator backend or relayer).
Problem
For
FeeOnBuy:If
bpsis excessively large (e.g., 50,000 = 500%), the router attempts to acquire an unrealistic buy amount.This inflated target propagates into
_swap_exact_token_to, where the iterative swap loop attempts to pull additional sell tokens until the target is met. Eventually, the required sell amount exceedssell_token_max_amount, causing the transaction to revert with:This ties an unbounded economic parameter directly to execution feasibility and allows economically nonsensical inputs to disrupt swap execution.
Proof of Concept
The following test demonstrates the issue:
With:
buy_token_amount = 100,000integrator_fee_bps = 50,000The computed values become:
The swap loop attempts to reach 600,000 buy tokens, eventually exceeding
sell_token_max_amountand reverting.Impact
integrator_fee_amount_bpsis externally controlled, an attacker can grief swaps by forcing predictable revertsSeverity: Informational → Low (depending on parameter control surface)
Mitigation Options
Option 1 — Hard Cap at 100%
Enforce:
This ensures fees cannot exceed 100% of the reference amount.
Option 2 — Protocol-Level Maximum
Define a protocol constant:
Then enforce:
This enforces economically reasonable limits aligned with protocol policy.
Option 3 — Defensive Target Bounding (Alternative Approach)
Instead of only bounding BPS, cap the internal target:
This decouples execution feasibility from fee amplification.