# SNIP 23: Mixed-case checksum address encoding

**URL:** <https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949>\
**Category:** SNIPs\
**Tags:** conventions\
**Created:** [October 24, 2024, 1:34pm UTC](https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949 "2024-10-24T13:34:53Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![ClementWalter](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/clementwalter/32/85516_2.png) [@ClementWalter](https://community.starknet.io/u/ClementWalter)\
**Post date:** [October 24, 2024, 1:34pm UTC](https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949/1 "2024-10-24T13:34:53Z")

</div>

I’m proposing to enforce the address representation to be 32 bytes long, checksumed as in the Ethereum ecosystem.

The checksum mechanism can be the same.

See also [ERCs/ERCS/erc-55.md at master · ethereum/ERCs · GitHub](https://github.com/ethereum/ERCs/blob/master/ERCS/erc-55.md)

Proposed implementation

```python
from starkware.starknet.public.abi import starknet_keccak

def checksum_encode(addr: int): # Takes a 32-byte binary address as input
    addr_bytes = int.to_bytes(addr, 32, "big")
    hex_addr = addr_bytes.hex()
    checksummed_buffer = ""

    # Treat the hex address as ascii/utf-8 for hashing
    hashed_address = f"{starknet_keccak(addr_bytes):064x}"

    # Iterate over each character in the hex address
    for nibble_index, character in enumerate(hex_addr):

        if character in "0123456789":
            # We can't upper-case the decimal digits
            checksummed_buffer += character
        elif character in "abcdef":
            # Check if the corresponding hex digit (nibble) in the hash is 8 or higher
            hashed_address_nibble = int(hashed_address[nibble_index], 16)
            if hashed_address_nibble > 7:
                checksummed_buffer += character.upper()
            else:
                checksummed_buffer += character
        else:
            raise eth_utils.ValidationError(
                f"Unrecognized hex character {character!r} at position {nibble_index}"
            )

    return "0x" + checksummed_buffer

checksum_encode(0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7)
# 0x049D36570D4e46f48e99674bd3fcc84644DdD6b96F7C741B1562B82f9e004dC7

checksum_encode(0xbd3fcc84644ddd6b96f7c741b1562b82f9e004dc7)
# 0x00000000000000000000000Bd3fcc84644dDd6B96F7C741b1562B82f9e004dc7

```

---

<div class="post-metadata">

**Author:** ![estheroche](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/estheroche/32/85345_2.png) [@estheroche](https://community.starknet.io/u/estheroche)\
**Post date:** [October 24, 2024, 3:19pm UTC](https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949/2 "2024-10-24T15:19:26Z")

</div>

Awesome the checksum mechanism will be amazing since its same Ethereum

---

<div class="post-metadata">

**Author:** ![milan](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/milan/32/23836_2.png) [@milan](https://community.starknet.io/u/milan)\
**Post date:** [October 25, 2024, 12:31pm UTC](https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949/3 "2024-10-25T12:31:15Z")

</div>

100% in favor of padding addresses.

It’s a huge PITA because every tool treats it differently (SDKs, Apibara, block explorers, etc.) and while 0x0f00 and 0xf00 are numerically the same, since they pretty much have to be stored as strings for interop, this introduces hard to spot bugs.

---

<div class="post-metadata">

**Author:** ![ClementWalter](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/clementwalter/32/85516_2.png) [@ClementWalter](https://community.starknet.io/u/ClementWalter)\
**Post date:** [October 25, 2024, 4:45pm UTC](https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949/4 "2024-10-25T16:45:09Z")

</div>

See the full proposal to be merged™ soon™

> <https://github.com/starknet-io/SNIPs/pull/113/files>
>
> Add SNIP-55 similar to ERC-55

---

<div class="post-metadata">

**Author:** ![robertkodra](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/robertkodra/32/85379_2.png) [@robertkodra](https://community.starknet.io/u/robertkodra)\
**Post date:** [October 31, 2024, 11:38am UTC](https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949/5 "2024-10-31T11:38:34Z")

</div>

I’m also in favour of padding addresses for the sake of consistency as it’s always different with every dev tool.

---

<div class="post-metadata">

**Author:** ![estheroche](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/estheroche/32/85345_2.png) [@estheroche](https://community.starknet.io/u/estheroche)\
**Post date:** [November 1, 2024, 1:08am UTC](https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949/6 "2024-11-01T01:08:25Z")

</div>

padding is a neccessary tool for dev, especially when it comes to issues of slot

---

<div class="post-metadata">

**Author:** ![haroldtrk](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/haroldtrk/32/85418_2.png) [@haroldtrk](https://community.starknet.io/u/haroldtrk)\
**Post date:** [November 3, 2024, 11:05am UTC](https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949/7 "2024-11-03T11:05:06Z")

</div>

from starkware.starknet.public.abi import starknet\_keccak  
from typing import Union

class AddressValidationError(Exception):  
“”“Custom exception for address validation errors.”“”  
pass

def checksum\_encode(addr: Union[int, str]) → str:  
“”"  
Generate a checksummed address following ERC-55 style convention for Starknet addresses.

```
Args:
    addr (Union[int, str]): Address as integer or hex string
    
Returns:
    str: Checksummed address string
    
Raises:
    AddressValidationError: If address is invalid
"""
try:
    # Convert string input to int if needed
    if isinstance(addr, str):
        addr = int(addr.replace("0x", ""), 16)
        
    # Validate address size
    if addr < 0:
        raise AddressValidationError("Address cannot be negative")
    if addr.bit_length() > 256:
        raise AddressValidationError("Address exceeds 32 bytes")
        
    # Convert to 32-byte representation
    addr_bytes = int.to_bytes(addr, 32, "big")
    hex_addr = addr_bytes.hex()
    
    # Calculate hash using starknet_keccak
    hashed_address = f"{starknet_keccak(addr_bytes):064x}"
    
    checksummed_buffer = []
    
    # Process each character
    for nibble_index, character in enumerate(hex_addr):
        if character in "0123456789":
            checksummed_buffer.append(character)
        elif character in "abcdef":
            # Check corresponding hash nibble
            hash_nibble = int(hashed_address[nibble_index], 16)
            checksummed_buffer.append(
                character.upper() if hash_nibble > 7 else character
            )
        else:
            raise AddressValidationError(
                f"Invalid hex character '{character}' at position {nibble_index}"
            )
            
    return "0x" + "".join(checksummed_buffer)
    
except ValueError as e:
    raise AddressValidationError(f"Invalid address format: {str(e)}")

```

def validate\_checksum(address: str) → bool:  
“”"  
Validate if an address string has the correct checksum.

```
Args:
    address (str): Address string to validate
    
Returns:
    bool: True if checksum is valid, False otherwise
"""
try:
    if not address.startswith("0x"):
        return False
        
    addr_int = int(address.replace("0x", ""), 16)
    return checksum_encode(addr_int) == address
except (AddressValidationError, ValueError):
    return False

```

---

<div class="post-metadata">

**Author:** ![eiki](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/eiki/32/85100_2.png) [@eiki](https://community.starknet.io/u/eiki)\
**Post date:** [November 5, 2024, 12:52pm UTC](https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949/8 "2024-11-05T12:52:19Z")

</div>

Could we get buy-in from SDKs, as well as Wallets?  
We’d like an answer and plan to include (and possible alerts and warnings on non-backward compatibility) from:

- Braavos
- Argent
- Keplr
- starknet-react
- starknetJS
- get-starknet
- ledger
- CEXes
- starknet-rs
- starkscan
- voyager

etc.  
whoever makes sense

---

<div class="post-metadata">

**Author:** ![0xjanek](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/0xjanek/32/424_2.png) [@0xjanek](https://community.starknet.io/u/0xjanek)\
**Post date:** [December 9, 2024, 11:16pm UTC](https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949/9 "2024-12-09T23:16:35Z")

</div>

What’s wrong with the current checksum approach?

> <https://github.com/starknet-io/starknet.js/blob/develop/src/utils/address.ts#L66>

---

<div class="post-metadata">

**Author:** ![ClementWalter](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/clementwalter/32/85516_2.png) [@ClementWalter](https://community.starknet.io/u/ClementWalter)\
**Post date:** [December 10, 2024, 8:24am UTC](https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949/10 "2024-12-10T08:24:14Z")

</div>

most probably very similar as in the SNIP I’ve taken the EIP implementation and the snippet from starknet js quotes ethers.js

This is not a standard in Starknet though, which is the main purpose of this SNIP

---

<div class="post-metadata">

**Author:** ![0xjanek](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/0xjanek/32/424_2.png) [@0xjanek](https://community.starknet.io/u/0xjanek)\
**Post date:** [December 10, 2024, 1:37pm UTC](https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949/11 "2024-12-10T13:37:09Z")

</div>

Okay, if it’s just about formalizing, can we make sure the SNIP matches the implementation?  
Migrating to a new implementation would be painful for everyone

---

<div class="post-metadata">

**Author:** ![OdedSW](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/odedsw/32/85534_2.png) [@OdedSW](https://community.starknet.io/u/OdedSW)\
**Post date:** [December 24, 2024, 11:04am UTC](https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949/12 "2024-12-24T11:04:07Z")

</div>

Hey @ClementWalter, I want to try and push this SNIP forward. Have you taken a look at the `BigNumberish` type in Starknet.js and check if the current SNIP matches the implementation?

---

<div class="post-metadata">

**Author:** ![ClementWalter](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/clementwalter/32/85516_2.png) [@ClementWalter](https://community.starknet.io/u/ClementWalter)\
**Post date:** [December 24, 2024, 11:55am UTC](https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949/13 "2024-12-24T11:55:36Z")

</div>

Not really yet. Let me summarize everything after Christmas, including feedback regarding starknet js existing implementation, and move forward beginning of Jan

---

<div class="post-metadata">

**Author:** ![ClementWalter](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/clementwalter/32/85516_2.png) [@ClementWalter](https://community.starknet.io/u/ClementWalter)\
**Post date:** [December 27, 2024, 10:21am UTC](https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949/14 "2024-12-27T10:21:48Z")

</div>

So summarizing the inputs from @haroldtrk and @0xjanek, here is a python implementation matching the already existing starknet-js one.

The key difference between the two implementation (proposed and refactored python VS starknet-js) is that starknet-js is hashing the minimal length input address (so a message of possibly less than 32 bytes) while I was proposing to hash the input address interpreted as a 32 bytes long message.

See

```auto
# Calculate hash using starknet_keccak
addr_bytes = int.to_bytes(addr, math.ceil(addr.bit_length() / 8), "big")
hashed_address = f"{starknet_keccak(addr_bytes):064x}"

```

instead of

```auto
# Calculate hash using starknet_keccak
addr_bytes = int.to_bytes(addr, 32, "big")
hashed_address = f"{starknet_keccak(addr_bytes):064x}"

```

I don’t see any issue adopting the existing starknet-js implementation, and consequently the final proposition consistent with the existing starknet-js is

```auto
import math
from typing import Union

from starkware.starknet.public.abi import starknet_keccak

class AddressValidationError(Exception):
    """Custom exception for address validation errors."""
    pass

def checksum_encode(addr: Union[int, str]) -> str:
    """
    Generate a checksummed address following ERC-55 style convention for Starknet addresses.
    Args:
        addr (Union[int, str]): Address as integer or hex string

    Returns:
        str: Checksummed address string

    Raises:
        AddressValidationError: If address is invalid
    """
    try:
        # Convert string input to int if needed
        if isinstance(addr, str):
            addr = int(addr.replace("0x", ""), 16)

        # Validate address size
        if addr < 0:
            raise AddressValidationError("Address cannot be negative")
        if addr.bit_length() > 256:
            raise AddressValidationError("Address exceeds 32 bytes")

        # Convert to 32-byte representation
        hex_addr = int.to_bytes(addr, 32, "big").hex()

        # Calculate hash using starknet_keccak
        addr_bytes = int.to_bytes(addr, math.ceil(addr.bit_length() / 8), "big")
        hashed_address = f"{starknet_keccak(addr_bytes):064x}"

        checksummed_buffer = []

        # Process each character
        for nibble_index, character in enumerate(hex_addr):
            if character in "0123456789":
                checksummed_buffer.append(character)
            elif character in "abcdef":
                # Check corresponding hash nibble
                hash_nibble = int(hashed_address[nibble_index], 16)
                checksummed_buffer.append(
                    character.upper() if hash_nibble > 7 else character
                )
            else:
                raise AddressValidationError(
                    f"Invalid hex character '{character}' at position {nibble_index}"
                )

        return "0x" + "".join(checksummed_buffer)

    except ValueError as e:
        raise AddressValidationError(f"Invalid address format: {str(e)}")

def validate_checksum(address: str) -> bool:
    """
    Validate if an address string has the correct checksum.

    Args:
        address (str): Address string to validate

    Returns:
        bool: True if checksum is valid, False otherwise
    """
    try:
        if not address.startswith("0x"):
            return False

        addr_int = int(address.replace("0x", ""), 16)
        return checksum_encode(addr_int) == address
    except (AddressValidationError, ValueError):
        return False

```

---

<div class="post-metadata">

**Author:** ![mubarak23](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/mubarak23/32/85335_2.png) [@mubarak23](https://community.starknet.io/u/mubarak23)\
**Post date:** [January 6, 2025, 1:16pm UTC](https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949/15 "2025-01-06T13:16:14Z")

</div>

Encoding addresses in a typo-resistant format reduces the likelihood of funds being lost or misrouted due to human errors in address entry. This is a practical improvement that enhances the user experience and trust in the ecosystem.

Personally i have had issues with typos, thankfully it is not a huge fund

---

<div class="post-metadata">

**Author:** ![Immanuelolivia1](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/immanuelolivia1/32/85409_2.png) [@Immanuelolivia1](https://community.starknet.io/u/Immanuelolivia1)\
**Post date:** [January 8, 2025, 1:08am UTC](https://community.starknet.io/t/snip-23-mixed-case-checksum-address-encoding/114949/16 "2025-01-08T01:08:59Z")

</div>

> [@estheroche](#):
>
> Awesome the checksum mechanism will be amazing since its same Ethereum

The checksum mechanism will be fantastic, and fully supports padding addresses.
