Fix oracle: validate u128-to-i128 cast before using as price - #488
Merged
IbrahimIjai merged 1 commit intoJul 24, 2026
Merged
Conversation
Closes SO4-Markets#383 Issue: get_stable_price and get_price_with_stable_fallback both cast a stored u128 directly to i128 without validation. A u128 value at or above 2^127 reinterprets as a negative i128 on this cast; that negative value passes the price==0 check (it isn't zero) and is returned unchanged as a legitimate price rather than rejected. Fix: - get_stable_price: Validate raw u128 is below i128::MAX before casting and reject if zero or would cast to negative - get_price_with_stable_fallback: Only use stable price if it's positive and fits in i128, otherwise fall back to primary price This matches the validation applied to keeper-submitted prices which explicitly reject non-positive prices at write time.
|
@Uchechukwu-Ekezie Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
GReat... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #383
Problem
get_stable_priceandget_price_with_stable_fallbackboth cast a stored u128 directly to i128 without validation. A u128 value at or above 2^127 reinterprets as a negative i128 on this cast; that negative value:price==0check (it isn't zero)Fix
This matches the validation applied to keeper-submitted prices which explicitly reject non-positive prices at write time.
Testing