SSM-Clock Stamp – Minimal Verifier Pseudocode (4.5)

Purpose. A compact, portable outline to implement a verifier for SSM-Clock Stamp. All math and comparisons are plain ASCII and deterministic.

Pseudocode (copy-ready, ASCII)

# inputs
#   file_bytes
#   stamp_line = "SSMCLOCK1|iso_utc|rasi_idx|theta_deg|sha256(file)|chain[|kv:...]"
#   optional: ledger_rows[], anchor_note, observed_sidecar

defaults():
    return {"algo":"sha256","chain_algo":"sha256","theta_prec":"5","float":"ieee75464","time_mode":"derived_utc"}

select_hash(name):
    if name == "sha256":    return SHA256
    if name == "sha3_256":  return SHA3_256
    if name == "blake2b-256": return BLAKE2B_256
    FAIL("unsupported algo")

parse_stamp(line):
    parts = split(line, "|")
    if parts[0] != "SSMCLOCK1" or len(parts) not in {6,7}: FAIL("syntax")
    iso_utc   = parts[1]
    rasi_idx  = parts[2]
    theta_deg = parts[3]
    sha_field = parts[4]
    chain_hex = parts[5]
    kv = defaults()
    if len(parts) == 7:
        if not startswith(parts[6], "kv:"): FAIL("kv syntax")
        for kvpair in split(substr(parts[6],3), ";"):
            k,v = split_once(kvpair,"="); if k in kv: kv[k]=v else: continue  # ignore unknown keys
    # shape checks
    require matches(iso_utc, "YYYY-MM-DDTHH:MM:SSZ") and second != 60
    require int(rasi_idx) in [0..11]
    require decimal(theta_deg) in [0,360)
    require matches(sha_field, "[0-9a-f]{64}") and matches(chain_hex, "[0-9a-f]{64}")
    # kv domains
    require kv["algo"] in {"sha256","sha3_256","blake2b-256"}
    require kv["chain_algo"] in {"sha256","sha3_256","blake2b-256"}
    require int(kv["theta_prec"]) in {3,4,5,6,7,8,9}
    require kv["float"] == "ieee75464"
    require kv["time_mode"] in {"derived_utc","observed"}
    return {iso_utc,rasi_idx,theta_deg,sha_field,chain_hex,kv}

wrap360(x): return x - 360*floor(x/360)
angdiff(a,b): return ((a - b + 180.0) % 360.0) - 180.0  # not needed here, kept for parity

format_fixed(x, p):  # IEEE-754 binary64, round-half-to-even, '.' decimal
    return fixed_decimal_half_even(x, p)

clock_from_iso(iso_utc):
    unix_seconds = seconds_since_1970_UTC(iso_utc)  # UTC, no subseconds, no offsets
    theta = wrap360( (unix_seconds / 86400.0) * 360.0 )
    rasi  = floor(theta / 30.0)
    return theta, rasi

# main
S = parse_stamp(stamp_line)

# 1) HASH
Hf    = select_hash(S.kv["algo"])
hprim = hex_lower(Hf(file_bytes))
HASH_OK = (hprim == S.sha_field)

# 2) CLOCK
theta_prime, rasi_prime = clock_from_iso(S.iso_utc)
rasi_ok = (rasi_prime == int(S.rasi_idx))
p = int(S.kv["theta_prec"])
theta_fmt = format_fixed(theta_prime, p)
theta_ok  = (theta_fmt == S.theta_deg)  # prefer string equality
CLOCK_OK = (rasi_ok and theta_ok)

# 3) CHAIN (if ledger present)
if have(ledger_rows):
    tip = "0"*64
    CHAIN_OK = true
    for row in ledger_rows:   # in ledger order
        row_core = "SSMCLOCK1|" + row.iso_utc + "|" + row.rasi_idx + "|" + row.theta_deg + "|" + row.sha_field
        Hc = select_hash(row.kv.get("chain_algo","sha256"))
        tip = hex_lower(Hc( ascii(tip + "|" + row_core) ))
        if tip != row.chain_hex: CHAIN_OK = false; break
    if CHAIN_OK and not any(r.chain_hex == S.chain_hex for r in ledger_rows): CHAIN_OK = false
