Skip to content
DoS Audit finding Intermediate

Inconsistent balance accounting in stETH deposits leads to DOS of core functions and reward loss

When stETH is deposited, the actual transferred amount can be slightly less than the requested amount due to rounding. The Distributor contract records the requested amount instead of the actual balance difference, causing an underflow in reward distribution that blocks core functions and loses rewards.

KlosMitSoss Follow with 0xDemon, Aristos and 9 others

Originally disclosed on Code4rena

Submitted by KlosMitSoss, also found by 0xDemon, Aristos, Avalance, Ivcho332, mishoko, mrMorningstar, newspacexyz, Olugbenga, SOPROBRO, Utsav, and Yaneca_b

https://github.com/code-423n4/2025-08-morpheus/blob/d275e9035b7e703efe26cdee6543e78f452774bb/contracts/capital-protocol/Distributor.sol#L295-L301

https://github.com/code-423n4/2025-08-morpheus/blob/d275e9035b7e703efe26cdee6543e78f452774bb/contracts/capital-protocol/Distributor.sol#L384-L386

Finding Description and Impact

When stETH is staked, the DepositPool::_stake() function only stores the actual balance difference, which might be different from the amount that was provided for the transfer due to rounding down:

// https://docs.lido.fi/guides/lido-tokens-integration-guide/#steth-internals-share-mechanics
uint256 balanceBefore_ = IERC20(depositToken).balanceOf(address(this));
IERC20(depositToken).safeTransferFrom(_msgSender(), address(this), amount_);
uint256 balanceAfter_ = IERC20(depositToken).balanceOf(address(this));

amount_ = balanceAfter_ - balanceBefore_;

https://github.com/code-423n4/2025-08-morpheus/blob/a65c254e4c3133c32c05b80bf2bd6ff9eced68e2/contracts/capital-protocol/DepositPool.sol#L379-L384

The link from the Lido documentation provided in the code comment explains that the “stETH balance calculation includes integer division, and there is a common case when the whole stETH balance can’t be transferred from the account while leaving the last 1-2 wei on the sender’s account. The same thing can actually happen at any transfer or deposit transaction. In the future, when the stETH/share rate becomes greater, the error can become a bit bigger. To avoid it, one can use transferShares to be precise.”

This means that the actual transferred amount could be lower than the amount that the transfer operation was called with due to rounding down. Hence, the actual balance difference is used in DepositPool::_stake(). This mechanism is also documented in the Morpheus documentation.

However, when Distributor::supply() is called within DepositPool::_stake(), which transfers the amount_ it was called with from the deposit pool to the distributor, the amount_ is stored in depositPool.deposited and depositPool.lastUnderlyingBalance instead of the actual balance difference:

IERC20(depositPool.token).safeTransferFrom(depositPoolAddress_, address(this), amount_);

depositPool.deposited += amount_;
depositPool.lastUnderlyingBalance += amount_;

https://github.com/code-423n4/2025-08-morpheus/blob/a65c254e4c3133c32c05b80bf2bd6ff9eced68e2/contracts/capital-protocol/Distributor.sol#L295-L301

As a result, the value stored in depositPool.lastUnderlyingBalance and depositPool.deposited could be larger than the actual balance of the contract. This leads to an issue in Distributor::distributeRewards() where this difference causes an underflow:

uint256 balance_ = IERC20(yieldToken_).balanceOf(address(this));
uint256 decimals_ = IERC20Metadata(yieldToken_).decimals();
uint256 underlyingYield_ = (balance_ - depositPool.lastUnderlyingBalance).to18(decimals_);

https://github.com/code-423n4/2025-08-morpheus/blob/a65c254e4c3133c32c05b80bf2bd6ff9eced68e2/contracts/capital-protocol/Distributor.sol#L384-L386

When the strategy of the deposit pool is Strategy.NONE (which is the case for stETH according to this code comment in IDistributor), the yieldToken_ will be the depositToken.

As long as the yield that stETH accrued does not exceed this difference between the stored value and actual balance, this leads to a DOS of Distributor::distributeRewards() and all functions that call it, including stake(), withdraw(), lockClaim(), and claim functions.

When stETH has accrued enough yield, this DOS will be resolved. However, the yield needed to balance out the values will not be recognized as actual yield. As a result, it will not be included in the rewards calculation. This leads to a loss of rewards for the stakers of the stETH deposit pool.

This issue also exists during the migration flow, where Distributor::supply() is called:

uint256 remainder_ = IERC20(depositToken).balanceOf(address(this)) - totalDepositedInPublicPools;
require(remainder_ > 0, "DS: yield for token is zero");
IERC20(depositToken).transfer(distributor, remainder_);

IDistributor(distributor).supply(rewardPoolIndex_, totalDepositedInPublicPools);

isMigrationOver = true;

https://github.com/code-423n4/2025-08-morpheus/blob/a65c254e4c3133c32c05b80bf2bd6ff9eced68e2/contracts/capital-protocol/DepositPool.sol#L151-L157

According to this documentation, migrate() will be used for stETH. Furthermore, the DepositPool.test.ts also uses a deposit pool with stETH as the depositToken and Strategy.NONE as its strategy.

Recommended Mitigation Steps

Only store the balance difference every time stETH is transferred, similar to the approach used in DepositPool::_stake().

Proof of Concept

