Skip to content
Business logic Audit finding Intermediate

V3Vault.sol permit signature does not check receiving token address is USDC

The V3Vault contract accepted Permit2 signatures without verifying that the transferred token was USDC, allowing an attacker to use a permit for any ERC20 token and have it treated as USDC. This could let an attacker deposit a worthless token and steal USDC from the vault.

VAD37 Follow with santiellena, ArsenLupin and 2 others

Originally disclosed on Code4rena

Submitted by VAD37, also found by thank_you (1, 2, 3), santiellena, ArsenLupin, jesusrod15, and ayden

In V3Vault.sol there all 3 instances of permit2.permitTransferFrom(), all 3 does not check token transfered in is USDC token. Allowing user to craft permit signature from any ERC20 token and Vault will accept it as USDC.

Impact

User can steal all USDC from vault using permit signature of any ERC20 token.

Proof of Concept

Here is how Vault accept USDC from user. Vault will accept Uniswap.Permit2 signature transfer allowance from Permit2 then to vault contract.

https://github.com/code-423n4/2024-03-revert-lend/blob/435b054f9ad2404173f36f0f74a5096c894b12b7/src/V3Vault.sol#L877C1-L917C6

    if (params.permitData.length > 0) {
        (ISignatureTransfer.PermitTransferFrom memory permit, bytes memory signature) =
            abi.decode(params.permitData, (ISignatureTransfer.PermitTransferFrom, bytes));
        permit2.permitTransferFrom(
            permit,
            ISignatureTransfer.SignatureTransferDetails(address(this), state.liquidatorCost),
            msg.sender,
            signature
        );
    } else {
        // take value from liquidator
        SafeERC20.safeTransferFrom(IERC20(asset), msg.sender, address(this), state.liquidatorCost);
    }

Below is permit signature struct that can be decoded from user provided data:

interface ISignatureTransfer is IEIP712 {
    /// @notice The token and amount details for a transfer signed in the permit transfer signature
    struct TokenPermissions {
        // ERC20 token address
        address token;
        // the maximum amount that can be spent
        uint256 amount;
    }

    /// @notice The signed permit message for a single token transfer
    struct PermitTransferFrom {
        TokenPermissions permitted;
        // a unique value for every token owner's signature to prevent signature replays
        uint256 nonce;
        // deadline on the permit signature
        uint256 deadline;
    }
}

V3Vault.sol needs to check TokenPermissions.token is USDC, same as vault main asset.

Uniswap.permit2.permitTransferFrom() only checks if the sign signature is correct. This is meaningless as Vault does not validate input data.

This allows users to use any ERC20 token, gives allowance and permits to Uniswap.Permit2. The Vault will accept any transfer token from Permit2 as USDC. Allowing users to deposit any ERC20 token and steal USDC from vault.

Recommended Mitigation Steps

Fix missing user input validations in 3 all instances of permit2:

https://github.com/code-423n4/2024-03-revert-lend/blob/main/src/V3Vault.sol#L717C1-L725C15 https://github.com/code-423n4/2024-03-revert-lend/blob/main/src/V3Vault.sol#L893C1-L898C15 https://github.com/code-423n4/2024-03-revert-lend/blob/main/src/V3Vault.sol#L877C1-L917C6

    if (params.permitData.length > 0) {
        (ISignatureTransfer.PermitTransferFrom memory permit, bytes memory signature) =
            abi.decode(params.permitData, (ISignatureTransfer.PermitTransferFrom, bytes));
        require(permit.permitted.token == asset, "V3Vault: invalid token");
        //@permitted amount is checked inside uniswap Permit2
        permit2.permitTransferFrom(
            permit,
            ISignatureTransfer.SignatureTransferDetails(address(this), state.liquidatorCost),
            msg.sender,
            signature
        );
    } else {
        // take value from liquidator
        SafeERC20.safeTransferFrom(IERC20(asset), msg.sender, address(this), state.liquidatorCost);
    }

Assessed type

ERC20

kalinbas (Revert) confirmed

Revert mitigated:

PR here - checks token in permit.

Status: Mitigation confirmed. Full details in reports from thank_you, b0g0 and ktg.


The original report as published on Code4rena, by VAD37. 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

The contract did not validate that the token address in the Permit2 signature matched the vault's asset (USDC).

Impact

An attacker could deposit any ERC20 token and steal all USDC from the vault.

What the attacker needed

A Permit2 signature for any ERC20 token; access to a vault function using permitData

The fix

The vault was fixed by adding a check that the permitted token equals the vault's asset before calling permitTransferFrom.

How it was found

  1. Craft a Permit2 signature for an arbitrary ERC20 token.
  2. Call a vault function that accepts permitData, passing the crafted signature.
  3. The vault processes the permit without checking the token address and treats the transfer as USDC.

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 signature is a way to approve a token transfer without a separate transaction. The vault failed to check which token the permit was for, so someone could approve a transfer of a different token and the vault would still credit them with USDC, letting them take real USDC from the vault.

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 by VAD37

View all

3 more disclosed reports, best first.

More from Revert Lend

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.