You are on page 1of 61

IoT 607 : IoT Security Block Chain Raghudathesh G P

IoT 607: IoT Security


Block Chain:
Crypto-currencies, Bitcoin P2P network, distributed consensus, incentives and
proof-of-work, mining, scripts and smart contracts, wallets: hot and cold storage,
anonymity, altcoins, IOTA (next generation Blockchain) (6 Hrs)

P
BY:

G
RAGHUDATHESH G P
Asst Professor
Dept of ECE, GMIT

SH
Davangere - 577004
Cell: +91-7411459249
Mail: datheshraghu@gmail.com
Website: raghudathesh.weebly.com
EYoutube: dathu’s class
TH
Suggested Reading:
Books:
DA

1. Mastering Bitcoin: Unlocking Digital Cryptocurrencies, by Andreas Antonopoulos


Blockchain by Melanie Swa, O’Reilly,2014.
2. A. Narayanan et al., “Bitcoin and Cryptocurrency Technologies: A Comprehensive
U

Introduction”, Princeton University Press, 2016.


3. Hyperledger Fabric - https://www.hyperledger.org/projects/fabric
GH

4. Zero to Blockchain - An IBM Redbooks course, by Bob Dill, David Smits -


https://www.redbooks.ibm.com/Redbooks.nsf/RedbookAbstracts/crse0401.html
RA

Hands-On Blockchain with Hyperledger:


1. Public github repository with code samples:
https://github.com/HyperledgerHandsOn/trade-finance-logistics

SOIS, Manipal raghudathesh.weebly.com Page 1


IoT 607 : IoT Security Block Chain Raghudathesh G P

Online Courses:
1. Blockchain Architecture Design and Use Cases, NPTEL:
https://onlinecourses.nptel.ac.in/noc18_cs47/preview
Youtube Link:
https://www.youtube.com/watch?v=PPFsG92-
HiI&list=PLbRMhDVUMngfxxyVLh2t2gKDUfsOdGn56&index=1
2. Blockchain Basics by University at Buffalo & The State University of New York,

P
Coursera: https://www.coursera.org/learn/blockchain-basics/home/info
3. Blockchain A-Z™: Learn How To Build Your First Blockchain, Udemy:

G
https://www.udemy.com/build-your-blockchain-az/

SH
Quotes:
 Life is what happens to us while we are busy making other plans.
 Temporary people give permanent lessons.
 E
Be selective with your battles - Sometimes peace is better than being right.
TH
 Seeking satisfaction through accumulation increases accumulation not satisfaction.
 Sometimes we're taken into troubled waters not to drown, but to be cleansed.
 Nobody can go back & start a new beginning but anyone can start today & make a
DA

new ending.
U
GH
RA

SOIS, Manipal raghudathesh.weebly.com Page 2


IoT 607 : IoT Security Block Chain Raghudathesh G P

What is Block Chain:


 Blockchain, the technology behind Bitcoin, seems to be the driving technology behind
the next generation of Internet, also referred to as the Decentralized Web, or the Web3.
 Blockchain is a novel solution to the age-old human problem of trust. It provides an
architecture for so-called trustless trust. It allows us to trust the outputs of the system
without trusting any actor within it.

P
Blockchain is a distributed database technology where chain is a continuously growing
list of records, called blocks, which are linked and secured using cryptography that

G
provides very hard to tamper, ledger records.
 A Blockchain protocol operates on top of the Internet, on a P2P Network of computers

SH
that all run the protocol and hold an identical copy of the ledger of transactions, enabling
P2P value transactions without a middleman though machine consensus.
 Blockchain itself a file – a shared and public ledger of transactions that records all


E
transactions from the genesis block (first block) until today.
TH
Each block typically contains a cryptographic hash of the previous block, a timestamp,
and transaction data.
 Blocks are the key concept of the technology. They are small sets of transactions that
DA

have taken place within the system. Each new block stores reference of the previous
transaction by including a SHA-256 hash of the previous transaction. In this way, it
creates a „chain‟ of blocks and hence the name.
U

 By design, a blockchain is resistant to modification of the data. It is “an open, distributed


GH

ledger that can record transactions between two parties efficiently and in a verifiable and
permanent way”.
 The security comes from use of strong public-key cryptography, strong cryptographic
RA

hash and complete decentralization, maintains a distributed ledger.


 For use as a distributed ledger, a blockchain is typically managed by a peer-to-peer
network collectively adhering to a protocol for inter-node communication and validating
new blocks.
 Once recorded, the data in any given block cannot be altered retroactively without
alteration of all subsequent blocks, which requires collusion of the network majority.

SOIS, Manipal raghudathesh.weebly.com Page 3


IoT 607 : IoT Security Block Chain Raghudathesh G P

 Blocks are computationally difficult to create, and takes multiple specialized processors
and significant amounts of time to generate.
 Since generating a block is difficult and to tamper one block, one has to tamper the
previous block and then has to follow the chain to change it completely, blockchain
technology is considered to be tamper resistant.
 Miners are the ones who run powerful computers to create blocks.
 The blockchain is an ingenious invention – the brainchild of a person or group of people

P
known by the pseudonym, Satoshi Nakamoto.

G
The invention of the blockchain for bitcoin made it the first digital currency without the need
of a trusted authority or central server. The bitcoin design has inspired other applications.

SH
The Concept of blockchain is shown below

E
TH
U DA
GH
RA

Figure: What is Blockchain


 Following figure shows how blockchain gets its name and 3 main concepts behind its
development

SOIS, Manipal raghudathesh.weebly.com Page 4


IoT 607 : IoT Security Block Chain Raghudathesh G P

P
G
E SH
TH
U DA
GH
RA

Figure: How Blockchain Gets Its Name

SOIS, Manipal raghudathesh.weebly.com Page 5


IoT 607 : IoT Security Block Chain Raghudathesh G P

 Application:

P
G
SH
Figure: Application of Blockchain

 Ecosystem: E
TH
URL: https://techcrunch.com/2017/10/16/mapping-the-blockchain-project-ecosystem/
U DA
GH
RA

Figure: Blockchain Ecosystem

SOIS, Manipal raghudathesh.weebly.com Page 6


IoT 607 : IoT Security Block Chain Raghudathesh G P

What is Double-Spending?
 Suppose that Alice wants to pay Bob 1$. If Alice and Bob use physical cash, then Alice
will not longer have the 1$ after the transaction is executed.
 If Alice and Bob use digital money, then the problem gets more complicated. Digital
money is in digital form and can be easily duplicated.
 If Alice sends a digital file worth 1$ to Bob by email for example, Bob cannot know for

P
sure if Alice has deleted her copy of the file. If Alice still has the 1$ digital file, then she
can choose to send the same file to Carol. This problem is called double-spending.

G
E SH
TH
U DA
GH

Figure: Double Spending


RA

 One way of solving the double-spending problem is to have a trusted third party (a bank
for example) between Alice, Bob and all other participants in the network.
 This third party is responsible for managing a centralized ledger that keeps track of and
validates all the transactions in the network. The drawback of this solution is that for the
system to function, it requires trust in a centralized third party.

SOIS, Manipal raghudathesh.weebly.com Page 7


IoT 607 : IoT Security Block Chain Raghudathesh G P

Bitcoin: A Decentralized Solution for the Double-Spending Problem:


 To solve the double-spending problem, Satoshi proposed a public ledger, i.e., Bitcoin‟s
blockchain to keep track of all transactions in the network. Bitcoin‟s blockchain has the
following characteristics:
1. Distributed: The ledger is replicated across a number of computers, rather than being
stored on a central server. Any computer with an internet connection can download a

P
full copy of the blockchain.
2. Cryptographic: Cryptography is used to make sure that the sender owns the bitcoin

G
that she's trying to send, and to decide how the transactions are added to the
blockchain.

SH
3. Immutable: The blockchain can be changed in append only fashion. In other words,
transactions can only be added to the blockchain but cannot be deleted or modified.
4. Uses Proof of Work (PoW): A special type of participants in the network called

E
miners compete on searching for the solution to a cryptographic puzzle that will allow
them to add a block of transactions to Bitcoin‟s blockchain. This process is called
TH
Proof of Work and it allows the system to be secure.
U DA
GH

Figure: Physical v/s Digital Cash

Sending Bitcoin Money Goes as Follows:


RA

 Step 1 (one-time effort): Create a bitcoin wallet. For a person to send or receive
bitcoins, she needs to create a bitcoin wallet. A bitcoin wallet stores 2 pieces of
information: A private key and a public key. The private key is a secret number that
allows the owner to send bitcoin to another user, or spend bitcoins on services that accept
them as payment method. The public key is a number that is needed to receive bitcoins.
The public key is also referred to as bitcoin address (not entirely true, but for simplicity

SOIS, Manipal raghudathesh.weebly.com Page 8


IoT 607 : IoT Security Block Chain Raghudathesh G P

we will assume that the public key and the bitcoin address are the same). Note that the
wallet doesn‟t store the bitcoins themselves. Information about bitcoins balances are
stored on the Bitcoin‟s blockchain.
 Step 2: Create a bitcoin transaction. If Alice wants to send 1 BTC to Bob, Alice needs to
connect to her bitcoin wallet using her private key, and create a transaction that contains
the amount of bitcoins she wants to send and the address where she wants to send them
(in this case Bob‟s public address).

P
 Step 3: Broadcast the transaction to Bitcoin‟s network. Once Alice creates the bitcoin
transaction, she needs to broadcast this transaction to the entire Bitcoin‟s network.

G
 Step 4: Confirm the transaction. A miner listening to Bitcoin‟s network authenticates the
transaction using Alice's public key, confirms that Alice has enough bitcoins in her wallet

SH
(in this case at least 1 BTC), and adds a new record to Bitcoin‟s Blockchain containing
the details of the transaction.

E
Step 5: Broadcast the blockchain change to all miners. Once the transaction is confirmed,
the miner should broadcast the blockchain change to all miners to make sure that their
TH
copies of the blockchain are all in sync.
DA

Terminologies:
1. Block:
 A block is a container data structure, which brings together transactions for
U

inclusion in the public ledger, known as the blockchain.


 The block is made up of:
GH

1. A header: containing metadata.


2. A long list of transactions.

