gdp-wired 0.44.0 → 0.46.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 +58 -7
- package/dist/core/bitsets.d.ts +2 -0
- package/dist/core/bitsets.js +23 -0
- package/dist/core/bmc.js +6 -2
- package/dist/core/c/reader.d.ts +9 -1
- package/dist/core/c/reader.js +445 -38
- package/dist/core/calendar.d.ts +29 -0
- package/dist/core/calendar.js +82 -0
- package/dist/core/check.js +3 -2
- package/dist/core/cli.d.ts +4 -0
- package/dist/core/cli.js +335 -39
- package/dist/core/compose.js +3 -1
- package/dist/core/counts.d.ts +5 -2
- package/dist/core/counts.js +335 -88
- package/dist/core/cycles.js +8 -1
- package/dist/core/cyclic.d.ts +1 -0
- package/dist/core/cyclic.js +13 -7
- package/dist/core/data-synth.d.ts +3 -0
- package/dist/core/data-synth.js +252 -0
- package/dist/core/data.d.ts +8 -2
- package/dist/core/data.js +1113 -172
- package/dist/core/discover.js +3 -1
- package/dist/core/draft.d.ts +19 -0
- package/dist/core/draft.js +53 -0
- package/dist/core/dsl.d.ts +39 -3
- package/dist/core/dsl.js +250 -31
- package/dist/core/effect-prims.js +2 -2
- package/dist/core/effect.d.ts +1 -4
- package/dist/core/effect.js +1 -15
- package/dist/core/ex/reader.exs +17 -1
- package/dist/core/exists.d.ts +16 -1
- package/dist/core/exists.js +447 -50
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +185 -31
- package/dist/core/extract-check.d.ts +7 -0
- package/dist/core/extract-check.js +115 -3
- package/dist/core/extract-ex.js +3 -3
- package/dist/core/extract-go-check.d.ts +1 -1
- package/dist/core/extract-go-check.js +21 -13
- package/dist/core/extract-go.d.ts +1 -0
- package/dist/core/extract-go.js +58 -9
- package/dist/core/extract-ir.d.ts +1 -0
- package/dist/core/extract-ir.js +15 -0
- package/dist/core/extract-jvm.d.ts +1 -1
- package/dist/core/extract-jvm.js +65 -14
- package/dist/core/extract-orm.d.ts +12 -0
- package/dist/core/extract-orm.js +244 -0
- package/dist/core/extract-print.js +23 -1
- package/dist/core/extract-py.d.ts +1 -0
- package/dist/core/extract-py.js +4 -4
- package/dist/core/extract-rb.js +3 -3
- package/dist/core/extract-read.d.ts +25 -0
- package/dist/core/extract-read.js +60 -5
- package/dist/core/extract-rs.js +22 -20
- package/dist/core/extract-shapes.js +22 -0
- package/dist/core/extract-sol.d.ts +10 -1
- package/dist/core/extract-sol.js +89 -30
- package/dist/core/extract-step.d.ts +201 -4
- package/dist/core/extract-step.js +1514 -111
- package/dist/core/extract-swift.js +24 -13
- package/dist/core/extract.d.ts +9 -0
- package/dist/core/extract.js +88 -7
- package/dist/core/fiber-run.d.ts +5 -0
- package/dist/core/fiber-run.js +18 -0
- package/dist/core/fresh.d.ts +2 -2
- package/dist/core/fresh.js +7 -3
- package/dist/core/go/reader.go +7 -1
- package/dist/core/infer.d.ts +4 -1
- package/dist/core/infer.js +1020 -246
- package/dist/core/jvm/JavaReader.java +33 -8
- package/dist/core/jvm/Jvm.java +20 -1
- package/dist/core/jvm/KtReader.java +59 -6
- package/dist/core/laws.d.ts +10 -3
- package/dist/core/laws.js +193 -14
- package/dist/core/machine.d.ts +16 -3
- package/dist/core/machine.js +212 -28
- package/dist/core/nonterm.js +14 -1
- package/dist/core/orm/harness.js +61 -0
- package/dist/core/orm-fixtures/schema.prisma +5 -0
- package/dist/core/py/harness.py +260 -21
- package/dist/core/py/reader.py +278 -39
- package/dist/core/rb/reader.rb +52 -5
- package/dist/core/reader-fixtures/README.md +28 -0
- package/dist/core/reader-fixtures/c-693042.cpp +8 -0
- package/dist/core/reader-fixtures/go-685506.go +14 -0
- package/dist/core/reader-fixtures/jvm-724362.kt +8 -0
- package/dist/core/reader-fixtures/jvm-737430.kt +7 -0
- package/dist/core/reader-fixtures/jvm-765282.kt +3 -0
- package/dist/core/reader-fixtures/swift-735726.swift +15 -0
- package/dist/core/reader-fixtures/swift-735990.swift +15 -0
- package/dist/core/reader-fixtures/swift-739158.swift +4 -0
- package/dist/core/reader-fixtures/swift-744834.swift +15 -0
- package/dist/core/reader-fixtures/swift-746946.swift +31 -0
- package/dist/core/reader-fixtures/typescript-673062.ts.txt +2 -0
- package/dist/core/relation.d.ts +1 -1
- package/dist/core/relation.js +29 -2
- package/dist/core/relational.js +4 -2
- package/dist/core/rs/src/main.rs +18 -2
- package/dist/core/sample-cache.d.ts +8 -0
- package/dist/core/sample-cache.js +46 -0
- package/dist/core/security.d.ts +38 -0
- package/dist/core/security.js +88 -0
- package/dist/core/sol/harness.py +63 -7
- package/dist/core/sol-concrete.d.ts +23 -0
- package/dist/core/sol-concrete.js +195 -0
- package/dist/core/solver.js +8 -5
- package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
- package/dist/core/system.d.ts +62 -1
- package/dist/core/system.js +263 -4
- package/dist/core/transfer.js +39 -9
- package/dist/core/translate.js +39 -10
- package/dist/core/watch.js +51 -6
- package/dist/interchange/check.js +10 -10
- package/dist/interchange/format.d.ts +4 -0
- package/dist/interchange/format.js +24 -6
- package/dist/kernel/cdcl.d.ts +5 -0
- package/dist/kernel/cdcl.js +88 -10
- package/dist/kernel/epr.js +141 -29
- package/dist/kernel/kernel.d.ts +31 -1
- package/dist/kernel/kernel.js +391 -101
- package/dist/kernel/model-sequence.d.ts +3 -0
- package/dist/kernel/model-sequence.js +34 -0
- package/dist/kernel/prove.d.ts +30 -1
- package/dist/kernel/prove.js +481 -71
- package/dist/kernel/reader.d.ts +3 -0
- package/dist/kernel/reader.js +101 -14
- package/dist/kernel/share.d.ts +1 -0
- package/dist/kernel/share.js +27 -0
- package/dist/lean-kernel/emit.d.ts +9 -3
- package/dist/lean-kernel/emit.js +200 -66
- package/dist/lean-kernel/lean-terms.js +5 -0
- package/dist/lean-kernel/library.js +10 -10
- package/package.json +7 -2
|
@@ -632,6 +632,8 @@ function chainOf(s, cls) {
|
|
|
632
632
|
const h = c.heritageClauses?.find(x => x.token === ts.SyntaxKind.ExtendsKeyword);
|
|
633
633
|
if (!h)
|
|
634
634
|
return chain;
|
|
635
|
+
if (h.types.length !== 1)
|
|
636
|
+
return refuse(h, 'extends must name exactly one base class');
|
|
635
637
|
c = base(h.types[0].expression, h);
|
|
636
638
|
}
|
|
637
639
|
}
|
|
@@ -950,6 +952,17 @@ function attempt(code, file, opts, written) {
|
|
|
950
952
|
// The methods: each public one an event (the nearest of each name, through the classes it extends), run from the
|
|
951
953
|
// state as variables.
|
|
952
954
|
const seenNames = new Set(), methods = [];
|
|
955
|
+
// (two bodies of one name in one class: JavaScript keeps the last, TypeScript refuses it)
|
|
956
|
+
for (const c of chain) {
|
|
957
|
+
const bodies = new Set();
|
|
958
|
+
for (const m of c.members)
|
|
959
|
+
if (ts.isMethodDeclaration(m) && m.body) {
|
|
960
|
+
const k = `${has(m, ts.SyntaxKind.StaticKeyword) ? 'static ' : ''}${memberName(m.name)}`;
|
|
961
|
+
if (bodies.has(k))
|
|
962
|
+
refuse(m, `${memberName(m.name)}: a second body of it in one class (JavaScript keeps the last; TypeScript refuses it)`);
|
|
963
|
+
bodies.add(k);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
953
966
|
for (const c of chain)
|
|
954
967
|
for (const m of c.members) {
|
|
955
968
|
if (!ts.isMethodDeclaration(m) || seenNames.has(memberName(m.name)))
|
|
@@ -1294,6 +1307,15 @@ function factoryAttempt(code, file, opts, written, fxOf) {
|
|
|
1294
1307
|
for (const [id, o] of fx?.start ?? [])
|
|
1295
1308
|
stateHeap.set(id, o);
|
|
1296
1309
|
const strip0 = (e) => (ts.isParenthesizedExpression(e) || ts.isAsExpression(e) ? strip0(e.expression) : e);
|
|
1310
|
+
// (two members of one name: JavaScript keeps the last, TypeScript refuses it)
|
|
1311
|
+
const names = new Set();
|
|
1312
|
+
for (const p of obj.properties)
|
|
1313
|
+
if (p.name && !ts.isComputedPropertyName(p.name)) {
|
|
1314
|
+
const n = memberName(p.name);
|
|
1315
|
+
if (names.has(n))
|
|
1316
|
+
refuse(p, `${n}: a second member of it in the object returned (JavaScript keeps the last; TypeScript refuses it)`);
|
|
1317
|
+
names.add(n);
|
|
1318
|
+
}
|
|
1297
1319
|
const fns = obj.properties.map(p => {
|
|
1298
1320
|
if (ts.isMethodDeclaration(p))
|
|
1299
1321
|
return { name: memberName(p.name), decl: p };
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { type Extraction } from './extract.js';
|
|
2
2
|
import { type FileURL } from './extract-read.js';
|
|
3
|
+
import { type SolidityHarness } from './sol-concrete.js';
|
|
4
|
+
export type { SolidityHarness } from './sol-concrete.js';
|
|
3
5
|
import { type SModule, type SType, type StepOptions, type StepRead } from './extract-step.js';
|
|
4
6
|
export { proveRule, proveSteps } from './dsl.js';
|
|
5
7
|
export type SolOptions = StepOptions & {
|
|
6
8
|
root?: string;
|
|
7
9
|
remappings?: string[];
|
|
10
|
+
harness?: 'auto' | false | {
|
|
11
|
+
file: string;
|
|
12
|
+
entry?: string;
|
|
13
|
+
};
|
|
8
14
|
reentrant?: boolean;
|
|
9
15
|
solc?: string;
|
|
10
16
|
anvil?: string;
|
|
@@ -18,6 +24,8 @@ type Ast = {
|
|
|
18
24
|
};
|
|
19
25
|
export declare const MOD = "W256$";
|
|
20
26
|
export type Compiled = {
|
|
27
|
+
harness?: SolidityHarness;
|
|
28
|
+
harnessMethods?: string[];
|
|
21
29
|
main: number;
|
|
22
30
|
ast: Map<number, Ast>;
|
|
23
31
|
text: Map<number, string>;
|
|
@@ -50,7 +58,7 @@ export type Compiled = {
|
|
|
50
58
|
};
|
|
51
59
|
}>>;
|
|
52
60
|
};
|
|
53
|
-
export declare function compile(file: string, o: SolOptions): Compiled;
|
|
61
|
+
export declare function compile(file: string, o: SolOptions, extra?: Record<string, string>): Compiled;
|
|
54
62
|
type Field = {
|
|
55
63
|
name: string;
|
|
56
64
|
t: SType;
|
|
@@ -88,4 +96,5 @@ export declare function readSolidity(file: string, o?: SolOptions, reenter?: boo
|
|
|
88
96
|
};
|
|
89
97
|
export declare function extractSolidity(at: string | FileURL, opts?: SolOptions): Extraction & {
|
|
90
98
|
read?: StepRead;
|
|
99
|
+
harness?: SolidityHarness;
|
|
91
100
|
};
|
package/dist/core/extract-sol.js
CHANGED
|
@@ -27,7 +27,9 @@ import { fromModel } from "./extract.js";
|
|
|
27
27
|
import { evalC, interpret, seeded } from "./machine.js";
|
|
28
28
|
import { allowed, watch } from "./watch.js";
|
|
29
29
|
import { kindOfVar } from "./extract-check.js";
|
|
30
|
-
import {
|
|
30
|
+
import { substN } from "./extract-ir.js";
|
|
31
|
+
import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
|
|
32
|
+
import { concreteSolidity, SolidityHarnessRefusal } from "./sol-concrete.js";
|
|
31
33
|
const refuse = (where, what) => { throw new Refusal(where, what); };
|
|
32
34
|
import { asset, checkStep, node, readStep, stepNames } from "./extract-step.js";
|
|
33
35
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
@@ -36,18 +38,18 @@ export const MOD = 'W256$';
|
|
|
36
38
|
const CHECK_W = 2 ** 52;
|
|
37
39
|
const U256 = { k: 'int', bits: 256, signed: false, mod: MOD };
|
|
38
40
|
const env = () => globalThis.process?.env ?? {};
|
|
39
|
-
export function compile(file, o) {
|
|
41
|
+
export function compile(file, o, extra = {}) {
|
|
40
42
|
const cp = node('node:child_process'), fs = node('node:fs'), path = node('node:path');
|
|
41
43
|
const root = path.resolve(o.root ?? path.dirname(file)), rel = path.relative(root, path.resolve(file));
|
|
42
|
-
const input = { language: 'Solidity', sources: { [rel]: { content: fs.readFileSync(file, 'utf8') } },
|
|
44
|
+
const input = { language: 'Solidity', sources: { ...Object.fromEntries(Object.entries(extra).map(([p, content]) => [p, { content }])), [rel]: { content: fs.readFileSync(file, 'utf8') } },
|
|
43
45
|
settings: { remappings: o.remappings ?? [], optimizer: { enabled: false }, outputSelection: { '*': { '': ['ast'], '*': ['abi', 'evm.bytecode.object', 'evm.deployedBytecode.object', 'evm.methodIdentifiers', 'storageLayout'] } } } };
|
|
44
46
|
let out;
|
|
45
47
|
const solc = o.solc ?? env().GDP_SOLC ?? 'solc';
|
|
46
48
|
try {
|
|
47
|
-
out = cp.execFileSync(solc, ['--standard-json', '--base-path', root, '--include-path', `${root}/node_modules`, '--allow-paths', root], { input: JSON.stringify(input), encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
49
|
+
out = cp.execFileSync(solc, ['--standard-json', '--base-path', root, '--include-path', `${root}/node_modules`, '--allow-paths', root], { input: JSON.stringify(input), encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['pipe', 'pipe', 'pipe'], ...readerRun() });
|
|
48
50
|
}
|
|
49
51
|
catch (e) {
|
|
50
|
-
throw new Refusal(file, `solc didn't run (${String(e.message).slice(0, 300)}): solc 0.8 is needed to extract Solidity (on the PATH, or $GDP_SOLC)`);
|
|
52
|
+
throw new Refusal(file, statedRefusal(e) ?? `solc didn't run (${String(e.message).slice(0, 300)}): solc 0.8 is needed to extract Solidity (on the PATH, or $GDP_SOLC)`);
|
|
51
53
|
}
|
|
52
54
|
const j = JSON.parse(out);
|
|
53
55
|
const errs = (j.errors ?? []).filter(e => e.severity === 'error');
|
|
@@ -61,7 +63,7 @@ export function compile(file, o) {
|
|
|
61
63
|
ast.set(s.id, s.ast);
|
|
62
64
|
paths.set(s.id, p);
|
|
63
65
|
const abs = p === rel ? path.resolve(file) : [path.resolve(root, p), path.resolve(root, 'node_modules', p)].find(x => fs.existsSync(x));
|
|
64
|
-
text.set(s.id, abs ? fs.readFileSync(abs, 'utf8') : '');
|
|
66
|
+
text.set(s.id, extra[p] ?? (abs ? fs.readFileSync(abs, 'utf8') : ''));
|
|
65
67
|
}
|
|
66
68
|
return { main, ast, text, paths, contracts: j.contracts };
|
|
67
69
|
}
|
|
@@ -73,6 +75,7 @@ class Lower {
|
|
|
73
75
|
funcs = {};
|
|
74
76
|
fields = [];
|
|
75
77
|
consts = new Map();
|
|
78
|
+
ctorParams = new Map();
|
|
76
79
|
minW = 2;
|
|
77
80
|
addrBits = 0;
|
|
78
81
|
get ADDR() { return { k: 'int', bits: this.addrBits, signed: false }; }
|
|
@@ -161,7 +164,7 @@ class Lower {
|
|
|
161
164
|
return { k: 'map', key: k.k === 'int' && k.mod ? { k: 'int' } : k, val };
|
|
162
165
|
}
|
|
163
166
|
// The contract: its linearized bases, state, functions.
|
|
164
|
-
module(name) {
|
|
167
|
+
module(name, selected) {
|
|
165
168
|
const contracts = [...this.defs.values()].filter(d => d.nodeType === 'ContractDefinition');
|
|
166
169
|
const main = this.c.ast.get(this.c.main);
|
|
167
170
|
const own = contracts.filter(d => main && main.nodes.includes(d));
|
|
@@ -201,11 +204,11 @@ class Lower {
|
|
|
201
204
|
if (f.kind === 'constructor')
|
|
202
205
|
continue;
|
|
203
206
|
const id = this.fnId(f);
|
|
204
|
-
if (
|
|
207
|
+
if (fns[id])
|
|
205
208
|
continue;
|
|
206
209
|
const pub = f.visibility === 'public' || f.visibility === 'external';
|
|
207
210
|
const name = f.kind === 'receive' ? 'receive' : f.kind === 'fallback' ? 'fallback' : f.name;
|
|
208
|
-
if (pub && f.stateMutability !== 'view' && f.stateMutability !== 'pure') {
|
|
211
|
+
if (pub && (selected ? selected.includes(name) : f.stateMutability !== 'view' && f.stateMutability !== 'pure')) {
|
|
209
212
|
if (methods[name])
|
|
210
213
|
this.no(f, `${name}: an overloaded external function (the subset reads one of a name)`);
|
|
211
214
|
methods[name] = `entry:${id}`;
|
|
@@ -293,6 +296,12 @@ class Lower {
|
|
|
293
296
|
const mk = body[i], pre = body.slice(0, i), rest = body.slice(i + 1);
|
|
294
297
|
if (callsOut(rest))
|
|
295
298
|
refuse(p, `${name}: two calls into other code (the subset splits at one)`);
|
|
299
|
+
// (a failed call must revert the caller, as transfer and require(ok) do: the EVM undoes what the callee did, the
|
|
300
|
+
// contract's calls back included, which the steps between the two the rule holds can't undo)
|
|
301
|
+
const okv = String(mk.ok), r0 = rest[0], x0 = r0?.c;
|
|
302
|
+
const reverts = mk.how === 'transfer' || (r0?.s === 'if' && x0?.e === 'not' && x0.x?.e === 'var' && x0.x.n === okv && (r0.then[0]?.s === 'fail'));
|
|
303
|
+
if (!reverts)
|
|
304
|
+
refuse(p, `${name}: a call into other code whose failure the function goes on past (the EVM undoes what the callee did, its calls back included; the subset reads a failed call that reverts the caller: require(ok) right after it)`);
|
|
296
305
|
// The locals the rest may read: the parameters, and every local the part before sets.
|
|
297
306
|
const locals = new Map();
|
|
298
307
|
for (const pa of params)
|
|
@@ -386,6 +395,35 @@ class Lower {
|
|
|
386
395
|
this.cur = { entry: true, payable: top?.stateMutability === 'payable', rets: [], tmp: 0 };
|
|
387
396
|
if (this.cur.payable)
|
|
388
397
|
this.ether = true;
|
|
398
|
+
// Bind constructor arguments derived-first, then execute bodies base-first. Each parameter has a fresh local:
|
|
399
|
+
// a base's `n` must neither read an unbound derived `n` nor overwrite it when the base mutates its own argument.
|
|
400
|
+
const used = new Set([...this.defs.values()].map(d => d.name).filter((n) => typeof n === 'string'));
|
|
401
|
+
const callsCode = (a) => {
|
|
402
|
+
if (Array.isArray(a))
|
|
403
|
+
return a.some(callsCode);
|
|
404
|
+
if (!a || typeof a !== 'object')
|
|
405
|
+
return false;
|
|
406
|
+
const n = a;
|
|
407
|
+
return n.nodeType === 'FunctionCall' && n.kind !== 'typeConversion' || Object.values(n).some(v => v && typeof v === 'object' && callsCode(v));
|
|
408
|
+
};
|
|
409
|
+
for (const c of this.lin) {
|
|
410
|
+
const cf = ctorOf(c);
|
|
411
|
+
for (const [i, pa] of (cf?.parameters.parameters ?? []).entries()) {
|
|
412
|
+
const a = c === k ? undefined : given.get(c.id)?.[i];
|
|
413
|
+
if (c !== k && !a)
|
|
414
|
+
this.no(cf, `${c.name}'s constructor given no ${pa.name}`);
|
|
415
|
+
if (a && callsCode(a))
|
|
416
|
+
this.no(a, 'a constructor argument calling code (its initialization order is not supported)');
|
|
417
|
+
const x = a ? this.ex(a) : { e: 'var', n: pa.name, p: this.at(pa) };
|
|
418
|
+
let name = `gdp$ctor$${pa.id}`;
|
|
419
|
+
while (used.has(name))
|
|
420
|
+
name += '_';
|
|
421
|
+
used.add(name);
|
|
422
|
+
const to = { e: 'var', n: name, p: this.at(pa) };
|
|
423
|
+
body.push({ s: 'set', p: this.at(pa), to, x, t: this.ty(pa.typeDescriptions.typeString, pa) });
|
|
424
|
+
this.ctorParams.set(pa.id, to);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
389
427
|
for (const c of [...this.lin].reverse()) {
|
|
390
428
|
for (const n of c.nodes) {
|
|
391
429
|
if (n.nodeType !== 'VariableDeclaration' || n.constant)
|
|
@@ -398,9 +436,6 @@ class Lower {
|
|
|
398
436
|
const cf = ctorOf(c);
|
|
399
437
|
if (!cf)
|
|
400
438
|
continue;
|
|
401
|
-
if (c !== k)
|
|
402
|
-
cf.parameters.parameters.forEach((pa, i) => { const a = given.get(c.id)?.[i]; if (!a)
|
|
403
|
-
this.no(cf, `${c.name}'s constructor given no ${pa.name}`); body.push({ s: 'set', p: this.at(cf), to: { e: 'var', n: pa.name, p: this.at(cf) }, x: this.ex(a) }); });
|
|
404
439
|
body.push(...this.withModifiers(cf, (cf.modifiers ?? []).filter(m => this.defs.get(m.modifierName.referencedDeclaration)?.nodeType === 'ModifierDefinition'), 0));
|
|
405
440
|
}
|
|
406
441
|
if (this.ether)
|
|
@@ -415,6 +450,7 @@ class Lower {
|
|
|
415
450
|
const params = [{ name: 'self', t: { k: 'rec', name: k.name }, self: true }, { name: MOD, t: { k: 'int' } }, { name: 'msg.sender', t: this.ADDR }, ...(this.cur.payable ? [{ name: 'msg.value', t: U256 }] : [])];
|
|
416
451
|
for (const pa of (top?.parameters.parameters ?? []))
|
|
417
452
|
params.push({ name: pa.name, t: this.ty(pa.typeDescriptions.typeString, pa) });
|
|
453
|
+
this.ctorParams.clear();
|
|
418
454
|
return { id: '__init__', name: '__init__', p, span: [p, 0, 0], params, ret: { k: 'none' }, body, decorators: [] };
|
|
419
455
|
}
|
|
420
456
|
// --- statements ------------------------------------------------------------------------------------------------------
|
|
@@ -533,7 +569,7 @@ class Lower {
|
|
|
533
569
|
const f = this.fieldOf(n);
|
|
534
570
|
if (f)
|
|
535
571
|
return f.t.k === 'opaque' ? (/string|bytes/.test(f.sol) ? undefined : this.no(n, f.t.why)) : self(f.name, p);
|
|
536
|
-
return { e: 'var', n: n.name, p };
|
|
572
|
+
return this.ctorParams.get(n.referencedDeclaration) ?? { e: 'var', n: n.name, p };
|
|
537
573
|
}
|
|
538
574
|
if (n.nodeType === 'IndexAccess') {
|
|
539
575
|
if (this.nestedOf(n)) {
|
|
@@ -596,6 +632,8 @@ class Lower {
|
|
|
596
632
|
return this.no(n, `${n.name} alone`);
|
|
597
633
|
if (this.consts.has(n.referencedDeclaration))
|
|
598
634
|
return this.consts.get(n.referencedDeclaration);
|
|
635
|
+
if (this.ctorParams.has(n.referencedDeclaration))
|
|
636
|
+
return this.ctorParams.get(n.referencedDeclaration);
|
|
599
637
|
const f = this.fieldOf(n);
|
|
600
638
|
if (f)
|
|
601
639
|
return f.t.k === 'opaque' ? { e: 'opaque', p, why: `${n.name}: ${f.t.why}` } : self(f.name, p);
|
|
@@ -787,11 +825,18 @@ const hasReturn = (ss) => ss.some(s => s.s === 'ret' || (s.s === 'if' && (hasRet
|
|
|
787
825
|
const abiType = (ts) => (ts.startsWith('address') ? 'address' : ts.startsWith('enum ') ? 'uint8' : ts.startsWith('contract ') ? 'address' : ts.replace(/ (storage|memory|calldata).*$/, ''));
|
|
788
826
|
// --- the front end ---------------------------------------------------------------------------------------------------
|
|
789
827
|
export function readSolidity(file, o = {}, reenter = false, compiled) {
|
|
790
|
-
const c = compiled ?? compile(file, o);
|
|
828
|
+
const c = compiled ?? concreteSolidity(file, o, compile(file, o), compile);
|
|
791
829
|
const L = new Lower(c, file, reenter);
|
|
792
|
-
const entry = typeof o.entry === 'string' ? o.entry : undefined;
|
|
793
|
-
|
|
794
|
-
|
|
830
|
+
const entry = c.harness?.entry ?? (typeof o.entry === 'string' ? o.entry : undefined);
|
|
831
|
+
try {
|
|
832
|
+
const { mod, meta } = L.module(entry, o.methods ?? c.harnessMethods);
|
|
833
|
+
return { mod, meta, c };
|
|
834
|
+
}
|
|
835
|
+
catch (e) {
|
|
836
|
+
if (e instanceof Refusal && c.harness)
|
|
837
|
+
throw new SolidityHarnessRefusal(e, c.harness);
|
|
838
|
+
throw e;
|
|
839
|
+
}
|
|
795
840
|
}
|
|
796
841
|
export function extractSolidity(at, opts = {}) {
|
|
797
842
|
const file = pathOf(at);
|
|
@@ -801,10 +846,11 @@ export function extractSolidity(at, opts = {}) {
|
|
|
801
846
|
}
|
|
802
847
|
catch (e) {
|
|
803
848
|
if (e instanceof Refusal)
|
|
804
|
-
return { ok: false, refusals: [{ where: e.where, what: e.what }], notes: [] };
|
|
849
|
+
return { ok: false, refusals: [{ where: e.where, what: e.what }], notes: e instanceof SolidityHarnessRefusal ? e.harness.notes : [], ...(e instanceof SolidityHarnessRefusal ? { harness: e.harness } : {}) };
|
|
805
850
|
throw e;
|
|
806
851
|
}
|
|
807
852
|
const { mod, meta, c } = r;
|
|
853
|
+
const info = c.harness ? { harness: c.harness } : {};
|
|
808
854
|
const out = c.contracts[meta.source]?.[meta.contract];
|
|
809
855
|
const harness = (read) => {
|
|
810
856
|
read.arms.length = 0;
|
|
@@ -825,16 +871,21 @@ export function extractSolidity(at, opts = {}) {
|
|
|
825
871
|
const havoc = Object.fromEntries(meta.fields.filter(f => meta.nested.includes(f.name)).map(f => [f.name, f.t.val.k === 'bool' ? 'bool' : 'int']));
|
|
826
872
|
const o = { ...opts, methods, share: opts.share ?? true, strict: true, onError: 'discard', entry: meta.contract, check: { probes: 'writes', ...opts.check }, answers: { ...havoc, ...opts.answers } };
|
|
827
873
|
// extractStep's run, the width's param fixed for the check's own draws (2^52: the proof is for every width)
|
|
828
|
-
const notes = [];
|
|
874
|
+
const notes = [...c.harness?.notes ?? []];
|
|
829
875
|
let read;
|
|
830
876
|
try {
|
|
831
877
|
read = readStep(mod, o);
|
|
832
878
|
}
|
|
833
879
|
catch (e) {
|
|
834
880
|
if (e instanceof Refusal)
|
|
835
|
-
return { ok: false, refusals: [{ where: e.where, what: e.what }], notes };
|
|
881
|
+
return { ok: false, refusals: [{ where: e.where, what: e.what }], notes, ...info };
|
|
836
882
|
throw e;
|
|
837
883
|
}
|
|
884
|
+
// Constructor argument bounds name the state width; before an object exists that is its initial parameter.
|
|
885
|
+
// Keep the bound, but bind it in the parameter-only precondition rather than leaving a state reference there.
|
|
886
|
+
const widthInit = read.model.init[MOD];
|
|
887
|
+
if (widthInit?.s === 'num')
|
|
888
|
+
read.model.pre = substN(read.model.pre, MOD, widthInit.e);
|
|
838
889
|
const w = read.model.params.find(v => v.name.startsWith(MOD));
|
|
839
890
|
if (w)
|
|
840
891
|
w.derived = { op: 'const', v: CHECK_W };
|
|
@@ -846,11 +897,11 @@ export function extractSolidity(at, opts = {}) {
|
|
|
846
897
|
const unsigned = Object.fromEntries([...read.model.inputs, ...read.model.params].filter(v => read.ints[v.name] && !read.ints[v.name].signed).map(v => [v.name, 'nat']));
|
|
847
898
|
const x = fromModel(read.model, mod.file, { ...unsigned, ...o.domains }, notes, (rule, sorts) => checkStep(harness(read), read, rule, sorts, o));
|
|
848
899
|
if (!x.ok)
|
|
849
|
-
return { ...x, read, names: stepNames(read) };
|
|
900
|
+
return { ...x, ...info, read, names: stepNames(read) };
|
|
850
901
|
// (a run that breaks a law, from the prover at any width: replayed on the code at the check's before it is shown)
|
|
851
902
|
if (!meta.calls || opts.reentrant === false) {
|
|
852
903
|
const rp = replayer({ rule: x.rule, sorts: x.sorts, model: read.model, names: stepNames(read), leaves: read.leaves, hello: harness(read).hello.sol, ctor: read.ctor, replay: compileReplay(opts), opts });
|
|
853
|
-
return { ...x, read, names: stepNames(read), replay: (run, law) => rp(run, law) };
|
|
904
|
+
return { ...x, ...info, read, names: stepNames(read), replay: (run, law) => rp(run, law) };
|
|
854
905
|
}
|
|
855
906
|
// The rule the laws are proven of: every call into other code a point where any of the contract's calls may run.
|
|
856
907
|
let re, rread;
|
|
@@ -860,14 +911,17 @@ export function extractSolidity(at, opts = {}) {
|
|
|
860
911
|
}
|
|
861
912
|
catch (e) {
|
|
862
913
|
if (e instanceof Refusal)
|
|
863
|
-
return { ok: false, refusals: [{ where: e.where, what: `re-entrancy: ${e.what}` }], notes: [...x.notes] };
|
|
914
|
+
return { ok: false, refusals: [{ where: e.where, what: `re-entrancy: ${e.what}` }], notes: [...x.notes], ...info };
|
|
864
915
|
throw e;
|
|
865
916
|
}
|
|
917
|
+
const reWidthInit = rread.model.init[MOD];
|
|
918
|
+
if (reWidthInit?.s === 'num')
|
|
919
|
+
rread.model.pre = substN(rread.model.pre, MOD, reWidthInit.e);
|
|
866
920
|
const rw = rread.model.params.find(v => v.name.startsWith(MOD));
|
|
867
921
|
if (rw)
|
|
868
922
|
rw.derived = { op: 'const', v: CHECK_W };
|
|
869
923
|
rread.model.notes.push(...boundaryNotes(meta), `re-entrancy: each call into other code (${re.meta.resumes.map(r => r.replace(/\$resume$/, '')).join(', ')}) is two steps, any of the contract's calls between them (a callee that calls back); a law about the state holds where no call is pending (pending$ == 0)`);
|
|
870
|
-
const rnotes = [];
|
|
924
|
+
const rnotes = [...c.harness?.notes ?? []];
|
|
871
925
|
// The check of the re-entrant rule: its own random runs (calls inside calls, by any address) replayed on the code,
|
|
872
926
|
// every address an Agent that makes the run's calls from inside the call it receives.
|
|
873
927
|
let replays;
|
|
@@ -880,7 +934,12 @@ export function extractSolidity(at, opts = {}) {
|
|
|
880
934
|
const run = randomRun(rule, rread.model, rand);
|
|
881
935
|
if (!run.trace.length)
|
|
882
936
|
continue;
|
|
883
|
-
|
|
937
|
+
// (the replay's harness failing: once more, then the check's failure, no verdict)
|
|
938
|
+
let r = replays(run);
|
|
939
|
+
if (!r.ok && r.harness)
|
|
940
|
+
r = replays(run);
|
|
941
|
+
if (!r.ok && r.harness)
|
|
942
|
+
return { ...ev, harness: r.what };
|
|
884
943
|
if (!r.ok)
|
|
885
944
|
return { ...ev, mismatch: `re-entrancy: a run of the rule replayed on the code: ${r.what}` };
|
|
886
945
|
runs.runs++;
|
|
@@ -892,7 +951,7 @@ export function extractSolidity(at, opts = {}) {
|
|
|
892
951
|
});
|
|
893
952
|
if (rx.ok)
|
|
894
953
|
rx.notes.push(`re-entrancy: checked by ${runs.runs} runs of the rule replayed on the code (${runs.txs} transactions, ${runs.nested} calls made from inside another, ${runs.steps} steps), an Agent at every address making each call from inside the one it receives`);
|
|
895
|
-
return { ...rx, read: rread, names: stepNames(rread), quiet: 'pending$', ...(replays ? { replay: (run, law) => replays(run, law) } : {}) };
|
|
954
|
+
return { ...rx, ...info, read: rread, names: stepNames(rread), quiet: 'pending$', ...(replays ? { replay: (run, law) => replays(run, law) } : {}) };
|
|
896
955
|
}
|
|
897
956
|
function compileReplay(o) {
|
|
898
957
|
const c = compile(asset('sol/Replay.sol'), { ...o, root: asset('sol/') });
|
|
@@ -948,7 +1007,7 @@ function randomRun(rule, model, rand) {
|
|
|
948
1007
|
// rule's, every call made. With a law, the law broken by the run at that width too.
|
|
949
1008
|
function replayer(c) {
|
|
950
1009
|
return (run, law) => {
|
|
951
|
-
const no = (what) => ({ ok: false, what, txs: 0, nested: 0 });
|
|
1010
|
+
const no = (what, harness = false) => ({ ok: false, what, txs: 0, nested: 0, ...(harness ? { harness: true } : {}) });
|
|
952
1011
|
const isLaw = !!law && typeof law === 'object' && 'holds' in law;
|
|
953
1012
|
let R = c.rule;
|
|
954
1013
|
try {
|
|
@@ -1016,14 +1075,14 @@ function replayer(c) {
|
|
|
1016
1075
|
out = JSON.parse(cp.execFileSync(c.opts.python ?? 'python3', [asset('sol/harness.py'), '--replay', `${dir}/run.json`], { encoding: 'utf8', maxBuffer: 1 << 26, stdio: ['ignore', 'pipe', 'pipe'], env: { ...env(), ...(c.opts.anvil ? { GDP_ANVIL: c.opts.anvil } : {}) } }));
|
|
1017
1076
|
}
|
|
1018
1077
|
catch (e) {
|
|
1019
|
-
return no(`the replay didn't run (${String(e.message).slice(0, 300)})
|
|
1078
|
+
return no(`the replay didn't run (${String(e.message).slice(0, 300)})`, true);
|
|
1020
1079
|
}
|
|
1021
1080
|
finally {
|
|
1022
1081
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
1023
1082
|
}
|
|
1024
|
-
if (out.error)
|
|
1025
|
-
return no(`the code: ${out.error}`);
|
|
1026
1083
|
const shown = (g) => groups[g].map(e => (e.kind === 'ret' ? `return(${e.ok})` : `${e.m}(${e.a.map(([n, v]) => `${n}=${String(v.in)}`).join(', ')})`)).join(' ');
|
|
1084
|
+
if (out.error)
|
|
1085
|
+
return no(out.transport ? `the replay's harness: ${out.error}` : `the code: ${out.error} (the run: ${groups.map((_, g) => shown(g)).join('; ')})`, !!out.transport);
|
|
1027
1086
|
for (const [g, ok] of (out.oks ?? []).entries())
|
|
1028
1087
|
if (ok.some(x => !x))
|
|
1029
1088
|
return no(`transaction ${g + 1} (${shown(g)}): a call the rule takes reverts in the code`);
|