gdp-wired 0.40.0 → 0.41.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/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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gdp-wired",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
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",
|