OpenIslet

scripts/verify_iip0042_master_multilayer_portfolio_crosswalk.py

IIP-0042 / DEC-121 (CAND-033 / EXP-030): Master Exact 2^20 Multi-Layer Portfolio

script Release v0.8.0 gen-eb955f8266035aba 881 KB · 63 sections

Use this file in any AI chat (paste-only or attachment-capable):

Download as text (.txt) Download section (.txt)

Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0042_master_multilayer_portfolio_crosswalk.py · SHA-256: 16964a158458b5cf…

            f"(embedded={existing_receipt['portable_payload_sha256']}, fresh={fresh_portable_sha})"
        )
    return fresh_portable_sha


def main() -> None:
    parser = argparse.ArgumentParser(
        description="EXP-030 / IIP-0042 Master Exact 2^20 Portfolio & Crosswalk Verifier (Fail-Closed)"
    )
    parser.add_argument("--repo-root", default=None, help="Path to read-only OpenIslet repo")
    mode_group = parser.add_mutually_exclusive_group()
    mode_group.add_argument(
        "--standalone",
        action="store_true",
        help="Verify exact 2^20 engine + pinned live IIP-0035 parity only (mutually exclusive with --cross-track-dir)",
    )
    mode_group.add_argument(
        "--cross-track-dir",
        default=None,
        help="Directory containing EXP-028 and archived EXP-029 folders (mutually exclusive with --standalone)",
    )
    pin_group = parser.add_mutually_exclusive_group()
    pin_group.add_argument(
        "--expected-shipped-sha256",
        default=None,
        help="Optional explicit SHA-256 digest override for live shipped IIP-0035 portfolio fixture (defaults to canonical pinned 31320c0e...)",
    )
    pin_group.add_argument(
        "--allow-unpinned-diagnostic",
        action="store_true",
        help="Explicit diagnostic opt-in permitting unpinned IIP-0035 fixture bytes (disabled by default; fail-closed otherwise)",
    )
    parser.add_argument(
        "--expected-exp028-sha256",
        default=None,
        help="Optional pinned SHA-256 digest for EXP-028 verification receipt (verified before parity)",
    )
    parser.add_argument(
        "--expected-exp029-sha256",
        default=None,
        help="Optional pinned SHA-256 digest for archived EXP-029 verification receipt (verified before parity)",
    )
    parser.add_argument(
        "--out",
        default=None,
        help="Optional output receipt path (defaults to data/extracted/iip0042_master_multilayer_portfolio_crosswalk_v0.8.0.json)",
    )
    parser.add_argument(
        "--check-portable",
        action="store_true",
        help=(
            "Read-only cross-build verification mode: compares freshly computed receipt against --out "
            "(defaulting to the installed receipt) ignoring ONLY runtime_environment.python_version "
            "(verifying exact portable_payload_sha256 and full semantic equality across CPython builds) "
            "without writing."
        ),
    )
    args = parser.parse_args()

    if args.standalone and (args.expected_exp028_sha256 or args.expected_exp029_sha256):
        parser.error("--expected-exp028-sha256 and --expected-exp029-sha256 cannot be combined with --standalone")

    openislet_root = resolve_openislet_root(args.repo_root)
    ct_dir = Path(args.cross_track_dir) if args.cross_track_dir else None
    if args.out:
        out_path = Path(args.out).expanduser().resolve()
    elif args.check_portable and args.repo_root is not None:
        out_path = openislet_root / "data" / "extracted" / "iip0042_master_multilayer_portfolio_crosswalk_v0.8.0.json"
    else:
        out_path = RECEIPT_PATH

    receipt = run_all(
        openislet_root,
        standalone=args.standalone,
        cross_track_dir=ct_dir,
        expected_shipped_sha256=args.expected_shipped_sha256,
        expected_exp028_sha256=args.expected_exp028_sha256,
        expected_exp029_sha256=args.expected_exp029_sha256,
        allow_unpinned_diagnostic=args.allow_unpinned_diagnostic,
    )
    # Run full authenticated public manifest inventory + Wave-5 4-class Gate 30-TOS-QUARANTINE scan (no double-counting!)
    extra_texts: dict[str, str] = {}
    if ART_DIR.name == "artifacts-carbon":
        extra_texts[Path(__file__).name] = Path(__file__).read_text(encoding="utf-8")
        for pub_path in (
            ART_DIR / "exp030_iip0043_side_contract.json",
            ART_DIR / "GATE-30-PORTFOLIO-AND-TRACKB-CONTINGENCY-PROTOCOL.md",
            ART_DIR.parent / "confirmation-carbon-2026-11-28.md",
            INV_ROOT / "candidate-proposals" / "CAND-033-finite-host-reset-and-unified-multilayer-portfolio-carbon.md",
        ):
            if not pub_path.is_file():
                raise FileNotFoundError(f"Gate 30-TOS-QUARANTINE: missing required staging public document {pub_path.name}")
            txt = pub_path.read_text(encoding="utf-8")
            if pub_path.suffix == ".md":
                txt = mask_canonical_layer2_disclaimer_only(txt)
            extra_texts[pub_path.name] = txt

    quarantine_audit = verify_gate30_tos_quarantine_full_inventory(
        openislet_root,
        extra_wave5_texts=extra_texts if extra_texts else None,
    )
    portable_quarantine_audit = dict(quarantine_audit)
    portable_quarantine_audit["inventory_source"] = "manifest_json_verified"
    portable_quarantine_audit["manifest_scan_mode"] = "PUBLIC_ALLOWLIST_MANIFEST"
    portable_quarantine_audit["public_disk_membership_scope"] = "PUBLIC_BUNDLE_ROOT_OR_ALLOWLIST_TREE_VERIFIED"
    portable_quarantine_audit.pop("manifest_file_sha256", None)
    portable_quarantine_audit["manifest_file_sha256_scope"] = (
        "OMITTED_FROM_PORTABLE_RECEIPT_TO_AVOID_MANIFEST_SELF_HASH_CYCLE; "
        "returned directly by verify_gate30_tos_quarantine_full_inventory()"
    )
    receipt["gate30_tos_quarantine_audit"] = portable_quarantine_audit
    receipt["portable_payload_sha256"] = compute_portable_payload_sha256(receipt)
    out_str = json.dumps(receipt, indent=2, ensure_ascii=False, allow_nan=False) + "\n"
    assert_public_hygiene_clean(out_str, out_path.name)

    if args.check_portable:
        fresh_portable_sha = verify_portable_receipt_file(out_path, receipt)
        print(
            f"PASS (--check-portable cross-build semantic match ignoring runtime_environment.python_version): "
            f"receipt={out_path.name} portable_payload_sha256={fresh_portable_sha} "
            f"py={sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]} (optimize={sys.flags.optimize})"
        )
        return

    out_path.write_text(out_str, encoding="utf-8")

    p = receipt["parity_verification"]
    if args.standalone:
        print(
            f"=== STANDALONE PARITY PASS: 24/24 LIVE IIP-0035 EXACT (4-dp display) | "
            f"L0-raw-err={p['l0_live_unrounded_max_abs_err']:.2e} | "
            f"4096-err={p['l1_phi25_4096_state_max_abs_err']:.2e} | py={sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]} ==="
        )
    else:
        p29 = p["exp029_parked_archive_cross_track_parity"]
        raw29_str = f"{p29['raw_unrounded_max_abs_err']:.2e}" if p29["raw_unrounded_max_abs_err"] is not None else "N/A"
        print(
            f"=== FULL CROSS-TRACK PARITY PASS: 24/24 SHIPPED EXACT (4-dp display) | "
            f"L0-raw-err={p['l0_live_unrounded_max_abs_err']:.2e} | "
            f"4096-err={p['l1_phi25_4096_state_max_abs_err']:.2e} | "
            f"EXP-028 verified={p['exp028_cross_track_parity']['verified']} err={p['exp028_cross_track_parity']['unrounded_max_abs_err']:.2e} | "
            f"EXP-029(parked) verified={p29['verified']} raw_err={raw29_str} disp4dp_diff={p29['display_4dp_max_abs_diff']:.2e} | "
            f"py={sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]} ==="
        )
    cb = receipt["checkerboard_mass_transfer_stress_test"]["parked_r3b_L4_AE_phi25"]
    print(
        f"=== CHECKERBOARD (0.003) L4-AE phi=0.25: indep={cb['independent_delta_vs_baseline_pp']:+.4f} pp -> "
        f"coupled={cb['coupled_delta_vs_baseline_pp']:+.4f} pp (flips_negative={cb['flips_sign_negative']}) ==="
    )
    elig_row = next(
        r for r in receipt["policy_option1_trackb_eligibility_corrected_ev"]["legacy_parked_r3b_comparator_eligibility_audit"]
        if r["p_shield1_pass"] == 0.30 and r["p_cocktail_pass_trackb_ineligible_zero_credit"] == 0.12
    )
    print(
        f"=== ELIGIBILITY CHECK (p_S1=0.30, p_cock=0.12, P_XREACT=1.00): "
        f"gross={elig_row['ev_conditional_on_xreact_pass_1p0_upside_phi25_pp']:+.4f} pp | "
        f"AE={elig_row['ev_conditional_on_xreact_pass_1p0_AE_phi25_pp']:+.4f} pp ==="
    )
    sha = hashlib.sha256(out_path.read_bytes()).hexdigest()
    print(f"Wrote {out_path.name} (SHA-256: {sha})")


if __name__ == "__main__":
    main()