Skip to content
Business logic Audit finding Intermediate

Exiting a farm on mainnet assumes a peg of 1:1 when swapping stETH for ETH

The contract assumes a 1:1 peg between stETH and ETH when calculating the minimum ETH output for a Curve swap, so if stETH depegs, the swap reverts because the requested minimum exceeds what the pool can provide. An attacker could exploit this to cause legitimate users' transactions to fail, potentially disrupting operations.

0xStalin Follow

Originally disclosed on Code4rena

Submitted by 0xStalin

When stETH depegs from ETH, the swaps on Curve will revert due to requesting a higher amountOut than what the curves pool will give.

Proof of Concept

When exiting a farm on mainnet, the requested tokensOut is set as stETH for redeeming the SY tokens on the PENDLE_SY contract. Once the PowerFarm has on its balance the stETH tokens, it does a swap from stETH to ETH using the Curves protocol.

The problem is that the implementation is assuming a peg of 1 ETH ~= 1 stETH. Even though both tokens have a tendency to keep the peg, this hasn’t been always the case as it can be seen in this dashboard. There have been many episodes of market volatility that affected the price of stETH, notably the one in last June when stETH traded at ~0.93 ETH.

When computing the _minOutAmount, the PowerFarm calculates the ethValue of the received stETH tokens by requesting the price of the WETH asset, and then it applies the reverAllowedSpread to finally determine the _minOutAmount of ETH tokens that will be accepted from the swap on Curves.

The WETH price is pegged 1:1 to ETH, 1 WETH will always be 1 ETH, but, using the price of WETH to determine the minOutAmount is problematic, because, as seen in the dashboard, historically, 1 stETH has deppeged from 1:1 from ETH.

Example: Assume a user sets a slippage of 1%. If stETH were to depeg to 0.95 per ETH, when swapping it would try to make sure that the user received at least 0.99 ETH. Whenever trying to swap it will revert because curves can’t give the requested minOutAmount of ETH tokens, it could give at most 0.95 ETH per stETH.

function _logicClosePosition(
    ...
)
    private
{
    ...

    //@audit-info => When exiting a farm on mainnet, the `tokenOut` is set to be `stETH`
    address tokenOut = block.chainid == 1
        ? ST_ETH_ADDRESS
        : ENTRY_ASSET;

    ...

    uint256 ethAmount = _getEthBack(
        tokenOutAmount,
        _getTokensInETH(
            //@audit-info => When exiting a farm on mainnet, the price of the `tokenOut` is requested as if it were the price of `WETH`
            //@audit-issue => Here is where the code assumes a peg of `1 stETH to be 1 ETH`
            block.chainid == 1
                ? WETH_ADDRESS
                : ENTRY_ASSET,
            tokenOutAmount
        )
            * reverseAllowedSpread
            / PRECISION_FACTOR_E18
    );

    ...
}

function _getEthBack(
    uint256 _swapAmount,
    uint256 _minOutAmount
)
    internal
    returns (uint256)
{
    if (block.chainid == ETH_CHAIN_ID) {
        //@audit-info => Does a swap of stETH for ETH on the Curves exchange
        return _swapStETHintoETH(
            _swapAmount,
            _minOutAmount
        );
    }

    ...
}

function _swapStETHintoETH(
    uint256 _swapAmount,
    uint256 _minOutAmount
)
    internal
    returns (uint256)
{
    return CURVE.exchange(
        {
            fromIndex: 1,
            toIndex: 0,
            exactAmountFrom: _swapAmount,
            //@audit-info => minimum amount of ETH that the PowerFarm will accept for swapping `exactAmountFrom` of `stETH` tokens!
            minReceiveAmount: _minOutAmount
        }
    );
}

Tools Used

Referenced H-06 finding on Asymmetry Finance Solodit audit and Asymmetry’s C4 mitigation review here and here.

Recommended Mitigation Steps

The recommendation would be to implement a mitigation similar to the one implemented on the referenced issues. Basically, fetch the current price of stETH from a Chainlink Oracle and multiply the minOutAmount by the current price of stETH. In this way, the minOutAmount that is sent to the Curves exchange will now be within the correct limits based on the current price of stETH.

Also, make sure to multiply the ethValueBefore by the current price of stETH (only when exiting farms on mainnet). In this way, both amounts, ethValueAfter and ethValueBefore will be computed based on the current price of stETH, allowing the slippage to validate that no ethValue was lost during the process of removing liquidity from pendle, redeeming the sy tokens and swapping on curves. In the end, both, ethValueAfter and ethValueBefore will represent the ethValue based on the stETH price.

Assessed type

Context

vonMangoldt (Wise Lending) commented:

Since we have ethValueBefore and after we could also set it to 0 and no harm done, thus invalid.

Trust (judge) commented:

@vonMangoldt - Would need additional description for the issue described is not actually effective, as from my analysis I can’t find a counter-example.

vm06007 (Wise Lending) commented:

Mitigated here.

Additionally, the team decided to use PendleRouter (here) instead of Curve moving forward during farm exit.


The original report as published on Code4rena, by 0xStalin. 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 uses the price of WETH (which is always 1:1 with ETH) to calculate the minimum acceptable ETH output for a stETH-to-ETH swap, ignoring that stETH can trade below 1 ETH.

Impact

When stETH depegs, farm exits on mainnet could revert, preventing users from withdrawing their funds until the peg is restored or the contract is fixed.

What the attacker needed

StETH must be depegged from ETH; user initiates a farm exit on mainnet

The fix

The contract should fetch the current stETH price from a Chainlink oracle and use it to adjust the minimum output amount, and also apply it to the ethValueBefore calculation.

How it was found

  1. A user initiates a farm exit on mainnet, which sets tokenOut to stETH.
  2. The contract redeems SY tokens for stETH and holds them in the PowerFarm.
  3. The contract calculates the minimum ETH output using the WETH price and the allowed slippage.
  4. The contract calls Curve to swap stETH for ETH with that minimum output.
  5. If stETH is depegged, the swap reverts because Curve cannot provide the requested minimum ETH.

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.

This is about a smart contract that swaps one token (stETH) for another (ETH) on a decentralised exchange. The contract assumes these tokens are always worth the same, but sometimes stETH is worth less than ETH. When that happens, the swap fails because the contract asks for more ETH than the exchange can give.

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 0xStalin

View all

20 more disclosed reports, best first.

More from Wise Lending

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.