DeFiLayer 1Layer 2
14,723 OP
View results
Submission Details
Severity: high
Invalid

Incorrect Handling of No Price Change in update_price() in the ScrvusdOracleV2

Summary

The update_price function incorrectly returns 0 when the new_price is equal to the current_price. This behavior is misleading, as it implies that the price has dropped to zero, which is not the case. Instead, the function should return the current price or a value indicating no change.

Vulnerability Details

The function calculates the absolute relative price change as follows:

if new_price > current_price:
return (new_price - current_price) * 10**18 // current_price
else:
return (current_price - new_price) * 10**18 // current_price
  • If new_price > current_price, it returns the positive relative change.

  • If new_price < current_price, it returns the negative relative change.

  • If new_price == current_price, it returns 0.

  • The issue arises when new_price == current_price. Returning 0 in this case is misleading, as it does not accurately represent the situation (no price change).

Impact

  • Misleading Behavior: Returning 0 when there is no price change could lead to incorrect assumptions, such as the price dropping to zero.

  • User Confusion: Users or external systems relying on this function might misinterpret the result, leading to incorrect decisions or actions.

  • Inconsistent Behavior: The function does not handle the "no change" scenario in a meaningful way, reducing its reliability.

Tools Used

  • Manual code review

Recommendations

Modify the Function to Return the Current Price:

  • Update the function to return the current price when new_price == current_price:

if new_price > current_price:
return (new_price - current_price) * 10**18 // current_price
elif new_price < current_price:
return (current_price - new_price) * 10**18 // current_price
else:
return current_price # Return current price if no change
Updates

Lead Judging Commences

0xnevi Lead Judge
6 months ago
0xnevi Lead Judge 5 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.