Dafny: a cross-file contract that names a helper from its own file is lifted without the helper (unresolved, or opaque when imported)

Open
#307 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
43/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript

Research direction

The report names i6lib.ts and i6.ts as reproductions, but does not identify implementation files or tests. Start by tracing how lsc check --backend=dafny i6.ts lifts imported function contracts and how Dafny output is generated. Reproduce the unresolved helper and opaque axiom cases; done means helper-dependent contracts either include transparent helper bodies or report the unsupported dependency at lift time.

Written by the indexing model from the issue text.

Description

Version: lsc 0.6.10 (npm), Dafny 4.11.

When file B calls a verified function from file A, lsc lifts A's //@ ensures into B's .dfy as an {:axiom} signature. If that ensures calls a helper predicate defined in A, the helper doesn't come with it.

i6lib.ts verifies on its own (2 verified, 0 errors):

//@ backend dafny
export function isPos(n: number): boolean {
  //@ verify
  return n > 0
}

export function bump(n: number): number {
  //@ verify
  //@ requires n >= 0
  //@ ensures isPos(\result)
  return n + 1
}

i6.ts:

//@ backend dafny
import { bump } from './i6lib.ts'

export function twice(n: number): number {
  //@ verify
  //@ requires n >= 0
  //@ ensures \result > 0
  return bump(bump(n))
}

lsc check --backend=dafny i6.ts emits:

function {:axiom} bump(n: int): int
  requires (n >= 0)
  ensures isPos(bump(n))
i6.dfy(5,10): Error: unresolved identifier: isPos

If B also imports isPos and calls it, the helper is emitted as a bodiless axiom, function {:axiom} isPos(n: int): bool. The lifted ensures then tells B nothing. Here bump(bump(n)) can't establish the inner call's requires n >= 0:

import { bump, isPos } from './i6lib.ts'
export function twice(n: number): boolean {
  //@ verify
  //@ requires n >= 0
  return isPos(bump(bump(n)))
}
i6x.dfy(12,12): Error: function precondition could not be proved
i6x.dfy(6,14): Related location: this proposition could not be proved
  |
6 |   requires (n >= 0)

Naming isPos only in B's own //@ ensures leaves it unresolved, as in the first case.

Expected: a lifted contract carries the pure helpers it mentions, with their bodies, the same way they are emitted in A's own .dfy. Or lsc reports, at lift time, that the contract depends on a helper it can't bring in.

Suggested direction: when lifting an imported function's spec, collect the pure functions it references, transitively, and emit them as transparent functions with bodies. Emitting them as axioms gives B nothing to reason with.

Workaround: write cross-file contracts without helpers, e.g. //@ ensures \result > 0 instead of isPos(\result). With that, i6.ts verifies.

Dominant language
TypeScript
Stars
113
Forks
13
Avg merge
15h 35m
Merged PRs (30d)
56

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from midspiral/LemmaScript

All issues in midspiral/LemmaScript

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.