#!/usr/bin/env python3 """Reproducible graph identity and modulo-8 example; no website write. Place beside the unchanged omega_joint_witness_v2.py; requires SymPy. This exports a test fixture, not a complete network record protocol. """ import contextlib import hashlib import io import json from pathlib import Path import omega_joint_witness_v2 as core def main(): trace = io.StringIO() with contextlib.redirect_stdout(trace): vertices, neighbors = core.build_graph() inverse, denominator = core.inverse_certificate(neighbors) graph = { 'schema': 'OMEGA_600CELL_GRAPH_FIXTURE/1', 'coordinate_rule': 'vertex coordinate is (a+b*phi)/2 for pair [a,b]', 'vertex_order': 'Python lexicographic order of tuples of four integer pairs', 'vertices': vertices, 'neighbors': neighbors, } graph_bytes = (json.dumps(graph, ensure_ascii=True, sort_keys=True, separators=(',', ':'))+'\n').encode('ascii') graph_digest = hashlib.sha256(graph_bytes).hexdigest() predecessor = tuple(range(120)) output, remainder = core.full_step(predecessor, neighbors) wire = core.encode_joint_bytes(predecessor) stats = {} recovered = core.joint_decode(output, tuple(a % 8 for a in predecessor), neighbors, inverse, denominator, nonnegative=True, stats=stats, use_proposal=False, try_nearest=False) if recovered != predecessor or len(wire) != 45: raise RuntimeError('exact-only fixture recovery failed') if int.from_bytes(wire, 'little') != sum((a % 8) << (3*i) for i, a in enumerate(predecessor)): raise RuntimeError('wire convention failed') if any(core.Q*z != core.D*y+r for z, y, r in zip(core.m_apply(predecessor, neighbors), output, remainder)): raise RuntimeError('full remainder identity failed') bad_payloads = [b'', bytes(44), bytes(46)] for payload in bad_payloads: try: core.decode_joint_bytes(output, payload, neighbors, inverse, denominator) except ValueError: pass else: raise RuntimeError('wrong witness length accepted') fixture = { 'schema': 'OMEGA_600CELL_MOD8_TEST_VECTOR/1', 'graph_sha256': graph_digest, 'core_source_sha256': hashlib.sha256(Path(core.__file__).read_bytes()).hexdigest(), 'Q': str(core.Q), 'S': str(core.S), 'D': str(core.D), 'state_domain': 'nonnegative integer vector of length 120', 'predecessor': [str(a) for a in predecessor], 'output': [str(a) for a in output], 'residues_mod8': [a % 8 for a in predecessor], 'witness_hex': wire.hex(), 'witness_bytes': len(wire), 'witness_endianness': 'little', 'decoder_path': 'exact propagation/search; nearest and MILP disabled', 'exact_search_statistics': stats, 'malformed_length_cases_rejected': len(bad_payloads), 'status': 'PASS', } Path('graph-fixture.json').write_bytes(graph_bytes) Path('joint-witness-test-vector.json').write_text( json.dumps(fixture, indent=2)+'\n', encoding='utf-8') print(json.dumps({'status': 'PASS', 'graph_sha256': graph_digest, 'witness_hex': wire.hex(), 'exact_search': stats, 'invalid_lengths_rejected': len(bad_payloads)}, indent=2)) if __name__ == '__main__': main()