Skip to content
Business logic Audit finding Intermediate

It’s impossible to retrieve collected fines from the yield staking contract

When a staker repays after a forced unstake, the fine is added to the debt and pulled into the contract, but only the base debt is forwarded to the lending pool. The fine therefore accumulates in the staking contract with no function to withdraw it, so those funds are permanently stuck.

SpicyMeatball Follow with oakcobalt, 0x73696d616f and 1 other

Originally disclosed on Code4rena

Submitted by SpicyMeatball, also found by oakcobalt, 0x73696d616f, and bin2chen

https://github.com/code-423n4/2024-07-benddao/blob/main/src/yield/YieldStakingBase.sol#L329-L337 https://github.com/code-423n4/2024-07-benddao/blob/main/src/yield/YieldStakingBase.sol#L407 https://github.com/code-423n4/2024-07-benddao/blob/main/src/yield/YieldStakingBase.sol#L426

Impact

No means to retrieve collected fines from the staking contract.

Proof of Concept

If botAdmin forcefully unstakes a position, a staker will have to pay an additional fine when the stake is repayed:

  function _repay(uint32 poolId, address nft, uint256 tokenId) internal virtual {
    ---SNIP---

    vars.nftDebt = _getNftDebtInUnderlyingAsset(sd);
>>  vars.nftDebtWithFine = vars.nftDebt + sd.unstakeFine;

    // compute repay value
    if (vars.claimedYield >= vars.nftDebtWithFine) {
      vars.remainAmount = vars.claimedYield - vars.nftDebtWithFine;
    } else {
      vars.extraAmount = vars.nftDebtWithFine - vars.claimedYield;
    }

    // transfer eth from sender
    if (vars.extraAmount > 0) {
>>    underlyingAsset.safeTransferFrom(vars.nftOwner, address(this), vars.extraAmount);
    }

    if (vars.remainAmount > 0) {
      underlyingAsset.safeTransfer(vars.nftOwner, vars.remainAmount);
    }

    // repay lending pool
>>  poolYield.yieldRepayERC20(poolId, address(underlyingAsset), vars.nftDebt);

    poolYield.yieldSetERC721TokenData(poolId, nft, tokenId, false, address(underlyingAsset));

    // update shares
    accountYieldInWithdraws[address(vars.yieldAccout)] -= sd.withdrawAmount;
    totalDebtShare -= sd.debtShare;

    delete stakeDatas[nft][tokenId];

    emit Repay(msg.sender, nft, tokenId, vars.nftDebt);
  }

Note that the user’s total debt consists of the actual NFT debt and the fine. When the stake is paid off, only the nftDebt is sent to the pool, and the unstakeFine remains in the contract. However, there are no functions that send the collected funds to the admin, and so they will remain in the contract forever.

Recommended Mitigation Steps

Implement a function that allows admin to collect fines from the yield staking contract.

Assessed type

Token-Transfer

thorseldon (BendDAO) confirmed and commented:

Fixed here.


The original report as published on Code4rena, by SpicyMeatball. 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 repay logic transfers only the base debt to the pool and never routes the fine portion to any recipient or admin withdrawal function.

Impact

Collected fines become permanently locked in the staking contract, so the protocol cannot recover them.

What the attacker needed

A forced unstake by the admin; staker repays the stake

The fix

A function was added allowing the admin to collect fines from the yield staking contract, and the project confirmed it was fixed.

How it was found

  1. An admin forcefully unstakes a position, setting a fine on the stake.
  2. The staker repays, and the contract pulls in the debt plus the fine.
  3. Only the base debt is forwarded to the lending pool.
  4. The fine stays in the contract with no way to withdraw it.

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.

A staking contract lets people lock tokens and borrow against them. If an admin force-closes a position, the owner owes a small penalty on top of their debt. When they pay back, the whole amount including the penalty goes into the contract, but only the debt part is passed on, and nothing lets anyone take the penalty out, so it sits there forever.

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 SpicyMeatball

View all

18 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.