Skip to content
Business logic Audit finding Intermediate

Mismatch between yield amount deposited in shares calculation and getAccountYieldBalance()

The yield staking contract records the number of shares minted when depositing ETH into Etherfi or Lido as if they were the deposited asset amount, but later calculates yield using the actual ETH balance. This mismatch causes the yield amount for each staked NFT to be incorrect, allowing some NFTs to withdraw excess yield while others may be closer to liquidation.

0x73696d616f Follow

Originally disclosed on Code4rena

Submitted by 0x73696d616f, also found by bin2chen (1, 2)

Mismatch between the return amount in all yield Etherfi and Lido assets and the getAccountYieldBalance() call causes the yield amount of each staked nft to the same YieldAccount to be incorrect, leading to the possibility of withdrawing the excess for some nfts while being closer to liquidation on others

Proof of Concept

The issue stems from the fact that in YieldStakingBase::stake(), on deposit of the borrowed amount to the corresponding yield source (Etherfi or Lido), it returns the minted shares of each integration Etherfi and Lido. As all these integrations shares increase in value over time, on each deposit, less shares than the deposited ETH are minted. This will be problematic because YieldStakingBase uses the returned shares value from depositing as if they were assets, here. But then, it calculates totalAssets to compute the yield using the actual ETH balance of the positions Etherfi, Lido.

Due to this, if more than 1 nft is deposited, the borrowed amount and the yield amount will differ significantly. The first staked nft will have a bigger yield amount that can be claimed immediately and the following nfts will have instant losses that may end up being liquidated.

Replace the MockEtherfiLiquidityPool deposit logic to mimic the real behaviour. It is the same as having an assets/shares ratio in Etherfi of 0.9:

function deposit() external payable override returns (uint256) {
  require(msg.value > 0, 'msg value is 0');

  MockeETH(payable(eETH)).mint(msg.sender, msg.value);
  return msg.value * 9 / 10;
}

Place the following test in YieldEthStakingEtherfi.t.sol. The yield amount of each staked nft is different, but the borrowed amounts are the same.

function test_POC_Incorrect_Yield_tracking() public {
  YieldTestVars memory testVars;

  prepareWETH(tsDepositor1);

  uint256[] memory tokenIds = prepareIsolateBAYC(tsBorrower1);

  uint256 stakeAmount = tsYieldEthStakingEtherfi.getNftValueInUnderlyingAsset(address(tsBAYC));
  stakeAmount = (stakeAmount * 80) / 100;

  tsHEVM.prank(address(tsBorrower1));
  address yieldAccount = tsYieldEthStakingEtherfi.createYieldAccount(address(tsBorrower1));

  tsHEVM.prank(address(tsBorrower1));
  tsYieldEthStakingEtherfi.stake(tsCommonPoolId, address(tsBAYC), tokenIds[0], stakeAmount);

  tsHEVM.prank(address(tsBorrower1));
  tsYieldEthStakingEtherfi.stake(tsCommonPoolId, address(tsBAYC), tokenIds[1], stakeAmount);

  (testVars.poolId, testVars.state, testVars.debtAmount, testVars.yieldAmount) = tsYieldEthStakingEtherfi
    .getNftStakeData(address(tsBAYC), tokenIds[0]);

  assertEq(testVars.yieldAmount, 23433454429562988687);

  (testVars.poolId, testVars.state, testVars.debtAmount, testVars.yieldAmount) = tsYieldEthStakingEtherfi
    .getNftStakeData(address(tsBAYC), tokenIds[1]);

  assertEq(testVars.yieldAmount, 21090108986606689816);
}

Tools Used

Vscode, Foundry

Recommended Mitigation Steps

On YieldStakingBase::deposit() the claimed amount should be the assets deposited (roughly equal to the borrowed amount minus rounding errors).

thorseldon (BendDAO) confirmed and commented:

Fixed here and here.


The original report as published on Code4rena, by 0x73696d616f. 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 returned share amount from the yield source deposit as if it were the asset amount, while later calculations use the actual ETH balance, leading to inconsistent yield tracking.

Impact

The yield amount for each staked NFT becomes incorrect, allowing some NFTs to withdraw excess yield while others may be closer to liquidation.

What the attacker needed

Multiple NFTs staked in the same yield account; Yield source shares increase in value over time

The fix

The issue was fixed by making the deposit function use the actual assets deposited (roughly equal to the borrowed amount minus rounding errors) instead of the returned shares.

How it was found

  1. Modify the mock Etherfi liquidity pool deposit function to return 90% of the deposited value as shares.
  2. Create a yield account and stake two NFTs with the same borrowed amount.
  3. Check the yield amount for each NFT; they differ despite identical borrowed amounts.

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 ETH into a staking service like Lido, you get back 'shares' that represent your portion of the pool. Over time, each share is worth more ETH, so a deposit of 1 ETH might give you slightly less than 1 share. The bug is that the contract treats the number of shares as if it were the amount of ETH deposited, which throws off the accounting for each NFT's yield.

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

View all

172 more disclosed reports, best first.

More from BendDAO Invitational

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.