0% found this document useful (0 votes)
15 views

Unit 2

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Unit 2

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Blockchain

UNIT - 2
Ethereum

 Ethereum was proposed in 2013 and brought to life in 2014 by Vitalik Buterin.
 Unlike the Bitcoin network which was designed for Bitcoin transactions only, Ethereum is a DIY
platform for decentralized apps (or Dapps) that uses smart contracts.
 ‘Ether’ is Ethereum network’s currency and it is used for running Dapps.
Bitcoin vs. Blockchain

 Before we get into what Ethereum is we need to do a quick recap about Bitcoin, since it’s the
basis from which Ethereum was born.
 By now you probably know that Bitcoin is a form of decentralized money.
 Bitcoin was invented, the only way to use money digitally was through an intermediary such as
a bank, or Paypal. Even then, the money used was still a government issued and controlled
currency.
 However, Bitcoin changed all that by creating a decentralized form of currency that individuals
could trade directly without the need for an intermediary. Each Bitcoin transaction is validated
and confirmed by the entire Bitcoin network. There’s no single point of failure so the system is
virtually impossible to shut down, manipulate or control.
From Bitcoin to Blockchain

 Well, now that we know that money can be decentralized, what other functions of society that
are centralized today would be better served on a decentralized system?
 What about voting? Voting requires a central authority to count and validate votes. Real estate
transfer records currently use centralized property registration authorities. Social networks like
Facebook are based on centralized servers that control all of the data we upload to them.
 What if we could use the technology behind Bitcoin, more commonly known as Blockchain, to
decentralize other things as well?
 The interesting thing about Blockchain technology is that it’s actually a by product of the
Bitcoin invention.
 Blockchain technology was created by fusing already existing technologies like cryptography,
proof of work and decentralized network architecture together in order to create a system that
can reach decisions without a central authority.
From Bitcoin to Blockchain

 There was no such thing as “blockchain technology” before Bitcoin was invented. But once Bitcoin
became a reality, people started noticing how and why it works and named this “thing” blockchain
technology.
 Blockchain is to Bitcoin what the Internet is to email. A system, on top of which you can build
applications and programs. A currency like Bitcoin is just one of the options.
 So this got people very excited, and they began to explore what else can we decentralize.
 However, in order for a system to be truly decentralized it needs a large network of computers to run
it. Back then the only network that existed was Bitcoin and it was pretty limited.
 Bitcoin is written in what is known as a “turing incomplete” language which makes it understand only
a small set of orders (like who sent how much money to whom). If you want to create a more
complex system, you’ll need a different programming language, which means a different network of
computers.
 Imagine for a second you wanted to build your own decentralized program, just like Bitcoin, at
home. You’d need to understand how Bitcoin’s decentralization works, write code that mimics the
same behaviour, get a huge network of computers to run this code and so on….that’s a lot of work.
What is Ethereum?

 Ethereum was first proposed in late 2013 and then brought to life in 2014 by Vitalik Buterin who
back at the time was the co-founder of Bitcoin Magazine.
 Ethereum is the Do It Yourself platform for decentralized programs also known as Dapps –
decentralized apps.
 If you want to create a decentralized program that no single person controls (not even you
even though you wrote it), all you have to do is learn the Ethereum programming language
called Solidity and begin coding.
 The Ethereum platform has thousands of independent computers running it meaning it’s fully
decentralized. Once a program is deployed to the Ethereum network these computers, also
known as nodes, will make sure it executes as written.
 Ethereum’s goal is to truly decentralize the Internet. Many people believe the Internet already is
decentralized and that anyone can start their own site.
What is Ethereum?

 While in theory that might be true, in practice Amazon, Google, Facebook, Netflix and other
giants control most of the world wide web as we know it. There’s almost no activity on the web
that happens without some sort of intermediary or 3rd party.
 But once the concept of digital decentralization was demonstrated by Bitcoin, a whole new
array of opportunities became available.
 We can finally start to imagine and design an Internet that connects users directly without the
need for centralized 3rd parties.
 People can “rent” hard drive space directly to other people and make Dropbox obsolete.
Drivers can offer their services directly to passengers and remove “Uber” as the middleman.
People can buy cryptocurrencies directly from one another without the need for an exchange
that can get hacked or steal your money.
 Ethereum allows people to connect directly with each other without a central authority to take
care of things. It’s a network of computers that together combine into one powerful,
decentralized supercomputer.
How Ethereum Works – Smart Contracts?

 Now we know what Ethereum does but we haven’t touched upon HOW it does it.
 Ethereum’s coding language, Solidity, is used to write “Smart Contracts” that are the logic that
runs Dapps.
 In real life, all a contract is, is a set of “Ifs” and “Thens”. Meaning a set of conditions and actions.
