Skip to content

Add contract and transparency pass#16

Draft
keyboardDrummer wants to merge 317 commits intomainfrom
issue-924-contract-and-proof-pass
Draft

Add contract and transparency pass#16
keyboardDrummer wants to merge 317 commits intomainfrom
issue-924-contract-and-proof-pass

Conversation

@keyboardDrummer
Copy link
Copy Markdown
Owner

@keyboardDrummer keyboardDrummer commented Apr 21, 2026

Builds on:

No longer, maybe we can close this:

Summary

Add these passes:

  • [New] EliminateReturnStatements: rewrite return to exit statements, needed for the next pass.
  • [New] ContractPass: translate away pre and postconditions entirely by introducing assertion and assumptions at call sites and at procedure starts and ends
  • [New] TransparencyPass: for each Core procedure, generate a function with the same signature and name suffixed with $asFunction. If a Core procedure is marked as transparent, attempt to generate a functional version of it, where assertions are erased and all calls are to functional versions. Tie the functional version to the procedure using a free postcondition.
  • [Existing] Lift assertions, assumptions and procedure calls when they occur in expressions.
  • [Follow-up] AxiomatizeExpressionAssumptionsPass: erase assumptions in Core function expressions by introducing functions and axioms.

The effect of the contract and transparency pass:

  1. Allow postconditions on functions
  2. Allow calling procedures from contracts
  3. Improve diagnostics related to contracts, using the correct verbiage "precondition" and "postcondition" instead of "assertion"
  4. Allow transparent procedures IF they have an expression body
  5. Allow assertions in transparent procedures and functions

The combined effect of 2 and 4 is that there is no more difference between Laurel functions and transparent procedures.

TODO

  • Differentiate between bugs and user errors in LaurelToCoreTranslator translateExpr
  • Add a free postcondition to the Core procedure to tie it to its functional counterpart.
  • Lift all calls inside expressions in Core procedure bodies, since they are calls to procedures and are not allowed.
  • Let all remaining calls from expressions - which is all calls in Core functions, and all calls in the free procedure postconditions - be to Core functions, and other calls to procedures.
  • Rename FunctionsAndProofsProgram to UnorderedCoreWithLaurelTypes and FunctionsAndProof.lean to TransparencyPass.lean

Follow-up work

  • Remove the 'functional' keyword from the Laurel grammar
  • Lift assumptions in expressions to axioms.
  • In the transparency phase, if something has no asserts and only calls functions, only create a function and no procedure
  • Move the transparency phase so its Core->Core instead of UnorderedCoreWithLaurelTypes -> UnorderedCoreWithLaurelTypes

keyboardDrummer-bot and others added 23 commits May 1, 2026 18:36
At most call sites, a Variable was wrapped in StmtExpr.Var to create a
StmtExprMd, then immediately unwrapped by stmtExprToVar. Instead, keep
the VariableMd and use it directly in Assign targets.

- Rename freeVar to freeVarMd (returns VariableMd) and add freeVarExpr
  (returns StmtExprMd) for expression positions
- Change maybeExceptVar and nullcall_var to VariableMd
- Use mkVariableMd directly for targetExpr and fieldAccess
- stmtExprToVar is retained only for the 2 call sites where the
  StmtExprMd comes from translateExpr
…ent procedures (strata-org#1076)

### Changes
#### Functional
- Add a resolution check that disallows transparent bodies on
non-functional procedures. A procedure declared with `procedure` (not
`function`) that has no `opaque` clause now emits a diagnostic:
`transparent bodies on procedures are not yet supported. Add 'opaque';
to make the procedure opaque`
- When a procedure has a body, always use the body to determine whether
it has heap parameters, instead of always using the modifies clause
- Improve error message when modifies clause can not be proven, so it
refers to "modifies clause" instead of "assertion"

#### Bug fixes and debugging improvements
- Fix a bug in Laurel's Resolution.lean that caused a later error "could
not infer type"
- Change the error "could not infer type" to "bug in Laurel: unknown
type encountered while translating to Core"
- Replace many usages of empty source locations with concrete ones
- Fix defaults for LaurelTranslateOptions and LaurelVerifyOptions

### Testing
- Many existing tests have been updated to add `opaque`
- Added the test `T20_TransparentBodyError.lean`

---------

Co-authored-by: keyboardDrummer-bot <keyboardDrummer-bot@users.noreply.github.com>
Co-authored-by: Remy Willems <rwillems@amazon.com>
Co-authored-by: Michael Tautschnig <mt@debian.org>
Co-authored-by: Shilpi Goel <shigoel@gmail.com>
Co-authored-by: Robin Salkeld <salkeldr@amazon.com>
Co-authored-by: thanhnguyen-aws <ntson@amazon.com>
@keyboardDrummer keyboardDrummer force-pushed the issue-924-contract-and-proof-pass branch from da18905 to 3ce6673 Compare May 4, 2026 13:17
@github-actions github-actions Bot added the SMT label May 4, 2026
@github-actions github-actions Bot added the Git conflicts PR has merge conflicts with the base branch label May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Core Git conflicts PR has merge conflicts with the base branch GOTO Laurel Python SMT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants