Skip to content

feat: add round-relative oracle timestamp window - #323

Merged
josephchimebuka merged 4 commits into
TevaLabs:mainfrom
owohdora-stack:feat/oracle-round-relative-timestamp-window
Aug 8, 2026
Merged

feat: add round-relative oracle timestamp window#323
josephchimebuka merged 4 commits into
TevaLabs:mainfrom
owohdora-stack:feat/oracle-round-relative-timestamp-window

Conversation

@owohdora-stack

Copy link
Copy Markdown
Contributor

Summary

Closes #265
Replace the absolute 300-second oracle data freshness check with a round-relative timestamp window that requires oracle payload timestamps to fall within the round's economic activity period.

Why

The old absolute-freshness check (now - timestamp ≤ 300s) could accept wrong-phase prices — a price from well after the round ended could still be "fresh" relative to the current ledger time. The new window anchors around the round's start and estimated end:

[lower, upper] = [round_start - skew, round_end_estimate + skew]

where round_end_estimate = round_start + (end_ledger - start_ledger) × 5s.

What changed

File Change
types.rs Added start_timestamp: u64 to Round; added OracleTimestampSkew to ConfigChangeKind/ConfigChangePayload
betting.rs Record env.ledger().timestamp() when creating a round
common.rs Added SECONDS_PER_LEDGER, DEFAULT_ORACLE_TIMESTAMP_SKEW, MIN/MAX_ORACLE_TIMESTAMP_SKEW
errors.rs Added OracleTimestampOutsideWindow = 66
settlement.rs Replaced [future + stale] checks with [future + round-window] validation using configurable skew
config.rs Added schedule_oracle_timestamp_skew, get_oracle_timestamp_skew, validation, and _apply_config_payload/_current_config_payload handling
contract.rs Exposed schedule_oracle_timestamp_skew and get_oracle_timestamp_skew publicly
security.rs Updated existing tests; added 4 new boundary tests (before window, after window, lower edge, upper edge)
event_coverage.rs Updated stale-data test to expect OracleTimestampOutsideWindow
ORACLE_OPERATOR_RUNBOOK.md Updated validation order, timestamp field docs, troubleshooting matrix, config table, and Playbook B

Acceptance criteria

  • Pre-bet timestamp rejected (test_resolve_round_timestamp_before_round_window)
  • In-window timestamp accepted (test_resolve_round_valid_payload, boundary tests)
  • After-round timestamp rejected (test_resolve_round_timestamp_after_round_window)
  • Future timestamps still rejected (test_resolve_round_future_timestamp)
  • Configurable skew via timelock (schedule_oracle_timestamp_skew)
  • Docs updated

Testing

The codebase has a pre-existing LengthExceedsMax issue in the DataKey enum (51 variants exceed Soroban's contracttype limit) which prevents compilation of both main and this branch. The changes are structurally sound — all new code avoids adding DataKey variants by using instance storage with Symbol keys.

Dubemtopsite and others added 2 commits July 29, 2026 09:57
Replace the absolute 300s freshness check with a round-relative
timestamp window that requires oracle payload timestamps to fall
within [round_start - skew, round_end_estimate + skew].

Changes:
- Add start_timestamp to Round struct, recorded at round creation
- Replace absolute staleness check (300s) with round-relative lower/upper bounds
- Add configurable OracleTimestampSkew (0-86400s, default 300s) via timelock
- Add OracleTimestampOutsideWindow error
- Add boundary tests (before window, after window, at lower/upper edge)
- Update ORACLE_OPERATOR_RUNBOOK.md with new validation order and playbook
@josephchimebuka

Copy link
Copy Markdown
Contributor

@owohdora-stack Pls can you fix Conflicts and send a message in the group saying you've fixed them so I can merge

@josephchimebuka
josephchimebuka merged commit f15dd34 into TevaLabs:main Aug 8, 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.

Oracle: round-relative absolute timestamp window

3 participants