feat(transform): Add ProcBodyVerify transformation#509
Merged
aqjune-aws merged 142 commits intomainfrom Apr 6, 2026
Merged
Conversation
Add transformation that converts a procedure into a statement that verifies the procedure's body against its contract. The transformation: - Initializes all input parameters, output parameters, and modified globals - For each modified global g, creates old_g (pre-state) and g (post-state) - Converts non-free preconditions to assume statements - Wraps the body in a labeled block - Converts non-free postconditions to assert statements Includes: - Strata/Transform/ProcBodyVerify.lean: Main transformation implementation - StrataTest/Transform/ProcBodyVerify.lean: Unit tests (placeholder) - StrataTest/Transform/ProcBodyVerifyCorrect.lean: Correctness proof (placeholder) TODO: - Get actual types from program context for modified globals - Add comprehensive unit tests - Complete correctness proof
- Add proper type lookup for modified globals using getIdentTy! - Add unit test verifying transformation succeeds - Remove placeholder type (was using int, now looks up actual types) The transformation now properly: - Looks up types from the program context for modified globals - Creates old_g and g variables with correct types - Initializes all parameters and modified globals - Converts preconditions to assumes and postconditions to asserts
Add structure for correctness proof with: - Helper functions to extract assertions and assumptions - Placeholder theorems for precondition and postcondition correspondence - Main soundness theorem (placeholder) The proof structure documents the key properties that need to be proven: 1. Preconditions in the procedure become assumptions in the verification statement 2. Postconditions in the procedure become assertions in the verification statement 3. If verification fails, the call can fail (main soundness property)
- Use DDM to parse test programs instead of manually constructing AST - Test procedure with modifies clause and old variables - Test simple procedure without modifies - Tests verify transformation succeeds on realistic programs
- Prove requiresToAssumes produces only assume statements - Prove ensuresToAsserts produces only assert statements - Add helper functions for counting non-free conditions - Improve theorem documentation
- Prove transformation preserves procedure body in output - Improve soundness theorem documentation - Explain what full proof would require
- Test that free preconditions/postconditions are correctly filtered - Verify transformation handles mixed free and non-free specs
- Test procedure modifying multiple global variables - Verify old_g variables created for each modified global
- Tests now verify transformation produces correct block structure - Check that output has expected label (verify_<ProcName>) - Tests cover: modifies clauses, free specs, multiple globals - Use DDM to parse input programs - All tests pass with #guard_msgs
- Each test now displays the actual transformed statement - Shows complete structure: inits, assumes, body block, asserts - Demonstrates how old_g variables are created for modified globals - Verifies free specifications are correctly filtered out
- Remove toString to display properly formatted output - No more escaped newlines in guard_msgs - Output is now human-readable
- Create showTransformed helper to reduce code duplication - Inline program definitions directly in #eval calls - Remove separate Test1-4 definitions - Tests now more concise and easier to read
- Add Core.formatStatement function to format statements using DDM - Update test outputs to show readable Core syntax instead of AST - Tests now display var declarations, assumes, and asserts in proper syntax
Free specifications are assumptions that won't be checked at call sites. They should be included in the verification statement as assumes.
- Rewrite correctness file to use small-step semantics - Add helper lemmas for requiresToAssumes and ensuresToAsserts lengths - Add main soundness theorem (structure proof in progress) - Remove old big-step based helpers
- Add requiresToAssumes_preserves_exprs lemma - Add ensuresToAsserts_preserves_exprs lemma - These lemmas establish that the transformation preserves contract expressions
The main soundness theorem has one sorry remaining - proving that procToVerifyStmt produces a block statement. This is trivially true by construction (the last line returns Stmt.block) but requires navigating through the ExceptT/StateM monad stack. All other helper lemmas are proven: - requiresToAssumes_length - ensuresToAsserts_length - requiresToAssumes_preserves_exprs - ensuresToAsserts_preserves_exprs - procBodyVerify_produces_block (helper for structure)
Completed proofs: - ensuresToAsserts_length: induction on list - requiresToAssumes_preserves_exprs: direct from definition - ensuresToAsserts_preserves_exprs: filterMap membership 3 sorries remaining (1 structural, 2 semantic)
The procBodyVerify_produces_block_structure theorem is trivially true by inspection (last line returns Stmt.block), but proving it requires unwinding the monad stack which is tedious. Remaining: 3 sorries (1 structural, 2 semantic)
Changed from call-based to body-based correctness: - Soundness: verification failure → contract violation - Completeness: verification success → contract satisfaction This better reflects that ProcBodyVerify verifies procedure bodies against their contracts, not procedure calls. Still 3 sorries (all substantive proofs)
Documented the proof approach for soundness and completeness: - Both require frame reasoning and semantic lemmas - Need to relate verification context to isolated body execution - Require lemmas about block evaluation, assumes, and asserts These are substantial proofs requiring significant infrastructure. Status: 4 theorems proven, 3 sorries remaining (all substantive)
Tried to prove procBodyVerify_produces_block_structure by unwinding the monad, but this is tedious. Started a helper lemma for assert checking but hit mutual induction issues. The main semantic theorems require substantial infrastructure: - Frame reasoning lemmas - Determinism/uniqueness of evaluation - Lemmas about how init/assume/assert interact with stores - Decomposition lemmas for block evaluation Status: 4 theorems proven, 3 sorries (1 structural, 2 semantic)
Added useful lemma showing block evaluation is equivalent to evaluating the list of statements inside. This will be useful for decomposing the verification statement. Status: 5 theorems proven, 3 sorries remaining
Added two key lemmas: - eval_assert_implies_condition: assert success → condition holds - eval_assume_implies_condition: assume success → condition holds These extract the semantic meaning from successful evaluation. Status: 7 theorems proven, 3 sorries remaining
Key lemma: if a list of statements containing an assert evaluates successfully, then the assert's condition held at some point. Uses structural recursion on the list to handle mutual induction. Status: 8 theorems proven, 3 sorries remaining
Simple wrapper showing postconditions appear in generated asserts. Status: 9 theorems proven, 3 sorries remaining
New lemmas: - eval_stmts_concat_with_assert: Assert in suffix of concat - postcondition_expr_in_getCheckExprs: Expression membership Added PROOF_PROGRESS.md to track completion (11/12 = 92%) Status: 11 theorems proven, 3 sorries remaining
13ebf55 to
aa507d3
Compare
c4a473a to
f17aad6
Compare
atomb
previously approved these changes
Apr 3, 2026
Contributor
atomb
left a comment
There was a problem hiding this comment.
That was a good catch! A one-identifier change can make so much difference.
It's encouraging that the proof became substantially longer.
I left a few comments (all from Kiro), but they're all minor proof style things.
atomb
approved these changes
Apr 6, 2026
aqjune-aws
approved these changes
Apr 6, 2026
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
Adds
ProcBodyVerifytransformation converting procedures to verification statements. ComplementsCallElimby providing the callee's view of verification.Example
Input procedure:
procedure P(x: int) returns (y: int) spec { modifies g; requires x > 0; ensures y > 0; ensures g == old g + 1; } { y := x; g := g + 1; }Output verification statement:
Implementation
getIdentTy!for proper type lookupTesting
DDM-based tests verify transformation output matches expected structure for: