Skip to content

feat(verify): bind an OTS proof to the ledger before claiming external time - #55

Merged
bhyi4 merged 2 commits into
mainfrom
claude/ots-ledger-binding
Nov 24, 2026
Merged

bhyi4 merged 2 commits into
mainfrom
claude/ots-ledger-binding

Conversation

@bhyi4

@bhyi4 bhyi4 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Requested by 범후연이 · project thread

Problem

mirror-stack-verify --ots PROOF checked the proof's Bitcoin block, but it never checked which file the proof stamps. Any valid proof for any file passed. The tool said this itself: "ledger-to-proof binding is not checked here". So nothing in the stack let an outsider confirm the core claim, that a preregistration existed before a given time. locate_ledger() already existed but was only used in tests.

Second, smaller issue: verify() used the first BitcoinBlockHeaderAttestation printed by ots info. A real proof stamped on three calendars, dated 2026-07-25, lists blocks 959655, 959599 and 959609 in that order. verify() reported 959655, which is 56 blocks later than the earliest. That understates the proof rather than overstating it, but it was still wrong.

Change

  • New ots_anchor.bind(ledger, manifest, proof). It reports external time only when all three checks hold:

    1. Proof to manifest: the File sha256 hash in ots info equals the sha256 of the manifest.
    2. Manifest to ledger: a manifest row pins a prefix of this ledger, using locate_ledger. Both format 1 and format 2 work, and appends after the stamp are fine.
    3. Proof to Bitcoin: the earliest attested block's merkle root matches a public explorer.

    It returns the covered lines with their type and claim_id, and lists the lines appended after the stamp as uncovered.

  • New mirror-stack-verify --manifest option. With --ots, it prints [binding] and [EXTERNAL_TIME] lines, including the preregistrations that the proof covers. --manifest without --ots fails. With --ots alone, behaviour is unchanged and precedence is still reported as UNVERIFIED.

  • verify() now picks the earliest attestation, pairs each merkle root with its own block, and also returns attested_blocks and proof_file_sha256.

  • Replaced the deprecated datetime.utcnow() and utcfromtimestamp() calls. The output format is the same.

  • Updated README, docs/ANCHORING.md and the CHANGELOG.

The MCP tool mm_anchor_verify was not changed and gets no binding option in this PR. That keeps the tool schema test (22 tools) as it is. Binding could be added to the MCP tool as a follow-up.

Verification

  • New tests/test_ots_binding.py (8 tests). It fakes ots info with the same layout as the real output, where each merkle root comment comes right after its attestation and the earliest block is not listed first, and it fakes the explorer. The tests cover:
    • the bound case;
    • a proof for another file;
    • a reordered ledger;
    • an explorer mismatch;
    • the CLI output and exit codes.
  • Full suite: 138 passed, 2 skipped. Python 3.13, Linux, mcp<2.
  • Run against a real private proof, manifest and ledger. These files are not committed.
    • Matching proof and manifest: the proof stamps the manifest and the manifest pins the first 8 of 20 ledger lines. The earliest block reported was 959599.
    • Proof from 07-25 against the 07-26 manifest: correctly rejected as "does not stamp this manifest".
  • Not verified: the explorer comparison on real data. The cloud environment blocks both blockstream.info and mempool.space, so the real run ended at "NOT CONFIRMED" for the Bitcoin step.

Generated by Claude Code

…l time

mirror-stack-verify checked an OTS proof's Bitcoin block without checking
which file the proof stamped, so any valid proof passed, and it left ledger
precedence UNVERIFIED by design. With --manifest it now checks
proof -> manifest (file sha256 from ots info), manifest -> ledger prefix
(locate_ledger) and proof -> Bitcoin, and only then reports the pinned
lines and the preregistrations among them as existing before the block.

verify() now uses the earliest attestation and pairs each merkle root with
its own block; a real multi-calendar proof listed block 959655 before 959599.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Aq8kkjKAMDjSSK54hcWnuc
@bhyi4 bhyi4 self-assigned this Nov 24, 2026
On Windows, opentimestamps-client crashes on import (python-bitcoinlib finds
no OpenSSL library). _info() returned the empty stdout, which bind() then
misreported as a proof that names no file. It now raises with the client's
error. Also look for ots beside sys.executable when the venv is not active.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Aq8kkjKAMDjSSK54hcWnuc
@bhyi4
bhyi4 merged commit 3056788 into main Nov 24, 2026
6 checks passed
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.

2 participants