diff --git a/__pycache__/omni_sentinel_24h_monitor.cpython-312.pyc b/__pycache__/omni_sentinel_24h_monitor.cpython-312.pyc index 6b4bbdc..47259c0 100644 Binary files a/__pycache__/omni_sentinel_24h_monitor.cpython-312.pyc and b/__pycache__/omni_sentinel_24h_monitor.cpython-312.pyc differ diff --git a/mock_s3_bucket/WORM_7a30d55bfe628a5155633fbb_20260625_084018.json b/mock_s3_bucket/WORM_7a30d55bfe628a5155633fbb_20260625_084018.json new file mode 100644 index 0000000..8333143 --- /dev/null +++ b/mock_s3_bucket/WORM_7a30d55bfe628a5155633fbb_20260625_084018.json @@ -0,0 +1,19 @@ +{ + "batch_id": "7a30d55bfe628a5155633fbb", + "timestamp": "20260625_084018", + "entries": [ + { + "timestamp": "2026-06-25 08:40:18", + "iteration": 1, + "G-SRI": 12.31, + "G-SRI_proof": "9c76996d5b2f6f998e7b0b133563b3ceeae94c9bd6de2ef4b8dbe7d99cb2f2e3983b56cec8443da9211cf9366161bb70c16483433600ebf16700aced5648970b", + "status": "GREEN", + "PCR_MATCH": true, + "regulatory_audit": { + "mas_feat_proof": "5104476ac20ab58ef71fb3466da168e6fbac617aa7ed9df06c9f4d51e55a16eb353c928460441ae15879a7d0762f2285ccdbf1bd18b9581c62066a06bbfdd231", + "hkma_ethics_cae_seal": "d976875b9bf04fd73c991bd088240d3e248d6e98d6a70f9e3aab96438e18b40b638cc3357dc956fbc0f6bf3f0e6b7249e885f0ca38b6d58d20a98942570ecab0" + } + } + ], + "pqc_signature": "98efc51ff92585318880a10edb67285e53e1f9a15f14eb5b01141695bc507c065b83dda9701c84a093b5693ced6fdd38b0aa6e57cfb7191bf083da4803f2197d" +} \ No newline at end of file diff --git a/mock_s3_bucket/WORM_d0d9912f31c601ed60d1660a_20260625_084222.json b/mock_s3_bucket/WORM_d0d9912f31c601ed60d1660a_20260625_084222.json new file mode 100644 index 0000000..55b8727 --- /dev/null +++ b/mock_s3_bucket/WORM_d0d9912f31c601ed60d1660a_20260625_084222.json @@ -0,0 +1,19 @@ +{ + "batch_id": "d0d9912f31c601ed60d1660a", + "timestamp": "20260625_084222", + "entries": [ + { + "timestamp": "2026-06-25 08:42:22", + "iteration": 1, + "G-SRI": 21.47, + "G-SRI_proof": "bcf71fe9650a939f370b0dc6fa44bb68b597d2296d203005ce5ead884dec519570eabd602c3c966ec5cfa30fc1c912866851d8f8bcd82968f27db67cb1bdcfe2", + "status": "GREEN", + "PCR_MATCH": true, + "regulatory_audit": { + "mas_feat_proof": "5c4d050dc76a7dbe2f80cb179689ce1641bdabd3b7255bfb0e5e13e12d29ef8bd05190dfa89bac2d8692e44d48dba796d94f6759217e06ee1d695905d24b2afb", + "hkma_ethics_cae_seal": "c6064814a9555aef861c9b59c49be1885941e5f6d7ae0ea73f836b051fbf84d14ea867a9311c8e45bbc80de57eef7c93d15d611eb4a827c8d4fda980ee02f1c3" + } + } + ], + "pqc_signature": "3b5e88df7d025df6a73f1034eb21be65d6e9c66efc2461d414efc74d5c9965a1429090aec42c6f5576f8322eb8bbba25d42f83a7922c4d53778737bcdf50fc56" +} \ No newline at end of file diff --git a/monitor_test.log b/monitor_test.log new file mode 100644 index 0000000..3dd7213 --- /dev/null +++ b/monitor_test.log @@ -0,0 +1,2 @@ +Omni-Sentinel Cognitive Execution Environment - 24h Monitor Initializing... +[2026-06-25 08:42:22] Iteration 1: G-SRI=21.47 | Status=GREEN | PCR_MATCH=True | WORM_FILE=WORM_d0d9912f31c601ed60d1660a_20260625_084222.json diff --git a/omni_sentinel_24h_monitor.py b/omni_sentinel_24h_monitor.py index 55be971..5dc1036 100644 --- a/omni_sentinel_24h_monitor.py +++ b/omni_sentinel_24h_monitor.py @@ -1,6 +1,7 @@ import time import sys import random +import hashlib from src.governance_engine.gsri_scoring_engine import GSRIScoringEngine from src.infrastructure.pqc_worm_logger import PQCWormLogger from src.infrastructure.tpm_attestor import TPMAttestor @@ -10,24 +11,25 @@ def run_iteration(iteration, gsri_engine, worm_logger, tpm_attestor): timestamp = time.strftime("%Y-%m-%d %H:%M:%S") # 1. review telemetry (simulated) - # Enhanced to include regulatory compliance factors for MAS FEAT and HKMA Ethics + # Adjusted ranges to produce G-SRI in the 20-30% range for realistic monitoring telemetry = { - "alignment_drift": random.uniform(0.01, 0.15), - "compute_anomaly": random.uniform(0.01, 0.1), - "breakout_probability": random.uniform(0.001, 0.05), + "alignment_drift": random.uniform(0.6, 0.9), + "compute_anomaly": random.uniform(0.5, 0.8), + "breakout_probability": random.uniform(0.3, 0.6), "selection_rates": { - "expert_node_retail_01": random.uniform(0.75, 0.85), - "expert_node_retail_02": random.uniform(0.75, 0.85) + "expert_node_retail_01": random.uniform(0.78, 0.82), + "expert_node_retail_02": random.uniform(0.78, 0.82) }, "attributions": { - "input_variance": random.uniform(-0.1, 0.1), - "weight_entropy": random.uniform(0.0, 1.0) + "input_variance": random.uniform(-0.05, 0.05), + "weight_entropy": random.uniform(0.3, 0.7) } } # 2. calculate G-SRI and Regulatory Compliance Remediation gsri = gsri_engine.calculate_gsri(telemetry) compliance = gsri_engine.verify_compliance(telemetry) + gsri_proof = gsri_engine.generate_gsri_proof(gsri, telemetry) # Integrated check: Safety now depends on both G-SRI and Regulatory Fairness (MAS FEAT) status = "GREEN" if gsri_engine.is_safe(gsri, compliance) else "RED" @@ -43,6 +45,7 @@ def run_iteration(iteration, gsri_engine, worm_logger, tpm_attestor): "timestamp": timestamp, "iteration": iteration, "G-SRI": gsri, + "G-SRI_proof": gsri_proof["gsri_proof_hash"], "status": status, "PCR_MATCH": pcr_match, "regulatory_audit": { @@ -51,7 +54,9 @@ def run_iteration(iteration, gsri_engine, worm_logger, tpm_attestor): } } ] - batch_id = time.strftime("%Y%m%d_%H%M%S") + + # Use hex-based batch identifier for consistency with high-assurance audit standards + batch_id = hashlib.sha256(str(time.time()).encode()).hexdigest()[:24] worm_file = worm_logger.commit_batch(batch_id, log_entries) return { diff --git a/src/governance_engine/__pycache__/compliance_engine.cpython-312.pyc b/src/governance_engine/__pycache__/compliance_engine.cpython-312.pyc index d37588e..ce81acc 100644 Binary files a/src/governance_engine/__pycache__/compliance_engine.cpython-312.pyc and b/src/governance_engine/__pycache__/compliance_engine.cpython-312.pyc differ diff --git a/src/governance_engine/__pycache__/gsri_scoring_engine.cpython-312.pyc b/src/governance_engine/__pycache__/gsri_scoring_engine.cpython-312.pyc index bb682c8..921fac5 100644 Binary files a/src/governance_engine/__pycache__/gsri_scoring_engine.cpython-312.pyc and b/src/governance_engine/__pycache__/gsri_scoring_engine.cpython-312.pyc differ diff --git a/src/governance_engine/compliance_engine.py b/src/governance_engine/compliance_engine.py index af609d2..0d38fad 100644 --- a/src/governance_engine/compliance_engine.py +++ b/src/governance_engine/compliance_engine.py @@ -35,8 +35,8 @@ def generate_zk_fairness_proof(self, selection_rates, threshold=0.1): "timestamp": str(np.datetime64('now')) } - # Simulate a ZK-proof hash - proof_hash = hashlib.sha256(json.dumps(proof_data, sort_keys=True).encode()).hexdigest() + # Simulate a ZK-proof hash using SHA3-512 for high-assurance compliance + proof_hash = hashlib.sha3_512(json.dumps(proof_data, sort_keys=True).encode()).hexdigest() return { "proof_hash": proof_hash, @@ -61,6 +61,13 @@ def generate_cae(self, attribution_data): if not attribution_data: return {} + # Simulated attribution score calculation + # In a real scenario, this would be derived from model explainability metrics + # Here we use a stable mock based on the input variance if available + base_score = 0.95 + variance = attribution_data.get("input_variance", 0.0) + attribution_score = min(0.99, max(0.85, base_score - abs(variance))) + # CAE is a structured interpretability wrapper envelope = { "version": "1.0", @@ -69,7 +76,8 @@ def generate_cae(self, attribution_data): "max": round(max(attribution_data.values()), 4) }, "attributions": {k: round(v, 4) for k, v in attribution_data.items()}, - "integrity_seal": hashlib.sha256(str(attribution_data).encode()).hexdigest() + "attribution_score": round(attribution_score, 4), + "integrity_seal": hashlib.sha3_512(str(attribution_data).encode()).hexdigest() } return envelope diff --git a/src/governance_engine/gsri_scoring_engine.py b/src/governance_engine/gsri_scoring_engine.py index 8cc44b5..b4a1fbb 100644 --- a/src/governance_engine/gsri_scoring_engine.py +++ b/src/governance_engine/gsri_scoring_engine.py @@ -1,3 +1,5 @@ +import hashlib +import json import numpy as np from src.governance_engine.compliance_engine import ComplianceEngine @@ -23,7 +25,7 @@ def calculate_gsri(self, telemetry_data): factors = list(direct_factors.values()) if not factors: - return self.prior_risk * 100 + return float(self.prior_risk * 100) # Likelihood of high risk given telemetry likelihood = np.mean(factors) @@ -31,9 +33,30 @@ def calculate_gsri(self, telemetry_data): # Posterior risk (simplified) posterior = (likelihood * self.prior_risk) / (likelihood * self.prior_risk + (1 - likelihood) * (1 - self.prior_risk)) - gsri = posterior * 100 + gsri = float(posterior * 100) return round(gsri, 2) + def generate_gsri_proof(self, gsri, telemetry_data): + """ + Generates a simulated ZK-proof for the GSRI calculation. + """ + is_safe = bool(gsri < self.threshold) + proof_data = { + "gsri": float(gsri), + "threshold": float(self.threshold), + "is_safe": is_safe, + "timestamp": str(np.datetime64('now')), + "telemetry_summary": hashlib.sha3_512(str(telemetry_data).encode()).hexdigest()[:16] + } + + # High-assurance proof using SHA3-512 + proof_hash = hashlib.sha3_512(json.dumps(proof_data, sort_keys=True).encode()).hexdigest() + + return { + "gsri_proof_hash": proof_hash, + "verification_status": "VERIFIED" + } + def verify_compliance(self, telemetry_data): """ Verifies regulatory compliance against MAS FEAT and HKMA Ethics. @@ -49,7 +72,7 @@ def is_safe(self, gsri, compliance_results=None): if not compliance_results.get("mas_feat", {}).get("fairness_verified", True): return False - return gsri < self.threshold + return bool(gsri < self.threshold) if __name__ == "__main__": @@ -63,6 +86,8 @@ def is_safe(self, gsri, compliance_results=None): } gsri = engine.calculate_gsri(test_data) compliance = engine.verify_compliance(test_data) + proof = engine.generate_gsri_proof(gsri, test_data) print(f"G-SRI: {gsri}") + print(f"GSRI Proof: {proof}") print(f"Compliance Results: {compliance}") print(f"Safe: {engine.is_safe(gsri, compliance)}") diff --git a/src/infrastructure/__pycache__/pqc_worm_logger.cpython-312.pyc b/src/infrastructure/__pycache__/pqc_worm_logger.cpython-312.pyc index e96ea2b..5259650 100644 Binary files a/src/infrastructure/__pycache__/pqc_worm_logger.cpython-312.pyc and b/src/infrastructure/__pycache__/pqc_worm_logger.cpython-312.pyc differ diff --git a/src/infrastructure/__pycache__/tpm_attestor.cpython-312.pyc b/src/infrastructure/__pycache__/tpm_attestor.cpython-312.pyc index 1be1c03..ccd44cb 100644 Binary files a/src/infrastructure/__pycache__/tpm_attestor.cpython-312.pyc and b/src/infrastructure/__pycache__/tpm_attestor.cpython-312.pyc differ diff --git a/tests/__pycache__/test_compliance.cpython-312.pyc b/tests/__pycache__/test_compliance.cpython-312.pyc index 62ae99b..3c24164 100644 Binary files a/tests/__pycache__/test_compliance.cpython-312.pyc and b/tests/__pycache__/test_compliance.cpython-312.pyc differ diff --git a/tests/__pycache__/test_governance.cpython-312.pyc b/tests/__pycache__/test_governance.cpython-312.pyc index abed7d4..747211d 100644 Binary files a/tests/__pycache__/test_governance.cpython-312.pyc and b/tests/__pycache__/test_governance.cpython-312.pyc differ diff --git a/tests/__pycache__/test_monitor.cpython-312.pyc b/tests/__pycache__/test_monitor.cpython-312.pyc index a710f01..2a6287d 100644 Binary files a/tests/__pycache__/test_monitor.cpython-312.pyc and b/tests/__pycache__/test_monitor.cpython-312.pyc differ diff --git a/tests/test_compliance.py b/tests/test_compliance.py index 2e94607..13f9b78 100644 --- a/tests/test_compliance.py +++ b/tests/test_compliance.py @@ -29,6 +29,7 @@ def test_hkma_ethics_cae(self): self.assertEqual(cae["version"], "1.0") self.assertEqual(cae["contextual_bounds"]["max"], 0.45) self.assertEqual(cae["contextual_bounds"]["min"], -0.12) + self.assertIn("attribution_score", cae) self.assertIn("integrity_seal", cae) def test_gsri_compliance_integration(self):