ELI12 crypto - part 2

Hands on with hashes

Be honest: did you watch the video from part 1? At least the first 13 minutes or so? If not, I’d highly encourage it. Even if it doesn’t all sink in, you’ll pick up some through osmosis.

Now let’s get hands-on and start to work through some of these concepts. In your browser, visit: https://andersbrownworth.com/blockchain/hash

In the Data field, start typing ‘Bitcoin is great’. With each character you type, notice how the Hash field is radically different each time. Once you’re done, you should see the exact same hash that I see:

There are a few points here:

  1. For a given input (“Bitcoin is great”), the “hash” of that input will always return the same output (“dd7f…5061”). Doesn’t matter if you type it or I type it, or if it’s Windows or Mac or Linux.

  2. The hash is one way. Meaning, I can’t feed `dd7fc5c521428cd50f8f799a4355442b83991804eb1d627c25ac300c806c5061` into some function and have it spit out “Bitcoin is great”. This one way-ness is a key concept.

  3. It’s very very very unlikely that a different input will return the same hash. This is known as a hash collision and hasn’t happened yet with this particular hash function (SHA256) as far as anyone knows.

  4. Computing a hash is fast. There’s no heavy lifting here on the part of the computer. You feed it a block of data, and it quickly spits out the resulting hash.

Why’s this hashing important, then, and what does it have to do with blockchain?

Remember checks?

Cheque - Wikipedia

Maybe you’ve been behind someone at the grocery who is filling out while your ice cream melts? We write the amount — $100.55 in this case — and then we also spell it out in long-form, just to make double sure it’s clear to all parties what the amount is, since arguably that’s the most important part of the check. Instead, what if you could type the key details into a hash function and then write down the hash in the memo line?

You don’t even need to write the whole hash in the memo line… just the first few characters is enough. Then, if there were any future question about the date, amount, or payee on the check itself, you could type the details into the form above, get the hash (“d157…075a”), and compare it to the one written on the check. If any fields had changed on the check — maybe someone changed the 5’s to 8’s to try to steal 33 cents! — then you’d have proof that the check has been altered. The hash for a 150.88 check would be wildly different, and all we did was change two characters.

Moving away from paper checks and into the digital domain, imagine you had something like:

If a single character is changed from this data, the hash changes and is no longer (“d0e9…822c”); thus, you know someone is up to no good and has either changed the names or the amounts. The hash is a quick way of verifying the details haven’t been tampered with.

In the next newsletter: blocks and blockchain!