Add verifier-only mode for anchored Polymarket evidence - #209
Conversation
📝 WalkthroughWalkthroughThe snapshot binary adds ChangesPolymarket verification mode
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Sequence Diagram(s)sequenceDiagram
participant CLI
participant VerifyMode
participant EvidenceVerifier
participant EvidenceFiles
CLI->>VerifyMode: --verify-polymarket-evidence arguments
VerifyMode->>EvidenceVerifier: anchored artifact and SHA-256 values
EvidenceVerifier->>EvidenceFiles: verify sealed evidence triplet
EvidenceFiles-->>EvidenceVerifier: verified evidence
EvidenceVerifier-->>VerifyMode: verified artifact results
VerifyMode-->>CLI: monday.polymarket.evidence_verification.v1 JSON
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
Actionable comments posted: 2
🤖 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/bin/monday-prediction-snapshot.rs`:
- Around line 260-286: The members collection in the snapshot serialization flow
must be deterministic regardless of CLI group order. In the artifact mapping
around verify_polymarket_artifact, retain each verified member’s identity and
sort the collected members by event_start_gte, then event_start_lt, then
content_sha256 before producing the serialized JSON; do not add cross-artifact
policy validation.
- Around line 207-220: Update the artifact verification flow around
artifact_triplet, PolymarketEvidenceTrustAnchor::from_lower_hex, and
seal_polymarket_evidence_triplet so every fallible step is wrapped with
artifact-path context before propagation. Ensure malformed anchors, missing
sidecars, sealing failures, and verification failures all retain the existing
“verify Polymarket artifact” path context.
🪄 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: cd812209-2495-44d0-ac30-c54e59f74db2
📒 Files selected for processing (1)
rust_hft/prediction-markets/crates/ploy-research/src/bin/monday-prediction-snapshot.rs
| let (data, manifest, success) = artifact_triplet(&artifact.data)?; | ||
| let trust = PolymarketEvidenceTrustAnchor::from_lower_hex( | ||
| &artifact.content_sha256, | ||
| &artifact.manifest_sha256, | ||
| )?; | ||
| verify_polymarket_evidence(seal_polymarket_evidence_triplet( | ||
| &PolymarketEvidenceTriplet { | ||
| data, | ||
| manifest, | ||
| success, | ||
| }, | ||
| &trust, | ||
| )?) | ||
| .with_context(|| format!("verify Polymarket artifact {}", artifact.data.display())) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Add artifact-path context to anchor and sealing failures.
The ? operators on lines 207-219 return before line 220’s .with_context(...) runs. Malformed anchors, missing sidecars, and seal failures therefore omit the artifact path, contrary to this mode’s path-contextual error contract.
Proposed fix
- let (data, manifest, success) = artifact_triplet(&artifact.data)?;
+ let context = || format!("verify Polymarket artifact {}", artifact.data.display());
+ let (data, manifest, success) = artifact_triplet(&artifact.data).with_context(&context)?;
let trust = PolymarketEvidenceTrustAnchor::from_lower_hex(
&artifact.content_sha256,
&artifact.manifest_sha256,
- )?;
- verify_polymarket_evidence(seal_polymarket_evidence_triplet(
+ )
+ .with_context(&context)?;
+ let sealed = seal_polymarket_evidence_triplet(
&PolymarketEvidenceTriplet {
data,
manifest,
success,
},
&trust,
- )?)
- .with_context(|| format!("verify Polymarket artifact {}", artifact.data.display()))
+ )
+ .with_context(&context)?;
+ verify_polymarket_evidence(sealed).with_context(context)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| let (data, manifest, success) = artifact_triplet(&artifact.data)?; | |
| let trust = PolymarketEvidenceTrustAnchor::from_lower_hex( | |
| &artifact.content_sha256, | |
| &artifact.manifest_sha256, | |
| )?; | |
| verify_polymarket_evidence(seal_polymarket_evidence_triplet( | |
| &PolymarketEvidenceTriplet { | |
| data, | |
| manifest, | |
| success, | |
| }, | |
| &trust, | |
| )?) | |
| .with_context(|| format!("verify Polymarket artifact {}", artifact.data.display())) | |
| let context = || format!("verify Polymarket artifact {}", artifact.data.display()); | |
| let (data, manifest, success) = artifact_triplet(&artifact.data).with_context(&context)?; | |
| let trust = PolymarketEvidenceTrustAnchor::from_lower_hex( | |
| &artifact.content_sha256, | |
| &artifact.manifest_sha256, | |
| ) | |
| .with_context(&context)?; | |
| let sealed = seal_polymarket_evidence_triplet( | |
| &PolymarketEvidenceTriplet { | |
| data, | |
| manifest, | |
| success, | |
| }, | |
| &trust, | |
| ) | |
| .with_context(&context)?; | |
| verify_polymarket_evidence(sealed).with_context(context) |
🤖 Prompt for 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.
In
`@rust_hft/prediction-markets/crates/ploy-research/src/bin/monday-prediction-snapshot.rs`
around lines 207 - 220, Update the artifact verification flow around
artifact_triplet, PolymarketEvidenceTrustAnchor::from_lower_hex, and
seal_polymarket_evidence_triplet so every fallible step is wrapped with
artifact-path context before propagation. Ensure malformed anchors, missing
sidecars, sealing failures, and verification failures all retain the existing
“verify Polymarket artifact” path context.
| let members = artifacts | ||
| .iter() | ||
| .map(|artifact| { | ||
| let (data, manifest, success) = artifact_triplet(&artifact.data)?; | ||
| let trust = PolymarketEvidenceTrustAnchor::from_lower_hex( | ||
| &artifact.content_sha256, | ||
| &artifact.manifest_sha256, | ||
| )?; | ||
| verify_polymarket_evidence(seal_polymarket_evidence_triplet( | ||
| &PolymarketEvidenceTriplet { | ||
| data, | ||
| manifest, | ||
| success, | ||
| }, | ||
| &trust, | ||
| )?) | ||
| .with_context(|| format!("verify Polymarket artifact {}", artifact.data.display())) | ||
| let verified = verify_polymarket_artifact(artifact)?; | ||
| let identity = verified.identity(); | ||
| let market_ids = verified | ||
| .contracts() | ||
| .iter() | ||
| .map(|contract| contract.market_id.as_str()) | ||
| .collect::<std::collections::BTreeSet<_>>(); | ||
| Ok(serde_json::json!({ | ||
| "data": artifact.data, | ||
| "content_sha256": identity.content_sha256, | ||
| "manifest_sha256": identity.manifest_sha256, | ||
| "event_start_gte": identity.event_start_gte.to_rfc3339(), | ||
| "event_start_lt": identity.event_start_lt.to_rfc3339(), | ||
| "rows": identity.rows, | ||
| "events": identity.events, | ||
| "market_ids": market_ids, | ||
| "contracts": verified.contracts().len(), | ||
| "books": verified.books().len(), | ||
| "references": verified.references().len(), | ||
| "trades": verified.trades().len(), | ||
| "settlements": verified.settlements().len(), | ||
| })) | ||
| }) | ||
| .collect::<anyhow::Result<Vec<_>>>()?; |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Canonicalize member ordering before serializing.
members retains CLI group order, so the same anchored artifact set produces different JSON when groups are permuted. Sort verified members by the existing identity ordering (event_start_gte, event_start_lt, content_sha256) before serialization, without invoking cross-artifact policy validation.
🤖 Prompt for 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.
In
`@rust_hft/prediction-markets/crates/ploy-research/src/bin/monday-prediction-snapshot.rs`
around lines 260 - 286, The members collection in the snapshot serialization
flow must be deterministic regardless of CLI group order. In the artifact
mapping around verify_polymarket_artifact, retain each verified member’s
identity and sort the collected members by event_start_gte, then event_start_lt,
then content_sha256 before producing the serialized JSON; do not add
cross-artifact policy validation.
Change contract
Add an explicit verifier-only mode to the existing research snapshot CLI that binds each Polymarket artifact to external content/manifest SHA-256 anchors and reuses the existing typed seal plus per-artifact semantic verifier before printing deterministic JSON.
Relates to #208 and unblocks #173.
Out of scope
Dependency or merge order
No stacked code dependency. Merge this PR before the #173 fresh-pod typed verification. #208 remains open until that cloud proof passes.
Focused validation
cargo test --locked -p ploy-research --features db --bin monday-prediction-snapshotcargo check -p ploy-research --features db --bin monday-prediction-snapshotrustfmt --edition 2021 --check crates/ploy-research/src/bin/monday-prediction-snapshot.rsThe repository-wide
clippy -D warningslane still reports pre-existing warnings in unmodifiedploy-market-contractsandploy-researchlibrary files; this PR does not widen scope to change them.Rollout/rollback impact
After merge, publish one immutable
research-runnerimage and run the exact two #173 BTC-only triplets in a fresh ACK pod. The explicit mode returns before ordinary snapshot parsing and does not publish a snapshot. Rollback removes the mode; evidence bytes and verifier semantics are unchanged.Summary by CodeRabbit
New Features
Bug Fixes