Skip to content

feat: add oracle price deviation bound to resolution path#575

Merged
greatest0fallt1me merged 2 commits into
Predictify-org:masterfrom
Vvictor-commits:feature/oracle-deviation-bound
May 29, 2026
Merged

feat: add oracle price deviation bound to resolution path#575
greatest0fallt1me merged 2 commits into
Predictify-org:masterfrom
Vvictor-commits:feature/oracle-deviation-bound

Conversation

@Vvictor-commits
Copy link
Copy Markdown
Contributor

@Vvictor-commits Vvictor-commits commented May 28, 2026

Closes #554


Summary

Adds a configurable price deviation guard to the oracle validation path. A Reflector (or any oracle) price that moves beyond a configured percentage from the last accepted reading is rejected before it can influence market resolution — closing a key oracle manipulation vector.

Changes

types.rs

  • Added max_deviation_bps: Option<u32> to GlobalOracleValidationConfig and EventOracleValidationConfig
  • None disables the check (fully backward-compatible)

oracles.rsOracleValidationConfigManager

  • validate_oracle_data now runs a deviation check after staleness/confidence:
    • Loads the last accepted reference price from persistent storage (key: ("ORC_REF", market_id))
    • First reading: no reference → accepted and stored immediately
    • Subsequent readings: deviation_bps = abs(price - ref) * 10_000 / ref; if > max_deviation_bpsErr(OracleNoConsensus) + oracle_validation_failed event with reason price_deviation_exceeded
    • Reference is updated only on acceptance
  • Added get_reference_price helper (used by tests)
  • validate_config_values rejects max_deviation_bps = 0 or > 10_000
  • Removed "temporarily disabled" stubs from set_global_config / set_event_config

lib.rs

  • set_oracle_val_cfg_global and set_oracle_val_cfg_event accept new max_deviation_bps: Option<u32> param and call through to OracleValidationConfigManager
  • get_oracle_val_cfg_effective returns live config instead of hardcoded defaults

Tests (6 new, inline in oracles.rs)

Test Covers
test_deviation_first_reading_accepted_and_stored No reference → accepted, reference stored
test_deviation_within_bound_accepted 3% move with 5% bound → ok
test_deviation_exactly_at_bound_accepted Exactly 5% with 5% bound → ok (not strictly greater)
test_deviation_spike_beyond_bound_rejected 20% spike with 5% bound → OracleNoConsensus + event
test_deviation_disabled_when_none max_deviation_bps: None → 50% move passes
test_deviation_per_event_override Per-event 2% bound overrides global None

Run tests

cargo test -p predictify-hybrid -- oracle

michaelvic123 and others added 2 commits May 28, 2026 12:03
- Add max_deviation_bps: Option<u32> to GlobalOracleValidationConfig and
  EventOracleValidationConfig in types.rs (None = disabled, backward-compat)
- validate_oracle_data in OracleValidationConfigManager now checks the
  fetched price against the last accepted reference price stored per market;
  deviation > max_deviation_bps returns Err(OracleNoConsensus) and emits
  an oracle_validation_failed event with reason 'price_deviation_exceeded'
- First reading (no reference stored) is always accepted and stored
- add get_reference_price helper for test inspection
- validate_config_values rejects deviation = 0 or > 10_000 bps
- Wire set_oracle_val_cfg_global / set_oracle_val_cfg_event entrypoints
  through to OracleValidationConfigManager (removes 'temporarily disabled')
- get_oracle_val_cfg_effective now returns live config instead of hardcoded defaults
- Update all existing struct construction sites and tests with new field
- 6 new deviation tests: first-reading, within-bound, exactly-at-bound,
  spike-beyond-bound, disabled-when-none, per-event-override
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 28, 2026

@Vvictor-commits 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

@greatest0fallt1me greatest0fallt1me merged commit ccd7596 into Predictify-org:master May 29, 2026
1 check failed
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 configurable per-market oracle deviation bound to reject anomalous Reflector prices

3 participants