Add the test to POC.test.ts and run npx hardhat test --grep "should expose lastUnderlyingBalance tracking issue due to stETH rounding during stake"

  describe('#stETH rounding behavior - lastUnderlyingBalance vs actual balance', () => {
    let stETHDepositPool: DepositPool;

    beforeEach(async () => {
      // Create a deposit pool with stETH as the deposit token
      const lib1 = await (await ethers.getContractFactory('ReferrerLib')).deploy();
      const lib2 = await (await ethers.getContractFactory('LockMultiplierMath')).deploy();
      const stETHDepositPoolFactory = await ethers.getContractFactory('DepositPool', {
        libraries: {
          ReferrerLib: await lib1.getAddress(),
          LockMultiplierMath: await lib2.getAddress(),
        },
      });
      const stETHDepositPoolImpl = await stETHDepositPoolFactory.deploy();
      const proxyFactory = await ethers.getContractFactory('ERC1967Proxy');
      const stETHDepositPoolProxy = await proxyFactory.deploy(await stETHDepositPoolImpl.getAddress(), '0x');
      stETHDepositPool = stETHDepositPoolFactory.attach(await stETHDepositPoolProxy.getAddress()) as DepositPool;

      await stETHDepositPool.DepositPool_init(await stETH.getAddress(), await distributor.getAddress());

      // Add stETH deposit pool to distributor
      await distributor.addDepositPool(
        publicRewardPoolId,
        await stETHDepositPool.getAddress(),
        await stETH.getAddress(),
        'ETH/USD',
        Strategy.NONE,
      );

      // Complete migration
      await stETHDepositPool.migrate(publicRewardPoolId);

      // Setup reward pool timestamp (required before any staking)
      await distributor.setRewardPoolLastCalculatedTimestamp(publicRewardPoolId, 1);

      // Set up a realistic total pooled ether amount to trigger rounding
      await stETH.setTotalPooledEther(wei('123456.789123456789'));

      // Set time to start reward distribution
      await setNextTime(oneDay * 11);
    });

    it('should expose lastUnderlyingBalance tracking issue due to stETH rounding during stake', async () => {
      const testAmounts = [
        wei('1.000000001'),      // Small fractional amount
      ];

      for (const amount of testAmounts) {
        // Mint exact stETH amount to alice
        await stETH.mint(alice.address, amount);
        await stETH.connect(alice).approve(await stETHDepositPool.getAddress(), amount);

        // Get initial balances
        const distributorInitialBalance = await stETH.balanceOf(await distributor.getAddress());

        // Get initial distributor pool state
        const initialDepositPoolData = await distributor.depositPools(publicRewardPoolId, await stETHDepositPool.getAddress());
        const initialLastUnderlyingBalance = initialDepositPoolData.lastUnderlyingBalance;

        // Perform stake operation - this triggers supply() in distributor
        // The distributor.supply() will update lastUnderlyingBalance with the amount parameter
        // But the actual stETH transfer may round down due to stETH mechanics
        await stETHDepositPool.connect(alice).stake(publicRewardPoolId, amount, 0, ZERO_ADDR);

        // Get final balances
        const distributorFinalBalance = await stETH.balanceOf(await distributor.getAddress());
        expect(distributorFinalBalance).to.be.gt(distributorInitialBalance);

        // Get final distributor pool state
        const finalDepositPoolData = await distributor.depositPools(publicRewardPoolId, await stETHDepositPool.getAddress());
        const finalLastUnderlyingBalance = finalDepositPoolData.lastUnderlyingBalance;
        expect(finalLastUnderlyingBalance).to.be.gt(initialLastUnderlyingBalance);

        // lastUnderlyingBalance > actual transferred stETH (distributor balance)
        expect(finalLastUnderlyingBalance).to.be.gt(distributorFinalBalance);

        // distributeRewards reverts due to 0x11 which is the panic code for underflow
        await expect(
          distributor.distributeRewards(publicRewardPoolId)
        ).to.be.revertedWithPanic(0x11);

        // the same goes for the functions where this is called (like stake and withdraw):
        // Mint exact stETH amount to alice
        await stETH.mint(alice.address, amount);
        await stETH.connect(alice).approve(await stETHDepositPool.getAddress(), amount);

        await expect(
          stETHDepositPool.connect(alice).stake(publicRewardPoolId, amount, 0, ZERO_ADDR)
        ).to.be.revertedWithPanic(0x11);
      }
    });
  });

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

Likely the Distributor contract stores the requested transfer amount instead of the actual balance difference when receiving stETH, so its recorded balance can exceed the real balance.

Impact

As long as accrued yield does not exceed the rounding difference, reward distribution and all functions that call it (stake, withdraw, lockClaim, claim) are blocked; once yield covers the gap, the yield used to balance the books is not counted as rewards, causing a loss for stakers.

What the attacker needed

StETH as deposit token; Strategy.NONE; small fractional deposit amount

The fix

The Distributor should store the actual balance difference after each stETH transfer, similar to the approach already used in DepositPool::_stake().

How it was found

  1. Deploy a DepositPool with stETH as the deposit token and Strategy.NONE.
  2. Complete migration and set the reward pool timestamp.
  3. Mint a small fractional stETH amount to a user and approve the DepositPool.
  4. Call stake() on the DepositPool, which triggers Distributor::supply().
  5. Observe that lastUnderlyingBalance is greater than the actual stETH balance of the Distributor.
  6. Call distributeRewards() and see it revert with an underflow panic.

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.

Some tokens like stETH can lose a tiny fraction (a few wei) when transferred because of how balances are calculated. The contract here records the full amount you asked to transfer, not what actually arrived, so its internal accounting becomes slightly too high. Later, when it tries to subtract that recorded amount from the real balance, the maths goes negative and the transaction fails, blocking deposits, withdrawals, and reward claims.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by KlosMitSoss

View all

25 more disclosed reports, best first.

More from Morpheus

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.