a light explanation of proof of work using Bitcoin



Cryptocurrencies are typically purposed to achieve some basic characteristics: they should be decentralized, trustless, and immutable. Since they are digitial assets, concensus mechanisms (i.e. protocols or concensus algorithms) must be implemented to ensure these characteristics are met. Two of the main concensus mechanisms are proof of work and proof of stake.

First, it's important to understand that decentralized cryptocurrency networks fundamentally do not depend on a central authority, such as a bank or other financial broker, to faciliate transactions, and all transactions are performed directly between peer nodes.

$ proof of work 


To illustrate how proof of work works, we will walk through how it is implemented in Bitcoin. Let's say Alice wants to send 1 Bitcoin to Bob and initiates the transaction. Miners will add this transaction, which still needs to be verified and hasn't yet been received by Bob, into a block to add into a blockchain. A block is comprised of hundreds of transactions along with metadata about the block in the block header (think of a block header as something similar to a letterhead that prefaces the actual content/message of the letter).

The following lists information stored in the block header and their sizes in bytes: - [4 bytes] the version of the block/blockchain
- [32 bytes] a hashed reference to the previous block in the blockchain
- [32 bytes] the Merkle root of the hashes of the transactions in the block
- [4 bytes] the epoch timestamp of the block
- [4 bytes] the target
- [4 bytes] the nonce (more on the nonce later)


Notice if you summate the byte sizes, the block header will come up to 80 bytes (or 640 bits since there are 8 bits in a byte) in total size.

Once transactions "fill up" a block, miners from across the global network will then compete to generate a sequence of alphanumeric characters. To generate this sequence, each of the byte streams in the block header are joined together to form one single sequence of characters, which is then hashed twice using the SHA256 hashing algorithm. Note that even if the length of the input data is smaller or bigger than 256 characters long, the output of the SHA256 algorithm is always 256 characters long. This 256-bit hashed output is the sequence of characters miners are generating to compare against the target.

The first miner who guesses a 256-bit hash equal to or less than the target is given the right to update the block of transactions onto the blockchain and is also rewarded with some Bitcoin (from the block reward and transaction fees). Peer nodes in the network will then verify the work and update their ledger with the newly verified block. Note that anyone can be a miner, but not every participant in the network is required to be a miner.

If the target is 0x0000000000002F5AA30000000000000000000000000000000000000000000000 in hexadecimal or 76095023984727922457360037957170140302343630369423681199800320 in base 10, and a hash generated by a miner is 0x00000000000016BF116FC90CF45AEC2DA4D13349358159D8B4EDDCB37EAB295B or 36551990950853533658225321687497789580066641734434828845787483 in base 10, then the miner wins and earns the right to update the blockchain, since 36551990950853533658225321687497789580066641734434828845787483 is less than 76095023984727922457360037957170140302343630369423681199800320.

This is the process of mining, and mining is the "proof of work" (PoW) required to verify the legitimacy of transactions. It is called "work" because it actually takes a lot of computational power to make these calculations (think the concept of "work" in physics), and since the mining process is incentivized, the time and competition required to pursue this work is the "proof" (think mathematical proofs).

You might wonder, if blockchains are public ledgers visible to peer nodes, why would miners need to compete to guess a string of alphanumeric characters? Wouldn't it virtually be easy, since information about the transactions are known? Recall the metadata in a block called the nonce, which is an abbreviation for "number used only once." In classic cryptography, the nonce is a random or pseudo-random number typically used in hash algorithms and other cryptographic protocols. When a miner fails to guess a winning hash, the nonce is changed, the new mining process will need to begin.

There is also a characteristic called "mining difficulty" that indicates the level of computational complexity of the "puzzle" at hand. This level of difficulty changes depending on the number of miners and hashpower available to the network. It has a direct relationship, meaning the difficulty increases when the number of miners and hashpower increase.



Written: August 20, 2022