Unit II
Unit II
Cryptography in Blockchain:
Cryptography is the method of securing important data from unauthorized access. In the blockchain,
cryptographic techniques are a part of security protocols. It secures a transaction taking place between two
nodes in a blockchain network. As we know from our previous discussions, blockchain technology is based
on three main pillars; Distributed ledger, Peer-to-peer network, and Cryptographic security.
The successful and safe working of a distributed ledger system and the point-to-point network is impossible
without a robust security technique in place. Blockchain uses two types of security approaches
i.e. Cryptography and Hashing. The basic difference between these two is that cryptography is used to
encrypt messages in a P2P (Point-to-Point) network. Whereas, hashing is used to secure block information
and link blocks in a blockchain.
So, in this discussion, we keep our focus on how we can use these cryptographic techniques, keys, and
algorithms. How we can use them to secure a message or information at one node and sent to the other.
We can break down the word cryptography into two parts; Crypto meaning “hidden” and Graphy meaning
“writing”. Therefore, cryptography is a method of converting plaintext into unreadable coded text.
Two main concepts behind cryptography are Encryption and Decryption. Encryption is coding information in
such a way that you and I cannot understand what it means just by looking at it. Decryption is the reverse of
encryption, i.e. decoding of the coded information.
The encrypted text or information is also known as ciphertext. And this ciphertext is deciphered through
specific techniques known as a cipher (steps of encoding). Therefore, cryptography is a security method that
secures a transition or exchange of information between two nodes and prevents it from third-party
intervention.
We have discussed the Byzantine generals’ problem earlier in the Blockchain security lesson. Blockchain’s
solution to the Byzantine generals’ problem is cryptography. A blockchain network uses cryptographic
techniques at two levels that keep the data secure. One is the key-encryption method and another is hashing.
Key encryption is a cryptographic method that ensures safe transmission of information from point A to point
B. This is like an external layer of protection. The internal layer is hashing. Hashing is a process of
irreversible encryption of data in a block. All the data present in the block is encrypted using the SHA256
hashing algorithm which is irreversible. Thus, applying cryptography at two levels in a blockchain network
makes it absolutely secure.
The Block Chain is the invention that allows digitally generated information to be allocated without being
copied. BlockChainTechnology is the heart of the new internet i.e. digital currency, BitCoin and any other
online transaction. Tech experts found a big potential in this technology. “Block Chain is an incorruptible
digital ledger of economic transaction that can be programmed to record not just financial transactions but
virtually everything of value.”In plain layout, the data is not owned by any single computer but by a chain
of computers so that the blocks of data are secured and bound to each other using chain, that technology is
known as Block Chain technology. There is no transaction cost due to Block Chain, in Layman language
Block Chain is a process to pass information or data from A to B in a safe and automated manner.
Crypto currency works on the principle of Block Chain Technology, that is why, Block Chain is the most
trending item of current era, due to it’s secure nature crypto currency is widely accepted. It’s value is
increasing day by day. Many oil industries, IBM Technologies, Mercedes Benz, Swiss Bank, Samsung,
and even Google is planning to launch their own cryptocurrency in 2019 for safe and secure transactions.
Now, this technology is disrupting almost every market share due to its popularity and demand in the
world.
Satoshi Nakamoto introduced the concept of BlockChain in 2008 in the form of cryptocurrency BitCoin.
It’s function is to allow users to secure and control their monetary values so that no third party like
government or banks would be able to access or control it. It is a process to carry everyone to the highest
grade of liability.Three technologies work behind the BlockChain Technology-
Private Key Cryptography
Peer 2 Peer Network
BlockChain’s Protocol
Program Private Key
Cryptography
Peer 2 Peer Network
BlockChain’s Protocol Program
Blockchain, as one of the crypto-intensive creatures, has become a very hot topic recently. Although many
surveys have recently been dedicated to the security and privacy issues of blockchains, there still lacks a
systematic examination on the cryptographic primitives in blockchains.
Since its introduction in the early 1980s (Chaum, 1982), the design of e-cash has always been one of the
main research topics in the field of cryptography. However, the one without any trusted third party
remained an open problem till Bitcoin (Nakamoto) launched in 2009. Due to its decentralization,
unforgeability, double- spending resistance and pseudonymity, this brand new e-cash system has brought
a remarkable culmination of cryptocurrency research and its applications. Based on its main framework,
many new cryptocurrencies including decentralized (such as (Litecoin), Nxtcoin (Nxt)) and centralized
ones (such as RScoin (Danezis and Meiklejohn, 2016)) have been proposed. The market value of these
cryptocurrencies has increased more than 30 times during 2017 (from about $17 billion on 1st Jan. to $591
billion on 31st Dec.) (Coinmarketcap). As the core technology behind Bitcoin, the blockchain has
demonstrated its capability of innovation and infiltration in many domains, including finance,
insurance, industry, healthcare, agriculture and so on.
There are many recent surveys have been dedicated to the security and privacy issues of blockchains .
classify cryptographic primitives in blockchains into two categories: primary and optional. The former
category includes cryptographic hashes and standard digital signatures that are essential for ensuring the
blockchain as a globe ledger with tamper-proof, public verifiability and achievable consensus. While the
latter category, mainly used for enhancing the privacy and anonymity of blockchain-based transactions,
covers some special signatures (such as ring signatures), commitments, accumulators, zero-knowledge
proofs and so on.
Special signature primitives for blockchains: To enhance the privacy and anonymity of transactions, some
advanced signature primitives such as ring signature and multi-signature are also widely applied in blockchains.
1.Ring signatures :
Anonymity is always required in information systems (Shen et al., 2018), especially in the e-cash system.
However, Bitcoin can only provide pseudonymity due to the linkability of transactions. Therefore, many new
alternative cryptocurrencies have been proposed to address this problem. From a perspective of cryptography,
there are many kinds of signatures for achieving anonymity, such as blind signature (Chaum, 1982), ring
signature (Rivest et al., 2001), group signature (Chaum and van Heyst, 1991) and DC-nets (Chaum, 1988).
However, only ring signature and its variants have been used in blockchains for anonymity.
Another interesting primitive related to ring signature and blockchain is the so-called Borromean (ring)
signature (BRS), proposed by Maxwell and Poelstra in 2015 (Maxwell and Poelstra, 2015). Poelstra
(Poelstra, 2017) claimed that BRS is now used in Elements (Element, 2015), Liquid (Liquid) and Monero.
4. Multi-signatures:
The primitive of multi-signature allows a single signature to work as several ordinary signatures on the same
message. One of the critical requirements of multi-signature is that the single signature has the same size as
one regular signature.
Assymetric cryptography:
Public Key Cryptography or in short PKI is also known as asymmetric cryptography. It uses two pairs of
keys - public and private. A key is a some long binary number. The public key is distributed worldwide and
is truly public as its name suggests. The private key is to be strictly held private and one should never lose
it.
In case of Bitcoin, if you ever lose the private key to your Bitcoin wallet, the entire contents of your wallets
would be instantly vulnerable to theft and before you know it, all your money (the contents of your wallet)
would be gone with no mechanism in the system to trace out who stole it - that is the anonymity in the
system that I mentioned earlier.
The PKI accomplices’ two functions - authentication and the message privacy through
encryption/decryption mechanism. I will now explain both these functions
Authentication
When the two parties exchange messages, it is important to establish a trust between the sender and the
receiver. Especially, the receiver must trust the source of message. Going to our earlier scenario (depicted in
Figure 1) of Bob sending some money to Lisa for purchasing of some goods from her, let us see how the
PKI builds this trust between Bob and Lisa. Look at below image
In the first place, if Bob wants to send some money to Lisa, he has to create a private/public key of its own.
Note that both keys are always paired together and you can not mix the private and public keys of different
individuals or different instances.
Now, Bob says that he is sending $10 to Lisa. So he creates a message (a plain-text message) containing Bob’s
(sender) public key, Lisa’s (receiver) public key, and the amount ($10).
The purpose of this remittance such as “I want to buy pumpkin from you” is also added into the message. The
entire message is now signed using Bob’s private key. When Lisa receives this message, she will use the
signature verification algorithm of PKI and Bob’s public key to ensure that the message indeed originated from
Bob. How the PKI works is beyond the scope of this tutorial. The interested reader is referred to this site for a
more detailed discussion on PKI. This establishes the authenticity of the message originator. Now, let us look at
the message privacy
Message Privacy:
Now, as Lisa has received her payment, she wants to send the link to her ebook which Bob wants to buy. So
Lisa would create a message and send it to Bob as shown in image
Public and private keys -line interface:
In order to understand public key cryptography, the first concept that needs to be looked at is the idea of public
and private keys.
A private key, as the names suggests, is basically a randomly generated number that is kept secret and held
privately by the users. Private key needs to be protected and no unauthorized access should be granted to that
key; otherwise, the whole scheme of public key cryptography will be jeopardized as this is the key that is used to
decrypt messages. Private keys can be of various lengths depending upon the type and class of algorithms used.
For example, in RSA, typically, a key of 1024-bit or 2048-bits is used. 1024-bit key size is no longer considered
secure and at least 2048 bit is recommended to be used in practice.
A public key is the public part of the private-public key pair. A public key is available publicly and published by
the private key owner. Anyone who would then like to send the publisher of the public key an encrypted
message.
The Lisa creates a message such as “Here is the link to my ebook which you had requested”, signs it with Bob’s
public key that she has received in Bob’s request message and also encrypts the message using some secret key
which is shared between the two during HTTPS handshake.
Now, Lisa is sure that only Bob can decode the message using the private key that is held by Bob alone. Also,
somebody intercepting the message would not be able to recover its contents because the contents are encrypted
by a secret key held only by Bob and Alice. This guarantees to Lisa that access to her ebook is granted only to
Bob.
Having seen both the features, Authentication and Message Privacy, implied by PKI, let us move ahead to see
how Bitcoin makes use of PKI to secure the public ledger.
Major cryptocurrencies like Bitcoin, Ethereum, and Bitcoin Cash function using three fundamental pieces of
information: the address, associated with a balance and used for sending and receiving funds, and the address’
corresponding public and private keys. The generation of a bitcoin address begins with the generation of a
private key. From there, its corresponding public key can be derived using a known algorithm. The address,
which can then be used in transactions, is a shorter, representative form of the public key.
The private key is what grants a cryptocurrency user ownership of the funds on a given address. The Blockchain
wallet automatically generates and stores private keys for you. When you send from a Blockchain wallet, the
software signs the transaction with your private key (without actually disclosing it), which indicates to the entire
network that you have the authority to transfer the funds on the address you’re sending from.
The security of this system comes from the one-way street that is getting from the private key to the public
address. It is not possible to derive the public key from the address; likewise, it is impossible to derive the private
key from the public key.
In the Blockchain.com Wallet, your 12-word Secret Private Key Recovery Phrase is a seed of all the private keys
of all the addresses generated within the wallet. This is what allows you to restore access to your funds even if
you lose access to your original wallet. Using the recovery phrase will allow you to recover your crypto.
Bitcoin improvement proposals (BIPs):
A Bitcoin Improvement Proposal (BIP) is a design document for introducing features or information to Bitcoin.
This is the standard way of communicating ideas since Bitcoin has no formal structure.
The first BIP (BIP 0001) was submitted by Amir Taaki on 2011-08-19 and described what a BIP is.
Types
Standards Track BIPs - Changes to the network protocol, block or transaction validation, or anything
affecting interoperability.
Informational BIPs - Design issues, general guidelines. This type of BIP is NOT for proposing new
features and do not represent community consensus
Process BIPs - Describes or proposes a change in process. Similar to Standards BIPs but apply outside
the Bitcoin protocol.
Layers
1. Consensus
2. Peer Services
3. API/RPC
4. Applications
Workflow:
We know that Blockchain is a distributed decentralized network that provides immutability, privacy, security,
and transparency. There is no central authority present to validate and verify the transactions, yet every
transaction in the Blockchain is considered to be completely secured and verified. This is possible only because
of the presence of the consensus protocol which is a core part of any Blockchain network.
A consensus algorithm is a procedure through which all the peers of the Blockchain network reach a common
agreement about the present state of the distributed ledger. In this way, consensus algorithms achieve reliability
in the Blockchain network and establish trust between unknown peers in a distributed computing environment.
Essentially, the consensus protocol makes sure that every new block that is added to the Blockchain is the one
and only version of the truth that is agreed upon by all the nodes in the Blockchain.
The Blockchain consensus protocol consists of some specific objectives such as coming to an agreement,
collaboration, co-operation, equal rights to every node, and mandatory participation of each node in the
consensus process. Thus, a consensus algorithm aims at finding a common agreement that is a win for the entire
network.
Now, we will discuss various consensus algorithms and how they work.
ProofofWork(PoW):
This consensus algorithm is used to select a miner for the next block generation. Bitcoin uses this PoW
consensus algorithm. The central idea behind this algorithm is to solve a complex mathematical puzzle and easily
give out a solution. This mathematical puzzle requires a lot of computational power and thus, the node who
solves the puzzle as soon as possible gets to mine the next block. For more details on PoW, please read Proof of
Work (PoW) Consensus
PracticalByzantineFaultTolerance(PBFT):
Please refer to the existing article on practical Byzantine Fault Tolerance(pBFT).
ProofofStake(PoS):
This is the most common alternative to PoW. Ethereum has shifted from PoW to PoS consensus. In this type of
consensus algorithm, instead of investing in expensive hardware to solve a complex puzzle, validators invest in
the coins of the system by locking up some of their coins as stake. After that, all the validators will start
validating the blocks. Validators will validate blocks by placing a bet on it if they discover a block which they
think can be added to the chain. Based on the actual blocks added in the Blockchain, all the validators get a
reward proportionate to their bets and their stake increase accordingly.
In the end, a validator is chosen to generate a new block based on their economic stake in the network. Thus, PoS
encourages validators through an incentive mechanism to reach to an agreement.
ProofofBurn(PoB):
With PoB, instead of investing into expensive hardware equipment, validators ‘burn’ coins by sending them to
an address from where they are irretrievable. By committing the coins to an unreachable address, validators earn
a privilege to mine on the system based on a random selection process. Thus, burning coins here means that
validators have a long-term commitment in exchange for their short-term loss.
Depending on how the PoB is implemented, miners may burn the native currency of the
Blockchain application or the currency of an alternative chain, such as bitcoin. While
PoB is an interesting alternative to PoW, the protocol still wastes resources needlessly.
And it is also questioned that mining power simply goes to those who are willing to burn
more money.
ProofofCapacity:
In the Proof of Capacity consensus, validators are supposed to invest their hard drive
space instead of investing in expensive hardware or burning coins. The more hard drive
space validators have, the better are their chances of getting selected for mining the next
block and earning the block reward.
ProofofElapsedTime:
PoET is one of the fairest consensus algorithms which chooses the next block using fair
means only. It is widely used in permissionned Blockchain networks. In this algorithm,
every validator on the network gets a fair chance to create their own block. All the nodes
do so by waiting for random amount of time, adding a proof of their wait in the block.
The created blocks are broadcasted to the network for others consideration. The winner is
the validator which has least timer value in the proof part. The block from the winning
validator node gets appended to the Blockchain. There are additional checks in the
algorithm to stop nodes from always winning the election, stop nodes from generating a
lowest timer value.
There also exist other consensus algorithms like Proof of Activity, Proof of Weight,
Proof of Importance, Leased Proof of Stake, etc. It is therefore important to wisely
choose one as per the business network requirement because Blockchain networks cannot
function properly without the consensus algorithms to verify each and every transaction
that is being commited.