Skip to content
Access control Audit finding Intermediate

FlywheelCore.setBooster() can be used to steal unclaimed rewards

The setBooster function allows an authorised user to replace the booster contract with a malicious one that returns inflated balances for the attacker, enabling them to claim more rewards than earned and steal unclaimed rewards from other users.

IllIllI Follow

Originally disclosed on Code4rena

Submitted by IllIllI

A malicious authorized user can steal all unclaimed rewards and break the reward accounting

Even if the authorized user is benevolent the fact that there is a rug vector available may negatively impact the protocol’s reputation. Furthermore since this contract is meant to be used by other projects, the trustworthiness of every project cannot be vouched for.

Proof of Concept

By setting a booster that returns zero for all calls to boostedBalanceOf() where the user address is not under the attacker’s control, and returning arbitrary values for those under his/her control, an attacker can choose specific amounts of rewardToken to assign to himself/herself. The attacker can then call claimRewards() to withdraw the funds. Any amounts that the attacker assigns to himself/herself over the amount that normally would have been assigned, upon claiming, is taken from other users’ unclaimed balances, since tokens are custodied by the flywheelRewards address rather than per-user accounts.

File: flywheel-v2/src/FlywheelCore.sol

182       /// @notice swap out the flywheel booster contract
183       function setBooster(IFlywheelBooster newBooster) external requiresAuth {
184           flywheelBooster = newBooster;
185
186           emit FlywheelBoosterUpdate(address(newBooster));
187       }

FlywheelCore.sol#L182-L187

File: flywheel-v2/src/FlywheelCore.sol

258           uint256 supplierTokens = address(flywheelBooster) != address(0)
259               ? flywheelBooster.boostedBalanceOf(strategy, user)
260               : strategy.balanceOf(user);
261
262           // accumulate rewards by multiplying user tokens by rewardsPerToken index and adding on unclaimed
263           uint256 supplierDelta = (supplierTokens * deltaIndex) / ONE;
264           uint256 supplierAccrued = rewardsAccrued[user] + supplierDelta;
265
266           rewardsAccrued[user] = supplierAccrued;

FlywheelCore.sol#L258-L266

File: flywheel-v2/src/FlywheelCore.sol

119       function claimRewards(address user) external {
120           uint256 accrued = rewardsAccrued[user];
121
122           if (accrued != 0) {
123               rewardsAccrued[user] = 0;
124
125               rewardToken.safeTransferFrom(address(flywheelRewards), user, accrued);

FlywheelCore.sol#L119-L125

Projects also using BaseFlywheelRewards or its child contrats, are implicitly approving infinite transfers by the core

File: flywheel-v2/src/rewards/BaseFlywheelRewards.sol

25        constructor(FlywheelCore _flywheel) {
26            flywheel = _flywheel;
27            ERC20 _rewardToken = _flywheel.rewardToken();
28            rewardToken = _rewardToken;
29
30            _rewardToken.safeApprove(address(_flywheel), type(uint256).max);
31        }

BaseFlywheelRewards.sol#L25-L31

The attacker need not keep the booster set this way - he/she can set it, call accrue() for his/her specific user, and unset it, all in the same block.

Recommended Mitigation Steps

Make flywheelRewards immutable, or only allow it to change if there are no current users.

Joeysantoro (xTRIBE) commented:

This is a similar issue to one which already affects the SushiSwap masterchef. If rewards are decreased without first calling the accrue-equivalent on the masterchef, then previous rewards are lost.

If trust minimization is a desired property (in my opinion it is), then these functions should be behind timelocks.

If a user can call accrue before the booster is updated, they can lock in past rewards as they are added onto the rewardsAccrued global state var 266 rewardsAccrued[user] = supplierAccrued;

I don’t really see this as a vulnerability, but will leave it to the C4 judge.

0xean (judge) commented:

I do see this as a vulnerability. Essentially, there is a backdoor by which a privileged address can extract value from users. A timelock would be a potential solution to mitigate some of the risk, as well as the mitigation options presented by the warden.

2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.

This is a hypothetical attack path with external requirements and deserves the medium severity rating.


The original report as published on Code4rena, by IllIllI. 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 setBooster function lacks restrictions (such as a timelock or immutability) and allows an authorised user to replace the booster with a malicious contract that manipulates reward calculations.

What the attacker needed

Attacker is an authorised user; attacker can deploy a malicious booster contract

The fix

The flywheelRewards should be made immutable, or only allowed to change if there are no current users.

How it was found

  1. Deploy a malicious booster contract that returns zero for boostedBalanceOf for users not under attacker control and arbitrary values for the attacker.
  2. Call setBooster to set the malicious booster.
  3. Call accrue for the attacker's user to update rewardsAccrued with inflated values.
  4. Call claimRewards to withdraw the inflated rewards, taking from other users' unclaimed balances.

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 trusted admin can swap out a helper contract that calculates how many reward tokens each user has earned. By making that helper lie about the attacker's balance, the attacker can claim more rewards than they deserve, taking tokens that belong to other users.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by IllIllI

View all

119 more disclosed reports, best first.

More from xTRIBE contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.