The ScrvusdOracleV2.vy
oracle uses a linear time-based approximation for price smoothing that allows exploitation through timing of transactions. An attacker can delay interactions with the oracle to force larger price movements than intended, potentially allowing value extraction from stableswap pools using this oracle.
The oracle's _smoothed_price
function uses a linear approximation based on the time elapsed since the last update to calculate the maximum allowed price change:
The above code assumes that price changes should scale linearly with time, but lacks a cap on the maximum time delta used in calculations. This results in no minimum update frequency being enforced.
This vulnerability can lead to significant fund loss in stableswap pools that rely on this oracle for pricing. An attacker can:
Wait for a period where the oracle hasn't been updated
Observe the actual price change of scrvUSD during this period
If the price has moved beyond what would typically be allowed, exploit the oracle's permissive bounds after the delay
Execute trades against the stableswap pool at manipulated prices
Extract value from the price discrepancy
Add the following test function to ScrvusdOracleV2.vy
:
Deploy the modified contract and make these calls:
With max_price_increment = 2 * 10**12
:
1-day calculation: 2 * 10**12 * 86400 * 1e18 / 1e18 = 172,800,000,000,000 (0.0173%)
7-day calculation: 2 * 10**12 * 604800 * 1e18 / 1e18 = 1,209,600,000,000,000 (0.121%)
With a 7-day gap, the price can move significantly more than would be allowed with frequent updates. This would allow for an attacker to time their interactions to maximize price slippage.
Manual Testing
One major fix would be to add a maximum time delta to limit the effect of long periods without updates:
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.