0% found this document useful (0 votes)
2 views28 pages

Lecture 5 - Block

The document discusses the CAP theorem, which states that distributed systems can only guarantee two out of three properties: consistency, availability, and partition tolerance. It also covers Bitcoin's structure, including blocks, timestamps, proof-of-work, and Merkle trees, which are used to efficiently verify transactions. Additionally, it introduces Bitcoin Improvement Proposals (BIPs) as formal proposals for changes to the Bitcoin protocol.

Uploaded by

sohailyasserr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views28 pages

Lecture 5 - Block

The document discusses the CAP theorem, which states that distributed systems can only guarantee two out of three properties: consistency, availability, and partition tolerance. It also covers Bitcoin's structure, including blocks, timestamps, proof-of-work, and Merkle trees, which are used to efficiently verify transactions. Additionally, it introduces Bitcoin Improvement Proposals (BIPs) as formal proposals for changes to the Bitcoin protocol.

Uploaded by

sohailyasserr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Blockchain and Cryptocurrencies

Bitcoin Transactions
and Merkle Trees

Prepared by:
Dr. Hossam Mahmoud Moftah
Faculty of Computers and Artificial Intelligence
Beni-Suef University
CAP theorem
• CAP theorem also known as Brewer’s theorem
is a concept used for distributed systems. It says
that any distributed system provides only 2
guarantees out of the three (C, A & P) . This
theorem is used by System Designers to choose
the best architecture when designing distributed
systems.

https://medium.com/nerd-for-tech/cap-theorem-with-focus-on-partition-tolerance-1af4403cb35a
CAP theorem

https://medium.com/nerd-for-tech/cap-theorem-with-focus-on-partition-tolerance-1af4403cb35a
CAP theorem in protocols
All have their place.
• Availability + consistency
– Single-site databases
– (Not an option for distributed systems)
• Partition tolerance + consistency
– Distributed databases
– Majority protocols
• Partition tolerance + availability
– DNS

Source: Prof. Tom Austin, San José State University


Bitcoin
• Partition tolerance
– Yes – pretty much essential for dist. protocols
• Availability
– Yes
• Consistency
– "Eventually consistent"
• Fancy term for "not consistent"
– Transactions may be dropped
– But… pretty good after a while

Source: Prof. Tom Austin, San José State University


Lab, part 2: Break consistency of
distributed ledger
Eject a user by framing them as a cheater.

Send different messages to different clients


to confuse them.

How could we defend against this attack?

Source: Prof. Tom Austin, San José State University


Bitcoin Blocks
• Collections of transactions
• Fixed size
• Collectively, form a blockchain
• Genesis block – the very first block

Source: Prof. Tom Austin, San José State University


Block Information
• Version
• Timestamp
• Previous block hash
• Proof-of-work (PoW) target
• Nonce (the "proof") Determines
transactions in
• Merkle root block

Source: Prof. Tom Austin, San José State University


Block Version
• The block version number indicates which set of block
validation rules to follow. See the list of block versions
below.
• Version 1 was introduced in the genesis block (January
2009).
• Version 2 was introduced in Bitcoin Core 0.7.0 (September
2012)
• Version 3 blocks were introduced in Bitcoin Core 0.10.0
(February 2015)
• Version 4 blocks specified in BIP65 and introduced
in Bitcoin Core 0.11.2 (November 2015)

https://developer.bitcoin.org/
What Is a Bitcoin Improvement Proposal (BIP)?

• A Bitcoin Improvement Proposal (BIP) is a formal proposal


to change Bitcoin.
• As a piece of software, Bitcoin is always undergoing
upgrades—bugs need to be fixed, algorithms can be made
more efficient, code can be simplified, compatibility with
other software must be maintained, and new features can be
added.

https://developer.bitcoin.org/
What is Timestamp?

• The timestamp is a small data stored in each block as a


unique serial and whose main function is to determine the
exact moment in which the block has been mined and
validated by the blockchain network.

https://academy.bit2me.com/
What is a block hash?

• a block hash is a unique identifier for each block, generated


