Dbatu University Blockchain Notes BCT 1st Unit
Dbatu University Blockchain Notes BCT 1st Unit
Public ledger
•A public ledger is an open-access network; anyone can join at any time.
•The public ledger is fully decentralized, and no single entity controls the
blockchain network.
• The Bitcoin and Ethereum blockchains are both considered public ledgers.
The public ledger was available for general public viewing as well as for
verification
The public ledger is utilized as a record-keeping system that supports
participants' identities in a more secure and (pseudo-)anonymous form, their
respective cryptocurrency balances, and a record book of all the genuine
transactions completed between network participants.
public ledger is a record-keeping system
Smart Contracts
Smart contracts are simply programs stored on a blockchain that run when
predetermined conditions are met. They typically are used to automate the
execution of an agreement so that all participants can be immediately certain of
the outcome, without any intermediary's involvement or time loss.
Smart contracts are self-executing contracts in which the contents of the buyer-
seller agreement are inscribed directly into lines of code.
Using it makes the transactions traceable, transparent, and irreversible.
Benefits of Smart Contracts
• Distributed: All bitcoin transactions are recorded in a public ledger known as the blockchain. There are nodes in
the network that maintain copies of the ledger and contribute to the correct propagation of the transactions
following the rules of the protocols making it impossible for the network to suffer downtime.
• Decentralized: There is no third party or no CEO who controls the bitcoin network. The network consists of
willing participants who agree to the rules of a protocol and changes to the protocol are done by the consensus of
its users. This makes bitcoin a quasi-political system.
• Transparent: The addition of new transactions to the blockchain ledger and the state of the bitcoin network is
arrived upon by consensus in a transparent manner according to the rules of the protocol.
• Peer-to-peer: In Bitcoin transactions, the payments go straight from one party to another party so there is no need
for any third party to act as an intermediary.
• Public: All bitcoin transactions are available publicly for everyone to see. All the transactions are recorded, which
eliminates the possibility of fraudulent transactions.
• Permissionless: Bitcoin is completely open access and ready to use for everyone, there are no complicated rules of
entry. Any transaction that follows the set algorithm will be processed with certainty.
Drawbacks of bitcoins
Public Ledgers
◦ The ledger which holds the details of all transactions which happen on the Blockchain, is open and completely accessible to everyone who
is associated with the system.
◦ Even though the complete ledger is publicly accessible, the details of the people involved in the transactions remains completely
anonymous.
The first cryptocurrency was Bitcoin, which was founded in 2009 and
remains the best known today. Much of the interest in cryptocurrencies is
to trade for profit, with speculators at times driving prices skyward.
How does cryptocurrency work
Cryptocurrencies run on a distributed public ledger called blockchain, a
record of all transactions updated and held by currency holders.
Units of cryptocurrency are created through a process called mining,
which involves using computer power to solve complicated
mathematical problems that generate coins. Users can also buy the
currencies from brokers, then store and spend them using cryptographic
wallets.
If you own cryptocurrency, you don’t own anything tangible. What you
own is a key that allows you to move a record or a unit of measure from
one person to another without a trusted third party.
Cryptographic primitives
Hashing Functions
A hashing function is a mathematical function that takes an input and returns a fixed-size string of
characters, or hash. Hashing functions are commonly used in cryptography to create digital signatures
and to verify the integrity of data.
SHA3-256 is a commonly used hash function.
SHA3-256(“Hello world”) =
“369183d3786773cef4e56c7b849e7ef5f742867510b676d6b38f8e38a222d8a2”
SHA3-256(“hello world”) =
“644bcc7e564373040999aac89e7622f3ca71fba1d972fd94a31c3bfbf24e3938”
Determinism: A given input will always produce the same output.
Pre-image resistance: Given a hash, it is computationally infeasible to find an input that would produce
that hash.
Collision resistance: It is computationally infeasible to find two different inputs that produce the same
hash.
Fixed-length output: Regardless of the size of the input string, the hash function will always generate an
output string of the same length.
Hash Pointer
.
A hash pointer is a data structure that is used a lot in the systems.
· It is basically a pointer to the place where some information is stored.
· Together with the pointer, a cryptographic hash of the information is
stored.
Hash Pointer is comprised of two parts:
•Pointer to where some information is stored.
•Cryptographic hash of that information.
The pointer can be used to get the information, the hash can be used to
verify that information hasn't been changed
Merkle tree
Merkle tree is a fundamental part of blockchain technology.
· A Merkle tree is a data structure that is used in computer science
applications.
· It is composed of hashes of different blocks of data, and which serves as a
summary of all the transactions in a block.
· It also helps to verify the consistency and content of the data.
· Both Bitcoin and Ethereum use Merkle Trees structure.
· Merkle Tree is also known as Hash Tree.
· It serves to encode blockchain data more efficiently and securely.
· They are also referred to as binary hash trees.
A Merkle tree stores all the transactions in a block by producing a digital fingerprint of
the entire set of transactions.
· It allows the user to verify whether a transaction can be included in a block or not.
· Merkle trees are created by repeatedly calculating hashing pairs of nodes until there is
only one hash left.
· Every leaf node is a hash of transactional data, and the non-leaf node is a hash of its
previous hashes.
· Merkle trees are in a binary tree, so it requires an even number of leaf nodes.
· If there is an odd number of transactions, the last hash will be duplicated once to
create an even number of leaf nodes.
The above example is the most common and simple form of a Merkle tree,
i.e., Binary Merkle Tree.
· There are four transactions in a block: TX1, TX2, TX3, and TX4.
· There is a top hash which is the hash of the entire tree, known as the Root Hash,
or the Merkle Root.
· Each of these is repeatedly hashed, and stored in each leaf node, resulting in Hash
0, 1, 2, and 3.
· The two hashes (Hash01 and Hash23) are then hashed again to produce the Root
Hash or the Merkle Root.
Merkle Root is stored in the block header.
· The block header is the part of the bitcoin block which gets hash in the
process of mining.
· It contains the hash of the last block, a Nonce, and the Root Hash of all the
transactions in the current block in a Merkle Tree.
· So having the Merkle root in block header makes the transaction tamper-
proof.
· As this Root Hash includes the hashes of all the transactions within the
block, these transactions may result in saving the disk space.
The Merkle Tree maintains the integrity of the data.
· If any single detail of transactions or order of the transaction's changes, then these changes reflected
in the hash of that transaction.
· This change would cascade up the Merkle Tree to the Merkle Root, changing the value of the
Merkle root and thus invalidating the block.
· So everyone can see that Merkle tree allows for a quick and simple test of whether a specific
transaction is included in the set or not.
Public key cryptography isPublic Key Cryptography
an asymmetric type of cryptography where we
use a pair of keys (public key and private key). It uses them to
encrypt/decrypt the information and verify the users.
Encryption of the information at the sender’s end using the public key (of
the receiver). This ensures that no third party can access or understand the
encrypted information in or out of the network. Only the intended receiver
ca
public-key cryptography is a way of providing a digital identity to the user.
Through this one can carry out secure transactions within a blockchain
networkn decrypt and read the message using its own private key.
A public key is the counterpart of a private key as it is cryptographically
derived from it. A public key is available for all the nodes in the network.
This helps in the verification of a transaction by all the nodes in a
blockchain network. Let’s suppose that you are a node in the network and
you want to send a message or information to another node.
To carry out a secure transaction you will sign the message from your
private key and send it for verification from the entire network. Each node
can access your public key and so they will verify the transaction as
authentic and pass it. When all the nodes verify your transaction using your
public key the transaction can take place. Generally, a public address is used
for transactions rather than the public key because of its length. The public
key is long and not easily shareable. So, a shorter version of it is created by
hashing which is the public address.
The two main functions of a public key in providing security in a
blockchain network are:
a. To encrypt a message or information using the public key of the
receiver. This ensures that only the receiver who has its
corresponding private key can decrypt and read the message.
b. To verify if the sender is authentic by confirming the digital
signature. A digital signature is done by the sender’s private key. A
public key verifies the sender’s identity by matching
(complementing) with his private key.
Suppose you are a legitimate node on a blockchain network. Now, you need to
have three things in order to carry out secure transactions within the network; a
private key, a public key, and a wallet address, or a public address.
For this, you need to install a blockchain wallet software that will automatically
create a pair of private key and public key and a wallet address. This software is an
independent platform from the blockchain.
It gives you a digital identity and a safe place to keep your keys.
Furthermore, your public address is like a mailbox and your private key is like the
key of that mailbox.
Your mailbox or its address is known to everyone and anyone can send you things
using the mailbox. But, only you can open your mailbox and access the contents
inside it using the key to the mailbox. Similarly, anyone within the blockchain
network can send you tokens or messages to your public address. But only you can
decrypt and read that message using your private key.
Digital signature
digital signature is created by the Elliptic Curve Digital Signature
Algorithm (ECDSA)
the purpose of doing a digital signature before sending the information is
to state authority over the information and tokens (cryptocurrency). It is
like signing a cheque where you state that it is your money that you are
giving from your authorized bank account.
when you digitally sign the information you send in a blockchain
network, you say that you are an authorized node. And you rightfully own
the tokens or currency you wish to give to someone in the
network. Therefore, the digital signature proves the ownership of the funds
and the account and protects them from forgery