| @@ -0,0 +1,70 @@ |
| 1 | +"""Replay Meng's archived witnesses from regenerated rows in a disposable checkout.""" |
| 2 | +import argparse |
| 3 | +from decimal import Decimal |
| 4 | +import hashlib |
| 5 | +import importlib.metadata |
| 6 | +import json |
| 7 | +from pathlib import Path |
| 8 | +import subprocess |
| 9 | +import sys |
| 10 | + |
| 11 | +PIN = "30856f7e88b521952e1a04b31bba51fe25c2f5a5" |
| 12 | + |
| 13 | + |
| 14 | +def endpoints(interval): |
| 15 | + lo, hi = map(Decimal, interval.strip("[]").split(",")) |
| 16 | + assert lo <= hi |
| 17 | + return lo, hi |
| 18 | + |
| 19 | + |
| 20 | +def main(): |
| 21 | + parser = argparse.ArgumentParser(description=__doc__) |
| 22 | + parser.add_argument("source", type=Path, help="disposable clone of whenpoem's archive at the pinned revision") |
| 23 | + parser.add_argument("--levels", type=int, nargs="+", choices=range(15, 19), default=list(range(15, 19))) |
| 24 | + parser.add_argument("--workers", type=int, default=6) |
| 25 | + args = parser.parse_args() |
| 26 | + root = args.source.resolve() |
| 27 | + def git(*cmd): |
| 28 | + return subprocess.check_output(["git", *cmd], cwd=root) |
| 29 | + if git("rev-parse", "HEAD").decode().strip() != PIN or git("status", "--porcelain", "--untracked-files=no").strip(): |
| 30 | + sys.exit("Use a clean disposable checkout of " + PIN) |
| 31 | + cache = root / ".lake" / "kernel-rows-112-v1" |
| 32 | + if any(cache.glob("*.npz")): |
| 33 | + sys.exit("Use a fresh cache to exercise row generation") |
| 34 | + if not __debug__: |
| 35 | + sys.exit("Run with Python assertions enabled") |
| 36 | + import flint |
| 37 | + print("Python", sys.version.split()[0], "FLINT", flint.__FLINT_VERSION__, flush=True) |
| 38 | + print({pkg: importlib.metadata.version(pkg) for pkg in |
| 39 | + ("python-flint", "numpy", "scipy", "mpmath", "threadpoolctl")}, flush=True) |
| 40 | + if flint.__version__ != "0.9.0": |
| 41 | + sys.exit("Install python-flint==0.9.0 for this replay") |
| 42 | + for k in args.levels: |
| 43 | + cert = root / f"再生核下界_k{k}.json" |
| 44 | + blob = git("show", f"HEAD:{cert.name}") |
| 45 | + archived = json.loads(blob) |
| 46 | + print(f"k={k} archived certificate SHA-256 {hashlib.sha256(blob).hexdigest()}", flush=True) |
| 47 | + for script, options in [ |
| 48 | + ("kernel_rows.py", ["--workers", str(args.workers)]), |
| 49 | + ("kernel_grid_certificate.py", ["--replay", "--cutoff", "16384"]), |
| 50 | + ]: |
| 51 | + subprocess.run([sys.executable, "-B", script, "--levels", str(k), *options], cwd=root, check=True) |
| 52 | + result = json.loads(cert.read_text(encoding="utf-8")) |
| 53 | + replay = result["replay"] |
| 54 | + assert result["row_bits"] == 112 and replay["bits"] == 192 and replay["cutoff"] == 16384 |
| 55 | + for side in ("min", "max"): |
| 56 | + assert result[side+"_witness"]["coefficients"] == archived[side+"_witness"]["coefficients"] |
| 57 | + lo, hi = endpoints(replay["intervals"][side]) |
| 58 | + old_lo, old_hi = endpoints(archived["replay"]["intervals"][side]) |
| 59 | + assert max(lo, old_lo) <= min(hi, old_hi) |
| 60 | + pos_lo, _ = endpoints(replay["intervals"]["max"]) |
| 61 | + _, neg_hi = endpoints(replay["intervals"]["min"]) |
| 62 | + bound = max(pos_lo, -neg_hi) |
| 63 | + _, delta_upper = endpoints(replay["delta"]) |
| 64 | + assert replay["R_at_modulus_excluded"] and bound > delta_upper |
| 65 | + print(f"k={k} m={result['nodes']} lower={bound} delta_upper={delta_upper} " |
| 66 | + f"margin={bound-delta_upper} identical_archived_replay={replay == archived['replay']}", flush=True) |
| 67 | + |
| 68 | + |
| 69 | +if __name__ == "__main__": |
| 70 | + main() |