RA

A block can be identified in two ways:


1. referencing the block hash
2. Through referencing the block height.
 Blocks are files where data is permanently recorded.
 A single blockheader consists of the following fields:

SOIS, Manipal raghudathesh.weebly.com Page 9


IoT 607 : IoT Security Block Chain Raghudathesh G P

P
G
SH
Figure: Structure of a Block
 The block header is 80 bytes, whereas the average transaction is at least 250 bytes
E
and the average block contains more than 500 transactions.
TH
 A complete block, with all transactions, is therefore 1,000 times larger than the
block header.
 Each block in a chain is distributed across the network and are stored
DA

independently from one another.

a. Block Header:
U

 The block header consists of three sets of block metadata. Metadata is data that
GH

provides information about other data.


 There is a reference to a previous block hash, which connects this block
to the previous block, lying in the blockchain.
 This metadata relates to the mining competition; namely the difficulty,
RA

timestamp and nonce.


 This piece of metadata is the Merkle Tree root; a data structure used to
summarize all the transactions in the block in an efficient manner.

SOIS, Manipal raghudathesh.weebly.com Page 10


IoT 607 : IoT Security Block Chain Raghudathesh G P

P
Figure: Data Structure of a BlockHeader

G
b. Block Identifiers:

SH
I. Block Header Hash:
 The primary identifier of a block is its cryptographic hash, a digital
fingerprint, made by hashing the block header through the SHA256

E
algorithm. The resulting 32-byte hash is called the block hash but is more
TH
accurately the block header hash, because only the block header is used to
compute it.
 E.x: 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a
DA

8ce26f is the block hash of the first bitcoin block ever created.
 The block hash identifies a block uniquely and unambiguously and can
be independently derived by any node by simply hashing the block header.
U

 Note that the block hash is not actually included inside the block‟s data
GH

structure, neither when the block is transmitted on the network, nor when
it is stored on a node‟s persistence storage as part of the blockchain.
 Instead, the block‟s hash is computed by each node as the block is
RA

received from the network.


 The block hash might be stored in a separate database table as part of the
block‟s metadata, to facilitate indexing and faster retrieval of blocks from
disk.
II. Block Height:
 The first block ever created is at block height 0 (zero) and is the same
block that was previously referenced by the following block

SOIS, Manipal raghudathesh.weebly.com Page 11


IoT 607 : IoT Security Block Chain Raghudathesh G P

hash 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60
a8ce26f.
 Each subsequent block added “on top” of that first block is one position
“higher” in the blockchain, like boxes stacked one on top of the other. The
block height on January 1, 2014, was approximately 278,000, meaning
there were 278,000 blocks stacked on top of the first block created in
January 2009.

P
 The block height is also not a part of the block‟s data structure; it is not
stored within the block.

G
 Each node dynamically identifies a block‟s position (height) in the
blockchain when it is received from the bitcoin network.

SH
 The block height might also be stored as metadata in an indexed database
table for faster retrieval.
c. The Genesis Block:

E
The first block in the blockchain is called the genesis block and was created in
TH
2009.
 It is the common ancestor of all the blocks in the blockchain, meaning that if you
DA

start at any block and follow the chain backward in time, you will eventually
arrive at the genesis block.
 Every node always starts with a blockchain of at least one block because the
U

genesis block is statically encoded within the bitcoin client software, such that it
cannot be altered.
GH

 Every node always “knows” the genesis block‟s hash and structure, the fixed time
it was created, and even the single transaction within. Thus, every node has the
starting point for the blockchain, a secure “root” from which to build a trusted
RA

blockchain.
 See the statically encoded genesis block inside the Bitcoin Core client,
in chainparams.cpp.
 The following identifier hash belongs to the genesis block:
000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f

SOIS, Manipal raghudathesh.weebly.com Page 12


IoT 607 : IoT Security Block Chain Raghudathesh G P

 You can search for that block hash in any block explorer website, such as
blockchain.info, and you will find a page describing the contents of this block,
with a URL containing that hash:
https://blockchain.info/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f

https://blockexplorer.com/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f

 An genesis block is as as shown below

P
G
E SH
TH
U DA

Figure: Genesis Block


 Using the Bitcoin Core reference client on the command line:
GH

$ bitcoind getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f


{
"hash" :
"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
"confirmations" : 308321,
"size" : 285,
RA

"height" : 0,
"version" : 1,
"merkleroot" :
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
"tx" : [
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
],
"time" : 1231006505,
"nonce" : 2083236893,
"bits" : "1d00ffff",
"difficulty" : 1.00000000,

SOIS, Manipal raghudathesh.weebly.com Page 13


IoT 607 : IoT Security Block Chain Raghudathesh G P

"nextblockhash" :
"00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048"
}

d. Linking Blocks in the Blockchain:


 Bitcoin full nodes maintain a local copy of the blockchain, starting at the genesis
block.
 The local copy of the blockchain is constantly updated as new blocks are found

P
and used to extend the chain. As a node receives incoming blocks from the
network, it will validate these blocks and then link them to the existing

G
blockchain.
 To establish a link, a node will examine the incoming block header and look

SH
for the “previous block hash.”
 Ex: A node has 277,314 blocks in the local copy of the blockchain. The last block
the node knows about is block 277,314, with a block header hash of
E
TH
00000000000000027e7ba6fe7bad39faf3b5a83daed765f05f7d1b71a1632249

 The bitcoin node then receives a new block from the network, which it parses as
follows:
DA

{
"size" : 43560,
"version" : 2,
"previousblockhash" :
U

"00000000000000027e7ba6fe7bad39faf3b5a83daed765f05f7d1b71a1632249",
"merkleroot" :
"5e049f4030e0ab2debb92378f53c0a6e09548aea083f3ab25e1d94ea1155e29d",
GH

"time" : 1388185038,
"difficulty" : 1180923195.25802612,
"nonce" : 4215469401,
"tx" : [
"257e7497fb8bc68421eb2c7b699dbab234831600e7352f0d9e6522c7cf3f6c77",
RA

#[... many more transactions omitted ...]

"05cfd38f6ae6aa83674cc99e4d75a1458c165b7ab84725eda41d018a09176634"
]
}
 Looking at this new block, the node finds the previous blockhash field, which
contains the hash of its parent block.

SOIS, Manipal raghudathesh.weebly.com Page 14


IoT 607 : IoT Security Block Chain Raghudathesh G P

 It is a hash known to the node, that of the last block on the chain at height
277,314. Therefore, this new block is a child of the last block on the chain and
extends the existing blockchain.
 The node adds this new block to the end of the chain, making the blockchain
longer with a new height of 277,315.
 Figure below shows the chain of three blocks, linked by references in the previous
blockhash field.

P
G
E SH
TH
U DA

Figure: Blocks linked in a chain, by reference to the previous block header hash
GH

e. Merkle Trees:
 A merkle tree, also known as a binary hash tree, is a data structure used for
efficiently summarizing and verifying the integrity of large sets of data. Merkle
RA

trees are binary trees containing cryptographic hashes.


 Merkle trees are used in bitcoin to summarize all the transactions in a block,
producing an overall digital fingerprint of the entire set of transactions, providing
a very efficient process to verify whether a transaction is included in a block.
A Merkle tree is constructed by recursively hashing pairs of nodes until there is
only one hash, called the root, or merkle root. The cryptographic hash algorithm

SOIS, Manipal raghudathesh.weebly.com Page 15


IoT 607 : IoT Security Block Chain Raghudathesh G P

used in bitcoin‟s merkle trees is SHA256 applied twice, also known as double-
SHA256.
 When N data elements are hashed and summarized in a merkle tree, you can
check to see if any one data element is included in the tree with at
most 2*log2(N) calculations, making this a very efficient data structure.
 The merkle tree is constructed bottom-up.

P
Merkle Tree Example:
 We start with four transactions, A, B, C and D, which form the leaves of the

G
Merkle tree, as shown in Figure below.

E SH
TH
U DA

Figure: Calculating the nodes in a Merkle Tree


GH

 The transactions are not stored in the merkle tree; rather, their data is hashed and
the resulting hash is stored in each leaf node as HA, HB, HC, and HD:
RA

H~A~ = SHA256(SHA256(Transaction A))

 Consecutive pairs of leaf nodes are then summarized in a parent node, by


concatenating the two hashes and hashing them together. For example, to
construct the parent node HAB, the two 32-byte hashes of the children are
concatenated to create a 64-byte string. That string is then double-hashed to
produce the parent node‟s hash:

SOIS, Manipal raghudathesh.weebly.com Page 16


IoT 607 : IoT Security Block Chain Raghudathesh G P

H~AB~ = SHA256(SHA256(H~A~ + H~B~))

 The process continues until there is only one node at the top, the node known as
the Merkle root. That 32-byte hash is stored in the block header and summarizes
all the data in all four transactions.
 Because the merkle tree is a binary tree, it needs an even number of leaf nodes. If
there is an odd number of transactions to summarize, the last transaction hash will

P
be duplicated to create an even number of leaf nodes, also known as a balanced
tree. This is shown in figure below where transaction C is duplicated.

G
E SH
TH
U DA
GH

Figure: Duplicating one data element achieves an even number of data


 The same method for constructing a tree from four transactions can be generalized
to construct trees of any size.

RA

In bitcoin it is common to have several hundred to more than a thousand


transactions in a single block, which are summarized in exactly the same way,
producing just 32 bytes of data as the single merkle root.
 In figure below, a tree is built from 16 transactions. Note that although the root
looks bigger than the leaf nodes in the diagram, it is the exact same size, just 32
bytes. Whether there is one transaction or a hundred thousand transactions in the
block, the merkle root always summarizes them into 32 bytes.

SOIS, Manipal raghudathesh.weebly.com Page 17


IoT 607 : IoT Security Block Chain Raghudathesh G P

P
G
Figure: A Merkle Tree Summarizing Many Data Elements

SH
 To prove that a specific transaction is included in a block, a node only needs to
produce log2(N) 32-byte hashes, constituting an authentication path or merkle
E
path connecting the specific transaction to the root of the tree.
TH
 The above is especially important as the number of transactions increases,
because the base-2 logarithm of the number of transactions increases much more
DA

