liveBook · Manning

Proof of work

As explained in The Joy of JavaScript

A computational procedure that requires searching for a value meeting a difficulty condition, often by repeated hashing.

Proof of work is a computational search for a value that satisfies a difficulty condition. In a blockchain, repeated hashing makes a block expensive to produce but easy to verify. section 7.4.2 section 1.6

A basic proof-of-work loop:

  • Derive a hash prefix from the block’s difficulty, using leading zeroes as the acceptance condition. section 7.4.2
  • Increment the block’s nonce and recalculate its hash. section 7.4.2
  • Repeat until the hash starts with the required prefix, then return the mined block. section 7.4.2

Mining a block asynchronously

A synchronous proofOfWork function can occupy the JavaScript thread for seconds. A proofOfWorkAsync wrapper starts a Node.js Worker, passes serialized block data to it, resolves with the mined block, and rejects on worker errors or abnormal exit. section 8.3

How The Joy of JavaScript covers it

How deep it goes
Explains the nonce-and-hash loop and its difficulty prefix, then defers production-grade blockchain implementation.
Examples
Demonstrates leading-zero difficulty, nonce mutation, block hashing, block mining, and Worker Threads execution.
What it assumes
Assumes some JavaScript background while teaching blockchain mechanics without requiring prior blockchain knowledge.
What you can do after
Build proof-of-work from scratch and run its long computation asynchronously with Node.js Worker Threads.
How it connects
Connects proof of work to blockchain, hashing, mining, cryptographic hashes, blocks, nonces, and asynchronous workers.

Also explained in

Compare how 2 books explain proof of work →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Joy of JavaScript. The section links point to the parts of the book it draws on.