FinTech Lecture 2
FinTech Lecture 2
FIN17018
Lecture 2:
The Blockchain Innovation
In Preparation for this Lecture
• All students should watch:
– The the Bitcoin documentary on Netflix (“Banking on Bitcoin”) about
the background and events associated with Bitcoin. Very interesting!
Quoted in satoshi;
Equivalent to 50
bitcoins
• Next, say in another transaction Bob wants to pay Carol one Bitcoin.
• Carol of course sets up an address and a key.
• And then Bob essentially takes the Bitcoin Alice gave him and uses his address and
key from that transfer to sign the bitcoin over to Carol:
• This transaction gets sent out to all of the miners, and they will check (using the reference
number from Alice’s transfer to Bob) to make sure that Bob hasn’t already transferred
that bitcoin to somebody else. No double spending.
• After validating the transfer, each miner will then send a message to all of the other
miners, giving his/her blessing.
Maintaining Privacy in a Blockchain (cont’d)
Blocks lifecycle
Each node, periodically:
1 listens for transactions published by other nodes
2 validates, consistency-checks & executes them
3 compiles the new local candidate transactions to potentially form a new block
4 participates to the consensus algorithm
i.e. negotiates the next block to be appended to the blockchain
- this phase also includes a spreading of the block to peers
Proof of Work and Ledger Security
• The second thing that keeps the ledger security is by usage of
cryptographic puzzle (proof of work).
– So dividing the ledger up into distributed blocks isn’t enough on
its own to protect the ledger from fraud.
• To add a new block to the chain, a miner has to finish what’s
called a cryptographic proof-of-work problem.
• Such problems are impossible to solve without applying a ton
of brute computing force.
– If you have a solution in hand, it’s proof that you’ve done a
certain quantity of computational work.
– The computational problem is different (varying difficulty and
time consumed) for every block in the chain.
– It involves a particular kind of algorithm called a hash function.
– Like any function (e.g., log(x), etc.), a cryptographic hash function
takes an input—a string of numbers and letters—and produces an
output.
Properties of Cryptographic Hash Functions
• There are several things that set cryptographic hash functions apart:
1. The output is of predetermined length, regardless of the input.
– The hash function that Bitcoin relies on is called SHA-256 (developed by the US
National Security Agency) and it always produces a string that is 64 characters
long (=256 bits).
For exp: 7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069
– You could run your name through that hash function, or an entire book. In either
case, you’ll get 64 characters out the other end.
– And, for a given input, you’ll always get the same output.
• 2. It’s impossible to make a cryptographic hash function work in
reverse.
• If you have the output of a cryptographic hash function (called “a hash” for short),
there’s no way of knowing what the input was.
• It’s a one-way street. And that’s what makes it cryptographic—you can use a hash
function to scramble text in a way that’s impossible to unscramble (remember the
word “crypto”).
Properties of Hash Functions (cont’d)
3. Changing the input even a little bit changes the output dramatically
• With hash functions, a slight variation in the input results in a completely different
output:
• The proof-of-work problem that miners have to solve involves taking a hash of the
contents of the block that they are working on (all of the transactions, some meta-
data like a timestamp, and the reference to the previous block) plus a random
number called a nonce.
• Their goal is to find a hash output that has at least a certain number of leading
zeroes. Something like this:
– Example of a real solution: 0000000000000000011eae2aca0e002ed6d5fa1fb6a3755dbcaa8b0cab0ec3f6
• That constraint is what makes the problem more or less difficult.
• More leading zeroes means fewer possible solutions, and more time required to
solve the problem. Every 2,016 blocks (roughly two weeks), that difficulty is reset.
• If it took miners less than 10 minutes on average to solve those 2,016 blocks, then
the difficulty is automatically increased. If it took longer, then the difficulty is
decreased.
• Miners search for an acceptable hash by choosing a nonce, running the hash
function, and checking. If the hash doesn’t have the right number of leading
zeroes, they change the nonce, run the hash function, and check again.
Properties of Hash Functions (cont’d)
3. Changing the input even a little bit changes the output dramatically
• Because of the one-way nature of hash functions, you can’t work
your way backwards to find a nonce that fits.
• And because of a hash function’s unpredictability, applying
“strategies” or logic to different nonces never really gets you closer
to the right one. It’s all a process of elimination.
• When a miner is finally lucky enough to find a nonce that works, and
wins the block, that nonce gets appended to the end of the block,
along with the resulting hash output.
• The whole block then gets sent out to every other miner in the
network, each of whom can then run the hash function with the
winner’s nonce, and verify that it works.
• If the solution is accepted by a majority of miners, the winner gets
the reward, and a new block is started, using the previous block’s
hash output as a reference.
• Read also Narayana, et al. (2015) book. Chapter 1.
SHA-256 Hash Function
• The creator of the Bitcoin protocol, Satoshi Nakomoto, chose to use the
SHA-256 hash function as the basis for Bitcoin mining.
• This is a specific cryptographic hash function developed by NSA that has
been mathematically proven to hold the properties we mentioned.
• It always outputs a 256 bit number, which is usually represented in the
hexadecimal number system with 64 characters for human-readability.
• The output of the SHA-256 function is usually referred to as the hash of
its input.
• Try creating hash output yourselves through this website:
• https://www.xorbin.com/tools/sha256-hash-calculator
• Try any word and play with it. Then, also try this: Hello, world!4250
Cracking SHA-256 Hash Function: How tough?
• SHA‐256 maximum input size is 264‐1 bits: How large number is this number? 18.45
quintillion
• Suppose you put one penny on the first square of a chess board, two pennies on next, etc.
• How much is on the last square?
• Answer: $9,223,372,036,854,780.00 ($9.2 quintillion)
• US GDP is ~$20,000,000,000.00 ($20 trillion)
• Since 264‐1 = 18.45 quintillion, so maximum input size is 18.45 quintillion bits of
input
• Thus, to back-engineer (i.e., “to break”) a hash output of the SHA‐256, you need to
evaluate 2256 possible inputs.
Composition of a Block
• Composition of a Block (80 bytes):
• 4 bytes: version number (same for all miners)
• 32 bytes: the hash output of the previous block (same for all miners)
• 32 bytes: hash output of the transactions in the candidate block
• 4 bytes: time stamp
• 4 bytes: difficulty of task (same for all miners)
• 4 bytes: nonce
• Miner will search for a nonce:
• A good machine can try all possible 32‐bit nonce combinations in about 1
second (about 4 billion calculations); 55
• Miner will also vary the order to which transactions are grouped (in a Merkle
tree);
• Time stamp can also be varied;