gdp-wired 0.40.0 → 0.41.1
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/counts.js +38 -3
- package/dist/core/extract-sol.js +1 -1
- package/dist/core/extract-step.d.ts +2 -0
- package/dist/core/extract-step.js +19 -1
- package/dist/kernel/kernel.js +24 -5
- package/package.json +1 -1
package/dist/core/counts.js
CHANGED
|
@@ -17,7 +17,7 @@ finally {
|
|
|
17
17
|
let dumped = 0;
|
|
18
18
|
const v = (name) => ({ op: 'var', name }), k = (value) => ({ op: 'const', value });
|
|
19
19
|
const json = (t) => JSON.stringify(t);
|
|
20
|
-
const knob = { pairs: env.GDP_K_PAIRS === '1', rounds: Number(env.GDP_K_ROUNDS ?? 0), cap: Number(env.GDP_K_CAP ?? 24), ts: env.GDP_K_TS === '1', keyed: env.GDP_K_KEYED !== '0', flagTs: env.GDP_K_FLAGTS !== '0', shrink: Number(env.GDP_K_SHRINK ?? 150), walks: Number(env.GDP_K_WALKS ?? 100_000), alone: Number(env.GDP_K_ALONE ?? 300), hops: Number(env.GDP_K_HOPS ?? 16), first: env.GDP_K_FIRST !== '0', decide: Number(env.GDP_K_DECIDE ?? 0), mbqi: Number(env.GDP_K_MBQI ?? 12), once: env.GDP_K_ONCE !== '0', reads: Number(env.GDP_K_READS ?? 6), memo: env.GDP_K_MEMO !== '0', part: env.GDP_K_PART !== '0' };
|
|
20
|
+
const knob = { pairs: env.GDP_K_PAIRS === '1', rounds: Number(env.GDP_K_ROUNDS ?? 0), cap: Number(env.GDP_K_CAP ?? 24), ts: env.GDP_K_TS === '1', keyed: env.GDP_K_KEYED !== '0', flagTs: env.GDP_K_FLAGTS !== '0', shrink: Number(env.GDP_K_SHRINK ?? 150), walks: Number(env.GDP_K_WALKS ?? 100_000), alone: Number(env.GDP_K_ALONE ?? 300), hops: Number(env.GDP_K_HOPS ?? 16), first: env.GDP_K_FIRST !== '0', decide: Number(env.GDP_K_DECIDE ?? 0), mbqi: Number(env.GDP_K_MBQI ?? 12), once: env.GDP_K_ONCE !== '0', reads: Number(env.GDP_K_READS ?? 6), memo: env.GDP_K_MEMO !== '0', part: env.GDP_K_PART !== '0', rows: env.GDP_K_ROWS !== '0', widen: env.GDP_K_WIDEN !== '0' };
|
|
21
21
|
const one = k(1), zero = k(0);
|
|
22
22
|
// Every term t with `get(map, t)` in t0.
|
|
23
23
|
function reads(t0, map, out = new Map()) {
|
|
@@ -241,17 +241,52 @@ function searchCounted0(m0, caller, ms = 60_000) {
|
|
|
241
241
|
const most = Math.max(0, ...states.flatMap(({ sts }) => sts.flatMap(st => [...(st.maps[mp]?.values() ?? [])])));
|
|
242
242
|
return { name: `${mp} at most ${most}`, forall: 'a$c', holds: { op: '<=', a: { op: 'get', map: mp, key: v('a$c') }, b: k(most) } };
|
|
243
243
|
});
|
|
244
|
+
// (a relation written at a composed key N·a + b under a quantified flag that its row a (or column b) holds no cell:
|
|
245
|
+
// at most one b a row (one a a column), K2's support the engine's cubes of two keys can't state, three keys read:
|
|
246
|
+
// one decision a node where a decision needs the node undecided; a map a caller reads)
|
|
247
|
+
const rowLaws = Object.entries(m.step.maps ?? {}).flatMap(([mp, w]) => {
|
|
248
|
+
const key = 'each' in w ? undefined : w.key;
|
|
249
|
+
if (key?.op !== 'add' || key.a.op !== 'mul' || key.a.a.op !== 'var' || key.b.op !== 'var' || !caller.some(l => reads(l.holds, x => x === mp).size))
|
|
250
|
+
return [];
|
|
251
|
+
const n = key.a.k, row = key.a.a, col0 = key.b, cellAt = (p, q) => ({ op: 'get', map: mp, key: { op: 'add', a: { op: 'mul', k: n, a: p }, b: q } });
|
|
252
|
+
const empty = (col) => Object.values(m.step.flags ?? {}).some(q => q.op === 'all' && !q.keys?.length && json(q.c).includes(json(col ? cellAt(v(q.key), col0) : cellAt(row, v(q.key)))));
|
|
253
|
+
return [false, true].filter(empty).map((col) => {
|
|
254
|
+
const [a, x, y] = [v('a$c'), v('x$c'), v('y$c')], cell = (z) => ({ op: '<=', a: one, b: col ? cellAt(z, a) : cellAt(a, z) });
|
|
255
|
+
return { name: `${mp}: one ${col ? 'first key a second' : 'second key a first'}`, forall: 'a$c', keys: ['x$c', 'y$c'],
|
|
256
|
+
holds: { op: 'or', xs: [{ op: 'not', x: { op: 'and', xs: [...[a, x, y].map((z) => ({ op: '<', a: z, b: k(n) })), cell(x), cell(y)] } }, { op: '=', a: x, b: y }] } };
|
|
257
|
+
});
|
|
258
|
+
});
|
|
244
259
|
const trueAll = (l) => clock() < until && states.every(({ p, sts }) => sts.every(st => holdsAt(m, l, p, st, 4)));
|
|
245
260
|
if (!caller.every(trueAll))
|
|
246
261
|
return { proven: false, laws: caller, m, why: clock() < until ? 'a law fails on the small instances' : 'time' };
|
|
247
262
|
// (the engine's minimal ∀ cubes on its own small instances and data filter, core/infer.ts's: the supports no guard reads)
|
|
248
263
|
const t1 = clock(), rows = states.flatMap(({ p, sts }) => sts.map(st => ({ params: p, st })));
|
|
249
|
-
const
|
|
264
|
+
const cubes0 = ptime('cubes', () => inferLaws(m0, caller, [], { cubes: 2, ms: Math.min(15_000, ms / 4), first: { proven: false, checked: false }, rows }).found.map(f => f.law));
|
|
265
|
+
// (a cube's guard `u < param` dropped where u sits at a map's place that a caller reads with no param bound, the
|
|
266
|
+
// decided value below N and not below size, if the small instances still hold it: the engine's template reads every
|
|
267
|
+
// key of a composed map as one sort)
|
|
268
|
+
const placesOf = (key) => (key.op === 'var' ? [key.name] : key.op === 'add' && key.a.op === 'mul' && key.a.a.op === 'var' && key.b.op === 'var' ? [key.a.a.name, key.b.name] : undefined);
|
|
269
|
+
const conjs = (c) => (c.op === 'and' ? c.xs.flatMap(conjs) : [c]);
|
|
270
|
+
const guardsOf = (l) => (l.holds.op === 'or' ? l.holds.xs.flatMap(d => (d.op === 'not' ? conjs(d.x) : [])) : []);
|
|
271
|
+
const bounded = (gs, u) => gs.some(c => c.op === '<' && c.a.op === 'var' && c.a.name === u && c.b.op === 'var' && m.params.includes(c.b.name));
|
|
272
|
+
const loose = new Set(caller.filter(l => guardsOf(l).length).flatMap(l => [...reads(l.holds, mp => mp in (m.maps ?? {})).values()].flatMap(([mp, key]) => (placesOf(key) ?? []).flatMap((u, i) => (bounded(guardsOf(l), u) ? [] : [`${mp}:${i}`])))));
|
|
273
|
+
const loosened = (c) => {
|
|
274
|
+
const drop = new Set([...reads(c.holds, () => true).values()].flatMap(([mp, key]) => (placesOf(key) ?? []).filter((u, i) => loose.has(`${mp}:${i}`))));
|
|
275
|
+
const keep = (x) => !(x.op === '<' && x.a.op === 'var' && drop.has(x.a.name) && x.b.op === 'var' && m.params.includes(x.b.name));
|
|
276
|
+
if (!drop.size || c.holds.op !== 'or' || !guardsOf(c).some(x => !keep(x)))
|
|
277
|
+
return c;
|
|
278
|
+
// (the engine names the law's keys x, y, z in order)
|
|
279
|
+
const shown = [c.forall, ...(c.keys ?? [])].flatMap((u, i) => (u && drop.has(u) ? ['xyzw'[i] ?? u] : []));
|
|
280
|
+
const name = shown.reduce((t, x) => t.replace(new RegExp(`\\b${x} < (${m.params.join('|')}) ∧ `, 'g'), ''), c.name);
|
|
281
|
+
const w = { ...c, name: name === c.name ? `${c.name} (any ${shown.join(', ')})` : name, holds: { op: 'or', xs: c.holds.xs.map(d => (d.op === 'not' ? { op: 'not', x: { op: 'and', xs: conjs(d.x).filter(keep) } } : d)) } };
|
|
282
|
+
return trueAll(w) ? w : c;
|
|
283
|
+
};
|
|
284
|
+
const cubes = knob.widen ? cubes0.map(loosened) : cubes0;
|
|
250
285
|
if (env.GDP_COUNTS_TRACE)
|
|
251
286
|
console.error(`counts: small ${states.map(({ sts }) => sts.length).join('/')}; declared ${Object.keys(g.counts ?? {}).join(', ')}`);
|
|
252
287
|
if (env.GDP_COUNTS_TRACE)
|
|
253
288
|
console.error(`counts: cubes ${cubes.length} in ${Math.round(clock() - t1)} ms: ${cubes.map(l => l.name).join('; ')}`);
|
|
254
|
-
let set = [...caller, ...ptime('filter', () => [...kinds, ...g.laws, ...cubes].filter(trueAll))];
|
|
289
|
+
let set = [...caller, ...ptime('filter', () => [...kinds, ...g.laws, ...(knob.rows ? rowLaws : []), ...cubes].filter(trueAll))];
|
|
255
290
|
if (env.GDP_COUNTS_TRACE)
|
|
256
291
|
console.error(`counts: candidates at ${Math.round(clock() - t1)} ms: ${set.map(l => l.name).join('; ')}`);
|
|
257
292
|
// (the law's own names and the request's values that key a map: an action's value keys none)
|
package/dist/core/extract-sol.js
CHANGED
|
@@ -823,7 +823,7 @@ export function extractSolidity(at, opts = {}) {
|
|
|
823
823
|
// (the check's probes: the branches' conditions, each a state and request the prover finds; a revert's condition
|
|
824
824
|
// holds at no step the rule takes, and a contract's rule is large)
|
|
825
825
|
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
|
-
const o = { ...opts, methods, strict: true, onError: 'discard', entry: meta.contract, check: { probes: 'writes', ...opts.check }, answers: { ...havoc, ...opts.answers } };
|
|
826
|
+
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
827
|
// extractStep's run, the width's param fixed for the check's own draws (2^52: the proof is for every width)
|
|
828
828
|
const notes = [];
|
|
829
829
|
let read;
|
|
@@ -195,6 +195,7 @@ export type StepOptions = {
|
|
|
195
195
|
domains?: Record<string, 'nat' | 'int'>;
|
|
196
196
|
defaults?: string[];
|
|
197
197
|
fields?: Record<string, null | boolean | number | string>;
|
|
198
|
+
share?: boolean;
|
|
198
199
|
check?: {
|
|
199
200
|
runs?: number;
|
|
200
201
|
depth?: number;
|
|
@@ -586,6 +587,7 @@ export declare class Stepper {
|
|
|
586
587
|
intTy(t: SType): IntTy | undefined;
|
|
587
588
|
typed(v: Var, t: SType | IntTy, role: Var['role'], sel?: I.B): void;
|
|
588
589
|
sel: B;
|
|
590
|
+
shared: Map<string, [V, PArg]>;
|
|
589
591
|
clock(at: {
|
|
590
592
|
p: string;
|
|
591
593
|
}, p: Path): [V, Path];
|
|
@@ -240,6 +240,8 @@ export class Stepper {
|
|
|
240
240
|
this.refusals.push(I.and(sel, I.cmp('<', x, I.num(0))));
|
|
241
241
|
}
|
|
242
242
|
sel = I.T;
|
|
243
|
+
// (StepOptions.share: each shared input by its type and place, made at its first method)
|
|
244
|
+
shared = new Map();
|
|
243
245
|
// The clock: one input a step.
|
|
244
246
|
clock(at, p) {
|
|
245
247
|
// (read again in the step: the same time, as the check's clock gives it; the step taken to run within one tick)
|
|
@@ -4766,8 +4768,24 @@ function readOnce(mod, opts, g) {
|
|
|
4766
4768
|
refuse(fn, `${fn.name}: a method that takes self by value (it consumes the object)`);
|
|
4767
4769
|
if (fn.generic)
|
|
4768
4770
|
refuse(fn, `${fn.name}: a generic method`);
|
|
4771
|
+
const kth = new Map();
|
|
4769
4772
|
for (const pa of fn.params.filter(x => !x.self && !x.star)) {
|
|
4770
|
-
const
|
|
4773
|
+
const s = opts.share && names.length > 1 ? g.scalar(pa.t) : undefined, ty = JSON.stringify(pa.t), k = kth.get(ty) ?? 0;
|
|
4774
|
+
kth.set(ty, k + 1);
|
|
4775
|
+
// (shared: named by the argument where every method names its k-th of the type alike, else by the type and k)
|
|
4776
|
+
const at = s && chosen.map(f => f.params.filter(x => !x.self && !x.star && JSON.stringify(x.t) === ty)[k]?.name).filter(Boolean);
|
|
4777
|
+
const it = pa.t;
|
|
4778
|
+
const nm = at ? (at.every(x => x === pa.name) ? pa.name : `${it.k === 'int' ? `${it.signed ? '' : 'u'}int${it.bits || ''}` : it.k}_${k}`) : `${names.length > 1 ? `${fn.name}_` : ''}${pa.name}`;
|
|
4779
|
+
const had = at ? g.shared.get(`${ty} ${k}`) : undefined;
|
|
4780
|
+
if (had && had[1].k === 'in') {
|
|
4781
|
+
g.typed(g.vars.get(had[1].name), pa.t, 'input');
|
|
4782
|
+
args.push(had[0]);
|
|
4783
|
+
pargs.push([pa.name, had[1]]);
|
|
4784
|
+
continue;
|
|
4785
|
+
}
|
|
4786
|
+
const [v, a] = g.input(nm, pa.t, fn, p);
|
|
4787
|
+
if (at)
|
|
4788
|
+
g.shared.set(`${ty} ${k}`, [v, a]);
|
|
4771
4789
|
args.push(v);
|
|
4772
4790
|
pargs.push([pa.name, a]);
|
|
4773
4791
|
}
|
package/dist/kernel/kernel.js
CHANGED
|
@@ -792,8 +792,14 @@ function inScope(what, ts, vars, maps = [], flags = []) {
|
|
|
792
792
|
// A name the kernel's linear forms would read as something else: '1' is the constant, and '*', '[', ']', ',' and ':'
|
|
793
793
|
// build monomials and cells; '#' marks the fresh name a law is proven at (k#, its key's), which a name of the machine or
|
|
794
794
|
// another key of the law would capture. Such a name could never be proven about; refused instead, with its name.
|
|
795
|
-
|
|
796
|
-
|
|
795
|
+
// The names the kernel makes are kept apart the same way: '?' a flag's variable ?f and its witnesses w?f, w2?f; '~' a
|
|
796
|
+
// state named after a step (s~1); ''' the state and maps after the step (s', M'); '⟦' and '⟧' a term's column (⟦n⟧).
|
|
797
|
+
// ('@', a later step's a@2, ?f@2, I@2, is not reserved: compose's steps names its inputs x@s1; stepLawObligations
|
|
798
|
+
// keeps a later step's names apart from every name of the machine instead.) A name of the machine, a law's or step
|
|
799
|
+
// law's key with one of them would be read as the kernel's own (a param ?f as the flag f's 0/1 variable: "s <= ?f" was
|
|
800
|
+
// accepted, false at ?f = 0; Lean refuses it).
|
|
801
|
+
const plainName = (what, name) => { if (name === '1' || /[*[\],:#?~'⟦⟧]/.test(name))
|
|
802
|
+
throw new Error(`${what}: the name ${name} is reserved (1, or * [ ] , : # ? ~ ' ⟦ ⟧)`); };
|
|
797
803
|
const distinct = (what, names) => { const seen = new Set(); for (const name of names) {
|
|
798
804
|
if (seen.has(name))
|
|
799
805
|
throw new Error(`${what} declares ${name} twice`);
|
|
@@ -1532,6 +1538,7 @@ export function checkRecurCases(l, r) {
|
|
|
1532
1538
|
// hold of every request where the sums are exact: Sums.lean's sum_allowed).
|
|
1533
1539
|
export function progressObligations(m0, laws, instances, p) {
|
|
1534
1540
|
const m = plainOf(m0), own = m0.sums && Object.keys(m0.sums).length ? m0.assume : m.assume;
|
|
1541
|
+
scope(m, laws); // (as obligations scopes it: a param ?f would be read as the flag f's variable here too)
|
|
1535
1542
|
if (!m.inputs.every(i => i in p.request) || !Object.values(p.request).every(natural) || mentions(p.when, m.inputs))
|
|
1536
1543
|
throw new Error('outside the kernel');
|
|
1537
1544
|
for (const e of Object.values(p.request))
|
|
@@ -1621,11 +1628,17 @@ export function stepLawObligations(machine, laws, instances, sl) {
|
|
|
1621
1628
|
const later = laters.flatMap(l => Object.values(l.vars).map(e => e.name)), laterMaps = laters.flatMap(l => Object.values(l.maps));
|
|
1622
1629
|
const names = Array.from({ length: k - 1 }, (_, i) => state.map(n => stateName(n, i + 1))).flat();
|
|
1623
1630
|
const taken = [...m.params, ...m.inputs, ...state, ...maps, ...carried];
|
|
1631
|
+
// (and every name the run reads besides: the functions, each flag's variable ?f and its witnesses, which a later
|
|
1632
|
+
// step's names, a@2, I@2, ?f@2, must not be: a function I@2 was read as the second request's carried map)
|
|
1633
|
+
const own = [...taken, ...Object.keys(m.fns ?? {}), ...flagNames.map(f => `?${f}`), ...quantified(m).flatMap(([f, q]) => witnessesOf(f, q))];
|
|
1624
1634
|
for (const p of [...primes, ...later, ...laterMaps, ...names])
|
|
1625
|
-
if (
|
|
1635
|
+
if (own.includes(p))
|
|
1626
1636
|
throw new Error(`${m.name}: ${p} is a name of the machine and a name a step law reads`);
|
|
1627
1637
|
for (const key of [sl.forall, ...(sl.keys ?? [])])
|
|
1628
|
-
if (key
|
|
1638
|
+
if (key)
|
|
1639
|
+
plainName(`step law ${sl.name}'s key`, key);
|
|
1640
|
+
for (const key of [sl.forall, ...(sl.keys ?? [])])
|
|
1641
|
+
if (key && [...own, ...primes, ...later, ...names].includes(key))
|
|
1629
1642
|
throw new Error(`step law ${sl.name}'s key ${key} is already a name of ${m.name}`);
|
|
1630
1643
|
if (sl.keys?.length && (!sl.forall || new Set([sl.forall, ...sl.keys]).size !== sl.keys.length + 1))
|
|
1631
1644
|
throw new Error(`step law ${sl.name}: further keys come with a first, each a different name`);
|
|
@@ -1706,6 +1719,12 @@ export function foldObligations(f, laws) {
|
|
|
1706
1719
|
throw new Error('outside the kernel');
|
|
1707
1720
|
const names = Object.keys(f.leaf);
|
|
1708
1721
|
distinct(f.name, [...f.params, ...f.inputs, ...names]);
|
|
1722
|
+
// The children's copies (l_n, r_n) are names of their own (Lean's copiesOk): a param l_size would be read as the left
|
|
1723
|
+
// child's size at a node.
|
|
1724
|
+
const copies = names.flatMap(n => [`l_${n}`, `r_${n}`]);
|
|
1725
|
+
for (const name of [...f.params, ...f.inputs, ...names])
|
|
1726
|
+
if (copies.includes(name))
|
|
1727
|
+
throw new Error(`${f.name}: ${name} is a name of the fold and a child's copy (l_<name>, r_<name>)`);
|
|
1709
1728
|
if (Object.keys(f.node).sort().join() !== [...names].sort().join())
|
|
1710
1729
|
throw new Error(`${f.name}'s leaf and node set the same names`);
|
|
1711
1730
|
inScope(`${f.name}'s leaf`, [...Object.values(f.leaf), ...(f.assume ? [f.assume] : [])], [...f.params, ...f.inputs]);
|
|
@@ -1776,7 +1795,7 @@ export function qdec(path, r) {
|
|
|
1776
1795
|
}
|
|
1777
1796
|
export function qlinear(e, path) {
|
|
1778
1797
|
switch (e.op) {
|
|
1779
|
-
case 'var': return e.name === '1' ? undefined : { row: { cs: new Map([[e.name, 1n]]), c: 0n }, den: 1n };
|
|
1798
|
+
case 'var': return e.name === '1' || /[*[\],:⟦]/.test(e.name) ? undefined : { row: { cs: new Map([[e.name, 1n]]), c: 0n }, den: 1n }; // (a row's key is its canonical text: a variable x:1,y read as x + y's)
|
|
1780
1799
|
case 'const': {
|
|
1781
1800
|
const q = ratNorm(e.q);
|
|
1782
1801
|
return { row: { cs: new Map(), c: q.num }, den: q.den };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gdp-wired",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.1",
|
|
4
4
|
"description": "An automatic prover for stateful rules (budgets, caps, windows, workflows, policies): laws proven with no proof to write, checked again in Lean, counterexamples found on the GPU, the rule shipped as code",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"verification",
|