UNIT - 4 Notes
UNIT - 4 Notes
DEPARTMENTOFCOMPUTERSCIENCEANDENGINEERING
.
ALTERNATE APPROACHES TO CONSENSUS AND MINING
Some alternate approaches that might have emerged or gained prominence:
1. Delegated Proof of Stake (DPoS): DPoS is a variation of PoS where token
holders vote for a limited number of delegates who are responsible for
validating transactions and creating new blocks. These delegates are chosen
based on the number of votes they receive. DPoS aims to increase scalability
by reducing the number of validators compared to traditional PoS systems.
In a DPoS system, token holders in the network have the
power to elect a limited number of delegates who will be responsible for
validating transactions and creating new blocks on behalf of the entire
network. These delegates, also known as "witnesses" or "block producers,"
are chosen through a voting process based on the number of tokens they hold
or have been delegated to them.
The DPoS process typically works as follows:
a. Voting: Token holders in the network vote for their preferred
delegates. The weight of their votes is determined by the number of
tokens they hold or have staked.
b. Delegates Selection: The delegates with the highest number of votes
become the active block producers. The number of active delegates is
limited to a fixed number, which helps maintain network efficiency
and decentralization.
c. Block Production: The active delegates take turns in producing new
blocks in a round-robin manner. Each delegate gets a chance to
produce a block in a specific order, and this rotation ensures that the
responsibility of block production is distributed fairly among the
chosen delegates.
d. Block Verification: After a delegate produces a block, it is
broadcasted to the network. Other delegates and participants in the
network then verify the validity of the block and the transactions it
contains.
e. Consensus: If the majority of the delegates agree that the block is
valid, it is added to the blockchain. Consensus is achieved through a
combination of voting and the reputation of the delegates.
Cons:
Lower popularity and smaller market cap: Altcoins have a smaller
investment market compared to Bitcoin. Bitcoin has generally hovered
around 40% of the global cryptocurrency market since May of 2021.8
Less liquid than Bitcoin: The altcoin market is characterized by fewer
investors and less activity, resulting in thin liquidity.
Difficult to determine use cases: It is not always easy to distinguish
between different altcoins and their respective use cases, making investment
decisions even more complicated and confusing.
Many altcoins are scams or lost developer and community interest:
There are several "dead" altcoins that ended up sinking investor dollars.
Ethereum definition
Ethereum is a decentralized blockchain network powered by the Ether token that
enables users to make transactions, earn interest on their holdings through staking,
use and store nonfungible tokens (NFTs), trade cryptocurrencies, play games, use
social media and so much more.
How does Ethereum work?
Like Bitcoin, the Ethereum network exists on thousands of computers
worldwide, thanks to users participating as “nodes,” rather than a centralized
server. This makes the network decentralized and highly immune to attacks, and
essentially unable to go down as a result. If one computer goes down, it doesn’t
matter because thousands of others are holding the network up.
Ethereum is essentially a single decentralized system that runs a computer called
the Ethereum Virtual Machine (EVM). Each node holds a copy of that
computer, meaning that any interactions must be verified so everyone can update
their copy.
Network interactions are otherwise considered “transactions” and are stored within
blocks on the Ethereum blockchain. Miners validate these blocks before
committing them to the network and acting as transaction history or a digital
ledger. Mining to verify transactions is known as a proof-of-work (PoW)
consensus method. Each block has a unique 64-digit code identifying it. Miners
commit their computer power to find that code, proving that it’s unique. Their
computer power is “proof” of that work, and miners are rewarded in ETH for their
efforts.
Also, like Bitcoin, all Ethereum transactions are entirely public. Miners
broadcast completed blocks to the rest of the network, confirming the change and
adding the blocks to everyone’s copy of the ledger. Confirmed blocks cannot be
tampered with, serving as a perfect history of all network transactions.
Each transaction comes with a fee, called “gas,” which is paid by the user initiating
the said transaction. That fee is paid to the miner who validates the transaction,
incentivizing future mining and ensuring network security. Gas essentially serves
as a limit, restricting the number of actions a user can make per transaction. It’s
also in place to prevent network spam.
Because ETH is more of a utility token than a token of value, its supply is infinite.
Ether consistently enters circulation in the form of miner rewards, and it will with
staking rewards as well once the network moves to proof-of-stake (PoS). In theory,
Ether will always be in demand, meaning inflation should never devalue the asset
beyond use.
Ethereum gas fees can run quite high based on network activity. This is because
a block can only hold so much gas which varies based on transaction types and
amounts. As a result, miners will choose transactions with the highest gas fees,
meaning users are competing to validate transactions first. This competition pushes
fees higher and higher, congesting the network during busy times.
Network congestion is a significant problem, though it’s being addressed in
Ethereum 2.0 — a complete overhaul that will be discussed as a separate section.
Interacting with Ethereum requires cryptocurrency, which is stored in a wallet.
That wallet connects to DApps, acting as a passport for the Ethereum ecosystem.
From there, anyone can purchase items, play games, lend money and do all sorts of
activities just as they do on the traditional internet. Only, the traditional web is free
to users, as they’re giving away personal information. Centralized entities running
websites then sell that data to make money.
Cryptocurrency takes the place of data here, meaning users are free to browse and
interact anonymously. This also means DApp use is nondiscriminatory. For
example, no lending or banking DApp can reject someone based on their race or
financial status. An intermediary can’t block what they consider a “suspicious
transaction.” Users control what they do and how they do it, which is why many
consider Ethereum to be Web 3.0 — the future of web interaction.
Ethereum Mining
The process of creating a block of transactions to be added to the Ethereum
blockchain is referred to as mining. Ethereum currently uses a proof-of-work
blockchain but is moving to proof-of-stake (PoS) with Ethereum 2.0 for scalability
purposes and a more environmentally friendly approach.
Ethereum miners are computers that run the software and use their time and
processing power to process transactions and create blocks. Network participants
must ensure that everyone agrees on sequencing transactions in decentralized
systems like Ethereum. Miners assist in this by generating blocks by solving
computationally challenging riddles, thereby safeguarding the network from
attackers.
Bitcoin Vs Ethereum
Smart Contract Smart contracts on Bitcoin are Smart contracts on Ethereum are
Programming written in programming written in programming languages
Language languages like Script, Clarity. like Solidity, Vyper, etc.
Rewards Miner got nearly 6.25 BTC on Miner got nearly 5 BTC along with
Basis Bitcoin Ethereum
Advantages of Ethereum
1. Decentralization
2. Anonymity
3. Lack of censorship. For example, if someone tweets something offensive,
Twitter can choose to take it down and punish that user. However, on an
Ethereum-based social media platform, that can only happen if the
community votes to do it. That way, users with different viewpoints can
discuss as they see fit, and the people can decide what should and shouldn’t
be said.
4. Community requirements also prevent bad actors from taking over.
Someone with ill intentions would need to control 51% of the network to
make a change, which is nearly impossible in most cases. It’s much safer
than a simple server that can be broken into.
5. There are smart contracts, which automate many of the steps taken by
central authorities on the traditional web. A freelancer on, for example,
Upwork must use the platform to find clients and set up payment contracts.
Upwork’s business model takes a percentage of each contract to pay its
employees, server costs, etc. On Web 3.0, a client can simply write a smart
contract that states, “If the work is turned in at X time, the funds will be
released.” The rules are hard-coded into the contract and cannot be tampered
with by either party once written.
Disadvantages of Ethereum
1. Scalability. Due to the PoW consensus algorithm, interaction is limited by
block validation times and gas fees. Furthermore, decentralization is a
hindrance. A central entity, like Visa, manages everything and has
perfected the transaction process.
3. web3.js API: Once a Solidity contract is compiled with solc and sent to the
network, you can call it using the Ethereum web3.js JavaScript API and
build web apps that interact with contracts. (No need to install this yet, read
up on DApp Frameworks below first.)
Solidity
Solidity is a brand-new programming language created by Ethereum which
is the second-largest market of cryptocurrency by capitalization, released in
the year 2015 and 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 a statically typed object-oriented(contract-oriented) language.
Solidity is highly influenced by Python, c++, and JavaScript which run on
the Ethereum Virtual Machine(EVM).
Solidity supports complex user-defined programming, libraries, and
inheritance.
Solidity is the primary language for blockchains running platforms.
Solidity can be used to create contracts like voting, blind auctions,
crowdfunding, multi-signature wallets, etc.
Smart Contracts
Smart contracts refer to high-level program codes compiled into EVM
before being posted to the Ethereum blockchain for execution.
It enables you to conduct trustworthy transactions without the involvement
of a third party; these transactions are traceable and irreversible.
Programming languages commonly used to create and write smart contracts
are Serpent, Solidity, Mutan, and LLL.
Pragmas are directives to the compiler about how to handle the code. Every
line of solidity source code should begin with a "version pragma," which
specifies which version of the solidity compiler to use.
This prevents the code from being incompatible with future compiler
versions that may introduce changes.
The Contract Keyword
This is a function named “set” of access modifier type public which takes a
variable a and variable b of data type uint as a parameter.
This was an example of a simple smart contract that updates the value of
var1 and var2. Anyone with access to the Ethereum blockchain can use the
set function to change the value of var1 and var2.
By adding the values of the variables var1 and var2, it can calculate the
variable sum.
It will retrieve and print the value of the state variable sum using the “get”
function.
How to Execute the Code
You can execute a Solidity Program in two ways -
1. Offline Mode
2. Online Mode
Offline Mode
To operate a Solidity smart contract in Offline mode, it must meet three conditions
and follow four essential actions:
Conditions
1. Download and install node.js.
2. Install Truffle globally.
3. Install ganache-cli.
Actions
1. Create a truffle project and set up a development network for it.
2. Develop and deploy a smart contract for it.
3. From the Truffle console, interact with the smart contract.
4. Create tests to evaluate Solidity's primary features.
Online Mode
In the Online Mode, the Remix IDE is typically used to compile and run Solidity
smart contracts.