Objective. Restore a damaged ledger without touching any stamps by rebuilding it from sidecar lines — deterministic, plain ASCII.
Setup (inputs)
- Sidecars on disk, each containing the single-line stamp:
SSMCLOCK1|iso_utc|rasi_idx|theta_deg|sha256(file)|chain[|kv:...] - The existing ledger may have deletions/reorders.
Procedure (deterministic, copy-ready)
- Collect sidecars for the time range you want to rebuild. Read each full line verbatim (carry any
kv:tail unchanged). - Sort by local creation order if known; otherwise, use a stable ASCII order you will keep for the rebuilt ledger (this choice affects only ledger presentation, not stamp validity).
- Rebuild from zero:
- Seed:
chain_0 = "0"*64. - For each sidecar line
k, reconstructstamp_core_k = "SSMCLOCK1|" + iso_utc + "|" + rasi_idx + "|" + theta_deg + "|" + sha256(file). - Select
H_chainfromkv:chain_algo(or defaultsha256). - Compute
chain_k' = H_chain( ascii(chain_{k-1} + "|" + stamp_core_k) ). - Require
chain_k' == chainfrom the sidecar. - Append the original full line to the new ledger; set
prev = chain_k'.
- Seed:
- Atomically replace the damaged ledger with the rebuilt file (e.g., write to
ledger.tmpthen rename).
Expected result
- A fresh, append-only ledger whose per-row
chainvalues match the sidecars exactly; a subsequent continuity rewalk yieldsCHAIN_OK=true.
Why this works
- Sidecars are the ground truth: each includes the recorded
chainderived fromchain_0 = "0"*64and itsstamp_core. - Recomputing
chain_k = H_chain( ascii(chain_{k-1} + "|" + stamp_core_k) )using the exact ASCII fields guarantees parity when no bytes changed.
Operational notes
- Do not reprint/normalize inner fields (keep
theta_degas recorded with its fixed digits; digests remain lowercase64-hex). - Mixed algorithms are fine: choose
H_chainper row fromkv:chain_algo. - If any sidecar fails the recomputation, flag that sidecar as suspect and do not include it.
Minimal verifier tail (after rebuild)
LEDGER_OK=true
Navigation
Back: SSM-Clock Stamp – Ledger Break (row deletion/reorder) (5.4)
Next: SSM-Clock Stamp – Daily Anchor Parity (ledger vs sidecars) (5.6)