-
Notifications
You must be signed in to change notification settings - Fork 17
Harden formal audit trust gates #1937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a1ea6e1
Harden formal audit trust gates
Th0rgal 110ed3c
Merge remote-tracking branch 'origin/main' into prod-ready-unlink-abi…
Th0rgal 3938bf2
Harden trust surface registry check
Th0rgal 18468af
Address trust gate review findings
Th0rgal b4ebd86
Deduplicate benchmark case discovery
Th0rgal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| #!/usr/bin/env python3 | ||
| """Validate optional benchmark-case metadata. | ||
|
|
||
| Core Verity checkouts do not normally contain `Benchmark/`; downstream | ||
| benchmark repos may vendor or overlay `Benchmark/`, while the standalone | ||
| benchmark repository keeps metadata under `cases/`. When present, each | ||
| `case.yaml` is a publication boundary and must identify the upstream target | ||
| commit. If a case has `FormalAudit.lean`, it must not still be marked | ||
| `proof_status: not_started`. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import re | ||
| from pathlib import Path | ||
|
|
||
| from property_utils import ROOT, report_errors | ||
|
|
||
| KEY_VALUE_RE = re.compile(r"^\s*([A-Za-z_][A-Za-z0-9_-]*)\s*:\s*(.*?)\s*$") | ||
|
|
||
|
|
||
| def parse_case_yaml(path: Path) -> dict[str, str]: | ||
| values: dict[str, str] = {} | ||
| for line in path.read_text(encoding="utf-8").splitlines(): | ||
| line = line.split("#", 1)[0].strip() | ||
| if not line: | ||
| continue | ||
| match = KEY_VALUE_RE.match(line) | ||
| if match: | ||
| values[match.group(1)] = match.group(2).strip().strip("\"'") | ||
| return values | ||
|
|
||
|
|
||
| def discover_case_files(root: Path = ROOT) -> list[Path]: | ||
| case_files = sorted((root / "Benchmark").glob("Cases/**/case.yaml")) | ||
| case_files += sorted((root / "cases").glob("**/case.yaml")) | ||
| return case_files | ||
|
|
||
|
|
||
| def check_benchmark_cases(root: Path = ROOT) -> list[str]: | ||
| case_files = discover_case_files(root) | ||
| if not case_files: | ||
| return [] | ||
|
|
||
| errors: list[str] = [] | ||
| for case_yaml in case_files: | ||
| metadata = parse_case_yaml(case_yaml) | ||
| case_dir = case_yaml.parent | ||
| rel = case_yaml.relative_to(root) | ||
|
|
||
| if not metadata.get("upstream_commit"): | ||
| errors.append(f"{rel}: missing upstream_commit") | ||
|
|
||
| if (case_dir / "FormalAudit.lean").exists(): | ||
| proof_status = metadata.get("proof_status") | ||
| if proof_status == "not_started": | ||
| errors.append(f"{rel}: FormalAudit.lean exists but proof_status is not_started") | ||
|
|
||
| audit_target_commit = metadata.get("audit_target_commit") | ||
| if audit_target_commit is not None and not re.fullmatch(r"[0-9a-fA-F]{7,40}", audit_target_commit): | ||
| errors.append(f"{rel}: audit_target_commit must be a 7-40 character git hex prefix") | ||
|
|
||
| return errors | ||
|
|
||
|
|
||
| def main() -> int: | ||
| case_files = discover_case_files() | ||
| if not case_files: | ||
| print("OK: no benchmark case metadata found; benchmark metadata check skipped") | ||
| return 0 | ||
|
|
||
| errors = check_benchmark_cases() | ||
| report_errors(errors, "Benchmark case metadata check failed") | ||
| print(f"OK: benchmark metadata check passed for {len(case_files)} case.yaml file(s)") | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| #!/usr/bin/env python3 | ||
| """Validate that non-axiom trusted surfaces are documented. | ||
|
|
||
| The Lean kernel axiom registry is intentionally separate from Verity's broader | ||
| trusted surface. This checker covers mechanisms that do not create project | ||
| Lean axioms, but still matter for audit soundness: | ||
|
|
||
| * `native_decide` | ||
| * `@[implemented_by ...]` | ||
| * `partial def` | ||
| * explicit ECM assumption strings in `axioms := [...]` | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import re | ||
| from pathlib import Path | ||
|
|
||
| from property_utils import ROOT, report_errors, scrub_lean_code, strip_lean_comments | ||
|
|
||
| SCAN_ROOTS = ("Compiler", "Verity", "Contracts", "Benchmark") | ||
| DOC_PATHS = ("AXIOMS.md", "TRUST_ASSUMPTIONS.md") | ||
| DOC_DIRS = ("docs",) | ||
|
|
||
| ECM_AXIOM_STRING_RE = re.compile(r'"([^"]+)"') | ||
|
|
||
| MECHANISM_PATTERNS = ( | ||
| ("native_decide", re.compile(r"\bnative_decide\b")), | ||
| ("@[implemented_by", re.compile(r"@\[\s*implemented_by\b")), | ||
| ("partial def", re.compile(r"\bpartial\s+def\b")), | ||
| ) | ||
|
|
||
|
|
||
| def _iter_lean_files(root: Path = ROOT) -> list[Path]: | ||
| files: list[Path] = [] | ||
| for subdir in SCAN_ROOTS: | ||
| base = root / subdir | ||
| if base.exists(): | ||
| files.extend(sorted(base.rglob("*.lean"))) | ||
| return files | ||
|
|
||
|
|
||
| def _read_doc_corpus(root: Path = ROOT) -> str: | ||
| chunks: list[str] = [] | ||
| for rel in DOC_PATHS: | ||
| path = root / rel | ||
| if path.exists(): | ||
| chunks.append(path.read_text(encoding="utf-8")) | ||
| for rel in DOC_DIRS: | ||
| base = root / rel | ||
| if base.exists(): | ||
| for path in sorted(base.rglob("*.md")): | ||
| chunks.append(path.read_text(encoding="utf-8")) | ||
| return "\n".join(chunks) | ||
|
|
||
|
|
||
| def collect_trust_surface(root: Path = ROOT) -> tuple[dict[str, int], dict[str, tuple[str, int]]]: | ||
| mechanisms = {name: 0 for name, _ in MECHANISM_PATTERNS} | ||
| ecm_axioms: dict[str, tuple[str, int]] = {} | ||
|
|
||
| for path in _iter_lean_files(root): | ||
| raw_text = path.read_text(encoding="utf-8") | ||
| text = scrub_lean_code(raw_text) | ||
| text_without_comments = strip_lean_comments(raw_text) | ||
| rel = str(path.relative_to(root)) | ||
| for name, pattern in MECHANISM_PATTERNS: | ||
| mechanisms[name] += len(pattern.findall(text)) | ||
| for match in re.finditer(r"axioms\s*:=\s*\[(.*?)\]", text_without_comments, flags=re.DOTALL): | ||
| line_no = text_without_comments.count("\n", 0, match.start()) + 1 | ||
| for axiom_name in ECM_AXIOM_STRING_RE.findall(match.group(1)): | ||
| ecm_axioms.setdefault(axiom_name, (rel, line_no)) | ||
|
|
||
| return mechanisms, ecm_axioms | ||
|
|
||
|
|
||
| def main() -> int: | ||
| docs = _read_doc_corpus() | ||
| mechanisms, ecm_axioms = collect_trust_surface() | ||
|
|
||
| errors: list[str] = [] | ||
| for name, count in mechanisms.items(): | ||
| if count > 0 and name not in docs: | ||
| errors.append( | ||
| f"{name}: {count} occurrence(s) found in Lean sources but missing from trust docs" | ||
| ) | ||
|
|
||
| for axiom_name, (rel, line) in sorted(ecm_axioms.items()): | ||
| if axiom_name not in docs: | ||
| errors.append( | ||
| f"{axiom_name}: ECM assumption from {rel}:{line} is missing from trust docs" | ||
| ) | ||
|
|
||
| report_errors(errors, "Trust-surface registry check failed") | ||
| print( | ||
| "OK: trust-surface registry documents " | ||
| f"{len(ecm_axioms)} ECM assumption(s), " | ||
| + ", ".join(f"{name}={count}" for name, count in mechanisms.items()) | ||
| ) | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.