In Depth Guide to Ethereum — Part 1- Accounts

Prateek Reddy
Blockchain Musings
Published in
4 min readMar 19, 2018

This is the first of the series of 10 posts on in-depth guide to Ethereum. This series of posts assume a basic knowledge of Ethereum and provides a comprehensive view of how Ethereum works. Each post in this series is on a specific component of the Ethereum system. This post is about accounts in Ethereum.

Accounts in Ethereum are of 2 types:

  1. Externally Owned Accounts
  2. Contract Accounts

We will now look at creation of both accounts and how what they mean on Ethereum.

Account Creation:

Externally Owned Accounts:

Externally owned accounts in Ethereum are the identifiers with which a user can interact with the system. Unlike a traditional system in which accounts are created by a central authority which checks for clashes in identifiers, here in ethereum as we do not have a central authority we need a way in which identifiers can be generated in a decentralized way. So let us see how accounts are created in ethereum.

Accounts in case of Ethereum are a set of public private keys generated using secp256k1 ECDSA standard according to which private keys are randomly generated in the range of0x01–0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140.We can see that private key has a range of around 16⁶⁴ = 2²⁵⁶ which is the total number of private keys that can be created. To give you a perspective of how big this number is, it is estimated that the number of atoms in observable universe is about 10⁷⁰ to 10⁸⁰ and number of possible private keys are around 2²⁵⁶ which is roughly 10⁷⁷. So if there is sufficient randomness in creating the private key it is incredibly hard to guess. Also the probability of collision of private keys is incredibly low.

Once we pick a random private key from the range, we have to generate a Ethereum address from the private key which will act as an identifier on Ethereum. First a public key is generated from the private key using ECDSA algorithm, then this public key is hashed using Keccak256 algorithm and then right most 160 bits are taken from the hash. These 160 bits or 40 hex characters represent the public key in ethereum. So number of possible addresses in Ethereum are 2¹⁶⁰ = 10⁴⁸. To get a better estimate of this number, the total number of atoms on earth are estimated to be around 10⁴⁹- 10⁵⁰. This is how ethereum implements a decentralized way of creating accounts which have a incredibly low probability of collision.

This is based on Elliptic curve logarithm problem, which is the source of obscurity in ECDSA. You can learn more about the elliptic curve cryptography behind generation of public private keypair here.

Account Address = keccak256(ecdsapubkey(private key))[:40]

Contract Accounts

Contract are the identifiers to the code that is running on blockchain. Contract addresses can only be interacted with by sending transactions which are executed as per the code in the contract. Contract accounts can be created by sending a transaction with the contract code from externally owned accounts, we will discuss this in more detail in later posts. Now we will look at how contract addresses are created.

Addresses that are assigned to a new contract are predetermined as the address depends on 2 parameters, nonce for the account and the account address. Nonce for an account is the number of transactions that are sent from that account, this is not to be confused with block nonce. Contract addresses are generated by performing rlp encoding of address and nonce and then a keccak256 hash of the rlp encoded value. Then the last 40 hex characters of the hash is the contract address. In this case as there will be only one transaction from an account with a specific nonce, so the contract address will be unique.

Contract Address = keccak256(rlp([accounts, nonce]))[:40]

Properties of accounts

Accounts in Ethereum have some data mapped to them in the blockchain. The data fields are nonce, balance, storage root and code hash. This data is stored in global state of Ethereum secured by the blockchain.

Externally Owned Accounts

Externally owned account is nothing more than a public private key pair, whose data is mapped to the public key in Ethereum blockchain and private key must be used to make any changes to that data. For externally owned accounts only nonce and balance are relevant and the other 2 fields are null as they do not have any code and storage. Balance is the balance of ether present with that account. Nonce is the number of transactions that are sent from that account. We will discuss more about nonce and it’s use in next posts.

Contract Accounts

Contract accounts store code and interactions to the code are managed by sending transactions to the contract account. Contract accounts has nonce, balance, storage root, code hash. Nonce is the number of transactions sent by that account, balance is the amount of ether that is stored by the contract, storage root is the identifier to the storage of the contract and code hash is an identifier that points to the code that is present in the contracts. We will discuss more about how storage is implemented and how code gets executed in contracts in further posts.

For the next post we will look at transactions and try to understand internally how transactions work.

--

--