For example – if I pay my landlord $1500 on the 1st of the month Then he lets me use my
apartment.
 That’s exactly how smart contracts work on Ethereum. Ethereum developers write the
conditions for their program or Dapp and then the Ethereum network executes it.
 They are called smart contracts because they deal with all of the aspects of the contract –
enforcement, management, performance, and payment.
 For example, if I have a smart contract that is used for paying rent, the landlord doesn’t need
to actively collect the money from me. The contract itself “knows” if the money has been sent.
If I indeed sent the money, then I will be able to open my apartment door. If I miss my payment,
I will be locked out.
How Ethereum Works – Smart Contracts?

 However smart contracts also have their downsides. Going back to my previous example,
instead of having to kick out a renter that isn’t paying, a “smart” contract would lock the non-
paying renter out of their apartment.
 A truly intelligent contract on the other hand, would take into account other factors as well,
such as extenuating circumstances, the spirit with which the contract was written and it would
also be able to make exceptions if warranted. In other words, it would act like a really good
judge.
 Instead, a “smart contract” in the context of Ethereum is not intelligent at all. It’s actually
uncompromisingly letter strict. It follows the rules down to a T and can’t take any secondary
considerations or the “spirit” of the law into account like what commonly happens with real
world contracts.
 Once a smart contract is deployed on the Ethereum network, it can not be edited or
corrected, even by its original author. It’s immutable.
How Ethereum Works – Smart Contracts?

 The only way to change a smart contract would be to convince the entire Ethereum network
(i.e. all the computers participating around the world) that a change should be made and
that’s virtually impossible.
 This creates a very serious problem since unlike Bitcoin, Ethereum was built with the ability to
create really complex contracts, and complex contracts are very difficult to secure.
 With any contract, the more complicated it is, the harder it is to enforce as more room is left for
interpretations, or more clauses must be written to deal with contingencies.
 With smart contracts, security means handling with perfect accuracy every possible way in
which a contract could be executed in order to make sure that the contract does only what
the author intended.
 Ethereum launched with the idea that “code is law”. That is, a contract on Ethereum is the
ultimate authority and nobody could overrule the contract.
 This all came to a crashing halt when the DAO event happened.
The DAO – When smart contracts go
wrong
 The DAO stands for “Decentralized Autonomous Organization” which allowed users to deposit
money and get returns based on the investments that the DAO made.
 The decisions themselves would be crowd-sourced and decentralized. The DAO raised $150M
in Ethereum currency, – ether. When Ether was trading at around $20.
 While this all sounded very good, the code wasn’t secured very well and resulted in someone
figuring out a way to drain the DAO out of money.
 Now you could say that the person who drained the DAO was a “hacker”. But some would
argue that this was just someone that was taking advantage of the loopholes he found in the
DAO’s smart contract.
 This isn’t very different from a creative lawyer figuring out a loophole in the current law to effect
a positive result for his client.
The DAO – When smart contracts go
wrong
 What happened next is that the Ethereum community decided that code no longer is law and
changed the Ethereum rules in order to revert all the money that went into the DAO. In other
words, the contract writers and investors did something stupid and the Ethereum developers
decided to bail them out.
 The small minority that didn’t agree with this move stuck to the original Ethereum Blockchain
before its protocol was altered and that’s how Ethereum Classic was born (which is actually the
original Ethereum).
Ether – Ethereum’s currency

 We’ve already established that Ethereum is basically a large bunch of computers working
together like one super computer to execute code that powers Dapps. However this costs
money – Money to get the machines, to power them up, store them and cool them if needed.
 That’s why Ether was invented. When people talk about the price of Ethereum they actually are
referring to Ether – the currency that incentivizes people to run the Ethereum protocol on their
computer.
 This is very similar to the way Bitcoin miners get paid for maintaining the Bitcoin blockchain.
 In order to deploy a smart contract to the Ethereum platform, its author must pay to do so. That
payment is made in the form of ether. This is done so that people will write optimized and
efficient code and won’t waste the Ethereum network computing power on unnecessary tasks.
 Ether was first distributed in Ethereum’s original Initial Coin Offering back in 2014. Back then it
cost around 40 cents to buy one Ether. Today, one Ether is valued in hundreds of dollars since
the use of the Ethereum network has grown immensely due to the ICO hype that started in
2017.
Ethereum Virtual Machine (EVM)

 The EVM’s physical instantiation can’t be described in the same way that one might point to a
cloud or an ocean wave, but it does exist as one single entity maintained by thousands of
connected computers running an Ethereum client.
 The Ethereum protocol itself exists solely for the purpose of keeping the continuous,
uninterrupted, and immutable operation of this special state machine; It's the environment in
which all Ethereum accounts and smart contracts live. At any given block in the chain,
Ethereum has one and only one 'canonical' state, and the EVM is what defines the rules for
computing a new valid state from block to block.
EVM - From Ledger To State Machine

 The analogy of a 'distributed ledger' is often used to describe blockchains like Bitcoin, which
