lemmascript 0.6.11 → 0.6.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lemmascript",
3
- "version": "0.6.11",
3
+ "version": "0.6.12",
4
4
  "description": "A verification toolchain for TypeScript — generates Lean 4 or Dafny from annotated TS",
5
5
  "type": "module",
6
6
  "engines": {
@@ -10,18 +10,30 @@ function writeGen(genPath, text) {
10
10
  writeFileSync(genPath, text);
11
11
  console.log(`Generated: ${genPath}`);
12
12
  }
13
- export function dafnyGen(genPath, dfyPath, text) {
13
+ export function dafnyGen(genPath, dfyPath, text, basePath) {
14
+ // Preserve the previous generation as the three-way merge base when overwriting
15
+ // a changed .dfy.gen beside an existing .dfy, so a later `lsc regen` still
16
+ // merges from the generation the proof derives from.
17
+ if (basePath && existsSync(dfyPath) && existsSync(genPath) && !existsSync(basePath)) {
18
+ const oldGen = readFileSync(genPath, "utf-8");
19
+ if (oldGen !== text)
20
+ writeFileSync(basePath, oldGen);
21
+ }
14
22
  writeGen(genPath, text);
15
23
  if (!existsSync(dfyPath)) {
16
24
  writeFileSync(dfyPath, text);
17
25
  console.log(`Created: ${dfyPath}`);
18
26
  }
19
27
  }
20
- export function dafnyCheckDiff(genPath, dfyPath, log) {
28
+ export function dafnyCheckDiff(genPath, dfyPath, log, basePath) {
21
29
  const ok = additionsOnly(genPath, dfyPath);
22
- if (!ok)
30
+ if (!ok) {
23
31
  log?.finish({ stage: "diff", exit: 1, dfyPath });
24
- return ok;
32
+ return false;
33
+ }
34
+ if (basePath && existsSync(basePath))
35
+ unlinkSync(basePath);
36
+ return true;
25
37
  }
26
38
  function additionsOnly(genPath, dfyPath) {
27
39
  for (const filePath of [genPath, dfyPath]) {
@@ -44,7 +56,7 @@ function additionsOnly(genPath, dfyPath) {
44
56
  }
45
57
  let diff = "";
46
58
  try {
47
- diff = execFileSync("git", ["diff", "--no-index", "--minimal", "--no-color", "--no-ext-diff", "--no-textconv", "--text", "--", genPath, dfyPath], { encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] });
59
+ diff = execFileSync("git", ["diff", "--no-index", "--minimal", "--no-color", "--no-ext-diff", "--no-textconv", "--text", "--", genPath, dfyPath], { encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: Infinity });
48
60
  }
49
61
  catch (e) {
50
62
  // `git diff --no-index` exits 1 for a valid, non-empty comparison. Every
@@ -79,10 +91,10 @@ function additionsOnly(genPath, dfyPath) {
79
91
  console.error(" " + d);
80
92
  return false;
81
93
  }
82
- // Added lines must not bypass the verifier or change its options.
94
+ // Added lines must not bypass the verifier, weaken generated contracts, or change verifier options.
83
95
  const violations = proofAdditionViolations(readFileSync(genPath, "utf-8"), readFileSync(dfyPath, "utf-8"), path.basename(dfyPath));
84
96
  if (violations.length > 0) {
85
- console.error(`ERROR: ${path.basename(dfyPath)} has proof additions that bypass verification:`);
97
+ console.error(`ERROR: ${path.basename(dfyPath)} has disallowed proof additions:`);
86
98
  for (const v of violations)
87
99
  console.error(" " + v);
88
100
  return false;
@@ -3,7 +3,6 @@
3
3
  */
4
4
  import { decimalNumberLiteral, exactIntegerLiteral, usesName, usesNameInDecl, usesNameInStmts } from "./ir.js";
5
5
  import { freshNameWhere, userNames } from "./names.js";
6
- import { renameFreeVar } from "./transform.js";
7
6
  import { DEFAULT_OPTIONS, resolveOptions } from "./config.js";
8
7
  /** Appended to a function's name for the lemma that carries its `//@ ensures`. */
9
8
  export const ENSURES_LEMMA_SUFFIX = "_ensures";
@@ -15,21 +14,13 @@ export const SPEC_FUNCTION_SUFFIX = "_fun_spec";
15
14
  function freshBinder(base, ...wrapped) {
16
15
  return freshNameWhere(base, name => wrapped.some(w => usesName(w, name)));
17
16
  }
18
- /** Binder + body for lowering a single-return lambda to a comprehension whose
19
- * receiver is emitted inside the binder's scope. TS scoping keeps the receiver
20
- * outside the lambda, so a lambda param sharing a name with anything free in
21
- * the receiver would capture it — e.g. `mk(n).some(n => …)` naively emitting
22
- * `exists n :: n in mk(n) && …`. Alpha-rename the param out of the way (and
23
- * its free uses in the body); the zero-param default must also dodge free
24
- * names in the body. */
17
+ /** Binder for lowering a single-return lambda to a comprehension whose
18
+ * receiver is emitted inside the binder's scope. A source parameter is used
19
+ * as is: extraction renames one that shares a name with anything its receiver
20
+ * reads (see LexicalNames), so `mk(n).some(n => …)` arrives as `n_2 => …`.
21
+ * The zero-param default is minted here and must dodge free names itself. */
25
22
  function comprehensionBinder(lam, value, receiver) {
26
- const rawName = lam.params[0]?.name;
27
- if (rawName === undefined)
28
- return { binder: escapeName(freshBinder("x", receiver, value)), body: value };
29
- if (!usesName(receiver, rawName))
30
- return { binder: escapeName(rawName), body: value };
31
- const fresh = freshBinder(rawName, receiver, value);
32
- return { binder: escapeName(fresh), body: renameFreeVar(value, rawName, fresh) };
23
+ return escapeName(lam.params[0]?.name ?? freshBinder("x", receiver, value));
33
24
  }
34
25
  // ── Ty → Dafny type string ─────────────────────────────────
35
26
  function tyToDafny(ty) {
@@ -285,7 +276,12 @@ function wrapQuantifier(sub) {
285
276
  }
286
277
  function emitExpr(e) {
287
278
  switch (e.kind) {
288
- case "var": return e.name === "undefined" ? "None" : escapeName(e.name);
279
+ case "var":
280
+ if (e.name === "undefined") {
281
+ needPreamble("OptionType");
282
+ return "None";
283
+ }
284
+ return escapeName(e.name);
289
285
  case "num": return decimalNumberLiteral(e.value);
290
286
  // Already canonical decimal; Dafny's `int` is mathematical, so no `n` suffix.
291
287
  case "bigint": return e.value;
@@ -473,9 +469,8 @@ function emitExpr(e) {
473
469
  const lam = e.args[0];
474
470
  let p, body;
475
471
  if (lam.kind === "lambda" && lam.body.length === 1 && lam.body[0].kind === "return") {
476
- const cb = comprehensionBinder(lam, lam.body[0].value, e.obj);
477
- p = cb.binder;
478
- body = emitExpr(cb.body);
472
+ p = comprehensionBinder(lam, lam.body[0].value, e.obj);
473
+ body = emitExpr(lam.body[0].value);
479
474
  }
480
475
  else {
481
476
  p = escapeName(freshBinder("x", e.obj, e.args[0]));
@@ -626,8 +621,8 @@ function emitExpr(e) {
626
621
  const ret = lam.body[0];
627
622
  if (ret.kind !== "return")
628
623
  throw new Error("unreachable");
629
- const { binder: p, body: v } = comprehensionBinder(lam, ret.value, e.obj);
630
- const body = emitExpr(v);
624
+ const p = comprehensionBinder(lam, ret.value, e.obj);
625
+ const body = emitExpr(ret.value);
631
626
  return `(set ${p} | ${p} in ${obj} && ${body})`;
632
627
  }
633
628
  }
@@ -701,6 +696,10 @@ function emitExpr(e) {
701
696
  }
702
697
  case "app": {
703
698
  const args = e.args.map(emitExpr);
699
+ // Optional coercions also arrive as applications, including locals
700
+ // whose inferred types never pass through tyToDafny.
701
+ if (!e.ctorOf && (e.fn === "Some" || e.fn === "None"))
702
+ needPreamble("OptionType");
704
703
  if (e.fn === "SetToSeq") {
705
704
  needPreamble("SetToSeq");
706
705
  return `SetToSeq(${args.join(", ")})`;
@@ -1,16 +1,25 @@
1
1
  /**
2
2
  * Check the lines a `.dfy` proof adds to its `.dfy.gen` companion for
3
- * constructs that bypass verification.
3
+ * constructs that bypass verification or weaken generated contracts.
4
+ *
5
+ * Added lines may not contain `assume`, `expect`, `decreases *`, `{:axiom}`,
6
+ * `@Axiom`, `{:verify false}`, `{:only}`, `@VerifyOnly`, or `{:extern}`.
7
+ * Text inside comments (including nested block comments), strings (including
8
+ * verbatim strings), and character literals is ignored.
9
+ *
10
+ * Inside a generated declaration header (before its body `{` or the next
11
+ * declaration for bodyless declarations), added lines may introduce complete
12
+ * `ensures`, `modifies`, `reads`, or `decreases` clauses (other than
13
+ * `decreases *`), but may not add `requires` clauses or extend/split a
14
+ * generated signature or header clause. Auxiliary declarations added in the
15
+ * proof may declare their own `requires` and other clauses freely.
4
16
  *
5
- * Added lines may not contain `assume` statements or `{:axiom}` / `@Axiom`
6
- * attributes. Text inside comments (including nested block comments),
7
- * strings (including verbatim strings), and character literals is ignored.
8
17
  * Separately, added lines may not introduce an `// lsc options:` header,
9
18
  * because verifier flags are read from that header in the proof, and may not
10
19
  * contain line breaks other than `\n` (Dafny ends a `//` comment at `\r`).
11
20
  * A generated line kept in the proof must lex to the same tokens it has in
12
21
  * the generated file, so added comments or strings cannot disable it, and an
13
- * added line may not repeat a generated `assume` / axiom line.
22
+ * added line may not repeat a generated verification-bypass line.
14
23
  */
15
24
  const OPERATORS = ["<==>", "==>", "<==", "==", "!=", "<=", ">=", ":=", "::", "->", "=>", "&&", "||", ".."];
16
25
  /** Dafny identifiers may start with `'` or `?` (`?x` and `'x` are names). */
@@ -135,17 +144,271 @@ function tokensByLine(tokens, lineCount) {
135
144
  lines[t.line]?.push(t.text);
136
145
  return lines.map(l => l.join("\u0000"));
137
146
  }
138
- /** Whether a token sequence contains an `assume`, `{:axiom}` or `@Axiom`. */
147
+ /** Whether a token sequence bypasses verification or assumes an unproved fact. */
139
148
  function trustsFact(tokens, k) {
140
149
  const t = tokens[k].text, following = tokens[k + 1]?.text;
141
150
  if (t === "assume")
142
- return "assume statements are not allowed in proof additions; prove the fact instead";
151
+ return { reason: "assume statements are not allowed in proof additions; prove the fact instead", end: k };
152
+ if (t === "expect")
153
+ return { reason: "expect statements are not allowed in proof additions; prove the fact instead", end: k };
154
+ if (t === "decreases" && following === "*")
155
+ return { reason: "`decreases *` is not allowed in proof additions; provide a termination metric instead", end: k + 1 };
143
156
  if (t === "{:" && following === "axiom")
144
- return "{:axiom} attributes are not allowed in proof additions; give the declaration a proof or body";
157
+ return { reason: "{:axiom} attributes are not allowed in proof additions; give the declaration a proof or body", end: k + 1 };
145
158
  if (t === "@" && following === "Axiom")
146
- return "@Axiom attributes are not allowed in proof additions; give the declaration a proof or body";
159
+ return { reason: "@Axiom attributes are not allowed in proof additions; give the declaration a proof or body", end: k + 1 };
160
+ if (t === "{:" && following === "verify" && !(tokens[k + 2]?.text === "true" && tokens[k + 3]?.text === "}")) {
161
+ const close = findMatchingBrace(tokens, k);
162
+ return {
163
+ reason: "{:verify ...} attributes that disable verification are not allowed in proof additions",
164
+ end: close >= 0 ? close : k + 1,
165
+ };
166
+ }
167
+ if (t === "{:" && following === "only")
168
+ return { reason: "{:only} attributes are not allowed in proof additions; they skip verification of other declarations", end: k + 1 };
169
+ if (t === "@" && following === "VerifyOnly")
170
+ return { reason: "@VerifyOnly attributes are not allowed in proof additions; they skip verification of other declarations", end: k + 1 };
171
+ if (t === "{:" && following === "extern")
172
+ return { reason: "{:extern} attributes are not allowed in proof additions; declare externs in TypeScript with //@ extern", end: k + 1 };
147
173
  return undefined;
148
174
  }
175
+ const CALLABLE_KEYWORDS = new Set(["method", "lemma", "function", "predicate", "constructor"]);
176
+ const DECL_MODIFIERS = new Set(["ghost", "twostate", "least", "greatest", "static", "opaque", "protected", "abstract"]);
177
+ const CONTAINER_KEYWORDS = new Set(["class", "trait", "module"]);
178
+ const NON_CALLABLE_DECLS = new Set([
179
+ "datatype", "codatatype", "type", "newtype", "class", "trait", "module",
180
+ "const", "import", "include", "export",
181
+ ]);
182
+ const SPEC_CLAUSE_KEYWORDS = new Set(["requires", "ensures", "reads", "modifies", "decreases"]);
183
+ const ALLOWED_ADDED_HEADER_CLAUSES = new Set(["ensures", "reads", "modifies", "decreases"]);
184
+ /** Whether `tokens[k]` is a modifier prefixing a declaration (not an identifier like `least` in an expression). */
185
+ function isDeclModifierAt(tokens, k) {
186
+ let i = k;
187
+ while (i < tokens.length && DECL_MODIFIERS.has(tokens[i].text))
188
+ i++;
189
+ if (i === k || i >= tokens.length)
190
+ return false;
191
+ const next = tokens[i].text;
192
+ return CALLABLE_KEYWORDS.has(next) || NON_CALLABLE_DECLS.has(next) || next === "var";
193
+ }
194
+ /** Tokens after a closing `}` that show `{ ... }` was a set literal inside a header, not a body. */
195
+ const HEADER_CONTINUATION_AFTER_BRACE = new Set([
196
+ "requires", "ensures", "reads", "modifies", "decreases", "{",
197
+ "==", "!=", "<", "<=", ">", ">=", "+", "-", "*", "/", "%",
198
+ "&&", "||", "==>", "<==", "<==>", "in", "!", ".", "[", "(", ")", "]", ",", "?", ":", "::", "|", ";",
199
+ "then", "else", "as", "is",
200
+ ]);
201
+ /** Tokens before `{` inside a spec clause that unambiguously introduce a set/multiset literal. */
202
+ const EXPR_BEFORE_BRACE = new Set([
203
+ "requires", "ensures", "reads", "modifies", "decreases",
204
+ "==", "!=", "<=", ">=", "<", "+", "-", "/", "%",
205
+ "&&", "||", "==>", "<==", "<==>", "!", "in", "::", ":=",
206
+ "then", "else", "iset", "multiset", "set",
207
+ ]);
208
+ /** Return the index of the `}` matching `tokens[openIdx]` (`{` or `{:`), or -1. */
209
+ function findMatchingBrace(tokens, openIdx) {
210
+ let depth = 0;
211
+ for (let i = openIdx; i < tokens.length; i++) {
212
+ const text = tokens[i].text;
213
+ if (text === "{" || text === "{:")
214
+ depth++;
215
+ else if (text === "}") {
216
+ depth--;
217
+ if (depth === 0)
218
+ return i;
219
+ }
220
+ }
221
+ return -1;
222
+ }
223
+ /** Whether `{` at `openIdx` inside a declaration header is a set/multiset literal rather than the body `{`. */
224
+ function isHeaderExprBrace(tokens, openIdx, inSpecClause) {
225
+ const closeIdx = findMatchingBrace(tokens, openIdx);
226
+ const afterClose = closeIdx >= 0 ? tokens[closeIdx + 1]?.text : undefined;
227
+ if (afterClose !== undefined && HEADER_CONTINUATION_AFTER_BRACE.has(afterClose))
228
+ return true;
229
+ const prev = openIdx > 0 ? tokens[openIdx - 1]?.text : undefined;
230
+ if (inSpecClause && prev !== undefined && EXPR_BEFORE_BRACE.has(prev))
231
+ return true;
232
+ return false;
233
+ }
234
+ /**
235
+ * Check generated callable declaration headers for added `requires` clauses,
236
+ * added continuations that alter a generated signature or clause, and added
237
+ * clauses that split a multi-line generated clause.
238
+ */
239
+ function checkGeneratedHeaders(tokens, added, report) {
240
+ let parenDepth = 0;
241
+ let bracketDepth = 0;
242
+ const braceStack = [];
243
+ let pendingContainer = false;
244
+ let inGenHeader = false;
245
+ let inAddedHeader = false;
246
+ let headerSawCallable = false;
247
+ let headerHasName = false;
248
+ let inSpecClause = false;
249
+ let inAddedClause = false;
250
+ let declContainerDepth = 0;
251
+ const reportedExtendLines = new Set();
252
+ const resetHeader = () => {
253
+ inGenHeader = false;
254
+ inAddedHeader = false;
255
+ headerSawCallable = false;
256
+ headerHasName = false;
257
+ inSpecClause = false;
258
+ inAddedClause = false;
259
+ };
260
+ for (let k = 0; k < tokens.length; k++) {
261
+ const t = tokens[k];
262
+ const text = t.text;
263
+ const isAdded = added[t.line];
264
+ const prev = k > 0 ? tokens[k - 1].text : undefined;
265
+ if (text === "{:") {
266
+ braceStack.push("attr");
267
+ continue;
268
+ }
269
+ if (text === "{") {
270
+ const inNonContainer = braceStack.some(b => b !== "container");
271
+ if (parenDepth > 0 || bracketDepth > 0 || inNonContainer) {
272
+ braceStack.push("expr");
273
+ }
274
+ else if (pendingContainer) {
275
+ pendingContainer = false;
276
+ resetHeader();
277
+ braceStack.push("container");
278
+ }
279
+ else if ((inGenHeader || inAddedHeader) && isHeaderExprBrace(tokens, k, inSpecClause)) {
280
+ if (inGenHeader && isAdded && !inAddedClause && !reportedExtendLines.has(t.line)) {
281
+ reportedExtendLines.add(t.line);
282
+ report(t.line, "added lines in a generated declaration header must start a new ensures, modifies, reads, or decreases clause and may not extend a generated signature or clause");
283
+ }
284
+ braceStack.push("expr");
285
+ }
286
+ else {
287
+ resetHeader();
288
+ braceStack.push("body");
289
+ }
290
+ continue;
291
+ }
292
+ if (text === "}") {
293
+ braceStack.pop();
294
+ continue;
295
+ }
296
+ const inNonContainer = braceStack.some(b => b !== "container");
297
+ const atDeclLevel = parenDepth === 0 && bracketDepth === 0 && !inNonContainer;
298
+ if (text === "(") {
299
+ if (inGenHeader && isAdded && !inAddedClause && !reportedExtendLines.has(t.line)) {
300
+ reportedExtendLines.add(t.line);
301
+ report(t.line, "added lines in a generated declaration header must start a new ensures, modifies, reads, or decreases clause and may not extend a generated signature or clause");
302
+ }
303
+ parenDepth++;
304
+ continue;
305
+ }
306
+ if (text === ")") {
307
+ if (parenDepth > 0)
308
+ parenDepth--;
309
+ if (inGenHeader && isAdded && !inAddedClause && !reportedExtendLines.has(t.line)) {
310
+ reportedExtendLines.add(t.line);
311
+ report(t.line, "added lines in a generated declaration header must start a new ensures, modifies, reads, or decreases clause and may not extend a generated signature or clause");
312
+ }
313
+ continue;
314
+ }
315
+ if (text === "[") {
316
+ if (inGenHeader && isAdded && !inAddedClause && !reportedExtendLines.has(t.line)) {
317
+ reportedExtendLines.add(t.line);
318
+ report(t.line, "added lines in a generated declaration header must start a new ensures, modifies, reads, or decreases clause and may not extend a generated signature or clause");
319
+ }
320
+ bracketDepth++;
321
+ continue;
322
+ }
323
+ if (text === "]") {
324
+ if (bracketDepth > 0)
325
+ bracketDepth--;
326
+ if (inGenHeader && isAdded && !inAddedClause && !reportedExtendLines.has(t.line)) {
327
+ reportedExtendLines.add(t.line);
328
+ report(t.line, "added lines in a generated declaration header must start a new ensures, modifies, reads, or decreases clause and may not extend a generated signature or clause");
329
+ }
330
+ continue;
331
+ }
332
+ if (atDeclLevel && prev !== ".") {
333
+ // `by method {` follows a function body and is not a new method declaration.
334
+ if (text === "method" && prev === "by")
335
+ continue;
336
+ if (NON_CALLABLE_DECLS.has(text)) {
337
+ resetHeader();
338
+ pendingContainer = CONTAINER_KEYWORDS.has(text);
339
+ continue;
340
+ }
341
+ if (text === "var" && !headerSawCallable) {
342
+ resetHeader();
343
+ pendingContainer = false;
344
+ continue;
345
+ }
346
+ if (CALLABLE_KEYWORDS.has(text) || isDeclModifierAt(tokens, k)) {
347
+ pendingContainer = false;
348
+ if ((!inGenHeader && !inAddedHeader) || headerHasName) {
349
+ inGenHeader = !isAdded;
350
+ inAddedHeader = isAdded;
351
+ headerSawCallable = CALLABLE_KEYWORDS.has(text);
352
+ headerHasName = false;
353
+ inSpecClause = false;
354
+ inAddedClause = false;
355
+ declContainerDepth = braceStack.length;
356
+ }
357
+ else {
358
+ if (CALLABLE_KEYWORDS.has(text))
359
+ headerSawCallable = true;
360
+ if (!isAdded) {
361
+ inGenHeader = true;
362
+ inAddedHeader = false;
363
+ }
364
+ }
365
+ continue;
366
+ }
367
+ if ((inGenHeader || inAddedHeader) && headerSawCallable && !headerHasName) {
368
+ headerHasName = true;
369
+ if (!inGenHeader)
370
+ continue;
371
+ }
372
+ }
373
+ if (!inGenHeader)
374
+ continue;
375
+ const atHeaderClauseLevel = parenDepth === 0 && bracketDepth === 0 && braceStack.length === declContainerDepth;
376
+ if (!isAdded) {
377
+ if (atHeaderClauseLevel) {
378
+ if (SPEC_CLAUSE_KEYWORDS.has(text)) {
379
+ inSpecClause = true;
380
+ inAddedClause = false;
381
+ }
382
+ else if (inAddedClause) {
383
+ report(t.line, "an added clause splits a generated header clause");
384
+ inAddedClause = false;
385
+ }
386
+ }
387
+ continue;
388
+ }
389
+ // Token is on an added line inside a generated declaration header.
390
+ if (atHeaderClauseLevel) {
391
+ if (text === "requires") {
392
+ report(t.line, "added requires clauses are not allowed in generated declaration headers; strengthen preconditions in TypeScript instead");
393
+ inSpecClause = true;
394
+ // Suppress follow-on continuation diagnostics for the body of this rejected clause.
395
+ inAddedClause = true;
396
+ }
397
+ else if (ALLOWED_ADDED_HEADER_CLAUSES.has(text)) {
398
+ inSpecClause = true;
399
+ inAddedClause = true;
400
+ }
401
+ else if (!inAddedClause && !reportedExtendLines.has(t.line)) {
402
+ reportedExtendLines.add(t.line);
403
+ report(t.line, "added lines in a generated declaration header must start a new ensures, modifies, reads, or decreases clause and may not extend a generated signature or clause");
404
+ }
405
+ }
406
+ else if (!inAddedClause && !reportedExtendLines.has(t.line)) {
407
+ reportedExtendLines.add(t.line);
408
+ report(t.line, "added lines in a generated declaration header must start a new ensures, modifies, reads, or decreases clause and may not extend a generated signature or clause");
409
+ }
410
+ }
411
+ }
149
412
  /** Matches the header `dafnyVerifyArgs` reads verifier options from. */
150
413
  const LSC_OPTIONS_HEADER = /^\/\/ lsc options:/m;
151
414
  /** Line terminators other than `\n` that Dafny or a header regex may honor. */
@@ -165,12 +428,20 @@ export function proofAdditionViolations(generated, proof, proofName) {
165
428
  const report = (line, reason) => violations.push(`${proofName}:${line + 1}: ${reason}: ${proofLines[line].trim()}`);
166
429
  const tokens = lexDafny(proof);
167
430
  for (let k = 0; k < tokens.length; k++) {
168
- if (!added[tokens[k].line])
431
+ const match = trustsFact(tokens, k);
432
+ if (!match)
169
433
  continue;
170
- const reason = trustsFact(tokens, k);
171
- if (reason)
172
- report(tokens[k].line, reason);
434
+ let addedLine = -1;
435
+ for (let j = k; j <= match.end && j < tokens.length; j++) {
436
+ if (added[tokens[j].line]) {
437
+ addedLine = tokens[j].line;
438
+ break;
439
+ }
440
+ }
441
+ if (addedLine >= 0)
442
+ report(addedLine, match.reason);
173
443
  }
444
+ checkGeneratedHeaders(tokens, added, report);
174
445
  const genTokens = lexDafny(generated);
175
446
  const trustedGenLines = new Set();
176
447
  for (let k = 0; k < genTokens.length; k++) {
@@ -191,7 +462,7 @@ export function proofAdditionViolations(generated, proof, proofName) {
191
462
  if (LSC_OPTIONS_HEADER.test(text))
192
463
  report(line, "an added `// lsc options:` line would change verifier options; options come from the generated file");
193
464
  if (trustedGenLines.has(text))
194
- report(line, "added lines may not repeat a generated assume or axiom line; keep the generated line in place");
465
+ report(line, "added lines may not repeat a generated assume, axiom, or verification-bypass line; keep the generated line in place");
195
466
  });
196
467
  return violations;
197
468
  }