gdp-wired 0.55.1 → 0.56.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/README.md +48 -0
- package/dist/core/agent-consult/cli.js +11 -0
- package/dist/core/agent-consult/worker.js +9 -0
- package/dist/core/c/reader.d.ts +74 -2
- package/dist/core/c/reader.js +3144 -121
- package/dist/core/c/safety.d.ts +98 -0
- package/dist/core/c/safety.js +642 -0
- package/dist/core/cli.d.ts +9 -0
- package/dist/core/cli.js +215 -8
- package/dist/core/extract-c.d.ts +8 -0
- package/dist/core/extract-c.js +114 -15
- package/dist/core/extract-check.js +124 -12
- package/dist/core/extract-go-check.js +6 -0
- package/dist/core/extract-go.d.ts +15 -1
- package/dist/core/extract-go.js +102 -4
- package/dist/core/extract-print.js +4 -2
- package/dist/core/extract-step.d.ts +22 -0
- package/dist/core/extract-step.js +261 -9
- package/dist/core/extract.d.ts +10 -0
- package/dist/core/extract.js +37 -3
- package/dist/core/law-answer.d.ts +1 -0
- package/dist/core/law-answer.js +23 -0
- package/dist/core/laws.js +3 -16
- package/dist/core/native-law.js +11 -3
- package/dist/interchange/cli.js +13 -0
- package/package.json +1 -1
|
@@ -0,0 +1,642 @@
|
|
|
1
|
+
// C memory & UB safety (Stage 1): first-fault monitor over the checked C subset,
|
|
2
|
+
// independent kernel proof checking (checkLaws / checkKInduction), and native
|
|
3
|
+
// ASan/UBSan replay of every broken obligation.
|
|
4
|
+
import { checkKInduction, checkLaws } from "../../kernel/kernel.js";
|
|
5
|
+
import { clock, proveLaw, proveLaws, withDeadline } from "../../kernel/prove.js";
|
|
6
|
+
import { proveRule } from "../dsl.js";
|
|
7
|
+
import { quietly } from "../cyclic.js";
|
|
8
|
+
import * as I from "../extract-ir.js";
|
|
9
|
+
import { Refusal } from "../extract-read.js";
|
|
10
|
+
import { iteTerm, varTerm } from "../extract-step.js";
|
|
11
|
+
import { fromSafetyModel } from "../extract.js";
|
|
12
|
+
import { conjunction, proveKInduction } from "../kind.js";
|
|
13
|
+
import { evalC, interpret, walk } from "../machine.js";
|
|
14
|
+
import { proofOutput } from "../proof-output.js";
|
|
15
|
+
import { allowed } from "../watch.js";
|
|
16
|
+
import { node, scrubbedClangEnv } from "./reader.js";
|
|
17
|
+
const safetyArtifacts = new WeakMap();
|
|
18
|
+
export const cSafetyArtifactOf = (result) => safetyArtifacts.get(result);
|
|
19
|
+
const assumptions = [
|
|
20
|
+
'ABI, types & compiler/macro configuration (assumption): Clang is resolved from a fixed safe PATH to a verified native executable (custom clang options, scripts, wrapper binaries, external .cfg files, and compiler flags outside -I/-D/-U/-std=/-O*/-W* are refused) running in a closed-world allowlisted environment (PATH, LC_ALL=C, TMPDIR only), with 8-bit char, 16-bit short, 32-bit int, and two’s-complement signed integers under the reported target triple, compiler & absolute path, libc version, SHA-256 digests and path lists of every included user file (userFilesSha256/userFiles) and system header (systemHeadersSha256/systemHeaders), C standard (__STDC_VERSION__/std), -I/-D flags, and macro configuration (macroConfig; only covered scalar types up to 32 bits, constant lookup tables, and fixed arrays of known extent are modeled). Same-UID concurrent processes are trusted (outside the threat model, as a same-UID attacker could equally modify gdp-wired or Clang directly).',
|
|
21
|
+
'Ownership, zeroed start & aliasing (assumption): Selected methods execute sequentially on one live, zero-initialized receiver (or single-declaration file-local static globals from their C initialization) with non-aliasing receiver and scalar out-parameters, no concurrency, and no external mutation from other translation units.',
|
|
22
|
+
'Checked TU closure & failure paths (checked): System headers are classified strictly by resolved path under Clang’s built-in search directories (never linemarker flag 3; caveat: system headers under Clang’s default search list — including /usr/local/include on Linux and Homebrew directories such as /opt/homebrew/include on macOS — are trusted as system headers, with every included system header’s path and snapshot SHA-256 reported in macroConfig), and an AST node is system only if both its spelling and expansion locations are system files. The full include closure (both user files and system headers) is discovered by Clang (-E -H) on the original tree, resolved component-wise (without collapsing .. before symlinks), verified via O_NONBLOCK/O_NOFOLLOW fstat as regular files (refusing case-insensitive /proc, /dev, or /sys paths/symlink hops, non-regular files/FIFOs, -I directories overlapping system directories, user-visible includes resolving into system directories, absolute includes, and user includes outside root/-I), snapshotted once into a private temp tree locked read-only (dirs 0500, files 0400) with -nostdinc and mapped -I/-isystem dirs, cross-checked via Clang -H on every snapshot pass (preprocessor, AST, expanded tokens, alt-path/cwd/mtime/SOURCE_DATE_EPOCH differentials, and build-mode alternates, which snapshot any extra variant system headers under -nostdinc and never fall back to live system directories) for exact include-list and order equality, walked at the end to refuse any modified, removed, or added files/directories in the snapshot, digested from those snapshot bytes for both user and system files, and re-hashed on disk at the end to refuse concurrent writers (modified or added files in the snapshot plus modified original user/system files; same-UID concurrent processes remain outside the threat model). Any user-defined or -D macro expanded inside a system header is refused. User files are audited from Clang’s own raw/expanded token streams and preprocessor (-Xclang -dump-raw-tokens verified byte-contiguously from byte 0/BOM to EOF, -Xclang -dump-tokens, and -E -H -dD): raw NUL bytes, all 9 trigraph sequences (??= ??/ ??\' ??( ??) ??! ??< ??> ??-), and non-C23 digit-quote sequences are refused outright; only literal #include, #define, #undef, #if/#elif/#ifdef/#ifndef/#elifdef/#elifndef/#else/#endif, #pragma once, and #error/#warning are allowed; every #if/#ifdef/#ifndef/#elif/defined() may reference only macros defined earlier in user files or listed in -D flags (any predefined or undefined-elsewhere macro, __has_* query, _Pragma, non-once #pragma, token pasting ##, <scratch space> expansion, invocation-dependent macro __FILE__/__BASE_FILE__/__FILE_NAME__/__TIMESTAMP__/__DATE__/__TIME__/__COUNTER__/__LINE__/__INCLUDE_LEVEL__, SourceLocExpr/PredefinedExpr, or any __builtin_* identifier is refused with name and line), backed by differential checks comparing both preprocessed tokens and folded AST facts (array sizes, constants, types) across alternate path/filename length, alternate empty cwd with stdin=/dev/null, file mtime, SOURCE_DATE_EPOCH days, and NDEBUG/-O0/-O2/-Os/-fsanitize=address,undefined/DEBUG. Every non-system function body must be covered as a selected method or an inlined file-local static helper, or is refused as unchecked and named. Symbol aliases/weak/file-scope __asm__/attributed or post-definition function declarations, non-system globals with pointers/fn-ptrs (including struct/array fields) or function-referencing initializers, bodyless prototypes taking the entry type or pointers, and configured failure returns (fails) after state writes are also refused.',
|
|
23
|
+
'First-fault & replay scope: Only the first tracked array/table-bounds, signed-overflow, or division/remainder fault is checked. Broken obligations require site-matched ASan/UBSan replay (matchedSite); unproven sites are never claimed proven or broken. Abstract stutter on fault is a monitor convention, not native rollback. Known limit: C safety refuses files including <string.h> in this release (glibc __REDIRECT_NTH macro expansion triggers the closed-world system-header macro check).',
|
|
24
|
+
];
|
|
25
|
+
export const uncheckedCSafety = (issues = [], coverage) => ({
|
|
26
|
+
status: 'unchecked',
|
|
27
|
+
issues,
|
|
28
|
+
assumptions,
|
|
29
|
+
coveredFunctions: coverage?.coveredFunctions ?? [],
|
|
30
|
+
...(coverage?.coveredHelpers?.length ? { coveredHelpers: coverage.coveredHelpers } : {}),
|
|
31
|
+
...(coverage?.uncheckedFunctions?.length ? { uncheckedFunctions: coverage.uncheckedFunctions } : {}),
|
|
32
|
+
...(coverage?.macroConfig ? { macroConfig: coverage.macroConfig } : {}),
|
|
33
|
+
});
|
|
34
|
+
const limits = ({ bits, signed }) => signed ? [-(2 ** (bits - 1)), 2 ** (bits - 1) - 1] : [0, 2 ** bits - 1];
|
|
35
|
+
// Bind the alarm conditions to the real C input domain independently of the
|
|
36
|
+
// backend's accumulated refusals. A hit must never override a type restriction.
|
|
37
|
+
function inputDomain(read, c) {
|
|
38
|
+
const m = read.model, event = m.inputs.find(v => v.name === m.event);
|
|
39
|
+
const sorts = {};
|
|
40
|
+
if (!event || event.sort.k !== 'choice')
|
|
41
|
+
throw new Refusal(m.file, 'C safety needs explicit event selectors');
|
|
42
|
+
const selector = { op: 'var', name: event.name, values: event.sort.values };
|
|
43
|
+
const seen = new Set([event.name]);
|
|
44
|
+
const boundScalar = (name, ty) => {
|
|
45
|
+
if (!ty)
|
|
46
|
+
throw new Refusal(m.file, 'C safety needs scalar inputs with a covered C type');
|
|
47
|
+
seen.add(name);
|
|
48
|
+
if (ty.k === 'bool')
|
|
49
|
+
return I.T;
|
|
50
|
+
if (ty.k !== 'int' || !Number.isInteger(ty.bits) || ty.bits < 1 || ty.bits > 32 || typeof ty.signed !== 'boolean')
|
|
51
|
+
throw new Refusal(m.file, 'C safety needs supported fixed-width integer inputs');
|
|
52
|
+
sorts[name] = ty.signed ? 'int' : 'nat';
|
|
53
|
+
const [lo, hi] = limits({ bits: ty.bits, signed: ty.signed }), e = I.nvar(name);
|
|
54
|
+
return I.and(I.cmp('<=', I.num(lo), e), I.cmp('<=', e, I.num(hi)));
|
|
55
|
+
};
|
|
56
|
+
const domain = I.and(...read.methods.map(method => {
|
|
57
|
+
const sel = I.is(selector, method.name);
|
|
58
|
+
return I.or(I.not(sel), I.and(...method.params.map(({ arg, t }) => {
|
|
59
|
+
const ty = c.pkg.ttab[t];
|
|
60
|
+
if (arg.k === 'input')
|
|
61
|
+
return boundScalar(arg.name, ty);
|
|
62
|
+
if (arg.k === 'rec' && ty?.k === 'ptr') {
|
|
63
|
+
const box = c.pkg.ttab[ty.elem];
|
|
64
|
+
if (box?.box && box.fields?.length === 1) {
|
|
65
|
+
const elem = c.pkg.ttab[box.fields[0].t];
|
|
66
|
+
const val = arg.fields.find(([f]) => f === 'value')?.[1];
|
|
67
|
+
if (!val)
|
|
68
|
+
return I.T;
|
|
69
|
+
if (val.k === 'input')
|
|
70
|
+
return boundScalar(val.name, elem);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
throw new Refusal(m.file, 'C safety needs scalar inputs or boxed scalar out-parameters with a covered C type');
|
|
74
|
+
})));
|
|
75
|
+
}));
|
|
76
|
+
if (m.inputs.some(v => !seen.has(v.name)) || m.params.length)
|
|
77
|
+
throw new Refusal(m.file, 'C safety does not admit inferred inputs or constructor parameters');
|
|
78
|
+
return { domain, sorts };
|
|
79
|
+
}
|
|
80
|
+
export function monitorCSafety(m, sites, domain) {
|
|
81
|
+
if (m.maps.length || Object.keys(m.mapWrites).length || m.seqs?.length || m.folds?.length || m.leasts?.length || m.lists?.some(d => d.len === undefined) || Object.values(m.listWrites ?? {}).some(ops => ops.some(o => o.op !== 'set')))
|
|
82
|
+
throw new Refusal(m.file, 'C safety cannot frame maps, dynamic lists or collection folds at a fault');
|
|
83
|
+
const names = new Set([...m.params, ...m.inputs, ...m.state].map(v => v.name));
|
|
84
|
+
const lists = new Set((m.lists ?? []).map(d => d.name));
|
|
85
|
+
const lengths = new Set([...lists].map(n => `${n}_len`));
|
|
86
|
+
for (const site of sites) {
|
|
87
|
+
const refs = I.varsOf(site.condition);
|
|
88
|
+
if ([...refs.vars].some(n => !names.has(n) && !lengths.has(n)) || [...refs.maps].some(n => !lists.has(n)))
|
|
89
|
+
throw new Refusal(site.where, 'a C safety site refers to missing or unsupported model state');
|
|
90
|
+
}
|
|
91
|
+
const reserved = new Set([...names, ...lists, ...lengths]);
|
|
92
|
+
let nextId = 0;
|
|
93
|
+
const alarms = [];
|
|
94
|
+
const alarmNames = sites.map((s) => {
|
|
95
|
+
if (s.condition.op === 'const' && !s.condition.v)
|
|
96
|
+
return undefined;
|
|
97
|
+
let name;
|
|
98
|
+
do {
|
|
99
|
+
name = `cSafetyAlarm${++nextId}`;
|
|
100
|
+
} while (reserved.has(name));
|
|
101
|
+
reserved.add(name);
|
|
102
|
+
alarms.push({ name, sort: { k: 'bool' }, role: 'state' });
|
|
103
|
+
return name;
|
|
104
|
+
});
|
|
105
|
+
const already = alarms.length ? I.or(...alarms.map(a => I.bvar(a.name))) : I.F;
|
|
106
|
+
// Do not infer an order from the site list: each condition is already
|
|
107
|
+
// guarded by the backend's source-specific defined prefix.
|
|
108
|
+
const hits = sites.map((s, j) => (alarmNames[j] ? I.and(I.not(already), domain, s.condition) : I.F));
|
|
109
|
+
const liveHits = hits.filter((_, j) => alarmNames[j] !== undefined);
|
|
110
|
+
const stutter = alarms.length ? I.or(already, ...liveHits) : I.F;
|
|
111
|
+
const init = { ...m.init }, writes = { ...m.writes };
|
|
112
|
+
if (alarms.length)
|
|
113
|
+
for (const v of m.state)
|
|
114
|
+
if (writes[v.name])
|
|
115
|
+
writes[v.name] = iteTerm(stutter, varTerm(v), writes[v.name]);
|
|
116
|
+
const listWrites = Object.fromEntries(Object.entries(m.listWrites ?? {}).map(([n, ops]) => [n, ops.map(o => ({ ...o, when: alarms.length ? I.and(I.not(stutter), o.when) : o.when }))]));
|
|
117
|
+
const alarmLaws = sites.map((site, j) => {
|
|
118
|
+
const name = alarmNames[j];
|
|
119
|
+
if (!name)
|
|
120
|
+
return `r.law(${JSON.stringify(`no first C ${site.kind} fault (static #${j + 1})`)}, () => all())`;
|
|
121
|
+
init[name] = { s: 'bool', e: I.F };
|
|
122
|
+
writes[name] = { s: 'bool', e: I.or(I.bvar(name), hits[j]) };
|
|
123
|
+
return `r.law(${JSON.stringify(`no first C ${site.kind} fault (${name})`)}, ({${name}}) => ${name}.not())`;
|
|
124
|
+
});
|
|
125
|
+
return { model: { ...m, state: [...m.state, ...alarms], init, writes, listWrites,
|
|
126
|
+
refuse: I.or(I.not(domain), alarms.length ? I.and(I.not(stutter), m.refuse) : m.refuse), laws: [...(m.laws ?? []), ...alarmLaws] }, alarmLaws, alarmNames };
|
|
127
|
+
}
|
|
128
|
+
const isArithFn = (name) => /^(?:div|mod)\$\d+$/.test(name);
|
|
129
|
+
function sameSafetyMachine(candidate, expected) {
|
|
130
|
+
const core = (m) => JSON.stringify({
|
|
131
|
+
primitiveFailure: m.primitiveFailure,
|
|
132
|
+
params: m.params, inputs: m.inputs, state: m.state, maps: m.maps,
|
|
133
|
+
pre: m.pre, assume: m.assume, step: m.step, history: m.history, sums: m.sums,
|
|
134
|
+
inputMaps: m.inputMaps, counts: m.counts, leasts: m.leasts,
|
|
135
|
+
});
|
|
136
|
+
if (core(candidate) !== core(expected))
|
|
137
|
+
return false;
|
|
138
|
+
const efns = expected.fns ?? {}, cfns = candidate.fns ?? {};
|
|
139
|
+
for (const [k, v] of Object.entries(efns))
|
|
140
|
+
if (JSON.stringify(cfns[k]) !== JSON.stringify(v))
|
|
141
|
+
return false;
|
|
142
|
+
for (const k of Object.keys(cfns))
|
|
143
|
+
if (!(k in efns) && !isArithFn(k))
|
|
144
|
+
return false;
|
|
145
|
+
const efacts = new Set((expected.facts ?? []).map(f => JSON.stringify(f)));
|
|
146
|
+
for (const f of expected.facts ?? []) {
|
|
147
|
+
if (!(candidate.facts ?? []).some(cf => JSON.stringify(cf) === JSON.stringify(f)))
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
for (const cf of candidate.facts ?? []) {
|
|
151
|
+
if (!efacts.has(JSON.stringify(cf)) && !isArithFn(cf.name.slice(0, cf.name.indexOf(':'))))
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
const hasAllTargets = (provenLaws, targets) => targets.every(t => provenLaws.some(l => JSON.stringify(l.holds) === JSON.stringify(t.holds) && !l.forall && !l.keys?.length && !l.some?.length));
|
|
157
|
+
// Independent kernel proof verification bound to the exact safety machine and target laws.
|
|
158
|
+
// Rejects missing, tampered, or mismatched proofs.
|
|
159
|
+
export function verifyCSafetyProof(machine, targets, bundle) {
|
|
160
|
+
if (!bundle || !targets.length)
|
|
161
|
+
return false;
|
|
162
|
+
if (!sameSafetyMachine(bundle.machine, machine))
|
|
163
|
+
return false;
|
|
164
|
+
try {
|
|
165
|
+
if (bundle.kind === 'usual') {
|
|
166
|
+
if (!bundle.proof || !hasAllTargets(bundle.laws, targets))
|
|
167
|
+
return false;
|
|
168
|
+
return checkLaws(bundle.machine, bundle.laws, bundle.proof);
|
|
169
|
+
}
|
|
170
|
+
if (!bundle.kproof || !bundle.kl)
|
|
171
|
+
return false;
|
|
172
|
+
const expectedGoal = conjunction([...targets]).holds;
|
|
173
|
+
if (JSON.stringify(bundle.kl.law.holds) !== JSON.stringify(expectedGoal))
|
|
174
|
+
return false;
|
|
175
|
+
return checkKInduction(bundle.machine, bundle.assumed, bundle.kl, bundle.kproof);
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function findVerifiedBundle(node, machine, targets) {
|
|
182
|
+
if (!node)
|
|
183
|
+
return undefined;
|
|
184
|
+
if (node.kind === 'usual') {
|
|
185
|
+
const bundle = { kind: 'usual', machine: node.machine, laws: node.laws, proof: node.proof };
|
|
186
|
+
return verifyCSafetyProof(machine, targets, bundle) ? bundle : undefined;
|
|
187
|
+
}
|
|
188
|
+
if (node.kind === 'derived') {
|
|
189
|
+
for (const parent of node.parents) {
|
|
190
|
+
const found = findVerifiedBundle(parent, machine, targets);
|
|
191
|
+
if (found)
|
|
192
|
+
return found;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
// Fast generic Houdini pass over scalar state bounds directly mentioned by the
|
|
198
|
+
// machine's own transitions and safety guards. Every surviving bound is verified
|
|
199
|
+
// from init and step by the kernel and checked jointly via verifyCSafetyProof.
|
|
200
|
+
function tryScalarBoundsProof(rule, machine, base, targets, budgetMs) {
|
|
201
|
+
const stateKeys = Object.keys(machine.state);
|
|
202
|
+
const scalars = stateKeys.filter(k => !k.startsWith('cSafetyAlarm') && !k.endsWith('$neg') && !k.endsWith('_len') && !k.endsWith('_result'));
|
|
203
|
+
if (!scalars.length)
|
|
204
|
+
return undefined;
|
|
205
|
+
const scalarSet = new Set(scalars);
|
|
206
|
+
const boundsByVar = new Map();
|
|
207
|
+
const addBound = (v, k) => {
|
|
208
|
+
if (!scalarSet.has(v) || !Number.isInteger(k) || k < 0 || k > 65536)
|
|
209
|
+
return;
|
|
210
|
+
let s = boundsByVar.get(v);
|
|
211
|
+
if (!s) {
|
|
212
|
+
s = new Set();
|
|
213
|
+
boundsByVar.set(v, s);
|
|
214
|
+
}
|
|
215
|
+
s.add(k);
|
|
216
|
+
};
|
|
217
|
+
const varNameOf = (e) => {
|
|
218
|
+
if (!e || typeof e !== 'object')
|
|
219
|
+
return undefined;
|
|
220
|
+
const o = e;
|
|
221
|
+
if (o.op === 'var' && typeof o.name === 'string' && scalarSet.has(o.name))
|
|
222
|
+
return { v: o.name, shift: 0 };
|
|
223
|
+
if (o.op === 'add') {
|
|
224
|
+
const a = o.a, b = o.b;
|
|
225
|
+
if (a?.op === 'var' && typeof a.name === 'string' && scalarSet.has(a.name) && b?.op === 'const' && typeof b.value === 'number')
|
|
226
|
+
return { v: a.name, shift: b.value };
|
|
227
|
+
if (b?.op === 'var' && typeof b.name === 'string' && scalarSet.has(b.name) && a?.op === 'const' && typeof a.value === 'number')
|
|
228
|
+
return { v: b.name, shift: a.value };
|
|
229
|
+
}
|
|
230
|
+
return undefined;
|
|
231
|
+
};
|
|
232
|
+
for (const v of scalars) {
|
|
233
|
+
walk(machine.step.state?.[v], o => {
|
|
234
|
+
if (o.op === 'get' && typeof o.map === 'string' && /^mod\$\d+$/.test(o.map)) {
|
|
235
|
+
const mod = Number(o.map.slice(4));
|
|
236
|
+
if (mod >= 2 && mod <= 65536)
|
|
237
|
+
addBound(v, mod - 1);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
walk([machine.step.state, machine.assume], o => {
|
|
242
|
+
if (o.op !== '<' && o.op !== '<=' && o.op !== '=')
|
|
243
|
+
return;
|
|
244
|
+
const check = (lhs, rhs) => {
|
|
245
|
+
const vr = varNameOf(lhs), r = rhs;
|
|
246
|
+
if (!vr || r?.op !== 'const' || typeof r.value !== 'number')
|
|
247
|
+
return;
|
|
248
|
+
const k = r.value - vr.shift;
|
|
249
|
+
if (k >= 1 && k <= 65536)
|
|
250
|
+
addBound(vr.v, k - 1);
|
|
251
|
+
if (k >= 0 && k <= 65536)
|
|
252
|
+
addBound(vr.v, k);
|
|
253
|
+
};
|
|
254
|
+
check(o.a, o.b);
|
|
255
|
+
check(o.b, o.a);
|
|
256
|
+
});
|
|
257
|
+
const run = interpret(machine), g = rule.compiled(), p = rule.encodeParams({});
|
|
258
|
+
const initSt = run.init(p);
|
|
259
|
+
const rawCands = [];
|
|
260
|
+
for (const v of scalars) {
|
|
261
|
+
const negName = `${v}$neg`;
|
|
262
|
+
if (negName in machine.state) {
|
|
263
|
+
const holds = { op: '<=', a: { op: 'var', name: negName }, b: { op: 'const', value: 0 } };
|
|
264
|
+
if (evalC(holds, p, initSt, machine))
|
|
265
|
+
rawCands.push({ name: `c safety bound: ${v} >= 0`, holds });
|
|
266
|
+
}
|
|
267
|
+
const ks = [...(boundsByVar.get(v) ?? [])].sort((a, b) => a - b).slice(0, 4);
|
|
268
|
+
for (const k of ks) {
|
|
269
|
+
const holds = { op: '<=', a: { op: 'var', name: v }, b: { op: 'const', value: k } };
|
|
270
|
+
if (evalC(holds, p, initSt, machine))
|
|
271
|
+
rawCands.push({ name: `c safety bound: ${v} <= ${k}`, holds });
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const existing = new Set(base.map(l => JSON.stringify(l.holds)));
|
|
275
|
+
let kept = rawCands.filter(l => !existing.has(JSON.stringify(l.holds))).slice(0, 16);
|
|
276
|
+
if (!kept.length)
|
|
277
|
+
return undefined;
|
|
278
|
+
// Fast concrete reachability pre-filter (sound: only discards bounds falsified on
|
|
279
|
+
// reachable states before calling the kernel; all survivors are still proven by checkLaws).
|
|
280
|
+
const methodKey = machine.inputs[0];
|
|
281
|
+
if (methodKey) {
|
|
282
|
+
const zeroInp = (mIdx, fill = 0) => {
|
|
283
|
+
const inp = {};
|
|
284
|
+
for (const name of machine.inputs)
|
|
285
|
+
inp[name] = name === methodKey ? mIdx : (name.endsWith('$neg') ? 0 : fill);
|
|
286
|
+
return inp;
|
|
287
|
+
};
|
|
288
|
+
const filterAt = (st) => {
|
|
289
|
+
kept = kept.filter(l => evalC(l.holds, p, st, machine));
|
|
290
|
+
};
|
|
291
|
+
for (let mIdx = 0; mIdx < 16 && kept.length; mIdx++) {
|
|
292
|
+
for (const fill of [0, 1]) {
|
|
293
|
+
const inp = zeroInp(mIdx, fill);
|
|
294
|
+
let st = g.init(p);
|
|
295
|
+
if (!allowed(machine, run, p, st, inp))
|
|
296
|
+
continue;
|
|
297
|
+
for (let step = 0; step < 32 && kept.length; step++) {
|
|
298
|
+
if (!allowed(machine, run, p, st, inp))
|
|
299
|
+
break;
|
|
300
|
+
st = g.step(p, st, inp);
|
|
301
|
+
filterAt(st);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (kept.length) {
|
|
306
|
+
let st = g.init(p);
|
|
307
|
+
for (let step = 0; step < 32 && kept.length; step++) {
|
|
308
|
+
let moved = false;
|
|
309
|
+
for (let mIdx = 0; mIdx < 16 && kept.length; mIdx++) {
|
|
310
|
+
const inp = zeroInp(mIdx, step & 1);
|
|
311
|
+
if (!allowed(machine, run, p, st, inp))
|
|
312
|
+
continue;
|
|
313
|
+
st = g.step(p, st, inp);
|
|
314
|
+
filterAt(st);
|
|
315
|
+
moved = true;
|
|
316
|
+
}
|
|
317
|
+
if (!moved)
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (!kept.length)
|
|
323
|
+
return undefined;
|
|
324
|
+
const until = clock() + Math.max(500, budgetMs);
|
|
325
|
+
return withDeadline(until, () => {
|
|
326
|
+
// Houdini fixed point: drop any bound not inductive under the surviving set.
|
|
327
|
+
for (let round = 0; round < 16 && kept.length && clock() < until; round++) {
|
|
328
|
+
const all = [...base, ...kept];
|
|
329
|
+
const next = [];
|
|
330
|
+
let dropped = false;
|
|
331
|
+
for (let i = 0; i < kept.length; i++) {
|
|
332
|
+
if (clock() >= until)
|
|
333
|
+
return undefined;
|
|
334
|
+
const r = quietly(() => proveLaw(machine, all, base.length + i));
|
|
335
|
+
if (r.proven)
|
|
336
|
+
next.push(kept[i]);
|
|
337
|
+
else
|
|
338
|
+
dropped = true;
|
|
339
|
+
}
|
|
340
|
+
kept = next;
|
|
341
|
+
if (!dropped)
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
if (!kept.length || clock() >= until)
|
|
345
|
+
return undefined;
|
|
346
|
+
const laws = [...base, ...kept, ...targets];
|
|
347
|
+
const out = quietly(() => proveLaws(machine, laws));
|
|
348
|
+
if (out.proven && out.checked && out.proof) {
|
|
349
|
+
const bundle = { kind: 'usual', machine, laws, proof: out.proof };
|
|
350
|
+
if (verifyCSafetyProof(machine, targets, bundle))
|
|
351
|
+
return bundle;
|
|
352
|
+
}
|
|
353
|
+
return undefined;
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
function proveCSafetyTarget(rule, machine, base, ruleInvariants, targets, searchMs) {
|
|
357
|
+
// Fast direct check first (skip redundant cyclic cert translation; checkLaws verifies the usual proof directly).
|
|
358
|
+
const full = [...base, ...targets];
|
|
359
|
+
const direct = quietly(() => proveLaws(machine, full));
|
|
360
|
+
if (direct.proven && direct.checked && direct.proof) {
|
|
361
|
+
const bundle = { kind: 'usual', machine, laws: full, proof: direct.proof };
|
|
362
|
+
if (verifyCSafetyProof(machine, targets, bundle))
|
|
363
|
+
return { proven: true, bundle };
|
|
364
|
+
}
|
|
365
|
+
// Fast generic scalar-bounds Houdini before full invariant search.
|
|
366
|
+
const seeded = tryScalarBoundsProof(rule, machine, base, targets, Math.min(12_000, Math.floor(searchMs / 2)));
|
|
367
|
+
if (seeded)
|
|
368
|
+
return { proven: true, bundle: seeded };
|
|
369
|
+
const liveTargets = targets.filter(t => !t.name.includes('(static #'));
|
|
370
|
+
const sought = liveTargets.length ? liveTargets : targets;
|
|
371
|
+
// Reachable-state invariant search and bounded model checking, capturing the actual kernel proof.
|
|
372
|
+
let captured;
|
|
373
|
+
const prevObserver = proofOutput.on;
|
|
374
|
+
proofOutput.on = e => { captured = e; };
|
|
375
|
+
let v;
|
|
376
|
+
try {
|
|
377
|
+
v = quietly(() => proveRule(rule, [...ruleInvariants, ...sought], { search: { ms: searchMs, cycles: false } }));
|
|
378
|
+
}
|
|
379
|
+
finally {
|
|
380
|
+
proofOutput.on = prevObserver;
|
|
381
|
+
}
|
|
382
|
+
if (v.proven && v.checked) {
|
|
383
|
+
const found = findVerifiedBundle(captured?.proof, machine, targets);
|
|
384
|
+
if (found)
|
|
385
|
+
return { proven: true, bundle: found };
|
|
386
|
+
const stateNames = new Set(Object.keys(machine.state));
|
|
387
|
+
const extra = (v.found?.laws ?? []).map(f => f.law).filter(l => {
|
|
388
|
+
const text = JSON.stringify(l.holds);
|
|
389
|
+
return ![...text.matchAll(/"op":"var","name":"([^"]+\$sum)"/g)].some(m => !stateNames.has(m[1]));
|
|
390
|
+
});
|
|
391
|
+
const reprovedLaws = [...base, ...targets, ...extra];
|
|
392
|
+
const rp = quietly(() => proveLaws(machine, reprovedLaws));
|
|
393
|
+
if (rp.proven && rp.checked && rp.proof) {
|
|
394
|
+
const bundle = { kind: 'usual', machine, laws: reprovedLaws, proof: rp.proof };
|
|
395
|
+
if (verifyCSafetyProof(machine, targets, bundle))
|
|
396
|
+
return { proven: true, bundle };
|
|
397
|
+
}
|
|
398
|
+
if (v.k !== undefined) {
|
|
399
|
+
const kd = quietly(() => proveKInduction(machine, base, conjunction(targets), { from: v.k, to: v.k, ms: Math.min(searchMs, 5_000) }));
|
|
400
|
+
if (kd.proven && kd.checked && kd.kl && kd.proof) {
|
|
401
|
+
const bundle = { kind: 'kind', machine, assumed: base, kl: kd.kl, kproof: kd.proof };
|
|
402
|
+
if (verifyCSafetyProof(machine, targets, bundle))
|
|
403
|
+
return { proven: true, bundle };
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return { proven: false, why: 'kernel proof failed independent checkLaws verification' };
|
|
407
|
+
}
|
|
408
|
+
if (v.run)
|
|
409
|
+
return { proven: false, run: v.run, ...(v.goal ? { goal: v.goal } : {}) };
|
|
410
|
+
return { proven: false, why: v.why ?? v.stuck ?? 'unproven' };
|
|
411
|
+
}
|
|
412
|
+
// Fast deterministic boundary-value probe over C scalar input limits.
|
|
413
|
+
// Catches nonlinear faults (e.g. uint16_t * uint16_t overflow) that small-bound random
|
|
414
|
+
// walks or linear BMC miss; every candidate trace is still validated by ASan/UBSan replay.
|
|
415
|
+
function probeBoundaryFault(read, c, rule, machine, alarmName) {
|
|
416
|
+
if (!alarmName)
|
|
417
|
+
return undefined;
|
|
418
|
+
const g = rule.compiled(), run = interpret(machine), p = rule.encodeParams({}), init = g.init(p);
|
|
419
|
+
const samplesOf = (ty) => {
|
|
420
|
+
if (!ty)
|
|
421
|
+
return [0];
|
|
422
|
+
if (ty.k === 'bool')
|
|
423
|
+
return [false, true];
|
|
424
|
+
if (ty.k !== 'int' || !ty.bits)
|
|
425
|
+
return [0];
|
|
426
|
+
const [lo, hi] = limits({ bits: ty.bits, signed: ty.signed !== false });
|
|
427
|
+
return [...new Set(ty.signed !== false ? [lo, lo + 1, -1, 0, 1, hi - 1, hi] : [0, 1, Math.min(hi, 16), hi - 1, hi].filter(v => v >= lo && v <= hi))];
|
|
428
|
+
};
|
|
429
|
+
for (const m of read.methods) {
|
|
430
|
+
const params = [];
|
|
431
|
+
for (const pa of m.params) {
|
|
432
|
+
const ty = c.pkg.ttab[pa.t];
|
|
433
|
+
if (pa.arg.k === 'input')
|
|
434
|
+
params.push({ key: pa.arg.name, vals: samplesOf(ty) });
|
|
435
|
+
else if (pa.arg.k === 'rec' && ty?.k === 'ptr') {
|
|
436
|
+
const box = c.pkg.ttab[ty.elem], val = pa.arg.fields.find(([f]) => f === 'value')?.[1];
|
|
437
|
+
if (box?.box && val?.k === 'input')
|
|
438
|
+
params.push({ key: val.name, vals: samplesOf(c.pkg.ttab[box.fields[0].t]) });
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
let combos = [{}];
|
|
442
|
+
for (const pr of params) {
|
|
443
|
+
const next = [];
|
|
444
|
+
for (const base of combos) {
|
|
445
|
+
for (const v of pr.vals) {
|
|
446
|
+
next.push({ ...base, [pr.key]: v });
|
|
447
|
+
if (next.length >= 256)
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
if (next.length >= 256)
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
453
|
+
combos = next;
|
|
454
|
+
}
|
|
455
|
+
for (const args of combos) {
|
|
456
|
+
const raw = { method: m.name, ...args };
|
|
457
|
+
let enc;
|
|
458
|
+
try {
|
|
459
|
+
enc = rule.encodeInput(raw);
|
|
460
|
+
}
|
|
461
|
+
catch {
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
if (!allowed(machine, run, p, init, enc))
|
|
465
|
+
continue;
|
|
466
|
+
const nx = rule.decode(g.step(p, g.fork(init), enc));
|
|
467
|
+
if (nx[alarmName] === true)
|
|
468
|
+
return { params: {}, trace: [enc] };
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return undefined;
|
|
472
|
+
}
|
|
473
|
+
// Replay a counterexample run on the compiled C code under ASan and UBSan.
|
|
474
|
+
// Never uses shell interpolation; passes JSONL request input via a temporary file.
|
|
475
|
+
export function replaySafety(o, run, site) {
|
|
476
|
+
const fs = node('node:fs'), cp = node('node:child_process'), os = node('node:os');
|
|
477
|
+
const work = fs.mkdtempSync(`${os.tmpdir()}/gdp-replay-`), h = `${work}/harness.c`, bin = `${work}/harness`, inFile = `${work}/in.jsonl`, outFile = `${work}/out.jsonl`;
|
|
478
|
+
try {
|
|
479
|
+
fs.writeFileSync(h, o.harness);
|
|
480
|
+
// The generated replay harness uses POSIX sigsetjmp/siglongjmp/setitimer, which strict
|
|
481
|
+
// -std=c99/c11/c17/c23 hides on glibc/BSD; keep the same C standard year in GNU mode for replay.
|
|
482
|
+
const replayFlags = o.flags.map(f => f.replace(/^-std=c(\d+)$/, '-std=gnu$1'));
|
|
483
|
+
const b = cp.spawnSync(o.clang ?? 'clang', [
|
|
484
|
+
...replayFlags, '-w', '-O0', '-g', '-fno-omit-frame-pointer',
|
|
485
|
+
'-fsanitize=address,undefined', '-fsanitize-recover=all',
|
|
486
|
+
...(o.strictFlex ?? []), h, '-o', bin,
|
|
487
|
+
], { encoding: 'utf8', timeout: 60_000, env: scrubbedClangEnv() });
|
|
488
|
+
if (b.status !== 0)
|
|
489
|
+
return { built: false, requests: [], reports: [], states: [], stderr: b.stderr.split('\n').slice(0, 12).join('\n'), matchedSite: false };
|
|
490
|
+
const name = (t) => (typeof t.method === 'number' ? o.choices[t.method] : typeof t.method === 'string' ? t.method : o.methods[0].name);
|
|
491
|
+
const decodeScalar = (t, key, ty) => {
|
|
492
|
+
if (ty?.k === 'bool')
|
|
493
|
+
return Boolean(t[key]);
|
|
494
|
+
return Number(t[key] ?? 0) - Number(t[`${key}$neg`] ?? 0);
|
|
495
|
+
};
|
|
496
|
+
const requests = [], lines = [JSON.stringify({ op: 'new', a: o.ctor.map(p => run.params[p] ?? 0) })];
|
|
497
|
+
for (const t of run.trace) {
|
|
498
|
+
const m = o.methods.find(x => x.name === name(t));
|
|
499
|
+
if (!m)
|
|
500
|
+
return { built: true, requests, reports: [], states: [], stderr: `unknown method in trace: ${name(t)}`, matchedSite: false };
|
|
501
|
+
const a = [], shown = [];
|
|
502
|
+
for (const p of m.params) {
|
|
503
|
+
const ty = o.ttab[p.t];
|
|
504
|
+
if (p.arg.k === 'input') {
|
|
505
|
+
const v = decodeScalar(t, p.arg.name, ty);
|
|
506
|
+
a.push(v);
|
|
507
|
+
shown.push(String(v));
|
|
508
|
+
}
|
|
509
|
+
else if (p.arg.k === 'rec' && ty?.k === 'ptr') {
|
|
510
|
+
const box = o.ttab[ty.elem], val = p.arg.fields.find(([f]) => f === 'value')?.[1];
|
|
511
|
+
if (box?.box && val?.k === 'input') {
|
|
512
|
+
const v = decodeScalar(t, val.name, o.ttab[box.fields[0].t]);
|
|
513
|
+
a.push({ value: v });
|
|
514
|
+
shown.push(`&(${String(v)})`);
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
a.push({});
|
|
518
|
+
shown.push('&out');
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
requests.push(`${m.name}(${shown.join(', ')})`);
|
|
523
|
+
lines.push(JSON.stringify({ op: 'call', id: 1, m: m.name, a }));
|
|
524
|
+
}
|
|
525
|
+
fs.writeFileSync(inFile, lines.join('\n') + '\n');
|
|
526
|
+
const r = cp.spawnSync(bin, [inFile, outFile], {
|
|
527
|
+
encoding: 'utf8',
|
|
528
|
+
timeout: 30_000,
|
|
529
|
+
env: scrubbedClangEnv({ ASAN_OPTIONS: 'detect_leaks=0:halt_on_error=0', UBSAN_OPTIONS: 'print_stacktrace=0:halt_on_error=0' }),
|
|
530
|
+
});
|
|
531
|
+
const reports = r.stderr.split('\n')
|
|
532
|
+
.filter(l => /runtime error:|ERROR: AddressSanitizer|SUMMARY: AddressSanitizer|WRITE of size|READ of size/.test(l))
|
|
533
|
+
.map(l => l.replace(/^.*?([^/\s]+\.c:\d+:\d+: runtime error:)/, '$1').trim());
|
|
534
|
+
const states = fs.existsSync(outFile) ? fs.readFileSync(outFile, 'utf8').trim().split('\n').filter(Boolean).slice(1) : [];
|
|
535
|
+
const siteFileLine = site?.where.replace(/#\d+$/, '').replace(/:\d+$/, ':');
|
|
536
|
+
const siteRe = siteFileLine ? new RegExp(`(?:^|[/\\s])${siteFileLine.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`) : undefined;
|
|
537
|
+
const matchedSite = !siteRe ? reports.length > 0 : reports.some(l => siteRe.test(l)) || siteRe.test(r.stderr);
|
|
538
|
+
return { built: true, requests, reports, states, stderr: r.stderr.slice(0, 4000), matchedSite };
|
|
539
|
+
}
|
|
540
|
+
finally {
|
|
541
|
+
try {
|
|
542
|
+
fs.rmSync(work, { recursive: true, force: true });
|
|
543
|
+
}
|
|
544
|
+
catch { /* gone */ }
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
export function analyzeCSafety(read, c, sites, domains, opts = {}) {
|
|
548
|
+
const coveredFunctions = read.methods.map(m => m.name);
|
|
549
|
+
const coveredHelpers = c.helpers?.length ? [...c.helpers] : undefined;
|
|
550
|
+
const coverage = { coveredFunctions, ...(coveredHelpers ? { coveredHelpers } : {}), ...(c.macroConfig ? { macroConfig: c.macroConfig } : {}) };
|
|
551
|
+
if (!sites.length)
|
|
552
|
+
return uncheckedCSafety([], coverage);
|
|
553
|
+
// A single source site can appear on several symbolic paths or events.
|
|
554
|
+
const unique = new Map();
|
|
555
|
+
for (const site of sites) {
|
|
556
|
+
const key = JSON.stringify([site.where, site.kind]), prev = unique.get(key);
|
|
557
|
+
unique.set(key, prev ? { ...prev, condition: I.or(prev.condition, site.condition) } : site);
|
|
558
|
+
}
|
|
559
|
+
const all = [...unique.values()];
|
|
560
|
+
const issue = ({ kind, where }, status, extra) => ({ where, kind, status, ...(extra?.replay ? { replay: extra.replay } : {}), ...(extra?.why ? { why: extra.why } : {}) });
|
|
561
|
+
const { domain, sorts } = inputDomain(read, c);
|
|
562
|
+
const { model, alarmNames } = monitorCSafety(read.model, all, domain);
|
|
563
|
+
const x = fromSafetyModel(model, `${c.entry}.c`, { ...domains, ...sorts });
|
|
564
|
+
if (!x.ok || !x.rule)
|
|
565
|
+
return uncheckedCSafety(all.map(s => issue(s, 'unchecked')), coverage);
|
|
566
|
+
const rule = x.rule, machine = rule.machine;
|
|
567
|
+
const laws = x.invariants ?? [];
|
|
568
|
+
const first = (read.model.laws ?? []).length, targets = laws.slice(first, first + all.length);
|
|
569
|
+
if (targets.length !== all.length)
|
|
570
|
+
return uncheckedCSafety(all.map(s => issue(s, 'unchecked')), coverage);
|
|
571
|
+
const modelInvariants = [...laws.slice(0, first), ...laws.slice(first + all.length)];
|
|
572
|
+
const base = [...rule.kindLaws(), ...modelInvariants];
|
|
573
|
+
const searchMs = opts.searchMs ?? 25_000;
|
|
574
|
+
const jointly = proveCSafetyTarget(rule, machine, base, modelInvariants, targets, searchMs);
|
|
575
|
+
if (jointly.proven) {
|
|
576
|
+
const issues = all.map(site => issue(site, 'proven'));
|
|
577
|
+
const result = { status: 'proven', issues, assumptions, ...coverage };
|
|
578
|
+
safetyArtifacts.set(result, { rule, machine, source: x.source ?? '', baseLaws: base, targetLaws: targets, jointProof: jointly.bundle, siteProofs: targets.map(() => jointly.bundle) });
|
|
579
|
+
return result;
|
|
580
|
+
}
|
|
581
|
+
const siteProofs = [];
|
|
582
|
+
const issues = all.map((site, j) => {
|
|
583
|
+
const target = targets[j];
|
|
584
|
+
const reused = !jointly.proven && jointly.run && jointly.goal?.startsWith(target.name)
|
|
585
|
+
? jointly
|
|
586
|
+
: all.length === 1 ? jointly : proveCSafetyTarget(rule, machine, base, modelInvariants, [target], searchMs);
|
|
587
|
+
if (reused.proven) {
|
|
588
|
+
siteProofs.push(reused.bundle);
|
|
589
|
+
return issue(site, 'proven');
|
|
590
|
+
}
|
|
591
|
+
siteProofs.push(undefined);
|
|
592
|
+
const run = reused.run ?? probeBoundaryFault(read, c, rule, machine, alarmNames[j]);
|
|
593
|
+
if (run && opts.replay) {
|
|
594
|
+
const rp = opts.replay(run, site);
|
|
595
|
+
if (rp.built && rp.reports.length > 0 && rp.matchedSite)
|
|
596
|
+
return issue(site, 'broken', { replay: rp });
|
|
597
|
+
return issue(site, 'unproven', {
|
|
598
|
+
replay: rp,
|
|
599
|
+
why: !rp.built
|
|
600
|
+
? 'failed to build ASan/UBSan replay harness'
|
|
601
|
+
: rp.reports.length > 0
|
|
602
|
+
? `ASan/UBSan fired, but did not match target site ${site.where}`
|
|
603
|
+
: 'counterexample run did not trigger ASan/UBSan on compiled C',
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
return issue(site, 'unproven', { why: reused.why });
|
|
607
|
+
});
|
|
608
|
+
const status = issues.some(s => s.status === 'broken') ? 'broken' : issues.every(s => s.status === 'proven') ? 'proven' : 'unproven';
|
|
609
|
+
// If every site proved individually, assemble a single unified jointProof when possible.
|
|
610
|
+
let jointProof;
|
|
611
|
+
if (status === 'proven') {
|
|
612
|
+
const seen = new Set(base.map(l => JSON.stringify(l.holds)));
|
|
613
|
+
const combined = [...base];
|
|
614
|
+
for (const sp of siteProofs) {
|
|
615
|
+
if (sp?.kind !== 'usual')
|
|
616
|
+
continue;
|
|
617
|
+
for (const l of sp.laws) {
|
|
618
|
+
const key = JSON.stringify(l.holds);
|
|
619
|
+
if (!seen.has(key)) {
|
|
620
|
+
seen.add(key);
|
|
621
|
+
combined.push(l);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
for (const t of targets) {
|
|
626
|
+
const key = JSON.stringify(t.holds);
|
|
627
|
+
if (!seen.has(key)) {
|
|
628
|
+
seen.add(key);
|
|
629
|
+
combined.push(t);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
const jp = quietly(() => proveLaws(machine, combined));
|
|
633
|
+
if (jp.proven && jp.checked && jp.proof) {
|
|
634
|
+
const bundle = { kind: 'usual', machine, laws: combined, proof: jp.proof };
|
|
635
|
+
if (verifyCSafetyProof(machine, targets, bundle))
|
|
636
|
+
jointProof = bundle;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
const result = { status, issues, assumptions, ...coverage };
|
|
640
|
+
safetyArtifacts.set(result, { rule, machine, source: x.source ?? '', baseLaws: base, targetLaws: targets, ...(jointProof ? { jointProof } : {}), siteProofs });
|
|
641
|
+
return result;
|
|
642
|
+
}
|