File size: 3,295 Bytes
b67bb63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
"""The Faust Baseline - session open load proof, one pass.
Computes everything fresh from the files on disk. Recites nothing.
Usage: python3 faust-open.py [folder]   (default: /mnt/user-data/uploads)
"""
import sys, os, json, hashlib, random, urllib.request

DIR = sys.argv[1] if len(sys.argv) > 1 else "/mnt/user-data/uploads"
MANIFEST = "faust-baseline-master-manifest.json"

def sha(path):
    with open(path, "rb") as fh:
        return hashlib.sha256(fh.read()).hexdigest()

def load(name):
    with open(os.path.join(DIR, name), encoding="utf-8") as fh:
        return json.load(fh)

print("=== BLOCK ONE - LOAD PROOF (computed this run) ===")

# 1. Hash and byte-check every artifact against the manifest
mpath = os.path.join(DIR, MANIFEST)
if not os.path.exists(mpath):
    print("LOAD FAILURE - manifest not found in", DIR); sys.exit(1)
man = load(MANIFEST)
print(f"manifest r{man.get('manifest_revision')}  sha256 {sha(mpath)}  {os.path.getsize(mpath)} bytes")
failed = False
for key, a in sorted(man["artifacts"].items(), key=lambda kv: kv[1]["load_order"]):
    p = os.path.join(DIR, a["filename"])
    if not os.path.exists(p):
        print(f"{a['load_order']}. {a['filename']}: MISSING"); failed = True; continue
    h, b = sha(p), os.path.getsize(p)
    ok = (h == a["sha256"] and b == a["bytes"])
    failed |= not ok
    print(f"{a['load_order']}. {a['filename']}\n   sha256 {h}\n   {b} bytes  -> {'MATCH' if ok else 'MISMATCH vs manifest ' + a['sha256'][:12] + ' / ' + str(a['bytes'])}")

# 2. Stack-order hashes and counts, derived from the files' own bytes
spot_pool = []
for name in ("faust-baseline-core.json", "derfaust-codex-1.json"):
    if not os.path.exists(os.path.join(DIR, name)):
        continue
    d = load(name)
    ids = [i if isinstance(i, str) else i.get("id") for i in d["stack_order"]]
    j = ",".join(ids)
    actual = len(d["protocols"])
    print(f"\n{name}  edition r{d.get('edition_revision')}")
    print(f"   stack order ({len(ids)}): {ids[0]} ... {ids[-1]}")
    print(f"   stack-order hash {hashlib.sha256(j.encode()).hexdigest()}")
    print(f"   protocols in file {actual} / declared {d.get('protocol_count')}"
          + ("" if actual == d.get("protocol_count") else "  <- COUNT MISMATCH"))
    print(f"   still_undone items: {len(d.get('still_undone', []))}")
    for p in d["protocols"]:
        for n, r in enumerate(p.get("rules", []) or [], 1):
            if isinstance(r, str):
                spot_pool.append((name, p["id"], n, r))

# 3. Two spot values, drawn at random so they change session to session
print("\nSpot values (random draw this run):")
for fname, pid, n, r in random.sample(spot_pool, min(2, len(spot_pool))):
    print(f"   {pid} rule {n}: {r[:110]}{'...' if len(r) > 110 else ''}")

# 4. Live time
try:
    with urllib.request.urlopen(
        "https://timeapi.io/api/Time/current/zone?timeZone=America/New_York", timeout=10) as r:
        t = json.load(r)
    print(f"\nLive time: {t['dayOfWeek']} {t['date']} {t['time']} America/New_York (source: timeapi.io)")
except Exception as e:
    print(f"\nLive time: UNAVAILABLE ({e}) - name the gap, do not substitute a recalled time")

print("\nRESULT:", "LOAD FAILURE - report before proceeding" if failed else "all artifacts match manifest")