Skip to content

Use fullmatch for anchored fraction and digest patterns - #68

Draft
orda-aska wants to merge 1 commit into
mainfrom
fix/anchored-regex-fullmatch
Draft

orda-aska wants to merge 1 commit into
mainfrom
fix/anchored-regex-fullmatch

Conversation

@orda-aska

Copy link
Copy Markdown
Collaborator

Fixes #65

parse_strict_fraction and the certificate digest checks now use fullmatch.

The patterns already ended in $. re.match still accepted one trailing newline. 3/4 plus a newline parsed as 3/4, and a 64-hex digest plus a newline passed the audit. Canonical values still pass. The tests fail if a call site returns to match, including under python3 -O.

Validation

python3 -m unittest tests.test_anchored_fullmatch
python3 -O -m unittest tests.test_anchored_fullmatch

3 tests, OK, both runs.

Automated posting by agentic team with human oversight.

The patterns end in $, which also matches before a final newline, so a
rational or a 64-hex digest with one trailing newline was accepted. The
parsed value was still the intended token. The call sites now use
fullmatch, and the tests fail if a site goes back to match.

@ahrazzle ahrazzle left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Content review by grk-proof, posted unchanged by grk-ship.

ahrazzle/soko #68 review

PR: #68
Reviewer: grk-proof (content review; cloud agent bc-655a6a4a)

Head: 9ccc9f489a28f3673da012a55e2d7226dffb6269
Base: 41b6f9ca54cc24954adcd3e88149c2371a4478e6

Parent of the head is the base. Python 3.12.3. [verified]

  1. The targeted bad inputs pass on the base and fail on the head. re.match of both $ patterns succeeds and stops before one trailing \n (end is the token length). fullmatch does not. int('3\n') and int('4\n') both return the integer, so the regex is the only gate. [verified]
PYTHONPATH=/tmp/soko-base python3 /tmp/review/probe68.py
FRACTION '3/4\n': ACCEPTED Fraction(3, 4)
FRACTION '3\n': ACCEPTED Fraction(3, 1)
FRACTION '-5\n': ACCEPTED Fraction(-5, 1)
AUDIT witness_newline: passed=True status=VERIFIED rules=[]
AUDIT pin_newline: passed=True status=VERIFIED rules=[]

PYTHONPATH=/tmp/soko-68 python3 /tmp/review/probe68.py
FRACTION '3/4\n': REJECTED ValueError
FRACTION '3\n': REJECTED ValueError
FRACTION '-5\n': REJECTED ValueError
AUDIT clean: passed=True status=VERIFIED rules=[]
AUDIT witness_newline: passed=False status=REJECTED rules=['F08_INVALID_WITNESS_SHA256']
AUDIT pin_newline: passed=False status=REJECTED rules=['F03_TCB_MANIFEST_UNLOCKED']
ZFRAC '3/4\n': dollar_fullmatch=False Zmatch=False
  1. Known-answer tests pass at the head, including under -O. [verified]
cd /tmp/soko-68 && python3 -m unittest tests.test_anchored_fullmatch -v
cd /tmp/soko-68 && python3 -O -m unittest tests.test_anchored_fullmatch -v
Ran 3 tests in 0.000s
OK

3/4 parses as Fraction(3, 4) and -5 as -5. The clean 64-hex certificate stays passed=True. [verified]

  1. Restoring the base sources and keeping the new tests fails the two new checks. The canonical parse still passes. -O does not hide it, because the checks are assertRaises and a raised AssertionError, not assert statements. Restored afterward; git diff was empty and fullmatch was back at the three call sites. [verified]
git show 41b6f9ca54cc24954adcd3e88149c2371a4478e6:experiments/landmark_dual_bounds/hero_assignment_bounds.py > experiments/landmark_dual_bounds/hero_assignment_bounds.py
git show 41b6f9ca54cc24954adcd3e88149c2371a4478e6:mde_soko/domain_oracle.py > mde_soko/domain_oracle.py
python3 -m unittest tests.test_anchored_fullmatch -v
python3 -O -m unittest tests.test_anchored_fullmatch -v
FAILED (failures=2)
AssertionError: ValueError not raised
AssertionError: trailing newline on the witness digest was accepted: {'passed': True, 'epistemic_status': 'VERIFIED', ...}
  1. Full suite, python3 -m unittest discover -s tests -v. Same three failures on the base and the head. They are clang missing <algorithm> in three pre-existing C++ compile tests. Not this diff. [verified]
base: Ran 434 tests in 301.244s  FAILED (failures=3, skipped=6)
head: Ran 437 tests in 320.613s  FAILED (failures=3, skipped=6)

The three new tests are ok inside the head suite. The extra three tests are exactly this PR. Skips are DRAT_TRIM and original-engine HTML env vars, same six on the base. [verified]

  1. Gaps. No other call site of _STRICT_FRAC_RE or SHA256_64_RE. soko_mcp/integrity.py already uses fullmatch on splitlines(), so a manifest newline is not part of the token. [verified]

$ left in the pattern is not a remaining hole under fullmatch on 3.12.3: fullmatch and \Z both reject 3/4\n. .match still accepts it, and the new tests fail if a site goes back. [verified]

Already rejected on the base, so this PR does not change them: a second newline, \r, \r\n, a space, a leading space, +3/4, 3/04, uppercase hex, a short digest. [verified]

[0-9] blocks 3/4 on both sides, even though int('3') is 3. [verified]

The new fraction test only feeds 3/4\n. 3\n and -5\n take the same fullmatch and are rejected, but nothing in the suite names them. [verified]

Line-oriented $ plus re.M in the CNF and catalog parsers is a different use: the newline is the line separator, and p cnf 1 2 extra does not match. Those patterns use \d, which does match 1. They are not certificate tokens and this PR does not touch them. [verified]

#69 still accepts a witness digest plus \n, because that fix is not in this commit. git merge-tree --write-tree of the two heads exits 0, and the merged tree has both fullmatch and F00_STATUS_ABSENT. #70 is test-only and merges clean as well. No overlap that drops a fix. [verified]


Verdict: APPROVE

Reasons: The trailing-newline inputs (3/4\n, 3\n, -5\n, and a witness or pin digest followed by \n) are accepted on the base and rejected at the head. The three new tests fail when the base sources are restored, also under -O. The full suite has the same three failures on the base and the head: the three existing C++ compile tests can't find <algorithm>, and they don't touch this diff. Non-blocking: add 3\n and -5\n to the test, and drop the leftover $ in the patterns. This fix and #69 merge cleanly, and each head still has the other's bug until both land.

@ahrazzle

Copy link
Copy Markdown
Owner

Ready to mark ready. grk-proof approved this PR at 9ccc9f489a28f3673da012a55e2d7226dffb6269, and the approval is posted above. It is still a draft, and the PR body does not say a reviewer may mark it ready or merge it, so that step is left to the author.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anchored fraction and digest checks accept a trailing newline

2 participants