LemmaScript icon indicating copy to clipboard operation
LemmaScript copied to clipboard

lsc check accepts added requires/ensures lines in .dfy, so a proof file can make obligations vacuous

Open robertpenner opened this issue 2 weeks ago • 0 comments

This was generated by AI during triage.

Summary

lsc check treats any line that appears in foo.dfy but not in foo.dfy.gen as an allowed proof addition. additionsOnly in tools/src/dafny-commands.ts (checked on main at 566df0d) rejects only deleted lines. An added requires, assume, or {:axiom} passes the check. Each of these weakens what is proved while lsc check still reports success.

Reproduction

Observed with lemmascript 0.6.8 and Dafny 4.11.0. The code involved is unchanged on main.

  1. Write a function with a guard in its contract and run lsc gen, so that counter.dfy and counter.dfy.gen both contain:

    function increment(c: Counter): Counter
      requires inRange(c) && belowMaximum(c)
    
  2. Remove belowMaximum(context) from the TypeScript //@ requires (or from the guard in the body) and run lsc gen again. counter.dfy.gen is regenerated without the clause. counter.dfy is left as it was.

  3. Run lsc check. It reports all obligations verified. The diff from .dfy.gen to .dfy shows the stale requires ... && belowMaximum(c) line as an addition, so the check accepts it and Dafny verifies the old, stronger-precondition model instead of the current source.

The same check accepts lines added inside a generated header. Adding two lines to a generated contract lemma:

lemma increment_ensures(context: Context)
  requires inRange(context)
  requires belowMaximum(context)
  requires false   // added
  ensures false    // added
  ensures inRange(increment(context))

and running lsc check --backend=dafny quantityCounter.ts regenerates .dfy.gen, passes the diff check, and prints Dafny program verifier finished with 11 verified, 0 errors, including the proof of ensures false. It also accepts new declarations that use assume or {:axiom}, which a proof addition can then rely on. Putting {:axiom} on an existing generated line does count as a modification and is rejected.

Expected

Proof additions should not be able to change what the generated declarations claim. Possible rules:

  • Reject added lines that fall inside a generated declaration's header (requires, ensures, decreases, reads, attributes). Allow new declarations and lemma bodies.
  • Reject assume and {:axiom} in proof additions unless explicitly allowed by configuration.
  • Optionally, have lsc check warn when .dfy predates the latest .dfy.gen and the regen merge was not run.

Context

We work around this in a downstream runner by requiring the generated text to appear byte-for-byte in the proof file, allowing only appended declarations and lemma calls, and refusing assume and attributes. We would prefer to rely on lsc check for this. Related, closed: #280 (regen merge conflicts), #192 (a translation that verified the wrong model).

robertpenner avatar Nov 14 '26 23:11 robertpenner