gdp-wired 0.37.0 → 0.38.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/dist/core/cli.d.ts +2 -1
- package/dist/core/cli.js +25 -6
- package/dist/core/extract-check.d.ts +2 -2
- package/dist/core/extract-check.js +7 -4
- package/dist/core/extract-print.js +5 -3
- package/dist/core/extract-read.d.ts +2 -0
- package/dist/core/extract-sol.d.ts +91 -0
- package/dist/core/extract-sol.js +1106 -0
- package/dist/core/extract-step.d.ts +14 -6
- package/dist/core/extract-step.js +79 -18
- package/dist/core/extract.d.ts +8 -0
- package/dist/core/extract.js +18 -2
- package/dist/core/infer.js +48 -13
- package/dist/core/laws.js +16 -2
- package/dist/core/live.js +158 -63
- package/dist/core/machine.js +7 -4
- package/package.json +1 -1
package/dist/core/cli.d.ts
CHANGED
|
@@ -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
|
-
|
|
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)
|
|
@@ -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
|
-
|
|
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
|
-
|
|
834
|
-
|
|
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}`,
|
|
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(),
|
|
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
|
-
|
|
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));
|
|
@@ -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
|
+
};
|