File size: 756 Bytes
63f41a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3
"""Frozen-verifier hash (docs/LEAN_VERIFIER.md 7.2): sha256 over each align/verify/**/*.py in sorted path order,
hashing `path + NUL + bytes + NUL`. `--check HEX` exits 1 on mismatch."""
import argparse, hashlib, sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[2]


def verifier_hash() -> str:
    h = hashlib.sha256()
    for p in sorted((ROOT / "align/verify").rglob("*.py")):
        rel = p.relative_to(ROOT).as_posix()
        h.update(rel.encode() + b"\0" + p.read_bytes() + b"\0")
    return h.hexdigest()


if __name__ == "__main__":
    ap = argparse.ArgumentParser(); ap.add_argument("--check")
    a = ap.parse_args(); v = verifier_hash(); print(v)
    sys.exit(1 if a.check and a.check != v else 0)