unsafe_sub(raw_price + max_change, last_price)
in the _smoothed_price
function can revert if raw_price
is significantly lower than last_price
, causing an underflow.The _smoothed_price
function in the ScrvusdOracleV2.vy contract is designed to calculate a smoothed price based on the last price and the current raw price. Here is the relevant code:
The operation unsafe_sub(raw_price + max_change, last_price)
can cause an underflow if raw_price
is much lower than last_price
. This is because unsafe_sub
does not handle cases where the result of the subtraction is negative, leading to a transaction revert.
Denial of Service (DoS)**: If raw_price
is significantly lower than last_price
, the unsafe_sub
operation can cause an underflow and revert the transaction. This can be exploited to disrupt the normal functioning of the contract, causing a denial of service.
manual review
To mitigate this vulnerability, the logic should be reimplemented using safe operations. Here is a possible solution:
This implementation avoids the underflow by directly comparing raw_price
and last_price
and adjusting the smoothed price accordingly.
If underflow occurs, it must have meant that `raw_price` has deviated from `last_price` by more than `max_change`, meaning it is correct to restrict the `last_price` increment to `max_change`
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.