Unit 3 Slides
Unit 3 Slides
Cryptocurrency
Fundamentals
Text Book: – II
Mastering Blockchain
Unlocking the Power of Cryptocurrencies and Smart Contracts
Authors
Lorne Lantz & Daniel Cawrey
Custody, Blockchain Wallet & Its Types and Variations
Anshuman Kalla 2
Custody and Blockchain
• Custody in generalWallet
means the protective care or responsibility of care and maintenance
• In financial services, custody refers to the ability to hold, move, and protect your
financial assets
• Digital wallet is an software application that allows to store funds, make digital
transactions, track payments, and perform more financial operations related to your
account
• Blockchain wallet or crypto wallet
• stores securely your cryptographic keys
• allows secure access to your digital assets or cryptos
• allows secure exchange or transfer of digital assets by sending out digitally signed transactions
• allows to track your accounts and balances
• allows to interact with decentralized applications (dApps)
• can be web or mobile application
Custodial v/s Noncustodial
Wallets
Custodial Wallet
• In custodial wallets, the user’s private key is stored and hold by a trusted entity
(for example an exchange)
• A user registers with such a trusted entity and their system stores user’s
information
• User login to their system to access his/her funds or make a transaction
• User always access blockchain via such a trusted entity
• Example – If you create a wallet using the services of Coinbase company
• Advantage: User need not worry about safe-keeping of the account and
key
• Disadvantage: If the exchange goes bankrupt or runs away with the funds, the
user cannot do anything as s/he does not directly own or control the keys.
• Thus, trust is the issue since user has to trust such services that provides
Custodial v/s Noncustodial
Wallets
Noncustodial Wallet
• In noncustodial wallet, the user’s private key is stored and hold by the user
himself or herself
• A user does not need to register anywhere and thus no need to provide
information such as email ID or mobile number for SMS
• User directly accesses blockchain without any entity in between
• Example – if you create wallet using Matamask
• Advantage: It gives complete control of keys to the users
• Disadvantage: Use is entirely responsible for securing their private keys
• Thus, if a user looses the key(s), that could result in complete and total
inaccessibility of his/her funds.
Wallet Type
Variations
• Two primary wallet types (custodial and noncustodial) can be implemented in a
variety of ways as shown in the following figure
Anshuman Kalla 14
Security
• Most important aspectFundamentals
is to keep private keys safe and secure
• If anattacker somehow gets access to your private key, then s/he can
sign transactions on your behalf and empty your wallet
• One of the main reasons of crypto frauds is authentication issues
• Means exposure of either private keys or password associated with wallets.
• There are certain ways to help prevent this from happening:
• Identity verification
• Two-factor authentication
Security
Identity Verification: Fundamentals
• Due to wide use of digital services, especially different messaging services, it is difficult
to say that the person other side is actually the same you are expecting
• Thus, it is important to verify a person with some personally known information or
other way
• Especially if someone starts making strange requests – asking for cryptocurrency
Two-factor Authentication:
• Turning on two-factor authentication in addition to password is suggested
• Two-factor authentication requires another source for verification
• One way is to use SMS verification using app like Authy or Google
authenticator (however this option is susceptible to porting)
• Second way is to use hardware device like the YubiKey.
Security Fundamentals - Type of Security
Attacks
Anshuman Kalla 17
Type of Security
Cell Phone Porting: Attacks
• Porting is when an attacker takes over your cell phone’s number to intercept incoming
messages
• To do so, the attacker calls the service provider by giving user’s personal information
• Thus, using SMS for two-factor authentication is at times not good idea
• Alternate option is to set up a portable VoIP phone number like Google Voice
Phishing:
• Attacker pretends to be familiar and trusted organization (e.g., government
agency/ well known company) and sends link via messages to collect user’s personal
information
• Spoofed email (from your boss or parentis) is one of the popular ways of phishing
• Although it may not look that serious attack but actually it is a most effective way to
obtain personal information
Recovery
Seed
Anshuman Kalla 19
Recovery Seed
• Recovery seed is a(Mnemonic)
series of words that can be used to retrieve a private key
stored in a noncustodial wallet
• Here series of words implies string of random numbers and letters
• Seed is commonly used as a memory aid as private key is difficult to remember
• Seed phrases usually store enough information to allow the user to
recover their wallet
• Example of recovery seed phrase:
witch collapse practice feed shame open despair creek road again ice least
• The recovery seed phrase is actually your “wallet,” and an attacker can easily
access your funds if s/he gets access to recovery seed phrase
• Thus it is utmost important when using noncustodial wallets to keep safe your
recovery seed
Recovery Seed (Mnemonic) – Important
• If youTips
record your recovery seed on paper, be
sure to laminate or make sure writing does
not fade away
• Etched metal recover seed storage device can
look like as shown in the figure
• The fact is that cryptocurrency can and
has been lost
• Use secure communication tools, set up two-
factor authentication, have a PIN with a
cellular carrier, and be aware of phishing
• Cryptocurrency once gone out of your wallet
cannot be retrieved!
Mining and Its
Incentives
• Mining is process of generating new block and minting new coins which are awarded to the
miner who successfully generates that new block.
• Mining started as hobby -- Early supporters of Bitcoin, simply downloaded and ran Bitcoin software
• In 2010, miner used to get 50 BTC as reward to mine a new block
• In 2010 since 1 BTC was $0.30, a wining miner would ear $15
• Soon the price of BTC went rocket high and mining become serious profession
• With greater mining rewards the difficulty of mining a new block also went up
• Jump from regular computer to Graphics Processing Units (GPUs) Application Specific
Integrated Circuits (ASICs)
• With access to cheap power and computing facilities, today we are seeing enterprise level
large-scale data center based mining
• Mining turned into gold rush!
• In Bitcoin, after every 2,10,000 (aprox. 4 years) the new BTC generated is reduced by 50%
Mining and Its
Incentives
• As like the price of BTC is volatile so is the mining revenue (rewards + transaction
fee)
Block Generation – Mining and
• InBitcoin Difficulty
blockchain a block is
every 10 minutes
generated
• Bitcoin uses Proof-of-Work (PoW)
consensus
algorithm
• A miner who wants to create a new block
needs to provide a proof of the sufficient
work done
• The work here is a cryptographic puzzle which
miners needs to do (i.e., solve)
• The difficulty in Bitcoin is adjusted
• The solution of that cryptographic puzzle by a
miner is considered as proof of the effort
every 2016 blocks
made • Difficulty acts as a controlling knob
• solve the cryptographic
The computing power andpuzzle is
the difficulty to ensure
to that a new block is mined every 10
increasing
rapidly with time. minutes irrespective of number of
participating miners
Consensus Mechanism and Its
Need is a way to establish an agreement between various
• Consensus mechanism
participants (nodes in the blockchain network) who have shared values and goals
• The agreement is on the state of the distributed digital ledger
Consensus
Mechanisms
Proof-Based Voting-Based
• Because of the focus on cryptocurrency and mining, next we discuss PoW and how it applies
to bitcoin.
• Note: Enterprise applications that use blockchain usually do not use PoW and do not require
miners. Anshuman Kalla
28
Proof-of-Work
(PoW)
• It enables cryptocurrency transactions to be confirmed and blocks to be
published on the Bitcoin blockchain
• First described in paper by Markus Jakobsson of Bell Labs and Ari Juels of RSA
Laboratories,
• Proof-of-Work (PoW) was initially created to bind economic value via computer processing
to otherwise free services, like email, in order to stop spam.
• As PoW requires computing power, it reduces the incentive to attack or flood a
system.
• The economic value provided in PoW is directly correlated to the price of the
electric power that is used in the mining process.
Proof-of-Work
• In PoW mining, a hashing (PoW)
is used to
verify data.
• A hash is output on the blockchain as
public proof using a hash algorithm
• The computer speed at which this is
done is known as the hash rate
(hashes/sec).
• With many cryptocurrencies, the power
used by PoW has become quite
substantial
• Massive computation and the related
power is what secures the network
• Although hash rates fluctuate, Bitcoin
has surpassed 70 million terahashes per
second in the past
Block
Discovery
• About every 10 minutes, a new block is confirmed by a wining miner
• As there are thousands of miners participating at any time, the network needs to
achieve consensus on which miner gets the right to confirm the new block
• To discover a new block, a miner has to generate a Bitcoin block hash that
is considered valid by the network, using the following criteria:
It is a hash of a valid (new) block header
The resulting block hash is a number that is lower than the current network target
• target – constantly changing number – always higher than a valid block hash.
• difficulty – average number of attempts required to discover a valid block hash.
• network hash rate – how many times per second the miners collectively attempt
to generate a valid block hash.
Block
Discovery
• The goal for the Bitcoin blockchain network, set in bitcoin’s initial parameters, is
as follows:
A new valid block should be discovered approximately every 10 minutes.
• Over time, the number of miners using computer processing power to discover a
block changes along with variables like electricity use and processing power,
among other factors.
• The processing power they are consuming is called the hash power.
• The miners are consuming this power to try to generate a valid Bitcoin block
hash.
Block
• The increase in hash powerDiscovery
implies (collectively) higher computer processing
power is available to generate a valid block hash
• Obviously, blockchain network (of miners) with more hash power will take less
time for the network to discover a new block
• Therefore, in order to maintain an average of 1 block being discovered every 10
minutes, the Bitcoin network changes the network target to make it more or less
difficult for the network of miners to discover a valid block hash
• The initial target value set for generating the first Bitcoin block was:
00000000ffff0000000000000000000000000000000000000000000000000000 Eight zeros
• The actual block hash of first block was smaller than the target value set:
Initial target (8 zeros) - 00000000ffff0000000000000000000000000000000000000000000000000000
Block #0 hash (10 zeros) - 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
Block
• When block #0 was Discovery
discovered, there was little competition in the Bitcoin
network to discover a block So, the target value was high (meaning easier)
• The difficulty at that moment was 1, meaning that on average it would require 1
attempt to generate a valid hash.
• Ten years later, there are thousands of miners consuming significantly more hash
power to discover a block. Therefore, the target 10 years later is a lower value,
requiring more attempts.
Start
with
nonce
=0
Proof-of-Stake (PoS) Consensus
• PoW requires heavy computation and huge power due to the mining process which
involves cryptographical operations
• Proof-of-Stake (PoS) does not require mining; the mining is replaced by staking in
PoS
• PoS was first used in 2012 by virtual currency Peercoin
– Latter used by other virtual currencies like Blockcoin and ShadowCoin
• Higher the stake, higher is the chance that a miner gets to mine a new block
Source: https://maxthake.medium.com/what-is-proof-of-stake-pos-479a04581f3a by Max Thake 40
Proof-of-Stake (PoS) Consensus
• If a node (i.e., validator) tries to add an illegal block then that will be self-
destruction
• Usually, the incentive to be paid to the validator comes from transaction
fees
• The nodes in PoS are selected based on different staking criteria such as:
– Size of the stake: How much amount of the coins a node has staked to get chance to
create new block?
– Age: For how long a node has been holding the coin it has staked?
– Wealth: Which node has being holding the staked coins for more than X duration of
time?
– Randomization: Selecting randomly one node to become validator out of the nodes
which have staked their coins 41
Proof-of-Stake (PoS) Consensus
• Advantages of PoS compared to PoW
– Since there is no mining thus less computation and hence less power is required to run
PoS low carbon footprints
– PoS gives more control to the nodes which have been participating (and are invested) in
the network for long time
• Disadvantages of PoS
– Provided with that fact that the control of the system lies with the nodes that have
been participating for long and are rich this results in making the network centralized
(defeating the aim that blockchain should be decentralized)
– PoS creates more divide between rich and poor nodes (rich nodes get more chance to add
new block and become richer) Rich becomes more rich and poor become more poor
42
Proof-of-Stake (PoS) Consensus
• To ensure fairness in block creation and to avoid the situation where rich nodes
becomes richer, PoS follows different techniques
• The idea is to add randomness
• One of the popular ways is ‘Coin Age’
– Product of the token staked by a node and the holding time (combined with random
selection)
– The node with highest coin age becomes the validator to add a new block
– Once, the winning node creates a new block its coin age is reset so that it cannot mine
another
block for some time