Lecture 5 - Block
Lecture 5 - Block
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
https://developer.bitcoin.org/
What Is a Bitcoin Improvement Proposal (BIP)?
https://developer.bitcoin.org/
What is Timestamp?
https://academy.bit2me.com/
What is a block hash?
https://how.dev/
What is proof-of-work in PoW?
https://www.sec.gov/
https://scryptplatform.medium.com/
What is proof-of-work in PoW?
https://scryptplatform.medium.com/
The target hash
https://www.investopedia.com/
https://scryptplatform.medium.com/
What is nonce in 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
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
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
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