Understanding Ethereum Addresses Checksums
TL;DR: we see how to calculate Ethereum addresses checksums. If the nth letter in the address is a letter (a-f), and the nth digit of its keccak's hash is greater than 7, then the nth letter in the address is capitalized.
Ethereum's ecosystem is vast and intricate, with various components ensuring security and ease of use. One such feature, often overlooked but crucial for error prevention, is the address checksum mechanism. In this article, we'll delve into what Ethereum address checksums are, why they're important, and how they're calculated.
The Role of Checksums in Ethereum Addresses
When you deal with Ethereum addresses, a small mistake like a misplaced character can lead to significant issues, including loss of funds. Ethereum addresses are long strings of numbers and letters, making them prone to errors when typed manually. This is where checksums come into play.
Checksums in Ethereum addresses serve a similar purpose to a verification digit in a national identification number. They provide a layer of error detection, minimizing the risk of sending funds to the wrong address due to a typing error.
How Checksums Work
Ethereum addresses are 20 bytes long hexadecimal numbers, but their checksum mechanism involves a mix of upper and lower case letters, based on a simple rule linked to the address's hash value.
If the nth letter in the address is a letter (a-f), and the nth digit of its keccak's hash is greater than 7, then the nth letter in the address is capitalized. As simple as that.
Here’s a simple breakdown.
Hashing the Address
First, the all-lowercase Ethereum address (excluding the '0x' prefix) is hashed using the Keccak-256 algorithm.
For example:
cast keccak "8103b0a8a00be2ddc778e6e7eaa21791cd364625"
Outputs:
0x8d3aa2bbf2a1269f8841434f71116f08d25fcf8e4ed0e4f73408da6872b3c521
Applying the Rule
According to the rule expressed before, each character in the original address is compared to the corresponding character in the hash (which I've cut to the first 20 bytes). If it's a letter it'll be converted to uppercase if the hash digit is greater than 7, it'll be kept in lowercase otherwise.
To make it easier to visualize, I've colored in blue all the letters in the original address.
In the hash, I've colored in the same blue all the digits from 0 to 7 and in pink all the digits from 8 to F.
In the checksum address, I've colored the letters in the same color as the corresponding values in the hash. Those in blue have remained in lowercase, and those in pink have been converted to uppercase.
Practical Implications
As a Solidity developer or Ethereum user, understanding and utilizing checksums is vital for ensuring transaction accuracy. Most Ethereum wallets and tools automatically apply these checksums, but it's still crucial to be mindful, especially when manually entering addresses.
The checksum adds a layer of security to ensure that the address is the intended one. In VSC an address with an incorrect checksum will be flagged in red, as in the following image:
Conclusion
The Ethereum address checksum is a simple yet effective mechanism to prevent costly errors. As blockchain technology continues to evolve, understanding these fundamental aspects becomes increasingly important for developers and users alike. By grasping the checksum concept, you can contribute to safer and more efficient Ethereum interactions.
Subscribe to my newsletter
Read articles from Ramon Royo directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by