sherlock-audit / 2023-01-derby-judging

4 stars 1 forks source link

XKET - Underflow during LP price diff calculation #380

Closed sherlock-admin closed 1 year ago

sherlock-admin commented 1 year ago

XKET

high

Underflow during LP price diff calculation

Summary

priceDiff is wrongly implemented so Vault.storePriceAndRewards will revert when the LP price goes down.

Vulnerability Detail

In Vault.storePriceAndRewards, priceDiff is used when we calculate rewardPerLockedToken.

The implementation is as follows:

    int256 priceDiff = int256(currentPrice - lastPrices[_protocolId]);

The subtraction is called before conversion to int256. So it will revert when currentPrice < lastPrice.

Impact

It will block storePriceAndRewards is called during rebalance, and rebalance is a very important functionality, so it has a high impact.

Code Snippet

https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/Vault.sol#L233

Tool used

Manual Review

Recommendation

Use Conversion before subtraction.

    int256 priceDiff = int256(currentPrice) - int256(lastPrices[_protocolId]);

Duplicate of #408