Skip to content
Business logic Audit finding Intermediate

Rewards per locked token are calculated incorrectly

The protocol calculates rewards per locked token at the time new allocations are received, before the funds are deposited into providers. This means rewards are based on allocations that have not yet earned anything, leading to incorrect reward distribution.

rvierdiiev Follow

Originally disclosed on Sherlock

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

Found by

rvierdiiev

Summary

Rewards per locked token are calculated incorrectly as they are calculated, when at the allocation time, but should be calculated at the end of rebalancing period.

Vulnerability Detail

The purpose of Game is to allow user to make allocations into different providers. Depending on the price of providers LP and staked amount of derby token, player receive rewards for the rebalancing period. So actually user should allocate amount, then rebalancing period is started and according to the allocations of players different providers are funded. Then at the end of rebalance period, rewards should be calculated that players were able to earn by their allocations.

The problem is that protocol currently implements this in different way. Rewards are calculated, once vault received new allocations. So actually this allocations even didn't have time to work in order to calculate earning.

So once allocations are received from the game and XController provided needed underlying, then Vault.rebalance is called. This function will also call rebalanceCheckProtocols, which then calls storePriceAndRewards function. This function is responsible for calculating rewards per locked token for provider.

And as you can see it is called too early, as allocations and underlying for them just arrived and they are not even deposited yet into providers. So you shouldn't calculate earnings for that allocations yet, you need to wait till end of rebalance period.

End of rebalance period is when MainVault.sendRewardsToGame is called. So i believe, rewards should be calculated exactly at this function.

Impact

Rewards per locked token are calculated incorrectly.

Code Snippet

Provided above

Tool used

Manual Review

Recommendation

Calculate rewards inside MainVault.sendRewardsToGame function.

The original report as published on Sherlock, by rvierdiiev. 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 reward calculation function is called during the rebalance process before the allocated funds are deposited and have time to generate earnings.

What the attacker needed

None

The fix

Rewards should be calculated inside the MainVault.sendRewardsToGame function, which is called at the end of the rebalancing period.

How it was found

  1. User submits allocations to the game.
  2. Vault receives allocations and underlying tokens from XController.
  3. Vault.rebalance is called, which triggers rebalanceCheckProtocols.
  4. rebalanceCheckProtocols calls storePriceAndRewards, calculating rewards prematurely.
  5. Rewards are calculated before allocations are deposited into providers and before the rebalancing period ends.

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, users allocate funds to different investment providers and earn rewards based on how well those allocations perform over a period. The bug is that the reward calculation happens too early, right when the allocations are submitted, instead of after the period ends when the actual earnings are known. So users might get rewards that don't match what their allocations actually earned.

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 rvierdiiev

View all

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