UNIT-2
Bitcoin Platform and Wallets
Dr. Ramu Kuchipudi
Associate Professor
Chaitanya Bharathi Institute of Technology
Department of Information Technology
Bitcoin Platform
Bitcoin Platform
• Bitcoin can be defined in various ways.
– It's a protocol
– A digital currency
– platform.
• It is a combination of peer-to-peer network,
protocols, and software that facilitate the creation
and usage of the digital currency named bitcoin.
• Bitcoin with a capital B is used to refer to the
Bitcoin protocol, whereas bitcoin with a lowercase
b is used to refer to bitcoin, the currency.
• Nodes in this peer-to-peer network talk to each
other using the Bitcoin protocol.
Bitcoin Platform
• Decentralization of currency was made
possible for the first time with the invention of
bitcoin.
• Moreover, the double spending problem was
solved in an elegant and ingenious way in
bitcoin.
• Double spending problem arises when, for
example, a user sends coins to two different
users at the same time and they are verified
independently as valid transactions.
Bitcoin Platform
• Keys and addresses
• Elliptic curve cryptography is used to generate public
and private key pairs in the Bitcoin network.
• The bitcoin address is created by taking the
corresponding public key of a private key and hashing
it twice, first with the SHA256 algorithm and then with
RIPEMD160. The resultant 160-bit hash is then
prefixed with a version number and finally encoded
with a Base58Check encoding scheme.
• The bitcoin addresses are 26-35 characters long and
begin with digit 1 or 3.
• A typical bitcoin address looks like a string shown here:
1ANAguGG8bikEv2fYsTBnRUmx7QUcK58wt
Bitcoin Platform
• bitcoin address is also commonly encoded in
a QR code for easy sharing. The QR code of
the preceding address is shown in the
following image:
Bitcoin Platform
• Currently, there are two types of addresses,
the commonly used P2PKH and another P2SH
type, starting with 1 and 3, respectively.
• In the early days, bitcoin used direct Pay-
toPubkey, which is now superseded by P2PKH.
Bitcoin Platform
Bitcoin Platform
• Public keys in bitcoin
– In public key cryptography, public keys are generated from
private keys.
– Bitcoin uses ECC based on the SECP256K1 standard.
– A private key is randomly selected and is 256-bit in length.
Public keys can be presented in an uncompressed or
compressed format.
– Public keys are basically x and y coordinates on an elliptic
curve and in an uncompressed format and are presented
with a prefix of 04 in a hexadecimal format.
– X and Y coordinates are both 32- bit in length.
– In total, the compressed public key is 33 bytes long as
compared to 65 bytes in the uncompressed format. The
compressed version of public keys basically includes only
the X part, since the Y part can be derived from it.
Bitcoin Platform
• Keys are identified by various prefixes,
described as follows:
– Uncompressed public keys used 0x04 as the
prefix
– Compressed public key starts with 0x03 if the y
32-bit part of the public key is odd
– Compressed public key starts with 0x02 if the y
32-bit part of the public key is even
Bitcoin Platform
• Private keys in bitcoin
– Private keys are basically 256-bit numbers chosen in the
range specified by the SECP256K1 ECDSA
recommendation. Any randomly chosen 256-bit number
from 0x1 to 0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFE
BAAE DCE6 AF48 A03B BFD2 5E8C D036 4140 is a valid
private key.
– Private keys are usually encoded using Wallet Import
Format (WIF) in order to make them easier to copy and
use. WIF can be converted into private key and vice versa.
– Also, Mini Private Key Format is sometimes used to
encode the key in under 30 characters in order to allow
storage where physical space is limited.
– The bitcoin core client also allows the encryption of the
wallet that contains the private keys.
Bitcoin Platform
• The transaction life cycle
• 1. A user/sender sends a transaction using wallet
software or some other interface.
• 2. The wallet software signs the transaction using
the sender's private key.
• 3. The transaction is broadcasted to the Bitcoin
network using a flooding algorithm.
• 4. Mining nodes include this transaction in the
next block to be mined.
• 5. Mining starts once a miner who solves the
Proof of Work problem broadcasts the newly
mined block to the network.
Bitcoin Platform
• The transaction life cycle
• 6. The nodes verify the block and propagate the
block further, and confirmation starts to generate.
• 7. Finally, the confirmations start to appear in the
receiver's wallet and after approximately six
confirmations, the transaction is considered
finalized and confirmed. However, six is just a
recommended number; the transaction can be
considered final even after the first confirmation.
The key idea behind waiting for six confirmations
is that the probability of double spending is
virtually eliminated after six confirmations.
Transaction structure
Transaction structure
Transaction structure
Transaction structure
• Transactions are also chained together.
• Bitcoin wallet software gives the impression
that satoshis are sent from and to wallets, but
bitcoins really move from transaction to
transaction.
• Each transaction spends the satoshis
previously received in one or more earlier
transactions, so the input of one transaction is
the output of a previous transaction.
Transaction structure
Transaction structure
• A transaction at a high level contains
metadata, inputs, and outputs.
• Transactions are combined to create a block.
Transaction structure
• Each transaction has at least one input and one
output.
• Each input spends the satoshis paid to a previous
output.
• Each output then waits as an Unspent
Transaction Output (UTXO) until a later input
spends it.
• When your Bitcoin wallet tells you that you have
a 10,000 satoshi balance, it really means that you
have 10,000 satoshis waiting in one or more
UTXOs.
Transaction structure
Transaction structure
• MetaData: This part of the transaction contains some values
such as the size of the transaction, the number of inputs and
outputs, the hash of the transaction, and a lock_time field.
Every transaction has a prefix specifying the version number.
• Inputs: Generally, each input spends a previous output. Each
output is considered an Unspent Transaction Output (UTXO)
until an input consumes it.
• Outputs: Outputs have only two fields, and they contain
instructions for the sending of bitcoins. The first field
contains the amount of Satoshis, whereas the second field is
a locking script that contains the conditions that need to be
met in order for the output to be spent.
• Verification: Verification is performed using bitcoin's
scripting language.
Transaction structure
Sending Payments
Sending Payments
Double Spending
Bitcoin Script
Bitcoin Script
Bitcoin Script
Bitcoin Script
Bitcoin Script
Bitcoin Script
• So, traditionally bitcoin uses two scripts one is
corresponds to the signature which we call as
the scriptSig and another script corresponds
to the public key that is the scriptPubKey.
• scriptPubKey basically tells you that how you
can use the pub key to validate the
corresponding signature.
Bitcoin Script
The script language
• Bitcoin uses a simple stack-based language
called script to describe how bitcoins can be
spent and transferred.
• It is not Turing complete and has no loops to
avoid any undesirable effects of long
running/hung scripts on the bitcoin network.
• This scripting language is based on a Forth-like
syntax and uses a reverse polish notation in
which every operand is followed by its
operators. It is evaluated from the left to the
right using a Last in First Out (LIFO) stack.
The script language
• Scripts use various Opcodes or instructions to
define their operation.
• The various categories of the scripting
Opcodes are
– Constants
– flow control
– Stack
– bitwise logic
– splice and arithmetic
– Cryptography and lock time
Bitcoin Script
The script language
• A transaction script is evaluated by combining ScriptSig
and ScriptPubKey.
• ScriptSig is the unlocking script, whereas ScriptPubKey
is the locking script. This is how a transaction is
evaluated to be spent; first, it is unlocked and then it is
spent.
• ScriptSig is provided by the user who wishes to unlock
the transaction.
• ScriptPubkey is part of the transaction output and
specifies the conditions that need to be fulfilled in
order to spend the output. In other words, outputs are
locked by the ScriptPubKey (Locking script) that
contains the conditions, when met will unlock the
output, and coins can then be redeemed.
Commonly used Opcodes
Bitcoin Script
Bitcoin Script
Bitcoin Script
Bitcoin Script
Bitcoin Script
Bitcoin Script
Bitcoin Script
Bitcoin Script
Consensus mechanism in bitcoin
• POW
• POS
• POB
• POET
Consensus mechanism in bitcoin
• Proof of Work
• This is a proof that enough computational
resources have been spent in order to build a
valid block.
• Proof of Work (PoW) is based on the idea that a
random node is selected every time to create a
new block.
• In this model, nodes compete with each other
in order to be selected in proportion to their
computing capacity.
Consensus mechanism in bitcoin
Consensus mechanism in bitcoin
• The following equation sums up the Proof of Work
requirement in bitcoin:
• H ( N || P_hash || Tx || Tx || . . . Tx) < Target
• Where N is a nonce, P_hash is a hash of the previous
block, Tx represents transactions in the block, and Target is
the target network difficulty value.
• This means that the hash of the concatenated fields
should be less than the target hash value.
• The only way to find this nonce is the brute force method.
• Once a certain pattern of a certain number of zeroes is
met by a miner, the block is immediately broadcasted and
accepted by other miners.
Consensus mechanism in bitcoin
• The mining algorithm
• The mining algorithm consists of the following
steps.
• The previous hash block is retrieved from the
bitcoin network.
• Assemble a set of potential transactions
broadcasted on the network into a block.
• Compute the double hash of the block header
with a nonce and the previous hash using the
SHA256 algorithm.
Consensus mechanism in bitcoin
• The mining algorithm
• If the resultant hash is lower than the current
difficulty level (target), then stop the process.
• If the resultant hash is greater than the
current difficulty level (target), then repeat the
process by incrementing the nonce.
• Mining difficulty increased over time and
bitcoins that could be mined by single CPU
laptop computers now require dedicated
mining centers to solve the hash puzzle.
Wallets
• The wallet software is used to store private or
public keys and bitcoin address.
• It performs various functions, such as
receiving and sending bitcoins.
• Nowadays, software usually offers both
functionalities: bitcoin client and wallet.
• BIP-Bitcoin improvement proposals
Wallets
• On the disk, the bitcoin core client wallets are stored
as the Berkeley DB file:
• :~/.bitcoin$ file wallet.dat wallet.dat
• Private keys can be generated in different ways and
are used by different types of wallets.
• Wallets do not store any coins, and there is no
concept of wallets storing balance or coins for a user.
• In the bitcoin network, coins do not exist; instead,
only transaction information is stored on the
blockchain (more precisely, UTXO, unspent outputs),
which are then used to calculate the amount of
bitcoins.
Wallets
• Wallet types In bitcoin, there are different types of
wallets that can be used to store private keys.
• As a software program, they also provide some
functions to the users to manage and carry out
transactions on the bitcoin network.
– Non-deterministic wallets
– Deterministic wallets
– Hierarchical deterministic wallets
– Brain wallets
– Paper wallets
– Hardware wallets
– Online wallets
– Mobile wallets
Wallets
• Non-deterministic wallets
– These wallets contain randomly generated private
keys and are also called Just a Bunch of Key wallets.
– The bitcoin core client generates some keys when
first started and generates keys as and when
required.
– Managing a large number of keys is very difficult
and an errorprone process can lead to theft and
loss of coins.
– Moreover, there is a need to create regular
backups of the keys and protect them
appropriately in order to prevent theft or loss.
Wallets
• Deterministic wallets
– In this type of wallet, keys are derived out of a
seed value via hash functions.
– This seed number is generated randomly and is
commonly represented by human-readable
mnemonic code words.
– Mnemonic code words are defined in BIP39. This
phrase can be used to recover all keys and makes
private key management comparatively easier.
Wallets
• Hierarchical deterministic wallets
– Defined in BIP32 and BIP44, HD wallets store keys in
a tree structure derived from a seed.
– The seed generates the parent key (master key),
which is used to generate child keys and,
subsequently, grandchild keys.
– Key generation in HD wallets does not generate
keys directly; instead, it produces some information
(private key generation information) that can be
used to generate a sequence of private keys.
– The complete hierarchy of private keys in an HD
wallet is easily recoverable if the master private key
is known.
Wallets
• Brain wallets
– The master private key can also be derived from
the hash of passwords that are memorized.
– The key idea is that this passphrase is used to
derive the private key and if used in HD wallets,
this can result in a full HD wallet that is derived
from a single memorized password. This is known
as brain wallet.
– This method is prone to password guessing and
brute force attacks but techniques such as key
stretching can be used to slow down the progress
made by the attacker.
Wallets
• Paper wallets
– As the name implies, this is a paper-based wallet
with the required key material printed on it.
– It requires physical security to be stored.
– Paper wallets can be generated online from
various service providers, such as
https://bitcoinpaperwallet.com/ or
https://www.bi taddress.org/.
Wallets
• Hardware wallets
– Another method is to use a tamper-resistant
device to store keys.
– This tamper-resistant device can be custom-built
or with the advent of NFC-enabled phones, this
can also be a secure element (SE) in NFC phones.
– Trezor and Ledger wallets (various types) are the
most commonly used bitcoin hardware wallets.
Wallets
• Hardware wallets
Wallets
• Online wallets
– Online wallets, as the name implies, are stored
entirely online and are provided as a service
usually via cloud.
– They provide a web interface to the users to
manage their wallets.
– perform various functions such as making and
receiving payments.
– They are easy to use but imply that the user trust
the online wallet service provider.
Wallets
• Mobile wallets
– Mobile wallets, as the name suggests, are installed
on mobile devices.
– They can provide various methods to make
payments, most notably the ability to use smart
phone cameras to scan QR codes quickly and
make payments.
– Mobile wallets are available for the Android
platform and iOS, for example, breadwallet, copay,
and Jaxx.
Wallets
• Mobile wallets
Bitcoin payments
• Bitcoins can be accepted as payments using
various techniques.
• Bitcoin is not recognized as a legal currency in
many jurisdictions, but it is increasingly being
accepted as a payment method by many
online merchants and e-commerce websites.
• There are a numbers of ways in which buyers
can pay the business that accepts bitcoins.
Bitcoin payments
• Business can use the following screenshot to
advertise that they can accept bitcoins as
payment.
Bitcoin payments
• Various payment solutions, such as
xbtterminal and 34 bytes bitcoin POS terminal
are available commercially. (point of sale)
Bitcoin payments
• BIP 70 (secure payment protocol) describes
the protocol for secure communication
between a merchant and customers.
• This protocol uses X.509 certificates for
authentication and runs over HTTP and HTTPS.
• There are three messages in this protocol:
PaymentRequest, Payment, and PaymentACK.
Bitcoin payments
• Bitcoin investment and buying and selling
bitcoins
• There are many online exchanges where users
can buy and sell bitcoins. Ex. Cex.io
Bitcoin payments
• The following screenshot shows the order
book at the exchange where all buy and sell
orders are listed:
Bitcoin payments
Alternative Coins
• Since the initial success of bitcoin, many alternative
currency projects have been launched.
• Bitcoin was released in 2009 and the first alternative
coin project (named Namecoin) was introduced in
2011.
• In 2013 and 2014, the altcoin market grew
exponentially and many different types of alternative
coin project were started.
• Namecoin
• Litecoin
• Zcash
• https://coinmarketcap.com/
Alternative Coins
• Namecoin is a cryptocurrency originally forked
from bitcoin software. It uses proof-of-work
algorithm. Like bitcoin, it is limited to 21
million. Namecoin can store data within its
own blockchain transaction database.
• Code: NMC
• Hash function: SHA-256
• Ledger start: 17 April 2011 (12 years ago)
• Project fork of: Bitcoin
• Supply limit: 21,000,000
Alternative Coins
• Litecoin is a decentralized peer-to-peer cryptocurrency and
open-source software project released under the MIT/X11
license. Inspired by Bitcoin, Litecoin was among the earliest
altcoins, starting in October 2011. In technical details, the
Litecoin main chain shares a slightly modified Bitcoin
codebase.
• Symbol: Ł
• Block reward: Ł6.25 (as of August, 2 2023), (halved
approximately every four years)
• Code repository: github.com/litecoin-project/litecoin
• Developer(s): Litecoin Core Development Team
• Exchange rate: US$105 (July 2023)
• Hash function: scrypt
• Supply limit: Ł84,000,000
Alternative Coins
• Zcash is a privacy-focused cryptocurrency which is
based on Bitcoin's codebase. It shares many
similarities, such as a fixed total supply of 21 million
units.
• Initial release date: 28 October 2016
• Developer: Zooko Wilcox-O'Hearn, Matthew D. Green
• Block explorer: explorer.zcha.in
• Code: ZEC
• Issuance schedule: Similar to Bitcoin, with "slow start"
and different block interval
• Latest release: 5.4.2 / 13 March 2023; 5 months ago
• Operating system: Linux, Windows, macOS
Alternative Coins