Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion experiments/landmark_dual_bounds/hero_assignment_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def parse_strict_fraction(value: Any) -> Fraction:
raise ValueError("Fraction component exceeds 10^60 bound")
return value
if isinstance(value, str):
if not _STRICT_FRAC_RE.match(value):
if not _STRICT_FRAC_RE.fullmatch(value):
raise ValueError(f"Invalid canonical rational string: {value!r}")
if "/" in value:
num_s, den_s = value.split("/", 1)
Expand Down
4 changes: 2 additions & 2 deletions mde_soko/domain_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ def audit_soko_certificate(cert: Mapping[str, Any]) -> dict[str, Any]:
if status in CERTIFIED_STATUSES:
if not isinstance(pins, Mapping):
pins = {}
if pins.get("tcb_manifest_verified", False) is not True or not SHA256_64_RE.match(
if pins.get("tcb_manifest_verified", False) is not True or not SHA256_64_RE.fullmatch(
str(pins.get("checker_auditor_py_sha256", ""))
):
findings.append(
Expand Down Expand Up @@ -784,7 +784,7 @@ def audit_soko_certificate(cert: Mapping[str, Any]) -> dict[str, Any]:

if status in CERTIFIED_STATUSES:
w_sha = cert.get("witness_or_proof_sha256")
if not isinstance(w_sha, str) or not SHA256_64_RE.match(w_sha):
if not isinstance(w_sha, str) or not SHA256_64_RE.fullmatch(w_sha):
findings.append(
{
"rule": "F08_INVALID_WITNESS_SHA256",
Expand Down
67 changes: 67 additions & 0 deletions tests/test_anchored_fullmatch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""Anchored patterns must reject a trailing newline.

`$` matches before a final newline, so `re.match` accepted `3/4\\n` and a
64-hex digest with the same extra byte. `fullmatch` does not.
"""

from __future__ import annotations

import unittest

from experiments.landmark_dual_bounds.hero_assignment_bounds import parse_strict_fraction
from mde_soko.domain_oracle import audit_soko_certificate

HEX64 = "a" * 64


def _require(condition: bool, message: str) -> None:
if not condition:
raise AssertionError(message)


def _verified() -> dict:
return {
"epistemic_status": "VERIFIED",
"tcb_pins": {
"tcb_manifest_verified": True,
"checker_auditor_py_sha256": HEX64,
},
"witness_or_proof_sha256": "b" * 64,
}


class AnchoredFullmatchTests(unittest.TestCase):
def test_canonical_fraction_still_parses(self) -> None:
self.assertEqual(parse_strict_fraction("3/4").numerator, 3)
self.assertEqual(parse_strict_fraction("-5"), -5)

def test_fraction_trailing_newline_rejected(self) -> None:
with self.assertRaises(ValueError):
parse_strict_fraction("3/4\n")

def test_digest_trailing_newline_rejected(self) -> None:
clean = audit_soko_certificate(_verified())
_require(bool(clean["passed"]), f"control certificate rejected: {clean}")
bad_witness = _verified()
bad_witness["witness_or_proof_sha256"] = "b" * 64 + "\n"
res_w = audit_soko_certificate(bad_witness)
_require(
(not bool(res_w["passed"]))
and any(str(f["rule"]).startswith("F08") for f in res_w["findings"]),
f"trailing newline on the witness digest was accepted: {res_w}",
)
bad_pin = _verified()
bad_pin["tcb_pins"] = {
"tcb_manifest_verified": True,
"checker_auditor_py_sha256": HEX64 + "\n",
}
res_p = audit_soko_certificate(bad_pin)
_require(
(not bool(res_p["passed"]))
and any(str(f["rule"]).startswith("F03") for f in res_p["findings"]),
f"trailing newline on the checker digest was accepted: {res_p}",
)


if __name__ == "__main__":
unittest.main()
Loading