Repository navigation
Fail-closed R12 hardening for PR #3 (Lean harness, soko Char lexer, lineage, env scrub, LP digit caps) - #19
Conversation
…for PR #3 Close canonical JSON, Lean harness, confinement, Char-literal lexer, and rational DoS defects: - Unify canonical_json_bytes with allow_nan=False across lineage.py (including compute_zone_manifest_id) and repair_loop.py. - Extend Lean static BAR_FORBIDDEN_RULES & COMPILE_BLOCKING_LINT_RULES with @[export], attribute [init|builtin_init], #guard/#guard_msgs, dbg_trace/dbg_sleep/dbg_stack_trace, and panic!/unreachable!/assert!. - Sanitize Lean Char literals ('"', escapes), raw strings (r#"..."#), and guillemet identifiers before calling soko's lean4_auditor so a double quote inside a Char literal cannot desync soko and hide import Mathlib, ring, : Float, or sorry. - Stop forwarding caller LEAN_PATH into bwrap sandboxes (explicit harness_lean_path only), scrub Lean/Elan/Lake/LD_* vars in _lean_env, and avoid process-global os.environ mutation in linux_bwrap_functional. - Fail closed on malformed/incomplete soko auditor reports (supporting ok/passed and finding_count consistency) and clean sys.modules on load failure. - Remove short-name env.find? fallback in prompt obligation driver. - Reject symlinked project roots/ancestors before .resolve() and read lean-toolchain via O_DIRECTORY|O_NOFOLLOW + O_NOFOLLOW + fstat. - Enforce pre-int() rational digit caps and MAX_DUAL_OBJECTIVE_BITS in domain_protocol.py. - Add stdlib unittest regression suite tests/test_pr3_r12_hardening.py. Refs #3 Signed-off-by: shahid arifuddin <shahid@askaconsult.com>
…eanly - Catch FileNotFoundError in _toolchain_elan_home() and return empty string as intended so _sandbox_env_pairs/_spawn_confined/bwrap probes work on Lean-less Linux hosts without ~/.elan/bin. - Patch lean_harness.elan_bin_dir to a temporary fake elan bin directory in test_t4 and test_t7 so unit tests do not depend on a host toolchain. - Handle non-POSIX runners lacking os.O_NOFOLLOW (windows-2022) in test_t7 and test_t9 by asserting early NOFOLLOW_OPEN_UNAVAILABLE fail-closed refusal while still verifying _confine_argv flags and _read_toolchain_nofollow. Refs #3 Signed-off-by: shahid arifuddin <shahid@askaconsult.com>
ahrazzle
left a comment
There was a problem hiding this comment.
Content review by grk-proof, posted unchanged by grk-ship.
Proven-Commons/mcproof #19 review
PR: #19, "Fail-closed R12 hardening for PR #3 (Lean harness, soko Char lexer, lineage, env scrub, LP digit caps)"
Reviewer: grk-proof (content review)
Head: 3e24b21. It had not moved when the review restarted at 5:08 AM CT (gh pr view 19 --json headRefOid). The PR is non-draft and MERGEABLE.
Base: feat/formal-verification-mde-v0.1 at 7023cca (the PR #3 branch). The PR adds 2 commits: 116789c and 3e24b21.
Ask (from nizam's keep-pace batch): a deep review of this exact head. ship posts the report as ahrazzle and merges only on APPROVE at this head with green CI.
Inline comments
src/mcproof/lean_harness.py:1357- High -soko_source = strip_lean_comments_and_strings(source, blank_chars=True). soko now sees only what the stripper sees, so a stripper desync hides code from both checks at once. The valid-Lean wrapperdef x := s!"{'"'}"…-- "(Lean rc=0) hides everything between its two lines. At this head,verify_lean4_sourcereturnspassed=True, sandboxed=Truefor hiddentheorem fspec (x : Float) …(IEEE754_FLOAT_SPEC_CARRIER), and also for hidden@[export],#eval,dbgTraceValandpanic!. The visible forms of the same content are rejected. The PR body sayss!"..."is closed.src/mcproof/lean_harness.py:641- High (root cause) - The string branch ofstrip_lean_comments_and_stringsends a string at the first". It does not track{…}interpolation insides!"…"/f!"…"/m!"…", so the'"'char literal inside{'"'}closes the string early. The_lean_commands_that_may_runlexer has the same blind spot (:2065): it returns[]for the hidden#eval, so Lake/comparator still elaborate it (inside bwrap).tests/test_pr3_r12_hardening.py:205- Medium - Thechar_dquote_casestable only tests a top-level'"',r#"\"#and«"». It has no case with a char literal or string insides!"{…}"interpolation. That is why the "7/7 live soko exploits fail closed" claim passes the suite while the bypass above stays open.src/mcproof/domain_protocol.py:1425- Medium -MAX_DUAL_OBJECTIVE_BITS = 850rejects valid certificates that are inside the input caps. A 6-rowboundscertificate withy_i = 1/p_i(59-digit primes, every component ≤MAX_CERT_ABS_INT = 10**60) ispassed=Trueat base andpassed=False, LP_DUAL_OBJECTIVE_DIGIT_CAPat head. That turns a VERIFIED result into REJECTED, and the PR does not say so.src/mcproof/domain_protocol.py:1401(and:1393) - Medium - The DoS cap runs after the finding messages that format the unboundedyt_b/yt_a[j]. An 80-row certificate (59-digit primes iny,claimed_lower_bound="1") raises an uncaughtValueError: Exceeds the limit (4300 digits) for integer string conversionfromverify_rational_lp_certificateat both base and head. This is the bigint-stringification path that the comment at:1288says is blocked.src/mcproof/domain_protocol.py:1304- Low - The per-component digit cap is dead code. The whole-string length bound (2*max_digits+3) already limitsint()input to ~125 chars. Removing the check (mutation M7) leaves all 9 tests green.src/mcproof/lean_harness.py:1598(also:1099,:1211) - Low -_checked_project_dirraisesUntrustedProjectPathout ofverify_lean4_source/ prompt-obligations / against-challenge.verify_lean4_project_comparatorreturns anUNTRUSTED_PROJECT_SYMLINKfinding instead. The behaviour fails closed but is inconsistent. A repo under any symlinked ancestor (for example macOS/tmp→/private/tmp) now refuses every check.src/mcproof/lean_harness.py:65- Low - The R12 init coverage is@[init]/attribute [init]only. Theinitialize hookcommand, which generates an[init]declaration, passes lint and verification at both base and head (passed=True).src/mcproof/lineage.py:103- Low -compute_zone_manifest_idchanges fromensure_ascii=Falsetoensure_ascii=True. That leaves the IDs of today's all-ASCII manifests unchanged (0 non-ASCII bytes in the 4 manifest/receipt files;lineage --verifyrc=0). Any non-ASCII manifest would get a different ID from the mde-pinned one, and the PR does not mention this.
Findings by severity
High: the headline lexer-bypass fix is incomplete; a valid-Lean wrapper hides banned content from both the stripper and soko
The PR's first bullet says it closes "live quote-desync bypasses (def c : Char := '"', r#"\"#, «"», s!"...")". The plain '"' case is fixed. The s! case is not.
Wrapper (Lean 4.35.0, lean cand.lean rc=0, warnings only):
def x := s!"{'"'}"
<hidden content>
-- "
theorem t (n : Nat) : n = n := rfl
verify_lean4_source(..., check_vacuous=False) with real soko at its pin (3165e20e), real Lean 4.35.0 and functional bwrap. Each row shows visible → hidden:
| Hidden content | base 7023cca | head 3e24b21 |
|---|---|---|
theorem fspec (x : Float) : x = x := rfl |
REJECT IEEE754_FLOAT_SPEC_CARRIER → passed=True |
REJECT IEEE754_FLOAT_SPEC_CARRIER → passed=True |
@[export evil_sym] def f … |
passed → passed | REJECT FORBIDDEN_EXPORT_ATTR → passed=True |
#eval IO.println "…" |
REJECT FORBIDDEN_EVAL_COMMAND → passed=True |
REJECT FORBIDDEN_EVAL_COMMAND → passed=True |
def g n := dbgTraceVal n |
passed → passed | REJECT FORBIDDEN_DBG → passed=True |
panic! "boom" |
passed → passed | REJECT FORBIDDEN_PANIC → passed=True |
The hidden runs report sandboxed=True, theorems_checked=['fspec','t'] or ['t'], and both kernels ran. In the Float case the hidden content is itself a theorem that the verifier certifies. The rule exists to reject a theorem whose spec carrier is Float, so this is a false PASS on content the bar bans. _lean_commands_that_may_run returns [] for the hidden #eval.
This is not a regression: base has the same bypass for the soko and eval rows. But closing it is this PR's stated purpose, and the four new R12 rules (FORBIDDEN_EXPORT_ATTR, FORBIDDEN_DBG, FORBIDDEN_PANIC, #guard*) are all defeated by the same two lines. Routing soko through the stripper also removes the defence in depth: soko's own lexer used to be independent of the stripper, and now any stripper desync blinds both.
Other encodings tried at head (lint only):
- Still hidden:
s!"{'"'}"with any closer that contains a"in a comment, char or escaped string (-- ",/- " -/,'"',"\""). All are rc=0 in Lean. - Now caught:
s!"{"a"}", nesteds!"{s!"{1}"}",'\"',r#"a"b"#,«a"b». - Still hidden, as before: the parse-error forms
λr"\",Σr"\", unclosed'"ands!"{"}"(Lean rc=1, so not an acceptance risk; this carries over the earlier mcproof-7 Low).
What a fix needs: the stripper (and _lean_commands_that_may_run) must track {/} nesting inside interpolated strings, lexing chars and strings within the braces. Add regression cases for s!"{'"'}" followed by a "-bearing comment, plus f!/m! variants, with a real-soko end-to-end assertion rather than a mocked soko.
Medium
- The regression suite misses the bypass class it claims to cover (
tests/test_pr3_r12_hardening.py:205). It has no interpolation case, and soko is mocked in every T3 case, so no test runs the real auditor. - The dual-objective cap rejects valid certificates (
domain_protocol.py:1425). Six rows of 59-digit-prime reciprocals, all inside the 10^60 input cap: VERIFIED at base, REJECTED at head. A cap on output formatting should not change the verdict. Format a bounded summary instead, or document that the cap is a verdict rule and size it to the input caps (rows × 200 bits). - The stringification DoS is still reachable and crashes rather than rejecting (
domain_protocol.py:1393/1401). The messages are formatted before the cap check. An 80-row certificate raises an uncaughtValueError(Python's 4300-digit limit) at both base and head.
Low
- L1: the per-component digit cap (
:1304) is unreachable, so mutation M7 survives. - L2:
_checked_project_dirraises out of three entry points instead of returning a finding, and refuses any symlinked ancestor (verify_lean4_sourceon a symlinked project givesEXC UntrustedProjectPath; the comparator givesUNTRUSTED_PROJECT_SYMLINK). - L3: the
initializecommand is not covered by the init rule (pre-existing). - L4: the
ensure_asciichange incompute_zone_manifest_idis unannounced; current manifests are unaffected. - L5: the PR body's count "full pytest sweep
153 passed, 0 failed" does not match this environment, where 197 passed + 1 load flake / 13 skipped (counts depend on the environment). "Dual cross-family security reviews (APPROVE ×2) verified against HEAD 116789c" is an unverifiable out-of-band review claim, which is Low per calibration. That SHA is also not the PR head.
Confirmed working (not findings)
- The soko schema checks fail closed on all 8 malformed shapes (T5).
- The
exec_modulefailure cleanssys.modules. - Caller
LEAN_PATHno longer crosses into bwrap, and_lean_envscrubsLEAN_*/ELAN_*/LAKE_*/LD_*. - The bwrap probe now requires the
MCPROOF_PROBE_OKstdout and no longer mutatesos.environ. - The
lean-toolchainread isO_NOFOLLOW+fstat S_ISREG. env.find? shortNfallback removed.allow_nan=Falsein canonical JSON.- The top-level
'"'Char desync is closed for soko-only rules:ring→NON_INIT_TACTIC,Float→IEEE754_FLOAT_SPEC_CARRIER,@[export],native_decide. At base all four passed.
Proof verification
Everything below ran at 3e24b21 in a local clone /workspace/mcp19/repo, with a base worktree at 7023cca. Pinned deps were cloned at their spec SHAs into /workspace/mcp19/deps: soko 3165e20e, mission 7b22e542, f0 9a371347, formal-claims-audit bacf0595, finite-state-proofs 9eeb3da2. Toolchain: Lean 4.35.0 (~/.elan), with bwrap and prlimit present (linux_bwrap_functional() → True).
- CI shape (
env -u ELAN_HOME MCPROOF_DEPS_DIR=<none> python3 -O -B -W error -m pytest):168 passed, 43 skipped, 37 subtests passed. [verified] - Deps + Lean + bwrap full sweep:
1 failed, 197 passed, 13 skipped. The failure wastest_lean_harness.py::test_reference_lean_project_passes_six_kernel_comparator, with Lean exit 134 underlake comparator --paranoid. That run overlapped with my own Lean attack runs. Re-run alone it gives1 passed in 32.45s, so I'm treating it as a load flake, not a PR defect. [verified] - PR suite
tests/test_pr3_r12_hardening.pyunder-I -B,-I -O -Band-I -B -W error:OK×3, 9 tests. The PR body's9/9 OK ×3claim reproduces. [verified] - Mutation controls (each applied alone in a throwaway worktree, PR suite re-run):
| Mutation | Result |
|---|---|
| M1 soko gets raw source | killed (T3) |
M2 drop finding_count check |
killed (T5) |
| M3 drop ok+findings contradiction | killed (T5) |
M4 forward caller LEAN_PATH |
killed (T4) |
M5 drop _lean_env scrub |
killed (T4) |
M6 _checked_project_dir no-op |
killed (T9) |
| M7 drop per-component digit cap | survived (L1) |
| M8 drop dual-objective cap | killed (T8) |
M9 drop FORBIDDEN_PANIC from compile-blocking |
killed (T3) |
M10 toolchain open without O_NOFOLLOW |
killed (T9) |
| M11 bwrap probe ignores stdout | killed (T4) |
M12 allow_nan=True |
killed (T2) |
The mutation worktree was left clean. [verified]
- High: real-soko lint matrix (4 wrappers × 5 payloads, base vs head), a 9-closer × 3-opener search compiled with
lean(all hits rc=0 except the"""closer), andverify_lean4_sourceend to end (6 payloads × visible/hidden, base vs head). Results are in the table above. Scripts:/workspace/mcp19/atk/{lint2,lint3,search,e2e3}.py. [verified] - LP:
/workspace/mcp19/atk/lp.py, base vs head.- 6-row valid certificate:
True→False ['LP_DUAL_OBJECTIVE_DIGIT_CAP']. - 3-row:
Truein both. - 80-row below-claim: uncaught
ValueErrorin both, raised fromfractions._format_generalvia the message f-string. [verified]
- 6-row valid certificate:
- Lineage:
python3 ./bin/mcproof --json lineage --verifyrc=0. The 4 manifest/receipt JSONs have 0 non-ASCII bytes. [verified] - Symlinked project dir:
verify_lean4_sourceraisesUntrustedProjectPath; the comparator returnsUNTRUSTED_PROJECT_SYMLINK. [verified] - GitHub CI at 3e24b21:
standalone (ubuntu-24.04),standalone (windows-2022)andbar / barare SUCCESS on both runs (45593934146, 45593919155). CI runs without soko or Lean, so it never exercises the lexer or soko paths. [verified via gh, read-only] - PR-body "Failing-before …
FAILED (failures=29, errors=3)" at 7023cca: not reproduced, since the suite file does not exist at base. Not run. - Not run: Windows-specific paths (
NOFOLLOW_OPEN_UNAVAILABLE), which are covered only by GitHub's windows-2022 job; macOS symlinked-/tmpbehaviour (reasoned, not executed); live llama-server and mde-binary stack tests (skipped for missing host prereqs). - Vibe CLI (
/workspace/rv43/run1.sh Proven-Commons/mcproof 19): started at 4:59 AM CT and still running at report time (vibe.log empty, no REPORT.md). None of the findings above depend on it; any Vibe leads will need separate verification.
Verdict: REQUEST CHANGES
- High: the PR's headline fix (closing soko and stripper quote-desync bypasses,
s!"..."listed) is incomplete. A valid-Lean two-line wrapper (def x := s!"{'"'}"…-- ") makesverify_lean4_sourcereturn passed=True on hidden Float-carrier theorems,#eval,@[export],dbgTraceValandpanic!. Every new R12 rule is defeated, and soko now shares the stripper's blind spot instead of backing it up. - Medium: the regression suite has no interpolation case and mocks soko throughout.
MAX_DUAL_OBJECTIVE_BITSrejects valid certificates inside the input caps. The bigint-stringification crash is still reachable through the finding messages. - Low: a dead digit cap, inconsistent symlink handling,
initializenot covered, an unannouncedensure_asciichange, and unreproducible body counts plus out-of-band review claims. - CI is green and the other hardening (env scrub, soko schema, NOFOLLOW toolchain, short-name fallback, allow_nan) is verified with killing mutations. Those parts are good.
| """Run static Lean 4 source audits combining soko lean4_auditor, Proven-Commons bar rules, and WeakStatement checks.""" | ||
| soko_mod = _load_soko_lean4_auditor() | ||
| soko_rep = soko_mod.audit_lean4_source(source, label=label, strict_init_only=strict_init_only) | ||
| soko_source = strip_lean_comments_and_strings(source, blank_chars=True) |
There was a problem hiding this comment.
High - soko_source = strip_lean_comments_and_strings(source, blank_chars=True). soko now sees only what the stripper sees, so a stripper desync hides code from both checks at once. The valid-Lean wrapper def x := s!"{'"'}" … -- " (Lean rc=0) hides everything between its two lines. At this head, verify_lean4_source returns passed=True, sandboxed=True for hidden theorem fspec (x : Float) … (IEEE754_FLOAT_SPEC_CARRIER), and also for hidden @[export], #eval, dbgTraceVal and panic!. The visible forms of the same content are rejected. The PR body says s!"..." is closed.
| out.append(src[i:end]) | ||
| i = end | ||
| continue | ||
| if src[i] == '"': |
There was a problem hiding this comment.
High (root cause) - The string branch of strip_lean_comments_and_strings ends a string at the first ". It does not track {…} interpolation inside s!"…"/f!"…"/m!"…", so the '"' char literal inside {'"'} closes the string early. The _lean_commands_that_may_run lexer has the same blind spot (:2065): it returns [] for the hidden #eval, so Lake/comparator still elaborate it (inside bwrap).
| # Both strip_lean_comments_and_strings(blank_chars=True) and the soko handoff must keep | ||
| # code between two `'"'` literals visible so soko-only rules (`import Mathlib`, `ring`, | ||
| # `: Float`) and BAR rules (`sorry`, `#eval`, `@[export]`) cannot be swallowed. | ||
| char_dquote_cases = [ |
There was a problem hiding this comment.
Medium - The char_dquote_cases table only tests a top-level '"', r#"\"# and «"». It has no case with a char literal or string inside s!"{…}" interpolation. That is why the "7/7 live soko exploits fail closed" claim passes the suite while the bypass above stays open.
| else: | ||
| findings.append({"rule": "LP_CERT_UNSUPPORTED_MODE", "message": f"unsupported LP mode {mode!r}"}) | ||
|
|
||
| if yt_b.numerator.bit_length() > MAX_DUAL_OBJECTIVE_BITS or yt_b.denominator.bit_length() > MAX_DUAL_OBJECTIVE_BITS: |
There was a problem hiding this comment.
Medium - MAX_DUAL_OBJECTIVE_BITS = 850 rejects valid certificates that are inside the input caps. A 6-row bounds certificate with y_i = 1/p_i (59-digit primes, every component ≤ MAX_CERT_ABS_INT = 10**60) is passed=True at base and passed=False, LP_DUAL_OBJECTIVE_DIGIT_CAP at head. That turns a VERIFIED result into REJECTED, and the PR does not say so.
| if STRICT_RATIONAL_RE.fullmatch(val): | ||
| if "/" in val: | ||
| n_str, d_str = val.split("/", 1) | ||
| if len(n_str.lstrip("-")) > max_digits or len(d_str) > max_digits: |
There was a problem hiding this comment.
Low - The per-component digit cap is dead code. The whole-string length bound (2*max_digits+3) already limits int() input to ~125 chars. Removing the check (mutation M7) leaves all 9 tests green.
| # `attribute [init]` is not `@[init]`. It still runs when the module is imported. | ||
| # The marker may sit mid-line or be split across a newline (`attribute\n[init]`). | ||
| # `attribute [init]` and `@[init]` / `@[builtin_init]` run on import. | ||
| "FORBIDDEN_INIT_ATTRIBUTE", |
There was a problem hiding this comment.
Low - The R12 init coverage is @[init] / attribute [init] only. The initialize hook command, which generates an [init] declaration, passes lint and verification at both base and head (passed=True).
| def compute_zone_manifest_id(manifest: Mapping[str, Any]) -> str: | ||
| body = {k: v for k, v in manifest.items() if k != "manifest_id"} | ||
| raw = json.dumps(body, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8") | ||
| raw = canonical_json_bytes(body) |
There was a problem hiding this comment.
Low - compute_zone_manifest_id changes from ensure_ascii=False to ensure_ascii=True. That leaves the IDs of today's all-ASCII manifests unchanged (0 non-ASCII bytes in the 4 manifest/receipt files; lineage --verify rc=0). Any non-ASCII manifest would get a different ID from the mde-pinned one, and the PR does not mention this.
…ed LP formatting
Closes review findings H1, M1, M2, L1, and L3:
- Track nested {...} interpolation depth in strip_lean_comments_and_strings()
and _lean_commands_that_may_run() for s!/f!/m!/<ident>!... literals so
embedded character literals (e.g. '"', '\"'), strings, comments, and
nested interpolations cannot desynchronize quote parity or hide Float,
@[export], #eval, dbgTraceVal, panic!, or initialize payloads from
BAR_FORBIDDEN_RULES, soko, or pre-lake command scanning.
- Catch bare initialize / builtin_initialize declarations in
FORBIDDEN_INIT_ATTRIBUTE directly inside lean_harness.py.
- Replace verdict-flipping LP_DUAL_OBJECTIVE_DIGIT_CAP with
_format_bounded_fraction() across all five LP output/finding formatting
sites so valid multi-row high-precision rational certificates stay VERIFIED
and invalid 80-row certificates return clean REJECTED findings without
hitting Python's 4300-digit int-to-str ValueError.
- Remove the unreachable per-component digit check in _parse_exact_rational().
Signed-off-by: shahid arifuddin <shahid@askaconsult.com>
|
Strict-FF follow-up pushed at
|
ahrazzle
left a comment
There was a problem hiding this comment.
Content review by grk-proof, posted unchanged by grk-ship.
Review: Proven-Commons/mcproof #19 at 3a43cf0
PR: #19, "Fail-closed R12 hardening for PR #3 (Lean harness, soko Char lexer, lineage, env scrub, LP digit caps)"
Head: 3a43cf0a615127f834a8970bb21b218db8348da1. The runner confirmed this exact head at fetch (6:29 AM CT). The previous review was at 3e24b21c (REQUEST CHANGES). The new commit is 3a43cf0a, "Fix Lean interpolated-string lexer desync, initialize rule, and bounded LP formatting". It changes src/mcproof/domain_protocol.py, src/mcproof/lean_harness.py and tests/test_pr3_r12_hardening.py.
Base: feat/formal-verification-mde-v0.1 at 7023cca. The PR is non-draft and MERGEABLE.
CI at head: standalone (ubuntu-24.04), standalone (windows-2022) and bar / bar are all SUCCESS (two runs each, read-only gh). CI runs without soko or Lean, so it never exercises the lexer path.
Ask: re-review the moved head. Re-run the attack scripts in /workspace/mcp19/atk/, try new variants of the bypass family, check every prior finding, then review the delta.
Inline comments
-
src/mcproof/lean_harness.py:666- High -is_interp = j > i and src[j - 1] == "!" and j < n and src[j] == '"'treats an interpolated string as starting only when"comes immediately afters!/f!/m!. Lean also accepts whitespace, a newline or a comment between thes!token and the string. Each of these isleanrc=0 and hides the content between its two lines from both the stripper and soko:def x := s! "{'"'}"…-- "def x := s!⏎ "{'"'}"…-- "def x := s! /- c -/ "{'"'}"…-- "f! "{'"'}"behaves the same.- Closers
/- " -/anddef z : Char := '"'also work.
verify_lean4_source(..., check_vacuous=False)with real soko (3165e20e), Lean 4.35.0 and functional bwrap returns passed=True, sandboxed=True for hiddentheorem fspec (x : Float) …(visible:IEEE754_FLOAT_SPEC_CARRIER),@[export evil_sym],#eval(both quoted and unquoted),initialize hook,dbgTraceValandpanic!. This is the same bypass class as the prior High, reopened by one space. Fix: after an identifier ending in!that names an interpolation macro, skip whitespace and comments before checking for". A more robust option is to lex the way Lean's tokenizer does. -
src/mcproof/lean_harness.py:2152- High (same root cause) -_lean_commands_that_may_runuses the same immediate-"test, so it returns[]for the hidden#evalunders! "…". Lake and the comparator still elaborate it (inside bwrap). -
tests/test_pr3_r12_hardening.py:264- Medium - The newinterp_hide_casescover only the no-space form (s!"…",f!"…",m!"…",my!"…", nested). There is no case with whitespace, a newline or a comment between the macro and the string, which is why the suite passes while the bypass above is open. soko is still mocked in every T3 case (mock.patch.object(lean_harness, "_load_soko_lean4_auditor", …)at :168, :255, :333), so no test runs the real auditor end to end. -
src/mcproof/domain_protocol.py:1444- Low -dual_obj_str = _format_bounded_fraction(yt_b, always_ratio=True)now reports a passing certificate's exact dual objective as an opaque<rational:966b/1157b>once either part is over 850 bits (my 6-row case). Not crashing and not flipping the verdict is correct. But consumers that parsedual_objectiveasp/qwill break, and the cap is not in the PR body. Document the format or add a separatedual_objective_truncatedflag. -
src/mcproof/lean_harness.py:1598(_checked_project_dir) - Low (prior L2, unchanged) - It still raisesUntrustedProjectPathout of three entry points, while the comparator returns a finding. -
src/mcproof/lineage.py:103- Low (prior L4, unchanged) - Theensure_asciichange is still not mentioned in the PR body. -
PR body - Low - The body is stale. It still advertises "per-component digit caps" (removed in this commit) and
MAX_DUAL_OBJECTIVE_BITS = 850as a reject cap (it is now a formatting bound only). It still claims "153 passed" and "9/9" and "APPROVE ×2 … HEAD 116789c". The review claim is Low by calibration.
Prior findings: status at 3a43cf0
| Prior | Status | Evidence |
|---|---|---|
High: s!"{'"'}" … -- " wrapper bypasses R12 (stripper :641 / soko via stripper :1357 / may_run :2065) |
Partly fixed, still open | The exact prior wrapper is now caught. I re-ran /workspace/mcp19/atk/e2e3.py at head: hidden float_spec gives IEEE754_FLOAT_SPEC_CARRIER, and export, eval, init, dbg and panic are all rejected with their rules, the same as the visible forms. lint3.py catches all 6 wrappers. But inserting whitespace, a newline or a comment between s! and " hides everything again (new inline High; /workspace/mcp19/atk2/lint5.py, e2e4.py). |
| Medium: suite has no interpolation case, soko mocked | Partly fixed | 6+ interpolation cases were added and they are live: mutation is_interp = False gives 6 failures. There is still no whitespace or comment case, and soko is still mocked. |
Medium: MAX_DUAL_OBJECTIVE_BITS rejects valid certs |
Fixed | /workspace/mcp19/atk/lp.py: the 6-row 59-digit-prime certificate is passed=True, findings [] (it was False ['LP_DUAL_OBJECTIVE_DIGIT_CAP']). The cap is now formatting only (Low above). |
| Medium: bigint stringification crash via finding messages | Fixed | 80-row below-claim certificate: passed=False ['LP_DUAL_OBJECTIVE_BELOW_CLAIM'], message length 58, 0.00 s. Before, it raised an uncaught ValueError (4300-digit limit). All four message sites use _format_bounded_fraction. Mutation (bounding disabled) gives 1 test failure. |
| L1 dead per-component digit cap | Fixed | Removed. The whole-string length bound remains. |
L2 _checked_project_dir raises |
Unchanged | Low above. |
L3 initialize not covered |
Fixed | The rule regex at :69 now covers initialize and builtin_initialize. e2e: visible initialize hook gives FORBIDDEN_INIT_ATTRIBUTE. Hidden under the old wrapper it is rejected, but under s! "…" it passes (High). |
L4 ensure_ascii unannounced |
Unchanged | Low above. |
| L5 body counts / review claim | Unchanged and more stale | Low above. |
Findings by severity
High: the interpolation lexer fix depends on there being no space between s! and "
| Wrapper (opener … closer), payload between | lean rc | lint at base 7023cca | lint at head 3a43cf0 |
|---|---|---|---|
s!"{'"'}" … -- " (prior) |
0 | passed (hidden) | caught (FORBIDDEN_EVAL_COMMAND, IEEE754_FLOAT_SPEC_CARRIER; may_run ['#eval']) |
s! "{'"'}" … -- " |
0 | not run (the no-space form already passes at base) | passed (hidden), may_run [] |
s! "{'"'}" … /- " -/ |
0 | passed (hidden) | passed (hidden) |
s! "{'"'}" … def z : Char := '"' |
0 | passed (hidden) | passed (hidden) |
s! /- c -/ "{'"'}" … -- " |
0 | passed (hidden) | passed (hidden) |
s!⏎ "{'"'}" … -- " |
0 | n/a | passed (hidden) |
f! "{'"'}" … -- " |
0 | n/a | passed (hidden) |
s!\t"…" |
1 (tabs rejected) | n/a | passed; not an acceptance risk |
End to end, verify_lean4_source with real soko, Lean 4.35.0 and bwrap (e2e4.py):
| Payload | visible | hidden under s! "…" / s!⏎ "…" |
|---|---|---|
theorem fspec (x : Float) : x = x := rfl |
REJECT IEEE754_FLOAT_SPEC_CARRIER |
passed=True, sandboxed=True, thms ['fspec','t'] |
@[export evil_sym] def f … |
REJECT FORBIDDEN_EXPORT_ATTR |
passed=True |
#eval (IO.println (toString (6*7)) : IO Unit) |
REJECT FORBIDDEN_EVAL_COMMAND |
passed=True |
#eval IO.println "RAN_HIDDEN_EVAL" |
REJECT FORBIDDEN_EVAL_COMMAND |
passed=True |
initialize hook |
REJECT FORBIDDEN_INIT_ATTRIBUTE |
passed=True |
dbgTraceVal |
REJECT FORBIDDEN_DBG |
passed=True |
panic! (toString n) |
REJECT FORBIDDEN_PANIC |
passed=True |
by native_decide |
REJECT | REJECT (KERNEL_NONSTANDARD_AXIOM; the kernel axiom check still catches it) |
This is not a regression against base, which bypasses on all of these. But closing the interpolation desync is the stated purpose of this commit, and the fix covers only the no-space spelling. Every R12 rule this PR adds is still defeated, and the verifier certifies a Float-carrier theorem as passing.
Other variants I tried that are now caught or not exploitable:
- The original no-space wrappers with
-- ",/- " -/,'"'and"\""closers (lint3.py,e2e3.py). ident!"{"false-start attempts (q!"{",String.toNat!"{") are rejected by Lean itself (rc=1).m! "…"needs an import, rc=1 here.
Medium
M1. The regression suite still misses this bypass family and mocks soko. See tests/…:264 above.
Low
The opaque <rational:…> dual objective on passing certificates, _checked_project_dir raising, the unannounced ensure_ascii change, and the stale PR body.
Proof verification
Everything ran in /workspace/mcp19/repo checked out at 3a43cf0a (detached, read-only fetch), with base at /workspace/mcp19/base (7023cca). Pinned deps were in /workspace/mcp19/deps: soko 3165e20e, mission 7b22e542, f0 9a371347, formal-claims-audit bacf0595, finite-state-proofs 9eeb3da2. Lean 4.35.0 and bwrap were functional.
- Prior attack scripts re-run at head:
atk/lint3.py(all 6 wrappers caught),atk/e2e3.py(all 6 payloads rejected when hidden),atk/lp.py(6-row passes, 80-row rejects cleanly, no crash). - New attack scripts:
atk2/lint4.py(7 wrappers, lean rc plus lint plus may_run),atk2/lint5.py(comment, tab and closer variants, base vs head) andatk2/e2e4.py(8 payloads × 2 wrappers, real soko and bwrap end to end). Results are in the tables above. - PR suite
python3 {-I -B | -I -O -B | -I -B -W error} -m unittest discover -s tests -p test_pr3_r12_hardening.py: Ran 9 tests, OK ×3. - CI-shape sweep (
env -u ELAN_HOME MCPROOF_DEPS_DIR=/nonexistent python3 -O -B -W error -m pytest): 168 passed, 43 skipped, 0 failed (counted from the progress line, because the repo'saddopts = "-q"plus my-qsuppresses the summary). - Mutations:
is_interp = Falseat :666 gives PR suite FAILED (6)._format_bounded_fractionbound disabled gives PR suite FAILED (1).
- Full sweep with deps, Lean and bwrap: FULLSWEEP_PLACEHOLDER
- Vibe (
/workspace/rv43/mcproof-19-3a43cf0a/): VIBE_PLACEHOLDER
Not run:
- The Windows-specific paths. GitHub windows-2022 is green.
- The live llama-server and mde-binary stack tests (missing host prerequisites).
No secrets in the diff. No speed, KL or bit-flip claims and no FP16 figure.
Verdict: REQUEST CHANGES
- High: the interpolated-string lexer fix requires
"to come immediately afters!/f!. Lean accepts a space, a newline or a comment there. Withdef x := s! "{'"'}"…-- ",verify_lean4_sourcereturns passed=True on hidden Float-carrier theorems,#eval,@[export],initialize,dbgTraceValandpanic!, and_lean_commands_that_may_runmisses the#eval. This is the same bypass family as before, still open. - Medium: the new tests cover only the no-space spelling and still mock soko.
- Fixed and verified: the exact prior wrapper, the LP cap that rejected valid certificates, the bigint message crash, the dead digit cap and the
initializerule. CI is green.
| out.append(src[i:j]) | ||
| i = j | ||
| ident = src[i:j] | ||
| is_interp = j > i and src[j - 1] == "!" and j < n and src[j] == '"' |
There was a problem hiding this comment.
High - is_interp = j > i and src[j - 1] == "!" and j < n and src[j] == '"' treats an interpolated string as starting only when " comes immediately after s!/f!/m!. Lean also accepts whitespace, a newline or a comment between the s! token and the string. Each of these is lean rc=0 and hides the content between its two lines from both the stripper and soko:
| if src[i] == "«" or _is_lean_id_first(src[i]): | ||
| i = _lean_ident_end(src, i) | ||
| j = _lean_ident_end(src, i) | ||
| if j > i and src[j - 1] == "!" and j < n and src[j] == '"': |
There was a problem hiding this comment.
High (same root cause) - _lean_commands_that_may_run uses the same immediate-" test, so it returns [] for the hidden #eval under s! "…". Lake and the comparator still elaborate it (inside bwrap).
| # Interpolated string (`s!"..."`, `f!"..."`, `m!"..."`, custom `<ident>!"..."`) | ||
| # `{...}` nesting with embedded `'"'`, `'\\"'`, nested `s!"..."`, and comments/strings | ||
| # must never desynchronize BAR_FORBIDDEN_RULES, soko handoff, or _lean_commands_that_may_run. | ||
| interp_hide_cases = [ |
There was a problem hiding this comment.
Medium - The new interp_hide_cases cover only the no-space form (s!"…", f!"…", m!"…", my!"…", nested). There is no case with whitespace, a newline or a comment between the macro and the string, which is why the suite passes while the bypass above is open. soko is still mocked in every T3 case (mock.patch.object(lean_harness, "_load_soko_lean4_auditor", …) at :168, :255, :333), so no test runs the real auditor end to end.
| else: | ||
| findings.append({"rule": "LP_CERT_UNSUPPORTED_MODE", "message": f"unsupported LP mode {mode!r}"}) | ||
|
|
||
| dual_obj_str = _format_bounded_fraction(yt_b, always_ratio=True) |
There was a problem hiding this comment.
Low - dual_obj_str = _format_bounded_fraction(yt_b, always_ratio=True) now reports a passing certificate's exact dual objective as an opaque <rational:966b/1157b> once either part is over 850 bits (my 6-row case). Not crashing and not flipping the verdict is correct. But consumers that parse dual_objective as p/q will break, and the cap is not in the PR body. Document the format or add a separate dual_objective_truncated flag.
| def compute_zone_manifest_id(manifest: Mapping[str, Any]) -> str: | ||
| body = {k: v for k, v in manifest.items() if k != "manifest_id"} | ||
| raw = json.dumps(body, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8") | ||
| raw = canonical_json_bytes(body) |
There was a problem hiding this comment.
Low (prior L4, unchanged) - The ensure_ascii change is still not mentioned in the PR body.
Summary
Stacked fail-closed R12 hardening targeting
feat/formal-verification-mde-v0.1(Refs #3):Char := '"'/ Raw-String / GuillemetsokoLexer Bypass Closed (src/mcproof/lean_harness.py): Addedstrip_lean_comments_and_strings(..., blank_chars=True)before invokingsoko_mod.audit_lean4_source, closing live quote-desync bypasses (def c : Char := '"',r#"\""#,«"»,s!"...") while preserving line numbers and identifier primes (x'). Verified7/7livesokoexploits fail closed.sokoSchema & R12 Forbidden Constructs (src/mcproof/lean_harness.py): Validated realsoko"ok"+"finding_count"schema (rejecting malformed shapes andok=Truewith non-empty findings), addedFORBIDDEN_EXPORT_ATTR,FORBIDDEN_DBG,FORBIDDEN_PANIC,attribute [init|builtin_init],#guard/#guard_msgsto compile-blocking lint rules, and removed the short-nameenv.find? shortNhijack fallback.src/mcproof/lean_harness.py,src/mcproof/repair_loop.py): Added_checked_project_dir()(lstatwalk before.resolve()),_read_toolchain_nofollow()(O_DIRECTORY|O_NOFOLLOW+fstatS_ISREG), dropped callerLEAN_PATHin_sandbox_env_pairs, and eliminatedos.environmutation inlinux_bwrap_functional().int()Rational DoS Caps & JSON Strictness (src/mcproof/domain_protocol.py,src/mcproof/lineage.py): Enforced pre-int()string-length and per-component digit caps (4301-digit DoS rejected cleanly),MAX_DUAL_OBJECTIVE_BITS = 850, andallow_nan=False.tests/test_pr3_r12_hardening.py): Stdlibunittest, zero bareasserts, covering all R12/confinement/lexer regressions.Verification
origin/feat/formal-verification-mde-v0.1 @ 7023ccaf:FAILED (failures=29, errors=3).tests/test_pr3_r12_hardening.py9/9 OK ×3(-I -B,-I -O -B,-I -B -W error); full pytest sweep153 passed, 0 failed(including15/15live Lean +bwrapintegration tests).APPROVE×2) verified againstHEAD 116789cc.