This blog is in reference with the Blockchain At Berkeley course Lecture 2.

https://www.youtube.com/watch?v=0s23w5GUAeU

Ethereum preview

For ethereum a blockchain is a “cryptographically secure transactional singleton machine with shared-state”. Cryptographically secure means no one can create a fake transaction or erase a transaction because of the complex mathematical algorithms. Transactional singleton machine implies single instances of the machine for all the transaction being created in the network. Shared-state means state stored on this machine is shared and open to everyone.

Ethereum is a transaction based state machine, i.e. it will read a series of input and based on those input there will be change in the state. The initial state is referred as genesis state, a state at which no transactions have occurred. There is also a final state which shows the current sate of the network.

Why ether or why not bitcoin?

Bitcoin works on running client software that agrees on state transition. Even ethereum agrees on state transition. The state in bitcoin is the ownership status of all existing bitcoins. They use a function apply for it which takes a list of transactions and outputs a new state from that. The function checks whether the input UTXO(unspent transaction output) is in the current state, if input signature is the same as that of the lookup UTXO signature and if sum of input UTXOs is greater than the sum of output UTXO, if not the function will return an error. Then it update the state by updating all the input UTXO’s as the output UTXO’s. This algorithms for apply function works perfectly for a centralized currency system. For bitcoin to be a decentralized currency system it need to have consensus along with state transitions.

How blockchain validation works?

It produces a package of transactions in every 10 minutes called blocks. Let us go through the pseudo code of VALIDATE_BLOCK function which takes input as a block. It has an is_valid function which check whether the previous block is validated. Then check whether the current block timestamp is greater than the previous blocks timestamp. Then check proof of work for the current block. Then check the transaction list of the previous blocks and scan through them for making state transition for the next block using apply function.

Blockchain applications

Namecoin: It is a decentralized domain name registration which uses first to file paradigm and works perfectly using bitcoin consensus .

Colored coins: It is an application which allows people to create their own currencies by publicaly assigning color to a specific UTXO. Therefore by using existing transaction data one can define it as a different colored coin.

Metacoins: It is also a bitcoin application that live on top of bitcoin. It provides an alternative state transition function but have all the mining and networking infrastructure as that of bitcoins.

Limitations of bitcoin script

> Though it supports a good amount of computation but it does not support loops therefore it lacks completeness.

> Since it uses UTXO script it cannot have control over the amount withdrawn(either full or nothing) hence difficult to withdraw very small denominations over a small period of time.

> It lacks state i.e. it has only spent and unspent UTXOs which is completely binary therefore could not have formal withdraw limits like ethereum.

> UTXOs cannot look into the on chain data like nonce, timestamp and previous block hash.

Difference between Ethereum and Bitcoin

Accounts

A Bitcoin user’s available balance is the sum of UTXO’s whose private key he owns, but Ethereum uses accounts which keeps track of balance. The shared state of ethereum has accounts which can interact with each other through a message passing framework. An account has state and 20 byte identifiers. Account state consist of nonce, balance, storageRoots and codeHash. There are two types of accounts:

○ Externally owned, which are controlled by private keys and have no code associated with them.

○ Contract accounts, which are controlled by their code and have code associated with them.

Externally owned account fires up a transaction to contract account which can in turn fire a contract account for internal transactions. Externally owned account can directly transact to another externally owned account. Any action on the ethereum blockchain is always initiated by transactions fired from externally owned account.

The current state of the account shows the current state of the ethereum network where all the nodes on the network agrees on the current balance, storage state, contract code etc. Every new block on the network takes the previous state and produces a new state where everyone has to agree upon new network state. Accounts can interact with networks, other accounts, and other contracts.

Why accounts not UTXOs

The nodes only need to update each accounts balance other than storing each UTXOs, hence it saves space. Its easy to script when transferring rather than updating a UTXO set to compute a computers available balance. Due to merklization we do not need to download the entire blockchain to set up a light node to send ether(SPV)

Gas and payment

Ether is the fuel for ethereum network. When a person wants to send tokens, interact with a contract, send ETH, or do anything else on the network , he must pay for that computation. That payment is calculated in gas and it is paid in ETH. Eg. the total cost of the transaction is the product of gas limit and gas price. Gas limit is the maximum amount of units of gas one is willing to spend on a transaction and gas price is the price he pays for each gas. Gas limit is like the amount amount of liters/gallons/units of gas for running a car and gas price as the amount of liter/gallon/unit of gas.

If they have enough ether to spend on his account balance to cover the gas limit to execute the transaction then the transaction will execute. A transaction becomes invalid if it runs out of gas during the process. Hence the change in the state is reversed and failing transactions are recorded, but the gas is not refunded since computations was already done on the network. The fees are like rewards given to the miners as a compensation for running computations and validate transactions. Greater the gas price, the greater the value the miners derive.

Ethereum is not used for computations alone but also can be used for storage, so the storage is proportional to the smallest multiple of 32 bytes. Increase in storage increases the size of the Ethereum state on all nodes and there is incentives to keep it small because a bigger blockchain means less accessibility for full modes coming to the network which means more centralization.

Why need fees?

Every computations on the network simultaneously affects every full node, so computation steps the EVM are very expensive. Ethereum is like a very redundant parallel computer. It wastes lots of computational power by verifying the same thing over and over again. But it is very secure, the more the people agreeing on it more secure the network gets. So verification is a very important task, so to encourage miners to validate transactions with these redundant operations. Hence smart contracts are used for simple tasks like verifying signatures. another reason is turning completeness allows for loops which may lead to halting problems(inability to determine when a loop will terminate hence not able to check whether the program runs infinitely). It is not possible to prevent people from DDoSing the network, but if they pay fees then it is ok for them to DDoS the network. They have to face an increase in fees as the DDoSing goes to a point where it gets unsustainable, where the network will become disturbed for a little bit of time.

Transactions

A transaction is a cryptographically signed piece of instruction that is generated by an externally owned account, serialized(uses a hash function), and then submitted to a blockchain. Transactions changes the state of an account within the global state i.e., from one state to another. The important thing with transactions is that they are of two types; message calls and contract creations.

The transaction contains nonce; gasPrice; gasLimit; to(the address of the sender); value(amount the sender has to transact to the recipient); v, r, s(user generated to identify the signature of the sender of the transaction); init-(only exists for contract creating transactions) It is an EVM code fragment that is used to initialize the new contract account; data(message fields that exists only for message calls) it is the input data of the message call.

Message calls

Message calls and contract creating transactions are always initiated by externally owned accounts. Transactions link the external world with the internal state of ethereum. Contracts that exist within the global state of ethereum can talk to other contracts using messages(internal transactions) to other contracts using . Message is similar to transactions that happens only between contracts.

Messages does not contain gas limit. Hence the gas limit is set high by the creator of the externally owned account to carry out the transactions and other additional computations that must be executed for the transactions(messages). If we run out of gas during execution of the parent contract, then the current and the subsequent message execution will be reverted, but the parent execution will not be reverted.

Smart Contract

Contracts in ethereum is like autonomous agent that live inside the ethereum network i.e, it is executed by the network itself. It reacts with the external world when poked by transactions which calls functions. Network consensus with smart contracts removes the need for trusted third party. So in order to mess with code one has to subvert the entire network. Smart contracts have direct access to the internal ether balance, internal ether state and permanent storage. They main four purpose of ethereum smart contracts are:

>storing and mining of data

>manage relationship between untrusting users

>provide functions to other contracts, serve as libraries

>complex authentication

I shall explain more about these on my upcoming blogs. Thanks for reading.