Professional Documents
Culture Documents
Blockchain TIC
Blockchain TIC
Source: Blockchain.com
Bitcoin Hash Rate
■ It is a measure of how many times the Bitcoin network can attempt to solve
Proof of Work (POW) puzzle per second for mining.
■ The more hashing power in the network, the greater its security and overall
resistance to 51% attack.
Halving of Bitcoin Rewards
Halving of Bitcoin rewards:
■ Every 210,000 blocks (approx. 4 yrs)
■ Maintains a controlled supply of currency. As reduced supply leads to
an increased demand.
■ Previous halvings:
– Jan 2009: 50 BTC
– Nov 2012: 25 BTC
– Jul 2016: 12.5 BTC
– May 2020: 6.25 BTC
■ Next halving:
– At block 740,000, approx in April, 2024
– Block reward: 3.125 BTC
Bitcoin - Gaining Value
■ 1st Bitcoin transfer: from Satoshi Nakamoto to Hal Finney.
■ May, 2010: Laszlo Hanyecz purchased $25 worth of pizza for 10,000 BTC.
■ 2010: Jed McCaleb creates Mt. Gox, the biggest online bitcoin exchange.
■ 2014: Mt. Gox loses 744,408 bitcoins in a theft; Mt. Gox declares
bankruptcy.
Bitcoin- Gaining Value
■ Feb 2011: Silk Road
opens as the anonymous
“eBay of Drugs”, using
Tor and payments using
Bitcoin.
■ Oct 2013: the FBI shut
down Silk Road.
■ Bitcoin Boom:
Dec 2017: Bitcoin price
~ Rs. 13 lacs
Nov, 2021: 1 BTC ~ Rs.
47 lacs
Bitcoin - Gaining in Last 1 Year
Highest BTC value in Nov 2021, 1 BTC ~ Rs. 47 lacs
Currently, 1 BTC ~ Rs. 31.4 lacs (on Nov 24th, 2023)
Considered as
Digital Gold by
market experts.
Token pegged
to US dollar
ETH staked
in LIDO
liquidity
Token pegged protocol
to US dollar
Token on
Binance
blockchain
Token on
Cardano
blockchain
y256
2
= (x332+ 7) 9mod8 p 7 6 4
■p=2 –2 –2 –2 –2 –2 –2 –1
■ Security of Bitcoin is guaranteed by the inefficiency of Elliptic Curve
Discrete Logarithm Problem (ECDLP) solution for large enough
private keys.
i.e. finding the integer k such that P = k * G
Cryptography in Bitcoin
■ Ownership of Bitcoins is established through:
– Digital keys
– Digital signature
■ Use of Asymmetric cryptography in which a pair of keys
(public/private) is used.
■ Public key is used to receive funds and Private key is used to sign txns
to spend funds.
■ Private key, k is a 256 bit random number within 1 and 2256.
■ Public key, P is a point on elliptic curve generated from private key:
P=k*G
where, G is the generator for the elliptic curve
It is a one-way function and calculating P from k is not possible.
Cryptography in Bitcoin
Public key and Address generation:
Digital Signatures
■ Digital signatures are used in txns to provide authentication of who is
signing the transaction and integrity of the msg being signed.
■ It also provides non-repudiation which ensures that neither the sender or
receiver can deny participating in the communication.
■ Digital Signature used in Bitcoin:
– Elliptic Curve Digital Signature Algorithm (ECDSA)
– Schnorr Signature
Digital Signatures
Significance of Bitcoin
■ First ever cryptocurrency which is:
– purely digital,
– not controlled by any central entity,
– solves double spending issue.
■ Peer-to-peer network in which transactions directly between users; no
intermediary.
■ Transactions verified by network users.
■ Transactions recorded as block in public ledger- blockchain
Blockchain
Blocks are chained together using the previous block’s hash to form a
Blockchain.
Amount of Bitcoin
Txn fees = Output bitcoins - Input transferred
bitcoins
Blockchain Transaction
In a Bitcoin txn, each input spends the bitcoins paid to a previous output.
Receiver’s address
Blockchain Databases
Other than blockchain, each bitcoin client stores these databases as well:
UTXO set -
■ file that contains all the spendable o/p that are available to be spent in
a txn.
Mempool -
■ file that contains txns which are received by peer nodes but are yet to
be included in any block i.e. unconfirmed txns.
Hashing
Cryptographic hash function used: SHA256
Data changed in this block. Change in hash of next blocks. Requires re-mining of blocks.
Bitcoin Ledger
We can check ledger of bitcoin on a blockchain explorer like
blockchain.info, blockexplorer.com
Merkle Root combines the hash values of txns together until there is a
singular root (a Merkle tree root hash).
■ In case of 3 generals, 1
commander and 2 lieutenants, if 1
is faulty (Byzantine) and others
are loyal:
– Consensus cannot be achieved
as Lieutenant1 has received
conflicting msgs- Retreat,
Attack.
Four Generals’ Problem
■ In case of 4 generals, 1
commander (Byzantine) and 3
lieutenants (honest). Consensus
can be achieved as the received
msgs are:
– Lieutenant1- R, R, A
– Lieutenant2- R, R, A
– Lieutenant3- R, R, A
■ Final decision- Retreat.
Consensus achieved
n Generals’ Problem
More stake a user has in the system, the more likely it will want the
system to succeed thus expecting honest behavior.
Delegated Proof Of Stake
■ Stakeholders select a node (delegate) that proposes and validates a
block.
■ Delegates are selected using some lottery mechanism.
■ Delegates are scored based upon:
– Punctuality in block creation when selected.
– Creating valid blocks.
■ Blockchains like Ethereum and Cardano use DPoS, as they use
staking pools which other users can delegate to.
■ The more stake that is delegated to a stake pool, the greater chance it
has of being selected as a slot leader.
Risks in Cryptocurrency
A blockchain
network is
considered
anonymous as:
each user is
identified by its
address only and
can generate as
many addresses as
required.
Privacy Attacks on Blockchain
Using txn patterns and info gathered off the network, an adversary can
attempt to deanonymize the users
by mapping their bitcoin addresses with their real-world identities making
it pseudo-anonymous.
Txn Network Analysis: example
All input addresses belong to a same user as txn is generated from one
source.
Txn Network Analysis: example
Txn 1
Txn 2
All change addresses and Original Address belong to the same user.
Illegal Activity using Cryptocurrency
■ Wallet is a file that contains credentials, i.e. public and private keys
for a blockchain address.
■ In some blockchains like Bitcoin, wallet file is stored unencrypted by
default.
■ Malware attacks on host computer can led to wallet theft.
■ If adversary steals the file, they can sign txns on user’s behalf,
spending their balance.
Bitcoin Scripting Language
■ Bitcoin transaction script language: Script
• Stack-based execution language
• Simple language with limited operations
• Designed to be limited in scope and executable on a range of
hardware, perhaps as simple as an embedded device.
• Requires minimal processing
• Limited in operations as compared to modern programming
languages.
Bitcoin Transaction
Input Outputs
Bitcoin Locking Script
● Locking script is a spending condition placed on a Bitcoin transaction
output.
○ Specifies the conditions that must be met to spend the output in
the future.
○ Also called scriptPubKey, as it usually contains a public key or
bitcoin address (public key hash).
● A script is valid if the top and only element left on the stack is a 1 (or
greater).
Unlocking Locking
Script Script
Executing a Script
● P2PKH is the default script used by wallets when you want to send
someone bitcoins.
● Most common scripts used in transactions.
Working of P2PKH Script
● The P2PKH script pattern contains a hashed public key surrounded by
following shown opcodes.
2 04C16B8698A9ABF84250A7C3EA7EEDEF9897D1C8C6ADF47F06CF73370D74DCCA01CDCA79DCC5C395
D7EEC6984D83F1F50C900A24DD47F569FD4193AF5DE762C58704A2192968D8655D6A935BEAF2CA23
E3FB87A3495E7AF308EDF08DAC3C1FCBFC2C75B4B0F4D0B1B70CD2423657738C0C2B1D5CE65C97D7
8D0E34224858008E8B49047E63248B75DB7379BE9CDA8CE5751D16485F431E46117B9D0C1837C9D5
737812F393DA7D4420D7E1A9162F0279CFC10F1E8E8F3020DECDBC3C0DD389D99779650421D65CBD
7149B255382ED7F78E946580657EE6FDA162A187543A9D85BAAA93A4AB3A8F044DADA618D0872274
40645ABE8A35DA8C5B73997AD343BE5C2AFD94A5043752580AFA1ECED3C68D446BCAB69AC0BA7DF5
0D56231BE0AABF1FDEEC78A6A45E394BA29A1EDF518C022DD618DA774D207D137AAB59E0B000EB7E
D238F4D800 5 CHECKMULTISIG
P2SH Script
● P2SH means “pay to a script matching this hash, a script that will be
presented later when this output is spent.”
● Locking script that is replaced by a hash is referred to as the redeem
script because it is presented to the system at redemption time rather
than as a locking script.
Working of P2SH Script
Advantages of P2SH Script
● Complex scripts replaced by shorter fingerprints in the transaction output,
making the transaction smaller.
● P2SH shifts the burden of constructing the script to the recipient, not the
sender.
● P2SH shifts the burden in data storage for the long script from the output
(which is in the UTXO set) to the input (stored on the blockchain).
● P2SH shifts the burden in data storage for the long script from the present
time (payment) to a future time (when it is spent).
● P2SH shifts the transaction fee cost of a long script from the sender to the
recipient,who has to include the long redeem script to spend it.
Hash Lock Script
■ A txn output is locked until a specified data is revealed
■ It can be used in applications like atomic swaps where both parties cannot
swap their funds until a secret used to lock the txn, is exchanged between
them.
■ Output Script:
– OP_HASH160 <Hash value> OP_EQUALVERIFY OP_DUP OP_hash160 <hash of
public key> OP_EQUALVERIFY OP_CHECKSIG
■ Input Script:
– Sender has to reveal the secret such that its hash results in the hash mentioned in the
output lock.
– <Size of signature> <Signature> <Public key> <secret>
Time Lock Script
■ A txn output is locked until a specified time or a block height.
■ It can be used in applications like investing bitcoins until a point in time.
■ Output Script:
– Script to lock bitcoins until specified expiry time. After that the funds can be spent by
signing the output with the specified public key in the script
– <expiry time> OP_CHECKLOCKTIMEVERIFY OP_DROP OP_DUP OP_HASH160
<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
■ Input Script:
– Spent only after waiting for the expiry time to be reached.
– <Signature> <Public key>
Pay to Taproot (P2TR)
■ Taproot is a major Bitcoin upgrade rolled out in Aug, 2021.
■ Introduction of P2TR txns and Schnorr digital signatures in Bitcoin.
■ P2TR allows script path or key path spending of a txn output.
■ If a P2TR output is unlocked using key spending path, the possibility of
spending through a script path is not even revealed.
■ In case if a particular script path is used to unlock the output, the other
scripts are not revealed.
■ Saves space and transaction fee on the unused conditions to be specified by
the spending party in txn.
■ Increases the privacy of a contract between parties.
Features of P2TR
■ Indistinguishable locking and unlocking for spending bitcoins using key or
script path.
■ Alternative signature scheme- Schnorr signatures.
– Allows aggregation of public keys for multisignature txn, making it
appear as a single party signature on-chain.
■ Specifying txn spending paths in the form of a data structure called
Merkelized Abstract Syntax Tree(MAST).
■ Batch verification of multiple signatures. It saves time in individual
verification of each signature.
P2TR Transaction
■ Output locking script:
<Witness version 1> <32 Bytes Taproot Output Key>
■ Taproot output key: Q = P + hash(P || M) * G
Here,
P = Taproot internal key corresponding to key path spending. It can be the
public key whose signature is required for spending the output. In case of a
multisig txn, it can an aggregate public key.
M = Root of merkle tree whose leaves represent possible ways to unlock the
output.
G = Generator point of elliptic curve.
P2TR Transaction
■ Script Tree:
– All possible script paths for locking an output are arranged in a
merkle tree.
– Scripts are arranged as merkle tree leaf nodes.
P2TR Transaction
■ Key path spending, unlocking script:
<signature corresponding to taproot internal key, P>
■ Script path spending, unlocking script consists of following elements:
– Taproot internal key
– Script which is used to spend the output
– Inputs for successful execution of the script
– Merkle path from the unlocking script to the merkle tree root -
This confirms the presence of script in the tree
Blockchain 2.0
Blockchain applications also called as dApps (Decentralized
Applications) other than cryptocurrencies:
■ Supply chain management
■ Land Registry
■ Healthcare
and many more...
Blockchain in Healthcare
■ Blockchain allows for secure recording and sharing of medical
information in a ledger to:
– Verify integrity of patient health information.
– Perform unchangeable medical audits.
– Prove the integrity of clinical research results.
– Ensure data safety.
– Detect fraudulent drug dealers.
Blockchain 2.0: Smart Contract
Documentation: https://solidity.readthedocs.io/en/v0.7.0/
Editors:
Remix- https://remix.ethereum.org/
Visual Studio Code- extensions available for solidity
Ethereum Development Framework
Ethereum Development Framework
Coin.sol
A simple smart contract to
mint and send coins of a
cryptocurrency.
Attacks in Smart Contracts
If the code written in smart contract is not secure, it may lead to some
attacks:
■ Reentrancy Attacks:
– recursive calls to call.value() of the smart contract.
– happened in famous DAO hack in Ethereum in 2016.
– DAO is decentralized autonomous organization intended to act as
an automated company.
Attacks in Smart Contracts
■ Reentrancy Attacks:
– Less than 3 months after its launch, DAO was hacked and $60M of
ether was stolen.
Attacks in Smart Contracts
Contract code with DAO vulnerability: Contract code exploiting DAO vulnerability:
withdrawBalance() calls itself again and again:
If the code written in smart contract is not secure, it may lead to some
attacks:
■ Overflow Attack: Ethereum smart contracts don't support values
greater than 2256. Buffer overflow attacks might be created by having a
really large value.
■ Forcible Balance Transfer: If the contract is vulnerable, forcible
balance transfer can be done and limits can be exceeded.
■ DoS Attacks: Smart contract can be written with malicious intent
causing denial of service.
Ethereum Token Standards
Types of Txns:
■ Funds transfer between EOA.
■ Deploy contract on Ethereum blockchain.
■ Execute a function on a contract account.
Ethereum Txn
From: Txn sender who
initiates this txn.
State is the
information Change in state of Ethereum when txn is
about each made.
Ethereum
account.
Eth Account 1
Eth Account 2
Eth Account 3
Eth Account 4
Ethereum Txn
Client interacts with
DApp deployed on Ethereum application on blockchain.
blockchain. Cost Ethers.
Cost Ethers. A txn results in change of
Ethereum state.
Validated by miners.
Permissioned Blockchain
■ Permissioned blockchain controls:
– which user can join the network
– which user can participate in consensus and validate txns and
blocks
■ Such blockchains are preferred by the centralized organizations.
■ Users cannot:
– easily join the network
– view the history and issue txns
Hyperledger
■ Hyperledger is an open
source, enterprise-grade suite
of tools and frameworks for
a permissioned blockchain
solution development.
■ Hyperledger Fabric:
Framework for developing
blockchain apps with a
modular architecture.
Hyperledger
Linkability:
Ability to link all addresses
held by a single person by
analyzing txns.
Monero provides
untraceability by
using Ring
signatures.
Monero- Ring Signatures
Inputs in a txn-
■ Atleast one real participant and other mixins.
■ Mixins are outputs from some previous txns.
■ Ring signature created to sign the txn.
For a verifier, no way to tell who is the real participant, all appears valid
Monero- Ring Signatures
■ Find some outputs in the blockchain with the same amount X as the
output A you want to spend.
■ These other outputs are called “mixins”. All mixins of same value.
■ You can use 4-25 mixins in a txn.
■ You sign this txn using a ring signature.
Monero- Ring Signatures
■ It is easy to verify that at least one user from inputs have signed this
ring txn.
■ Not easy to find which user has signed the txn.
Monero- Ring Signatures
All inputs: mixins and real input are of same value.
Mixin 1
Real Input
Mixin 2
Mixin 3