Skip to content
Smart contracts Audit finding Intermediate

Protocol mints less rsETH on deposit than intended

The deposit function transfers the user's tokens before calculating how many rsETH to mint, so the price used for the calculation already includes the new deposit. As a result, depositors receive fewer rsETH than they should, causing a direct loss of funds.

T1MOH Follow with 0xepley, SBSecurity and 34 others

Originally disclosed on Code4rena

Submitted by T1MOH, also found by 0xepley, SBSecurity, cryptothemex, adriro, AlexCzm, trachev, adam-idarrha, Aymen0909, deepplus, xAriextz, ast3ros, Weed0607, DanielArmstrong, rouhsamad, osmanozdemir1, GREY-HAWK-REACH, 0x1337, zhaojie, Jiamin, crunch, Varun_05, 7siech, QiuhaoLi, circlelooper, HChang26, Juntao, ayden, Aamir, rvierdiiev, max10afternoon, crack-the-kelp, Ruhum, 0xluckhu, 0xNaN, mahdirostami, and 0xmystery

Price of rsETH is calculated as totalLockedETH / rsETHSupply. rsETH price is used to calculate rsETH amount to mint when user deposits. Formulas are following:

  • rsethAmountToMint = amount * assetPrice / rsEthPrice
  • rsEthPrice = totalEthLocked / rsETHSupply

Problem is that it transfers deposit amount before calculation of rsethAmountToMint. It increases totalEthLocked. As a result rsethAmountToMint is less than intended because rsEthPrice is higher.

For example:

  1. Suppose totalEthLocked = 10e18, assetPrice = 1e18, rsETHSupply = 10e18
  2. User deposits 30e18. He expects to receive 30e18 rsETH
  3. However actual received amount will be 30e18 * 1e18 / ((30e18 * 1e18 + 10e18 * 1e18) / 10e18) = 7.5e18

Proof of Concept

Here you can see that it firstly transfers asset to address(this), then calculates amount to mint:

    function depositAsset(
        address asset,
        uint256 depositAmount
    )
        external
        whenNotPaused
        nonReentrant
        onlySupportedAsset(asset)
    {
        ...

        if (!IERC20(asset).transferFrom(msg.sender, address(this), depositAmount)) {
            revert TokenTransferFailed();
        }

        // interactions
        uint256 rsethAmountMinted = _mintRsETH(asset, depositAmount);

        emit AssetDeposit(asset, depositAmount, rsethAmountMinted);
    }

There is long chain of calls:

_mintRsETH()
    getRsETHAmountToMint()
        LRTOracle().getRSETHPrice()
            getTotalAssetDeposits()
                getTotalAssetDeposits()

Finally getTotalAssetDeposits() uses current balanceOf(), which was increased before by transferring deposit amount:

    function getAssetDistributionData(address asset)
        public
        view
        override
        onlySupportedAsset(asset)
        returns (uint256 assetLyingInDepositPool, uint256 assetLyingInNDCs, uint256 assetStakedInEigenLayer)
    {
        // Question: is here the right place to have this? Could it be in LRTConfig?
@>      assetLyingInDepositPool = IERC20(asset).balanceOf(address(this));

        uint256 ndcsCount = nodeDelegatorQueue.length;
        for (uint256 i; i < ndcsCount;) {
            assetLyingInNDCs += IERC20(asset).balanceOf(nodeDelegatorQueue[i]);
            assetStakedInEigenLayer += INodeDelegator(nodeDelegatorQueue[i]).getAssetBalance(asset);
            unchecked {
                ++i;
            }
        }
    }

Recommended Mitigation Steps

Transfer tokens in the end:

    function depositAsset(
        address asset,
        uint256 depositAmount
    )
        external
        whenNotPaused
        nonReentrant
        onlySupportedAsset(asset)
    {
        ...

+       uint256 rsethAmountMinted = _mintRsETH(asset, depositAmount);

        if (!IERC20(asset).transferFrom(msg.sender, address(this), depositAmount)) {
            revert TokenTransferFailed();
        }

-       // interactions
-       uint256 rsethAmountMinted = _mintRsETH(asset, depositAmount);
-
        emit AssetDeposit(asset, depositAmount, rsethAmountMinted);
    }

Assessed type

Oracle

RaymondFam (lookout) commented:

This vulnerability is worse than a donation attack.

gus (Kelp) confirmed and commented:

This is a legitimate issue and has been fixed in commit 3b4e36c740013b32b78e93b00438b25f848e5f76 to separately have rsETH price calculators and read value from state variables, which also helped reduce gas cost to a great extent as well. We thank the warden for alerting us to this issue.

0xDjango (judge) commented:

This is a High severity issue. The miscalculation causes direct fund loss to users.


The original report as published on Code4rena, by T1MOH. 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 deposit function updates the contract's token balance (by transferring tokens in) before reading that balance to compute the rsETH price used for minting, so the price is inflated by the deposit itself.

Impact

Depositors receive fewer rsETH than they should, causing direct fund loss to users.

What the attacker needed

User makes a deposit

The fix

The issue was fixed by calculating the rsETH amount before transferring the deposit tokens, and by using separate price calculators that read from state variables.

How it was found

  1. User calls depositAsset with a deposit amount.
  2. The contract transfers the deposit tokens from the user to itself, increasing its balance.
  3. The contract then calculates the rsETH price using the updated balance.
  4. The contract mints rsETH based on the inflated price, giving the user fewer rsETH than intended.

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.

When you deposit money into a system that gives you shares, the number of shares you get should be based on the value before your money arrives. Here, the system counted the new money first, which made each share look more valuable, so the depositor got fewer shares than they paid for. This means they lost money on every deposit.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by T1MOH

View all

11 more disclosed reports, best first.

More from Kelp DAO | rsETH

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.