Skip to content
Business logic Audit finding Advanced

User-supplied AMM pools and no input validation allows stealing of stEth protocol fees

The lend methods in several protocols accept user-supplied underlying asset and swap pool without verifying they match, allowing an attacker to supply a cheap token like DAI while instructing the contract to swap its accumulated stEth fees with zero minimum output. By sandwiching the transaction, the attacker can steal all stEth fees.

IllIllI Follow with 0x52 and kenzo

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-10-illuminate-judging/issues/47

Found by

IllIllI, 0x52, kenzo

Summary

Some of the protocols lend methods take as user input the underlying asset and the pool to swap on. They do not check that they match. Therefore a user can supply to Lender DAI underlying, instruct Lender to swap stEth with 0 minAmountOut, and sandwich the transaction to 0, thereby stealing all of Lender's stEth fees.

Vulnerability Detail

In Tempus, APWine, Sense, Illuminate and Swivel's lend methods, the underlying, the pool to swap on, and the minAmountOut, are all user inputs. There is no check that they match, and the external swap parameters do not contain the actual asset to swap - only the pool to swap in. Which is a user input. So an attacker can do the following, for example with APWine:

  • Let's say Lender has accumulated 100 stEth in fees.
  • The attacker will call APWine's lend, with underlying = DAI, amount = 100 eth, minimumAmountOfTokensToBuy = 0, and AMM pool (x) that is actually for stEth (tam tam tam!).
  • lend will pull 100 DAI from the attacker.
  • lend will call APWine's router with the stEth pool, and 0 minAmountOut. (I show this in code snippet section below).
  • The attacker will sandwich this whole lend call such that Lender will receive nearly 0 tokens. This is possible since the user-supplied minAmountOut is 0.
  • lend will execute this swapping operation. It will receive nearly 0 APWine-stEth-PTs.
  • Since the attacker sandwiched this transaction to 0, he will gain all the stEth that Lender tried to swap - all the stEth fees of the protocol.

Impact

Theft of stEth fees, as detailed above.

Code Snippet

Here is APWine's lend method. You can notice the following things. Specifically note the swapExactAmountIn operation.

  • There is no check that user-supplied pool swaps token u
  • apwinePairPath() and apwineTokenPath() do not contain actual asset addresses, but only relative 0 or 1
  • Therefore, pool can be totally unrelated to u
  • The user supplies the slippage limit - r - so he can use 0
  • The swap will be executed for the same amount (minus fees) that has been pulled from the user; but user can supply DAI and swap for same amount of stEth, a Very Profitable Trading Strategy
  • We call the real APWine router so Lender has already approved it

Because of these, the attack described above will succeed - the user can supply DAI as underlying, but actually make Lender swap stEth with 0 minAmountOut.

Solidity
    /// @notice lend method signature for APWine
    /// @param p principal value according to the MarketPlace's Principals Enum
    /// @param u address of an underlying asset
    /// @param m maturity (timestamp) of the market
    /// @param a amount of underlying tokens to lend
    /// @param r slippage limit, minimum amount to PTs to buy
    /// @param d deadline is a timestamp by which the swap must be executed
    /// @param x APWine router that executes the swap
    /// @param pool the AMM pool used by APWine to execute the swap
    /// @return uint256 the amount of principal tokens lent out
    function lend( uint8 p, address u, uint256 m, uint256 a, uint256 r, uint256 d, address x, address pool) external unpaused(u, m, p) returns (uint256) {
        address principal = IMarketPlace(marketPlace).token(u, m, p);

        // Transfer funds from user to Illuminate
        Safe.transferFrom(IERC20(u), msg.sender, address(this), a);

        uint256 lent;
        {
            // Add the accumulated fees to the total
            uint256 fee = a / feenominator;
            fees[u] = fees[u] + fee;

            // Calculate amount to be lent out
            lent = a - fee;
        }

        // Get the starting APWine token balance
        uint256 starting = IERC20(principal).balanceOf(address(this));

        // Swap on the APWine Pool using the provided market and params
        IAPWineRouter(x).swapExactAmountIn(
            pool,
            apwinePairPath(),
            apwineTokenPath(),
            lent,
            r,
            address(this),
            d,
            address(0)
        );

        // Calculate the amount of APWine principal tokens received after the swap
        uint256 received = IERC20(principal).balanceOf(address(this)) -
            starting;

        // Mint Illuminate zero coupons
        IERC5095(principalToken(u, m)).authMint(msg.sender, received);

        emit Lend(p, u, m, received, a, msg.sender);
        return received;
    }

    function apwineTokenPath() internal pure returns (uint256[] memory) {
        uint256[] memory tokenPath = new uint256[](2);
        tokenPath[0] = 1;
        tokenPath[1] = 0;
        return tokenPath;
    }

    /// @notice returns array pair path required for APWine's swap method
    /// @return array of uint256[] as laid out in APWine's docs
    function apwinePairPath() internal pure returns (uint256[] memory) {
        uint256[] memory pairPath = new uint256[](1);
        pairPath[0] = 0;
        return pairPath;
    }

