Skip to content
DoS Audit finding Intermediate

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.

PolarizedLight Follow

Originally disclosed on Code4rena

Submitted by PolarizedLight

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:

https://github.com/code-423n4/2025-05-blackhole/blob/92fff849d3b266e609e6d63478c4164d9f608e91/contracts/RouterV2.sol#L475-L475

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

https://github.com/code-423n4/2025-05-blackhole/blob/92fff849d3b266e609e6d63478c4164d9f608e91/contracts/RouterV2.sol#L475-L475

https://github.com/code-423n4/2025-05-blackhole/blob/92fff849d3b266e609e6d63478c4164d9f608e91/contracts/RouterV2.sol#L493

Impact

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.
  • Liquidity removal becomes unreliable, forcing users to abandon efficient permit-based operations.

Attack Prerequisites:

  • 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:

  1. 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
  2. Signature Creation:

    • Alice creates permit signature: permit(alice, routerV2, 1000, deadline, nonce=5)
    • Signature parameters: v=27, r=0x123..., s=0x456...
  3. Transaction Submission:

    • Alice submits: removeLiquidityWithPermit(tokenA, tokenB, false, 1000, 950, 950, alice, deadline, false, 27, 0x123..., 0x456...)
    • Transaction enters mempool with 20 gwei gas price
  4. Front-Running Execution:

    • Bob extracts parameters from Alice’s pending transaction
    • Bob submits direct call: IBaseV1Pair(0xABC...).permit(alice, routerV2, 1000, deadline, 27, 0x123..., 0x456...) with 25 gwei gas
    • Bob’s transaction mines first, consuming Alice’s nonce (nonce becomes 6)
  5. Victim Transaction Failure:

    • Alice’s transaction executes but fails at line 475
    • RouterV2 calls permit() with already-used signature
    • LP token rejects due to invalid nonce (expects 6, gets signature for nonce 5)
    • Entire transaction reverts with “Invalid signature” or similar error
  6. Attack Result:

    • Alice loses ~$15 in gas fees (failed transaction cost)
    • Alice cannot remove liquidity via permit method
    • Bob spent ~$3 in gas to grief Alice
    • Attack can be repeated indefinitely against any permit user

Impact Example:

  • During high network activity (50+ gwei), failed transactions cost $25-75 each
  • Systematic attacks against 100 users = $2,500-7,500 in direct user losses
  • No recourse for affected users; losses are permanent

Blackhole mitigated

Status: Unmitigated. Full details in reports from rayss and lonelybones, and also included in the Mitigation Review section below.


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.

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

  1. Alice creates a permit signature for the router to spend her LP tokens.
  2. Alice submits removeLiquidityWithPermit with the signature.
  3. Bob sees the pending transaction and extracts the permit parameters.
  4. Bob submits a direct permit call with higher gas, consuming the nonce.
  5. 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.

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.

More from Blackhole

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.