_unlocked_shares
calculation exposes a division error, leading to accumulative estimation error of unlocked shares
The _unlocked_shares
function in the ScrvusdOracleV2
contract uses integer division to calculate unlocked shares out. This division has a truncation issue which could lead to accumulative mathmatical error if it's being conducted over an extended period.
The issue lies in the _unlocked_shares
function, which calculates unlocked shares using integer division. As in Vyper, truncation happens while integer division and this drives the result being rounded down over time.
In the code snippet below, it shows where and how it is affected to the calculation of _unlocked_shares
:
Over time, this truncation is being accumulated which takes the underestimated unlocked_shares
to the calculation of total supply and co. Consequent errors are to be taking place like having raw_price
in an undervalued price.
The truncation error leads to a wrong calculation of the oracle’s raw_price
. It will cause significant loss for liquidity providers as malicious actors can exploit the discrepancy to redeem scrvUSD
for more underlying assets than expected.
Add a correction factor before performing the division to account for truncation, so as to minimize the effect of truncation.
All values will be scaled to a combined of 36 decimals before division (be it price-related values or totalSupply). Considering the 18 decimals of all values, no realistic values were presented in any duplicates to proof a substantial impact on precision loss.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.