Spaces:
Running
Running
Pin Brain formula evidence and verify SHA-256
#7
by betterwithage - opened
- static/3d/brain.html +6 -5
- szl3d_holographic.py +25 -2
- test/test_holographic_zero_cdn.py +28 -2
static/3d/brain.html
CHANGED
|
@@ -12,8 +12,8 @@
|
|
| 12 |
server performs fixed-allowlist, read-only, timeout + byte-bounded public reads:
|
| 13 |
· Models / Datasets / Spaces / Collections — Hugging Face Hub API (SZLHOLDINGS)
|
| 14 |
· Repositories — GitHub REST API (org szl-holdings)
|
| 15 |
-
· Proved formulas —
|
| 16 |
-
|
| 17 |
· Fleet vitals — live /healthz probes of the organ Spaces (a11oy · killinchu ·
|
| 18 |
anatomy · amaru · sentra), each answer is that organ's own, right now.
|
| 19 |
· Open frontier — live Hub counts of the open-weights orgs the a11oy backbone
|
|
@@ -196,13 +196,14 @@ function countText(lobe) {
|
|
| 196 |
const LOBES = [
|
| 197 |
{
|
| 198 |
key: "formulas", name: "Frontal — proved formulas", color: COL.formulas,
|
| 199 |
-
dir: [0, 0.55, 0.95], url: "https://github.com/" + GH_ORG + "/a11oy/blob/
|
| 200 |
fetchStat: async () => {
|
| 201 |
const s = requireLive(await EVIDENCE, "formulas");
|
| 202 |
const n = s.theorem_count;
|
| 203 |
return { text: n + " theorems", honesty: "MEASURED",
|
| 204 |
-
caption: "Frontal lobe · " + n + " `theorem` declarations counted server-side from
|
| 205 |
-
"ProvedFormulas.lean
|
|
|
|
| 206 |
},
|
| 207 |
},
|
| 208 |
{
|
|
|
|
| 12 |
server performs fixed-allowlist, read-only, timeout + byte-bounded public reads:
|
| 13 |
· Models / Datasets / Spaces / Collections — Hugging Face Hub API (SZLHOLDINGS)
|
| 14 |
· Repositories — GitHub REST API (org szl-holdings)
|
| 15 |
+
· Proved formulas — a commit-pinned ProvedFormulas.lean artifact, fetched
|
| 16 |
+
server-side, SHA-256 verified, then counted for `theorem` declarations.
|
| 17 |
· Fleet vitals — live /healthz probes of the organ Spaces (a11oy · killinchu ·
|
| 18 |
anatomy · amaru · sentra), each answer is that organ's own, right now.
|
| 19 |
· Open frontier — live Hub counts of the open-weights orgs the a11oy backbone
|
|
|
|
| 196 |
const LOBES = [
|
| 197 |
{
|
| 198 |
key: "formulas", name: "Frontal — proved formulas", color: COL.formulas,
|
| 199 |
+
dir: [0, 0.55, 0.95], url: "https://github.com/" + GH_ORG + "/a11oy/blob/22b084d4a74abb4d5911ca9dc303c35d222bd284/proofs/lutar-lean/Lutar/Puriq/Formulas/ProvedFormulas.lean",
|
| 200 |
fetchStat: async () => {
|
| 201 |
const s = requireLive(await EVIDENCE, "formulas");
|
| 202 |
const n = s.theorem_count;
|
| 203 |
return { text: n + " theorems", honesty: "MEASURED",
|
| 204 |
+
caption: "Frontal lobe · " + n + " `theorem` declarations counted server-side from a commit-pinned " +
|
| 205 |
+
"ProvedFormulas.lean artifact · SHA-256 " + s.content_sha256.slice(0, 12) + "… VERIFIED · " +
|
| 206 |
+
"MEASURED via same-origin bounded evidence route · click to read the pinned proofs" };
|
| 207 |
},
|
| 208 |
},
|
| 209 |
{
|
szl3d_holographic.py
CHANGED
|
@@ -26,6 +26,7 @@ Mirrors the existing in-image static-serve pattern (serve.py /static/shared/{fna
|
|
| 26 |
from __future__ import annotations
|
| 27 |
|
| 28 |
import asyncio
|
|
|
|
| 29 |
import json
|
| 30 |
import os
|
| 31 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
@@ -251,8 +252,14 @@ def no_cdn_violations(base: Path):
|
|
| 251 |
_BRAIN_PAGE_CAP = 100
|
| 252 |
_BRAIN_TIMEOUT_S = 4.0
|
| 253 |
_BRAIN_MAX_BYTES = 5 * 1024 * 1024
|
|
|
|
|
|
|
|
|
|
| 254 |
_BRAIN_SOURCES: Dict[str, str] = {
|
| 255 |
-
"formulas":
|
|
|
|
|
|
|
|
|
|
| 256 |
"models": "https://huggingface.co/api/models?author=SZLHOLDINGS&limit=100&full=false",
|
| 257 |
"datasets": "https://huggingface.co/api/datasets?author=SZLHOLDINGS&limit=100&full=false",
|
| 258 |
"spaces": "https://huggingface.co/api/spaces?author=SZLHOLDINGS&limit=100&full=false",
|
|
@@ -301,6 +308,8 @@ def _brain_health(url: str) -> Dict[str, Any]:
|
|
| 301 |
|
| 302 |
|
| 303 |
def _brain_error(exc: BaseException) -> str:
|
|
|
|
|
|
|
| 304 |
if isinstance(exc, HTTPError):
|
| 305 |
return f"upstream_http_{exc.code}"
|
| 306 |
if isinstance(exc, (TimeoutError, OSError)):
|
|
@@ -338,6 +347,7 @@ def brain_evidence(
|
|
| 338 |
fetch_json: Callable[[str], Any] = _brain_json,
|
| 339 |
fetch_text: Callable[[str], str] = _brain_text,
|
| 340 |
fetch_health: Callable[[str], Dict[str, Any]] = _brain_health,
|
|
|
|
| 341 |
) -> Dict[str, Any]:
|
| 342 |
"""Build one honest Brain observation from fixed public sources.
|
| 343 |
|
|
@@ -371,10 +381,21 @@ def brain_evidence(
|
|
| 371 |
if "formulas" in errors:
|
| 372 |
raise errors["formulas"]
|
| 373 |
source = raw["formulas"]
|
|
|
|
|
|
|
|
|
|
| 374 |
theorem_count = len(_re.findall(r"(^|\n)\s*theorem\s", source))
|
| 375 |
lobes["formulas"] = {
|
| 376 |
"state": "LIVE", "data_label": "MEASURED",
|
| 377 |
-
"source_url": _BRAIN_SOURCES["formulas"],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
}
|
| 379 |
except BaseException as exc:
|
| 380 |
lobes["formulas"] = _unavailable(_BRAIN_SOURCES["formulas"], exc)
|
|
@@ -456,6 +477,8 @@ def brain_evidence(
|
|
| 456 |
"read_only": True, "same_origin_browser_read": True,
|
| 457 |
"fixed_allowlist": True, "timeout_seconds_per_source": _BRAIN_TIMEOUT_S,
|
| 458 |
"response_byte_cap": _BRAIN_MAX_BYTES, "page_cap": _BRAIN_PAGE_CAP,
|
|
|
|
|
|
|
| 459 |
"cache_or_last_good_fallback": False,
|
| 460 |
"note": "Every request is a fresh bounded observation. Missing sources remain UNAVAILABLE.",
|
| 461 |
},
|
|
|
|
| 26 |
from __future__ import annotations
|
| 27 |
|
| 28 |
import asyncio
|
| 29 |
+
import hashlib
|
| 30 |
import json
|
| 31 |
import os
|
| 32 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
|
|
| 252 |
_BRAIN_PAGE_CAP = 100
|
| 253 |
_BRAIN_TIMEOUT_S = 4.0
|
| 254 |
_BRAIN_MAX_BYTES = 5 * 1024 * 1024
|
| 255 |
+
_BRAIN_FORMULA_COMMIT = "22b084d4a74abb4d5911ca9dc303c35d222bd284"
|
| 256 |
+
_BRAIN_FORMULA_PATH = "proofs/lutar-lean/Lutar/Puriq/Formulas/ProvedFormulas.lean"
|
| 257 |
+
_BRAIN_FORMULA_SHA256 = "847d2e332017a5bfe3e7823092acf0245840f6b20f3d6f1544f723fd1607612e"
|
| 258 |
_BRAIN_SOURCES: Dict[str, str] = {
|
| 259 |
+
"formulas": (
|
| 260 |
+
"https://raw.githubusercontent.com/szl-holdings/a11oy/"
|
| 261 |
+
f"{_BRAIN_FORMULA_COMMIT}/{_BRAIN_FORMULA_PATH}"
|
| 262 |
+
),
|
| 263 |
"models": "https://huggingface.co/api/models?author=SZLHOLDINGS&limit=100&full=false",
|
| 264 |
"datasets": "https://huggingface.co/api/datasets?author=SZLHOLDINGS&limit=100&full=false",
|
| 265 |
"spaces": "https://huggingface.co/api/spaces?author=SZLHOLDINGS&limit=100&full=false",
|
|
|
|
| 308 |
|
| 309 |
|
| 310 |
def _brain_error(exc: BaseException) -> str:
|
| 311 |
+
if isinstance(exc, ValueError) and str(exc) == "source_integrity_mismatch":
|
| 312 |
+
return "source_integrity_mismatch"
|
| 313 |
if isinstance(exc, HTTPError):
|
| 314 |
return f"upstream_http_{exc.code}"
|
| 315 |
if isinstance(exc, (TimeoutError, OSError)):
|
|
|
|
| 347 |
fetch_json: Callable[[str], Any] = _brain_json,
|
| 348 |
fetch_text: Callable[[str], str] = _brain_text,
|
| 349 |
fetch_health: Callable[[str], Dict[str, Any]] = _brain_health,
|
| 350 |
+
expected_formula_sha256: str = _BRAIN_FORMULA_SHA256,
|
| 351 |
) -> Dict[str, Any]:
|
| 352 |
"""Build one honest Brain observation from fixed public sources.
|
| 353 |
|
|
|
|
| 381 |
if "formulas" in errors:
|
| 382 |
raise errors["formulas"]
|
| 383 |
source = raw["formulas"]
|
| 384 |
+
content_sha256 = hashlib.sha256(source.encode("utf-8")).hexdigest()
|
| 385 |
+
if content_sha256 != expected_formula_sha256:
|
| 386 |
+
raise ValueError("source_integrity_mismatch")
|
| 387 |
theorem_count = len(_re.findall(r"(^|\n)\s*theorem\s", source))
|
| 388 |
lobes["formulas"] = {
|
| 389 |
"state": "LIVE", "data_label": "MEASURED",
|
| 390 |
+
"source_url": _BRAIN_SOURCES["formulas"],
|
| 391 |
+
"source_repository": "szl-holdings/a11oy",
|
| 392 |
+
"source_path": _BRAIN_FORMULA_PATH,
|
| 393 |
+
"source_commit": _BRAIN_FORMULA_COMMIT,
|
| 394 |
+
"mutable_reference": False,
|
| 395 |
+
"theorem_count": theorem_count,
|
| 396 |
+
"content_sha256": content_sha256,
|
| 397 |
+
"expected_content_sha256": expected_formula_sha256,
|
| 398 |
+
"integrity_state": "VERIFIED",
|
| 399 |
}
|
| 400 |
except BaseException as exc:
|
| 401 |
lobes["formulas"] = _unavailable(_BRAIN_SOURCES["formulas"], exc)
|
|
|
|
| 477 |
"read_only": True, "same_origin_browser_read": True,
|
| 478 |
"fixed_allowlist": True, "timeout_seconds_per_source": _BRAIN_TIMEOUT_S,
|
| 479 |
"response_byte_cap": _BRAIN_MAX_BYTES, "page_cap": _BRAIN_PAGE_CAP,
|
| 480 |
+
"formula_source_commit_pinned": True,
|
| 481 |
+
"formula_content_sha256_verified": True,
|
| 482 |
"cache_or_last_good_fallback": False,
|
| 483 |
"note": "Every request is a fresh bounded observation. Missing sources remain UNAVAILABLE.",
|
| 484 |
},
|
test/test_holographic_zero_cdn.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
"""Zero-CDN and honest same-origin evidence contract regressions."""
|
| 2 |
from __future__ import annotations
|
| 3 |
|
|
|
|
| 4 |
import unittest
|
| 5 |
from pathlib import Path
|
| 6 |
from unittest.mock import patch
|
|
@@ -39,14 +40,18 @@ class HolographicZeroCdnTests(unittest.TestCase):
|
|
| 39 |
self.assertNotIn("fetch('https://", brain)
|
| 40 |
|
| 41 |
def test_complete_observation_is_live_and_measured(self):
|
|
|
|
| 42 |
payload = holographic.brain_evidence(
|
| 43 |
fetch_json=self._json,
|
| 44 |
-
fetch_text=lambda _url:
|
| 45 |
fetch_health=self._health,
|
|
|
|
| 46 |
)
|
| 47 |
self.assertEqual(payload["state"], "LIVE")
|
| 48 |
self.assertEqual(payload["live_lobes"], payload["lobe_count"])
|
| 49 |
self.assertEqual(payload["lobes"]["formulas"]["theorem_count"], 2)
|
|
|
|
|
|
|
| 50 |
self.assertEqual(payload["lobes"]["models"]["downloads_sum"], 10)
|
| 51 |
self.assertEqual(payload["lobes"]["fleet"]["up_count"], 5)
|
| 52 |
self.assertFalse(payload["limits"]["cache_or_last_good_fallback"])
|
|
@@ -58,10 +63,12 @@ class HolographicZeroCdnTests(unittest.TestCase):
|
|
| 58 |
raise TimeoutError("test timeout")
|
| 59 |
return self._json(url)
|
| 60 |
|
|
|
|
| 61 |
payload = holographic.brain_evidence(
|
| 62 |
fetch_json=partial_json,
|
| 63 |
-
fetch_text=lambda _url:
|
| 64 |
fetch_health=self._health,
|
|
|
|
| 65 |
)
|
| 66 |
frontier = payload["lobes"]["frontier"]
|
| 67 |
self.assertEqual(payload["state"], "DEGRADED")
|
|
@@ -70,6 +77,25 @@ class HolographicZeroCdnTests(unittest.TestCase):
|
|
| 70 |
failed = next(row for row in frontier["sources"] if row["org"] == "zai-org")
|
| 71 |
self.assertEqual(failed["reason"], "upstream_unreachable_or_timeout")
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
def test_route_is_get_only_no_store_and_same_contract(self):
|
| 74 |
app = FastAPI()
|
| 75 |
expected = {
|
|
|
|
| 1 |
"""Zero-CDN and honest same-origin evidence contract regressions."""
|
| 2 |
from __future__ import annotations
|
| 3 |
|
| 4 |
+
import hashlib
|
| 5 |
import unittest
|
| 6 |
from pathlib import Path
|
| 7 |
from unittest.mock import patch
|
|
|
|
| 40 |
self.assertNotIn("fetch('https://", brain)
|
| 41 |
|
| 42 |
def test_complete_observation_is_live_and_measured(self):
|
| 43 |
+
formula_source = "theorem one : True := by trivial\n theorem two : True := by trivial\n"
|
| 44 |
payload = holographic.brain_evidence(
|
| 45 |
fetch_json=self._json,
|
| 46 |
+
fetch_text=lambda _url: formula_source,
|
| 47 |
fetch_health=self._health,
|
| 48 |
+
expected_formula_sha256=hashlib.sha256(formula_source.encode("utf-8")).hexdigest(),
|
| 49 |
)
|
| 50 |
self.assertEqual(payload["state"], "LIVE")
|
| 51 |
self.assertEqual(payload["live_lobes"], payload["lobe_count"])
|
| 52 |
self.assertEqual(payload["lobes"]["formulas"]["theorem_count"], 2)
|
| 53 |
+
self.assertEqual(payload["lobes"]["formulas"]["integrity_state"], "VERIFIED")
|
| 54 |
+
self.assertFalse(payload["lobes"]["formulas"]["mutable_reference"])
|
| 55 |
self.assertEqual(payload["lobes"]["models"]["downloads_sum"], 10)
|
| 56 |
self.assertEqual(payload["lobes"]["fleet"]["up_count"], 5)
|
| 57 |
self.assertFalse(payload["limits"]["cache_or_last_good_fallback"])
|
|
|
|
| 63 |
raise TimeoutError("test timeout")
|
| 64 |
return self._json(url)
|
| 65 |
|
| 66 |
+
formula_source = "theorem one : True := by trivial\n"
|
| 67 |
payload = holographic.brain_evidence(
|
| 68 |
fetch_json=partial_json,
|
| 69 |
+
fetch_text=lambda _url: formula_source,
|
| 70 |
fetch_health=self._health,
|
| 71 |
+
expected_formula_sha256=hashlib.sha256(formula_source.encode("utf-8")).hexdigest(),
|
| 72 |
)
|
| 73 |
frontier = payload["lobes"]["frontier"]
|
| 74 |
self.assertEqual(payload["state"], "DEGRADED")
|
|
|
|
| 77 |
failed = next(row for row in frontier["sources"] if row["org"] == "zai-org")
|
| 78 |
self.assertEqual(failed["reason"], "upstream_unreachable_or_timeout")
|
| 79 |
|
| 80 |
+
def test_formula_source_is_commit_pinned_and_hash_allowlisted(self):
|
| 81 |
+
url = holographic._BRAIN_SOURCES["formulas"]
|
| 82 |
+
self.assertIn(holographic._BRAIN_FORMULA_COMMIT, url)
|
| 83 |
+
self.assertNotIn("/main/", url)
|
| 84 |
+
self.assertEqual(len(holographic._BRAIN_FORMULA_COMMIT), 40)
|
| 85 |
+
self.assertEqual(len(holographic._BRAIN_FORMULA_SHA256), 64)
|
| 86 |
+
|
| 87 |
+
def test_formula_hash_mismatch_is_unavailable_not_measured(self):
|
| 88 |
+
payload = holographic.brain_evidence(
|
| 89 |
+
fetch_json=self._json,
|
| 90 |
+
fetch_text=lambda _url: "theorem tampered : True := by trivial\n",
|
| 91 |
+
fetch_health=self._health,
|
| 92 |
+
)
|
| 93 |
+
formula = payload["lobes"]["formulas"]
|
| 94 |
+
self.assertEqual(payload["state"], "DEGRADED")
|
| 95 |
+
self.assertEqual(formula["state"], "UNAVAILABLE")
|
| 96 |
+
self.assertEqual(formula["reason"], "source_integrity_mismatch")
|
| 97 |
+
self.assertNotIn("theorem_count", formula)
|
| 98 |
+
|
| 99 |
def test_route_is_get_only_no_store_and_same_contract(self):
|
| 100 |
app = FastAPI()
|
| 101 |
expected = {
|