slowly. This allows bitcoin nodes to efficiently produce paths of 10 or 12 hashes


(320–384 bytes), which can provide proof of a single transaction out of more than
a thousand transactions in a megabyte-size block.
U

 Ex: A node can prove that a transaction K is included in the block by producing a
merkle path that is only four 32-byte hashes long (128 bytes total). The path
GH

consists of the four hashes (noted in blue in figure below) HL, HIJ, HMNOP and
HABCDEFGH. With those four hashes provided as an authentication path, any node
can prove that HK (noted in green in the diagram) is included in the merkle root
RA

by computing four additional pair-wise hashes HKL, HIJKL, HIJKLMNOP, and the
merkle tree root (outlined in a dotted line in the diagram).
 The efficiency of merkle trees becomes obvious as the scale increases. Table
below shows the amount of data that needs to be exchanged as a merkle path to
prove that a transaction is part of a block.

SOIS, Manipal raghudathesh.weebly.com Page 18


IoT 607 : IoT Security Block Chain Raghudathesh G P

Table: Merkle Tree Efficiency

P
G

SH
As you can see from the table, while the block size increases rapidly, from 4 KB
with 16 transactions to a block size of 16 MB to fit 65,535 transactions, the
merkle path required to prove the inclusion of a transaction increases much more


E
slowly, from 128 bytes to only 512 bytes.
TH
With merkle trees, a node can download just the block headers (80 bytes per
block) and still be able to identify a transaction‟s inclusion in a block by
retrieving a small merkle path from a full node, without storing or transmitting the
DA

vast majority of the blockchain, which might be several gigabytes in size.


 Nodes that do not maintain a full blockchain, called simplified payment
verification (SPV nodes), use merkle paths to verify transactions without
U

downloading full blocks.


GH

f. Mining and Miners:


 Mining is the process by which new bitcoin is added to the money supply. Mining
also serves to secure the bitcoin system against fraudulent transactions or
RA

transactions spending the same amount of bitcoin more than once, known as a
double-spend.
 Miners provide processing power to the bitcoin network in exchange for the
opportunity to be rewarded bitcoin.
 Miners validate new transactions and record them on the global ledger. A new
block, containing transactions that occurred since the last block, is “mined” every
10 minutes, thereby adding those transactions to the blockchain.

SOIS, Manipal raghudathesh.weebly.com Page 19


IoT 607 : IoT Security Block Chain Raghudathesh G P

 Transactions that become part of a block and added to the blockchain are
considered “confirmed,” which allows the new owners of bitcoin to spend the
bitcoin they received in those transactions.
 Miners receive two types of rewards for mining:
1. New coins created with each new block
2. Transaction fees from all the transactions included in the block.
 To earn this reward, the miners compete to solve a difficult mathematical problem

P
based on a cryptographic hash algorithm. The solution to the problem, called the

G
proof of work, is included in the new block and acts as proof that the miner
expended significant computing effort. The competition to solve the proof-of-
work algorithm to earn reward and the right to record transactions on the

SH
blockchain is the basis for bitcoin‟s security model.
 The process of new coin generation is called mining because the reward is

E
designed to simulate diminishing returns, just like mining for precious metals.
Bitcoin‟s money supply is created through mining, similar to how a central bank
TH
issues new money by printing bank notes. The amount of newly created bitcoin a
miner can add to a block decreases approximately every four years (or precisely
DA

every 210,000 blocks).


 It started at 50 bitcoin per block in January of 2009
 halved to 25 bitcoin per block in November of 2012.
U

 It was halve again to 12.5 bitcoin per block in 2016.


 Based on this formula, bitcoin mining rewards decrease exponentially
GH

until approximately the year 2140, when all bitcoin (20.99999998 million)
will have been issued.
 After 2140, no new bitcoins will be issued.
RA

 Bitcoin miners also earn fees from transactions. Every transaction may include a
transaction fee, in the form of a surplus of bitcoin between the transaction‟s inputs
and outputs.
 The winning bitcoin miner gets to “keep the change” on the transactions included
in the winning block. Today, the fees represent 0.5% or less of a bitcoin miner‟s

SOIS, Manipal raghudathesh.weebly.com Page 20


IoT 607 : IoT Security Block Chain Raghudathesh G P

income, the vast majority coming from the newly minted bitcoins. After 2140, all
bitcoin miner earnings will be in the form of transaction fees.
 The word “mining” is somewhat misleading. By evoking the extraction of
precious metals, it focuses our attention on the reward for mining, the new
bitcoins in each block. Although mining is incentivized by this reward, the
primary purpose of mining is not the reward or the generation of new coins. If you
view mining only as the process by which coins are created, you are mistaking the

P
means (incentives) as a goal of the process.

G
Mining is the main process of the decentralized clearinghouse, by which
transactions are validated and cleared. Mining secures the bitcoin system and
enables the emergence of network-wide consensus without a central authority.

SH
 Mining is the invention that makes bitcoin special, a decentralized security
mechanism that is the basis for peer-to-peer digital cash. The reward of

E
newly minted coins and transaction fees is an incentive scheme that aligns the
actions of miners with the security of the network, while simultaneously
TH
implementing the monetary supply.
g. Bitcoin P2P Network:

DA

Bitcoin is structured as a peer-to-peer network architecture on top of the Internet.


The term peer-to-peer, or P2P, means that the computers that participate in the
network are peers to each other, that they are all equal, that there are no “special”
U

nodes, and that all nodes share the burden of providing network services.
 The network nodes interconnect in a mesh network with a “flat” topology. There
GH

is no server, no centralized service, and no hierarchy within the network.


 Nodes in a peer-to-peer network both provide and consume services at the same
time with reciprocity acting as the incentive for participation.
RA

 Peer-to-peer networks are inherently resilient, decentralized, and open.


 The preeminent example of a P2P network architecture was the early Internet
itself, where nodes on the IP network were equal. Today’s Internet architecture
is more hierarchical, but the Internet Protocol still retains its flat-topology
essence. Beyond bitcoin, the largest and most successful application of P2P

SOIS, Manipal raghudathesh.weebly.com Page 21


IoT 607 : IoT Security Block Chain Raghudathesh G P

technologies is file sharing with Napster as the pioneer and BitTorrent as the
most recent evolution of the architecture.
 Bitcoin’s P2P network architecture is much more than a topology choice.
Bitcoin is a peer-to-peer digital cash system by design, and the network
architecture is both a reflection and a foundation of that core characteristic.
 Decentralization of control is a core design principle and that can only be
achieved and maintained by a flat, decentralized P2P consensus network.

P
 The term “bitcoin network” refers to the collection of nodes running the

G
bitcoin P2P protocol. In addition to the bitcoin P2P protocol, there are other
protocols such as Stratum, which are used for mining and lightweight or mobile
wallets.

SH
 These additional protocols are provided by gateway routing servers that access the
bitcoin network using the bitcoin P2P protocol, and then extend that network to


E
nodes running other protocols.
Ex: Stratum servers connect Stratum mining nodes via the Stratum protocol to the
TH
main bitcoin network and bridge the Stratum protocol to the bitcoin P2P protocol.
We use the term “extended bitcoin network” to refer to the overall network that
DA

includes the bitcoin P2P protocol, pool-mining protocols, the Stratum protocol,
and any other related protocols connecting the components of the bitcoin system.
U
GH
RA

SOIS, Manipal raghudathesh.weebly.com Page 22


IoT 607 : IoT Security Block Chain Raghudathesh G P

P
G
E SH
TH
U DA
GH
RA

Figure: The Extended Bitcoin P2P Network Showing Various Node Types, Gateways, and Protocols

SOIS, Manipal raghudathesh.weebly.com Page 23


IoT 607 : IoT Security Block Chain Raghudathesh G P

P
G
E SH
TH
U DA
GH
RA

Figure: Different Types of Nodes on The Extended Bitcoin Network

SOIS, Manipal raghudathesh.weebly.com Page 24


IoT 607 : IoT Security Block Chain Raghudathesh G P

h. Nodes Types and Roles:


 Although nodes in the bitcoin P2P network are equal, they may take on different
roles depending on the functionality they are supporting.
 A bitcoin node is a collection of functions: routing, the blockchain database,
mining, and wallet services. A full node with all four of these functions is shown
in figure below

P
G
Figure: A bitcoin network node with all four functions:

SH
wallet, miner, full blockchain database, and network routing

E
TH
 All nodes include the routing function to participate in the network and might
include other functionality.
 All nodes validate, propagate transactions and blocks, and discover,
DA

maintain connections to peers. In the full-node example in figure above, the


routing function is indicated by an orange circle named “Network Routing
Node.”
U

 Some nodes, called full nodes, also maintain a complete and up-to-date copy of
GH

the blockchain. Full nodes can autonomously and authoritatively verify any
transaction without external reference.
 Some nodes maintain only a subset of the blockchain and verify transactions
RA

using a method called simplified payment verification, or SPV. These nodes are
known as SPV or lightweight nodes.
 In the full-node example in the figure, the full-node blockchain database function
is indicated by a blue circle named “Full Blockchain.”
 Mining nodes compete to create new blocks by running specialized hardware to
solve the proof-of-work algorithm. Some mining nodes are also full nodes,

SOIS, Manipal raghudathesh.weebly.com Page 25


IoT 607 : IoT Security Block Chain Raghudathesh G P

maintaining a full copy of the blockchain, while others are lightweight nodes
participating in pool mining and depending on a pool server to maintain a full
node. The mining function is shown in the full node as a black circle named
“Miner.”
 User wallets might be part of a full node, as is usually the case with desktop
bitcoin clients. Increasingly, many user wallets, especially those running on
resource-constrained devices such as smartphones, are SPV nodes. The wallet

P
function is shown in figure as a green circle named “Wallet”.

G
In addition to the main node types on the bitcoin P2P protocol, there are servers
and nodes running other protocols, such as specialized mining pool protocols and
lightweight client-access protocols.

SH
i. The Extended Bitcoin Network:
 The main bitcoin network, running the bitcoin P2P protocol, consists of between

E
7,000 and 10,000 listening nodes running various versions of the bitcoin reference
client (Bitcoin Core)
TH
 A few hundred nodes running various other implementations of the bitcoin P2P
