Skip to content
Business logic Audit finding Intermediate

Masterchef: Improper handling of deposit fee

The MasterChef contract subtracts a deposit fee from the user's credited amount but does not credit the fee to any recipient, causing the fee tokens to be permanently locked in the depositor contracts. An attacker could not directly exploit this, but users lose funds when depositing into pools with a non-zero deposit fee.

hickuphh3 Follow

Originally disclosed on Code4rena

Submitted by hickuphh3, also found by leastwood

MasterChef.sol#L170-L172

If a pool’s deposit fee is non-zero, it is subtracted from the amount to be credited to the user.

if (pool.depositFeeBP > 0) {
  uint depositFee = _amount.mul(pool.depositFeeBP).div(_perMille);
  user.amount = SafeCast.toUint128(user.amount + _amount - depositFee);
}

However, the deposit fee is not credited to anyone, leading to permanent lockups of deposit fees in the relevant depositor contracts (StakingRewards and ConvexStakingWrapper for now).

Proof of Concept

Example 1: ConvexStakingWrapper

Assume the following

  • The curve cDai / cUSDC / cUSDT LP token corresponds to pid = 1 in the convex booster contract.
  • Pool is added in Masterchef with depositFeeBP = 100 (10%).
  • Alice deposits 1000 LP tokens via the ConvexStakingWrapper contract. A deposit fee of 100 LP tokens is charged. Note that the deposits mapping of the ConvexStakingWrapper contract credits 1000 LP tokens to her.
  • However, Alice will only be able to withdraw 900 LP tokens. The 100 LP tokens is not credited to any party, and is therefore locked up permanently (essentially becomes protocol-owned liquidity). While she is able to do requestWithdraw() for 1000 LP tokens, attempts to execute withdraw() with amount = 1000 will revert because she is only credited 900 LP tokens in the Masterchef contract.

Example 2: StakingRewards

  • CRV pool is added in Masterchef with depositFeeBP = 100 (10%).
  • Alice deposits 1000 CRV into the StakingRewards contract. A deposit fee of 100 CRV is charged.
  • Alice is only able to withdraw 900 CRV tokens, while the 100 CRV is not credited to any party, and is therefore locked up permanently.

These examples are non-exhaustive as more depositors can be added / removed from the Masterchef contract.

Recommended Mitigation Steps

I recommend shifting the deposit fee logic out of the masterchef contract into the depositor contracts themselves, as additional logic would have to be added in the masterchef to update the fee recipient’s state (rewardDebt, send pending concur rewards, update amount), which further complicates matters. As the fee recipient is likely to be the treasury, it is also not desirable for it to accrue concur rewards.

if (pool.depositFeeBP > 0) {
  uint depositFee = _amount.mul(pool.depositFeeBP).div(_perMille);
  user.amount = SafeCast.toUint128(user.amount + _amount - depositFee);
  UserInfo storage feeRecipient = userInfo[_pid][feeRecipient];
  // TODO: update and send feeRecipient pending concur rewards
  feeRecipient.amount = SafeCast.toUint128(feeRecipient.amount + depositFee);
  // TODO: update fee recipient's rewardDebt
}

ryuheimat (Concur) confirmed

Alex the Entreprenerd (judge) commented:

The warden has identified a way for funds to be forever lost, because of that reason I believe High Severity to be appropriate.

Mitigation could be as simple as transferring the fee to a feeReceiver or adding a way to pull those fees.


The original report as published on Code4rena, by hickuphh3. 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 fee is subtracted from the user's amount but never added to any fee recipient's balance, so the tokens remain in the contract without an owner.

Impact

Users lose the deposit fee amount, which becomes permanently locked in the contract, reducing their withdrawable balance.

What the attacker needed

A pool with non-zero deposit fee; user deposits via a depositor contract

The fix

The deposit fee logic should be moved to the depositor contracts or the fee should be transferred to a fee recipient.

How it was found

  1. A pool is added to MasterChef with a non-zero deposit fee.
  2. Alice deposits tokens via a depositor contract (e.g., ConvexStakingWrapper or StakingRewards).
  3. The deposit fee is subtracted from Alice's credited amount in MasterChef.
  4. The fee tokens are not credited to any party and become permanently locked.

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 tokens into a pool, a fee is taken. The contract reduces your balance by the fee but does not give that fee to anyone else, so the tokens become stuck forever. This means you lose money even though the fee was supposed to go to the protocol.

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 hickuphh3

View all

43 more disclosed reports, best first.

More from Concur Finance contest

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.