#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Regression checks for the fail-closed release evidence gate.""" import copy import importlib.util import json from pathlib import Path from tempfile import TemporaryDirectory import unittest SCRIPT = Path(__file__).with_name("check-conformance.py") spec = importlib.util.spec_from_file_location("check_conformance", SCRIPT) gate = importlib.util.module_from_spec(spec) spec.loader.exec_module(gate) MANIFEST = json.loads(Path(__file__).with_name("conformance.json").read_text()) TARGETS = {(row["board"], row["chip"]): gate.REQUIRED_ALGORITHMS[row["chip"]] for row in MANIFEST["targets"]} class ConformanceGateTest(unittest.TestCase): def test_placeholder_matrix_cannot_pass_without_current_run_artifacts(self): manifest = copy.deepcopy(MANIFEST) for row in manifest["targets"]: row.update(sdk_image_sha256="0" * 64, stock_image_sha256="0" * 64, simulator_trace_sha256="0" * 64, stock_result="mines", alkane_share_accept_capture="does-not-exist.json", bench_validation="not-run") with TemporaryDirectory() as directory: errors = gate.validate(manifest, TARGETS, Path(directory), "123", "a" * 40, "b" * 64) self.assertEqual(len(errors), 64) self.assertTrue(all("evidence invalid" in error for error in errors)) def test_stale_source_identity_is_rejected(self): row = copy.deepcopy(MANIFEST["targets"][0]) row["stock_result"] = "mines" with TemporaryDirectory() as directory: root = Path(directory) report = root / "123" / row["board"] / f"{row['chip']}.json" report.parent.mkdir(parents=True) report.write_text(json.dumps({"schema": 1, "run_id": "123", "source_commit": "f" * 40, "os_binary_sha256": "b" * 64, "board": row["board"], "chip": row["chip"], "stock_firmware_modified": False})) with self.assertRaisesRegex(ValueError, "different run, source"): gate.verify_cell(row, root, "123", "a" * 40, "b" * 64, TARGETS[(row["board"], row["chip"])]) def test_share_accept_requires_real_difficulty_one_work(self): capture = {"nonce_source": "real_silicon_capture", "header80": "00" * 80, "pool_target_le": "ff" * 32, "nonce": 0, "submission": {"id": 4, "method": "mining.submit", "params": ["worker", "job", "", "00000000", "00000000"]}, "pool_response": {"id": 4, "result": True, "error": None}} with self.assertRaisesRegex(ValueError, "below difficulty one"): gate.verify_accept(capture, "Sha256") capture["submission"]["params"][4] = "00000001" with self.assertRaisesRegex(ValueError, "submitted nonce"): gate.verify_accept(capture, "Sha256") def test_non_sha256_cells_need_algorithm_specific_verifiers(self): with self.assertRaisesRegex(ValueError, "Scrypt share verifier"): gate.verify_accept({}, "Scrypt") with self.assertRaisesRegex(ValueError, "Equihash share verifier"): gate.verify_accept({}, "Equihash") if __name__ == "__main__": unittest.main()