Skip to content

feat: event emission audit for material state changes (#426)#483

Closed
jabir-dev788 wants to merge 1 commit intoPredictify-org:masterfrom
jabir-dev788:feature/event-emission-audit
Closed

feat: event emission audit for material state changes (#426)#483
jabir-dev788 wants to merge 1 commit intoPredictify-org:masterfrom
jabir-dev788:feature/event-emission-audit

Conversation

@jabir-dev788
Copy link
Copy Markdown
Contributor

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 #426
Fixes #426

Priority Level

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

📝 Detailed Description

What does this PR do?

This PR completes the Event Emission Audit for the Predictify Hybrid smart contracts to ensure all financially material state changes emit indexer-friendly events. Specifically, it:

  1. Fixes store_event in events.rs to publish directly to the Soroban event stream (env.events().publish) along with persistent storage.
  2. Adds new emit helpers for bet resolution (emit_bet_resolved), bet cancellation (emit_bet_cancelled), and market cancellation (emit_market_cancelled).
  3. Fixes resolve_market_bets in bets.rs to emit per-bet status events (removing the old implicit skip).
  4. Adds missing emit calls in disputes.rs (emit_dispute_resolved) to ensure dispute finalization is indexable.
  5. Re-enables and extends event_management_tests.rs with 9 new regression tests to verify that every material transition publishes an event.
  6. Updates documentation: Adds Section 6 to SECURITY_TESTING_GUIDE.md containing the threat model, invariant proofs, and full event tables, and updates the main README.md.

Why is this change needed?

Prior to this change, key state transitions (like bet resolutions, dispute finalization, and market cancellations) were only written to persistent contract storage. Off-chain indexers (like Horizon), analytics tools, and downstream DApps cannot effectively listen to state changes purely through storage modifications. This PR ensures a robust, auditable event stream is emitted for every financially material action.

How was this tested?

Tested by writing 9 new property/regression tests in event_management_tests.rs. Each test simulates a full contract action (e.g., place_bet, resolve_market_manual, dispute_market, claim_winnings) and asserts that env.events().all() is not empty and captures the correct state transition event.

Alternative Solutions Considered

Instead of fundamentally changing store_event to dual-write to the Soroban event stream, we considered writing a separate publish_event utility. However, updating store_event natively ensures all existing 15+ event-emitting call sites immediately become indexer-visible without requiring invasive caller-side refactoring.


🏗️ 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 (Event emission added to bet resolution loop)
  • Dispute mechanism modified (Event emission added to dispute finalization)
  • 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

cargo test -p predictify-hybrid event_management 2>&1
# Expected output: All 9 new event_management regression tests passed successfully.

- Fix store_event to publish to Soroban event stream
- Add bet resolution and cancellation emit helpers
- Fix resolve_market_bets and resolve_dispute to emit events
- Add event_management_tests.rs regression tests
- Update SECURITY_TESTING_GUIDE.md and docs
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 27, 2026

@jabir-dev788 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

@jabir-dev788 jabir-dev788 closed this by deleting the head repository Mar 27, 2026
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.

Event emission audit for material state changes

1 participant