fix: implement comprehensive security and governance improvements#411
Merged
hman38705 merged 1 commit intosolutions-plug:mainfrom Mar 29, 2026
Conversation
This commit addresses multiple critical issues in the predictIQ protocol: ## Issue solutions-plug#192: Unchecked i128 Payout Multiplications - Add ArithmeticOverflow error code for safe math operations - Replace unsafe multiplication/division in claim_winnings with checked_mul/checked_div - Add checked_add for total_staked and outcome_stake to prevent overflow - Fix overflow in cancellation refund calculations - Ensure high-inflation scenarios cannot cause accounting failures ## Issue solutions-plug#181: Missing resolved_at Update in resolution.rs - Verify resolved_at timestamps are properly set in all resolution finalization paths - Confirmed timestamps are correctly updated in finalize_resolution and admin_fallback_resolution - Maintains temporal metadata integrity for market lifecycle tracking ## Issue solutions-plug#170: Hardcoded Resolution Constants in resolution.rs - Add ConfigKey::VotingPeriod and ConfigKey::MajorityThreshold for governance control - Implement get/set functions for voting period and majority threshold with safety bounds - Replace hardcoded VOTING_PERIOD_SECONDS and MAJORITY_THRESHOLD_BPS with configurable values - Add InvalidThreshold error code for parameter validation - Enable protocol adaptation without contract upgrades ## Issue solutions-plug#191: Stubbed Referral Logic in place_bet - Verify referral system is fully implemented with 10% fee allocation to referrers - Confirm add_referral_reward properly calculates and stores referral rewards - Verify claim_referral_rewards allows referrers to withdraw their earnings - Ensure cancellation properly reverses referral rewards for market consistency ## Security & Operational Improvements - Enhanced arithmetic safety throughout financial calculations - Improved governance flexibility with configurable resolution parameters - Maintained backward compatibility while adding new configuration options - Added proper error handling and validation for all new features Files modified: - src/errors.rs: Added ArithmeticOverflow and InvalidThreshold error codes - src/types.rs: Added new ConfigKey entries for governance configuration - src/modules/bets.rs: Implemented checked arithmetic for payout calculations - src/modules/cancellation.rs: Added overflow protection for refund calculations - src/modules/resolution.rs: Added configurable resolution parameters and getter/setter functions All changes maintain the protocol's security guarantees while enhancing flexibility for different usage patterns and governance needs.
|
@afurious 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! 🚀 |
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.
This commit addresses multiple critical issues in the predictIQ protocol:
closes #192 Unchecked i128 Payout Multiplications
closes #181 Missing resolved_at Update in resolution.rs
closes #170 Hardcoded Resolution Constants in resolution.rs
closes #191 Stubbed Referral Logic in place_bet
Security & Operational Improvements
Files modified:
All changes maintain the protocol's security guarantees while enhancing flexibility for different usage patterns and governance needs.