Skip to content
Business logic Audit finding Intermediate

User should not receive rewards for the rebalance period, when protocol was blacklisted, because of unpredicted behaviour of protocol price

The reward calculation for a protocol continues even after it is blacklisted, using an unpredictable exchange rate. This can cause users to receive extremely large positive or negative rewards.

Bauer Follow with Ch_301, evan and 2 others

Originally disclosed on Sherlock

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

Found by

Bauer, Ch_301, evan, immeas, rvierdiiev

Summary

User should not receive rewards for the rebalance period, when protocol was blacklisted, because of unpredicted behaviour of protocol price.

Vulnerability Detail

When user allocates derby tokens to some underlying protocol, he receive rewards according to the exchange price of that protocols token. This reward can be positive or negative. Rewards of protocol are set to Game contract inside settleRewards function and they are accumulated for user, once he calls rebalanceBasket.

Let's check how they are calculated. https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/Vault.sol#L226-L245

Solidity
  function storePriceAndRewards(uint256 _totalUnderlying, uint256 _protocolId) internal {
    uint256 currentPrice = price(_protocolId);
    if (lastPrices[_protocolId] == 0) {
      lastPrices[_protocolId] = currentPrice;
      return;
    }


    int256 priceDiff = int256(currentPrice - lastPrices[_protocolId]);
    int256 nominator = (int256(_totalUnderlying * performanceFee) * priceDiff);
    int256 totalAllocatedTokensRounded = totalAllocatedTokens / 1E18;
    int256 denominator = totalAllocatedTokensRounded * int256(lastPrices[_protocolId]) * 100; // * 100 cause perfFee is in percentages


    if (totalAllocatedTokensRounded == 0) {
      rewardPerLockedToken[rebalancingPeriod][_protocolId] = 0;
    } else {
      rewardPerLockedToken[rebalancingPeriod][_protocolId] = nominator / denominator;
    }


    lastPrices[_protocolId] = currentPrice;
  }

Every time, previous price of protocol is compared with current price.

In case if some protocol is hacked, there is Vault.blacklistProtocol function, that should withdraw reserves from protocol and mark it as blacklisted. The problem is that because of the hack it's not possible to determine what will happen with exhange rate of protocol. It can be 0, ot it can be very small or it can be high for any reasons. But protocol still accrues rewards per token for protocol, even that it is blacklisted. Because of that, user that allocated to that protocol can face with accruing very big negative or positive rewards. Both this cases are bad.

So i believe that in case if protocol is blacklisted, it's better to set rewards as 0 for it.

Example. 1.User allocated 100 derby tokens for protocol A 2.Before Vault.rebalance call, protocol A was hacked which made it exchangeRate to be not real. 3.Derby team has blacklisted that protocol A. 4.Vault.rebalance is called which used new(incorrect) exchangeRate of protocol A in order to calculate rewardPerLockedToken 5.When user calls rebalance basket next time, his rewards are accumulated with extremely high/low value.

Impact

User's rewards calculation is unpredictable.

Code Snippet

Provided above

Tool used

Manual Review

Recommendation

In case if protocol is blacklisted, then set rewardPerLockedToken to 0 inside storePriceAndRewards function.

The original report as published on Sherlock, by Bauer. 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

Impact

User's rewards calculation becomes unpredictable, potentially leading to very large positive or negative rewards.

What the attacker needed

Protocol is blacklisted; user has allocated tokens to that protocol

The fix

The reward per locked token should be set to zero for blacklisted protocols inside the storePriceAndRewards function.

How it was found

  1. User allocates 100 derby tokens to protocol A.
  2. Protocol A is hacked, making its exchange rate unrealistic.
  3. The Derby team blacklists protocol A.
  4. Vault.rebalance is called, using the incorrect exchange rate to calculate rewardPerLockedToken.
  5. When the user next calls rebalanceBasket, their rewards are accumulated with an extremely high or low value.

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 put tokens into a protocol, you earn rewards based on how its price changes. If that protocol is hacked and then blacklisted, its price becomes unpredictable, but the system still calculates rewards from it. This can give users huge rewards or huge losses.

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 Bauer

View all

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