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

YieldStakingBase treats minted shares as assets when depositing into Etherfi/Lido, so multiple NFTs in one YieldAccount get mismatched yield balances, enabling excess withdrawal and premature liquidation.

- Payout: Audit contest
- Severity: high
- Program: BendDAO
- Found by: 0x73696d616f
- Disclosed: 2024-09-03
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-07-benddao-findings/issues/62
- Library page: https://bugbountylibrary.com/r/c4%3A2024-07-benddao%3AH-01
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:share-inflation

**Target:** YieldStakingBase and Etherfi/Lido yield integrations
**Root cause:** stake() records the returned minted shares as if they were deposited assets, while getAccountYieldBalance() computes yield from actual ETH balance, so per-NFT yield accounting diverges when shares are worth more than 1:1.
**Steps:**
1. Modify MockEtherfiLiquidityPool.deposit() to return `msg.value * 9 / 10` to simulate a 0.9 assets/shares ratio.
2. Create a YieldAccount and stake two BAYC NFTs with the same stakeAmount via `tsYieldEthStakingEtherfi.stake(...)`.
3. Read `getNftStakeData` for both tokenIds; observe yieldAmount differs (23433454429562988687 vs 21090108986606689816) despite equal debt.
**How found:** Code reading noticed stake() uses the shares returned by Etherfi/Lido deposit as assets, while getAccountYieldBalance() uses actual ETH balance; hypothesized divergence when shares appreciate above 1:1 and confirmed with a mock returning fewer shares.
**Exploitation:** An attacker stakes multiple NFTs in one YieldAccount; the first NFT's yield is inflated and can be withdrawn immediately, while later NFTs show instant losses and can be pushed toward liquidation.
**Insight:** When integrating yield-bearing share tokens, check whether accounting stores shares or assets and whether the same unit is used in all balance/valuation paths; a mock that returns shares != assets exposes mismatches.

## Proof of concept (copied exactly from the original report)

**Mock Etherfi deposit returning shares not assets**

```
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;
}
```

**Foundry test proving incorrect yield tracking**

```
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);
}
```

