Ethereum 101: Basic Introduction to Ethereum.

Ethereum 101: Basic Introduction to Ethereum.

These are resources to get anyone getting started with Ethereum. It covers all Ethereum Basic principles

Resources.

  1. Videos:

  2. Books:

    • Ethereum Handbook
  3. Web Links:

Notes based on Ethereum 101 by Secureum.

Turing complete: A system in which a program can be written that will find an answer for instance a simple addition. Most programming languages are Turing complete. Ethereum's programming language is also turing complete. The best explanation of Turing complete is available in this video.

Turing complete systems face the halting problem. This means that the program might go on forever i.e to infinity. Ethereum uses the concept of gas to make sure that this does not happen.

Ethereum’s purpose is not primarily to be a digital currency payment network. While the digital currency ether is both integral to and necessary for the operation of Ethereum, ether is intended as a utility currency to pay for use of the Ethereum Blockchain.

Bitcoin is UTXO based: This means that bitcoin tracks the state of units of bitcoin and their ownership.

While Ethereum is state-based: This means that Ethereum tracks the state transitions of data.

Ethereum uses Asymmetric cryptography. It is also known as public key cryptography. The public key is derived from the private key.

The public key cannot be used to derive the private key.

Ethereum also makes use of Elliptic Curve Digital Signature Algorithm(ECDSA) Cryptography.

Ethereum state is made up of objects called accounts. Each Account has a 20 byte address.

State transition is the transfer of value and information between the accounts.

An Ethereum Account has four fields:

  • Nounce: This is a counter, that ensures that each transaction can only be processed once.

  • Balance: This contains the account's current ether balance.

  • Contract code:

  • Storage

Ethereum has two account types:

  • Externally Owned Account(EOA): controlled by private keys. Anyone who gets hold of the private keys can create digital signatures that can be used to access the ETH account balance.

  • Contract Accounts are controlled by their smart contract code. whenever a contract account receives a message it runs the code and accesses the storage. When the code runs, it can send messages to other accounts or even create new contracts.

Ethereum uses Keccak-256 as its cryptographic hash function.

How to derive an Externally Owned Account(EOA) Address:

  • The private key is used to get the public key which is situated on the Elliptic curve.

  • The public key is then hashed using the keccak-256 cryptographic hash function.

  • The last 20 bytes of this hash are the address of the EOA.

Transactions are signed messages originated by an externally owned account (EOA), transmitted by the Ethereum network, and recorded on the Ethereum blockchain. Only transactions can trigger a change of state. Ethereum is a transaction-based state machine.

Properties of Transaction in Ethereum:

  • Atomic: it is all or nothing i.e. cannot be divided or interrupted by other transactions.

  • Serial: Transactions are processed sequentially one after the other without any overlapping by other transactions

  • Inclusion: Transaction inclusion is not guaranteed and depends on network congestion and gasPrice among other things. Miners determine inclusion.

  • Order: Transaction order is not guaranteed and depends on network congestion and gasPrice among other things. Miners determine order.

Components of a Transaction in Ethereum:

  • nonce: A sequence number, issued by the originating EOA, used to prevent message replay.

  • gasPrice: The amount of ether (in wei) that the originator is willing to pay for each unit of gas.

  • gasLimit: The maximum amount of gas the originator is willing to pay for this transaction.

  • recipient: The destination Ethereum address

  • value: The amount of ether (in wei) to send to the destination.

  • data: The variable-length binary data payload

  • v,r,s: The three components of an ECDSA digital signature of the originating EOA

Nonce.(Number used only Once).

  • This number is used only once and is used to prevent replay.

  • It is equal to the number of transactions sent from the EOA account.

  • For contract accounts, it is the number of contract-creations made by the account.

gasPrice.

  • This is the price that the sender of the transaction is willing to pay for the transaction.

  • It is measured in wei.

  • The higher the gas price, the faster the transaction is likely to be confirmed on the blockchain.

gasLimit.

  • This is the maximum gas units the transaction originator is willing to pay to complete the transaction.

Contract creation transactions are sent to a special destination address called the zero address i.e. 0x0. It contains a data payload with the compiled bytecode to create the contract. It also contains an optional ETH amount.

Transaction Vs Message.

A transaction is produced by an EOA where an external actor sends a signed data package which either:triggers a message to another EOA where it leads to a transfer of value or it triggers a message to a contract account where it leads to the recipient contract account running its code. (Offchain:- > OnChain).

A message is either: triggered by a transaction to another EOA or contract account, or triggered internally within the EVM by a contract account when it executes the Call family of opcodes and leads to the recipient contract account running its code or value transfer to the recipient EOA.

Transactions are grouped together into a block.The blocks are then linked together to form a blockchain.

Every block also contains a hash of the previous block.(This is why a blockchain is considered immutable.)

Ethereum Node: A node is a software application that implements the Ethereum specification and communicates over the peer-to-peer network with other Ethereum nodes.

Ethereum Client: This is a specific implementation of the Ethereum node.the most common implementation of Ethereum clients are Geth,OpenEthereum,Nethermind.

Ethereum transactions are sent to Ethereum nodes to be broadcast across the peer-to-peer network.

Ethereum State.

State is a mapping between addresses and account states implemented as a modified Merkle tree. The Merkle tree is a binary tree composed of nodes with:

  • leaf nodes at the bottom of the tree that contains underlying data.

  • Intermediate nodes,where each node is the hash of its two child nodes.

  • A single root node formed from the hash of its two child nodes representing the top of the tree.

Each ethereum block contains a block header,transactions and Ommers' block header.

The Ethereum Virtual Machine. (EVM)

The EVM is the runtime environment for smart contracts.

The EVM is a quasi turing complete machine.It is gas bounded.

The code in Ethereum contracts is written in a low-level, stack-based bytecode language, referred to as "Ethereum virtual machine code" or "EVM code"

Purpose of ECDSA Signatures.

  • Authorization: Proves that the owner of the private key, who is by implication the owner of an Ethereum account, has authorized the spending of ether, or execution of a contract

  • Non-Repudiation: This means that once a signature has been included, It cannot later be denied that it was not included. The proof of authorization is undeniable.

  • Integrity: Proves that the transaction data has not been and cannot be modified by anyone after the transaction has been signed.

A transaction can result in the creation of a contract.Contract creation transactions are sent to a special destination address called the zero address i.e. 0x0.A contract creation transaction contains a data payload with the compiled bytecode to create the contract. An optional ether amount in the value field will create the new contract with a starting balance.

What is the difference between a Message and a transaction(TXS & MSGS).

Transactions: originate From Offchain--------------> To Onchain.

Messages: Originate From OnChain ------------------> To OnChain.

A transaction is produced by an EOA where an external actor sends a signed data package which either:

  • triggers a message to another EOA where it leads to a transfer of value.

  • triggers a message to a contract account where it leads to the recipient contract account running its code.

A Message is either:

  • triggered by a transaction to another EOA or contract account or

  • triggered internally within the EVM by a contract account when it executes the CALL family of opcodes and leads to the recipient contract account running its code or value transfer to the recipient EOA.