Skip to content

fix: guard address validation against non-string values - #186

Open
ayushsingh82 wants to merge 1 commit into
monad-crypto:mainfrom
ayushsingh82:fix/validate-address-type-check
Open

fix: guard address validation against non-string values#186
ayushsingh82 wants to merge 1 commit into
monad-crypto:mainfrom
ayushsingh82:fix/validate-address-type-check

Conversation

@ayushsingh82

Copy link
Copy Markdown

Summary

  • is_valid_address() calls re.match() directly on the address field. If address in data.json isn't a string (e.g. a JSON number, null, or a list), this raises an uncaught TypeError.
  • validate_token_directory() doesn't catch exceptions from validate_token_data(), so this TypeError propagates all the way up to main()'s top-level except Exception, printing Unexpected error: ... and aborting validation for every token in the run — not just the malformed one.
  • Every other field validated in validate_token_data() (name, symbol, chainId, decimals) already checks isinstance() before further validation. The top-level address field and crossChainAddresses[chain_id].address did not follow this same pattern.
  • Adds the missing isinstance(address, str) guard in both places, matching the existing style, so a bad address field now produces a normal, scoped "Invalid address: ..." error for that token instead of crashing the whole script.

Test plan

  • Reproduced the crash in isolation: validate_token_data({"address": 12345, ...}, ...) raised TypeError: expected string or bytes-like object before the fix.
  • After the fix, the same input returns a normal error list including "Invalid address: 12345" — no crash.
  • Same fix verified for crossChainAddresses[chain_id].address (e.g. {"1": {"address": 999999}}).
  • Ran the address-format check against all 89 existing mainnet/*/data.json files — identical results before and after (no regression on valid string addresses).
  • uv run ruff check and uv run ruff format --check pass on the changed file.

is_valid_address() calls re.match() directly on the "address" field,
which raises an uncaught TypeError if the field isn't a string (e.g. a
JSON number). Because validate_token_directory() doesn't catch
exceptions from validate_token_data(), a single malformed data.json
aborts validation for every token in the run instead of failing just
that one, with a confusing "Unexpected error" message.

Every other field in validate_token_data() (name, symbol, chainId,
decimals) already checks isinstance() before further validation;
address and crossChainAddresses[].address did not. Add the same guard
so a bad address field produces a normal "Invalid address" error
scoped to that token.
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.

1 participant