|
|
|
|
@@ -36,11 +36,20 @@
|
|
|
|
|
// before trusting it. A row the ROUTER reads (`routes`) gets its own boot per
|
|
|
|
|
// view, because a hostile value in it legitimately changes which view renders.
|
|
|
|
|
// Every other swept field is corrupted on the SAME boot, one boot per view per
|
|
|
|
|
// hostile slot, and that boot has to land on the view it stored — so a field
|
|
|
|
|
// that does move the routing cannot hide in the crowd, and a field that is
|
|
|
|
|
// dereferenced by any renderer reachable from a stored record turns this file
|
|
|
|
|
// red. Booting each of them separately would be about six hundred boots and
|
|
|
|
|
// half a minute; this is thirty-three.
|
|
|
|
|
// slot, and that boot has to land on the view it stored — so a field that does
|
|
|
|
|
// move the routing cannot hide in the crowd. Every swept field is driven at
|
|
|
|
|
// BOTH POLARITIES: a value nothing in src/ writes is a wrong-typed one and so
|
|
|
|
|
// always truthy, which leaves `if (!state.x) { state.y.deref() }` unentered on
|
|
|
|
|
// the very boot that corrupts x. The last slot is the falsy one for that
|
|
|
|
|
// reason, and a field that cannot be falsy after the floor says so in its row
|
|
|
|
|
// and is proven so.
|
|
|
|
|
//
|
|
|
|
|
// What that buys: a field any restorable view dereferences on that view's
|
|
|
|
|
// render turns this file red, at either polarity. What it does not buy is a
|
|
|
|
|
// MIX of polarities — one boot puts every swept field on the same slot, so a
|
|
|
|
|
// branch reached only when one swept field is truthy and another falsy is not
|
|
|
|
|
// entered. Booting every field separately at every value would be several
|
|
|
|
|
// hundred boots and most of the suite's budget; this is forty-four.
|
|
|
|
|
//
|
|
|
|
|
// The three claims this replaced, all false, all caught here by construction:
|
|
|
|
|
// rpcUrl reaching `new JsonRpcProvider()` (a synchronous throw, not a caught
|
|
|
|
|
@@ -83,6 +92,14 @@ const everyEntry = (v, fn) => Array.isArray(v) && v.every(fn);
|
|
|
|
|
// floor and the sweep is the regression guard on it.
|
|
|
|
|
const swept = (row) => row.kind === KIND.LOOSE || Boolean(row.alsoSweep);
|
|
|
|
|
|
|
|
|
|
// Every value a swept row drives through a boot: the hostile set, plus the
|
|
|
|
|
// falsy slot that gives the field its other polarity. `hostile` values are all
|
|
|
|
|
// TRUTHY by nature — a value nothing in src/ writes is a wrong-typed one, and
|
|
|
|
|
// wrong-typed values are objects, non-empty strings and non-zero numbers. A
|
|
|
|
|
// field that is only ever truthy on the boot that corrupts it cannot falsify
|
|
|
|
|
// `if (!state.x) { state.y.deref() }`, so the falsy slot is not optional.
|
|
|
|
|
const sweptValues = (row) => [...row.hostile, ...(row.falsy || [])];
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------ the table
|
|
|
|
|
//
|
|
|
|
|
// `hostile` is values a stored record can carry that nothing in src/ ever
|
|
|
|
|
@@ -92,6 +109,15 @@ const swept = (row) => row.kind === KIND.LOOSE || Boolean(row.alsoSweep);
|
|
|
|
|
// floor alone, which is pure and free. `hostileRestore` is extra values driven
|
|
|
|
|
// through the restore path only, for a value that means nothing until a
|
|
|
|
|
// particular branch's gate has let it past.
|
|
|
|
|
//
|
|
|
|
|
// `falsy` is the other POLARITY of a swept field, driven for the same reason.
|
|
|
|
|
// It is not a value src/ never writes — for three of these fields it is the
|
|
|
|
|
// DEFAULT_STATE default, which is the branch every ordinary install takes —
|
|
|
|
|
// and that is the point: without it, a dereference behind `if (!state.x)` is
|
|
|
|
|
// unreachable on the one boot that corrupts x. A swept row that cannot supply
|
|
|
|
|
// one says `neverFalsy` instead, which is proven rather than asserted: every
|
|
|
|
|
// falsy value stored under that field comes back TRUTHY from the floor, so no
|
|
|
|
|
// `!state.x` branch is reachable from a stored record at all.
|
|
|
|
|
|
|
|
|
|
const CONTRACT = [
|
|
|
|
|
{
|
|
|
|
|
@@ -266,6 +292,9 @@ const CONTRACT = [
|
|
|
|
|
// coerces. Nothing renders FROM it without RESTORABLE_VIEWS.has()
|
|
|
|
|
// first, and Set.has() answers false for any value.
|
|
|
|
|
hostile: [42, "no-such-view", { a: 1 }],
|
|
|
|
|
// `saved.currentView || null`: the falsy polarity is the popup landing
|
|
|
|
|
// on Home, which every boot in "booting onto Home" below also drives.
|
|
|
|
|
falsy: [""],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
field: "viewData",
|
|
|
|
|
@@ -278,6 +307,10 @@ const CONTRACT = [
|
|
|
|
|
// renderer something it dereferences, which is where the entries are
|
|
|
|
|
// actually decided.
|
|
|
|
|
hostile: [42, "notarecord", { a: 1 }, [1, 2]],
|
|
|
|
|
// `structuredClone(saved.viewData || {})`: the container is never falsy
|
|
|
|
|
// in state whatever was stored, so no `!state.viewData` branch exists to
|
|
|
|
|
// drive.
|
|
|
|
|
neverFalsy: true,
|
|
|
|
|
hostileRestore: [
|
|
|
|
|
// success-tx passes on `data.hash`, and renderSuccess() then calls
|
|
|
|
|
// toAddressHtml(d.to) -> addressTitle() -> address.toLowerCase().
|
|
|
|
|
@@ -357,6 +390,10 @@ const CONTRACT = [
|
|
|
|
|
// Arithmetic only: `now - (s.lastBalanceRefresh || 0)` compares false
|
|
|
|
|
// for a non-number and forces a refresh.
|
|
|
|
|
hostile: [true, "notatime", { a: 1 }],
|
|
|
|
|
// `|| 0` collapses every falsy stored value to 0, so 0 IS the whole
|
|
|
|
|
// falsy polarity of this field — and it is the DEFAULT_STATE default,
|
|
|
|
|
// the value a profile carries until its first refresh lands.
|
|
|
|
|
falsy: [0],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
field: "tokenHolderCache",
|
|
|
|
|
@@ -366,6 +403,8 @@ const CONTRACT = [
|
|
|
|
|
// src/shared/state.js, which are safe for any value, and otherwise
|
|
|
|
|
// only reset wholesale in src/shared/chainSwitchFields.js.
|
|
|
|
|
hostile: [42, "notarecord", [1, 2]],
|
|
|
|
|
// `structuredClone(saved.tokenHolderCache || {})`.
|
|
|
|
|
neverFalsy: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
field: "theme",
|
|
|
|
|
@@ -373,11 +412,16 @@ const CONTRACT = [
|
|
|
|
|
// Compared against "dark"/"light" in applyTheme() and otherwise falls
|
|
|
|
|
// to the system branch; assigned into an input .value, which coerces.
|
|
|
|
|
hostile: [42, "chartreuse", { a: 1 }],
|
|
|
|
|
// `saved.theme || "system"`.
|
|
|
|
|
neverFalsy: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
field: "dustThresholdGwei",
|
|
|
|
|
kind: KIND.LOOSE,
|
|
|
|
|
hostile: ["notanumber", true, { a: 1 }],
|
|
|
|
|
// Survives verbatim, so the falsy slot is also wrong-typed: "" reaches
|
|
|
|
|
// filterTransactions() as a comparand and a settings input .value.
|
|
|
|
|
falsy: [""],
|
|
|
|
|
},
|
|
|
|
|
...[
|
|
|
|
|
"rememberSiteChoice",
|
|
|
|
|
@@ -393,6 +437,10 @@ const CONTRACT = [
|
|
|
|
|
kind: KIND.LOOSE,
|
|
|
|
|
// A flag: only ever tested for truthiness, and written back verbatim.
|
|
|
|
|
hostile: [42, "notabool", { a: 1 }],
|
|
|
|
|
// Both answers to that truthiness test have to be driven, and 0 is a
|
|
|
|
|
// value src/ never writes for a flag. For utcTimestamps and debugMode
|
|
|
|
|
// the falsy answer is also the DEFAULT_STATE default.
|
|
|
|
|
falsy: [0],
|
|
|
|
|
})),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
@@ -434,6 +482,10 @@ function profileWith(field, value) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe("the floor each row claims", () => {
|
|
|
|
|
// The falsy slot is deliberately NOT in here. `saved.x || default` is a
|
|
|
|
|
// floor on falsy values and on nothing else, so a falsy value is the one
|
|
|
|
|
// thing a LOOSE field need not carry through verbatim; what it has to carry
|
|
|
|
|
// through is being falsy, which "both polarities" below asserts.
|
|
|
|
|
for (const row of CONTRACT) {
|
|
|
|
|
const values = [...row.hostile, ...(row.floorOnly || [])];
|
|
|
|
|
|
|
|
|
|
@@ -506,9 +558,50 @@ const HEALTHY = { errors: [], blank: false };
|
|
|
|
|
// unversionedValidProfile() stores no currentView, so every boot in here lands
|
|
|
|
|
// on Home. That is the cheap half of the proof; the restore path below is the
|
|
|
|
|
// half that matters.
|
|
|
|
|
// Both polarities of every swept field are driven, or the field is proven
|
|
|
|
|
// unable to take one of them. This is the guard on the sweep itself: a hostile
|
|
|
|
|
// set is all-truthy by construction, so without a falsy slot a dereference
|
|
|
|
|
// behind `if (!state.x)` is never reached on the boot that corrupts x — the
|
|
|
|
|
// same falsy-collapse blind spot the fields below were floored for.
|
|
|
|
|
describe("both polarities of every swept field are driven", () => {
|
|
|
|
|
const FALSY_STORED = [0, "", false, null];
|
|
|
|
|
const floored = (field, value) =>
|
|
|
|
|
normalizePersisted(profileWith(field, value))[field];
|
|
|
|
|
|
|
|
|
|
for (const row of CONTRACT) {
|
|
|
|
|
if (!swept(row)) continue;
|
|
|
|
|
|
|
|
|
|
if (row.neverFalsy) {
|
|
|
|
|
test(`${row.field}: cannot be falsy in state at all`, () => {
|
|
|
|
|
for (const value of FALSY_STORED) {
|
|
|
|
|
expect({
|
|
|
|
|
stored: value,
|
|
|
|
|
truthy: Boolean(floored(row.field, value)),
|
|
|
|
|
}).toEqual({ stored: value, truthy: true });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test(`${row.field}: truthy and falsy`, () => {
|
|
|
|
|
// What the boots below actually drive, floored the way a renderer
|
|
|
|
|
// sees it — not what the row says it drives.
|
|
|
|
|
const driven = [
|
|
|
|
|
...sweptValues(row),
|
|
|
|
|
...(row.hostileRestore || []).map((entry) => entry.value),
|
|
|
|
|
].map((value) => floored(row.field, value));
|
|
|
|
|
|
|
|
|
|
expect({
|
|
|
|
|
truthy: driven.some((value) => Boolean(value)),
|
|
|
|
|
falsy: driven.some((value) => !value),
|
|
|
|
|
}).toEqual({ truthy: true, falsy: true });
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("a hostile value for one field, booting onto Home", () => {
|
|
|
|
|
for (const row of CONTRACT) {
|
|
|
|
|
for (const value of row.hostile) {
|
|
|
|
|
for (const value of sweptValues(row)) {
|
|
|
|
|
test(`${row.field} = ${JSON.stringify(value)}`, async () => {
|
|
|
|
|
await expect(
|
|
|
|
|
bootHealth(profileWith(row.field, value)),
|
|
|
|
|
@@ -622,7 +715,7 @@ describe("a hostile routing value restoring onto", () => {
|
|
|
|
|
for (const row of CONTRACT) {
|
|
|
|
|
if (!swept(row) || !routes(row)) continue;
|
|
|
|
|
const seen = new Set();
|
|
|
|
|
for (const value of row.hostile) {
|
|
|
|
|
for (const value of sweptValues(row)) {
|
|
|
|
|
for (const view of RESTORABLE_VIEWS) {
|
|
|
|
|
const profile = restoringOnto(view, { [row.field]: value });
|
|
|
|
|
const key = JSON.stringify(profile);
|
|
|
|
|
@@ -645,18 +738,27 @@ describe("a hostile routing value restoring onto", () => {
|
|
|
|
|
// routing turns this red and has to declare `routes` and take the individual
|
|
|
|
|
// sweep above.
|
|
|
|
|
//
|
|
|
|
|
// Nothing is masked by combining: a throw fails the boot whichever field threw,
|
|
|
|
|
// and the only other way a dereference could go unseen is the renderer not
|
|
|
|
|
// running at all, which is exactly what `restored` forbids. When it does go
|
|
|
|
|
// red, the same view is re-booted one field at a time so the failure names the
|
|
|
|
|
// fields rather than leaving a reader to bisect twelve of them.
|
|
|
|
|
// Combining does hide one thing, and the last slot is what stops it. A hostile
|
|
|
|
|
// value is wrong-typed and therefore TRUTHY, so on a boot where every swept
|
|
|
|
|
// field is hostile, no `if (!state.x)` branch is entered — and a dereference
|
|
|
|
|
// inside such a branch would go unseen however loudly it throws. The last slot
|
|
|
|
|
// is the falsy one: every swept field that CAN be falsy is falsy on it, which
|
|
|
|
|
// is also the state an ordinary install boots in for three of them, while the
|
|
|
|
|
// fields that cannot be falsy stay hostile. Beyond that, a throw fails the boot
|
|
|
|
|
// whichever field threw, and a renderer that never ran is what `restored`
|
|
|
|
|
// forbids. When it does go red, the same view is re-booted one field at a time
|
|
|
|
|
// so the failure names the fields rather than leaving a reader to bisect twelve
|
|
|
|
|
// of them.
|
|
|
|
|
const UNROUTED = CONTRACT.filter((row) => swept(row) && !routes(row));
|
|
|
|
|
const HOSTILE_SLOTS = Math.max(...UNROUTED.map((row) => row.hostile.length));
|
|
|
|
|
const HOSTILE_SLOTS = Math.max(
|
|
|
|
|
...UNROUTED.map((row) => sweptValues(row).length),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
function unroutedValues(slot) {
|
|
|
|
|
const fields = {};
|
|
|
|
|
for (const row of UNROUTED) {
|
|
|
|
|
fields[row.field] = row.hostile[slot % row.hostile.length];
|
|
|
|
|
const values = sweptValues(row);
|
|
|
|
|
fields[row.field] = values[slot % values.length];
|
|
|
|
|
}
|
|
|
|
|
return fields;
|
|
|
|
|
}
|
|
|
|
|
|