fix: the bundled token list names tokens on Ethereum Mainnet only (closes #632)
check / check (push) Waiting to run
e2e / e2e-chrome (push) Waiting to run
e2e / e2e-firefox (push) Waiting to run

bundledToken(address, chainId) in tokenList.js answers only for Ethereum
Mainnet's chain id. Every reader of TOKEN_BY_ADDRESS now goes through it,
with the chain id of the transaction, balance or history entry it draws.
The token sources the screens build carry that chain id. The Uniswap
decoder sets the transaction's chain id on them. fetchTokenBalances()
takes the chain id of the network it asks about.

isSpoofedSymbol() takes the chain id of the token's network. It checks the
bundled list's symbols only on Ethereum Mainnet. The native asset's labels
stay reserved on every network.

Eighteen existing tests and three shared test helpers read the bundled
list without naming a network. Each now names Ethereum Mainnet.

Model: opus-5-5
This commit is contained in:
clawbot
2026-10-27 20:14:25 +00:00
committed by sneak
parent 8998d6c661
commit a72f301fe1
21 changed files with 681 additions and 117 deletions
+110 -16
View File
@@ -72,6 +72,11 @@ const {
const { renderSendTokenSelect } = require("../src/popup/views/send");
const { state } = require("../src/shared/state");
const { debugFetch } = require("../src/shared/log");
const { NETWORKS } = require("../src/shared/networks");
// The bundled list's symbols are known symbols only on Ethereum Mainnet.
const MAINNET = NETWORKS.mainnet.chainId;
const SEPOLIA = NETWORKS.sepolia.chainId;
// The fake "Ethereum" token with symbol "ETH" from the attack documented in
// README.md, given a holder count high enough to clear every other filter so
@@ -116,14 +121,29 @@ describe("the shared rule", () => {
});
test("a known symbol from its own contract is not a spoof", () => {
expect(isSpoofedSymbol("USDC", USDC_CONTRACT)).toBe(false);
expect(isSpoofedSymbol("usdc", USDC_CONTRACT.toUpperCase())).toBe(
false,
);
expect(isSpoofedSymbol("USDC", USDC_CONTRACT, MAINNET)).toBe(false);
expect(
isSpoofedSymbol("usdc", USDC_CONTRACT.toUpperCase(), MAINNET),
).toBe(false);
});
test("a known symbol from another contract is a spoof", () => {
expect(isSpoofedSymbol("USDC", FAKE_ETH_CONTRACT)).toBe(true);
expect(isSpoofedSymbol("USDC", FAKE_ETH_CONTRACT, MAINNET)).toBe(true);
});
// https://git.eeqj.de/sneak/AutistMask/issues/632: the bundled list holds
// mainnet contracts, so on Sepolia any contract may carry one of its
// symbols.
test("on Sepolia, a bundled symbol from any contract is not a spoof", () => {
expect(isSpoofedSymbol("USDC", FAKE_ETH_CONTRACT, SEPOLIA)).toBe(false);
expect(isSpoofedSymbol("USDC", USDC_CONTRACT, SEPOLIA)).toBe(false);
});
test("on Sepolia, the native asset's labels are still reserved", () => {
expect(isSpoofedSymbol("ETH", FAKE_ETH_CONTRACT, SEPOLIA)).toBe(true);
expect(isSpoofedSymbol("SepoliaETH", FAKE_ETH_CONTRACT, SEPOLIA)).toBe(
true,
);
});
test("a symbol that is not in the table is not judged here", () => {
@@ -164,7 +184,9 @@ describe("the shared rule: symbols that render as a known symbol", () => {
test("ASCII padding does not buy a pass", () => {
expect(isSpoofedSymbol(" ETH ", FAKE_ETH_CONTRACT)).toBe(true);
expect(isSpoofedSymbol("\tETH\n", FAKE_ETH_CONTRACT)).toBe(true);
expect(isSpoofedSymbol(" usdc ", FAKE_ETH_CONTRACT)).toBe(true);
expect(isSpoofedSymbol(" usdc ", FAKE_ETH_CONTRACT, MAINNET)).toBe(
true,
);
});
test("non-breaking and other Unicode spaces do not either", () => {
@@ -243,7 +265,9 @@ describe("the shared rule: symbols that render as a known symbol", () => {
test("compatibility forms fold onto the symbol they imitate", () => {
expect(isSpoofedSymbol(FULLWIDTH_ETH, FAKE_ETH_CONTRACT)).toBe(true);
expect(isSpoofedSymbol(FULLWIDTH_USDC, FAKE_ETH_CONTRACT)).toBe(true);
expect(
isSpoofedSymbol(FULLWIDTH_USDC, FAKE_ETH_CONTRACT, MAINNET),
).toBe(true);
});
// The two knowingly open classes, asserted here so that the boundary is
@@ -271,8 +295,10 @@ describe("the shared rule: symbols that render as a known symbol", () => {
});
test("a genuine contract still bears its own padded symbol", () => {
expect(isSpoofedSymbol(" USDC ", USDC_CONTRACT)).toBe(false);
expect(isSpoofedSymbol(ZWSP + "WETH", WETH_CONTRACT)).toBe(false);
expect(isSpoofedSymbol(" USDC ", USDC_CONTRACT, MAINNET)).toBe(false);
expect(isSpoofedSymbol(ZWSP + "WETH", WETH_CONTRACT, MAINNET)).toBe(
false,
);
});
// Normalization must not invent a match. Interior ASCII whitespace is
@@ -296,7 +322,7 @@ describe("the shared rule: symbols that render as a known symbol", () => {
expect(symbol).toMatch(/^[!-~]+$/);
if (addresses === null) continue;
for (const address of addresses) {
expect(isSpoofedSymbol(symbol, address)).toBe(false);
expect(isSpoofedSymbol(symbol, address, MAINNET)).toBe(false);
}
}
});
@@ -317,7 +343,7 @@ describe("the shared rule: symbols that render as a known symbol", () => {
describe("the shipped token list", () => {
test("no bundled token is filtered at its own address", () => {
const filtered = TOKENS.filter((t) =>
isSpoofedSymbol(t.symbol, t.address),
isSpoofedSymbol(t.symbol, t.address, MAINNET),
).map((t) => t.symbol + " @ " + t.address);
expect(filtered).toEqual([]);
});
@@ -360,7 +386,9 @@ describe("the shipped token list", () => {
expect(shared.length).toBeGreaterThan(0);
for (const [, list] of shared) {
for (const t of list) {
expect(isSpoofedSymbol(t.symbol, t.address)).toBe(false);
expect(isSpoofedSymbol(t.symbol, t.address, MAINNET)).toBe(
false,
);
}
}
});
@@ -404,7 +432,7 @@ describe("the shipped token list", () => {
[...addresses].sort(),
);
for (const address of addresses) {
expect(isSpoofedSymbol(symbol, address)).toBe(false);
expect(isSpoofedSymbol(symbol, address, MAINNET)).toBe(false);
}
}
});
@@ -421,7 +449,9 @@ describe("the shipped token list", () => {
}
for (const [symbol, list] of bySymbol) {
if (list.length < 2) continue;
expect(isSpoofedSymbol(symbol, FAKE_ETH_CONTRACT)).toBe(true);
expect(isSpoofedSymbol(symbol, FAKE_ETH_CONTRACT, MAINNET)).toBe(
true,
);
}
});
});
@@ -506,10 +536,40 @@ describe("surface 2: the Send token selector", () => {
}
beforeEach(() => {
state.networkId = "mainnet";
state.fraudContracts = [];
state.hideLowHolderTokens = true;
});
afterAll(() => {
state.networkId = "mainnet";
});
// A token reporting USDC's symbol from another contract.
function otherUsdc() {
return {
address: FAKE_ETH_CONTRACT,
symbol: "USDC",
decimals: 6,
balance: "12.5",
holders: 900000,
};
}
test("a bundled symbol from another contract is not selectable", () => {
render([otherUsdc()]);
expect(select.children).toEqual([]);
});
// https://git.eeqj.de/sneak/AutistMask/issues/632: the bundled list holds
// mainnet contracts, so on Sepolia any contract may carry its symbols.
test("with Sepolia active, a bundled symbol from another contract is selectable", () => {
state.networkId = "sepolia";
render([otherUsdc()]);
expect(select.children).toHaveLength(1);
expect(select.children[0].value).toBe(FAKE_ETH_CONTRACT);
});
test("a fake ETH token is not selectable", () => {
render([
{
@@ -627,7 +687,12 @@ describe("surface 3: the balance list", () => {
decimals: "6",
}),
]);
const balances = await fetchTokenBalances(HOLDER, BLOCKSCOUT, []);
const balances = await fetchTokenBalances(
HOLDER,
BLOCKSCOUT,
[],
MAINNET,
);
expect(balances).toHaveLength(1);
expect(balances[0].symbol).toBe(" USDC ");
});
@@ -641,11 +706,40 @@ describe("surface 3: the balance list", () => {
decimals: "6",
}),
]);
const balances = await fetchTokenBalances(HOLDER, BLOCKSCOUT, []);
const balances = await fetchTokenBalances(
HOLDER,
BLOCKSCOUT,
[],
MAINNET,
);
expect(balances).toHaveLength(1);
expect(balances[0].symbol).toBe("USDC");
});
// https://git.eeqj.de/sneak/AutistMask/issues/632: the bundled list holds
// mainnet contracts, so on Sepolia any contract may carry its symbols.
test("a bundled symbol from another contract is listed on Sepolia only", async () => {
respondWith([fakeEthItem({ symbol: "USDC", decimals: "6" })]);
expect(
await fetchTokenBalances(HOLDER, BLOCKSCOUT, [], MAINNET),
).toEqual([]);
const sepolia = await fetchTokenBalances(
HOLDER,
BLOCKSCOUT,
[],
SEPOLIA,
);
expect(sepolia).toHaveLength(1);
expect(sepolia[0].symbol).toBe("USDC");
});
test("a fake ETH token is filtered on Sepolia too", async () => {
respondWith([fakeEthItem()]);
expect(
await fetchTokenBalances(HOLDER, BLOCKSCOUT, [], SEPOLIA),
).toEqual([]);
});
// The trap in this change: the user's real ETH balance is not an ERC-20
// and is fetched over RPC in refreshBalances, so it never passes through
// this loop at all. An explorer row that is not an ERC-20 is dropped