First, I want to thank Patrick McCorry for making all of this knowledge available to myself and others.
Second, I'd like to assert that I'm writing from a Bitcoin and Ethereum paradigm, but these principles apply to most blockchains.
Overview
We'll be looking at cryptography's role in cryptocurrency. Cryptography is not always used for data privacy. In cryptocurrency, it's used for protecting integrity, verifying transactions, and authenticating users- simply put, traceability. We won't be going over user authentication in this blog- but stay tuned!
The Hash Function
Q: What is a cryptographic hash function?
A: A function that can be used to map data (preimages) of arbitrary size to fixed-size values (hashes). The values returned by a hash function are called hash values, hash codes, digests, or simply hashes. Any change made to the preimage will result in a totally unique hash.
Three Properties The Hash Function
-
Preimage Resistance
- Given a hash (h), it should be difficult to find any preimage (p) such that h=hash(p). This property guarantees that the hash will give no clue as to what the preimage actually is.
-
Second Preimage Resistance
- Given a preimage (p1), it should be difficult to find a different preimage (p2) such that hash(p1)=hash(p2). This property guarantees you can't change your mind after making a public commitment.
-
Collision Resistance
- It should be difficult to find two different preimages (p1) (p2) such that hash(p1)==hash(p2). This is very similar to second preimage resistance except that collision resistance pertains to hash tables (maps), and second preimage resistance pertains to public commitments.
The Chain In Blockchain
In Bitcoin and Ethereum, each block appended at the end of the blockchain has a block header that contains a hash of the previous block's header as a way of pointing to the block that came before it. This creates a weighted blockchain where the heaviest (longest) chain is considered to be the "real" blockchain.
Verifying Transactions In The Blockchain
Each block header comes with a hash tree root that is a commitment to all transactions in the block (a hash of hashes of transactions).
Verifying that a transaction was confirmed in the blockchain is simply a matter of requesting information from a SPV (Simplified Payment Verification) client. The request to a SPV client carries with it the transaction we want to verify, the block id where the transaction is located, and a couple hashed transactions from the same block that will enable us to re-compute the hash tree root. If the re-computed hash tree root is equal to the original, then it's safe to say that this transaction was indeed verified and confirmed.
Top comments (1)
He does it again !! I like how you went into detail with this piece and explained each section very well for someone who has no knowledge on the subject like me! Very interesting topic now I have some knowledge on hash function & blockchains π«ΆπΌ