"""Generate the normative test vectors for the spec. Nonces are FIXED here so the vectors are reproducible. In production a nonce MUST be freshly generated from a CSPRNG per round per party (see new_nonce). """ import json from attestation import ( Chain, Policy, commitment, policy_hash, round_record, settle, settle_default, spread_bp, verify_reveal, ) P = Policy() NONCE_H = "a1" * 32 NONCE_I = "b2" * 32 cases = [ # name, holder $, inspector $, index $ or None ("TV-1 inside band, midpoint", 42000, 39000, None), ("TV-2 identical, bonus paid", 40000, 40000, None), ("TV-3 edge: exactly 1000 bp", 44000, 40000, None), ("TV-4 just outside band", 44100, 40000, 41500), ("TV-5 far apart, index clamped low", 90000, 30000, 20000), ("TV-6 inner band, bonus + cap", 41000, 40000, None), ("TV-7 low-value exemption", 4000, 3200, None), ("TV-8 non-reveal default", 38500, None, None), ] out = { "policy": { "values": { "tolerance_bp": P.tolerance_bp, "floor_cents": P.floor_cents, "absolute_floor_bp_exempt_cents": P.absolute_floor_bp_exempt_cents, "bonus_bp": P.bonus_bp, "bonus_inner_bp": P.bonus_inner_bp, "bonus_cap_cents": P.bonus_cap_cents, "late_reveal_penalty": P.late_reveal_penalty, "index_name": P.index_name, }, "policy_hash": policy_hash(P), }, "commitment_vector": {}, "settlement_vectors": [], "chain": {}, } # --- commitment vector ----------------------------------------------------- cv_args = dict( round_id="R-2026-08-0417", asset_id="SC-LT-000391", party_id="ACME-HOLDINGS", role="holder", amount_cents=42000, grade="B2", nonce_hex=NONCE_H, ) cv_hash = commitment(**cv_args) out["commitment_vector"] = { "input": cv_args, "commitment": cv_hash, "reveal_verifies": verify_reveal(cv_hash, {**cv_args, "nonce": NONCE_H}), "wrong_amount_rejected": not verify_reveal( cv_hash, {**cv_args, "amount_cents": 42001, "nonce": NONCE_H} ), "wrong_round_rejected": not verify_reveal( cv_hash, {**cv_args, "round_id": "R-2026-08-0418", "nonce": NONCE_H} ), "role_swap_rejected": not verify_reveal( cv_hash, {**cv_args, "role": "inspector", "nonce": NONCE_H} ), } # --- settlement vectors ---------------------------------------------------- for name, hc, ic, idx in cases: if ic is None: st = settle_default(hc, P) row = { "case": name, "holder_cents": hc, "inspector_cents": None, "index_cents": None, "spread_bp": None, **st.as_dict(), } else: st = settle(hc, ic, P, index_cents=idx) row = { "case": name, "holder_cents": hc, "inspector_cents": ic, "index_cents": idx, "spread_bp": spread_bp(hc, ic), **st.as_dict(), } out["settlement_vectors"].append(row) # --- chain vector ---------------------------------------------------------- chain = Chain() hr = { "round_id": "R-2026-08-0417", "asset_id": "SC-LT-000391", "party_id": "ACME-HOLDINGS", "role": "holder", "amount_cents": 42000, "grade": "B2", "nonce": NONCE_H, } ir = { "round_id": "R-2026-08-0417", "asset_id": "SC-LT-000391", "party_id": "SC-BENCH-04", "role": "inspector", "amount_cents": 39000, "grade": "B3", "nonce": NONCE_I, } hc_hash = commitment(**{k: v for k, v in hr.items() if k != "nonce"}, nonce_hex=NONCE_H) ic_hash = commitment(**{k: v for k, v in ir.items() if k != "nonce"}, nonce_hex=NONCE_I) st = settle(42000, 39000, P) rec = round_record( round_id="R-2026-08-0417", asset_id="SC-LT-000391", policy=P, holder_commit=hc_hash, inspector_commit=ic_hash, holder_reveal=hr, inspector_reveal=ir, settlement=st, timestamps={ "commit_opened": "2026-08-29T18:00:00Z", "commit_closed": "2026-09-01T18:00:00Z", "reveal_closed": "2026-09-02T18:00:00Z", "settled": "2026-09-02T18:04:11Z", }, ) e1 = chain.append({"type": "round_settled", "record": rec}) e2 = chain.append({"type": "placement", "asset_id": "SC-LT-000391", "tier": "C"}) out["chain"] = { "entry_0_hash": e1["entry_hash"], "entry_1_hash": e2["entry_hash"], "entry_1_prev": e2["prev"], "head": chain.head, "verifies": chain.verify(), } # tamper check chain.entries[0]["body"]["record"]["settlement"]["amount_cents"] = 41000 out["chain"]["detects_tamper"] = not chain.verify() print(json.dumps(out, indent=2))