protocol, such as BitcoinJ, Libbitcoin, and btcd.
DA

 A small percentage of the nodes on the bitcoin P2P network are also mining
nodes, competing in the mining process, validating transactions, and creating new
blocks.
U

 Various large companies interface with the bitcoin network by running full-node
clients based on the Bitcoin Core client, with full copies of the blockchain and a
GH

network node, but without mining or wallet functions. These nodes act as network
edge routers, allowing various other services (exchanges, wallets, block explorers,
merchant payment processing) to be built on top.
RA

 The extended bitcoin network includes the network running the bitcoin P2P
protocol, described earlier, as well as nodes running specialized protocols.
Attached to the main bitcoin P2P network are a number of pool servers and
protocol gateways that connect nodes running other protocols. These other
protocol nodes are mostly pool mining node and lightweight wallet clients, which
do not carry a full copy of the blockchain.

SOIS, Manipal raghudathesh.weebly.com Page 26


IoT 607 : IoT Security Block Chain Raghudathesh G P

j. Decentralized Consensus:
 Blockchain the global public ledger (list) of all transactions, which everyone in the
bitcoin network accepts as the authoritative record of ownership.
 But the question is how can everyone in the network agree on a single universal “truth”
about who owns what, without having to trust anyone?
 All traditional payment systems depend on a trust model that has a central authority
providing a clearinghouse service, basically verifying and clearing all transactions.

P
 But Bitcoin has no central authority, yet somehow every full node has a complete copy of

G
a public ledger that it can trust as the authoritative record. The blockchain is not created
by a central authority, but is assembled independently by every node in the network.

SH
Somehow, every node in the network, acting on information transmitted across insecure
network connections, can arrive at the same conclusion and assemble a copy of the same
public ledger as everyone else.

E
Satoshi Nakamoto’s main invention is the decentralized mechanism for emergent
consensus.
TH
 Emergent, because consensus is not achieved explicitly - there is no election or fixed
moment when consensus occurs. Instead, consensus is an emergent artifact of the
DA

asynchronous interaction of thousands of independent nodes, all following simple


rules.
 All the properties of bitcoin, including currency, transactions, payments, and the security
U

model that does not depend on central authority or trust, derive from this invention.
 Bitcoin‟s decentralized consensus emerges from the interplay of four processes that occur
GH

independently on nodes across the network:


1. Independent verification of each transaction, by every full node, based on a
RA

comprehensive list of criteria


2. Independent aggregation of those transactions into new blocks by mining nodes,
coupled with demonstrated computation through a proof-of-work algorithm
3. Independent verification of the new blocks by every node and assembly into a
chain
4. Independent selection, by every node, of the chain with the most cumulative
computation demonstrated through proof of work.

SOIS, Manipal raghudathesh.weebly.com Page 27


IoT 607 : IoT Security Block Chain Raghudathesh G P

k. Proof of Work (PoW):


 Proof of work (POW) to used by Satoshi Nakamoto to create distributed trustless
consensus and solve the double-spend problem.
 Proof of work is a requirement that expensive computations, also called mining, be
performed in order to facilitate transactions on the blockchain.
 To finish a page of the blockchain ledger, a block to speak, nodes (users) must figure out
complex mathematical equations before they can validate transactions. This process is

P
called mining, and those who take part in it are known as miners.

G
These mathematical problems are hard to compute but easy to verify. Once miners solve
them, they are rewarded with the corresponding digital currency, referred to as a block
reward.

SH
 As time goes by the mathematical equations become harder and harder.
 The transactions in the block are then validated and the block is added to the chain.

E
The proof-of-work involves scanning for a value that when hashed, such as with
SHA-256, the hash begins with a number of zero bits. The average work required is
TH
exponential in the number of zero bits required and can be verified by executing a single
hash.
DA

 Blockchain implement the proof-of-work by incrementing a nonce in the block until a


value is found that gives the block's hash the required zero bits.
 Once the CPU effort has been expended to make it satisfy the proof-of-work, the block
U

cannot be changed without redoing the work. As later blocks are chained after it, the
GH

work to change the block would include redoing all the blocks after it.
RA

Figure: Blocks in Chain


 When a miner creates a new block for the blockchain, he has to provide the network with
two hashes; one being a hash of all the transactions in a block, and the other being a hash
that proves the miner has expended a vast amount of energy on creating the block. This

SOIS, Manipal raghudathesh.weebly.com Page 28


IoT 607 : IoT Security Block Chain Raghudathesh G P

cost makes it unprofitable for the miner to lie. The miners need to also work on a lottery-
style system where there can only be one winner. Both of these problems are solved by
Proof-of-Work.
 Scenario:
 lets Hash my name “raghudatheshgp” this will yield the hash as below

75CF55F7C3362578D8793A46084608E88024553D5F20352EC05241E29D90BEDA
 Let‟s say I hashed my name, but instead of just “raghudatheshgp” I added a zero

P
to the end of my name so we had “raghudatheshgp0”. The resulting hash for this

G
would be

8B428EC80C2FE0169341670EF578AAE1B5BD3358894A42A37C2D0B0A11684E05

SH
 When you compare this hash to my previous hash of just “raghudatheshgp0”,
you‟ll notice the two hashes, when compared side-by-side, are totally different.

E
Now let‟s say I hash my name plus the number five. This gives me:
TH
073E12BF3EE525D02A75955ECA76E6DF4ED76B34A950E7B7B1AFC1470D74EA1F

 Here is the point, well, if you were a block chain network, the network could say
DA

to miners “give me the first number appended at the end of your name that results
in a hash starting with the number 0”. So what all miners would do is hash:
U

Hash(raghudatheshgp+0) = 8B428EC80C2FE0169341670EF578AAE1B5BD3358894A42A37C2D0B0A11684E05
GH

