gdp-wired 0.37.0 → 0.39.0

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/README.md CHANGED
@@ -558,7 +558,7 @@ Proving and checking: a law over 64 steps proves in about 5 s, and Lean checks i
558
558
  | `docs/` | The comparison with Bend and Lean, and the full scope |
559
559
  | `compare/` | The same three rules in gdp-wired, Bend and plain Lean, checked and measured |
560
560
  | `research/` | Everything around the library ([`research/README.md`](research/README.md)): the GPU searches (`search/`, `hw/`, `modal-gpu/`), invariant and rank synthesis (`synth/`), relational laws and guard synthesis (`next/`), bit-vector laws (`sat/`), the enumeration and benchmarks (`enum/`, `gpu/`, `perf/`), the first Lean checker (`lean/`) and the first prototype, the audit path (`audit/`) |
561
- | `modal/` | Everything above as Modal jobs: `suite.json` is the regression suite |
561
+ | `supercomputer/` | Everything above as jobs on boat (a warm pool), Modal and RunPod: `suite.json` is the regression suite (`modal/` links here until every lane has merged the rename) |
562
562
  | `scripts/` | The package build, the smoke test of the packed tarball, the Lean library generator, the diagram |
563
563
  | `vendor/handwired` | [monotykamary/handwired](https://github.com/monotykamary/handwired), branch `u32-words`: Cheng Lou's Handwired with exact u32 word circuits and word stages in loop programs |
564
564
  | `vendor/gdp-ts` | [rauchg/gdp-ts](https://github.com/rauchg/gdp-ts) |
@@ -587,7 +587,7 @@ cd kernel && bun run-kernel.ts && bun test kernel.test.ts
587
587
  The whole suite (163 jobs, about 10 minutes of wall time and 46 minutes of job time) runs on [Modal](https://modal.com):
588
588
 
589
589
  ```sh
590
- modal run modal/run.py --jobs modal/suite.json --out runs/modal/suite && sh modal/reap.sh
590
+ modal run supercomputer/run.py --jobs supercomputer/suite.json --out runs/modal/suite && sh supercomputer/reap.sh
591
591
  ```
592
592
 
593
593
  Each directory's README has its own runs and results.
@@ -16,7 +16,7 @@ export type Opts = {
16
16
  cert?: string;
17
17
  [k: string]: unknown;
18
18
  };
19
- export type Lang = 'python' | 'ruby' | 'elixir' | 'java' | 'kotlin' | 'go' | 'rust' | 'swift' | 'c' | 'cpp' | 'ts';
19
+ export type Lang = 'python' | 'ruby' | 'elixir' | 'java' | 'kotlin' | 'go' | 'rust' | 'swift' | 'c' | 'cpp' | 'ts' | 'solidity';
20
20
  export declare const LANG_NAME: Record<Lang, string>;
21
21
  type Target = {
22
22
  lang: Lang;
@@ -38,6 +38,7 @@ type LawOut = {
38
38
  kind?: 'law' | 'step' | 'two runs';
39
39
  verdict: 'proven' | 'broken' | 'unknown' | 'not read';
40
40
  run?: string[];
41
+ replayed?: string;
41
42
  why?: string;
42
43
  assumes?: string[];
43
44
  found?: string[];
package/dist/core/cli.js CHANGED
@@ -42,9 +42,9 @@ function args(argv) {
42
42
  return { cmd, targets, o };
43
43
  }
44
44
  const EXT = { '.py': 'python', '.rb': 'ruby', '.ex': 'elixir', '.exs': 'elixir', '.java': 'java', '.kt': 'kotlin', '.go': 'go', '.rs': 'rust', '.swift': 'swift', '.c': 'c', '.h': 'c',
45
- '.cpp': 'cpp', '.cc': 'cpp', '.cxx': 'cpp', '.hpp': 'cpp', '.ts': 'ts', '.mts': 'ts', '.tsx': 'ts', '.js': 'ts', '.mjs': 'ts' };
46
- const COMMENT = { python: '#', ruby: '#', elixir: '#', java: '//', kotlin: '//', go: '//', rust: '//', swift: '//', c: '//', cpp: '//', ts: '//' };
47
- export const LANG_NAME = { python: 'Python', ruby: 'Ruby', elixir: 'Elixir', java: 'Java', kotlin: 'Kotlin', go: 'Go', rust: 'Rust', swift: 'Swift', c: 'C', cpp: 'C++', ts: 'TypeScript' };
45
+ '.cpp': 'cpp', '.cc': 'cpp', '.cxx': 'cpp', '.hpp': 'cpp', '.ts': 'ts', '.mts': 'ts', '.tsx': 'ts', '.js': 'ts', '.mjs': 'ts', '.sol': 'solidity' };
46
+ const COMMENT = { python: '#', ruby: '#', elixir: '#', java: '//', kotlin: '//', go: '//', rust: '//', swift: '//', c: '//', cpp: '//', ts: '//', solidity: '//' };
47
+ export const LANG_NAME = { python: 'Python', ruby: 'Ruby', elixir: 'Elixir', java: 'Java', kotlin: 'Kotlin', go: 'Go', rust: 'Rust', swift: 'Swift', c: 'C', cpp: 'C++', ts: 'TypeScript', solidity: 'Solidity' };
48
48
  function targetsOf(p) {
49
49
  const abs = path.resolve(p);
50
50
  if (!fs.existsSync(abs))
@@ -137,6 +137,10 @@ async function extractWith(t, o) {
137
137
  const { extractC } = await import("./extract-c.js");
138
138
  return extractC(f, o, t.lang === 'cpp');
139
139
  }
140
+ case 'solidity': {
141
+ const { extractSolidity } = await import("./extract-sol.js");
142
+ return extractSolidity(f, { root: up(dir, d => ['foundry.toml', 'hardhat.config.js', 'hardhat.config.ts', 'package.json'].some(m => fs.existsSync(path.join(d, m)))) ?? dir, ...o });
143
+ }
140
144
  case 'ts': {
141
145
  // (Effect and XState run on the package the file's own project has, imported here as the code imports it)
142
146
  const code = fs.readFileSync(f, 'utf8'), file = path.relative(proc.cwd(), f) || f, { createRequire } = proc.getBuiltinModule('node:module');
@@ -285,6 +289,9 @@ async function rulesOf(t, o, laws) {
285
289
  const named = Object.keys(cfg.rules).filter(k => t.files.some(f => new RegExp(`\\b${k.replace(/[^\w]/g, '\\$&')}\\b`).test(fs.readFileSync(f, 'utf8'))));
286
290
  if (named.length)
287
291
  return Promise.all(named.map(k => one(k)));
292
+ // (a contract's file names its contracts: refused with none named, the refusal is the rule's)
293
+ if (t.lang === 'solidity')
294
+ return [first];
288
295
  // (else each class the refusal names, and each function outside a class a law is stated on)
289
296
  const what = first.x.refusals[0]?.what ?? '';
290
297
  const several = /several (?:classes|structs) (?:write their state|written by the file's functions) \(([^)]*)\)/.exec(what)?.[1].split(', ') ?? [];
@@ -296,7 +303,7 @@ function scoped(file) {
296
303
  return lawsIn(text, path.basename(file)).map(l => {
297
304
  let cls, fn;
298
305
  for (let i = l.line - 1; i >= 0 && !cls; i--) {
299
- const m = /\b(?:class|struct|actor|defmodule|module|object|impl|record|interface)\s+([\w.:]+)|\btype\s+(\w+)\s+struct\b/.exec(lines[i].replace(/(#|\/\/).*$/, ''));
306
+ const m = /\b(?:class|struct|actor|defmodule|module|object|impl|record|interface|contract)\s+([\w.:]+)|\btype\s+(\w+)\s+struct\b/.exec(lines[i].replace(/(#|\/\/).*$/, ''));
300
307
  if (m)
301
308
  cls = (m[1] ?? m[2]).split(/[.:]/).pop();
302
309
  }
@@ -387,7 +394,17 @@ function prove(x, l, ms, proven, ctx) {
387
394
  catch (e) {
388
395
  return { ...base, kind, verdict: 'unknown', why: e.message, ms: Date.now() - t0 };
389
396
  }
390
- const verdict = v.proven && v.checked ? 'proven' : v.run ? 'broken' : 'unknown';
397
+ let verdict = v.proven && v.checked ? 'proven' : v.run ? 'broken' : 'unknown', replayed;
398
+ // (a run the front end replays on the code: broken only where the code runs it so)
399
+ if (verdict === 'broken' && x.replay && v.run && !two) {
400
+ const r = x.replay(v.run, b.law);
401
+ if (r.ok)
402
+ replayed = r.what;
403
+ else {
404
+ verdict = 'unknown';
405
+ v.why = `a run breaks it in the rule, not on the code: ${r.what}`;
406
+ }
407
+ }
391
408
  // (a state the laws allow from which a step breaks the law, no run from the start reaching it: shown, not a break)
392
409
  const at = !v.run && v.witness && !two ? (x.names ?? []).filter(n => n.rule && n.rule in v.witness && n.role !== 'const').map(n => `${label(n)} = ${shownValue(x, n.rule, v.witness, n.none)}`) : [];
393
410
  if (verdict === 'proven' && b?.kind === 'law')
@@ -405,7 +422,7 @@ function prove(x, l, ms, proven, ctx) {
405
422
  fs.writeFileSync(cert, JSON.stringify(doc));
406
423
  }
407
424
  }
408
- return { ...base, kind, verdict, ...(v.run ? { run: two ? pairRunOf(x, v.run, two) : runOf(x, v.run) } : {}), ...(verdict === 'unknown' ? { why: [v.why ?? v.stuck ?? 'not proven', ...(at.length ? [`a state the laws allow where a step breaks it, no run from the start found reaching it: ${at.join(', ')}`] : [])].join('; ') } : {}),
425
+ return { ...base, kind, verdict, ...(replayed ? { replayed } : {}), ...(v.run && verdict === 'broken' ? { run: two ? pairRunOf(x, v.run, two) : runOf(x, v.run) } : {}), ...(verdict === 'unknown' ? { why: [v.why ?? v.stuck ?? 'not proven', ...(at.length ? [`a state the laws allow where a step breaks it, no run from the start found reaching it: ${at.join(', ')}`] : [])].join('; ') } : {}),
409
426
  ...(v.run && !two ? { assumes: assumedOf(x, v.run) } : {}), ...(found?.length ? { found } : {}), ...(cert ? { cert } : {}), ms: Date.now() - t0 };
410
427
  }
411
428
  // Two runs as calls of the code: each request once, the values the two runs take apart as `a | b`, and the run b leaves
@@ -566,6 +583,8 @@ function printRule(r, o) {
566
583
  if (l.run)
567
584
  for (const [i, s] of l.run.entries())
568
585
  out(` ${i === 0 ? 'run: ' : ' '}${paint('red', s)}`);
586
+ if (l.replayed)
587
+ out(` ${l.replayed}`);
569
588
  for (const a of l.assumes ?? [])
570
589
  out(` ${a}`);
571
590
  if (l.found)
@@ -1334,7 +1334,7 @@ export function foldNodes(f, laws, usual, st = tstats()) {
1334
1334
  let quiet = 0;
1335
1335
  export const cyclicOn = () => quiet === 0 && env.GDP_CYCLIC === '1';
1336
1336
  // The `cyclic: {...}` lines research/cyclic/ratios.ts reads, printed only with GDP_CYCLIC=1 (the cross-check) or
1337
- // GDP_CYCLIC_LOG=1 (modal/run.py sets it): a user's proofs print nothing.
1337
+ // GDP_CYCLIC_LOG=1 (supercomputer/run.py sets it): a user's proofs print nothing.
1338
1338
  export const cycLog = (o) => { if (env.GDP_CYCLIC === '1' || env.GDP_CYCLIC_LOG === '1')
1339
1339
  console.error(`cyclic: ${JSON.stringify(o)}`); };
1340
1340
  // A search's many trial proofs (core/discover.ts, core/infer.ts) aren't compared: what it finds is proven again.
package/dist/core/dsl.js CHANGED
@@ -16,11 +16,12 @@
16
16
  // A step returns its updates as one object: every right-hand side reads the state before the step, as the kernel and
17
17
  // both runtimes do.
18
18
  import { searchCounted } from "./counts.js";
19
+ import { env as knobs } from "./solver.js";
19
20
  import { argsKey, machineTerms, carriedView, compileFunction, divName, divisor, divisorsIn, evalC, evalE, interpret, isArithmetic, loadJs, modName, numbersOf, pairedArgs, seeded, withArithmetic } from "./machine.js";
20
21
  import { allowed, keysOf, requestEnv, watch, watchWork } from "./watch.js";
21
- import { someHolds, substVars, substVarsE } from "./exists.js";
22
+ import { ghostOf, proveSome, someHolds, substVars, substVarsE } from "./exists.js";
22
23
  import { check, checkRecur, foldObligations, loopObligations, substC, sumMachine } from "../kernel/kernel.js";
23
- import { certLoop, clock, counted, factsFor, fullRate, grow, proveLaws, proveLiveness, proveSetFast, proveStepLaws, usualProof, withDeadline, withWall } from "../kernel/prove.js";
24
+ import { certLoop, clock, counted, factsFor, fullRate, grow, proveLaw, proveLaws, proveLiveness, proveSetFast, proveStepLaws, usualProof, withDeadline, withWall } from "../kernel/prove.js";
24
25
  import { certCyclic, certOn, crossCyclic, cyclicOn, foldNodes, proveCyclic, quietly, recurNodes, translatedProof, uncovered } from "./cyclic.js";
25
26
  import { discover } from "./discover.js";
26
27
  import { inferLaws } from "./infer.js";
@@ -3049,9 +3050,24 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
3049
3050
  return { proven: true, checked: true, found: { laws: fresh, ...(lemmas ? { lemmas } : {}) }, assumes: reachableBy(fresh) };
3050
3051
  }
3051
3052
  }
3052
- const ms = until - clock() - tail;
3053
+ let ms = until - clock() - tail;
3053
3054
  if (ms < 500)
3054
3055
  return v;
3056
+ // (a law with "there exists" about no key: its ghost chosen with the engine's cubes kept, within half of it)
3057
+ if (!stepLaws.length && laws.some(l => l.some?.length) && laws.every(l => !l.some?.length || !l.forall)) {
3058
+ let c;
3059
+ try {
3060
+ c = withWall(performance.now() + ms / 2, () => withDeadline(clock() + ms / 2, () => someCone(rule, laws, ms / 2)));
3061
+ }
3062
+ catch (e) {
3063
+ if (knobs.GDP_EXISTS_LOG === '1')
3064
+ console.error(`exists: cone failed: ${String(e.stack ?? e).slice(0, 600)}`);
3065
+ }
3066
+ if (c)
3067
+ return { ...c, found: { ...c.found, ...(lemmas ? { lemmas } : {}) } };
3068
+ if ((ms = until - clock() - tail) < 500)
3069
+ return v;
3070
+ }
3055
3071
  // (the search's own wall ends where the tail begins: the last bounded runs keep it)
3056
3072
  const tailAt = () => performance.now() + Math.max(0, until - tail - clock());
3057
3073
  const inf = withWall(tailAt(), () => inferLaws(rule, [...fresh.map(f => f.law), ...laws], stepLaws, { ms, ...(rule === r && !fresh.length ? { first: v } : {}) }));
@@ -3077,6 +3093,51 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
3077
3093
  void _stats;
3078
3094
  return { ...verdict, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) };
3079
3095
  }
3096
+ // A law with "there exists" about no key, which the join can't take as its goal: its witness core/exists.ts's ghostOf;
3097
+ // the engine's minimal ∀ cubes of two literals (core/infer.ts's `cubes`, its template two keys at the bound value's
3098
+ // places, framed by the law's conjuncts that read the value and no map), each kept where it is proven from the kept ones
3099
+ // and itself (IC3's relative induction, its cone), again while more are kept; then the laws with those kept. (A law about
3100
+ // every key goes the usual way: its ghost maps' goals ran past the search's wall here, firewall's, and won nothing.)
3101
+ function someCone(r, laws0, ms) {
3102
+ const until = clock() + ms, m = r.machine, yes = { op: '<=', a: { op: 'const', value: 0 }, b: { op: 'const', value: 0 } };
3103
+ const laws = laws0.map(l => (l.some?.length && !l.forall && !l.witness ? { ...l, witness: ghostOf(m, l) } : l));
3104
+ if (laws.some(l => l.some?.length && !l.forall && !l.witness))
3105
+ return undefined;
3106
+ const named = (d, l) => l.some.some(x => JSON.stringify(d).includes(`"name":${JSON.stringify(x)}`));
3107
+ const shape = (l) => (l.some?.length ? shapeOf(l) : l);
3108
+ // (two keys at the bound value's places, the law's conjuncts that read the value and no map their frame)
3109
+ function shapeOf(l) {
3110
+ const x = l.some[0], at = (c, k) => substVars(c, { [x]: { op: 'var', name: k } }), ks = ['k$some', 'k2$some'];
3111
+ const cs = l.holds.op === 'and' ? l.holds.xs : [l.holds], frame = cs.filter(c => named(c, l) && !JSON.stringify(c).includes('"op":"get"')), rest = cs.filter(c => !frame.includes(c));
3112
+ return { name: l.name, forall: ks[0], keys: [ks[1]], holds: { op: 'or', xs: [{ op: 'not', x: { op: 'and', xs: ks.flatMap(k => frame.map(c => at(c, k))) } }, ...ks.flatMap(k => rest.map(c => at(c, k))), yes] } };
3113
+ }
3114
+ const cubes = [...withKinds(r, []), ...inferLaws(r, laws.map(shape), [], { cubes: 2, ms: Math.min(10_000, ms / 3), first: { proven: false, checked: false } }).found.map(f => f.law)];
3115
+ const kept = [], tried = new Map();
3116
+ for (let grew = true; grew && clock() < until;) {
3117
+ grew = false;
3118
+ for (const c of cubes) {
3119
+ if (kept.includes(c) || tried.get(c.name) === kept.length || clock() > until)
3120
+ continue;
3121
+ tried.set(c.name, kept.length);
3122
+ // (a cube the kernel refuses to state, one past its key rules, is never kept)
3123
+ let ok = false;
3124
+ try {
3125
+ ok = withDeadline(Math.min(until, clock() + 1000), () => proveLaw(m, [...kept, c], kept.length)).proven;
3126
+ }
3127
+ catch { /* not kept */ }
3128
+ if (ok) {
3129
+ kept.push(c);
3130
+ grew = true;
3131
+ }
3132
+ }
3133
+ }
3134
+ if (knobs.GDP_EXISTS_LOG === '1')
3135
+ console.error(`exists: cone ${kept.length} of ${cubes.length} kept: ${kept.map(l => l.name).join('; ').slice(0, 2000)}`);
3136
+ if (clock() > until)
3137
+ return undefined;
3138
+ const v = verdictOf(proveSome(m, [...laws, ...kept.filter(c => !laws.some(l => l.name === c.name))]));
3139
+ return v.proven && v.checked ? { ...v, found: { laws: kept.map(l => ({ law: l, text: l.name })) }, ...withAssumes(kept.map(l => ({ text: l.name }))) } : undefined;
3140
+ }
3080
3141
  // What a verdict proven with these found laws rests on: the states reachable from init (each found law is proven so).
3081
3142
  const reachableBy = (found) => ({ states: 'reachable', laws: found.map(f => f.text) });
3082
3143
  const withAssumes = (found) => (found.length ? { assumes: reachableBy(found) } : {});
@@ -7,6 +7,7 @@ export declare function groupsOf(vars: string[]): Group[];
7
7
  export declare function substVarsE(e: E, s: Record<string, E>): E;
8
8
  export declare function substVars(c: C, s: Record<string, E>): C;
9
9
  export declare function small(m: Machine, p: Env, b: number, cap?: number, work?: number): State[];
10
+ export declare function ghostOf(m: Machine, law: Law): SomeWitness | undefined;
10
11
  export declare function holdsAt(m: Machine, law: Law, p: Env, st: State, b: number): boolean;
11
12
  export declare function someHolds(body: C, vars: string[], env: Env, st: State, m: Machine): {
12
13
  holds: boolean;
@@ -189,6 +189,34 @@ export function small(m, p, b, cap = 3000, work = 300_000) {
189
189
  }
190
190
  return [...seen.values()];
191
191
  }
192
+ // A ghost for a law about no key with one value ∃x. P over maps (PCorrect's "some process not done, or its y is 1"): x a
193
+ // state variable that starts at 0 or a param (or one less) and after each step keeps its value while P still holds there
194
+ // after the step, else moves to a term the step reads a map at (the process before the one that stepped); the first
195
+ // whose P holds at every state of the small instances (each param 2 and 3), given as the law's witness, or none.
196
+ export function ghostOf(m, law) {
197
+ const x = law.some?.[0];
198
+ if (!x || law.forall || law.some.length !== 1 || x.endsWith('$neg') || !readsMaps(law.holds) || x in m.state)
199
+ return undefined;
200
+ const after = { vars: Object.fromEntries(Object.keys(m.state).map(n => [n, m.step.state?.[n] ?? v(n)])), flags: {},
201
+ maps: Object.fromEntries(Object.entries(m.step.maps ?? {}).map(([mp, w]) => [mp, (at) => ('each' in w ? substVarsE(w.value, { [w.each]: at }) : { op: 'if', c: { op: '=', a: at, b: w.key }, then: w.value, else: { op: 'get', map: mp, key: at } })])) };
202
+ const keep = substC(law.holds, after), ts = new Map(m.inputs.map(i => [key(v(i)), v(i)]));
203
+ walk([m.step, m.assume ?? null], o => { if (o.op === 'get' && namesOf(o.key).some(n => m.inputs.includes(n)))
204
+ ts.set(key(o.key), o.key); });
205
+ const starts = [k(0), ...m.params.flatMap(q => [v(q), sub(v(q), k(1))])];
206
+ for (const t of ts.values())
207
+ for (const start of starts) {
208
+ const step = { op: 'if', c: keep, then: v(x), else: t }, gm = { ...m, state: { ...m.state, [x]: start }, step: { ...m.step, state: { ...m.step.state, [x]: step } } };
209
+ const ok = [2, 3].every(q => { const ps = Object.fromEntries(m.params.map(p => [p, q])); try {
210
+ return small(gm, ps, 3, 3000, 100_000).every(st => holdsAt(gm, { ...law, some: undefined }, ps, st, 3));
211
+ }
212
+ catch {
213
+ return false;
214
+ } });
215
+ if (ok)
216
+ return { ghost: { [x]: { start, step } } };
217
+ }
218
+ return undefined;
219
+ }
192
220
  // A law at a state, its counts the state's, at every key below b.
193
221
  // (a state's view once: a law is read at every state, and every law at each)
194
222
  const views = new WeakMap();
@@ -78,7 +78,7 @@ export type CheckOptions = {
78
78
  states?: number;
79
79
  seed?: number;
80
80
  bound?: number;
81
- probes?: boolean;
81
+ probes?: boolean | 'writes';
82
82
  probeMs?: number;
83
83
  modules?: Record<string, unknown>;
84
84
  files?: Record<string, string>;
@@ -123,7 +123,7 @@ export declare function check(code: string, file: string, m: Model, r: Rule, sor
123
123
  export declare function drive(m: Model, r: Rule, sorts: Sorts, code: CodeSide, opts?: CheckOptions & {
124
124
  given?: Record<string, 'nat' | 'int'>;
125
125
  }): Evidence;
126
- export declare function conditionsOf(m: Model): B[];
126
+ export declare function conditionsOf(m: Model, writes?: boolean): B[];
127
127
  export declare function condAt(c: B, env: Record<string, unknown>): ReturnType<Term['lt']>;
128
128
  export declare function evalTerm(t: N | B | I.L, env: Record<string, Raw>, cell?: (map: string, key: Raw, field: string) => Raw): Raw;
129
129
  export {};
@@ -771,7 +771,7 @@ export function drive(m, r, sorts, code, opts = {}) {
771
771
  // Steps from the prover's counterexamples: each condition of the step, refuted as "never holds". (Not where the
772
772
  // rule carries folds: their equations, quantified over every pass, make each probe slow, and a witness's lists empty.)
773
773
  if (opts.probes !== false && !m.folds?.length) {
774
- const conds = conditionsOf(m);
774
+ const conds = conditionsOf(m, opts.probes === 'writes');
775
775
  for (const [i, c] of conds.entries()) {
776
776
  ev.probes.conditions++;
777
777
  let law;
@@ -821,7 +821,9 @@ export function drive(m, r, sorts, code, opts = {}) {
821
821
  }
822
822
  const mapReplacer = (_, v) => (isMap(v) ? { $map: [...v.entries()] } : v);
823
823
  // The conditions a step reads (each branch's, each refusal's), as a probe asks the prover to reach.
824
- export function conditionsOf(m) {
824
+ // ('writes': the branches' only; a refusal's condition holds at no step the rule takes, so where the rule is large its
825
+ // probe is a proof the kernel may take long over)
826
+ export function conditionsOf(m, writes = false) {
825
827
  const out = [], seen = new Set();
826
828
  const add = (c) => { if (c.op === 'const')
827
829
  return; const k = I.keyOf(c); if (!seen.has(k) && !hasCell(c)) {
@@ -830,8 +832,9 @@ export function conditionsOf(m) {
830
832
  } };
831
833
  walk([m.writes, m.mapWrites], o => { if ((o.op === 'ite' || o.op === 'kite') && o.c)
832
834
  add(o.c); });
833
- for (const d of m.refuse.op === 'or' ? m.refuse.xs : [m.refuse])
834
- add(d);
835
+ if (!writes)
836
+ for (const d of m.refuse.op === 'or' ? m.refuse.xs : [m.refuse])
837
+ add(d);
835
838
  return out.slice(0, 48);
836
839
  }
837
840
  const hasCell = (c) => I.varsOf(c).maps.size > 0;
@@ -279,10 +279,10 @@ export function sortsOf(m, given = {}) {
279
279
  }
280
280
  for (const d of m.maps)
281
281
  for (const f of d.fields) {
282
- const n = `${d.name}.${f.name}`, w = m.mapWrites[d.name]?.vals[f.name];
282
+ const n = `${d.name}.${f.name}`, mw = m.mapWrites[d.name];
283
283
  if (f.sort.k !== 'num' || sorts.get(n) === 'int' || given[n])
284
284
  continue;
285
- if (w && w.s === 'num' && !natOK(w.e, withAtom(ctx0(), m.mapWrites[d.name].has))) {
285
+ if (mw && [...(mw.pre ?? []), mw].some(x => { const w = x.vals[f.name]; return w && w.s === 'num' && !natOK(w.e, withAtom(ctx0(), x.has)); })) {
286
286
  sorts.set(n, 'int');
287
287
  changed = true;
288
288
  }
@@ -384,7 +384,9 @@ function pcmp(rel, a, b, P, ctx) {
384
384
  const op = rel === '<' ? 'lt' : rel === '<=' ? 'atMost' : 'eq', flip = rel === '<' ? 'gt' : rel === '<=' ? 'atLeast' : 'eq';
385
385
  const nat = natOK(a, ctx) && natOK(b, ctx);
386
386
  const [x, y, o] = a.op === 'const' && b.op !== 'const' ? [b, a, flip] : [a, b, op];
387
- return `${pn(x, P, ctx, nat ? 'nat' : 'int', true)}.${o}(${pn(y, P, ctx, nat || natOK(y, ctx) ? 'nat' : 'int')})`;
387
+ // (a natural by cases compared with an integer: its when(...) is a natural's, made an integer to compare from)
388
+ const left = !nat && x.op === 'ite' && natOK(x, ctx) ? `Int.of(${pn(x, P, ctx, 'nat')})` : pn(x, P, ctx, nat ? 'nat' : 'int', true);
389
+ return `${left}.${o}(${pn(y, P, ctx, nat || natOK(y, ctx) ? 'nat' : 'int')})`;
388
390
  }
389
391
  export function pb(c, P, ctx) {
390
392
  const h = P.hoisted.get(I.keyOf(c));
@@ -115,6 +115,8 @@ export type MapWrite = {
115
115
  key: K;
116
116
  has: B;
117
117
  vals: Record<string, Term>;
118
+ pre?: MapWrite[];
119
+ when?: B;
118
120
  };
119
121
  export type ListOp = {
120
122
  op: 'push';
@@ -0,0 +1,91 @@
1
+ import { type Extraction } from './extract.js';
2
+ import { type FileURL } from './extract-read.js';
3
+ import { type SModule, type SType, type StepOptions, type StepRead } from './extract-step.js';
4
+ export { proveRule, proveSteps } from './dsl.js';
5
+ export type SolOptions = StepOptions & {
6
+ root?: string;
7
+ remappings?: string[];
8
+ reentrant?: boolean;
9
+ solc?: string;
10
+ anvil?: string;
11
+ python?: string;
12
+ };
13
+ type Ast = {
14
+ nodeType: string;
15
+ id: number;
16
+ src: string;
17
+ [k: string]: any;
18
+ };
19
+ export declare const MOD = "W256$";
20
+ export type Compiled = {
21
+ main: number;
22
+ ast: Map<number, Ast>;
23
+ text: Map<number, string>;
24
+ paths: Map<number, string>;
25
+ contracts: Record<string, Record<string, {
26
+ abi: unknown[];
27
+ evm: {
28
+ bytecode: {
29
+ object: string;
30
+ };
31
+ deployedBytecode: {
32
+ object: string;
33
+ };
34
+ methodIdentifiers: Record<string, string>;
35
+ };
36
+ storageLayout: {
37
+ storage: {
38
+ label: string;
39
+ slot: string;
40
+ offset: number;
41
+ type: string;
42
+ }[];
43
+ types: Record<string, {
44
+ encoding: string;
45
+ numberOfBytes: string;
46
+ key?: string;
47
+ value?: string;
48
+ label: string;
49
+ }>;
50
+ };
51
+ }>>;
52
+ };
53
+ export declare function compile(file: string, o: SolOptions): Compiled;
54
+ type Field = {
55
+ name: string;
56
+ t: SType;
57
+ decl: Ast;
58
+ sol: string;
59
+ };
60
+ export type SolMeta = {
61
+ leftOut: string[];
62
+ calls: boolean;
63
+ resumes: string[];
64
+ addrBits: number;
65
+ contract: string;
66
+ source: string;
67
+ fields: Field[];
68
+ fns: Record<string, Ast>;
69
+ payable: string[];
70
+ minW: number;
71
+ nested: string[];
72
+ entries: Record<string, {
73
+ sig: string;
74
+ inputs: string[];
75
+ payable: boolean;
76
+ out?: string;
77
+ }>;
78
+ ctor: {
79
+ inputs: string[];
80
+ payable: boolean;
81
+ };
82
+ ether: boolean;
83
+ };
84
+ export declare function readSolidity(file: string, o?: SolOptions, reenter?: boolean, compiled?: Compiled): {
85
+ mod: SModule;
86
+ meta: SolMeta;
87
+ c: Compiled;
88
+ };
89
+ export declare function extractSolidity(at: string | FileURL, opts?: SolOptions): Extraction & {
90
+ read?: StepRead;
91
+ };