DEV Community

AllSwap
AllSwap

Posted on Edited on

Where address specifications and validators disagree: notes from 1,386 labelled strings

We maintain a dataset of 1,386 strings, each labelled as a well-formed mainnet address or not, for 12 address families. The label follows the cited specification, not any library. Building it showed us a handful of places where a careful reading of the specification and the behaviour of a typical validator part ways. This note lists them, with the commands that produce the numbers. You do not need to use any particular product to follow it.

The data is on Zenodo (doi.org/10.5281/zenodo.24540799) and GitHub (allswapio/address-format-test-vectors). Every label is computed twice, by scripts/build.py and by scripts/verify.py, which share no code. Both were written by the same maintainer with AI coding tools, so the agreement shows consistency, not independent review. If you disagree with a reading, the README asks for an issue that quotes the passage.

The Python scripts need only the standard library (Python 3); the two Node.js 22 checks also need the published library package. The scripts are in examples/ of the dataset repository.

1. One string, several families

Some strings are well formed under more than one family. The dataset lists six such strings in cross-family-ambiguities. We also counted them from the main file (a1_cross_family.py): 16 distinct strings have a spec_valid = true row in two or more families.

String (shortened) Valid under Why
1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa Bitcoin, Bitcoin Cash Base58Check version 0x00, which is also the legacy Bitcoin Cash format
3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy Bitcoin, Litecoin, Bitcoin Cash Version 0x05 is the script-hash version in all three
0x5aaeb605...1beaed (lower case) EVM, NEAR NEAR allows 0x plus 40 hex digits as an account name
11111111111111111111111111111111 Solana, NEAR 32 digits fit the NEAR account grammar
bc1qw508d6qe...f3t4 Bitcoin, NEAR lower-case letters and digits, 42 characters

The last two rows deserve a second look. A NEAR account ID is any 2 to 64 characters of a-z, 0-9 and the separators ., -, _ (NEAR documentation, account IDs). A lower-case Bitcoin Bech32 string is therefore also a legal NEAR name. Whether you can create that name on the network is a different question; the grammar does not answer it.

a1b_library_cross_check.mjs runs the 335 distinct valid strings through all 12 families of our own library, which is deliberately stricter than the specifications. Thirteen strings are accepted by two families, and every one is an EVM address that is also read as a NEAR account.

What to take from it: a validator should be told the family. Guessing the family from the string alone is not safe.

2. Checksums are what makes a typo detectable

Formats without a checksum accept most one-character edits. We took one valid string from the dataset and replaced every character with every other character of its alphabet. snippet_a_substitute.py holds this code and the two calls that run it, for the two Base58 cases:

import hashlib
B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"

