ERC-2612 permit front-running in RouterV2 enables DoS of liquidity operations
The RouterV2 contract's removeLiquidityWithPermit and removeLiquidityETHWithPermit functions call permit without error handling, so an attacker can front-run the permit signature and cause the victim's transaction to revert. This leads to gas fee losses and a denial of service for permit-based liquidity removal.
The removeLiquidityWithPermit() and removeLiquidityETHWithPermit() functions in RouterV2 are vulnerable to front-running attacks that consume user permit signatures, causing legitimate liquidity removal transactions to revert and resulting in gas fee losses and a DOS.
Finding description
The RouterV2 contract implements ERC-2612 permit functionality without protection against front-running attacks. The vulnerability stems from the deterministic nature of permit signatures and the lack of error handling when permit calls fail.
This vulnerability follows a well-documented attack pattern that has been extensively researched. According to Trust Security’s comprehensive disclosure in January 2024: https://www.trust-security.xyz/post/permission-denied
“Consider, though, a situation where permit() is part of a contract call:
function deposit(uint256 amount, bytes calldata _signature) external {
// This will revert if permit() was front-run
token.permit(msg.sender, address(this), amount, deadline, v, r, s);
// User loses this functionality when permit fails
stakingContract.deposit(msg.sender, amount);
}
This function deposits in a staking contract on behalf of the user. But what if an attacker extracts the _signature parameters from the deposit() call and frontruns it with a direct permit()? In this case, the end result is harmful, since the user loses the functionality that follows the permit().”
In RouterV2’s removeLiquidityWithPermit() follows this exact vulnerable pattern:
IBaseV1Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s);
// User loses liquidity removal functionality when permit fails
(amountA, amountB) = removeLiquidity(tokenA, tokenB, stable, liquidity, amountAMin, amountBMin, to, deadline);
As Trust Security formally identified: “In fact, any function call that unconditionally performs permit() can be forced to revert this way.”
The root cause of the issue within the blackhole protocol is that RouterV2 makes unprotected external calls to LP token permit functions without any fallback mechanism or error handling:
// Line 475 - No error handling
IBaseV1Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s);
This creates a systematic vulnerability where any permit-based transaction can be griefed by extracting and front-running the permit signature.
Code Location
RouterV2.sol#L475 - removeLiquidityWithPermit() function
RouterV2.sol#L493 - removeLiquidityETHWithPermit() function
This vulnerability enables attackers to systematically deny service to users attempting to remove liquidity through permit-based functions, resulting in direct financial losses and protocol dysfunction.
Users lose transaction fees (typically $5-50 per transaction depending on network congestion) when their transactions revert.
Users must pay additional gas for traditional approve+remove patterns.
Minimal: Attacker needs only basic mempool monitoring capability and gas fees.
No special permissions or large capital requirements.
Attack can be automated and executed repeatedly.
Works against any user attempting permit-based operations.
Recommended mitigation steps
Implement a different method of permit handling by wrapping the permit call in a try-catch block and only reverting if both the permit fails and the current allowance is insufficient for the operation.
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
bool stable,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external virtual override returns (uint amountA, uint amountB) {
address pair = pairFor(tokenA, tokenB, stable);
uint value = approveMax ? type(uint).max : liquidity;
// Try permit, but don't revert if it fails
try IBaseV1Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s) {
// Permit succeeded
} catch {
// Permit failed, check if we have sufficient allowance
require(
IBaseV1Pair(pair).allowance(msg.sender, address(this)) >= liquidity,
"Insufficient allowance"
);
}
(amountA, amountB) = removeLiquidity(tokenA, tokenB, stable, liquidity, amountAMin, amountBMin, to, deadline);
}
This approach follows the industry-standard mitigation pattern that successfully resolved this vulnerability across 100+ affected codebases.
Proof of Concept
Theoretical attack walkthrough:
Setup Phase:
Alice holds 1000 LP tokens in pair 0xABC...
Alice wants to remove liquidity efficiently using removeLiquidityWithPermit()
Bob (attacker) monitors the mempool for permit-based transactions
Signature Creation:
Alice creates permit signature: permit(alice, routerV2, 1000, deadline, nonce=5)
The original report as published on Code4rena, by PolarizedLight. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the router unconditionally calls permit without a try-catch or fallback, so a front-run permit causes the entire transaction to revert.
Impact
Attackers can repeatedly deny service to users removing liquidity via permit, causing gas fee losses and making permit-based operations unreliable.
What the attacker needed
Mempool monitoring; gas fees; victim uses permit-based function
The fix
The permit call should be wrapped in a try-catch block and only revert if both the permit fails and the current allowance is insufficient.
How it was found
Alice creates a permit signature for the router to spend her LP tokens.
Alice submits removeLiquidityWithPermit with the signature.
Bob sees the pending transaction and extracts the permit parameters.
Bob submits a direct permit call with higher gas, consuming the nonce.
Alice's transaction reverts because the permit is already used.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
A permit is a signed message that lets someone else spend your tokens without a separate approval transaction. Here, the router tries to use that permit inside a larger function, but if an attacker copies the permit and submits it first, the permit is used up and the victim's transaction fails, wasting gas.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.