Skip to content
Business logic Audit finding Intermediate

Players can call rebalanceBasket before rewards have been pushed to the game

The vault's rebalancing period is incremented at the start of the process, but the reward for that period is not pushed to the game until the end. An attacker can call rebalanceBasket during this window when currentReward is zero, causing incorrect reward calculations that can be exploited for profit or to cause losses to others.

evan Follow with nobody2018, oot2k and 1 other

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-01-derby-judging/issues/259

Found by

evan, nobody2018, oot2k, rvierdiiev

Summary

It's possible to manipulate game.sol to a state where players can call rebalanceBasket before rewards have been settled. In some cases, it's possible for a malicious user to profit. In other cases, it's possible for a malicious user to create a period where players lose a significant amount of rewards when they call rebalanceBasket.

Vulnerability Detail

https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/MainVault.sol#L343 Observe that vault's receiveProtocolAllocations can be called by the xProvider regardless what state the vault is in.

https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/XProvider.sol#L407 https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/Game.sol#L472 This means that game.sol's pushAllocationsToVaults can be called immediately after pushAllocationsToController.

https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/Game.sol#L476 PushAllocationsToVaults resets isXChainRebalancing.

https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/Game.sol#L324 So if someone call PushAllocationsToVaults for vaults on all the chains, players can rebalanceBasket again.

https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/Game.sol#L442 Vault's rebalancingPeriod on game.sol is incremented in pushAllocationsToController, which is at the very beginning of the rebalancing process.

https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/MainVault.sol#L362 The reward for this rebalancingPeriod is not pushed to the game until the very end of the rebalancing process.

https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/Game.sol#L390 The problem with calling rebalanceBasket before the reward for the current rebalancingPeriod is pushed, is that the value of the currentReward is 0 (hasn't been set yet) so the reward calculation is wrong. Depending on the actual value of currentReward, the user can make a profit or incur a loss.

Impact

Consider the following scenario. A vault is ready for rebalancing, so the malicious user calls pushAllocationsToController, and then calls pushAllocationsToVaults for vaults on all chains immediately after.

The period from now to when the rebalancing process finishes is a time frame where reward calculation is wrong (currentReward is 0) but rebalanceBasket can still be called. A unaware user can call rebalanceBasket and get a completely different reward than they are supposed to. More often than not, this is unfavorable since currentReward should usually be positive. The length of this period depends on how fast the rebalancing process, which can be delayed by a variety of factors, completes. As discussed in my other reports, there are various ways to interrupt the rebalancing process.

But regardless of how short this period is, the malicious user can predetermine the actual value of currentReward. If it's negative, then they immediately call rebalanceBasket and get a higher reward than they are supposed to.

Code Snippet

See Vulnerability Detail.

Tool used

Manual Review

Recommendation

Prevent rebalanceBasket from being called before rewards for the current period have been settled.

The original report as published on Sherlock, by evan. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 rebalancing period is incremented before the corresponding reward is settled, and rebalanceBasket is not restricted during that interval.

Impact

A malicious user could profit by calling rebalanceBasket when currentReward is negative, or cause other players to lose rewards by creating a period where reward calculation is wrong.

What the attacker needed

Vault is ready for rebalancing; attacker can call pushAllocationsToController; attacker can call pushAllocationsToVaults on all chains

The fix

Prevent rebalanceBasket from being called before rewards for the current period have been settled.

How it was found

  1. Call pushAllocationsToController to start the rebalancing process.
  2. Immediately call pushAllocationsToVaults for vaults on all chains to reset isXChainRebalancing.
  3. Call rebalanceBasket while currentReward is still zero, causing incorrect reward calculation.

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 this system, players can rebalance their basket of investments, and they earn rewards based on the vault's performance. The reward for a period is only recorded at the end of the rebalancing process, but players are allowed to rebalance as soon as the process starts. This means they can act while the reward is still zero, leading to incorrect payouts that a malicious user can exploit.

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 evan

View all

11 more disclosed reports, best first.

More from Derby

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.