Skip to content
Business logic Audit finding Intermediate

Malicious users can frontrun permits to DoS swaps

A swap-and-deposit function calls a token permit inside a try/catch that swallows all errors, so an attacker can front-run the permit transaction and consume the signature. The victim's permit then fails silently and the following swap reverts, griefing the user's gasless transaction.

jaraxxus Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

28702 - [SC - Insight] Malicious users can frontrun permits to DoS swaps

Submitted on Feb 24th 2024 at 12:22:34 UTC by @jaraxxus for Boost | Puffer Finance

Report ID: #28702

Report type: Smart Contract

Report severity: Insight

Target: https://etherscan.io/address/0x7276925e42f9c4054afa2fad80fa79520c453d6a

Impacts:

  • Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol)

Description

Brief/Intro

A novel attack recently discovered, if permit is used within a function, it can be frontrunned and griefed.

Vulnerability Details

When swaps are available to the users (currently restricted), there is an option to do gasless transactions through the use of permit.

        try ERC20Permit(address(tokenIn)).permit({
            owner: msg.sender,
            spender: address(this),
            value: permitData.amount,
            deadline: permitData.deadline,
            v: permitData.v,
            s: permitData.s,
            r: permitData.r
        }) { } catch { }

If permit is used within a larger function, it can be frontrunned. Also, since the try/catch block does not catch any errors, nothing will prevent the frontrunning.

Impact Details

Permit will be frontrunned and swaps can be griefed. The user will lose the functionality that follows the permit().

References

https://vscode.blockscan.com/ethereum/0x7276925e42f9c4054afa2fad80fa79520c453d6a

Permit issue: https://www.trust-security.xyz/post/permission-denied

Proof of Concept

The permit call is within the swapAndDepositWithPermit() function. Also, the permit call does not catch any errors.

  function swapAndDepositWithPermit(
        address tokenIn,
        uint256 amountOutMin,
        IPufferDepositor.Permit calldata permitData,
        bytes calldata routeCode
    ) public payable virtual restricted returns (uint256 pufETHAmount) {
>       try ERC20Permit(address(tokenIn)).permit({
            owner: msg.sender,
            spender: address(this),
            value: permitData.amount,
            deadline: permitData.deadline,
            v: permitData.v,
            s: permitData.s,
            r: permitData.r
        }) { } catch { }

>       return swapAndDeposit(tokenIn, permitData.amount, amountOutMin, routeCode);

A better way to code the try/catch block is as such:

try (permit) {
return;
} catch {
    if(IERC20(token).allowance(owner, spender) >= value) {
        return;
    }
} revert("permit failure");
}
  1. Try the permit first
  2. If the permit fails, check if there is still allowance for the spender
  3. Otherwise, revert the whole function.

The original report as published on Immunefi, by jaraxxus. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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 permit call is wrapped in a try/catch that ignores every error, so a front-run permit leaves no allowance and the subsequent swap reverts instead of the function handling the failure gracefully.

Impact

Swaps can be griefed and the user loses the functionality that follows the permit, with no stated profit for the attacker; the text notes swaps are currently restricted.

What the attacker needed

Swaps enabled (currently restricted); attacker can see pending permit tx

The fix

The permit should be attempted, and if it fails the code should check whether the spender already has sufficient allowance and only revert otherwise.

How it was found

  1. Call the swap-and-deposit-with-permit function with a permit signature.
  2. An attacker front-runs by submitting the same permit first.
  3. The victim's permit call fails and the error is swallowed.
  4. The following swap-and-deposit call reverts because no allowance remains.

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 move your tokens without you sending a separate approval transaction. Because the signature can be used by anyone, an attacker can submit it first, so when your own transaction arrives the signature is already used up. Here the code ignores that failure and carries on, so the rest of the action breaks and you lose the benefit of the transaction.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More from Puffer Finance

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.