Skip to content
Business logic Audit finding Intermediate

Wrong reward token calculation in MasterChef contract

The MasterChef contract's add function fails to update existing staking pools when a new pool is added, causing users in older pools to receive fewer rewards than they should. An attacker could exploit this to cause incorrect reward distribution, but the report does not describe a direct theft or gain.

throttle Follow

Originally disclosed on Code4rena

Submitted by throttle, also found by cccz, cmichel, and leastwood

MasterChef.sol#L86

When adding new token pool for staking in MasterChef contract

function add(address _token, uint _allocationPoints, uint16 _depositFee, uint _startBlock)

All other, already added, pools should be updated but currently they are not. Instead, only totalPoints is updated. Therefore, old (and not updated) pools will lose it’s share during the next update. Therefore, user rewards are not computed correctly (will be always smaller).

Proof of Concept

Scenario 1:

  1. Owner adds new pool (first pool) for staking with points = 100 (totalPoints=100) and 1 block later Alice stakes 10 tokens in the first pool.
  2. 1 week passes
  3. Alice withdraws her 10 tokens and claims X amount of reward tokens. and 1 block later Bob stakes 10 tokens in the first pool.
  4. 1 week passes
  5. Owner adds new pool (second pool) for staking with points = 100 (totalPoints=200) and 1 block later Bob withdraws his 10 tokens and claims X/2 amount of reward tokens. But he should get X amount

Scenario 2:

  1. Owner adds new pool (first pool) for staking with points = 100 (totalPoints=100).
  2. 1 block later Alice, Bob and Charlie stake 10 tokens there (at the same time).
  3. 1 week passes
  4. Owner adds new pool (second pool) for staking with points = 400 (totalPoints=500)
  5. Right after that, when Alice, Bob or Charlie wants to withdraw tokens and claim rewards they will only be able to claim 20% of what they should be eligible for, because their pool is updated with 20% (100/500) rewards instead of 100% (100/100) rewards for the past week.

Recommended Mitigation Steps

Update all existing pools before adding new pool. Use the massUdpate() function which is already present … but unused.

ryuheimat (Concur) confirmed

Alex the Entreprenerd (judge) commented:

The warden has identified a fallacy in how adds logic work.

Ultimately rewards in this contract have to be linearly vested over time, adding a new pool would change the rate at which vesting in all pools will go.

For that reason, it is necessary to accrue the rewards that each pool generated up to that point, before changing the slope at which rewards will be distributed.

In this case add should massUpdateFirst.

Because this vulnerability ultimately breaks the accounting of the protocol, I believe High Severity to be appropriate.


The original report as published on Code4rena, by throttle. 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 add function updates totalPoints but does not call massUpdate on existing pools before changing the total, so their reward accounting becomes stale.

Impact

Users in existing pools receive fewer rewards than they should, breaking the protocol's accounting; the judge rated this High severity.

What the attacker needed

Owner adds a new pool; Users have staked in existing pools

The fix

The add function should call massUpdate on all existing pools before adding a new pool.

How it was found

  1. Owner adds first pool with 100 points.
  2. Alice stakes 10 tokens in the first pool.
  3. After a week, Alice withdraws and claims X rewards.
  4. Bob stakes 10 tokens in the first pool.
  5. After a week, owner adds second pool with 100 points, making totalPoints 200.
  6. Bob withdraws and claims X/2 rewards instead of X.

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.

In a staking contract, users earn rewards based on their share of the total points. When a new pool is added, the total points increase, but the old pools' reward calculations are not updated to reflect the change. This means users in old pools get a smaller share of rewards than they deserve.

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 throttle

View all

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