Hash(raghudatheshgp+1) = AE348218CAA6D65AF3FA7F9A80D57F8CC1524934D90D4F5DE6001747ED6ABA54

 Etc, etc…
 Eventually it will hash “(raghudatheshgp5” and get the following hash that starts
RA

with a number zero:

073E12BF3EE525D02A75955ECA76E6DF4ED76B34A950E7B7B1AFC1470D74EA1F

SOIS, Manipal raghudathesh.weebly.com Page 29


IoT 607 : IoT Security Block Chain Raghudathesh G P

 Miners would then respond back with the text “raghudatheshgp5” and include the
hash; the receiving computer would simply hash “raghudatheshgp5” and see if the
resulting hash matches the hash that miners is sent through.
 This proves that miners has had to count from 0 to 5 to find that hash. So
effectively miners has done 5 pieces of work, but the receiving computer could
validate this with one piece of work.
 Effectively miners provided proof of their work, hence they have performed

P
“Proof of Work”.
 Here the number 5 which is hashed with name is called as nonce.

G
 The "nonce" in a bitcoin block is a field whose value is adjusted by miners so that
the hash of the block will be less than or equal to the current target of the network.

SH
 As you could probably guess, a miner could do millions of hashes per second, so
hashing a value 5 times is pretty pointless. But imagine if a network of computers
said to miners: “provide us with a valid block of transactions, provide a hash of
E
the block, plus a number that results in a hash starting with….15 zeros”.
TH
 The initial hash of the block would be instant:
BlockHash = Hash(„All of the transactions in the current block‟)
 then miners would grab that hash and go:
DA

Hash(BlockHash + 0)
Hash(BlockHash + 1)
Hash(BlockHash + 2)
U

 Etc, etc..
 To find a hash with 15 leading zeros at the start would require trillions and
GH

trillions and trillions of attempts. A slow computer would take hundreds of years
to do this, or a lot of very fast computers could go racing for several minutes
before the solution was found.
RA

 All of these computers obviously will be burning through a lot of electricity. It‟s
because of this electricity cost that it‟s impractical for a miner to find a valid hash
on an invalid block of transactions. That is, a miner would be foolish to not
correctly validate a block to prove all transactions are valid and to simply skip to
hashing of that block. All other computers on the network would reject the invalid
block and the miner would not receive a reward.

SOIS, Manipal raghudathesh.weebly.com Page 30


IoT 607 : IoT Security Block Chain Raghudathesh G P

 One of the things that helps keep mining decentralised is that no two miners are
hashing the same block. If I was to hash “a+b”, I‟ll get a different hash than if I
hash “b+a”. Miners all receive transactions across the network in a different
order to each other; because of this plus an individual preference for fees, it
means that each miner will create a block slightly different.
 Although all blocks may have been correctly validated, only one block can go
into the chain at one time. So all the miners will have to keep hashing away,

P
until they find a number that, when appended to their block hash then hashed,
returns a result with the leading number of zeros that the network has agreed to

G
accept as valid.
 To keep Bitcoin‟s monetary policy on schedule, the network ensures a block takes

SH
on average 10 minutes to be mined. The network does this by adjusting the
mining difficulty every 2 weeks. So if blocks are being found too fast due to a lot

E
of new miners coming online, to prevent an unplanned inflationary rate, the
network will increase the difficulty required and miners will have to find a longer
TH
number of preceding zeros on a hash.
 There is no way to know what this hash is in advance, so miners must work fast
using many fast computers. As it‟s random, the miner with the most powerful
DA

computer won‟t always win. The best way to look at this is like a lottery system,
where the user with the most tickets has a greater chance of winning but isn‟t
U

guaranteed to win everytime.


GH

l. Transaction Lifecycle:
 A transaction‟s lifecycle starts with the transaction‟s creation, also known as origination.
The transaction is then signed with one or more signatures indicating the authorization to
RA

spend the funds referenced by the transaction.


 The transaction is then broadcast on the bitcoin network, where each network node
(participant) validates and propagates the transaction until it reaches (almost) every node
in the network.
 Finally, the transaction is verified by a mining node and included in a block of
transactions that is recorded on the blockchain.

SOIS, Manipal raghudathesh.weebly.com Page 31


IoT 607 : IoT Security Block Chain Raghudathesh G P

 Once recorded on the blockchain and confirmed by sufficient subsequent blocks


(confirmations), the transaction is a permanent part of the bitcoin ledger and is accepted
as valid by all participants. The funds allocated to a new owner by the transaction can
then be spent in a new transaction, extending the chain of ownership and beginning the
lifecycle of a transaction again.
I. Creating Transactions:
 In some ways it helps to think of a transaction in the same way as a paper

P
check. Like a check, a transaction is an instrument that expresses the intent

G
to transfer money and is not visible to the financial system until it is
submitted for execution. Like a check, the originator of the transaction
does not have to be the one signing the transaction.

SH
 Transactions can be created online or offline by anyone, even if the person
creating the transaction is not an authorized signer on the account.

E
Ex: An accounts payable clerk might process payable checks for signature
by the CEO. Similarly, an accounts payable clerk can create bitcoin
TH
transactions and then have the CEO apply digital signatures to make them
valid. Whereas a check references a specific account as the source of the
DA

funds, a bitcoin transaction references a specific previous transaction as its


source, rather than an account.
 Once a transaction has been created, it is signed by the owner (or owners)
U

of the source funds. If it is properly formed and signed, the signed


transaction is now valid and contains all the information needed to execute
GH

the transfer of funds. Finally, the valid transaction has to reach the bitcoin
network so that it can be propagated until it reaches a miner for inclusion
in the pubic ledger (the blockchain).
RA

II. Broadcasting Transactions to the Bitcoin Network:


 First, a transaction needs to be delivered to the bitcoin network so that it
can be propagated and included in the blockchain.
 In essence, a bitcoin transaction is just 300 to 400 bytes of data and has to
reach any one of tens of thousands of bitcoin nodes.

SOIS, Manipal raghudathesh.weebly.com Page 32


IoT 607 : IoT Security Block Chain Raghudathesh G P

 The senders do not need to trust the nodes they use to broadcast the
transaction, as long as they use more than one to ensure that it propagates.
 The nodes don‟t need to trust the sender or establish the sender‟s
“identity.” Because the transaction is signed and contains no confidential
information, private keys, or credentials, it can be publicly broadcast using
any underlying network transport that is convenient.
 Unlike credit card transactions, for example, which contain sensitive

P
information and can only be transmitted on encrypted networks, a bitcoin
transaction can be sent over any network.

G
 As long as the transaction can reach a bitcoin node that will propagate it
into the bitcoin network, it doesn‟t matter how it is transported to the first

SH
node.
 Bitcoin transactions can therefore be transmitted to the bitcoin network

E
over insecure networks such as WiFi, Bluetooth, NFC, Chirp, barcodes, or
by copying and pasting into a web form. In extreme cases, a bitcoin
TH
transaction could be transmitted over packet radio, satellite relay, or
shortwave using burst transmission, spread spectrum, or frequency
DA

hopping to evade detection and jamming.


 A bitcoin transaction could even be encoded as smileys (emoticons) and
posted in a public forum or sent as a text message or Skype chat message.
U

Bitcoin has turned money into a data structure, making it virtually


impossible to stop anyone from creating and executing a bitcoin
GH

transaction.
III. Propagating Transactions on the Bitcoin Network:
 Once a bitcoin transaction is sent to any node connected to the bitcoin
RA

network, the transaction will be validated by that node. If valid, that node
will propagate it to the other nodes to which it is connected, and a success
message will be returned synchronously to the originator. If the
transaction is invalid, the node will reject it and synchronously return a
rejection message to the originator.

SOIS, Manipal raghudathesh.weebly.com Page 33


IoT 607 : IoT Security Block Chain Raghudathesh G P

 The bitcoin network is a peer-to-peer network, meaning that each bitcoin


node is connected to a few other bitcoin nodes that it discovers during
startup through the peer-to-peer protocol.
 The entire network forms a loosely connected mesh without a fixed
topology or any structure, making all nodes equal peers.
 Messages, including transactions and blocks, are propagated from each
node to the peers to which it is connected. A new validated transaction

P
injected into any node on the network will be sent to three to four of the
neighboring nodes, each of which will send it to three to four more nodes,

G
and so on. In this way, within a few seconds a valid transaction will
propagate in an exponentially expanding ripple across the network until all

SH
connected nodes have received it.
 The bitcoin network is designed to propagate transactions and blocks to all


E
nodes in an efficient and resilient manner that is resistant to attacks.
To prevent spamming, denial-of-service attacks, or other nuisance attacks
TH
against the bitcoin system, every node independently validates every
transaction before propagating it further. A malformed transaction will
DA

not get beyond one node. The rules by which transactions are
validated are explained in more detail in Independent Verification of
Transactions.
U

IV. Transaction Structure:


 A transaction is a data structure that encodes a transfer of value from a
GH

source of funds, called an input, to a destination, called an output.


 Transaction inputs and outputs are not related to accounts or identities.
Instead, you should think of them as bitcoin amounts - chunks of bitcoin -
RA

being locked with a specific secret that only the owner, or person who
knows the secret, can unlock. A transaction contains a number of fields, as
shown in table below

SOIS, Manipal raghudathesh.weebly.com Page 34


IoT 607 : IoT Security Block Chain Raghudathesh G P

Table: The structure of a transaction

P
G
SH
V. Transaction Outputs and Inputs:
 E
The fundamental building block of a bitcoin transaction is an unspent
TH
transaction output, or UTXO.
 UTXO are indivisible chunks of bitcoin currency locked to a specific
owner, recorded on the blockchain, and recognized as currency units
DA

by the entire network.


 The bitcoin network tracks all available (unspent) UTXO currently
U

numbering in the millions. Whenever a user receives bitcoin, that amount


is recorded within the blockchain as a UTXO.
GH

 Thus, a user‟s bitcoin might be scattered as UTXO amongst hundreds of


transactions and hundreds of blocks. In effect, there is no such thing as a
stored balance of a bitcoin address or account; there are only scattered
RA

UTXO, locked to specific owners.


 The concept of a user’s bitcoin balance is a derived construct created
by the wallet application. The wallet calculates the user‟s balance by
scanning the blockchain and aggregating all UTXO belonging to that user.

SOIS, Manipal raghudathesh.weebly.com Page 35


IoT 607 : IoT Security Block Chain Raghudathesh G P

 A UTXO can have an arbitrary value denominated as a multiple


of satoshis. Just like dollars can be divided down to two decimal places as
cents, bitcoins can be divided down to eight decimal places as satoshis.
 Although UTXO can be any arbitrary value, once created it is indivisible
just like a coin that cannot be cut in half.
 If a UTXO is larger than the desired value of a transaction, it must still be
consumed in its entirety and change must be generated in the

P
transaction. In other words, if you have a 20 bitcoin UTXO and want to
pay 1 bitcoin, your transaction must consume the entire 20 bitcoin UTXO

G
and produce two outputs: one paying 1 bitcoin to your desired recipient
and another paying 19 bitcoin in change back to your wallet. As a result,

SH
most bitcoin transactions will generate change.
 The UTXO consumed by a transaction are called transaction inputs, and


E
the UTXO created by a transaction are called transaction outputs.
This way, chunks of bitcoin value move forward from owner to owner in a
TH
chain of transactions consuming and creating UTXO.
 Transactions consume UTXO by unlocking it with the signature of the
DA

current owner and create UTXO by locking it to the bitcoin address of


the new owner.
 The exception to the output and input chain is a special type of transaction
U

called the coinbase transaction, which is the first transaction in each


block. This transaction is placed there by the “winning” miner and
GH

creates brand-new bitcoin payable to that miner as a reward for mining.


This is how bitcoin‟s money supply is created during the mining process.
 Sending someone bitcoin is creating an unspent transaction output
RA

(UTXO) registered to their address and available for them to spend.


 UTXO are tracked by every full-node bitcoin client in a database held in
memory, called the UTXO set or UTXO pool. New transactions consume
(spend) one or more of these outputs from the UTXO set.
 Transaction outputs consist of two parts:

SOIS, Manipal raghudathesh.weebly.com Page 36


IoT 607 : IoT Security Block Chain Raghudathesh G P

I. An amount of bitcoin, denominated in satoshis, the smallest


bitcoin unit
 A locking script, also known as an “encumbrance” that “locks” this
amount by specifying the conditions that must be met to spend the output.
Table below shows the structure of a transaction output.

P
G

E SH
TH
Following script calls the blockchain.info API to find the UTXO related to
an address
DA

# get unspent outputs from blockchain API

import json
U

import requests
GH

# example address
address = '1Dorian4RoXcnBv9hnQ4Y2C1an6NJ4UrjX'

# The API URL is https://blockchain.info/unspent?active=<address>


RA

# It returns a JSON object with a list "unspent_outputs", containing UTXO,


like this:
#{ "unspent_outputs":[
# {
#
"tx_hash":"ebadfaa92f1fd29e2fe296eda702c48bd11ffd52313e986e99ddad9084062167",
# "tx_index":51919767,

SOIS, Manipal raghudathesh.weebly.com Page 37


IoT 607 : IoT Security Block Chain Raghudathesh G P

# "tx_output_n": 1,
# "script":"76a9148c7e252f8d64b0b6e313985915110fcfefcf4a2d88ac",
# "value": 8000000,
# "value_hex": "7a1200",
# "confirmations":28691
# },
# ...

P
#]}

G
resp = requests.get('https://blockchain.info/unspent?active=%s' % address)
utxo_set = json.loads(resp.text)["unspent_outputs"]

SH
for utxo in utxo_set:
print "%s:%d - %ld Satoshis" % (utxo['tx_hash'], utxo['tx_output_n'],
utxo['value'])
E
TH
 Running the script, we see a list of transaction IDs, a colon, the index
number of the specific unspent transaction output (UTXO), and the value
DA

of that UTXO in satoshis.

$ python get-utxo.py
U

ebadfaa92f1fd29e2fe296eda702c48bd11ffd52313e986e99ddad9084062167:1 - 8000000 Satoshis


6596fd070679de96e405d52b51b8e1d644029108ec4cbfe451454486796a1ecf:0 - 16050000 Satoshis
GH

74d788804e2aae10891d72753d1520da1206e6f4f20481cc1555b7f2cb44aca0:0 - 5000000 Satoshis

b2affea89ff82557c60d635a2a3137b8f88f12ecec85082f7d0a1f82ee203ac4:0 - 10000000 Satoshis

...
RA

 In simple terms, transaction inputs are pointers to UTXO. They point to


a specific UTXO by reference to the transaction hash and sequence
number where the UTXO is recorded in the blockchain.

SOIS, Manipal raghudathesh.weebly.com Page 38


IoT 607 : IoT Security Block Chain Raghudathesh G P

 To spend UTXO, a transaction input also includes unlocking scripts that


satisfy the spending conditions set by the UTXO. The unlocking script is
usually a signature proving ownership of the bitcoin address that is in the
locking script.
 When users make a payment, their wallet constructs a transaction by
selecting from the available UTXO.
 Ex: to make a 0.015 bitcoin payment, the wallet app may select a 0.01

P
UTXO and a 0.005 UTXO, using them both to add up to the desired
payment amount.

G
 Following script are used for calculating how much total bitcoin will be
issued

SH
# Selects outputs from a UTXO list using a greedy algorithm.

from sys import argv E


TH
class OutputInfo:
DA

def __init__(self, tx_hash, tx_index, value):


self.tx_hash = tx_hash
self.tx_index = tx_index
self.value = value
U
GH

def __repr__(self):
return "<%s:%s with %s Satoshis>" % (self.tx_hash, self.tx_index,
self.value)
RA

# Select optimal outputs for a send from unspent outputs list.


# Returns output list and remaining change to be sent to
# a change address.
def select_outputs_greedy(unspent, min_value):
# Fail if empty.
if not unspent:
return None

SOIS, Manipal raghudathesh.weebly.com Page 39


IoT 607 : IoT Security Block Chain Raghudathesh G P

# Partition into 2 lists.


lessers = [utxo for utxo in unspent if utxo.value < min_value]
greaters = [utxo for utxo in unspent if utxo.value >= min_value]
key_func = lambda utxo: utxo.value
if greaters:
# Not-empty. Find the smallest greater.
min_greater = min(greaters)

P
change = min_greater.value - min_value
return [min_greater], change

G
# Not found in greaters. Try several lessers instead.
# Rearrange them from biggest to smallest. We want to use the least

SH
# amount of inputs as possible.
lessers.sort(key=key_func, reverse=True)
result = []
accum = 0
for utxo in lessers: E
TH
result.append(utxo)
accum += utxo.value
if accum >= min_value:
DA

change = accum - min_value


return result, "Change: %d Satoshis" % change
# No results found.
U

return None, 0
GH

def main():
unspent = [
RA

OutputInfo("ebadfaa92f1fd29e2fe296eda702c48bd11ffd52313e986e99ddad9084062167"
, 1, 8000000),

OutputInfo("6596fd070679de96e405d52b51b8e1d644029108ec4cbfe451454486796a1ecf"
, 0, 16050000),

OutputInfo("b2affea89ff82557c60d635a2a3137b8f88f12ecec85082f7d0a1f82ee203ac4"
, 0, 10000000),

SOIS, Manipal raghudathesh.weebly.com Page 40


IoT 607 : IoT Security Block Chain Raghudathesh G P

OutputInfo("7dbc497969c7475e45d952c4a872e213fb15d45e5cd3473c386a71a1b0c136a1"
, 0, 25000000),

OutputInfo("55ea01bd7e9afd3d3ab9790199e777d62a0709cf0725e80a7350fdb22d7b8ec6"
, 17, 5470541),

P
OutputInfo("12b6a7934c1df821945ee9ee3b3326d07ca7a65fd6416ea44ce8c3db0c078c64"
, 0, 10000000),

G
OutputInfo("7f42eda67921ee92eae5f79bd37c68c9cb859b899ce70dba68c48338857b7818"

SH
, 0, 16100000),
]

if len(argv) > 1:
target = long(argv[1]) E
TH
else:
target = 55000000
DA

print "For transaction amount %d Satoshis (%f bitcoin) use: " % (target,
target/10.0**8)
print select_outputs_greedy(unspent, target)
U

if __name__ == "__main__":
GH

main()

 If we run the select-utxo.py script without a parameter, it will attempt to


construct a set of UTXO (and change) for a payment of 55,000,000
RA

satoshis (0.55 bitcoin). If you provide a target payment amount as a


parameter, the script will select UTXO to make that target payment
amount. We run the script trying to make a payment of 0.5 bitcoin or
50,000,000 satoshis.

$ python select-utxo.py 50000000

For transaction amount 50000000 Satoshis (0.500000 bitcoin) use:

SOIS, Manipal raghudathesh.weebly.com Page 41


IoT 607 : IoT Security Block Chain Raghudathesh G P

([<7dbc497969c7475e45d952c4a872e213fb15d45e5cd3473c386a71a1b0c136a1:0 with 25000000 Satoshis>,

<7f42eda67921ee92eae5f79bd37c68c9cb859b899ce70dba68c48338857b7818:0 with 16100000 Satoshis>,

<6596fd070679de96e405d52b51b8e1d644029108ec4cbfe451454486796a1ecf:0 with 16050000 Satoshis>], 'Change: 7150000

Satoshis')

 Once the UTXO is selected, the wallet then produces unlocking scripts
containing signatures for each of the UTXO, thereby making them

P
spendable by satisfying their locking script conditions. The wallet adds
these UTXO references and unlocking scripts as inputs to the

G
transaction. Table below shows the structure of a transaction input.

E SH
TH
U DA
GH

m. Script Construction (Lock + Unlock):


 Bitcoin‟s transaction validation engine relies on two types of scripts to validate
RA

transactions:
 A locking script:
 A locking script is an encumbrance placed on an output, and it
specifies the conditions that must be met to spend the output in the
future.
 Historically, the locking script was called a scriptPubKey, because
it usually contained a public key or bitcoin address. In most bitcoin

SOIS, Manipal raghudathesh.weebly.com Page 42


IoT 607 : IoT Security Block Chain Raghudathesh G P

applications, what we refer to as a locking script will appear in the


source code as scriptPubKey.
 An unlocking script:
 An unlocking script is a script that “solves,” or satisfies, the
conditions placed on an output by a locking script and allows the
output to be spent.
 Unlocking scripts are part of every transaction input, and most of

P
the time they contain a digital signature produced by the user‟s
wallet from his or her private key.

G
 Historically, the unlocking script is called scriptSig, because it
usually contained a digital signature. In most bitcoin applications,

SH
the source code refers to the unlocking script as scriptSig.
 Every bitcoin client will validate transactions by executing the locking and

E
unlocking scripts together. For each input in the transaction, the validation
software will first retrieve the UTXO referenced by the input. That UTXO
TH
contains a locking script defining the conditions required to spend it. The
validation software will then take the unlocking script contained in the input that
DA

is attempting to spend this UTXO and execute the two scripts.


 First, the unlocking script is executed, using the stack execution engine. If the
unlocking script executed without errors (e.g., it has no “dangling” operators left
U

over), the main stack (not the alternate stack) is copied and the locking script is
executed.
GH

 Figure below is an example of the unlocking and locking scripts for the most
common type of bitcoin transaction (a payment to a public key hash), showing the
combined script resulting from the concatenation of the unlocking and locking
RA

scripts prior to script validation.

SOIS, Manipal raghudathesh.weebly.com Page 43


IoT 607 : IoT Security Block Chain Raghudathesh G P

P
Figure: Combining scriptSig and scriptPubKey to evaluate a transaction script

G
Smart Contracts:
 A smart contract is a computer code running on top of a blockchain containing a set of

SH
rules under which the parties to that smart contract agree to interact with each other. If
and when the pre-defined rules are met, the agreement is automatically enforced.
 The smart contract code facilitates, verifies, and enforces the negotiation or performance


E
of an agreement or transaction. It is the simplest form of decentralized automation.
TH
It is a mechanism involving digital assets and two or more parties, where some or all of
the parties deposit assets into the smart contract and the assets automatically get
redistributed among those parties according to a formula based on certain data, which is
DA

not known at the time of contract initiation.


 The term smart contract is a bit unfortunate since a smart contract is neither smart nor are
they to be confused with a legal contract.
U

1. A smart contract can only be as smart as the people coding taking into account all
GH

available information at the time of coding.


2. While smart contracts have the potential to become legal contracts if certain
conditions are met, they should not be confused with legal contracts accepted by
RA

courts and or law enforcement. However, we will probably see a fusion of legal
contracts and smart contracts emerge over the next few years as the technology
becomes more mature and widespread and legal standards are adopted.
 Smart contracts radically reduce transaction costs. Auto enforceable code – whether on
the protocol level or on the application level – standardizes transaction rules, thus
reducing the transaction costs of:
 reaching an agreement,

SOIS, Manipal raghudathesh.weebly.com Page 44


IoT 607 : IoT Security Block Chain Raghudathesh G P

 formalization, and
 enforcement
 The concept of a smart contract is not new. However, Blockchain seems to be the catalyst
for smart contract implementation. The most primitive form of a smart contract is a
vending machine. The rules of a transaction are programmed into a machine. Automatic
vending machines not only slashed transaction costs by making human vendors obsolete,
but they also expanded service, offering 24/7 availability instead of limited opening hours

P
of a kiosk.

G
Characteristics of a Smart Contract
 Smart contracts are capable of tracking performance in real time and can bring
tremendous cost savings. Compliance and controlling happen on the fly. In order

SH
to get external information, a smart contract needs information oracles, which
feed the smart contract with external information.
 Smart Contracts are
 Self-verifying
E
TH
 Self-executing
 Tamper resistant

DA

Smart Contracts can


 Turn legal obligations into automated processes.
 Guarantee a greater degree of security.
U

 Reduce reliance on trusted intermediaries.


 Lower transaction costs.
GH

 These smart contracts are a piece of code running on top of a blockchain network, where
digital assets are controlled by that piece of code implementing arbitrary rules. They have
properties of contractual agreements but should not be confused with legal contracts. (For
RA

more information on legal question around blockchain visit our Blockchain & Law page).

SOIS, Manipal raghudathesh.weebly.com Page 45


IoT 607 : IoT Security Block Chain Raghudathesh G P

P
G
SH
Figure: Block Chain and Smart Contract

 Scenario:
E
TH
 If A and B don‟t know and don‟t trust each other, they usually need a trusted third
party to serve as an intermediary to verify transactions and enforce them.
 With smart contracts & blockchains, you don‟t need those trusted intermediaries
DA

anymore for clearing or settlement of your transactions.


 Consider an example of buying and selling a car:
U

 Traditional Way:
 If Alice wants to purchase a car from Bob, a series of trusted third parties are
GH

required to verify and authenticate the deal.


 The process differs from country to country but always involves at least one, but
usually more, trusted third parties: motor vehicle registration authority, in
RA

combination with a notary and/or insurance company. It is a complicated and


lengthy process, and considerable fees for these middlemen apply.

SOIS, Manipal raghudathesh.weebly.com Page 46


IoT 607 : IoT Security Block Chain Raghudathesh G P

P
G
E SH
TH
Figure: Traditional Contact

 Blockchain Way:
DA

 On the Blockchain, once all involved authorities and companies are on a


blockchain, a smart contract could be used to define all the rules of a valid care
sale. If Alice wanted to buy the car from Bob using a smart contract on the
U

blockchain, the transaction would be verified by each node in the Blockchain


GH

Network to see if Bob is the owner of the car and if Alice has enough money to
pay Bob.
RA

SOIS, Manipal raghudathesh.weebly.com Page 47


IoT 607 : IoT Security Block Chain Raghudathesh G P

P
G
E SH
TH
U DA
GH

Figure: Blockchain Contact

 On the Blockchain, who owns what is transparent and at the same time anonymous or
RA

pseudonymous. This means that every computer running the blockchain protocol could
check whether a certain person is the rightful owner of the car or not.
 Stealing cars won‟t be as easy as today, especially once we have smart keys granting
access control verified on the blockchain, to unlock our future vehicles. As the owner of
the car, you could authorize other people to drive it (stating the public key of the

SOIS, Manipal raghudathesh.weebly.com Page 48


IoT 607 : IoT Security Block Chain Raghudathesh G P

respective individual). In such cases opening the car would only be possible with a smart
key on the Blockchain.

P
G
E SH
Figure: Trust in Smart Contract
TH
 Types of Smart Contracts:
 Blockchain and smart contracts have the potential to disrupt many industries. Use
cases can be found in banking, insurance, energy, e-government,
DA

telecommunication, music & film industry, art world, mobility, education and
many more. Smart contract use cases range from simple to complex.
 Time-stamping services like ascribe (art registry) or governmental and semi-
U

governmental registries (land titles, birth certificates, birth certificates, school and
GH

university degrees) are examples for simpler technological use cases (the
regulatory aspects might be more complex). Decentralized autonomous
organizations, on the other hand, are the most complex form of a smart contract.
RA

SOIS, Manipal raghudathesh.weebly.com Page 49


IoT 607 : IoT Security Block Chain Raghudathesh G P

P
G
Figure: Smart Contract Application

SH
 With blockchains and smart contracts, we can now imagine a world in which contracts
are embedded in digital code and stored in transparent, shared databases, where they are

E
protected from deletion, tampering, and revision. In this world, every agreement, every
TH
process, task, and payment would have a digital record and signature that could be
identified, validated, stored, and shared.
 Intermediaries like lawyers, brokers, and bankers, and public administrators might no
DA

longer be necessary. Individuals, organizations, machines, and algorithms would freely


transact and interact with one another with little friction and a fraction of current
transaction costs.
U

 Therefore, blockchains & smart contracts:


GH

 Radically reduce transaction costs (bureaucracy) through machine consensus and


auto-enforceable code.
 Bypass the traditional principal-agent dilemmas of organizations, thus providing
RA

an operating system for what some refer to as “trustless trust”. This means that
you don‟t have to trust people and organizations, you trust code, which is open
source and provides transparent processes.

SOIS, Manipal raghudathesh.weebly.com Page 50


IoT 607 : IoT Security Block Chain Raghudathesh G P

Digital Wallet:
 A digital wallet, also known as e-wallet is a virtual storage of user‟s payment and
identification information for various payment systems.
 Digital wallet allows people to streamline purchase process on dedicated services and can
also be used together with mobile payment systems.
 A cryptocurrency wallet, is a software program that stores private and public keys and

P
interacts with various blockchains to enable the user to transact with digital currency. In
the same fashion that you need a bank account to wire money. Or a Paypal account to

G
send money. You will need a cryptocurrency wallet in order to transact with other users.
 Cryptocurrency Wallet Types: There are five types of digital storage available for your

SH
use:
1. Online Wallet:
 Online wallets run on the cloud. Therefore, they can be accessed from


E
multiple devices with an internet connection.
TH
Like every cloud service, online wallets are practical and convenient.
 However, they are also more susceptible to theft and often require extra
layers of security.
DA

 Even then, you have to be very careful about choosing the online wallet
provider, as they have an extensive scam history.
2. Mobile Wallet:
U

 Mobile wallets are your phone applications. They are very handy since
GH

they can be used as a means of payment even in physical stores. All you
need to do is install an app on your phone and open an account.
 In general, mobile wallets are considered to be safer than cloud wallets.

RA

The risks associated with mobile wallets are losing your assets in case
your phone breaks down or encounters a security breach.
3. Desktop wallet:
 Desktop wallets is another popular choice which is also safer than online
wallets.
 They are downloaded and installed on a PC or laptop and are accessible
from the installation device.

SOIS, Manipal raghudathesh.weebly.com Page 51


IoT 607 : IoT Security Block Chain Raghudathesh G P

 However, if your computer is infected with a virus, gets hacked or


experiences external damage, there is a chance to lose all your funds.
4. Hardware wallet:
 This is by far one of the most secure types of wallet in the space.
 Hardware wallets are offline devices that store your cryptocurrencies.
 Hardware wallets store users private keys on a device, typically a USB
drive. They are able to make online transactions.

P
 Various manufacturers make hardware wallets compatible with different
web interfaces. Therefore, complete characteristics depend on wallets

G
integrations.
 Hardware storage is also convenient because of its ability to send and

SH
receive currencies by merely plugging them into the internet enabled
device and authorizing yourself. Therefore, hardware wallet is the most


E
expensive, but also one of the safest options.
Some hardware wallets come with features such as pin code access, 28
TH
word seed phrase, and much more.
 To access funds, the user simply plugs the device into their computer and
starts transacting. It‟s that easy! Hardware wallets should hold the bulk of
DA

your cryptocurrencies, due to it‟s high level of security.


5. Paper wallet:
U

 Paper wallets are by far the safest option to store your digital assets.
 A paper wallet is a physical copy of your generated public and private
GH

keys and can even refer to a printed sheet of paper.


 You can send funds by transferring the money to wallet‟s public address
and you can withdraw or send your currencies by entering your private
RA

keys or by scanning the QR code on the paper wallet.

Hot Wallet:
 A Hot Wallet is an online software that enables users to transact with cryptocurrencies
from a single device.
 This software holds onto your private and public key in storage.

SOIS, Manipal raghudathesh.weebly.com Page 52


IoT 607 : IoT Security Block Chain Raghudathesh G P

 The reason these wallets are called “hot” is because they are connected to the internet.
Making them and your funds susceptible to cyber attacks or theft.
 Pros:
1. Free
2. Quick access to your cryptocurrency (many hot wallets are accessible via your
cell phone)
3. Easy to use, and user-friendly

P
 Cons:

G
1. Hot wallets by definition are connected to the Internet which means that your
cryptocurrency is less secure (e.g. hackers, possible regulation, and other
technical vulnerabilities)

SH
 Best hot wallets:
1. Electrum
Desktop Wallet
2. Exodus
3. Copay
E
TH
4. Blockchain
5. Coinbase Mobile
Mobile Wallet
DA

6. Bread
7. MyEtherWallet
8. UpHold Online Wallet
U

9. Coinpayments
GH

Cold Wallet:
 A Cold Wallet is a much more secure offline wallet device.
RA

 That enables users to hold a significant amount of currencies on one device, with the
highest amount of security.
 These devices typically have a plethora of features that increase overall security, to keep
users minds at ease.

SOIS, Manipal raghudathesh.weebly.com Page 53


IoT 607 : IoT Security Block Chain Raghudathesh G P

 These wallets are called “cold” because they do not require to be connected to the
internet in order to store cryptocurrencies. It is only when the user want‟s to transact with
those currencies that the wallet needs to be connected to the internet.
 Pros:
1. The most secure option
2. As it‟s completely offline this provides a greater level of safety

P
Cons:
1. Expensive to buy ($80 USD+)

G
2. Not ideal for quick or regular transactions (because I leave one of mine at home,
and another in a safe deposit box)

SH
Best Cold wallets:
1. Ledger Nano S
2. Trezor - Stores BTC, BCH, BTG, ETH, ZCash, Dash (more coming soon)
3. KeepKey
E
4. Ledger Wallet - Stores BTC, BCH, BTG, ETH, ZCash, Ripple, Dash, ARK,
TH
Stellar, (hopefully Monero coming soon) and more
U DA

Hardware Wallets
GH

Anonymity:
 Bitcoin is often described as an anonymous currency because it is possible to send and
RA

receive bitcoins without giving any personally identifying information.


 Achieving reasonable anonymity with Bitcoin can be quite complicated and perfect
anonymity may be impossible.
 Bitcoin is pseudonymous. Sending and receiving bitcoins is like writing under a
pseudonym.
 If an author‟s pseudonym is ever linked to their identity, everything they ever wrote
under that pseudonym will now be linked to them.

SOIS, Manipal raghudathesh.weebly.com Page 54


IoT 607 : IoT Security Block Chain Raghudathesh G P

 In Bitcoin, your pseudonym is the address to which you receive Bitcoin. Every
transaction involving that address is stored forever in the blockchain. If your address is
ever linked to your identity, every transaction will be linked to you.
 Methods to Make Bitcoin as Anonymous:
1. Bitcoin Mixing:
 Bitcoin transactions are recorded on a public ledger. Anyone who traces a
public address can know the origin and/or destination. There is no protocol

P
level procedure to anonymize these bitcoins, which is why a Bitcoin

G
mixer is required to hide identity.
 Bitcoin mixing is a process which tries to break the linkability or
traceability.

SH
 Mixing breaks the link between bitcoin addresses by either creating
temporary addresses or by swapping coins with other addresses of the


E
same value. This makes the trail hard to follow on the blockchain.
Bitcoin mixing is also referred to as Bitcoin laundering, Bitcoin
TH
washing, or Bitcoin tumbling, and it is a paid service.
 Ex: BITMIXER, Helix
DA

2. Tor - Onion Router to Stay Anonymous:


 You can use a Tor browser to connect with the Bitcoin network. Tor is a
volunteer community which believes in anonymity and surveillance-free
U

internet usage.
 Tor nodes encrypt and route your internet traffic to random computer
GH

nodes on the Tor network before it reaches its final destination. Hence, it
becomes extremely difficult to pinpoint the IP address or system from
which the message or transaction was broadcasted.
RA

 However, if you use a KYC enabled Bitcoin sites


like CoinBase, CoinSecure or any other, then using Tor is not so useful.
when you are using P2P based sites like LocalBitcoins or BitSquare,
using Tor or a VPN is highly recommended.
3. Use Logless VPN:

SOIS, Manipal raghudathesh.weebly.com Page 55


IoT 607 : IoT Security Block Chain Raghudathesh G P

 A logless Virtual Private Network (VPN) is a network which doesn‟t store


the history of your activities on their servers. It encrypts all of your
Internet traffic and routes it through multiple servers of your choice at
different locations before arriving at the final location.
 Some logless VPNs also maintain a shared IP address for multiple users,
hence making it difficult to pinpoint and trace one person‟s identity.
 Using lossless VPNs to connect to your Bitcoin client is a away to

P
improve the privacy of your Bitcoin transactions. But in this case, you
have to trust the VPN service provider not to log your activities.

G
 Few popular based Logless VPN Service Providers are Windscribe,
VPNArea, Mullvad, AirVPN, CoinSutra

SH
Altcoins:
 Altcoins are alternative (Alt) coins which appear to be alternative to Bitcoins.
 E
Bitcoin and altcoins, in general, can have many similarities like- peer to peer transaction,
TH
mining process, etc.
 Various altcoins are trying to target the limitations of Bitcoins, which include its long
transaction time, lack of anonymity, expensive, difficult mining process and insufficient
DA

functionality.
 The vast majority of alt coins are derived from bitcoin‟s source code, also known as
“forks.” Some are implemented “from scratch” based on the blockchain model but
U

without using any of bitcoin‟s source code.


GH

 Based on the date of announcement, the first alt coin that was a fork of bitcoin appeared
in August 2011; it was called IXCoin. IXCoin modified a few of the bitcoin parameters,
specifically accelerating the creation of currency by increasing the reward to 96 coins per
RA

block.
 What distinguishes the best altcoins:
 Like any other currency, the success of cryptocurrencies to is mainly dependent
upon a wide array of parameters Like community, hype and more.
 Partnerships and Investments - New cryptocurrencies are increasingly
being used by companies and this has an effect on its value too.

SOIS, Manipal raghudathesh.weebly.com Page 56


IoT 607 : IoT Security Block Chain Raghudathesh G P

 Ex: Tron announced a partnership with leading gaming platform


Game.com, where users can purchase virtual pets via TRX and
thus the value of Tron is expected to grow.
 Protocol - Generally, there are two types of protocols that altcoins
make use of:
 1. Proof of Work (POW): Using the proof of work
method, miners dedicate their computer's processing power

P
so as to solve a mathematical function (a hash) so as to

G
verify a block-chain transaction.
 Proof of Stake (POS): According to this method, miners
verify the block transactions based on the number of coins

SH
that they deposit (place on a stake) on the network.
 As every method can have its own unique advantages and disadvantages, the negatives of

E
the proof of work protocol are listed below:
1. It uses up greater electrical power hence raising electricity costs.
TH
2. One requires a high-grade setup to successfully mine the more popular coins.
3. The mining reward reduces as more coins are released.

DA

On the other hand, the proof of stake protocol removes the above-mentioned challenges
of a POW protocol through the following features:
1. Does not consume a lot of electrical energy.
U

2. Does not require a high-grade setup (A simple laptop would be enough).


3. Validations are faster and the validators are more loyal.
GH

 Inference: Altcoins that use the Proof of Stake protocol are likely to gain greater
popularity as neither do they require a high-grade setup nor do they consume a high level
of electricity.
RA

 The proof of stake protocol also carries certain loopholes. For instance, if the majority of
the tokens are owned by a small group of people, then they themselves will be the
validators.
 Platform:
 The success of an altcoin depends on the Blockchain technology that which the
altcoin uses. Blockchains of different altcoins tend to have varying characteristics,

SOIS, Manipal raghudathesh.weebly.com Page 57


IoT 607 : IoT Security Block Chain Raghudathesh G P

each of which plays a role in determining whether it would make it to the list of
the best altcoin or not. The blockchain characteristics that affects altcoins
include:
 The energy required to be put in to secure Blockchain
 The mining difficulty level of the Blockchain
 The transaction time
 The Rewards:

P
 The energy required by a blockchain is a pretty important factor since it

G
determines whether the majority of the people will be able to afford to mine the
altcoin or not.
 Ex: POW blockchains tend to require a pretty high amount of electricity and

SH
processing power.
 Blockchains that carry a high mining difficulty level tend to be more secure and

E
hence, the greater is the price of the altcoin that is associated with it.
 The time that is taken to validate a transaction on the blockchain is yet another
TH
factor that differentiates a top altcoin from a mediocre one. The best altcoin is
usually the one that has a low transaction time.
 The reward that is received upon a successful transaction is yet again, another
DA

factor that determines the initial success of an altcoin. The greater the reward, the
more successful the altcoin would initially be. However, as with all blockchains
U

following the POW protocol, the amount of reward reduces as more and more
attcoins are released with time.
GH

 Community:
 Today millions of people are connected to Altcoin, wish has resulted in the
formation of a community around these Altcoins. This hype around new and
RA

emerging Attcoins has a great effect on value.


 Problems That Some Altcoins Try To Solve:
 Despite its popularity around the world Bitcoins are not perfect.
 Many users of Bitcoin face issues especially in terms of high transaction fees,
which can be rather incontinent.

SOIS, Manipal raghudathesh.weebly.com Page 58


IoT 607 : IoT Security Block Chain Raghudathesh G P

 Many altcoins have already found solutions to similar problems white much more
are trying to come up with even better ideas. The more problem solving the
altcoin is, the more it is expected to grow.
 Team:
 If you are interested in top altcoins or if you are trying to find the best altcoins to
invest in, one of the essential factors you need to pay attention to is the team
behind the altcoin. At first this may seem a bit strange, however, as a matter of

P
fact, the team has a lot to do with any altcoin's success in terms of the in-depth

G
understanding of the currency and the ability to manage possible issues.
 Varients of Altcoins: Steem, Ardor, Ethereum,stratis, Liecoin, Carano, Monero, ICO
(Initial Coin Offering)

SH
IOTA (Next Generation Blockchain):
 IOTA is a open source distributed ledger designed to record, execute transactions to
E
facilitate secure payments and communications between machines in the Internet of
TH
Things (IoT) ecosystem.
 IOTA has a cryptocurrency called mIOTA.
 IOTA‟s platform uses a Decentralized Acyclic Graph (DAG) instead of a blockchain
DA

technology to allows users to transact without incurring any fees.


 OTA intends to become the standard mode of transacting between Internet-connected
devices in the future.
U

 Their founder David Sonstebo, Dominik Schiener, Dr Serguei Popov, and Sergy
GH

Ivancheglo envision IOTA to be a public, permissionless backbone for the Internet of


Things that enable true interoperability between all devices
 IOTA‟s cryptocurrency - mIOTA - will enable micropayment transactions between
RA

connected devices. For example, it might enable you to purchase individual grocery items
from an ecommerce site using your Internet-connected fridge
 Confirmation and transaction times are faster than the blockchain, and the number of
individual transactions that the system can process simultaneously is unlimited - a distinct
advantage over the sometimes sluggish blockchain.

SOIS, Manipal raghudathesh.weebly.com Page 59


IoT 607 : IoT Security Block Chain Raghudathesh G P

 IOTA‟s distributed ledger, by contrast, does not consist of transactions grouped into
blocks and stored in sequential chains, but as a stream of individual transactions
entangled together as shown below

P
Figure: IOTA Tangle

G
 In order to participate in this network, a participant simply needs to perform a small
amount of computational work that verifies two previous transactions. Rather than

SH
creating a hierarchy of roles and responsibilities in the network, every actor has the same
incentives and rewards.
 In order to make a transaction in the Tangle, two previous transactions must be validated
E
with the reward for doing so being the validation of your own transaction by some
TH
subsequent transaction. With this 'pay-it-forward' system of validations, there is no need
to offer financial rewards. Transacting with IOTA is and will always be completely fee-
free.
DA

 Without the need for monetary rewards, IOTA is not limited to transactional value
settlements. It is possible to securely store information within Tangle transactions, or
U

even spread larger amounts of information across multiple bundled or linked transactions.
This structure also enables high scalability of transactions. The more activity in „the
GH

Tangle‟, the faster transactions can be confirmed as shown below


RA

Figure: IOTA Tangle Expansion


 Do visit the site below to get acquaint with IOTA tangle study with simulation:
https://blog.iota.org/the-tangle-an-illustrated-introduction-4d5eae6fe8d4

SOIS, Manipal raghudathesh.weebly.com Page 60


IoT 607 : IoT Security Block Chain Raghudathesh G P

Question Bank
1. What is double spending in digital currencies? How Block chain can overcome this.
2. Explain the following elements of block chain: Block, Genesis Block, Merkle Trees,
Mining, Miners.
3. Describe Bitcoin P2P Network.
4. Explain various types of nodes and their roles in Bitcoin P2P Network.
5. Explain Decentralized Consensus.

P
6. What is Proof of Work in block chain?
7. Explain Locking and Unlocking scripts in Bitcoin transactions.

G
8. What is a smart contract? Explain with a scenario.
9. What is a crypto currency wallet and list out various types of crypto currency wallet.

SH
10. What are Hot and Cold Wallets?
11. Write a note on: i. Altcoin, ii. IoTA

E
TH
U DA
GH
RA

SOIS, Manipal raghudathesh.weebly.com Page 61

You might also like