research: audit verified prediction artifacts - #139
Conversation
📝 WalkthroughWalkthroughAdds a verified-artifact audit builder for Binance and Polymarket evidence, exposes its API, validates coverage and event completeness, incorporates related sources into policy identity hashing, updates mission snapshot pins, and records the migration task. ChangesVerified artifact audit
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant BinanceTape
participant PolymarketEvidence
participant AuditBuilder
participant AuditReport
BinanceTape->>AuditBuilder: provide verified market evidence
PolymarketEvidence->>AuditBuilder: provide contracts, references, books, and settlements
AuditBuilder->>AuditBuilder: validate windows and compute audit observations
AuditBuilder->>AuditReport: return PredictionMarketDataAuditReport
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 654d751834
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@rust_hft/prediction-markets/crates/ploy-research/src/verified_artifact_audit.rs`:
- Around line 319-353: Update the reference validation loop around event_index
and present so each Chainlink reference is accepted only when its source_time
falls within the matching contract event’s governed reference window, rejecting
stale and post-event evidence before present.insert. Add counterexamples
covering both out-of-window cases and verify they do not mark the event bucket
as covered.
- Around line 501-516: Update the settlement validation predicate around
winner_matches so it requires the declared winner’s price to be Decimal::ONE and
the opposing token’s price to be Decimal::ZERO, while preserving token-ID
matching and the existing resolved/sum checks. Use the winning_side distinction
to validate the corresponding up or down price rather than accepting either
resolved assignment.
- Around line 416-448: Update the order-book loop around the visible book
filtering to validate book.available_at against book.source_time before payload
and bucket accounting: track and reject causality violations where available_at
precedes source_time, and track and reject books whose source delay exceeds the
configured source-delay gate. Ensure these rejections occur before row_count,
invalid-payload, usable-row, coverage, and bucket updates, using the existing
audit counters and delay configuration symbols.
In `@rust_hft/prediction-markets/tasks/todo.md`:
- Line 41: Update the migration checklist entry for building the prediction data
audit from externally verified artifacts to reflect the implemented audit
builder: mark the task complete, or rewrite it to specify only the remaining
deferred integration work.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e520f964-aa93-4f10-b4b7-ae2d06c018fd
📒 Files selected for processing (6)
rust_hft/prediction-markets/config/research_missions/polymarket-btc-5m.example.jsonrust_hft/prediction-markets/config/research_missions/polymarket-sol-5m.example.jsonrust_hft/prediction-markets/crates/ploy-research/src/lib.rsrust_hft/prediction-markets/crates/ploy-research/src/prediction_loop.rsrust_hft/prediction-markets/crates/ploy-research/src/verified_artifact_audit.rsrust_hft/prediction-markets/tasks/todo.md
Change contract
Build the governed six-surface prediction-market data audit directly from private typed
VerifiedBinanceMarketTapeandVerifiedPolymarketEvidenceSethandles, failing closed on invalid windows, causality or delay, missing event-local opening references, incomplete two-sided book buckets, or settlement absence while emitting canonical snapshot-consumable metrics.Out of scope
ResearchSnapshotDependency or merge order
Focused validation
source_timefor event-lifetime buckets even when availability is delayed999/1000book coverage even when the isolated gap is only 60 secondsRollout / rollback impact
Research-only typed audit seam. Roll forward by calling it inside the next snapshot adapter from the same verified handles. Roll back by reverting this PR only; immutable artifacts, collectors, deployment, live execution, and production ECS are unchanged, and live execution remains disabled.