enable a decentralized currency using fundamental tools of cryptography. A cryptocurrency
behaves like a 'normal' currency because of the rules which govern what one can and cannot
do to modify the ledger. For example, a Bitcoin address cannot spend more Bitcoin than it has
previously received. These rules underpin all transactions on Bitcoin and many other
blockchains.
 While Ethereum has its own native cryptocurrency (Ether) that follows almost exactly the same
intuitive rules, it also enables a much more powerful function: smart contracts. For this more
complex feature, a more sophisticated analogy is required. Instead of a distributed ledger,
Ethereum is a distributed state machine. Ethereum's state is a large data structure which holds
not only all accounts and balances, but a machine state, which can change from block to
block according to a pre-defined set of rules, and which can execute arbitrary machine code.
The specific rules of changing state from block to block are defined by the EVM.
EVM
Given an old valid state (S) and a new set of valid transactions (T), the Ethereum state transition function Y(S, T) produces a new valid output state S'

EVM - The Ethereum State Transition


Function
 The EVM behaves as a mathematical function would: Given an input, it produces a
deterministic output. It therefore is quite helpful to more formally describe Ethereum as having
a state transition function:
Y(S, T)= S‘

 Given an old valid state (S) and a new set of valid transactions (T), the Ethereum state transition function Y(S, T)
produces a new valid output state S‘
 State -In the context of Ethereum, the state is an enormous data structure called a modified
Merkle Patricia Trie, which keeps all accounts linked by hashes and reducible to a single root
hash stored on the blockchain.
 Transactions - Transactions are cryptographically signed instructions from accounts. There are
two types of transactions: those which result in message calls and those which result in contract
creation.
 Contract creation results in the creation of a new contract account containing compiled smart
contract bytecode. Whenever another account makes a message call to that contract, it
executes its bytecode.
Given an old valid state (S) and a new set of valid transactions (T), the Ethereum state transition function Y(S, T) produces a new valid output state S'

EVM - Instructions

 The EVM executes as a stack machine with a depth of 1024 items. Each item is a 256-bit word,
which was chosen for the ease of use with 256-bit cryptography (such as Keccak-256 hashes or
secp256k1 signatures).
Given an old valid state (S) and a new set of valid transactions (T), the Ethereum state transition function Y(S, T) produces a new valid output state S'

EVM - Instructions

 During execution, the EVM maintains a transient memory (as a word-addressed byte array), which does not
persist between transactions.
 Contracts, however, do contain a Merkle Patricia storage trie (as a word-addressable word array), associated with
the account in question and part of the global state.
 Compiled smart contract bytecode executes as a number of EVM opcodes, which perform standard stack
operations like XOR, AND, ADD, SUB, etc. The EVM also implements a number of blockchain-specific stack
operations, such as ADDRESS, BALANCE, BLOCKHASH, etc.
Given an old valid state (S) and a new set of valid transactions (T), the Ethereum state transition function Y(S, T) produces a new valid output state S'

The Mist browser

 What is Ethereum Mist?


 Blockchain technology and smart contract platforms such as Ethereum enable a computing
paradigm termed decentralized applications (DApps). In contrast to traditional web
applications that rely on a centralized backend or web server, the idea behind DApps is to
have applications that are censorship-resistant and do not rely on a single point of failure. The
Ethereum Mist was intended to facilitate the attainment of this vision.
 Instead of using centralized servers, DApps replace the backend with blockchain-deployed
smart contracts. The frontend code that is executed in the user’s browser can be distributed
through decentralized storage solutions, such as the Interplanetary Files System (IPFS), which
stores content on a peer-to-peer (P2P) network.
 The purest way of running DApps is for users to load the front-end code of the DApp from a
decentralized filesystem, or use their own local copy, and connect to the blockchain-based
smart contract backend using their own node software. This was the philosophy of the now
deprecated Ethereum Mist wallet and browser, which enabled users to interact with Ethereum-
based DApps.
Given an old valid state (S) and a new set of valid transactions (T), the Ethereum state transition function Y(S, T) produces a new valid output state S'

The Mist browser

 Mist is an Ethereum wallet implementing the full DApp stack. It was envisioned as a wallet software
covering all types of Ethereum DApps. In fact, Ethereum Mist treats the cryptocurrency wallet as one
type of DApp, amongst many others. As a DApp browser, Mist is a standalone application with a
graphical user interface that allows syncing to the blockchain. It also provides an easy way for users to
create their own DApps and deploy tokens and other smart contracts in a non-technical way.
 To achieve all this Ethereum Mist provides the following components:
