< up
2025-03-13

Proof of work

Proof of work plays an interesting role within secure networking, DDoS protection and an essential role creating blockchains aka mining coins1.

Hash functions

It is basically a concept of enforcing brute-force work that can’t be skipped or worked around. This can be accomplished by using a hash function which is by design not reversible. Hash functions compact an input with variable size into an output with fixed size. Because of the reduction, there is no way of mapping an output back to an input.

A loose analogy can be an addition of arbitrary numbers. Just the sum won’t tell you anything about the count of summands nor their value. There are infinite possible additions that have this sum as a result. In reality it’s more complex with substitution, shifting, modulo, padding and ominous s-boxes. Within my cs studies, I implemented the obsolete MD2 hash function, which is one of the more simple ones out there. Go check it out if you’re curious!

Practice

Proof of works asks an opponent to do some work by asking something like Give me an SHA1 hash starting with the string ‘dead’. As we have no other choice than guessing, we need to do the actual work:

[9] pry(main)> (0...).find{Digest::SHA1.hexdigest(_1.to_s).start_with?('dead')}
=> 42968
[10] pry(main)> (0...).find{Digest::SHA1.hexdigest(_1.to_s).start_with?('beef')}
=> 38838
[11] pry(main)> (0...).find{Digest::SHA1.hexdigest(_1.to_s).start_with?('deadbeef')}
=> 2943513

+hf


  1. Cryptocurrencies are bad, please don’t use them. They’re speculation and a huge waste of energy while they don’t solve any problem at all.