def decode(s):
    n = 0
    for c in s:
        n = n * 58 + B58.index(c)
    return b"\0" * (len(s) - len(s.lstrip("1"))) + n.to_bytes((n.bit_length() + 7) // 8, "big")

def solana_ok(s):                       # no checksum: only the decoded length matters
    return len(decode(s)) == 32

def bitcoin_p2pkh_ok(s):                # version 0x00 + 20 bytes + 4 checksum bytes
    b = decode(s)
    return len(b) == 25 and b[0] == 0 and hashlib.sha256(hashlib.sha256(b[:21]).digest()).digest()[:4] == b[21:]

def survivors(s, ok):
    n = sum(ok(s[:i] + c + s[i + 1:]) for i in range(len(s)) for c in B58 if c != s[i])
    return n, len(s) * 57
Enter fullscreen mode Exit fullscreen mode

a2_single_char_substitution.py adds the EVM cases, with a Keccak-256 written in the script. Output:

String Variants Still valid
Solana key (sol-0032, 44 characters) 2,508 2,466
Bitcoin P2PKH (btc-0001) 1,938 0
EVM address, all lower case (evm-0001 lowered) 631 600
EVM address, EIP-55 mixed case (evm-0001) 1,280 0

Two notes on the table. For the lower-case EVM address, 600 is exactly 40 positions times 15 other hex digits; the other 31 variants damage the 0x prefix. For Solana, all 42 variants that fail are substitutions of the first character: they push the decoded value over 32 bytes. That depends on the string: this key starts with F, a low digit of the alphabet, so a higher replacement can overflow. We tested one key only.

The dataset's own mutation rows show the same thing in a less controlled way: 249 rows apply a one-character edit (substitute, insert, drop, swap, extend, truncate), and 11 of them are still valid, all Solana (a6_mutation_rows.py). These rows were picked by the build rules, at most three per rule and family, so read them as examples, not as a rate.

EIP-55 itself says that a random mistyped address passes with a probability of 0.0247 % (EIP-55, Rationale). Our 0 of 1,280 is consistent with that, and says nothing more precise.

3. Bech32 and Bech32m differ in one constant

BIP-173 defines Bech32. BIP-350 changed the checksum constant to 0x2bc830a3 for witness versions 1 to 16 and kept the original constant 1 for version 0. A string that carries the wrong constant for its witness version is invalid, even though its checksum is internally consistent. BIP-350 says no string is valid under both.

CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
GEN = [0x3B6A57B2, 0x26508E6D, 0x1EA119FA, 0x3D4233DD, 0x2A1462B3]

def residue(s):
    s = s.lower()
    hrp, data = s[:s.rfind("1")], [CHARSET.index(c) for c in s[s.rfind("1") + 1:]]
    chk = 1
    for v in [ord(c) >> 5 for c in hrp] + [0] + [ord(c) & 31 for c in hrp] + data:
        top = chk >> 25
        chk = (chk & 0x1FFFFFF) << 5 ^ v
        for i in range(5):
            chk ^= GEN[i] if (top >> i) & 1 else 0
    return chk, data[0]          # residue 1 = Bech32, 0x2bc830a3 = Bech32m; data[0] = witness version
Enter fullscreen mode Exit fullscreen mode

Run on the BIP-350 invalid example bc1p0xlxvlhem...h2y7hd, it prints residue 0x1 with witness version 1. The checksum is a good Bech32 checksum, and the address is still invalid. A validator that only asks "is the checksum good?" accepts it.

The dataset has nine rows with the reason wrong_checksum_constant (a3_bech32_constants.py): six for Bitcoin, two for Litecoin, one for the Zcash TEX format (ZIP-320, always Bech32m). The 13 valid BIP-173 and BIP-350 examples in the same script pass.

Two more traps from the same specifications. Mixed case is never allowed, but an all-upper-case string is valid, which matters for QR codes. And witness versions 2 to 16 are valid recipients under BIP-350 although no standard output uses them yet. Whether to accept them is a product decision, not a format question.

4. EIP-55: what single-case means

EIP-55 defines the capitalisation of a hex address from a Keccak-256 hash. It does not say what to do with an address that is all lower case or all upper case; those appear in its test cases only (EIP-55). The ecosystem treats them as "no checksum asserted", and so does the dataset, with a note on each such row. The cost is visible in section 2: every one-digit error in a lower-case address stays valid.

A second trap is EIP-1191, which defines a different capitalisation for some chains. In the dataset, evm-0005 and evm-0049 are the same 20 bytes. One is capitalised by EIP-55, the other by EIP-1191 for chain id 30. Under EIP-55, the second fails. A validator that follows EIP-55 will reject a correct address from a chain that uses EIP-1191. Five such rows are in the data; the library we compare against accepts none.

5. Where a validator is narrower than the specification

The last column of the dataset records the result of multichain-memo-address-validator 1.0.0, a library we also maintain. It differs from the label on 90 of 1,386 rows, always in the same direction: specification valid, library invalid. On this data it never accepts a string that a specification rejects (a4_spec_vs_library.py, and scripts/compare.mjs in the dataset).

Policy of the library Rows
Refuses XRP X-addresses (they can carry a tag) 14
Bitcoin Cash: 20-byte hashes only / lower case only / no legacy Base58 11 / 8 / 7
Stellar: G... accounts only (no muxed or contract) 8
Litecoin: refuses legacy 3... 6
TRON: Base58Check only (no hex form) 6
NEAR: long top-level names only as implicit forms 5
Zcash: transparent Base58 only (no TEX) 5
Bitcoin and Litecoin: witness versions 0 and 1 only / lower case only 4 / 3
TON: workchain 0 only 3
All-zero values (application policy) 10

These are choices, and they are documented in the library's README. The point for validator authors is that "invalid" can mean three things: the string breaks the format, the format is not supported, or the application refuses it. Mixing them in one boolean is how a customer's correct address ends up rejected. The library returns a pitfall field for this reason; the data shows 90 cases where it matters.

6. TON, NEAR and Solana details

TON. The user-friendly form is 36 bytes in base64. The TON documentation says both standard and URL-safe base64 are valid and must be supported. a5_ton_forms.py decodes the documented example in both alphabets and in raw form: one account, three strings. The first byte holds flags (0x11 bounceable, 0x51 non-bounceable, +0x80 testnet-only). If you set the testnet bit and leave the CRC, the string is invalid; if you recompute the CRC, it is a well-formed string that should not be accepted on mainnet. In the second case the CRC passes, so the flag byte has to be read as well.

NEAR. The grammar admits implicit accounts (64 hex), Ethereum-like (0x and 40 hex) and plain names in one rule, which is why section 1 exists. The dataset follows the grammar of near-account-id-rs and does not say whether a name exists.

Solana. A base58 string that decodes to 32 bytes. That is all. The system program ID, 32 ones, is valid by that rule, and is a zero value many applications will want to refuse separately.

Limits and what we did not verify

  • The labels are our reading of the specifications, computed by two programs from one maintainer. Where a specification is silent, we left the row out.
  • The mutation rows are chosen by rules, not drawn at random. No rate in this note should be quoted as a rate for real typos.
  • The overlap counts in section 1 are lower bounds. Only strings that have a row in two families are counted, and the library check is stricter than the specifications.
  • The Solana exhaustive test used one key; other keys, for example ones that start with 1, were not tested.
  • The data says nothing on whether an address exists, is funded, or can receive a given asset. We did not test any other library, and we did not check the data against a live node.
  • Zcash shielded and unified addresses, Litecoin MWEB, regtest and most testnet forms are not covered.

Reproduce

git clone https://github.com/allswapio/address-format-test-vectors
cd address-format-test-vectors
python3 scripts/verify.py          # independent recomputation of every label
node scripts/compare.mjs <path>/multichain-memo-address-validator/src/index.mjs
Enter fullscreen mode Exit fullscreen mode

An interactive address checker is at allswap.io/tools/address-validator.

Disclosure: we maintain the dataset and the library discussed here, both published by AllSwap (Haohang Network Technology Co., Limited, service@allswap.io). AI tools were used in drafting the dataset, the scripts and this text. No independent review of the data has been done.

Top comments (0)