Skip to content

Add verifier-only mode for anchored Polymarket evidence - #209

Merged
proerror77 merged 1 commit into
mainfrom
codex/polymarket-evidence-verifier-cli
Jul 22, 2026
Merged

proerror77 merged 1 commit into
mainfrom
codex/polymarket-evidence-verifier-cli

Conversation

@proerror77

@proerror77 proerror77 commented Jul 22, 2026

Copy link
Copy Markdown
Owner

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

  • Cross-artifact cohort/set policy, including the retired BTC+SOL-per-slot aggregator
  • Collector or publisher changes
  • ResearchSnapshot construction or behavior changes
  • Evaluator/MCTS, Paper/Live, OMS, or RiskGate

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-snapshot
  • cargo check -p ploy-research --features db --bin monday-prediction-snapshot
  • rustfmt --edition 2021 --check crates/ploy-research/src/bin/monday-prediction-snapshot.rs
  • Real CLI counterexample: uppercase content digest exits 1 before file access and emits no success JSON
  • Matt code review: Standards 0 findings; Spec 0 findings
  • Review scope: 1 changed file, +162/-17; no lower review-tool limit is exposed, and the diff is below the repository 25-file/750-line split threshold

The repository-wide clippy -D warnings lane still reports pre-existing warnings in unmodified ploy-market-contracts and ploy-research library files; this PR does not widen scope to change them.

Rollout/rollback impact

After merge, publish one immutable research-runner image 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

    • Added a command-line mode to verify Polymarket evidence without generating a complete research snapshot.
    • Supports verification of multiple anchored artifacts and outputs structured JSON results.
    • Provides validation errors for malformed arguments and invalid SHA-256 inputs.
  • Bug Fixes

    • Improved evidence verification error reporting and consistency across multiple artifacts.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The snapshot binary adds --verify-polymarket-evidence, validates repeated anchored artifact groups, verifies each evidence set, and prints a monday.polymarket.evidence_verification.v1 JSON document without compiling a full research snapshot.

Changes

Polymarket verification mode

Layer / File(s) Summary
Grouped verification argument parsing
rust_hft/.../src/bin/monday-prediction-snapshot.rs
The CLI parser validates repeated artifact groups and converts them into AnchoredArtifact values, with tests for valid and malformed inputs.
Anchored artifact verification
rust_hft/.../src/bin/monday-prediction-snapshot.rs
Artifacts derive trust anchors, verify sealed evidence triplets, aggregate verified results, and report contextual errors.
Verifier-only output and routing
rust_hft/.../src/bin/monday-prediction-snapshot.rs
The binary derives artifact identity and count fields, emits versioned JSON, and routes the verification flag around snapshot/database compilation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • #208 — Implements the verifier-only mode for anchored Polymarket evidence with grouped SHA-256 inputs, per-artifact verification, and JSON output.

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
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the PR’s main change: adding a verifier-only mode for anchored Polymarket evidence.
Description check ✅ Passed All required sections are present with the needed context; only minor heading wording differs from the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/polymarket-evidence-verifier-cli

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0bdc61e and 522a30e.

📒 Files selected for processing (1)
  • rust_hft/prediction-markets/crates/ploy-research/src/bin/monday-prediction-snapshot.rs

Comment on lines +207 to +220
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()))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Suggested change
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.

Comment on lines +260 to 286
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<_>>>()?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ 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.

@proerror77
proerror77 merged commit 8ba6d7a into main Jul 22, 2026
28 checks passed
@proerror77
proerror77 deleted the codex/polymarket-evidence-verifier-cli branch July 24, 2026 08:44
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.

1 participant