gdp-wired 0.43.0 → 0.45.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 +8 -3
- package/dist/core/c/reader.js +22 -7
- package/dist/core/check.js +3 -2
- package/dist/core/cli.d.ts +7 -0
- package/dist/core/cli.js +184 -12
- package/dist/core/counts.d.ts +1 -1
- package/dist/core/counts.js +30 -12
- package/dist/core/data.d.ts +6 -1
- package/dist/core/data.js +894 -152
- package/dist/core/dsl.d.ts +2 -0
- package/dist/core/dsl.js +88 -10
- package/dist/core/effect-prims.d.ts +60 -0
- package/dist/core/effect-prims.js +625 -0
- package/dist/core/effect.d.ts +17 -1
- package/dist/core/effect.js +108 -4
- package/dist/core/ex/harness.exs +2 -0
- package/dist/core/ex/reader.exs +17 -1
- package/dist/core/exists.d.ts +15 -1
- package/dist/core/exists.js +263 -41
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +22 -13
- package/dist/core/extract-check.d.ts +7 -0
- package/dist/core/extract-check.js +57 -4
- package/dist/core/extract-ex.js +5 -5
- package/dist/core/extract-go-check.js +22 -17
- package/dist/core/extract-go.d.ts +3 -0
- package/dist/core/extract-go.js +24 -9
- package/dist/core/extract-jvm.js +68 -16
- package/dist/core/extract-print.js +3 -0
- package/dist/core/extract-py.js +5 -5
- package/dist/core/extract-rb.js +5 -5
- package/dist/core/extract-read.d.ts +8 -0
- package/dist/core/extract-read.js +55 -0
- package/dist/core/extract-rs.js +28 -25
- package/dist/core/extract-shapes.js +20 -0
- package/dist/core/extract-sol.js +23 -12
- package/dist/core/extract-step.d.ts +59 -3
- package/dist/core/extract-step.js +334 -64
- package/dist/core/extract-swift.js +22 -15
- package/dist/core/extract.d.ts +1 -0
- package/dist/core/extract.js +27 -2
- 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.js +113 -40
- package/dist/core/jvm/Harness.java +8 -1
- package/dist/core/jvm/JavaReader.java +10 -2
- package/dist/core/jvm/Jvm.java +18 -2
- package/dist/core/jvm/KtReader.java +60 -5
- package/dist/core/machine.d.ts +2 -0
- package/dist/core/machine.js +32 -6
- package/dist/core/py/harness.py +128 -24
- package/dist/core/py/reader.py +50 -5
- package/dist/core/rb/reader.rb +52 -5
- package/dist/core/rs/src/main.rs +10 -0
- package/dist/core/sol/Replay.sol +52 -0
- package/dist/core/sol/harness.py +511 -0
- package/dist/core/solver.js +5 -4
- package/dist/core/system.d.ts +62 -1
- package/dist/core/system.js +274 -6
- package/dist/core/transfer.js +17 -0
- package/dist/core/watch.js +1 -1
- package/dist/interchange/check.d.ts +18 -1
- package/dist/interchange/check.js +19 -12
- package/dist/interchange/cli.d.ts +2 -0
- package/dist/interchange/cli.js +45 -0
- package/dist/interchange/format.d.ts +5 -1
- package/dist/interchange/format.js +25 -9
- package/dist/kernel/cdcl.js +65 -14
- package/dist/kernel/epr.js +35 -5
- package/dist/kernel/kernel.d.ts +2 -0
- package/dist/kernel/kernel.js +67 -40
- package/dist/kernel/prove.d.ts +22 -0
- package/dist/kernel/prove.js +156 -7
- package/dist/kernel/reader.js +3 -2
- package/dist/lean-kernel/emit.d.ts +9 -3
- package/dist/lean-kernel/emit.js +170 -29
- package/dist/lean-kernel/library.js +1 -1
- package/package.json +12 -3
package/dist/core/extract-rs.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Refusal, pathOf } from "./extract-read.js";
|
|
2
|
-
import { entryNames, extractStep, node, stubbed } from "./extract-step.js";
|
|
1
|
+
import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
|
|
2
|
+
import { asset, buildCheck, compileLimit, entryNames, extractStep, node, stubbed } from "./extract-step.js";
|
|
3
3
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
4
4
|
const proc = globalThis.process;
|
|
5
5
|
// The reader, built once per version of its source (into the system's temporary directory).
|
|
6
6
|
export function rsReader(cargo = 'cargo') {
|
|
7
7
|
const fs = node('node:fs'), cp = node('node:child_process'), os = node('node:os'), crypto = node('node:crypto');
|
|
8
|
-
const dir =
|
|
8
|
+
const dir = asset('rs/');
|
|
9
9
|
const h = crypto.createHash('sha256').update(fs.readFileSync(`${dir}src/main.rs`, 'utf8') + fs.readFileSync(`${dir}Cargo.toml`, 'utf8')).digest('hex').slice(0, 12);
|
|
10
10
|
const target = `${os.tmpdir()}/gdp-rsreader-${h}`, bin = `${target}/release/gdp-rsreader`;
|
|
11
11
|
if (!fs.existsSync(bin))
|
|
@@ -16,10 +16,10 @@ export function readRust(dir, names, cargo) {
|
|
|
16
16
|
const cp = node('node:child_process');
|
|
17
17
|
let out;
|
|
18
18
|
try {
|
|
19
|
-
out = cp.execFileSync(rsReader(cargo), [JSON.stringify({ root: dir, names })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
19
|
+
out = cp.execFileSync(rsReader(cargo), [JSON.stringify({ root: dir, names })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'], ...readerRun() });
|
|
20
20
|
}
|
|
21
21
|
catch (e) {
|
|
22
|
-
throw new Refusal(dir, `the Rust reader didn't run (${String(e.stderr ?? e.message).split('\n').filter(Boolean).slice(-2).join(' | ')}): cargo is needed to extract Rust`);
|
|
22
|
+
throw new Refusal(dir, statedRefusal(e) ?? `the Rust reader didn't run (${String(e.stderr ?? e.message).split('\n').filter(Boolean).slice(-2).join(' | ')}): cargo is needed to extract Rust`);
|
|
23
23
|
}
|
|
24
24
|
return JSON.parse(out);
|
|
25
25
|
}
|
|
@@ -177,12 +177,15 @@ pub(crate) mod __gdp_harness {
|
|
|
177
177
|
// An answered call's value: the request's input for it (each answered call rewritten to crate::__gdp_answer).
|
|
178
178
|
static ANS: std::sync::Mutex<Option<Value>> = std::sync::Mutex::new(None);
|
|
179
179
|
pub(crate) trait GdpAns { fn of(v: &Value) -> Self; }
|
|
180
|
-
|
|
180
|
+
// (an answer outside the call's type, a type stated wider than the code's: a request the code can't be given)
|
|
181
|
+
pub(crate) struct GdpOutside(pub(crate) String);
|
|
182
|
+
macro_rules! gdp_int { ($($t:ty),*) => { $(impl GdpAns for $t { fn of(v: &Value) -> Self { match int(val(v)) { Ok(n) => <$t>::try_from(n).unwrap_or_else(|_| std::panic::panic_any(GdpOutside(format!("{} outside {}", n, stringify!($t))))), Err(_) => Default::default() } } })* } }
|
|
181
183
|
gdp_int!(i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize);
|
|
182
184
|
impl GdpAns for bool { fn of(v: &Value) -> Self { val(v).as_bool().unwrap_or(false) } }
|
|
183
185
|
impl GdpAns for String { fn of(v: &Value) -> Self { val(v).as_str().unwrap_or("").to_string() } }
|
|
184
186
|
impl<T: GdpAns> GdpAns for Option<T> { fn of(v: &Value) -> Self { if v.get("none").and_then(|x| x.as_bool()) == Some(true) { None } else { Some(T::of(v)) } } }
|
|
185
|
-
|
|
187
|
+
// (the value taken out of the lock first: an answer outside its type panics, which must leave the lock usable)
|
|
188
|
+
pub(crate) fn answer<T: GdpAns>(k: &str) -> T { let v = ANS.lock().unwrap_or_else(|e| e.into_inner()).as_ref().and_then(|a| a.get(k).cloned()).unwrap_or(Value::Null); T::of(&v) }
|
|
186
189
|
fn base() -> std::time::Instant { *BASE.get_or_init(|| std::time::Instant::now() + std::time::Duration::from_secs(1u64 << 31)) }
|
|
187
190
|
pub(crate) fn now() -> std::time::Instant { inst(NOW.load(std::sync::atomic::Ordering::SeqCst) as i128) }
|
|
188
191
|
fn inst(n: i128) -> std::time::Instant { if n >= 0 { base() + std::time::Duration::from_nanos(n as u64) } else { base() - std::time::Duration::from_nanos((-n) as u64) } }
|
|
@@ -216,7 +219,7 @@ pub(crate) mod __gdp_harness {
|
|
|
216
219
|
"call" => {
|
|
217
220
|
let i = req["id"].as_u64().unwrap() as usize - 1;
|
|
218
221
|
NOW.store(int(&req["now"]).unwrap_or(0) as i64, std::sync::atomic::Ordering::SeqCst);
|
|
219
|
-
*ANS.lock().
|
|
222
|
+
*ANS.lock().unwrap_or_else(|e| e.into_inner()) = Some(req["answers"].clone());
|
|
220
223
|
let m = req["m"].as_str().unwrap().to_string();
|
|
221
224
|
let a = req["a"].clone();
|
|
222
225
|
let o = &mut objs[i];
|
|
@@ -224,6 +227,7 @@ pub(crate) mod __gdp_harness {
|
|
|
224
227
|
Ok(Ok(Ok(v))) => json!({"out": v}),
|
|
225
228
|
Ok(Ok(Err(e))) => json!({"out": null, "err": e}),
|
|
226
229
|
Ok(Err(bad)) => json!({"out": null, "bad": bad}),
|
|
230
|
+
Err(p) if p.downcast_ref::<GdpOutside>().is_some() => json!({"out": null, "outside": p.downcast_ref::<GdpOutside>().unwrap().0}),
|
|
227
231
|
Err(p) => json!({"out": null, "err": format!("panic: {}", p.downcast_ref::<String>().cloned().or_else(|| p.downcast_ref::<&str>().map(|s| s.to_string())).unwrap_or_default())}),
|
|
228
232
|
}
|
|
229
233
|
}
|
|
@@ -257,8 +261,9 @@ function harnessFor(dir, mod, read, opts) {
|
|
|
257
261
|
// The clock: Instant::now() read through the harness (the request's time), the code's own calls rewritten first.
|
|
258
262
|
const lib = fs.existsSync(`${work}/src/lib.rs`) ? 'src/lib.rs' : 'src/main.rs';
|
|
259
263
|
const walk = (d) => fs.readdirSync(d, { withFileTypes: true }).flatMap((e) => { const x = e; return x.isDirectory() ? walk(`${d}/${x.name}`) : x.name.endsWith('.rs') ? [`${d}/${x.name}`] : []; });
|
|
260
|
-
// (each answered call rewritten to the harness's answer, from the crate's own text, before the clock's
|
|
261
|
-
|
|
264
|
+
// (each answered call rewritten to the harness's answer, from the crate's own text, before the clock's; the call
|
|
265
|
+
// kept in a branch never taken, so the answer is of the type the call is, which a binding needn't write)
|
|
266
|
+
for (const [f, t] of stubbed(read, f => fs.readFileSync(`${dir}/${f}`, 'utf8'), (a, _, call) => `(if false { ${call} } else { crate::__gdp_answer(${JSON.stringify(a.key)}) })`))
|
|
262
267
|
fs.writeFileSync(`${work}/${f}`, t);
|
|
263
268
|
for (const f of walk(`${work}/src`)) {
|
|
264
269
|
const s = fs.readFileSync(f, 'utf8');
|
|
@@ -266,24 +271,22 @@ function harnessFor(dir, mod, read, opts) {
|
|
|
266
271
|
if (t !== s)
|
|
267
272
|
fs.writeFileSync(f, t);
|
|
268
273
|
}
|
|
274
|
+
// (the lines of the code itself in the files the harness is appended to: an error past them is the harness's)
|
|
275
|
+
const own = new Map([file, lib].map(f => [f, fs.readFileSync(`${work}/${f}`, 'utf8').split('\n').length]));
|
|
269
276
|
fs.writeFileSync(`${work}/${file}`, fs.readFileSync(`${work}/${file}`, 'utf8') + harnessCode(mod, read, cls));
|
|
270
277
|
fs.writeFileSync(`${work}/${lib}`, `${fs.readFileSync(`${work}/${lib}`, 'utf8')}\n#[cfg(test)]\n#[allow(unused)]\npub(crate) fn __gdp_now() -> std::time::Instant { ${modPath}::__gdp_harness::now() }\n#[cfg(test)]\n#[allow(unused)]\npub(crate) fn __gdp_answer<T: ${modPath}::__gdp_harness::GdpAns>(k: &str) -> T { ${modPath}::__gdp_harness::answer(k) }\n`);
|
|
271
278
|
const target = `${os.tmpdir()}/gdp-rscheck-target`;
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
catch (e) {
|
|
277
|
-
const out = String(e.stdout ?? '');
|
|
278
|
-
const errs = out.split('\n').flatMap(l => { try {
|
|
279
|
-
const j = JSON.parse(l);
|
|
280
|
-
return j.reason === 'compiler-message' && j.message?.level === 'error' ? [j.message.rendered ?? ''] : [];
|
|
281
|
-
}
|
|
282
|
-
catch {
|
|
283
|
-
return [];
|
|
284
|
-
} });
|
|
285
|
-
return { cmd: 'false', args: [], hello: {}, error: `the crate doesn't build with the check's harness: ${(errs.join(' | ') || String(e.stderr ?? '')).replace(/\s+/g, ' ').slice(0, 600)}` };
|
|
279
|
+
const built = buildCheck('cargo', () => cp.execFileSync(opts.cargo ?? 'cargo', ['test', '--lib', '--no-run', '--message-format=json', '--target-dir', target], { cwd: work, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 1 << 28, env: { ...proc?.env }, timeout: compileLimit(), killSignal: 'SIGKILL' }), e => String(e.stdout ?? '').split('\n').flatMap(l => { try {
|
|
280
|
+
const j = JSON.parse(l);
|
|
281
|
+
return j.reason === 'compiler-message' && j.message?.level === 'error' ? [(j.message.rendered ?? '').replace(/\s+/g, ' ')] : [];
|
|
286
282
|
}
|
|
283
|
+
catch {
|
|
284
|
+
return [];
|
|
285
|
+
} }), l => { const m = /--> ([^\s:]+\.rs):(\d+):\d+/.exec(l); if (!m)
|
|
286
|
+
return false; const n = own.get(m[1]); return n === undefined || Number(m[2]) <= n; });
|
|
287
|
+
if (!('ok' in built))
|
|
288
|
+
return { cmd: 'false', args: [], hello: {}, error: built.why, kind: built.kind };
|
|
289
|
+
const msgs = built.ok;
|
|
287
290
|
const exe = msgs.split('\n').flatMap(l => { try {
|
|
288
291
|
const j = JSON.parse(l);
|
|
289
292
|
return j.reason === 'compiler-artifact' && j.executable && j.target?.kind?.includes('lib') ? [j.executable] : [];
|
|
@@ -292,7 +295,7 @@ function harnessFor(dir, mod, read, opts) {
|
|
|
292
295
|
return [];
|
|
293
296
|
} })[0];
|
|
294
297
|
if (!exe)
|
|
295
|
-
return { cmd: 'false', args: [], hello: {}, error: 'the test build gave no executable' };
|
|
298
|
+
return { cmd: 'false', args: [], hello: {}, error: 'the test build gave no executable', kind: 'harness' };
|
|
296
299
|
read.model.notes.push('Rust: the code is checked in a debug build (overflow checks on); its branch arms are not counted (no instrumentation yet)');
|
|
297
300
|
read.arms.length = 0;
|
|
298
301
|
const test = `${modPath === 'crate' ? '' : `${modPath.replace(/^crate::/, '')}::`}__gdp_harness::__gdp_harness_main`;
|
|
@@ -950,6 +950,17 @@ function attempt(code, file, opts, written) {
|
|
|
950
950
|
// The methods: each public one an event (the nearest of each name, through the classes it extends), run from the
|
|
951
951
|
// state as variables.
|
|
952
952
|
const seenNames = new Set(), methods = [];
|
|
953
|
+
// (two bodies of one name in one class: JavaScript keeps the last, TypeScript refuses it)
|
|
954
|
+
for (const c of chain) {
|
|
955
|
+
const bodies = new Set();
|
|
956
|
+
for (const m of c.members)
|
|
957
|
+
if (ts.isMethodDeclaration(m) && m.body) {
|
|
958
|
+
const k = `${has(m, ts.SyntaxKind.StaticKeyword) ? 'static ' : ''}${memberName(m.name)}`;
|
|
959
|
+
if (bodies.has(k))
|
|
960
|
+
refuse(m, `${memberName(m.name)}: a second body of it in one class (JavaScript keeps the last; TypeScript refuses it)`);
|
|
961
|
+
bodies.add(k);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
953
964
|
for (const c of chain)
|
|
954
965
|
for (const m of c.members) {
|
|
955
966
|
if (!ts.isMethodDeclaration(m) || seenNames.has(memberName(m.name)))
|
|
@@ -1294,6 +1305,15 @@ function factoryAttempt(code, file, opts, written, fxOf) {
|
|
|
1294
1305
|
for (const [id, o] of fx?.start ?? [])
|
|
1295
1306
|
stateHeap.set(id, o);
|
|
1296
1307
|
const strip0 = (e) => (ts.isParenthesizedExpression(e) || ts.isAsExpression(e) ? strip0(e.expression) : e);
|
|
1308
|
+
// (two members of one name: JavaScript keeps the last, TypeScript refuses it)
|
|
1309
|
+
const names = new Set();
|
|
1310
|
+
for (const p of obj.properties)
|
|
1311
|
+
if (p.name && !ts.isComputedPropertyName(p.name)) {
|
|
1312
|
+
const n = memberName(p.name);
|
|
1313
|
+
if (names.has(n))
|
|
1314
|
+
refuse(p, `${n}: a second member of it in the object returned (JavaScript keeps the last; TypeScript refuses it)`);
|
|
1315
|
+
names.add(n);
|
|
1316
|
+
}
|
|
1297
1317
|
const fns = obj.properties.map(p => {
|
|
1298
1318
|
if (ts.isMethodDeclaration(p))
|
|
1299
1319
|
return { name: memberName(p.name), decl: p };
|
package/dist/core/extract-sol.js
CHANGED
|
@@ -27,9 +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 { Refusal, pathOf } from "./extract-read.js";
|
|
30
|
+
import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
|
|
31
31
|
const refuse = (where, what) => { throw new Refusal(where, what); };
|
|
32
|
-
import { checkStep, node, readStep, stepNames } from "./extract-step.js";
|
|
32
|
+
import { asset, checkStep, node, readStep, stepNames } from "./extract-step.js";
|
|
33
33
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
34
34
|
export const MOD = 'W256$';
|
|
35
35
|
// (the width the check runs the rule at: past 2^256's half the code's values are the rule's near W)
|
|
@@ -44,10 +44,10 @@ export function compile(file, o) {
|
|
|
44
44
|
let out;
|
|
45
45
|
const solc = o.solc ?? env().GDP_SOLC ?? 'solc';
|
|
46
46
|
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'] });
|
|
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'], ...readerRun() });
|
|
48
48
|
}
|
|
49
49
|
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)`);
|
|
50
|
+
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
51
|
}
|
|
52
52
|
const j = JSON.parse(out);
|
|
53
53
|
const errs = (j.errors ?? []).filter(e => e.severity === 'error');
|
|
@@ -293,6 +293,12 @@ class Lower {
|
|
|
293
293
|
const mk = body[i], pre = body.slice(0, i), rest = body.slice(i + 1);
|
|
294
294
|
if (callsOut(rest))
|
|
295
295
|
refuse(p, `${name}: two calls into other code (the subset splits at one)`);
|
|
296
|
+
// (a failed call must revert the caller, as transfer and require(ok) do: the EVM undoes what the callee did, the
|
|
297
|
+
// contract's calls back included, which the steps between the two the rule holds can't undo)
|
|
298
|
+
const okv = String(mk.ok), r0 = rest[0], x0 = r0?.c;
|
|
299
|
+
const reverts = mk.how === 'transfer' || (r0?.s === 'if' && x0?.e === 'not' && x0.x?.e === 'var' && x0.x.n === okv && (r0.then[0]?.s === 'fail'));
|
|
300
|
+
if (!reverts)
|
|
301
|
+
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
302
|
// The locals the rest may read: the parameters, and every local the part before sets.
|
|
297
303
|
const locals = new Map();
|
|
298
304
|
for (const pa of params)
|
|
@@ -815,7 +821,7 @@ export function extractSolidity(at, opts = {}) {
|
|
|
815
821
|
const slots = Object.fromEntries(out.storageLayout.storage.map(s => [s.label, { slot: s.slot, offset: s.offset, bytes: Number(types[s.type]?.numberOfBytes ?? 32), map: types[s.type]?.encoding === 'mapping', nested: meta.nested.includes(s.label), type: s.type }]));
|
|
816
822
|
const kinds = Object.fromEntries(meta.fields.map(f => [f.name, kindOf(f.t, f.sol)]));
|
|
817
823
|
const mapKeys = Object.fromEntries(meta.fields.filter(f => f.sol.startsWith('mapping(')).map(f => [f.name, keyKinds(f.sol)]));
|
|
818
|
-
return { cmd: opts.python ?? 'python3', args: [
|
|
824
|
+
return { cmd: opts.python ?? 'python3', args: [asset('sol/harness.py')], env: { ...(opts.anvil ? { GDP_ANVIL: opts.anvil } : {}) },
|
|
819
825
|
hello: { sol: { creation: out.evm.bytecode.object, abi: out.abi, ids: out.evm.methodIdentifiers, slots, kinds, mapKeys, havoc: meta.nested, havocBy: havocBy(mod), mod: MOD, minW: meta.minW, addrBits: meta.addrBits, entries: meta.entries, ctor: meta.ctor, ether: meta.ether } } };
|
|
820
826
|
};
|
|
821
827
|
// (methods: the external functions that may write the state, unless named)
|
|
@@ -880,7 +886,12 @@ export function extractSolidity(at, opts = {}) {
|
|
|
880
886
|
const run = randomRun(rule, rread.model, rand);
|
|
881
887
|
if (!run.trace.length)
|
|
882
888
|
continue;
|
|
883
|
-
|
|
889
|
+
// (the replay's harness failing: once more, then the check's failure, no verdict)
|
|
890
|
+
let r = replays(run);
|
|
891
|
+
if (!r.ok && r.harness)
|
|
892
|
+
r = replays(run);
|
|
893
|
+
if (!r.ok && r.harness)
|
|
894
|
+
return { ...ev, harness: r.what };
|
|
884
895
|
if (!r.ok)
|
|
885
896
|
return { ...ev, mismatch: `re-entrancy: a run of the rule replayed on the code: ${r.what}` };
|
|
886
897
|
runs.runs++;
|
|
@@ -895,7 +906,7 @@ export function extractSolidity(at, opts = {}) {
|
|
|
895
906
|
return { ...rx, read: rread, names: stepNames(rread), quiet: 'pending$', ...(replays ? { replay: (run, law) => replays(run, law) } : {}) };
|
|
896
907
|
}
|
|
897
908
|
function compileReplay(o) {
|
|
898
|
-
const c = compile(
|
|
909
|
+
const c = compile(asset('sol/Replay.sol'), { ...o, root: asset('sol/') });
|
|
899
910
|
const k = c.contracts[c.paths.get(c.main)];
|
|
900
911
|
return { agent: k.Agent.evm.deployedBytecode.object, director: k.Director.evm.deployedBytecode.object };
|
|
901
912
|
}
|
|
@@ -948,7 +959,7 @@ function randomRun(rule, model, rand) {
|
|
|
948
959
|
// rule's, every call made. With a law, the law broken by the run at that width too.
|
|
949
960
|
function replayer(c) {
|
|
950
961
|
return (run, law) => {
|
|
951
|
-
const no = (what) => ({ ok: false, what, txs: 0, nested: 0 });
|
|
962
|
+
const no = (what, harness = false) => ({ ok: false, what, txs: 0, nested: 0, ...(harness ? { harness: true } : {}) });
|
|
952
963
|
const isLaw = !!law && typeof law === 'object' && 'holds' in law;
|
|
953
964
|
let R = c.rule;
|
|
954
965
|
try {
|
|
@@ -1013,17 +1024,17 @@ function replayer(c) {
|
|
|
1013
1024
|
let out;
|
|
1014
1025
|
try {
|
|
1015
1026
|
fs.writeFileSync(`${dir}/run.json`, JSON.stringify({ sol: c.hello, leaves: c.leaves, ctorSpec: c.ctor, ctor: ctorArgs, agent: c.replay.agent, director: c.replay.director, groups }));
|
|
1016
|
-
out = JSON.parse(cp.execFileSync(c.opts.python ?? 'python3', [
|
|
1027
|
+
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
1028
|
}
|
|
1018
1029
|
catch (e) {
|
|
1019
|
-
return no(`the replay didn't run (${String(e.message).slice(0, 300)})
|
|
1030
|
+
return no(`the replay didn't run (${String(e.message).slice(0, 300)})`, true);
|
|
1020
1031
|
}
|
|
1021
1032
|
finally {
|
|
1022
1033
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
1023
1034
|
}
|
|
1024
|
-
if (out.error)
|
|
1025
|
-
return no(`the code: ${out.error}`);
|
|
1026
1035
|
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(' ');
|
|
1036
|
+
if (out.error)
|
|
1037
|
+
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
1038
|
for (const [g, ok] of (out.oks ?? []).entries())
|
|
1028
1039
|
if (ok.some(x => !x))
|
|
1029
1040
|
return no(`transaction ${g + 1} (${shown(g)}): a call the rule takes reverts in the code`);
|
|
@@ -108,6 +108,7 @@ export type SRec = {
|
|
|
108
108
|
module: string;
|
|
109
109
|
p: string;
|
|
110
110
|
rets?: Record<string, SType>;
|
|
111
|
+
cattrs?: Record<string, number | string | boolean | null>;
|
|
111
112
|
};
|
|
112
113
|
export type SModule = {
|
|
113
114
|
lang: string;
|
|
@@ -164,13 +165,15 @@ type Try = {
|
|
|
164
165
|
ws: B[];
|
|
165
166
|
depth: number;
|
|
166
167
|
};
|
|
167
|
-
export type StoreVal = 'int' | 'float' | string[] | {
|
|
168
|
+
export type StoreVal = 'int' | 'float' | 'str' | string[] | {
|
|
168
169
|
json: Record<string, string | string[]>;
|
|
169
170
|
};
|
|
170
171
|
export type StoreDecl = {
|
|
171
172
|
get?: string[];
|
|
172
173
|
set?: string[];
|
|
173
174
|
delete?: string[];
|
|
175
|
+
add?: string[];
|
|
176
|
+
incr?: string[];
|
|
174
177
|
skip?: string[];
|
|
175
178
|
value?: 'int' | 'float' | 'str';
|
|
176
179
|
attrs?: Record<string, null | boolean | number | string>;
|
|
@@ -192,10 +195,13 @@ export type StepOptions = {
|
|
|
192
195
|
answers?: Record<string, string>;
|
|
193
196
|
skip?: string[];
|
|
194
197
|
stores?: Record<string, StoreDecl>;
|
|
198
|
+
effects?: string[];
|
|
199
|
+
stubs?: string[];
|
|
195
200
|
strict?: boolean;
|
|
196
201
|
failures?: 'refuse' | 'kept';
|
|
197
202
|
onError?: 'refuse' | 'discard';
|
|
198
203
|
domains?: Record<string, 'nat' | 'int'>;
|
|
204
|
+
types?: Record<string, string>;
|
|
199
205
|
keep?: string[];
|
|
200
206
|
defaults?: string[];
|
|
201
207
|
fields?: Record<string, null | boolean | number | string>;
|
|
@@ -329,6 +335,7 @@ type CellWrite = {
|
|
|
329
335
|
key: K;
|
|
330
336
|
has: B;
|
|
331
337
|
vals: Map<string, V>;
|
|
338
|
+
on?: B;
|
|
332
339
|
};
|
|
333
340
|
type Ptr = {
|
|
334
341
|
k: 'nil';
|
|
@@ -412,6 +419,7 @@ type Path = {
|
|
|
412
419
|
locks: string[];
|
|
413
420
|
defers: string[];
|
|
414
421
|
cont?: true;
|
|
422
|
+
eff?: Map<string, B>;
|
|
415
423
|
};
|
|
416
424
|
type Flow = {
|
|
417
425
|
live?: Path;
|
|
@@ -437,6 +445,7 @@ export type Leaf = {
|
|
|
437
445
|
store?: string;
|
|
438
446
|
tpl?: string;
|
|
439
447
|
ordered?: boolean;
|
|
448
|
+
str?: boolean;
|
|
440
449
|
json?: JField[];
|
|
441
450
|
choice?: boolean;
|
|
442
451
|
};
|
|
@@ -492,6 +501,8 @@ export type Answer = {
|
|
|
492
501
|
m: string;
|
|
493
502
|
}[];
|
|
494
503
|
pass?: boolean;
|
|
504
|
+
effect?: boolean;
|
|
505
|
+
quiet?: boolean;
|
|
495
506
|
};
|
|
496
507
|
export type StepRead = {
|
|
497
508
|
ints: Record<string, IntTy>;
|
|
@@ -507,13 +518,22 @@ export type StepRead = {
|
|
|
507
518
|
stores: Record<string, StoreDecl>;
|
|
508
519
|
results: Record<string, 'none' | 'scalar' | 'maybe'>;
|
|
509
520
|
inject?: string[];
|
|
521
|
+
globals?: {
|
|
522
|
+
name: string;
|
|
523
|
+
mod: string;
|
|
524
|
+
}[];
|
|
525
|
+
effectsOf?: Record<string, string[]>;
|
|
526
|
+
inert?: {
|
|
527
|
+
store: string;
|
|
528
|
+
path: string;
|
|
529
|
+
}[];
|
|
510
530
|
};
|
|
511
531
|
export type Inferred = {
|
|
512
532
|
answers: Map<string, SType>;
|
|
513
533
|
cut: Map<string, string>;
|
|
514
534
|
};
|
|
515
535
|
type Tag = {
|
|
516
|
-
k: 'skip' | 'answer' | 'strict';
|
|
536
|
+
k: 'skip' | 'answer' | 'strict' | 'effect';
|
|
517
537
|
arg: string;
|
|
518
538
|
};
|
|
519
539
|
type Bound = {
|
|
@@ -747,6 +767,14 @@ export declare class Stepper {
|
|
|
747
767
|
readonly storeTypes: Map<string, string>;
|
|
748
768
|
readonly storeKeyed: Set<string>;
|
|
749
769
|
readonly injectedFields: string[];
|
|
770
|
+
readonly globalStores: {
|
|
771
|
+
name: string;
|
|
772
|
+
mod: string;
|
|
773
|
+
}[];
|
|
774
|
+
readonly inertAttrs: {
|
|
775
|
+
store: string;
|
|
776
|
+
path: string;
|
|
777
|
+
}[];
|
|
750
778
|
readonly deps: {
|
|
751
779
|
name: string;
|
|
752
780
|
ty?: string;
|
|
@@ -779,6 +807,7 @@ export declare class Stepper {
|
|
|
779
807
|
answer(key: string, names: string[], patch: Patch | undefined, at: SX, p: Path, awaited: boolean, type?: string | SType, how?: string): [V, Path];
|
|
780
808
|
passing(key: string, name: string, patch: Patch | undefined, at: SX, p: Path, awaited: boolean): Path;
|
|
781
809
|
readonly pend: Map<string, Pend>;
|
|
810
|
+
readonly leftOut: Set<string>;
|
|
782
811
|
readonly returnedBy: Map<string, {
|
|
783
812
|
id: string;
|
|
784
813
|
roots: string[];
|
|
@@ -815,7 +844,7 @@ export declare class Stepper {
|
|
|
815
844
|
equal(a: V, b: V, at: SX, p: Path): B;
|
|
816
845
|
truth(x: SX, p: Path): [B, Path];
|
|
817
846
|
boolOp(x: SX, p: Path): [V, Path];
|
|
818
|
-
fstr(x: SX, p: Path): [V, Path];
|
|
847
|
+
fstr(x: SX, p: Path, given?: (string | V)[]): [V, Path];
|
|
819
848
|
call(x: SX, p: Path, awaited: boolean): [V, Path];
|
|
820
849
|
argsRead(x: SX, p: Path): Path;
|
|
821
850
|
evArgs<T>(x: SX, p: Path, k: (args: V[], kw: [string, V][], p: Path) => T): T;
|
|
@@ -968,12 +997,39 @@ export declare const varTerm: (v: Var) => Term;
|
|
|
968
997
|
export declare function iteTerm(c: B, a: Term, b: Term): Term;
|
|
969
998
|
type Raw = number | boolean | string;
|
|
970
999
|
export declare const node: <T>(id: string) => T;
|
|
1000
|
+
export declare function asset(rel: string): string;
|
|
1001
|
+
export declare const harnessLimit: () => number;
|
|
1002
|
+
export declare const compileLimit: () => number;
|
|
1003
|
+
export type Built<T> = {
|
|
1004
|
+
ok: T;
|
|
1005
|
+
} | {
|
|
1006
|
+
kind: 'source' | 'harness';
|
|
1007
|
+
why: string;
|
|
1008
|
+
};
|
|
1009
|
+
export declare function buildCheck<T>(tool: string, run: () => T, errorsOf: (e: unknown) => string[], ofSource: (line: string) => boolean, first?: unknown): Built<T>;
|
|
1010
|
+
export declare const builtEvidence: (b: {
|
|
1011
|
+
kind: "source" | "harness";
|
|
1012
|
+
why: string;
|
|
1013
|
+
}) => {
|
|
1014
|
+
source: string;
|
|
1015
|
+
} | {
|
|
1016
|
+
harness: string;
|
|
1017
|
+
};
|
|
1018
|
+
export declare const stopped: (res: Record<string, unknown>) => Record<string, unknown>;
|
|
1019
|
+
export declare function openHarness(work: string, cmd: string, args: string[], o: Record<string, unknown>): {
|
|
1020
|
+
child: {
|
|
1021
|
+
kill: () => void;
|
|
1022
|
+
};
|
|
1023
|
+
wi: number;
|
|
1024
|
+
ro: number;
|
|
1025
|
+
};
|
|
971
1026
|
export type Harness = {
|
|
972
1027
|
cmd: string;
|
|
973
1028
|
args: string[];
|
|
974
1029
|
env?: Record<string, string>;
|
|
975
1030
|
hello: Record<string, unknown>;
|
|
976
1031
|
error?: string;
|
|
1032
|
+
kind?: 'source' | 'harness';
|
|
977
1033
|
};
|
|
978
1034
|
export type StepEvidence = Evidence & {
|
|
979
1035
|
runMs: number;
|