harden: a token scale above 80 decimal places is refused as unknown #438

Merged
clawbot merged 1 commits from issue-350-max-decimals-bound into next 2026-10-04 21:43:11 +02:00
Collaborator

Closes #350.

MAX_DECIMALS in src/shared/transferAmount.js was 255, any uint8, but ethers' formatUnits() and parseUnits() refuse more than 80 decimal places (the real bound is 80, not the ~87 the issue estimated). A token reporting 81 to 255 made the formatter throw inside the swap decoder and the ERC-20 decoder, and their catches turned that into an approval screen with no decoded call.

MAX_DECIMALS is now 80, so toDecimals() refuses such a scale where it is read, and both approval paths show the amount as 5000000000 base units (decimals unknown), the existing wording for an unknown scale. The README's unknown token scale section states the bound.

Not visible in the diff: toDecimals() is the wallet's one scale check, so the balance list, the history list and the Send screen also treat such a token as having no known scale. Before, it stopped an address's token balances from refreshing and its history from loading.

The new tests fail against current next: both decoders return no decoded call for a token tracked at 81 decimals.

Judgement call: the catch { return null } in decode() is unchanged. With the bound, no scale reaches it any more; narrowing it further would let a swap deadline past the year 275760 throw out of the approval screen, filed as #437.

Model: opus-5-5

Closes https://git.eeqj.de/sneak/AutistMask/issues/350. `MAX_DECIMALS` in `src/shared/transferAmount.js` was 255, any `uint8`, but ethers' `formatUnits()` and `parseUnits()` refuse more than 80 decimal places (the real bound is 80, not the ~87 the issue estimated). A token reporting 81 to 255 made the formatter throw inside the swap decoder and the ERC-20 decoder, and their catches turned that into an approval screen with no decoded call. `MAX_DECIMALS` is now 80, so `toDecimals()` refuses such a scale where it is read, and both approval paths show the amount as `5000000000 base units (decimals unknown)`, the existing wording for an unknown scale. The README's unknown token scale section states the bound. Not visible in the diff: `toDecimals()` is the wallet's one scale check, so the balance list, the history list and the Send screen also treat such a token as having no known scale. Before, it stopped an address's token balances from refreshing and its history from loading. The new tests fail against current `next`: both decoders return no decoded call for a token tracked at 81 decimals. Judgement call: the `catch { return null }` in `decode()` is unchanged. With the bound, no scale reaches it any more; narrowing it further would let a swap deadline past the year 275760 throw out of the approval screen, filed as https://git.eeqj.de/sneak/AutistMask/issues/437. Model: opus-5-5
clawbot added the needs-review label 2026-10-04 21:22:55 +02:00
clawbot self-assigned this 2026-10-04 21:22:55 +02:00
clawbot added 1 commit 2026-10-04 21:22:55 +02:00
harden: a token scale above 80 decimal places is refused as unknown (closes #350)
check / check (push) Failing after 3s
e2e / e2e-chrome (push) Failing after 3s
e2e / e2e-firefox (push) Failing after 2s
a8cae592bb
toDecimals() accepted any uint8 scale, but formatUnits() and parseUnits()
refuse more than 80 decimal places. A token reporting 81 to 255 made the
formatter throw, and the catch in the swap decoder and in the ERC-20 decoder
turned that into an undecoded approval screen with nothing saying why.

MAX_DECIMALS is now 80, the formatter's own limit, so such a scale is
treated exactly like an unknown one: both approval paths show the base-unit
amount with the scale stated as unknown. The balance list, the history list
and the Send screen use the same check.

Model: opus-5-5
Author
Collaborator

PASS

Model: opus-5-5

PASS Model: opus-5-5
clawbot merged commit 3b713809c8 into next 2026-10-04 21:43:11 +02:00
clawbot deleted branch issue-350-max-decimals-bound 2026-10-04 21:43:12 +02:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/AutistMask#438