Differential fuzzer for Z3 encoder (decidability Step 2.5)#64
Merged
Conversation
Property-based fuzzer (hypothesis) verifying checker.py's encoder produces formulas semantically equivalent to what interpreter.py computes at runtime. Generates random condition ASTs and deontic statements paired with concrete fact bindings, evaluates both paths via a round-trip oracle, and asserts agreement. - Oracle catches the full exception surface on both sides ((_RuntimeError, TypeError) interpreter-side; (UnencodableConstruct, NonlinearArithmetic, z3.Z3Exception) encoder-side) as skips, never as failures. - Generators respect operator-type compatibility to keep the skip rate low (~0.1% oracle-level skips; hypothesis's own internal choice-budget overrun on the recursive condition strategy accounts for the rest of its "invalid examples" statistic). - Zero disagreements found in standard (500 examples) or heavy (LIMINATE_FUZZ_HEAVY=1, 5000 examples) mode across all three property tests. - Along the way: found interpreter._eval_value has no NameRef branch in condition value position (BareWord only) and that raw-double float generation could manufacture IEEE-754-vs-exact-rational precision mismatches at epsilon scale — both fixed in the generator rather than the frozen encoder/interpreter. checker.py, interpreter.py, and analyzer.py are untouched. Vocabulary unchanged at 61 words. Suite: 1763 -> 1775 (net +12), zero regressions. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Property-based differential fuzzer (Trust Infrastructure Addendum v1.0r §88.6) verifying that the Z3 encoder (
checker.py, PR #63) produces formulas semantically equivalent to what the interpreter (interpreter.py) computes at runtime. Generates random condition ASTs and deontic statements paired with concrete fact bindings, evaluates both paths via a round-trip oracle, and asserts agreement.tests/test_fuzzer.pyis new;pyproject.tomlgainshypothesisin thedevextra + afuzzerpytest marker;.gitignoregains.hypothesis/.checker.py,interpreter.py, andanalyzer.pyare byte-identical to main (verified viagit diff).Results
LIMINATE_FUZZ_HEAVY=1, 5000 examples/test): 0 disagreements across all 3 property tests.interp_runtime_error, 1interp_type_error, 0 encoder-side skips). Hypothesis's own "invalid examples" statistic (~13-17%) is a separate, internal choice-budget overrun on the recursive condition strategy, confirmed via debug-verbosity run — not oracle skips.Findings along the way
Two generator-side fixes (not encoder/interpreter changes):
interpreter._eval_valuehas noNameRefbranch in condition value position (onlyBareWord) — the original spec assumed otherwise; generator now usesBareWordonly there.x - 1.6e-256 == x); floats are now rounded to 2dp (currency-like), matching realistic literal shapes.Both are documented inline in the test file.
Test plan
python -m pytest -q— 1775 passedpython -m pytest tests/test_fuzzer.py -v --tb=short— 12 passedLIMINATE_FUZZ_HEAVY=1 python -m pytest tests/test_fuzzer.py -v --hypothesis-show-statistics— 0 disagreements at 5000 examples/testgit diff main -- src/liminate/checker.py src/liminate/interpreter.py src/liminate/analyzer.py— empty🤖 Generated with Claude Code