Skip to content

fix: implement comprehensive security and governance improvements#411

Merged
hman38705 merged 1 commit intosolutions-plug:mainfrom
afurious:fix/issue-192-181-170-191-safe-math-resolution-config-referral
Mar 29, 2026
Merged

fix: implement comprehensive security and governance improvements#411
hman38705 merged 1 commit intosolutions-plug:mainfrom
afurious:fix/issue-192-181-170-191-safe-math-resolution-config-referral

Conversation

@afurious
Copy link
Copy Markdown
Contributor

This commit addresses multiple critical issues in the predictIQ protocol:

closes #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

closes #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

closes #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

closes #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.

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.
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 28, 2026

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

Learn more about application limits

@hman38705 hman38705 merged commit e18f67f into solutions-plug:main Mar 29, 2026
2 of 13 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

2 participants