by applying a cryptographic hash function to the block's
data. It serves as a digital fingerprint, representing the entire
block's contents.

https://how.dev/
What is proof-of-work in PoW?

• Proof-of-work (“PoW”) is a consensus mechanism that


incentivizes network transaction validation by rewarding
network participants, called “miners,” who operate nodes
adding computational resources to the network.

• PoW involves validating transactions on a network and


adding them in blocks to the distributed ledger.

• The core of the PoW (Proof of Work) process involves


finding a hash below a target value set by the network. The
hash function used by Bitcoin is double SHA-256, which
produces a 256-bit hash value.

https://www.sec.gov/
https://scryptplatform.medium.com/
What is proof-of-work in PoW?

• Miners generate hash values by combining the block header


information with the nonce and passing it through the hash
function.
• Since the output of the hash function is unpredictable,
miners essentially guess different nonce values until they
find one that produces a hash below the target value.

• This process requires a significant amount of computational


power and is referred to as mining.

https://scryptplatform.medium.com/
The target hash

• The target hash is used in determining the difficulty of the


input and can be adjusted in order to ensure that blocks are
processed efficiently.

• At the time of this publication, the target hash requires 19


leading zeros for a miner to win the right to mine the block!

• However, if a miner discovers a hash with more than 19


leading zeros, the miner will still win the right to mine the
block.

https://www.investopedia.com/
https://scryptplatform.medium.com/
What is nonce in blockchain?

• Nonce is an abbreviation for “number used only once” or


“number once”. It is a random number that the Bitcoin
mining program uses.
• Nonce is included in the header block and then that number
is hashed.
• the function of a nonce is to be used as a base or as an
anchor to generate a hash value for a particular block in a
blockchain.

https://metaschool.so/
Block chain DEMO

• DEMO: https://andersbrownworth.com/blockchain
Merkle Trees
• Binary tree
• All nodes are hashes
– Leaves: hashes of the data
• Transactions, for Bitcoin
– Inner nodes: hashes of children nodes
• Definitions
– Merkle root: root of a Merkle tree
– Merkle path: nodes needed to reconstruct Merkle
root

Source: Prof. Tom Austin, San José State University


Merkle Trees
H1 = H(H(A),H(B)) MR

H2 = H(H(C),H(D)) H2
H1

MR = H(H1,H2)
H(A) H(B) H(C) H(D)
(Merkle root)

A B C D

Source: Prof. Tom Austin, San José State University


What if we have individual nodes?

The solution is to duplicate the nodes as shown in the figure.

https://www.youtube.com/watch?v=fB41w3JcR7U
Using Merkle Trees
• Merkle root is known
• Validator requests specific transaction
• Miner provides Merkle path
– Pieces needed to reconstruct Merkle root

Source: Prof. Tom Austin, San José State University


Merkle path
• Merkle path: represents the information which the user
needs to calculate the expected value for the Merkle root for
a block, from their own transaction hash contained in that
block.
• The Merkle path is used as part of of the Merkle proof.

https://docs.alchemy.com/
Using Merkle path to verify transactions
• What if we wanted to verify Transaction K?
• All we would need are the blue nodes to reconstruct the root,
so we wouldn't need the other nodes, thus saving a lot of time
until we reached the root.

https://www.youtube.com/watch?v=2kPFSoknlUU
Merkle Path
Merkle path for MR

transaction B:
• Transaction B H1 H2

• H(A)
• H2 H(A) H(B) H(C) H(D)

A B C D

Source: Prof. Tom Austin, San José State University


Why a Merkle Tree?
• Log n hashes to verify a transaction
• Minimal data needed to transmit
across the network
• Old transactions may be pruned

Source: Prof. Tom Austin, San José State University


Reading for Upcoming Classes
• Mastering Bitcoin, Chapters 1-2
–Bitcoin overview and history
• Mastering Bitcoin, Chapter 9
–Reviews the blockchain
• Mastering Bitcoin, Chapter 10
–Reviews mining and consensus

Source: Prof. Tom Austin, San José State University


Lab: Implement a Merkle Tree
Thank you

You might also like