Calculation Behind Ethereum Wallet Address

Ansh Vaid
Coinmonks
Published in
3 min readFeb 21, 2022

--

Image credits: Etfstream

In my previous blogs on blockchain, I had discussed the calculation behind generating the Bitcoin wallet address from the private key and also how the block hash in Bitcoin blockchain is calculated. To refer all my blogs you can refer https://medium.com/@the_harvester and my website https://cybergeeks.website/

In this blog I will be discussing about how the wallet address in Ethereum blockchain is generated from the private key. The private key is 256 random bits. For our example let’s take 0101001100101000100010101001010100001010101111010101110101000010100101010100000010010101010101011111010100010010001001000010101010101111101010010110101010110101010010011011001010101010101010101010100100010010100010111010110100000000000000111110101101010110 as our private key, they are totally random combinations of 0s and 1s, and there is very less chance that you would get the same private key anywhere else. These 256 bits are converted to hexadecimal format (0x), so now I get 256/4=>64 hexadecimal characters. Hexadecimal values is the combination of 4 bits, therefore, 2 hexadecimal values computes 8 bits therefore 1 byte.

Hexadecimal value of above private key (256-bits long) is 53288A950ABD5D4295409555F512242AAFA96AB549B2AAAAA9128BAD0003EB56

Just like Bitcoin, Ethereum also uses secp256k1 Elliptic Curve Cryptography. Public key is generated from private key. PublicKey = PrivateKey * G is the expression of finding the Public Key from Private Key. G is the generating point. You can find all the standard values of secp256k1 ECC from https://www.secg.org/sec2-v2.pdf. I have written a python code to calculate the public key using 64 hex values. Public key is 512 bits longer.

The above code will give the public key as 04A4A4C5160DFA830E9D5FAD6DBA5248E7A9C783C30974A3382247DCE5A815DBAA4CB31812FD016561DE57A5A53EF527499031705BE824016842688B498F61FDE7

This is the uncompressed public key because it has the prefix 04. Uncompressed public key means the public key has both X and Y axis coordinates in it. X-axis coordinates in above public key is A4A4C5160DFA830E9D5FAD6DBA5248E7A9C783C30974A3382247DCE5A815DBAA, therefore the left over part is Y-axis coordinate. The question is why X & Y axis coordinates are generated? This is because, G, which I discussed above in calculation of public key is a point, with which I multiplied private key value, therefore I will get X and Y axis. The multiplication is not the regular multiplication, rather it’s a ECC multiplication, different from regular multiplication.

Unlike Bitcoin public key, remove 04 prefix from the uncompressed public key and apply byte-wise keccak256 hash on the 128 hexadecimal values. Remember byte-wise hashing and not character-wise hashing.

The byte-wise hash of the 128 hex characters is 035aa4e9a4657a2faec812f23b75ea5c82e96d9489ed740d455da4900f152f95, but the last 20 bytes of this hash, i.e. 0x3b75ea5c82e96d9489ed740d455da4900f152f95, is the wallet address of the above mentioned private key. Just like the python codes in previous blogs, similarly do for the public key in this blog to get the hash, else use CyberChef.

Cyber Chef

Social Media Links: LinkedIn | GitHub | Instagram | Twitter

My Website: https://cybergeeks.website/

Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing

Also Read

--

--

Ansh Vaid
Coinmonks

Security Assessment Engineer at IITK | Cyber security researcher | eJPT | eWPTXv2 | PenTest+ | CASP+