A potential underflow exists in the _smoothed_price
function due to the usage of unsafe_sub()
. If raw_price + max_change
is less than last_price
, the subtraction operation underflows, leading to incorrect behavior or unexpected results. This could impact price smoothing calculations and introduce security vulnerabilities.
The issue can be found here: https://github.com/CodeHawks-Contests/2025-03-curve/blob/main/contracts/scrvusd/oracles/ScrvusdOracleV2.vy#L155-L164
unsafe_sub(a, b)
does not perform underflow checks.
If raw_price + max_change < last_price
, the subtraction operation underflows.
Vyper’s unsafe_sub()
removes the built-in safety checks, causing unintended behavior.
Assumptions:
raw_price = 0.90 * 10**18
last_price = 1.00 * 10**18
max_change = 0.05 * 10**18
Execution:
unsafe_sub(0.90 * 1018 + 0.05 * 1018, 1.00 * 10**18)
= unsafe_sub(0.95 * 1018, 1.00 * 1018)
Since 0.95 * 1018 < 1.00 * 1018, this results in an underflow, causing an incorrect result or unexpected behavior.
The function may return incorrect smoothed price values, affecting downstream logic.
Manual Review
Use Vyper’s built-in safe arithmetic:
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.