Blockchain basics(Part-2)

Ethereum Blockchain

Pre-requisite:- Blockchain basics (Part-1)

Smart Contract

Bitcoin is the mother of all blockchains, which was intended for peer to peer transfer of value. Around 2013, a framework for code execution was introduced by Ethereum Founders.

Bitcoin Vs Ethereum

Digital currency transfer like Bitcoin required simple addition and subtraction, Ethereum enables transaction that may carry out more sophisticated operations. The centrepiece and trust of this Ethereum Blockchain is a smart contract.

A smart contract is a piece of code deployed in the blockchain node. Execution of a smart contract is initiated by a message embedded in the transaction.

Structurally, a smart contract consists of a class definition in an object-oriented design pattern.

It has data, functions, or methods with modifier public or private along with getter and set function.

Specific programming languages have been designed for coding smart contracts.

E.g.- Solidity

Reference:- https://medium.com/coinmonks/how-to-write-a-simple-smart-contract-25f6d3c1d6db

Every node in the Ethereum network should be able to execute the code irrespective of that underlaying type of hardware or OS. This gives rise to the development of the Ethereum Virtual Machine(EVM).

Ethereum Virtual Machine(EVM)

An EVM provides a rum anywhere obstruction layer for the contract code. A smart contract written in a high-level language is translated into EVM byte code and then deployed on the EVM. Every node will host the same smart contract codes on the EVM.

Ethereum Structure

Bitcoin blockchain state was defined in terms of Unspent Transaction Outputs or UTXOs and a reference implementation of the wallet application that held the account reference.

Ethereum formally introduces the concept of an account as a part of the protocol. The account is the originator and the target of a transaction. A transaction directly updates the account balances as opposed to maintaining the sate such as in the bitcoin UTXOs. It allows for transmitting of values and messages and data between the accounts that may result in the state transitions. These transfers are implemented using transactions.

Ethereum block structure-

  • Header
  • Transaction
  • Runner-up header

Accounts types

  • The participant node can send a transaction for Ether transfer or it can send a transaction to invoke a smart contract code or both.
  • Both types of transactions require fees.
  • An account must have sufficient balance to meet the fees needed for the transaction activities.

Transactions

Reference:- https://etherscan.io/block/10316849

A transaction in Ethereum includes-

  • Transaction Hash — A TxHash or transaction hash is a unique 66 character identifier that is generated whenever a transaction is executed.
  • Status — The status of the transaction.
  • Block — The number of the block in which the transaction was recorded. Block confirmation indicates how many blocks since the transaction is mined.
  • Timestamp — The date and time at which a transaction is mined.
  • From — The sending party of the transaction (could be from a contract address).
  • To — The receiving party of the transaction (could be a contract address).
  • Value — The value being transacted in Ether and flat value.
  • Transaction fee — Amount paid to the miner for processing the transaction.
  • Gas Limit — Maximum amount of gas provided for the transaction. For normal Eth transfers, the value is 21,000. For contract, this value is higher and bound by block gas limit.
  • Gas Used by Transaction — The exact units of gas that was used for the transaction.
  • Gas Price — Cost per unit of gas specified for the transaction, in Ether and Gwei. The higher the gas price the higher chance of getting included in a block.
  • Nonce — Sequential running number for an address, beginning with 0 for the first transaction. For example, if the nonce of a transaction is 10, it would be the 11th transaction sent from the sender’s address.
  • Input Data — Additional information that is required for the transaction.
  • Private Note — Private note to keep track of the transaction. Only viewable to Etherscan’s user who assigned them.

Ethereum Operation and Incentive Model

Ethereum Operation

For a simple Ether transfer, the amount to transfer and the target address are specified along with the fees or gas points. The amount and the fees are transferred to their respective accounts.

An Ethereum Node is a computational system representing a business entity or an individual participant.

An Ethereum full Node hosts the software needed for-

  • Transaction initiation
  • Validation
  • Mining
  • Block creation
  • Smart contract execution
  • Ethereum Virtual Machine(EVM)

A smart contract is designed, developed, compiled, and deployed on the EVM that can be more than one smart contract address in an EVM. When the target address in a transaction is a smart contract, the execution code corresponding to the smart contract is activated and executed on the EVM.

The input needed for this execution is extracted from the payload field of the transaction.

The current state of the smart contract is the values of the variables defined in it.

The state of the smart contract may be updated by this execution. Results of this execution are stored in the receipts. A blockchain maintains both the state hash and the receipt hash.

All the transaction generated is validated. Transaction validation involves checking the time-stamp and the nonce combination to be valid and the availability of sufficient fees for execution.

Miner nodes in the network receive, verify, gather, and execute transactions. The in-work smart contract code is executed by all the miners.

Validation transactions are broadcast and gathered for block creation. The consensus protocol used is a memory-based rather than a CPU based proof-of-work.

Incentive Model

Mining is the process used to secure the network by validating the computations, collecting them to form block, verifying them, and broadcasting them.

Ethereum also uses an incentive-based model for block creation. Every action in Ethereum requires crypto fuel or gas. Gas points are used to specify the fees inside of Ether, for ease of computation using standard values.

Gas points allow the cryptocurrency independent valuation of the transaction fee and computation fees.

Ether, as a cryptocurrency, varies in values with market swing, but the gas points don’t vary.

Ethereum has specified gas points for each type of operation. Mining process computes gas points required for the execution of a transaction. If the fee specified and the gas point in the transaction are not sufficient, it is rejected.

The gas points needed for execution must be in the account balance for the execution to happen. If there is any amount left over after the execution of the transaction, it is returned to the originating account.

Mining Incentive model

The Proof of Work(PoW) puzzle winner, the miner that creates a new block is incentivized with the base fees of three Ethers, and the transaction fees in Ethereum blockchain. The winning miner also gets the fees, gas points for the execution of smart contract transactions.

That there may be other miners who also solve the puzzle besides the winner. These miners will solve the puzzle but didn’t win the block are Ommers. The blocks create but they are called Ommer blocks. These are added as side blocks to the main chain.

Ommer miners also get a small percentage of the total gas points as a consolation and for network security.

References

  1. What is Ethereum?
  2. Ether
  3. How Ethereum Works
  4. Etherscan
  5. Introduction to Smart Contracts
  6. Smart Contracts: A White Paper
  7. What Is Meant By The Term “Gas”?
  8. Proof of Work vs Proof of Stake: Basic Mining Guide

https://twitter.com/thecapital_io


Blockchain basics(Part-2) was originally published in The Capital on Medium, where people are continuing the conversation by highlighting and responding to this story.



from The Capital - Medium https://ift.tt/3j0yeRS

Post a Comment

0 Comments