The situation is similar in:

  • Tempus, where x is the pool to swap on.
  • Sense, where adapter is user-supplied.
  • Illuminate, where if the principal is Yield, the function is checking that the underlying token matches the pool. But the user can supply the principal to be Illuminate, bypassing this check, and supplying the YieldPool y to be one that swaps stEth for fyEth.
  • Swivel, where I believe that the user can supply an order to swap stEth instead of DAI.

Tool used

Manual Review

Recommendation

Check that the user-supplied pool/adapter/order's tokens match the underlying. This should ensure that the user only swaps assets he supplied.

Discussion

0x00052

Escalate for 25 USDC

This can be used to steal protocol fees, see my issue #161 (duplicate). Loss of funds with no external factors should be high not medium. Historically this has included protocol fees being stolen (see Mover H-1)

sherlock-admin

Escalate for 25 USDC

This can be used to steal protocol fees, see my issue #161 (duplicate). Loss of funds with no external factors should be high not medium. Historically this has included protocol fees being stolen (see Mover H-1)

You've created a valid escalation for 25 USDC!

To remove the escalation from consideration: Delete your comment. To change the amount you've staked on this escalation: Edit your comment (do not create a new comment).

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

Evert0x

Escalation accepted

sherlock-admin

Escalation accepted

This issue's escalations have been accepted!

Contestants' payouts and scores will be updated according to the changes made on this issue.

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

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 lack of validation that the user-supplied swap pool or adapter matches the underlying asset, combined with user-controlled slippage limits.

Impact

The attacker can steal all accumulated stEth protocol fees.

What the attacker needed

Lender has accumulated stEth fees; Attacker can sandwich the transaction

The fix

The contract should check that the user-supplied pool, adapter, or order's tokens match the underlying asset.

How it was found

  1. The attacker calls APWine's lend with underlying set to DAI, amount 100 eth, minimumAmountOfTokensToBuy set to 0, and an AMM pool that is actually for stEth.
  2. The lend function pulls 100 DAI from the attacker.
  3. The lend function calls APWine's router with the stEth pool and 0 minAmountOut.
  4. The attacker sandwiches the whole lend call so that Lender receives nearly 0 tokens.
  5. The lend function executes the swap and receives nearly 0 APWine-stEth-PTs.
  6. Because the attacker sandwiched the transaction to 0, he gains all the stEth that Lender tried to swap, i.e., all the stEth fees.

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.

The contract lets users choose both the token they deposit and the trading pool to use, but it never checks that the pool actually trades that token. An attacker can deposit a cheap token but point the contract at a pool holding a valuable token, then manipulate the trade so the contract gets almost nothing back, while the attacker keeps the valuable token.

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 IllIllI

View all

119 more disclosed reports, best first.

More from Illuminate Round 2

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.