Feature: check that `//@ extern` axioms are consistent (an unsatisfiable one makes every proof that reaches it vacuous)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 48/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- backend-api-design, testing-qa
Research direction
Start by reading how lsc check emits and verifies Dafny code for //@ extern contracts, then inspect the existing handling of string semantics and the linked issue #301 for context. The report describes a symbolic probe and edge-value probes, with Dafny's --filter-symbol to check only those probes; reproduce the surrogate example first. Done means contradictory extern axioms are reported while failed or timed-out probes remain inconclusive, with the unicode-scalar surrogate case covered.
Written by the indexing model from the issue text.
Description
Version: lsc 0.6.10 (npm), Dafny 4.11.
An //@ extern function's //@ ensures is trusted. It is emitted as an {:axiom} function. If the ensures can't hold in the model, any proof that reaches the extern is vacuous, and lsc says nothing.
One easy way to get there: under the default "string-semantics": "unicode-scalar" (--unicode-char:true), a Dafny char can't be a surrogate. An extern that describes JavaScript's UTF-16 behaviour, e.g. a lone surrogate, is then false:
//@ backend dafny
/** A lone high surrogate, as JavaScript can hold it. */
export function loneSurrogate(): string {
//@ extern
//@ ensures \result.length === 1 && \result.charCodeAt(0) === 0xD800
return String.fromCharCode(0xD800)
}
export function width(s: string): number {
//@ verify
//@ ensures \result === 42
return loneSurrogate().length + s.length
}
function {:axiom} loneSurrogate(): string
ensures ((|loneSurrogate()| == 1) && ((loneSurrogate()[0] as int) == 55296))
function width(s: string): int
{
(|loneSurrogate()| + |s|)
}
lemma width_ensures(s: string)
ensures (width(s) == 42)
{
}
Dafny program verifier finished with 2 verified, 0 errors
In JavaScript, width("abc") is 4. With //@ option string-semantics javascript-utf16 (and //@ option dafny-library local), the same file correctly fails on width(s) == 42. The extern is fine as JavaScript, but it contradicts the unicode-scalar model.
Surrogates are only one case. Any hand-written extern axiom can be contradictory, e.g. a typo, or two ensures that can't hold together. The effect is the same: the file reports green and proves nothing.
Suggested feature:
-
For each extern, have
lsc checkemit a sanity lemma that tries to provefalsefrom its axioms. If it verifies, fail or warn: "externloneSurrogate: its ensures are unsatisfiable under the current model". For an extern with parameters, the lemma would take arbitrary arguments satisfying therequires:lemma loneSurrogate_consistent() ensures false { var _ := loneSurrogate(); }I checked this by hand with
dafny verify --unicode-char:true. With55296, the lemma verifies, which flags the axiom. With65, it fails as it should. A failure or timeout is inconclusive, so it should stay silent. Only a proof offalseis reported.
A symbolic probe catches only an axiom that is false for EVERY argument. The case we actually hit was partial:codePointText(n)(wrappingString.fromCodePoint) promised two UTF-16 units forn > 0xFFFF, so it was contradictory only for astraln, andlemma P(n: int) requires 0 <= n <= 0x10FFFF ensures false { var _ := codePointText(n); }does not verify. What found it was instantiating the axiom on fixed edge values:var _ := codePointText(65536);provesfalse. We now run, per axiom, the symbolic probe plus one probe per edge value forint/nat/bool/stringparameters (0, ±1, 0xD800, 0xDFFF, 0x10000, 0x10FFFF and one past it;"", letters, path characters), withdafny verify --filter-symbol <probe prefix>so only the probes are checked (1-2 s a file). Dafny's own--warn-contradictory-assumptionsdid not help: it does not report function postconditions proved from a contradiction, and it was silent on this file. -
More narrowly: under
unicode-scalar, warn when an extern's contract mentions a code unit in0xD800..0xDFFF(charCodeAt(...) === 0xD8xx,\uD8xxin a literal), since nocharhas that value.
This complements #301, which is about proof files adding obligations. Here the obligation comes from the .ts itself.
Workaround: none in lsc. Review extern contracts by hand, and verify files whose externs talk about UTF-16 code units under "string-semantics": "javascript-utf16".
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from midspiral/LemmaScript
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
midspiral/LemmaScript#355 · 1 comment ·
Maintainers usually reply within 1 day
-
In a pure function body, a `const` declared inside an `if` branch stays in scope after the `if`, so a false `ensures` can verifyPossibly taken @namin claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
midspiral/LemmaScript#362 ·
Maintainers usually reply within 1 day
-
A `const` or `let` inside a bare `{ }` block stays in scope after the block, so a false `ensures` can verifyPossibly taken @namin claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 15/100
midspiral/LemmaScript#361 ·
Maintainers usually reply within 1 day
-
A closure declared before a same-name `const` or `let` in its block reads the outer variable, so a false `ensures` can verifyPossibly taken @namin claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 18/100
midspiral/LemmaScript#360 ·
Maintainers usually reply within 1 day
-
An assignment used as an expression, such as `(x = 7);` or `const y = (x = 7)`, is extracted as an equality test, so a false `ensures` can verifyPossibly taken @namin claimed this today. Open
Difficulty 3/5 Half a day Newbie friendliness 30/100
midspiral/LemmaScript#356 · 1 reaction ·
Maintainers usually reply within 1 day
All issues in midspiral/LemmaScript
Similar issues
-
bug done
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
neavo/LinguaGacha#1124 ·
Maintainers usually reply within 1 day
-
[fullsend] E2E: backstage-microsoft-auth — catalogQuery missing error handler for network errorsPossibly taken @fullsend-ai-coder claimed this today. Opene2e-failure ready-to-code
Difficulty 2/5 Under an hour Newbie friendliness 78/100
redhat-developer/rhdh-plugin-export-overlays#4821 · 1 comment ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
brylie/mission-island#225 ·
Maintainers usually reply within 1 day
-
status/need-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
google-gemini/gemini-cli#30412 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day