Skip to content

fix(rate-limiter): enforce bet and oracle limits and use ledger units… - #1476

Merged
greatest0fallt1me merged 2 commits into
Predictify-org:masterfrom
Kiosh-123:fix/rate-limit-enforcement
Oct 24, 2026
Merged

greatest0fallt1me merged 2 commits into
Predictify-org:masterfrom
Kiosh-123:fix/rate-limit-enforcement

Conversation

@Kiosh-123

Copy link
Copy Markdown
Contributor

Closes #1464
… for bucket TTL

Wires the dead rate-limit paths so bet_limit, oracle_call_limit, and the per-ledger bet cap are actually enforced. Fixes a critical bug where TTL extended in seconds instead of ledger counts, causing rent inflation.

Changes:

  • Enforce bet_limit in place_bet_inner, place_bets, and vote
  • Enforce oracle_call_limit in fetch_oracle_result before external calls
  • Expose set_per_ledger_bet_cap entrypoint with require_primary_admin
  • Fix TTL: convert seconds to ledgers using LEDGER_SECONDS constant
  • Fix voting limit: change key from (user, market) to (user) globally
  • Fix get_rate_limit_status to return accurate reset time in HalfLife mode

Test coverage: 12 scenarios covering limits, batch atomicity, TTL, error precedence

Closes #1464

Pull Request Description

📋 Basic Information

Type of Change

Please select the type of change this PR introduces:

  • 🐛 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
  • 🧪 Test addition/update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🔒 Security fix
  • 🎨 UI/UX improvement
  • 🚀 Deployment/Infrastructure change

Related Issues

Closes #(issue number)
Fixes #(issue number)
Related to #(issue number)

Priority Level

  • 🔴 Critical (blocking other development)
  • 🟡 High (significant impact)
  • 🟢 Medium (moderate impact)
  • 🔵 Low (minor improvement)

📝 Detailed Description

What does this PR do?

Why is this change needed?

How was this tested?

Alternative Solutions Considered


🏗️ Smart Contract Specific

Contract Changes

Please check all that apply:

  • Core contract logic modified
  • Oracle integration changes (Pyth/Reflector)
  • New functions added
  • Existing functions modified
  • Storage structure changes
  • Events added/modified
  • Error handling improved
  • Gas optimization
  • Access control changes
  • Admin functions modified
  • Fee structure changes

Oracle Integration

  • Pyth oracle integration affected
  • Reflector oracle integration affected
  • Oracle configuration changes
  • Price feed handling modified
  • Oracle fallback mechanisms
  • Price validation logic

Market Resolution Logic

  • Hybrid resolution algorithm changed
  • Dispute mechanism modified
  • Fee structure updated
  • Voting mechanism changes
  • Community weight calculation
  • Oracle weight calculation

Security Considerations

  • Access control reviewed
  • Reentrancy protection
  • Input validation
  • Overflow/underflow protection
  • Oracle manipulation protection

🧪 Testing

Test Coverage

  • Unit tests added/updated
  • Integration tests added/updated
  • All tests passing locally
  • Manual testing completed
  • Oracle integration tested
  • Edge cases covered
  • Error conditions tested
  • Gas usage optimized
  • Cross-contract interactions tested

Test Results

# Paste test output here
cargo test
# Expected output: X tests passed, Y tests failed

Manual Testing Steps


📚 Documentation

Documentation Updates

  • README updated
  • Code comments added/updated
  • API documentation updated
  • Examples updated
  • Deployment instructions updated
  • Contributing guidelines updated
  • Architecture documentation updated

Breaking Changes

Breaking Changes:

Migration Guide:


🔍 Code Quality

Code Review Checklist

  • Code follows Rust/Soroban best practices
  • Self-review completed
  • No unnecessary code duplication
  • Error handling is appropriate
  • Logging/monitoring added where needed
  • Security considerations addressed
  • Performance implications considered
  • Code is readable and well-commented
  • Variable names are descriptive
  • Functions are focused and small

Performance Impact

  • Gas Usage:
  • Storage Impact:
  • Computational Complexity:

Security Review

  • No obvious security vulnerabilities
  • Access controls properly implemented
  • Input validation in place
  • Oracle data properly validated
  • No sensitive data exposed

