@exploitlens/invariants 0.0.0-stage → 0.1.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.
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Security invariant evaluation (EL-050), rewritten for audit findings P3
3
+ * and P11.
4
+ *
5
+ * ## What was wrong
6
+ *
7
+ * The first implementation asked one question: "does *any* `native-transfer`
8
+ * effect anywhere in this side's `effects.json` move at least
9
+ * `minimumDelta` wei?" That is not the declared invariant, and it is wrong
10
+ * in both directions:
11
+ *
12
+ * - `extractEffects` deliberately walks every forge trace stage, so the
13
+ * demo fixture's own `setUp()` deposit — 10 ether from the victim *into*
14
+ * the vault, a perfectly legitimate act — satisfied it. The baseline gate
15
+ * could report "the exploit reproduced" on evidence that was not the
16
+ * exploit, and the patched replay could fail for the same reason.
17
+ * - It ignored direction entirely. Money moving *into* the vault counted the
18
+ * same as money being drained *out of* it.
19
+ * - `expectedExploit.asset` was read by no code at all.
20
+ *
21
+ * ## What it asks now
22
+ *
23
+ * The declared invariant is "no account may withdraw more value than it
24
+ * deposited". Expressed over the effects this pipeline can actually observe,
25
+ * that is a **directional, pairwise** question about the **exploit stage
26
+ * only**, asked in two steps:
27
+ *
28
+ * 1. **Find the parties that lost custody of value.** An eligible
29
+ * counterparty is an address that received value at some point in the run
30
+ * (any stage, so the vault's `setUp()` funding counts) *and* ended the
31
+ * exploit stage down by at least `minimumDelta`.
32
+ * 2. **Ask who took value out of one of them.** For each such counterparty,
33
+ * find an address whose value received *from that counterparty* exceeds
34
+ * what it sent *to that counterparty* by `minimumDelta` or more.
35
+ *
36
+ * The inbound requirement in step 1 is load-bearing, and getting it wrong
37
+ * was a real defect (review finding B1). A Foundry harness funds the
38
+ * attacker and never receives anything back: it is a pure payer, not a party
39
+ * that lost value it was holding. A global per-address net counts that
40
+ * funding as exploit proceeds, so on the *patched* demo commit — where the
41
+ * attacker deposits 1 ETH, is blocked from re-entering, and withdraws its
42
+ * own 1 ETH back — the attacker looked +1 ETH ahead and a working patch
43
+ * failed `exact-replay`. Requiring the counterparty to have held value, and
44
+ * measuring gain pairwise against it, reads that run correctly as a net of
45
+ * zero. This is a structural property of the flows, never a hardcoded
46
+ * address, so it holds for any fixture.
47
+ *
48
+ * Four properties follow directly, and each is pinned by a test — the
49
+ * last two against real Foundry output from the pinned commits, because
50
+ * synthetic traces did not expose the defect above:
51
+ *
52
+ * - **Setup cannot satisfy it.** `Deployment` and `Setup` effects are
53
+ * excluded by stage, so the fixture's seed deposit is not
54
+ * evidence of an exploit.
55
+ * - **Direction is checked.** A deposit is an outflow for the depositor and
56
+ * nets against anything it later withdraws.
57
+ * - **Recovering your own deposit is not exploitation.** Withdrawing exactly
58
+ * what you put in nets to zero against that counterparty.
59
+ * - **A violation names both sides.** The account that gained and the party
60
+ * it drained, with the pairwise amount.
61
+ *
62
+ * ## What it refuses to answer (P11)
63
+ *
64
+ * Each evaluator is honest about its own reach:
65
+ * - `vault-solvency-evaluator` supports exactly `native-transfer`.
66
+ * - `token-solvency-evaluator` supports `token-transfer` restricted to
67
+ * standard `ERC20` (refuses `ERC721` and `ERC1155`).
68
+ * Any manifest declaring an effect type outside the supported set, or an
69
+ * `asset` the evaluator cannot tie to the declared effect type, returns
70
+ * `inconclusive` rather than a verdict.
71
+ *
72
+ * `inconclusive` is the safe direction in both gates that consume this: the
73
+ * baseline gate reports `inconclusive` (never a false "reproduced"), and the
74
+ * exact-replay gate reports `inconclusive` rather than a false `pass`. An
75
+ * effect class we cannot see can therefore never become a green gate.
76
+ */
77
+ import { type EffectsFile } from "@exploitlens/effects";
78
+ import type { ExploitBundle } from "@exploitlens/manifest";
79
+ export type InvariantEvaluationStatus = "violated" | "not-violated" | "inconclusive";
80
+ /**
81
+ * Effect classes `vault-solvency-evaluator` can reason about.
82
+ */
83
+ export declare const SUPPORTED_EFFECT_TYPES: readonly ["native-transfer"];
84
+ /**
85
+ * Effect classes `token-solvency-evaluator` can reason about.
86
+ */
87
+ export declare const TOKEN_SUPPORTED_EFFECT_TYPES: readonly ["token-transfer"];
88
+ /**
89
+ * Asset names accepted alongside `effectType: "native-transfer"`. A native
90
+ * transfer *is* the chain's native currency, so naming anything else means
91
+ * the manifest and the effect type disagree.
92
+ */
93
+ export declare const NATIVE_ASSET_NAMES: readonly ["ETH", "WEI", "NATIVE"];
94
+ /** The forge trace stage that carries the exploit itself, as opposed to fixture setup. */
95
+ export declare const EXPLOIT_STAGE = "Execution";
96
+ export interface InvariantEvaluation {
97
+ status: InvariantEvaluationStatus;
98
+ /**
99
+ * Effect ids in the evaluated `effects.json` that constitute the
100
+ * violation. Always empty when `status` is not `"violated"`.
101
+ */
102
+ violatingEffectIds: string[];
103
+ /** The address that gained more than it contributed, when one was identified. */
104
+ beneficiary?: string;
105
+ /** The address that funded that gain, when one was identified. */
106
+ counterparty?: string;
107
+ /** Net amount the beneficiary gained over the exploit stage, as a base-10 string. */
108
+ netGainAmount?: string;
109
+ reasons: string[];
110
+ }
111
+ export interface InvariantEvaluationInput {
112
+ expectedExploit: ExploitBundle["expectedExploit"];
113
+ invariant: ExploitBundle["invariant"];
114
+ /** The side's `effects.json` (either `vulnerable/` or `patched/`). */
115
+ effects: EffectsFile;
116
+ }
117
+ export type InvariantEvaluator = (input: InvariantEvaluationInput) => InvariantEvaluation;
118
+ /**
119
+ * The evaluator for native ETH vault solvency
120
+ * (`invariant.evaluator: "vault-solvency-evaluator"`).
121
+ */
122
+ export declare const vaultSolvencyEvaluator: InvariantEvaluator;
123
+ /**
124
+ * Evaluator for ERC-20 token solvency
125
+ * (`invariant.evaluator: "token-solvency-evaluator"`).
126
+ *
127
+ * Follows the same custody-scoping, stage exclusion, and directional pairwise
128
+ * accounting principles as `vaultSolvencyEvaluator`.
129
+ *
130
+ * Restricted strictly to standard "ERC20" token transfers; fails closed
131
+ * (`inconclusive`) if non-ERC20 token-transfer standards (such as ERC721 or
132
+ * ERC1155) are encountered.
133
+ *
134
+ * If `expectedExploit.asset` is specified, it must be a valid 20-byte 0x-prefixed
135
+ * hex contract address to scope ledger accounting to that single token.
136
+ *
137
+ * LIMITATION: If `expectedExploit.asset` is omitted, all ERC20 token-transfer
138
+ * effects in the exploit stage are aggregated together. This is valid only for
139
+ * single-token fixtures (like STAX LP staking).
140
+ */
141
+ export declare const tokenSolvencyEvaluator: InvariantEvaluator;
142
+ /**
143
+ * Evaluates `input.invariant` against `input.effects` using the registry
144
+ * entry named by `input.invariant.evaluator`. Any evaluator id not in the
145
+ * registry fails closed as an explicit `"inconclusive"` result — never a
146
+ * thrown error, never a silent pass/fail guess.
147
+ *
148
+ * `registry` defaults to the built-in evaluators; a caller may pass a
149
+ * different registry (e.g. in tests, or once more evaluators exist).
150
+ */
151
+ export declare function evaluateInvariant(input: InvariantEvaluationInput, registry?: Readonly<Record<string, InvariantEvaluator>>): InvariantEvaluation;
152
+ //# sourceMappingURL=evaluate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../src/evaluate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AACH,OAAO,EAAoC,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAK3D,MAAM,MAAM,yBAAyB,GAAG,UAAU,GAAG,cAAc,GAAG,cAAc,CAAC;AAErF;;GAEG;AACH,eAAO,MAAM,sBAAsB,8BAA+B,CAAC;AAEnE;;GAEG;AACH,eAAO,MAAM,4BAA4B,6BAA8B,CAAC;AAExE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,mCAAoC,CAAC;AAEpE,0FAA0F;AAC1F,eAAO,MAAM,aAAa,cAAc,CAAC;AAEzC,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,yBAAyB,CAAC;IAClC;;;OAGG;IACH,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,iFAAiF;IACjF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qFAAqF;IACrF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,wBAAwB;IACvC,eAAe,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAClD,SAAS,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IACtC,sEAAsE;IACtE,OAAO,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,wBAAwB,KAAK,mBAAmB,CAAC;AA0I1F;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,kBAsGpC,CAAC;AAIF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,sBAAsB,EAAE,kBAgHpC,CAAC;AAOF;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,wBAAwB,EAC/B,QAAQ,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAsB,GAC1E,mBAAmB,CAMrB"}
@@ -0,0 +1,394 @@
1
+ /**
2
+ * Security invariant evaluation (EL-050), rewritten for audit findings P3
3
+ * and P11.
4
+ *
5
+ * ## What was wrong
6
+ *
7
+ * The first implementation asked one question: "does *any* `native-transfer`
8
+ * effect anywhere in this side's `effects.json` move at least
9
+ * `minimumDelta` wei?" That is not the declared invariant, and it is wrong
10
+ * in both directions:
11
+ *
12
+ * - `extractEffects` deliberately walks every forge trace stage, so the
13
+ * demo fixture's own `setUp()` deposit — 10 ether from the victim *into*
14
+ * the vault, a perfectly legitimate act — satisfied it. The baseline gate
15
+ * could report "the exploit reproduced" on evidence that was not the
16
+ * exploit, and the patched replay could fail for the same reason.
17
+ * - It ignored direction entirely. Money moving *into* the vault counted the
18
+ * same as money being drained *out of* it.
19
+ * - `expectedExploit.asset` was read by no code at all.
20
+ *
21
+ * ## What it asks now
22
+ *
23
+ * The declared invariant is "no account may withdraw more value than it
24
+ * deposited". Expressed over the effects this pipeline can actually observe,
25
+ * that is a **directional, pairwise** question about the **exploit stage
26
+ * only**, asked in two steps:
27
+ *
28
+ * 1. **Find the parties that lost custody of value.** An eligible
29
+ * counterparty is an address that received value at some point in the run
30
+ * (any stage, so the vault's `setUp()` funding counts) *and* ended the
31
+ * exploit stage down by at least `minimumDelta`.
32
+ * 2. **Ask who took value out of one of them.** For each such counterparty,
33
+ * find an address whose value received *from that counterparty* exceeds
34
+ * what it sent *to that counterparty* by `minimumDelta` or more.
35
+ *
36
+ * The inbound requirement in step 1 is load-bearing, and getting it wrong
37
+ * was a real defect (review finding B1). A Foundry harness funds the
38
+ * attacker and never receives anything back: it is a pure payer, not a party
39
+ * that lost value it was holding. A global per-address net counts that
40
+ * funding as exploit proceeds, so on the *patched* demo commit — where the
41
+ * attacker deposits 1 ETH, is blocked from re-entering, and withdraws its
42
+ * own 1 ETH back — the attacker looked +1 ETH ahead and a working patch
43
+ * failed `exact-replay`. Requiring the counterparty to have held value, and
44
+ * measuring gain pairwise against it, reads that run correctly as a net of
45
+ * zero. This is a structural property of the flows, never a hardcoded
46
+ * address, so it holds for any fixture.
47
+ *
48
+ * Four properties follow directly, and each is pinned by a test — the
49
+ * last two against real Foundry output from the pinned commits, because
50
+ * synthetic traces did not expose the defect above:
51
+ *
52
+ * - **Setup cannot satisfy it.** `Deployment` and `Setup` effects are
53
+ * excluded by stage, so the fixture's seed deposit is not
54
+ * evidence of an exploit.
55
+ * - **Direction is checked.** A deposit is an outflow for the depositor and
56
+ * nets against anything it later withdraws.
57
+ * - **Recovering your own deposit is not exploitation.** Withdrawing exactly
58
+ * what you put in nets to zero against that counterparty.
59
+ * - **A violation names both sides.** The account that gained and the party
60
+ * it drained, with the pairwise amount.
61
+ *
62
+ * ## What it refuses to answer (P11)
63
+ *
64
+ * Each evaluator is honest about its own reach:
65
+ * - `vault-solvency-evaluator` supports exactly `native-transfer`.
66
+ * - `token-solvency-evaluator` supports `token-transfer` restricted to
67
+ * standard `ERC20` (refuses `ERC721` and `ERC1155`).
68
+ * Any manifest declaring an effect type outside the supported set, or an
69
+ * `asset` the evaluator cannot tie to the declared effect type, returns
70
+ * `inconclusive` rather than a verdict.
71
+ *
72
+ * `inconclusive` is the safe direction in both gates that consume this: the
73
+ * baseline gate reports `inconclusive` (never a false "reproduced"), and the
74
+ * exact-replay gate reports `inconclusive` rather than a false `pass`. An
75
+ * effect class we cannot see can therefore never become a green gate.
76
+ */
77
+ import { parseEffectId } from "@exploitlens/effects";
78
+ /**
79
+ * Effect classes `vault-solvency-evaluator` can reason about.
80
+ */
81
+ export const SUPPORTED_EFFECT_TYPES = ["native-transfer"];
82
+ /**
83
+ * Effect classes `token-solvency-evaluator` can reason about.
84
+ */
85
+ export const TOKEN_SUPPORTED_EFFECT_TYPES = ["token-transfer"];
86
+ /**
87
+ * Asset names accepted alongside `effectType: "native-transfer"`. A native
88
+ * transfer *is* the chain's native currency, so naming anything else means
89
+ * the manifest and the effect type disagree.
90
+ */
91
+ export const NATIVE_ASSET_NAMES = ["ETH", "WEI", "NATIVE"];
92
+ /** The forge trace stage that carries the exploit itself, as opposed to fixture setup. */
93
+ export const EXPLOIT_STAGE = "Execution";
94
+ function notViolated(reason) {
95
+ return { status: "not-violated", violatingEffectIds: [], reasons: [reason] };
96
+ }
97
+ function inconclusive(reason) {
98
+ return { status: "inconclusive", violatingEffectIds: [], reasons: [reason] };
99
+ }
100
+ /**
101
+ * Sums native value per address and per directed pair, restricted to
102
+ * `stage`. An effect whose id carries no parseable stage is skipped.
103
+ */
104
+ function buildNativeFlowLedger(effects, stage) {
105
+ const netByAddress = new Map();
106
+ const receivedInboundAnyStage = new Set();
107
+ const sent = new Map();
108
+ const effectsByAddress = new Map();
109
+ let consideredEffects = 0;
110
+ const credit = (address, amount, effect) => {
111
+ netByAddress.set(address, (netByAddress.get(address) ?? 0n) + amount);
112
+ const list = effectsByAddress.get(address) ?? [];
113
+ list.push(effect);
114
+ effectsByAddress.set(address, list);
115
+ };
116
+ for (const effect of effects.effects) {
117
+ if (effect.type !== "native-transfer")
118
+ continue;
119
+ const parsed = parseEffectId(effect.id);
120
+ if (!parsed)
121
+ continue;
122
+ const amount = BigInt(effect.amountWei);
123
+ if (amount === 0n)
124
+ continue;
125
+ const from = effect.from.toLowerCase();
126
+ const to = effect.to.toLowerCase();
127
+ // Custody spans every stage; see `receivedInboundAnyStage`.
128
+ receivedInboundAnyStage.add(to);
129
+ if (parsed.stage !== stage)
130
+ continue;
131
+ consideredEffects += 1;
132
+ // A self-transfer nets to zero by construction; recording both sides
133
+ // keeps that true without a special case.
134
+ credit(to, amount, effect);
135
+ credit(from, -amount, effect);
136
+ const edges = sent.get(from) ?? new Map();
137
+ edges.set(to, (edges.get(to) ?? 0n) + amount);
138
+ sent.set(from, edges);
139
+ }
140
+ return { netByAddress, receivedInboundAnyStage, sent, effectsByAddress, consideredEffects };
141
+ }
142
+ /**
143
+ * Sums ERC-20 token value per address and per directed pair, restricted to
144
+ * `stage` and optionally scoped to `scopedToken`.
145
+ */
146
+ function buildTokenFlowLedger(effects, stage, scopedToken) {
147
+ const netByAddress = new Map();
148
+ const receivedInboundAnyStage = new Set();
149
+ const sent = new Map();
150
+ const effectsByAddress = new Map();
151
+ let consideredEffects = 0;
152
+ const credit = (address, amount, effect) => {
153
+ netByAddress.set(address, (netByAddress.get(address) ?? 0n) + amount);
154
+ const list = effectsByAddress.get(address) ?? [];
155
+ list.push(effect);
156
+ effectsByAddress.set(address, list);
157
+ };
158
+ for (const effect of effects.effects) {
159
+ if (effect.type !== "token-transfer")
160
+ continue;
161
+ if (effect.standard !== "ERC20")
162
+ continue;
163
+ if (scopedToken !== undefined && effect.token.toLowerCase() !== scopedToken)
164
+ continue;
165
+ const parsed = parseEffectId(effect.id);
166
+ if (!parsed)
167
+ continue;
168
+ const amount = BigInt(effect.amount);
169
+ if (amount === 0n)
170
+ continue;
171
+ const from = effect.from.toLowerCase();
172
+ const to = effect.to.toLowerCase();
173
+ // Custody spans every stage
174
+ receivedInboundAnyStage.add(to);
175
+ if (parsed.stage !== stage)
176
+ continue;
177
+ consideredEffects += 1;
178
+ credit(to, amount, effect);
179
+ credit(from, -amount, effect);
180
+ const edges = sent.get(from) ?? new Map();
181
+ edges.set(to, (edges.get(to) ?? 0n) + amount);
182
+ sent.set(from, edges);
183
+ }
184
+ return { netByAddress, receivedInboundAnyStage, sent, effectsByAddress, consideredEffects };
185
+ }
186
+ /** Value `a` received from `b` minus value `a` sent to `b`, over the stage. */
187
+ function pairwiseNet(ledger, a, b) {
188
+ const received = ledger.sent.get(b)?.get(a) ?? 0n;
189
+ const paid = ledger.sent.get(a)?.get(b) ?? 0n;
190
+ return received - paid;
191
+ }
192
+ /**
193
+ * The evaluator for native ETH vault solvency
194
+ * (`invariant.evaluator: "vault-solvency-evaluator"`).
195
+ */
196
+ export const vaultSolvencyEvaluator = ({ expectedExploit, effects }) => {
197
+ if (!SUPPORTED_EFFECT_TYPES.includes(expectedExploit.effectType)) {
198
+ return inconclusive(`this evaluator can only observe ${SUPPORTED_EFFECT_TYPES.join(", ")} effects, and the manifest ` +
199
+ `declares "${expectedExploit.effectType}" — no verdict can be reached from the evidence ` +
200
+ "this pipeline captures");
201
+ }
202
+ if (expectedExploit.asset !== undefined &&
203
+ !NATIVE_ASSET_NAMES.includes(expectedExploit.asset.toUpperCase())) {
204
+ return inconclusive(`expectedExploit.asset "${expectedExploit.asset}" is not the native asset, but ` +
205
+ `expectedExploit.effectType is "native-transfer"; the manifest is internally inconsistent`);
206
+ }
207
+ if (expectedExploit.minimumDelta === undefined) {
208
+ return inconclusive("expectedExploit.minimumDelta is required to decide whether a net gain constitutes a " +
209
+ "violation; without a threshold every nonzero transfer would qualify");
210
+ }
211
+ let minimumDelta;
212
+ try {
213
+ minimumDelta = BigInt(expectedExploit.minimumDelta);
214
+ }
215
+ catch {
216
+ return inconclusive(`expectedExploit.minimumDelta "${expectedExploit.minimumDelta}" is not a valid integer`);
217
+ }
218
+ if (minimumDelta <= 0n) {
219
+ return inconclusive("expectedExploit.minimumDelta must be greater than zero");
220
+ }
221
+ const ledger = buildNativeFlowLedger(effects, EXPLOIT_STAGE);
222
+ if (ledger.consideredEffects === 0) {
223
+ return notViolated(`no native-transfer effect occurred during the ${EXPLOIT_STAGE} stage of ` +
224
+ `${effects.side}/effects.json (setup and deployment transfers are excluded by design)`);
225
+ }
226
+ const counterparties = [...ledger.netByAddress.entries()]
227
+ .filter(([address, net]) => ledger.receivedInboundAnyStage.has(address) && -net >= minimumDelta)
228
+ // Largest loss first; ties broken by address for a deterministic verdict.
229
+ .sort((a, b) => (a[1] === b[1] ? a[0].localeCompare(b[0]) : a[1] > b[1] ? 1 : -1));
230
+ if (counterparties.length === 0) {
231
+ return notViolated(`no account that received value during the ${EXPLOIT_STAGE} stage of ${effects.side}/` +
232
+ `effects.json ended it down by ${minimumDelta} wei or more; nothing was drained from a ` +
233
+ "party holding value (transfers into the run from the test harness are not losses)");
234
+ }
235
+ for (const [counterparty, counterpartyNet] of counterparties) {
236
+ const candidates = [...ledger.netByAddress.keys()]
237
+ .filter((address) => address !== counterparty)
238
+ .map((address) => [address, pairwiseNet(ledger, address, counterparty)])
239
+ .filter(([, net]) => net >= minimumDelta)
240
+ .sort((a, b) => (b[1] === a[1] ? a[0].localeCompare(b[0]) : b[1] > a[1] ? 1 : -1));
241
+ const top = candidates[0];
242
+ if (!top)
243
+ continue;
244
+ const [beneficiary, netGain] = top;
245
+ // Cite only the transfers between the two named parties.
246
+ const violatingEffectIds = (ledger.effectsByAddress.get(beneficiary) ?? [])
247
+ .filter((effect) => {
248
+ const from = effect.from.toLowerCase();
249
+ const to = effect.to.toLowerCase();
250
+ return ((from === counterparty && to === beneficiary) ||
251
+ (from === beneficiary && to === counterparty));
252
+ })
253
+ .map((effect) => effect.id);
254
+ return {
255
+ status: "violated",
256
+ violatingEffectIds,
257
+ beneficiary,
258
+ counterparty,
259
+ netGainAmount: netGain.toString(10),
260
+ reasons: [
261
+ `account ${beneficiary} took ${netGain} wei more out of ${counterparty} than it put in ` +
262
+ `during the ${EXPLOIT_STAGE} stage of ${effects.side}/effects.json, at or above the ` +
263
+ `declared minimumDelta of ${minimumDelta} wei; ${counterparty} ended the stage down ` +
264
+ `${-counterpartyNet} wei overall`,
265
+ ],
266
+ };
267
+ }
268
+ return notViolated(`no account withdrew at least ${minimumDelta} wei more than it deposited from any party that ` +
269
+ `lost value during the ${EXPLOIT_STAGE} stage of ${effects.side}/effects.json`);
270
+ };
271
+ const HEX_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
272
+ /**
273
+ * Evaluator for ERC-20 token solvency
274
+ * (`invariant.evaluator: "token-solvency-evaluator"`).
275
+ *
276
+ * Follows the same custody-scoping, stage exclusion, and directional pairwise
277
+ * accounting principles as `vaultSolvencyEvaluator`.
278
+ *
279
+ * Restricted strictly to standard "ERC20" token transfers; fails closed
280
+ * (`inconclusive`) if non-ERC20 token-transfer standards (such as ERC721 or
281
+ * ERC1155) are encountered.
282
+ *
283
+ * If `expectedExploit.asset` is specified, it must be a valid 20-byte 0x-prefixed
284
+ * hex contract address to scope ledger accounting to that single token.
285
+ *
286
+ * LIMITATION: If `expectedExploit.asset` is omitted, all ERC20 token-transfer
287
+ * effects in the exploit stage are aggregated together. This is valid only for
288
+ * single-token fixtures (like STAX LP staking).
289
+ */
290
+ export const tokenSolvencyEvaluator = ({ expectedExploit, effects }) => {
291
+ if (!TOKEN_SUPPORTED_EFFECT_TYPES.includes(expectedExploit.effectType)) {
292
+ return inconclusive(`this evaluator can only observe ${TOKEN_SUPPORTED_EFFECT_TYPES.join(", ")} effects, and the manifest ` +
293
+ `declares "${expectedExploit.effectType}" — no verdict can be reached from the evidence ` +
294
+ "this pipeline captures");
295
+ }
296
+ let scopedToken;
297
+ if (expectedExploit.asset !== undefined) {
298
+ if (!HEX_ADDRESS_REGEX.test(expectedExploit.asset)) {
299
+ return inconclusive(`expectedExploit.asset "${expectedExploit.asset}" is not a valid 20-byte 0x-prefixed token contract address; ` +
300
+ `for token-transfer effects, asset must be a token address if specified`);
301
+ }
302
+ scopedToken = expectedExploit.asset.toLowerCase();
303
+ }
304
+ if (expectedExploit.minimumDelta === undefined) {
305
+ return inconclusive("expectedExploit.minimumDelta is required to decide whether a net gain constitutes a " +
306
+ "violation; without a threshold every nonzero transfer would qualify");
307
+ }
308
+ let minimumDelta;
309
+ try {
310
+ minimumDelta = BigInt(expectedExploit.minimumDelta);
311
+ }
312
+ catch {
313
+ return inconclusive(`expectedExploit.minimumDelta "${expectedExploit.minimumDelta}" is not a valid integer`);
314
+ }
315
+ if (minimumDelta <= 0n) {
316
+ return inconclusive("expectedExploit.minimumDelta must be greater than zero");
317
+ }
318
+ // Fail closed if any token-transfer effect uses a non-ERC20 standard (ERC721, ERC1155)
319
+ for (const effect of effects.effects) {
320
+ if (effect.type === "token-transfer" && effect.standard !== "ERC20") {
321
+ if (scopedToken === undefined || effect.token.toLowerCase() === scopedToken) {
322
+ return inconclusive(`token-solvency-evaluator only supports standard "ERC20" token transfers, but encountered standard "${effect.standard}" in effect "${effect.id}"`);
323
+ }
324
+ }
325
+ }
326
+ const ledger = buildTokenFlowLedger(effects, EXPLOIT_STAGE, scopedToken);
327
+ if (ledger.consideredEffects === 0) {
328
+ return notViolated(`no token-transfer effect occurred during the ${EXPLOIT_STAGE} stage of ` +
329
+ `${effects.side}/effects.json (setup and deployment transfers are excluded by design)`);
330
+ }
331
+ const counterparties = [...ledger.netByAddress.entries()]
332
+ .filter(([address, net]) => ledger.receivedInboundAnyStage.has(address) && -net >= minimumDelta)
333
+ .sort((a, b) => (a[1] === b[1] ? a[0].localeCompare(b[0]) : a[1] > b[1] ? 1 : -1));
334
+ if (counterparties.length === 0) {
335
+ return notViolated(`no account that received value during the ${EXPLOIT_STAGE} stage of ${effects.side}/` +
336
+ `effects.json ended it down by ${minimumDelta} tokens or more; nothing was drained from a ` +
337
+ "party holding value (transfers into the run from the test harness are not losses)");
338
+ }
339
+ for (const [counterparty, counterpartyNet] of counterparties) {
340
+ const candidates = [...ledger.netByAddress.keys()]
341
+ .filter((address) => address !== counterparty)
342
+ .map((address) => [address, pairwiseNet(ledger, address, counterparty)])
343
+ .filter(([, net]) => net >= minimumDelta)
344
+ .sort((a, b) => (b[1] === a[1] ? a[0].localeCompare(b[0]) : b[1] > a[1] ? 1 : -1));
345
+ const top = candidates[0];
346
+ if (!top)
347
+ continue;
348
+ const [beneficiary, netGain] = top;
349
+ const violatingEffectIds = (ledger.effectsByAddress.get(beneficiary) ?? [])
350
+ .filter((effect) => {
351
+ const from = effect.from.toLowerCase();
352
+ const to = effect.to.toLowerCase();
353
+ return ((from === counterparty && to === beneficiary) ||
354
+ (from === beneficiary && to === counterparty));
355
+ })
356
+ .map((effect) => effect.id);
357
+ return {
358
+ status: "violated",
359
+ violatingEffectIds,
360
+ beneficiary,
361
+ counterparty,
362
+ netGainAmount: netGain.toString(10),
363
+ reasons: [
364
+ `account ${beneficiary} took ${netGain} tokens more out of ${counterparty} than it put in ` +
365
+ `during the ${EXPLOIT_STAGE} stage of ${effects.side}/effects.json, at or above the ` +
366
+ `declared minimumDelta of ${minimumDelta}; ${counterparty} ended the stage down ` +
367
+ `${-counterpartyNet} tokens overall`,
368
+ ],
369
+ };
370
+ }
371
+ return notViolated(`no account withdrew at least ${minimumDelta} tokens more than it deposited from any party that ` +
372
+ `lost value during the ${EXPLOIT_STAGE} stage of ${effects.side}/effects.json`);
373
+ };
374
+ const BUILTIN_EVALUATORS = {
375
+ "vault-solvency-evaluator": vaultSolvencyEvaluator,
376
+ "token-solvency-evaluator": tokenSolvencyEvaluator,
377
+ };
378
+ /**
379
+ * Evaluates `input.invariant` against `input.effects` using the registry
380
+ * entry named by `input.invariant.evaluator`. Any evaluator id not in the
381
+ * registry fails closed as an explicit `"inconclusive"` result — never a
382
+ * thrown error, never a silent pass/fail guess.
383
+ *
384
+ * `registry` defaults to the built-in evaluators; a caller may pass a
385
+ * different registry (e.g. in tests, or once more evaluators exist).
386
+ */
387
+ export function evaluateInvariant(input, registry = BUILTIN_EVALUATORS) {
388
+ const evaluator = registry[input.invariant.evaluator];
389
+ if (!evaluator) {
390
+ return inconclusive(`unsupported invariant evaluator "${input.invariant.evaluator}"`);
391
+ }
392
+ return evaluator(input);
393
+ }
394
+ //# sourceMappingURL=evaluate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../src/evaluate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AACH,OAAO,EAAE,aAAa,EAAuC,MAAM,sBAAsB,CAAC;AAQ1F;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,iBAAiB,CAAU,CAAC;AAEnE;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,gBAAgB,CAAU,CAAC;AAExE;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAU,CAAC;AAEpE,0FAA0F;AAC1F,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC;AA2BzC,SAAS,WAAW,CAAC,MAAc;IACjC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,kBAAkB,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;AAC/E,CAAC;AAED,SAAS,YAAY,CAAC,MAAc;IAClC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,kBAAkB,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;AAC/E,CAAC;AAqBD;;;GAGG;AACH,S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ACL,MAAM,EAAE,UAAU;YAClB,kBAAkB;YAClB,WAAW;YACX,YAAY;YACZ,aAAa,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YACnC,OAAO,EAAE;gBACP,WAAW,WAAW,SAAS,OAAO,uBAAuB,YAAY,kBAAkB;oBACzF,cAAc,aAAa,aAAa,OAAO,CAAC,IAAI,iCAAiC;oBACrF,4BAA4B,YAAY,KAAK,YAAY,wBAAwB;oBACjF,GAAG,CAAC,eAAe,iBAAiB;aACvC;SACF,CAAC;IACJ,CAAC;IAED,OAAO,WAAW,CAChB,gCAAgC,YAAY,qDAAqD;QAC/F,yBAAyB,aAAa,aAAa,OAAO,CAAC,IAAI,eAAe,CACjF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAiD;IACvE,0BAA0B,EAAE,sBAAsB;IAClD,0BAA0B,EAAE,sBAAsB;CACnD,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAA+B,EAC/B,WAAyD,kBAAkB;IAE3E,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACtD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,YAAY,CAAC,oCAAoC,KAAK,CAAC,SAAS,CAAC,SAAS,GAAG,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Four-gate verdict engine (EL-051).
3
+ *
4
+ * Combines `EL-050`'s invariant evaluation with the patched control run's
5
+ * outcome into a `GateReport` carrying exactly the four gates
6
+ * `GateNameSchema` defines, always in that fixed order (`baseline`,
7
+ * `exact-replay`, `legitimate-control`, `neighborhood`) — see `schema.ts`'s
8
+ * `GateReportSchema` doc.
9
+ *
10
+ * - `baseline`: did the vulnerable-side run reproduce the declared exploit?
11
+ * This mirrors `packages/executor`'s own `"invalid-baseline"` concept
12
+ * (EL-023) — if the vulnerable side does not show the violation, the
13
+ * entire run's premise is broken, so this gate is `fail` (or
14
+ * `inconclusive` if evaluation itself could not run), never a false
15
+ * `pass`.
16
+ * - `exact-replay`: did the patched-side exploit replay NOT reproduce the
17
+ * effect? `pass` means "not violated" (the fix works), `fail` means
18
+ * "still violated" (the fix doesn't work).
19
+ * - `legitimate-control`: did the patched control run still succeed?
20
+ * - `neighborhood`: computed by `computeNeighborhoodGate` (EL-073) —
21
+ * `computeGateReport`'s `variantLedger` input is the one thing this gate
22
+ * depends on; every other gate above is independent of it. Without a
23
+ * ledger (the default, for any caller that hasn't wired
24
+ * `@exploitlens/variants`'s ledger through yet — see `ComputeGateReportInput`)
25
+ * it still unconditionally reports `inconclusive`, implementing the task
26
+ * doc's rule "Do not issue strong success before variants complete." With
27
+ * a ledger, it reports `pass` only when at least `NEIGHBORHOOD_MINIMUM_VALID_CANDIDATES`
28
+ * candidates validated on the vulnerable commit AND every one of them held
29
+ * on the patched replay; `fail` if any valid candidate's patched replay
30
+ * still reproduced the exploit; `inconclusive` otherwise (too few valid
31
+ * candidates, or any valid candidate's patched replay itself inconclusive).
32
+ *
33
+ * `hasStrongSuccess` is the minimal "combine the four gates' states" rollup
34
+ * this task calls for: it is `true` only when every gate is `pass`. It
35
+ * deliberately does not invent a fuller verdict taxonomy (e.g. distinct
36
+ * "invalid" vs "regression" labels) — that vocabulary belongs to whichever
37
+ * task builds the receipt/UI layer (EL-052, EL-061) and risks colliding
38
+ * with their design. Without a `variantLedger`, `neighborhood` is
39
+ * unconditionally `inconclusive`, so `hasStrongSuccess` can never be `true`
40
+ * for a caller that hasn't wired one in — that remains exactly the required
41
+ * pre-Phase-7 behavior for those callers.
42
+ */
43
+ import type { EffectsFile } from "@exploitlens/effects";
44
+ import { type HashedRunRecord } from "@exploitlens/executor";
45
+ import type { ExploitBundle } from "@exploitlens/manifest";
46
+ import type { z } from "zod";
47
+ import { type GateStatusSchema, type GateReport, type GateResult } from "./schema.js";
48
+ type GateStatus = z.infer<typeof GateStatusSchema>;
49
+ /**
50
+ * Structurally compatible with `@exploitlens/variants`'s `VariantLedger`
51
+ * (duck-typed on purpose, not imported): `@exploitlens/variants` already
52
+ * depends on `@exploitlens/invariants` (for `evaluateInvariant`, see
53
+ * `run.ts`), so importing it back here would invert that edge into a cycle.
54
+ * A `VariantLedger` value satisfies this interface without any conversion.
55
+ */
56
+ export interface NeighborhoodVariantLedger {
57
+ validDenominator: number;
58
+ results: ReadonlyArray<{
59
+ vulnerableValidity: "valid" | "invalid";
60
+ patchedStatus?: GateStatus;
61
+ }>;
62
+ }
63
+ /**
64
+ * The Phase 7 exit gate's own bar ("at least six valid vulnerable variants
65
+ * have complete patched results and correct receipt accounting" — see
66
+ * `docs/04_ORDERED_DEVELOPMENT_TASKS.md`'s Phase 7 entry): reused directly
67
+ * as this gate's own pass threshold rather than inventing a second number,
68
+ * so "the neighborhood gate passes" and "the exit gate is met" mean the same
69
+ * thing.
70
+ */
71
+ export declare const NEIGHBORHOOD_MINIMUM_VALID_CANDIDATES = 6;
72
+ export interface ComputeGateReportInput {
73
+ caseId: string;
74
+ expectedExploit: ExploitBundle["expectedExploit"];
75
+ invariant: ExploitBundle["invariant"];
76
+ /** `vulnerable/effects.json`. */
77
+ vulnerableEffects: EffectsFile;
78
+ /** `patched/effects.json`. */
79
+ patchedEffects: EffectsFile;
80
+ /** `patched/control-result.json`, written by `writePerSideArtifacts`. */
81
+ patchedControlResult: HashedRunRecord;
82
+ /**
83
+ * `variants/ledger.json`'s contents (EL-070-073). Optional and
84
+ * defaulted to `undefined` so every caller that predates the variant
85
+ * engine (e.g. already-merged tests) keeps getting today's unconditional
86
+ * `inconclusive` neighborhood gate without passing anything new.
87
+ */
88
+ variantLedger?: NeighborhoodVariantLedger;
89
+ }
90
+ /**
91
+ * See module doc for the mapping this implements. `ledger` is `undefined`
92
+ * for any caller that hasn't wired `@exploitlens/variants`'s ledger through
93
+ * `computeGateReport` yet, which reproduces this gate's pre-EL-073 behavior
94
+ * exactly (same status, same explanation substring already pinned by
95
+ * `gates.test.ts`'s "always reports neighborhood as inconclusive" case).
96
+ */
97
+ /**
98
+ * The neighborhood gate, exported so an independent reader can re-derive it.
99
+ *
100
+ * `computeGateReport` calls this internally; `@exploitlens/verifier` calls it
101
+ * again from the ledger it loaded off disk, so a receipt claiming a
102
+ * neighborhood verdict its own ledger does not support is caught. Exporting
103
+ * an existing function changes no gate semantics — it makes the existing
104
+ * semantics checkable from outside.
105
+ */
106
+ export declare function computeNeighborhoodGate(ledger: NeighborhoodVariantLedger | undefined): GateResult;
107
+ /**
108
+ * Assembles all four gates, in fixed order, from one run's evidence.
109
+ * `neighborhood` is `inconclusive` when `input.variantLedger` is omitted
110
+ * (see module doc) — it is still an explicit entry in `gates`, never
111
+ * omitted, regardless of whether a ledger was supplied.
112
+ */
113
+ export declare function computeGateReport(input: ComputeGateReportInput): GateReport;
114
+ /**
115
+ * `true` only when every gate in `report.gates` has `status: "pass"`. This
116
+ * is the sole rollup this package computes; see module doc for why it stays
117
+ * this narrow.
118
+ */
119
+ export declare function hasStrongSuccess(report: GateReport): boolean;
120
+ export {};
121
+ //# sourceMappingURL=gates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gates.d.ts","sourceRoot":"","sources":["../src/gates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAEtF,KAAK,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACxC,gBAAgB,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,aAAa,CAAC;QACrB,kBAAkB,EAAE,OAAO,GAAG,SAAS,CAAC;QACxC,aAAa,CAAC,EAAE,UAAU,CAAC;KAC5B,CAAC,CAAC;CACJ;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,qCAAqC,IAAI,CAAC;AAEvD,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAClD,SAAS,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IACtC,iCAAiC;IACjC,iBAAiB,EAAE,WAAW,CAAC;IAC/B,8BAA8B;IAC9B,cAAc,EAAE,WAAW,CAAC;IAC5B,yEAAyE;IACzE,oBAAoB,EAAE,eAAe,CAAC;IACtC;;;;;OAKG;IACH,aAAa,CAAC,EAAE,yBAAyB,CAAC;CAC3C;AA6ID;;;;;;GAMG;AACH;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,yBAAyB,GAAG,SAAS,GAAG,UAAU,CAyEjG;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,UAAU,CAW3E;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAE5D"}
package/dist/gates.js ADDED
@@ -0,0 +1,237 @@
1
+ import { runPassed } from "@exploitlens/executor";
2
+ import { evaluateInvariant } from "./evaluate.js";
3
+ import {} from "./schema.js";
4
+ /**
5
+ * The Phase 7 exit gate's own bar ("at least six valid vulnerable variants
6
+ * have complete patched results and correct receipt accounting" — see
7
+ * `docs/04_ORDERED_DEVELOPMENT_TASKS.md`'s Phase 7 entry): reused directly
8
+ * as this gate's own pass threshold rather than inventing a second number,
9
+ * so "the neighborhood gate passes" and "the exit gate is met" mean the same
10
+ * thing.
11
+ */
12
+ export const NEIGHBORHOOD_MINIMUM_VALID_CANDIDATES = 6;
13
+ function computeBaselineGate(input) {
14
+ const evaluation = evaluateInvariant({
15
+ expectedExploit: input.expectedExploit,
16
+ invariant: input.invariant,
17
+ effects: input.vulnerableEffects,
18
+ });
19
+ if (evaluation.status === "inconclusive") {
20
+ return {
21
+ gate: "baseline",
22
+ status: "inconclusive",
23
+ evidenceRefs: ["vulnerable/effects.json"],
24
+ explanation: `could not evaluate the declared invariant against the baseline run: ${evaluation.reasons.join("; ")}`,
25
+ };
26
+ }
27
+ if (evaluation.status === "violated") {
28
+ return {
29
+ gate: "baseline",
30
+ status: "pass",
31
+ evidenceRefs: [
32
+ "vulnerable/effects.json",
33
+ ...evaluation.violatingEffectIds.map((id) => `vulnerable/effects.json#${id}`),
34
+ ],
35
+ explanation: "The vulnerable-side run reproduced the declared exploit effect.",
36
+ };
37
+ }
38
+ return {
39
+ gate: "baseline",
40
+ status: "fail",
41
+ evidenceRefs: ["vulnerable/effects.json"],
42
+ explanation: "The vulnerable-side run did not reproduce the declared exploit effect; the run's premise is invalid.",
43
+ };
44
+ }
45
+ function computeExactReplayGate(input) {
46
+ const evaluation = evaluateInvariant({
47
+ expectedExploit: input.expectedExploit,
48
+ invariant: input.invariant,
49
+ effects: input.patchedEffects,
50
+ });
51
+ if (evaluation.status === "inconclusive") {
52
+ return {
53
+ gate: "exact-replay",
54
+ status: "inconclusive",
55
+ evidenceRefs: ["patched/effects.json"],
56
+ explanation: `could not evaluate the declared invariant against the patched exploit replay: ${evaluation.reasons.join("; ")}`,
57
+ };
58
+ }
59
+ if (evaluation.status === "not-violated") {
60
+ return {
61
+ gate: "exact-replay",
62
+ status: "pass",
63
+ evidenceRefs: ["patched/effects.json"],
64
+ explanation: "The patched-side exploit replay did not reproduce the declared exploit effect.",
65
+ };
66
+ }
67
+ return {
68
+ gate: "exact-replay",
69
+ status: "fail",
70
+ evidenceRefs: [
71
+ "patched/effects.json",
72
+ ...evaluation.violatingEffectIds.map((id) => `patched/effects.json#${id}`),
73
+ ],
74
+ explanation: "The patched-side exploit replay still reproduced the declared exploit effect.",
75
+ };
76
+ }
77
+ /**
78
+ * The legitimate-control gate (P7).
79
+ *
80
+ * This used to read `runPassed` alone — the process exit code — which is not
81
+ * evidence that the declared control test ran. `forge test` with a
82
+ * `--match-test` that matches nothing prints "No tests found" and exits 0,
83
+ * so a control-result recording a vacuous run produced a green "the
84
+ * legitimate control path still succeeds": the single most quotable line in
85
+ * a receipt, backed by nothing.
86
+ *
87
+ * The gate now requires positive execution evidence tied to the declared
88
+ * selector. Absence of that evidence is `inconclusive`, never `pass` — a
89
+ * control run we cannot prove happened is not a control run that failed, but
90
+ * it is certainly not one that succeeded.
91
+ */
92
+ function computeLegitimateControlGate(input) {
93
+ const record = input.patchedControlResult;
94
+ const evidenceRefs = ["patched/control-result.json"];
95
+ const outcome = record.testOutcome;
96
+ if (!outcome) {
97
+ return {
98
+ gate: "legitimate-control",
99
+ status: "inconclusive",
100
+ evidenceRefs,
101
+ explanation: `The patched legitimate-control run carries no execution evidence for selector ` +
102
+ `"${record.testSelector}" (process outcome: "${record.result.outcome.kind}"), so it cannot ` +
103
+ "be shown that the control test ran at all.",
104
+ };
105
+ }
106
+ if (outcome.matchedTests.length === 0) {
107
+ return {
108
+ gate: "legitimate-control",
109
+ status: "fail",
110
+ evidenceRefs,
111
+ explanation: `The patched legitimate-control run matched no test for selector "${record.testSelector}" ` +
112
+ `in "${record.testPath}". forge exits zero when nothing matches, so this is a vacuous run, ` +
113
+ "not a passing control path.",
114
+ };
115
+ }
116
+ if (!runPassed(record) || !outcome.allPassed) {
117
+ return {
118
+ gate: "legitimate-control",
119
+ status: "fail",
120
+ evidenceRefs,
121
+ explanation: `The patched legitimate-control run did not succeed (process outcome: ` +
122
+ `"${record.result.outcome.kind}"; matched ${outcome.matchedTests.length} test(s) with ` +
123
+ `status ${outcome.statuses.join(", ")}).`,
124
+ };
125
+ }
126
+ return {
127
+ gate: "legitimate-control",
128
+ status: "pass",
129
+ evidenceRefs,
130
+ explanation: `The patched legitimate-control run executed ${outcome.matchedTests.join(", ")} for selector ` +
131
+ `"${record.testSelector}" and every matched test passed.`,
132
+ };
133
+ }
134
+ /**
135
+ * See module doc for the mapping this implements. `ledger` is `undefined`
136
+ * for any caller that hasn't wired `@exploitlens/variants`'s ledger through
137
+ * `computeGateReport` yet, which reproduces this gate's pre-EL-073 behavior
138
+ * exactly (same status, same explanation substring already pinned by
139
+ * `gates.test.ts`'s "always reports neighborhood as inconclusive" case).
140
+ */
141
+ /**
142
+ * The neighborhood gate, exported so an independent reader can re-derive it.
143
+ *
144
+ * `computeGateReport` calls this internally; `@exploitlens/verifier` calls it
145
+ * again from the ledger it loaded off disk, so a receipt claiming a
146
+ * neighborhood verdict its own ledger does not support is caught. Exporting
147
+ * an existing function changes no gate semantics — it makes the existing
148
+ * semantics checkable from outside.
149
+ */
150
+ export function computeNeighborhoodGate(ledger) {
151
+ if (!ledger) {
152
+ /*
153
+ * No ledger means the neighborhood was never run, which is a different
154
+ * fact from running it and reaching no conclusion. The status is the
155
+ * same because the gate genuinely did not reach a verdict, but the
156
+ * explanation must not imply the patch was tested against a
157
+ * neighborhood and came up short.
158
+ *
159
+ * The previous wording said the engine was "not yet implemented", which
160
+ * stopped being true once it shipped and now misleads anyone whose run
161
+ * simply had no variant overlay or had variants disabled.
162
+ */
163
+ return {
164
+ gate: "neighborhood",
165
+ status: "inconclusive",
166
+ evidenceRefs: [],
167
+ explanation: "The variant neighborhood was not run for this case, so no neighborhood " +
168
+ "evidence exists. This is not a finding about the patch.",
169
+ };
170
+ }
171
+ const evidenceRefs = ["variants/ledger.json"];
172
+ if (ledger.validDenominator < NEIGHBORHOOD_MINIMUM_VALID_CANDIDATES) {
173
+ return {
174
+ gate: "neighborhood",
175
+ status: "inconclusive",
176
+ evidenceRefs,
177
+ explanation: `only ${ledger.validDenominator} of ${ledger.results.length} candidate(s) validated on the ` +
178
+ `vulnerable commit; at least ${NEIGHBORHOOD_MINIMUM_VALID_CANDIDATES} valid candidates are ` +
179
+ `required before the neighborhood gate can report a definitive verdict.`,
180
+ };
181
+ }
182
+ const validResults = ledger.results.filter((r) => r.vulnerableValidity === "valid");
183
+ const failed = validResults.filter((r) => r.patchedStatus === "fail");
184
+ const undetermined = validResults.filter((r) => r.patchedStatus === undefined || r.patchedStatus === "inconclusive");
185
+ if (failed.length > 0) {
186
+ return {
187
+ gate: "neighborhood",
188
+ status: "fail",
189
+ evidenceRefs,
190
+ explanation: `${failed.length} of ${validResults.length} valid candidates still reproduced the declared ` +
191
+ `exploit effect on the patched replay.`,
192
+ };
193
+ }
194
+ if (undetermined.length > 0) {
195
+ return {
196
+ gate: "neighborhood",
197
+ status: "inconclusive",
198
+ evidenceRefs,
199
+ explanation: `${undetermined.length} of ${validResults.length} valid candidates have no definitive patched ` +
200
+ `replay result yet (missing or inconclusive).`,
201
+ };
202
+ }
203
+ return {
204
+ gate: "neighborhood",
205
+ status: "pass",
206
+ evidenceRefs,
207
+ explanation: `All ${validResults.length} valid candidates (of ${ledger.results.length} attempted) did not ` +
208
+ `reproduce the declared exploit effect on the patched replay.`,
209
+ };
210
+ }
211
+ /**
212
+ * Assembles all four gates, in fixed order, from one run's evidence.
213
+ * `neighborhood` is `inconclusive` when `input.variantLedger` is omitted
214
+ * (see module doc) — it is still an explicit entry in `gates`, never
215
+ * omitted, regardless of whether a ledger was supplied.
216
+ */
217
+ export function computeGateReport(input) {
218
+ return {
219
+ schemaVersion: "1.0",
220
+ caseId: input.caseId,
221
+ gates: [
222
+ computeBaselineGate(input),
223
+ computeExactReplayGate(input),
224
+ computeLegitimateControlGate(input),
225
+ computeNeighborhoodGate(input.variantLedger),
226
+ ],
227
+ };
228
+ }
229
+ /**
230
+ * `true` only when every gate in `report.gates` has `status: "pass"`. This
231
+ * is the sole rollup this package computes; see module doc for why it stays
232
+ * this narrow.
233
+ */
234
+ export function hasStrongSuccess(report) {
235
+ return report.gates.every((gate) => gate.status === "pass");
236
+ }
237
+ //# sourceMappingURL=gates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gates.js","sourceRoot":"","sources":["../src/gates.ts"],"names":[],"mappings":"AA2CA,OAAO,EAAE,SAAS,EAAwB,MAAM,uBAAuB,CAAC;AAIxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAA2D,MAAM,aAAa,CAAC;AAmBtF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAG,CAAC,CAAC;AAqBvD,SAAS,mBAAmB,CAAC,KAA6B;IACxD,MAAM,UAAU,GAAG,iBAAiB,CAAC;QACnC,eAAe,EAAE,KAAK,CAAC,eAAe;QACtC,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,OAAO,EAAE,KAAK,CAAC,iBAAiB;KACjC,CAAC,CAAC;IAEH,IAAI,UAAU,CAAC,MAAM,KAAK,cAAc,EAAE,CAAC;QACzC,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,MAAM,EAAE,cAAc;YACtB,YAAY,EAAE,CAAC,yBAAyB,CAAC;YACzC,WAAW,EAAE,uEAAuE,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;SACpH,CAAC;IACJ,CAAC;IAED,IAAI,UAAU,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QACrC,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,MAAM,EAAE,MAAM;YACd,YAAY,EAAE;gBACZ,yBAAyB;gBACzB,GAAG,UAAU,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,2BAA2B,EAAE,EAAE,CAAC;aAC9E;YACD,WAAW,EAAE,iEAAiE;SAC/E,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,MAAM,EA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;YACL,IAAI,EAAE,cAAc;YACpB,MAAM,EAAE,cAAc;YACtB,YAAY;YACZ,WAAW,EACT,GAAG,YAAY,CAAC,MAAM,OAAO,YAAY,CAAC,MAAM,+CAA+C;gBAC/F,8CAA8C;SACjD,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,cAAc;QACpB,MAAM,EAAE,MAAM;QACd,YAAY;QACZ,WAAW,EACT,OAAO,YAAY,CAAC,MAAM,yBAAyB,MAAM,CAAC,OAAO,CAAC,MAAM,sBAAsB;YAC9F,8DAA8D;KACjE,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA6B;IAC7D,OAAO;QACL,aAAa,EAAE,KAAK;QACpB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE;YACL,mBAAmB,CAAC,KAAK,CAAC;YAC1B,sBAAsB,CAAC,KAAK,CAAC;YAC7B,4BAA4B,CAAC,KAAK,CAAC;YACnC,uBAAuB,CAAC,KAAK,CAAC,aAAa,CAAC;SAC7C;KACF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAkB;IACjD,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @exploitlens/invariants
3
+ *
4
+ * Security invariant evaluation and the four-gate verdict engine.
5
+ *
6
+ * Scaffolded by EL-001. The gate result contract lands in EL-002; evaluation
7
+ * and verdict behavior land in EL-050, EL-051.
8
+ */
9
+ /** Package identity, asserted against package.json by the workspace structure test. */
10
+ export declare const PACKAGE_NAME: "@exploitlens/invariants";
11
+ /** Artifact contract version this package will read and write. */
12
+ export declare const SCHEMA_VERSION: "1.0";
13
+ export * from "./schema.js";
14
+ export * from "./evaluate.js";
15
+ export * from "./gates.js";
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,uFAAuF;AACvF,eAAO,MAAM,YAAY,EAAG,yBAAkC,CAAC;AAE/D,kEAAkE;AAClE,eAAO,MAAM,cAAc,EAAG,KAAc,CAAC;AAE7C,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @exploitlens/invariants
3
+ *
4
+ * Security invariant evaluation and the four-gate verdict engine.
5
+ *
6
+ * Scaffolded by EL-001. The gate result contract lands in EL-002; evaluation
7
+ * and verdict behavior land in EL-050, EL-051.
8
+ */
9
+ /** Package identity, asserted against package.json by the workspace structure test. */
10
+ export const PACKAGE_NAME = "@exploitlens/invariants";
11
+ /** Artifact contract version this package will read and write. */
12
+ export const SCHEMA_VERSION = "1.0";
13
+ export * from "./schema.js";
14
+ export * from "./evaluate.js";
15
+ export * from "./gates.js";
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,uFAAuF;AACvF,MAAM,CAAC,MAAM,YAAY,GAAG,yBAAkC,CAAC;AAE/D,kEAAkE;AAClE,MAAM,CAAC,MAAM,cAAc,GAAG,KAAc,CAAC;AAE7C,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The four-gate verdict vocabulary. `executor`, `variants`, and `receipt`
3
+ * all import `GateResultSchema` from here so a run's status and its final
4
+ * receipt describe gates the same way.
5
+ */
6
+ import { z } from "zod";
7
+ export declare const GateNameSchema: z.ZodEnum<{
8
+ baseline: "baseline";
9
+ "exact-replay": "exact-replay";
10
+ "legitimate-control": "legitimate-control";
11
+ neighborhood: "neighborhood";
12
+ }>;
13
+ export declare const GateStatusSchema: z.ZodEnum<{
14
+ inconclusive: "inconclusive";
15
+ pass: "pass";
16
+ fail: "fail";
17
+ }>;
18
+ export declare const GateResultSchema: z.ZodObject<{
19
+ gate: z.ZodEnum<{
20
+ baseline: "baseline";
21
+ "exact-replay": "exact-replay";
22
+ "legitimate-control": "legitimate-control";
23
+ neighborhood: "neighborhood";
24
+ }>;
25
+ status: z.ZodEnum<{
26
+ inconclusive: "inconclusive";
27
+ pass: "pass";
28
+ fail: "fail";
29
+ }>;
30
+ evidenceRefs: z.ZodArray<z.ZodString>;
31
+ explanation: z.ZodString;
32
+ }, z.core.$strip>;
33
+ export type GateResult = z.infer<typeof GateResultSchema>;
34
+ /** The `gates.json` artifact: one result per gate, in fixed gate order. */
35
+ export declare const GateReportSchema: z.ZodObject<{
36
+ schemaVersion: z.ZodLiteral<"1.0">;
37
+ caseId: z.ZodString;
38
+ gates: z.ZodArray<z.ZodObject<{
39
+ gate: z.ZodEnum<{
40
+ baseline: "baseline";
41
+ "exact-replay": "exact-replay";
42
+ "legitimate-control": "legitimate-control";
43
+ neighborhood: "neighborhood";
44
+ }>;
45
+ status: z.ZodEnum<{
46
+ inconclusive: "inconclusive";
47
+ pass: "pass";
48
+ fail: "fail";
49
+ }>;
50
+ evidenceRefs: z.ZodArray<z.ZodString>;
51
+ explanation: z.ZodString;
52
+ }, z.core.$strip>>;
53
+ }, z.core.$strip>;
54
+ export type GateReport = z.infer<typeof GateReportSchema>;
55
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,cAAc;;;;;EAKzB,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;;EAA2C,CAAC;AAEzE,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;iBAK3B,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,2EAA2E;AAC3E,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;iBAI3B,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC"}
package/dist/schema.js ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The four-gate verdict vocabulary. `executor`, `variants`, and `receipt`
3
+ * all import `GateResultSchema` from here so a run's status and its final
4
+ * receipt describe gates the same way.
5
+ */
6
+ import { z } from "zod";
7
+ export const GateNameSchema = z.enum([
8
+ "baseline",
9
+ "exact-replay",
10
+ "legitimate-control",
11
+ "neighborhood",
12
+ ]);
13
+ export const GateStatusSchema = z.enum(["pass", "fail", "inconclusive"]);
14
+ export const GateResultSchema = z.object({
15
+ gate: GateNameSchema,
16
+ status: GateStatusSchema,
17
+ evidenceRefs: z.array(z.string().min(1)),
18
+ explanation: z.string().min(1),
19
+ });
20
+ /** The `gates.json` artifact: one result per gate, in fixed gate order. */
21
+ export const GateReportSchema = z.object({
22
+ schemaVersion: z.literal("1.0"),
23
+ caseId: z.string().min(1),
24
+ gates: z.array(GateResultSchema).min(1),
25
+ });
26
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,IAAI,CAAC;IACnC,UAAU;IACV,cAAc;IACd,oBAAoB;IACpB,cAAc;CACf,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;AAEzE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,IAAI,EAAE,cAAc;IACpB,MAAM,EAAE,gBAAgB;IACxB,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACxC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAC/B,CAAC,CAAC;AAGH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IAC/B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACzB,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;CACxC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@exploitlens/invariants",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Security invariant evaluation and the four-gate verdict engine.",
5
+ "license": "MIT",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "type": "module",
10
+ "homepage": "https://github.com/solutiono1/exploitlens#readme",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/solutiono1/exploitlens.git",
14
+ "directory": "packages/invariants"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/solutiono1/exploitlens/security/advisories/new"
18
+ },
19
+ "main": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "default": "./dist/index.js"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "engines": {
31
+ "node": ">=20"
32
+ },
33
+ "scripts": {
34
+ "build": "tsc -p tsconfig.build.json",
35
+ "clean": "rimraf dist tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo",
36
+ "test": "vitest run",
37
+ "typecheck": "tsc -p tsconfig.json",
38
+ "prepublishOnly": "pnpm run clean && pnpm run build"
39
+ },
40
+ "dependencies": {
41
+ "@exploitlens/effects": "workspace:*",
42
+ "@exploitlens/executor": "workspace:*",
43
+ "@exploitlens/manifest": "workspace:*",
44
+ "zod": "^4.4.3"
45
+ }
46
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.