Skip to content

fix: refuse bad address checksum on read actions instead of throwing - #114

Merged
portdeveloper merged 1 commit into
portdeveloper:mainfrom
natureloved:fix/read-checksum-refusal
Oct 2, 2026
Merged

portdeveloper merged 1 commit into
portdeveloper:mainfrom
natureloved:fix/read-checksum-refusal

Conversation

@natureloved

Copy link
Copy Markdown
Contributor

What this changes

Closes #111

get_token_balance and get_nfts accepted mixed-case 0x addresses with invalid EIP-55 checksums because isAddress() only tests 0x + 40 hex. This allowed malformed addresses to bypass initial checks and reach ethers unchecked, throwing raw INVALID_ARGUMENT: bad address checksum errors out of runAction instead of returning the standard Refused: … line.

This PR hardens both read paths upfront before ethers is touched:

  • get_token_balance: catches checksum failures from resolveToken(input) and returns Refused: invalid token address "<token>" (checksum failed), matching prepareTokenSend.
  • get_nfts: validates the owner address with toChecksumAddress before calling wallet.getNfts(owner), returning Refused: "<owner>" is not a valid address (checksum failed), matching resolveSend.
  • Adds unit tests covering mistyped checksum address inputs for both get_token_balance (test/tools.test.mjs) and get_nfts (test/nft.test.mjs).

How I tested it

  • npm run build succeeds
  • npm test passes full suite (537 passed, 0 failed, 2 skipped)
  • Tested unit repro with invalid checksum address 0x534B2f3A21130D7A60830C2Df862319E593943A3:
    • runAction({ action: "get_token_balance", token: BAD }) returns Refused: invalid token address "0x534B..." (checksum failed) with isRefusal: true
    • runAction({ action: "get_nfts", address: BAD }) returns Refused: "0x534B..." is not a valid address (checksum failed) with isRefusal: true

Model / platform tested on:
Node v24.16.0 on Windows x64

Scope check

  • This stays within v0 scope (native MON, single account, testnet)

Conventions

  • I used npm (not pnpm/yarn) and did not add a global sodium-native override.
  • I did not commit .env, seeds, keys, or model weights.

On get_token_balance and get_nfts, passing a mixed-case 0x address whose EIP-55 checksum failed bypassed regex address checks and reached ethers unchecked, throwing a raw INVALID_ARGUMENT error instead of returning a refusal string.

Validate the address checksum on both read paths:
- get_token_balance catches checksum errors from resolveToken and returns a refusal matching prepareTokenSend
- get_nfts validates the owner address checksum with toChecksumAddress and returns a refusal matching resolveSend

Closes portdeveloper#111

@portdeveloper portdeveloper left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@portdeveloper
portdeveloper merged commit ca31f86 into portdeveloper:main Oct 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_token_balance and get_nfts throw a raw ethers checksum error where every other field refuses

2 participants