• A full node implementation syncing to the Ethereum blockchain. In fact, Mist bundles the Go Ethereum software.
• A web application layer that allows visualizing web-based user interfaces for DApps.
• The web3.js library, allowing web interfaces to interact with the blockchain and smart contracts.
• A set of standard DApps that can be deployed through Mist.
 Ethereum Mist’s goal was to bring DApps to the end-user in a user-friendly way while maintaining a
philosophy of full decentralization. The project failed to achieve this and development was finally frozen,
in favor of other approaches.
Given an old valid state (S) and a new set of valid transactions (T), the Ethereum state transition function Y(S, T) produces a new valid output state S'

The Mist browser

 Reasons for Deprecation


 In 2019 the developers of Ethereum Mist took the decision to abandon the project and deprecate the
browser. There are a number of reasons behind this decision, as outlined by the developers
themselves. However, one reason for the failure of Mist resides in a fundamental problem of the fully
decentralized DApp approach, namely the fact that running a full blockchain node to interact with the
Ethereum network is not viable for most users.
 Blockchain networks, in general, scale badly with current technology and running a blockchain node is
extremely resource-intensive. In its pure form, Mist needed to be constantly synced to the Ethereum
blockchain to be used, requiring Gigabytes of storage, and most importantly, very high-speed disk IO.
Simply syncing a new installation to the current state of the network may take days, and keeping up to
date requires around-the-clock connectivity and places a large strain on disk write activity. These
drawbacks essentially mean that current technology does not support a fully decentralized philosophy
for DApps in a convenient and user-friendly way.
Given an old valid state (S) and a new set of valid transactions (T), the Ethereum state transition function Y(S, T) produces a new valid output state S'

The Mist browser

 Alternatives to Ethereum Mist


 As an alternative to the full-stack local node model, lightweight alternatives have emerged. Modern
browsers allow web3 access through JavaScript endpoints that are injected into the browser. Together
with wallet plugins, such as MetaMask, these allow managing keys and executing DApp frontends
locally, while the Ethereum connection is handled by a remote service, for example,
the Infura Ethereum gateway. This model makes it possible to run DApps from resource constraint
devices, such as mobile phones, without the need for constant connection and long sync times.
 Centralization Issues
 While the current model is clearly more efficient, it means that DApps can at best be considered
partially decentralized. While providers, such as Infura, probably act with good intentions, they are still
centralized points of failure, which break the fully censorship-resistant model. By not running their own
nodes, end-users of DApps lose the ability to verify transactions themselves, and the network itself
becomes less distributed and resilient.
 The deprecation of Ethereum Mist has shown that there still is a long way to go to make the philosophy
of a decentralized web fully viable.
Given an old valid state (S) and a new set of valid transactions (T), the Ethereum state transition function Y(S, T) produces a new valid output state S'

 The Bank Teller Metaphor, Breaking with Banking History, How Encryption Leads to Trust, System
Requirements, Using Parity with Geth, Anonymity in Cryptocurrency, Central Bank Network, Virtual
Machines, EVM Applications, State Machines, Guts of the EVM, Blocks, Mining’s Place in the State
Transition Function, Renting Time on the EVM, Gas, Working with Gas, Accounts, Transactions, and
Messages, Transactions and Messages, Estimating Gas Fees for Operations, Opcodes in the EVM.

 For all this topic read from Page 86 to 103 of University_M.Sc.IT-Part-II-Bolck-Chain-Semester-


IV_compressed (university Notes)
Given an old valid state (S) and a new set of valid transactions (T), the Ethereum state transition function Y(S, T) produces a new valid output state S'

Solidity Programming: Introduction

 Solidity is a brand-new programming language created by the Ethereum which is


the second-largest market of cryptocurrency by capitalization, released in the
year 2015 led by Christian Reitwiessner. Some key features of solidity are listed
below:
 Solidity is a high-level programming language designed for implementing smart
contracts.
 It is statically-typed object-oriented(contract-oriented) language.
 Solidity is highly influenced by Python, c++, and JavaScript which runs on the Ethereum
Virtual Machine(EVM).
 Solidity supports complex user-defined programming, libraries and inheritance.
 Solidity is primary language for blockchains running platforms.
 Solidity can be used to creating contracts like voting, blind auctions, crowdfunding,
multi-signature wallets, etc.
Given an old valid state (S) and a new set of valid transactions (T), the Ethereum state transition function Y(S, T) produces a new valid output state S'

Solidity Programming

 Global Banking Made Real, Complementary Currency, Programming the EVM, Design Rationale,
Importance of Formal Proofs, Automated Proofs, Testing, Formatting Solidity Files, Reading Code,
Statements and Expressions in Solidity, Value Types, Global Special Variables, Units, and Functions
 For all above topics read chapter 4 from page 70 to 88 of introducing ethereum and solidity book

You might also like