else:
    CHAIN_OK = "na"

# 4) ANCHOR (if note present)
if have(anchor_note):
    day = anchor_note.date  # "YYYY-MM-DD"
    day_lines = [L.full_line for L in collect_same_utc_day(day)]  # full stamp lines (with any kv)
    # build canonical sort keys
    keyed = []
    for line in day_lines:
        a = split(line,"|")
        stamp_core = "SSMCLOCK1|" + a[1] + "|" + a[2] + "|" + a[3] + "|" + a[4]
        key = (a[1], stamp_core, a[5])  # (iso_utc, stamp_core, chain)
        keyed.append((key,line))
    ordered = sort_by_key_ascii(keyed)
    joined  = join([line for key,line in ordered], "|")
    rollupD = hex_lower(SHA256(ascii(joined)))
    ANCHOR_OK = (rollupD == anchor_note.rollup_sha256) and (not anchor_note.count or len(day_lines)==anchor_note.count)
else:
    ANCHOR_OK = "na"

# 5) EVIDENCE (if observed-time sidecar present)
if have(observed_sidecar):
    iso_obs = observed_sidecar["obs_iso_utc"]
    tol     = int(observed_sidecar["tolerance_sec"])
    delta   = int(observed_sidecar["delta_sec"])
    # recompute delta
    delta2 = abs(seconds_since_1970_UTC(S.iso_utc) - seconds_since_1970_UTC(iso_obs))
    # canonical concat of sources: "label|ISO_Z" LF-joined, then sha256(ascii(...))
    concat = canonical_join_sources(observed_sidecar["obs_sources_ascii"])
    evid   = hex_lower(SHA256(ascii(concat)))
    EVIDENCE_OK = (delta2 <= tol) and (abs(delta2 - delta) <= 1) and (evid == observed_sidecar["obs_evidence_sha256"])
else:
    EVIDENCE_OK = "absent"

# 6) VERDICT
verdict = "PASS"
reason  = ""
if not HASH_OK:
    verdict, reason = "FAIL","HASH mismatch"
elif not CLOCK_OK:
    verdict, reason = "FAIL","CLOCK mismatch"
elif CHAIN_OK is False:
    verdict, reason = "FAIL","CHAIN rewalk failed"
elif ANCHOR_OK is False:
    verdict, reason = "FAIL","ANCHOR digest mismatch"
# optional policy: if time_mode=="observed" and evidence required -> enforce EVIDENCE_OK
print("HASH_OK="+str(HASH_OK), "CLOCK_OK="+str(CLOCK_OK),
      "CHAIN_OK="+str(CHAIN_OK), "ANCHOR_OK="+str(ANCHOR_OK),
      "EVIDENCE_OK="+str(EVIDENCE_OK), sep=" ")
print("VERDICT="+verdict)

Notes (determinism).

  • UTC only: iso_utc = "YYYY-MM-DDTHH:MM:SSZ"; reject :60.
  • Angle print: theta_deg uses exactly theta_prec digits with round-half-to-even; compare as strings.
  • Digests: lowercase 64-hex.
  • ASCII hashing inputs: use ascii("tip|stamp_core") and ascii("Stamp_1|...|Stamp_n") literally.
  • Anchor algo fixed: sha256 for rollup_D, regardless of per-stamp algo/chain_algo.

Why this helps. A reader can lift this pseudocode into any language and get identical PASS/FAIL results for the Shunyaya Symbolic Mathematical Clock Stamp.

Navigation
Back: SSM-Clock Stamp – Failure Mapping (4.4)
Next: SSM-Clock Stamp – Operational Playbook (4.6)