gdp-wired 0.51.0 → 0.52.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 +2 -2
- package/dist/core/accel-refute.d.ts +53 -0
- package/dist/core/accel-refute.js +997 -0
- package/dist/core/cli.d.ts +2 -0
- package/dist/core/cli.js +8 -1
- package/dist/core/cycles.d.ts +2 -0
- package/dist/core/cycles.js +12 -9
- package/dist/core/dsl.d.ts +7 -1
- package/dist/core/dsl.js +147 -26
- package/dist/core/live-support.d.ts +5 -0
- package/dist/core/live-support.js +148 -0
- package/dist/core/live.js +194 -37
- package/dist/core/lockstep.d.ts +5 -0
- package/dist/core/lockstep.js +23 -0
- package/dist/core/ordered-pair-seeds.d.ts +2 -0
- package/dist/core/ordered-pair-seeds.js +109 -0
- package/dist/core/proof-output.d.ts +38 -1
- package/dist/core/proof-output.js +38 -0
- package/dist/core/search-termination.d.ts +4 -0
- package/dist/core/search-termination.js +1 -1
- package/dist/core/source-check.d.ts +4 -1
- package/dist/core/source-check.js +5 -2
- package/dist/core/sparse-kind-proof.d.ts +7 -0
- package/dist/core/sparse-kind-proof.js +49 -0
- package/dist/core/step-seeds.d.ts +46 -0
- package/dist/core/step-seeds.js +316 -0
- package/dist/lean-kernel/Cert.lean +222 -0
- package/dist/lean-kernel/Count.lean +1568 -0
- package/dist/lean-kernel/Ghost.lean +373 -0
- package/dist/lean-kernel/GhostMap.lean +426 -0
- package/dist/lean-kernel/Kernel.lean +2881 -0
- package/dist/lean-kernel/Live.lean +1168 -0
- package/dist/lean-kernel/Progress.lean +543 -0
- package/dist/lean-kernel/Sets.lean +1975 -0
- package/dist/lean-kernel/StepLaw.lean +128 -0
- package/dist/lean-kernel/Steps.lean +477 -0
- package/dist/lean-kernel/Sums.lean +916 -0
- package/dist/lean-kernel/emit.d.ts +4 -0
- package/dist/lean-kernel/emit.js +23 -4
- package/dist/lean-kernel/lean-aggregate/FiniteFold.lean +44 -0
- package/dist/lean-kernel/lean-aggregate/GroupedTransport.lean +308 -0
- package/dist/lean-kernel/lean-aggregate/aggregate.d.ts +13 -0
- package/dist/lean-kernel/lean-aggregate/aggregate.js +68 -0
- package/dist/lean-kernel/lean-aggregate/assets.d.ts +5 -0
- package/dist/lean-kernel/lean-aggregate/assets.js +7 -0
- package/dist/lean-kernel/lean-aggregate/audit.d.ts +3 -0
- package/dist/lean-kernel/lean-aggregate/audit.js +13 -0
- package/dist/lean-kernel/lean-aggregate/exact.d.ts +15 -0
- package/dist/lean-kernel/lean-aggregate/exact.js +51 -0
- package/dist/lean-kernel/lean-aggregate/index.d.ts +19 -0
- package/dist/lean-kernel/lean-aggregate/index.js +52 -0
- package/dist/lean-kernel/lean-aggregate/point-fold.d.ts +27 -0
- package/dist/lean-kernel/lean-aggregate/point-fold.js +79 -0
- package/dist/lean-kernel/lean-aggregate/replay-fold.d.ts +2 -0
- package/dist/lean-kernel/lean-aggregate/replay-fold.js +163 -0
- package/dist/lean-kernel/lean-aggregate/source.d.ts +2 -0
- package/dist/lean-kernel/lean-aggregate/source.js +141 -0
- package/dist/lean-kernel/lean-aggregate/weighted-flags.d.ts +2 -0
- package/dist/lean-kernel/lean-aggregate/weighted-flags.js +26 -0
- package/dist/lean-kernel/lean-aggregate/weighted-replay.d.ts +7 -0
- package/dist/lean-kernel/lean-aggregate/weighted-replay.js +53 -0
- package/dist/lean-kernel/lean-aggregate/weighted-seeded.d.ts +30 -0
- package/dist/lean-kernel/lean-aggregate/weighted-seeded.js +64 -0
- package/dist/lean-kernel/lean-aggregate/weighted.d.ts +18 -0
- package/dist/lean-kernel/lean-aggregate/weighted.js +115 -0
- package/dist/lean-kernel/lean-aggregate/worker.d.ts +10 -0
- package/dist/lean-kernel/lean-aggregate/worker.js +46 -0
- package/docs/lean-aggregate.md +29 -0
- package/package.json +6 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Derive a filtered weighted-sum proposal from a guarded
|
|
2
|
+
// subtraction and the write cluster it refers to; never assume the proposal.
|
|
3
|
+
import { get, n, same, walkOnce, x } from "../../core/machine.js";
|
|
4
|
+
import { ghostedMachine, ghostedOk, substC, sumMachine } from "../../kernel/kernel.js";
|
|
5
|
+
const text = (u) => JSON.stringify(u);
|
|
6
|
+
const eq = (a, b) => text(a) === text(b);
|
|
7
|
+
const flat = (op, c) => c.op === op ? c.xs.flatMap(t => flat(op, t)) : [c];
|
|
8
|
+
const zero = n(0);
|
|
9
|
+
const sameKey = (t, k) => eq(t, k);
|
|
10
|
+
const at = (t, nm) => t.op === 'var' && t.name === nm;
|
|
11
|
+
const isZero = (t, o) => t.op === 'const' && t.value === (o ?? 0);
|
|
12
|
+
const and = (xs) => ({ op: 'and', xs });
|
|
13
|
+
const ite = (c, then, otherwise) => ({ op: 'if', c, then, else: otherwise });
|
|
14
|
+
const noSub = { vars: {}, maps: {}, flags: {} };
|
|
15
|
+
const termReads = (t) => { const a = []; walkOnce(t, o => { const e = o; if (e.op === 'get')
|
|
16
|
+
a.push(e); }); return a; };
|
|
17
|
+
const points = (m, map) => { const w = m.step.maps?.[map]; return w && !('each' in w) ? w : undefined; };
|
|
18
|
+
const labels = (m, c, matching, negated = false) => {
|
|
19
|
+
const r = [];
|
|
20
|
+
const pattern = (node) => {
|
|
21
|
+
if (node.op !== '=')
|
|
22
|
+
return;
|
|
23
|
+
const t = node.a.op === 'get' ? node.a : node.b.op === 'get' ? node.b : undefined, v = t === node.a ? node.b : node.a;
|
|
24
|
+
if (t && v.op === 'const' && matching(t) && Object.hasOwn(m.maps ?? {}, t.map) && m.maps[t.map] !== v.value)
|
|
25
|
+
r.push([t.map, v.value]);
|
|
26
|
+
};
|
|
27
|
+
if (!negated)
|
|
28
|
+
walkOnce(c, o => pattern(o));
|
|
29
|
+
else
|
|
30
|
+
walkOnce(c, o => { const q = o; if (q.op === 'not')
|
|
31
|
+
pattern(q.x); });
|
|
32
|
+
return r;
|
|
33
|
+
};
|
|
34
|
+
export function weightedCandidates(m, law) {
|
|
35
|
+
if (!law.forall || law.keys?.length || law.some?.length || m.history || m.sums || m.counts || m.inputMaps?.length)
|
|
36
|
+
return [];
|
|
37
|
+
const key = law.forall, ws = m.step.maps ?? {}, names = text([m, law]);
|
|
38
|
+
let prefix = 'weight$';
|
|
39
|
+
while (names.includes(prefix))
|
|
40
|
+
prefix += 'a';
|
|
41
|
+
const obs = `${prefix}observer`, binder = `${prefix}item`, wm = `${prefix}map`, sum = `${prefix}sum`, selected = x(obs);
|
|
42
|
+
const o = { ...m, params: [...m.params, obs] }, res = [];
|
|
43
|
+
const ownFlags = Object.fromEntries(Object.keys(m.step.flags ?? {}).map(name => [name, { op: 'flag', name }]));
|
|
44
|
+
for (const aMap of new Set(termReads(law.holds).filter(r => at(r.key, key)).map(r => r.map))) {
|
|
45
|
+
const wr = ws[aMap], u = wr && 'each' in wr && wr.value;
|
|
46
|
+
if (!u || u.op !== 'if' || !isZero(u.then))
|
|
47
|
+
continue;
|
|
48
|
+
const ix = wr.each, delta = u.else;
|
|
49
|
+
if (delta.op !== 'if' || !eq(delta.else, get(aMap, x(ix))) || delta.then.op !== 'sub')
|
|
50
|
+
continue;
|
|
51
|
+
const sub = delta.then;
|
|
52
|
+
if (sub.a.op !== 'add' || !eq(sub.a.a, get(aMap, x(ix))) || sub.b.op !== 'if' || !isZero(sub.b.else) || sub.b.then.op !== 'get')
|
|
53
|
+
continue;
|
|
54
|
+
const { map: weight, key: point } = sub.b.then, ww = points(m, weight);
|
|
55
|
+
if (!ww || !m.maps || m.maps[aMap] !== 0)
|
|
56
|
+
continue;
|
|
57
|
+
// Structural role match: the accumulator's addressed guard equates its
|
|
58
|
+
// own key to a foreign-key field of the same row as the removed weight.
|
|
59
|
+
const groups = new Set();
|
|
60
|
+
walkOnce(delta.c, node => {
|
|
61
|
+
const c = node;
|
|
62
|
+
if (c.op !== '=')
|
|
63
|
+
return;
|
|
64
|
+
for (const [k, t] of [[c.a, c.b], [c.b, c.a]]) {
|
|
65
|
+
if (at(k, ix) && t.op === 'get' && sameKey(t.key, point) && eq(points(m, t.map)?.key, ww.key))
|
|
66
|
+
groups.add(t.map);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
if (groups.size !== 1)
|
|
70
|
+
continue;
|
|
71
|
+
const [group] = groups;
|
|
72
|
+
const aliases = point.op === 'if' ? [point.then, point.else] : [point];
|
|
73
|
+
const guards = flat('or', sub.b.c).flatMap(c => c.op === 'flag' && m.step.flags?.[c.name] ? [m.step.flags[c.name]] : []);
|
|
74
|
+
if (!guards.length)
|
|
75
|
+
continue;
|
|
76
|
+
const byGuard = guards.map(c => labels(m, c, r => aliases.some(k => eq(k, r.key)) && !!points(m, r.map)));
|
|
77
|
+
const gates = [...new Map(byGuard[0].filter(a => byGuard.every(xs => xs.some(b => eq(a, b)))).map(t => [text(t), t])).values()];
|
|
78
|
+
if (!gates.length || gates.length > 3 || !gates.some(([name]) => eq(points(m, name)?.key, point)))
|
|
79
|
+
continue;
|
|
80
|
+
const initGuards = flat('and', u.c), creating = initGuards.find(c => c.op === 'flag');
|
|
81
|
+
const aRef = initGuards.find(c => c.op === '=' && at(c.a, ix));
|
|
82
|
+
const absent = creating?.op === 'flag' && aRef?.op === '=' && m.step.flags?.[creating.name] ?
|
|
83
|
+
labels(m, m.step.flags[creating.name], r => eq(r.key, aRef.b) && !!ws[r.map] && 'each' in ws[r.map], true) : [];
|
|
84
|
+
const absence = absent.length === 1 ? absent[0] : undefined;
|
|
85
|
+
const contribution = (read) => ite(and([...gates.map(([g, v]) => same(read(g), n(v))), same(read(group), selected)]), read(weight), zero);
|
|
86
|
+
const added = sub.a.b;
|
|
87
|
+
if (added.op !== 'if' || !isZero(added.else))
|
|
88
|
+
continue;
|
|
89
|
+
const groupSelected = substC(delta.c, { ...noSub, flags: ownFlags, vars: { [ix]: selected } });
|
|
90
|
+
// The delta must still agree with the complete post-row shape at every key.
|
|
91
|
+
const value = ite(and([groupSelected, sub.b.c]), zero, ite(and([groupSelected, added.c]), added.then, get(wm, point)));
|
|
92
|
+
const ghost = { orig: o, vars: {}, maps: { [wm]: { start: 0, write: { key: point, value } } } };
|
|
93
|
+
if (!ghostedOk(ghost))
|
|
94
|
+
continue;
|
|
95
|
+
const instrumented = ghostedMachine(ghost);
|
|
96
|
+
const machine = { ...instrumented, state: { ...instrumented.state, [sum]: zero }, sums: { [sum]: { term: get(wm, x(`${prefix}index`)), key: `${prefix}index` } } };
|
|
97
|
+
try {
|
|
98
|
+
sumMachine(machine);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const laws = [
|
|
104
|
+
...(absence ? [{ name: `${prefix}absent storage is zero`, holds: { op: 'or', xs: [same(get(absence[0], selected), n(absence[1])), same(get(aMap, selected), zero)] } }] : []),
|
|
105
|
+
{ name: `${prefix}point contribution`, forall: binder, holds: same(get(wm, x(binder)), contribution(name => get(name, x(binder)))) },
|
|
106
|
+
{ name: `${prefix}accumulator equals weighted live sum`, holds: same(get(aMap, selected), x(sum)) },
|
|
107
|
+
{ name: law.name, holds: substC(law.holds, { ...noSub, vars: { [key]: selected } }) },
|
|
108
|
+
];
|
|
109
|
+
const eventNames = new Set();
|
|
110
|
+
walkOnce([u.c, sub.a.b, sub.b], node => { const c = node; if (c.op === 'flag')
|
|
111
|
+
eventNames.add(c.name); });
|
|
112
|
+
res.push({ ghost, machine, laws, observer: obs, links: { balance: aMap, weight, group: group, gates, absence, point, events: [...eventNames] } });
|
|
113
|
+
}
|
|
114
|
+
return res;
|
|
115
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// This worker is used only by the opt-in API. A fresh worker-local kernel
|
|
2
|
+
// term table and emitter memo keep aggregate search separate from native calls.
|
|
3
|
+
import { parentPort, workerData } from 'node:worker_threads';
|
|
4
|
+
import { searchWall } from "../../core/wall.js";
|
|
5
|
+
import { withWall } from "../../kernel/prove.js";
|
|
6
|
+
import { foldTheory, provePointFold } from "./point-fold.js";
|
|
7
|
+
import { emitPointFold } from "./replay-fold.js";
|
|
8
|
+
import { emitWeighted } from "./weighted-replay.js";
|
|
9
|
+
import { weightedCandidates } from "./weighted.js";
|
|
10
|
+
import { closeWeightedFlags } from "./weighted-flags.js";
|
|
11
|
+
import { proveWeightedSeeded } from "./weighted-seeded.js";
|
|
12
|
+
function propose(machine, law, ms) {
|
|
13
|
+
if (foldTheory(machine, law)) {
|
|
14
|
+
const packet = provePointFold(machine, law, Math.min(4000, ms));
|
|
15
|
+
if (packet)
|
|
16
|
+
return { kind: 'candidate', mechanism: 'finite-fold', source: emitPointFold(packet) };
|
|
17
|
+
}
|
|
18
|
+
else if (law.forall) {
|
|
19
|
+
const candidates = weightedCandidates(machine, law).flatMap(p => closeWeightedFlags(p) ?? []);
|
|
20
|
+
if (candidates.length) {
|
|
21
|
+
const result = withWall(searchWall(Math.min(ms, 59_000)), () => {
|
|
22
|
+
for (const candidate of candidates) {
|
|
23
|
+
const v = proveWeightedSeeded(candidate, Math.min(ms, 58_000), () => { });
|
|
24
|
+
if (v.proven && v.checked && v.proof)
|
|
25
|
+
return emitWeighted(candidate, machine, law, v.proof);
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
});
|
|
29
|
+
if (result)
|
|
30
|
+
return { kind: 'candidate', mechanism: 'weighted', source: result };
|
|
31
|
+
return { kind: 'refused', reason: 'search', detail: 'Weighted equality did not close.' };
|
|
32
|
+
}
|
|
33
|
+
return { kind: 'refused', reason: 'unsupported', detail: 'No weighted update shape recognized.' };
|
|
34
|
+
}
|
|
35
|
+
else
|
|
36
|
+
return { kind: 'refused', reason: 'unsupported', detail: 'No finite-fold update shape recognized.' };
|
|
37
|
+
return { kind: 'refused', reason: 'search', detail: 'Finite-fold local goals did not close.' };
|
|
38
|
+
}
|
|
39
|
+
const { source, ms } = workerData;
|
|
40
|
+
try {
|
|
41
|
+
const [machine, law] = JSON.parse(source);
|
|
42
|
+
parentPort.postMessage(propose(machine, law, ms));
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
parentPort.postMessage({ kind: 'refused', reason: 'search', detail: String(e) });
|
|
46
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Opt-in aggregate proofs in Lean
|
|
2
|
+
|
|
3
|
+
`gdp-wired/lean-aggregate` is a separate, experimental entry for aggregate invariants. It is off by default. Neither `proveRule`, the standard CLI, nor the default corpus scores use it. There is no new gdp-wired kernel rule for aggregate closure in this release.
|
|
4
|
+
|
|
5
|
+
Install the official Lean **4.34.0** toolchain and put `lean` on `PATH` (with elan: `elan toolchain install leanprover/lean4:v4.34.0`). No Lake project or separate proof library is needed: the npm package ships the Lean sources used by this entry. Use this API from Node:
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import {proveLeanAggregate} from 'gdp-wired/lean-aggregate'
|
|
9
|
+
|
|
10
|
+
const result = await proveLeanAggregate(rule.machine, invariant)
|
|
11
|
+
if (result.kind === 'lean-checked') {
|
|
12
|
+
console.log(result.verdict) // checked in Lean, not by the kernel
|
|
13
|
+
console.log(result.receipt.inputSha256, result.receipt.sourceSha256)
|
|
14
|
+
} else {
|
|
15
|
+
console.log(result.reason, result.detail) // not checked; not a refutation
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Pass one invariant over reachable states, not a step or a liveness law. The adapter checks **unmarked symbolic models only**: it refuses source-bound machines or laws even if native translation evidence is available. Pass plain records and dense arrays of own enumerable data (ordinary DSL output or parsed JSON); omit absent optional fields instead of writing `undefined`. Proxies, accessors, serialization hooks (including inherited `toJSON`), custom prototypes, and extra fields outside the supported AST are refused. The adapter snapshots the data without calling hooks and applies the ordinary kernel scope check to that exact source before looking for either proof shape:
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
- **Finite fold:** counters over disjoint classes in a bounded table, maintained by a point update and a broadcast reset. The gdp-wired kernel checks local sequents. Lean checks those trees and composes them into the full original invariant.
|
|
23
|
+
- **Weighted sum:** an account-like accumulator updated by adding or removing weights associated with a key. The adapter proposes an instrumented row, an exact weighted equality, and the supporting invariants. Lean transports the checked instrumented family to the caller's original machine and original universally quantified invariant.
|
|
24
|
+
|
|
25
|
+
This route is intended for both etcd Raft tally invariants and TigerBeetle transfer limit invariants #0 and #1 in the repository corpus. The claims are about the corpus models, not equivalence with the upstream implementations. No special case in the prover matches those names or law indices. Other shapes, including custom functions, finite binders, and existing count/sum instrumentation, can be refused.
|
|
26
|
+
|
|
27
|
+
Success is **checked in Lean, not by the kernel**. There is no `checked: true` (or `proven` boolean) to mix with a native verdict. The receipt identifies the exact input (SHA-256 of the UTF-8 JSON snapshot of `[machine, law]`), the emitted `.lean` source and its digest, each used library's digest, the Lean version, and the axiom report for `aggregate_claim`. The adapter builds the packaged libraries in a fresh directory, runs Lean on the emitted theorem, and permits only `propext`, `Classical.choice`, and `Quot.sound`. It refuses incomplete reports, unexpected axioms, wrong toolchains, failures and timeouts. The receipt records local execution, not a signed attestation: trust the installed package and the local Lean executable as you would when running Lean yourself.
|
|
28
|
+
|
|
29
|
+
Imports do not start Lean or search. Calling the function starts an isolated search worker; only a retained candidate starts Lean. `{searchMs, leanMs}` sets separate deadlines (defaults: 60 s for search, with a small worker/serialization allowance; 180 s for compiling and checking in Lean). A refusal does not change the ordinary prover's result.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gdp-wired",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.52.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",
|
|
@@ -48,6 +48,10 @@
|
|
|
48
48
|
"types": "./dist/lean-kernel/emit.d.ts",
|
|
49
49
|
"default": "./dist/lean-kernel/emit.js"
|
|
50
50
|
},
|
|
51
|
+
"./lean-aggregate": {
|
|
52
|
+
"types": "./dist/lean-kernel/lean-aggregate/index.d.ts",
|
|
53
|
+
"default": "./dist/lean-kernel/lean-aggregate/index.js"
|
|
54
|
+
},
|
|
51
55
|
"./lift": {
|
|
52
56
|
"types": "./dist/lean-kernel/lift.d.ts",
|
|
53
57
|
"default": "./dist/lean-kernel/lift.js"
|
|
@@ -188,6 +192,7 @@
|
|
|
188
192
|
"README.md",
|
|
189
193
|
"LICENSE",
|
|
190
194
|
"docs/agent-consult.md",
|
|
195
|
+
"docs/lean-aggregate.md",
|
|
191
196
|
"docs/agent-consult-workspace-check.md",
|
|
192
197
|
"examples/agent-consult.json"
|
|
193
198
|
],
|