🚀 Deployment & Integration

Deployment Notes

  • Network: Testnet/Mainnet
  • Contract Address:
  • Migration Required: Yes/No
  • Special Instructions:

Integration Points

  • Frontend integration considered
  • API changes documented
  • Backward compatibility maintained
  • Third-party integrations updated

📊 Impact Assessment

User Impact

  • End Users:
  • Developers:
  • Admins:

Business Impact

  • Revenue:
  • User Experience:
  • Technical Debt:

✅ Final Checklist

Pre-Submission

  • Code follows Rust/Soroban best practices
  • All CI checks passing
  • No breaking changes (or breaking changes are documented)
  • Ready for review
  • PR description is complete and accurate
  • All required sections filled out
  • Test results included
  • Documentation updated

Review Readiness

  • Self-review completed
  • Code is clean and well-formatted
  • Commit messages are clear and descriptive
  • Branch is up to date with main
  • No merge conflicts

📸 Screenshots (if applicable)

🔗 Additional Resources

  • Design Document:
  • Technical Spec:
  • Related Discussion:
  • External Documentation:

💬 Notes for Reviewers

Please pay special attention to:

Questions for reviewers:


Thank you for your contribution to Predictify! 🚀

… for bucket TTL

Wires the dead rate-limit paths so bet_limit, oracle_call_limit, and the
per-ledger bet cap are actually enforced. Fixes a critical bug where TTL
extended in seconds instead of ledger counts, causing rent inflation.

Changes:
- Enforce bet_limit in place_bet_inner, place_bets, and vote
- Enforce oracle_call_limit in fetch_oracle_result before external calls
- Expose set_per_ledger_bet_cap entrypoint with require_primary_admin
- Fix TTL: convert seconds to ledgers using LEDGER_SECONDS constant
- Fix voting limit: change key from (user, market) to (user) globally
- Fix get_rate_limit_status to return accurate reset time in HalfLife mode

Test coverage: 12 scenarios covering limits, batch atomicity, TTL, error precedence

Closes Predictify-org#1464
@drips-wave

drips-wave Bot commented Oct 21, 2026

Copy link
Copy Markdown

@Kiosh-123 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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	contracts/predictify-hybrid/IMPLEMENTATION_SUMMARY.md
#	contracts/predictify-hybrid/src/bets.rs
@greatest0fallt1me
greatest0fallt1me merged commit 197e76f into Predictify-org:master Oct 24, 2026
1 check failed
greatest0fallt1me added a commit that referenced this pull request Oct 24, 2026
… limit

#1476 changed the voting bucket key from (user, market) to user, making
the voting limit global per user. The old test still expected a fresh
budget on a second market.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
greatest0fallt1me added a commit that referenced this pull request Oct 24, 2026
* fix(ci): restore green master build after #1471/#1476/#1478

- rate_limit_enforcement_tests (from #1476) never compiled: it imported a
  non-existent crate::test_utils, called CircuitBreaker::set_state and
  CircuitBreakerState::Open which do not exist, and lacked the testutils
  Ledger trait import. Its tests also registered a second, uninitialised
  contract after setup, so they could not pass. Drop the module; the
  rate-limiter enforcement changes from #1476 are kept.
- BudgetGuard::check compared *consumed* instructions against the
  "minimum remaining" threshold, so distribute_payouts aborted with
  OperationWouldExceedBudget after 100k instructions. This was hidden
  while resolution auto-distributed with `let _ =`; #1471 made
  distribution an explicit call and its payout gating tests exposed it.
  Compute remaining headroom against a per-transaction ceiling instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(rate-limiter): align test_different_markets with per-user voting limit

#1476 changed the voting bucket key from (user, market) to user, making
the voting limit global per user. The old test still expected a fresh
budget on a second market.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(conservation): distribute payouts explicitly after the dispute window

#1471 removed the automatic distribution from resolve_market_manual, so
the conservation test must wait out the post-resolution dispute window
and call distribute_payouts before checking credited balances.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: greatest0fallt1me <greatest0fallt1me@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

Wire the dead rate-limit paths so bet_limit, oracle_call_limit and the per-ledger bet cap are enforced, and fix the bucket TTL units

2 participants