Skip to content

feat: Implement Overflow-Safe Price Confidence Calculation#298

Merged
hman38705 merged 2 commits intosolutions-plug:mainfrom
Macnelson9:overflow
Mar 26, 2026
Merged

feat: Implement Overflow-Safe Price Confidence Calculation#298
hman38705 merged 2 commits intosolutions-plug:mainfrom
Macnelson9:overflow

Conversation

@Macnelson9
Copy link
Copy Markdown
Contributor

📋 Description

Implements overflow-safe absolute value handling for oracle price confidence checks to prevent panics on extreme signed inputs (notably i64::MIN). This hardens the Pyth validation path to follow zero-panic handling for hostile or malformed external data.

🎯 Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring
  • Test addition/update
  • CI/CD update

🔗 Related Issues

Closes #149

📝 Changes Made

  • Replaced unsafe manual absolute value conversion in oracle validation with a saturating conversion helper in oracles.rs.
  • Hardened confidence arithmetic using saturating multiplication and shared BPS denominator in oracles.rs.
  • Added regression unit tests for i64::MIN and normal signed values in oracles.rs.

🧪 Testing

Test Coverage

  • Unit tests added/updated
  • Integration tests added/updated
  • All tests passing locally
  • Test coverage maintained/improved

Manual Testing

  • Tested on testnet
  • Tested locally
  • Edge cases tested

Test Results:
Added module tests:

  • abs_price_handles_i64_min_without_panic
  • abs_price_preserves_normal_values

File diagnostics for the edited oracle module show no errors.

📸 Screenshots (if applicable)

Not applicable (no UI changes).

✅ Checklist

Code Quality

  • Code follows project style guidelines
  • Self-review completed
  • Comments added for complex code
  • No unnecessary console.log or debug code
  • No commented-out code

Documentation

  • Documentation updated (if needed)
  • API documentation updated (if applicable)
  • CHANGELOG.md updated
  • README updated (if needed)

Testing & Quality

  • All tests pass (cargo test)
  • No linting errors (cargo clippy)
  • Code formatted (cargo fmt)
  • No new warnings introduced
  • Gas benchmarks run (if applicable)

Security

  • Security implications considered
  • No sensitive data exposed
  • Input validation added
  • Authorization checks in place

Git

  • Branch is up to date with main
  • Commits are atomic and well-described
  • Commit messages follow convention
  • No merge conflicts

🔍 Reviewer Notes

Please focus review on:

  • Safety of abs_price_to_u64 behavior for i64::MIN.
  • Correctness of confidence threshold arithmetic after saturating math update.
  • Confirmation that no behavior changed for normal positive/negative price inputs.

📊 Performance Impact

  • No performance impact
  • Performance improved
  • Performance impact acceptable (explain below)

Details:
Changes are constant-time arithmetic substitutions with no additional I/O or storage access.

🚀 Deployment Notes

No migration required.
No configuration changes required.
Safe non-breaking contract logic hardening.

📚 Additional Context

Primary file changed:

  • oracles.rs

Suggested commit message:
fix: implement overflow-safe absolute value for Pyth price confidence


By submitting this PR, I confirm that:

  • I have read and followed the CONTRIBUTING.md guidelines
  • My code follows the project's coding standards
  • I have tested my changes thoroughly
  • I am ready for code review

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 26, 2026

@Macnelson9 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! 🚀

Learn more about application limits

@hman38705 hman38705 merged commit cf2dad1 into solutions-plug:main Mar 26, 2026
1 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Overflow-Safe Price Confidence Calculation

2 participants