#!/usr/bin/env python3 """Independently verify a ParamAI impact evidence ledger. An auditor does not have to trust ParamAI's own "chain intact" badge. Download the programme's evidence CSV from the impact dashboard (Evidence -> Download evidence CSV) and run: python3 verify_impact_ledger.py impact-evidence-.csv Standard library only. The rule it checks is the one published at https://paramai.in/impact-evidence-methodology: entry_hash = SHA-256 hex of the lines, joined with "\\n": PARAMAI-IMPACT-LEDGER-v1 partner_id programme_id seq event_type subject occurred_at (UTC, microseconds, e.g. 2026-11-08T07:57:07.123456Z) payload (canonical JSON: keys sorted, no spaces) prev_hash (64 zeros for the first entry) It also checks that seq runs 1, 2, 3, ... with no gaps, that every prev_hash is the entry_hash before it, and that each payload is in canonical form. To tie the ledger to a signed attestation, compare the attestation's ledger_head_seq / ledger_head_hash with the row of that seq printed here. Exit status: 0 if the chain is intact, 1 if not, 2 for a file problem. """ import csv import hashlib import json import sys DOMAIN = "PARAMAI-IMPACT-LEDGER-v1" GENESIS = "0" * 64 def canonical(payload: str) -> str: return json.dumps(json.loads(payload), sort_keys=True, separators=(",", ":"), ensure_ascii=False) def entry_hash(row: dict) -> str: parts = [DOMAIN, row["partner_id"], row["programme_id"], row["seq"], row["event_type"], row["subject"], row["occurred_at"], row["payload"], row["prev_hash"]] return hashlib.sha256("\n".join(parts).encode("utf-8")).hexdigest() def main(path: str) -> int: try: with open(path, newline="", encoding="utf-8") as f: rows = list(csv.DictReader(f)) except (OSError, csv.Error) as e: print(f"cannot read {path}: {e}") return 2 prev, expect = GENESIS, 1 counts = {} for row in rows: seq = int(row["seq"]) problem = None if seq != expect: problem = f"sequence gap: expected {expect}, found {seq}" elif row["prev_hash"] != prev: problem = "prev_hash does not match the entry before it" elif canonical(row["payload"]) != row["payload"]: problem = "payload is not in canonical form" elif entry_hash(row) != row["entry_hash"]: problem = "entry_hash does not match the entry's contents" if problem: print(f"BROKEN at entry {seq}: {problem}") return 1 counts[row["event_type"]] = counts.get(row["event_type"], 0) + 1 prev, expect = row["entry_hash"], expect + 1 print(f"INTACT: {len(rows)} entries, head {expect - 1} = {prev}") for k in sorted(counts): print(f" {k}: {counts[k]}") return 0 if __name__ == "__main__": if len(sys.argv) != 2: print(__doc__) sys.exit(2) sys.exit(main(sys.argv[1]))