{"id":221,"date":"2015-05-25T22:42:00","date_gmt":"2015-05-25T22:42:00","guid":{"rendered":"https:\/\/santiagomarquezsolis.com\/index.php\/2026\/04\/20\/consensus-algorithms-in-blockchain-proof-of-work\/"},"modified":"2026-04-20T16:12:43","modified_gmt":"2026-04-20T16:12:43","slug":"consensus-algorithms-in-blockchain-proof-of-work","status":"publish","type":"post","link":"https:\/\/santiagomarquezsolis.com\/index.php\/en\/2015\/05\/25\/consensus-algorithms-in-blockchain-proof-of-work\/","title":{"rendered":"Consensus Algorithms in Blockchain. Proof of Work."},"content":{"rendered":"<p>One of the most fascinating problems in distributed systems is achieving consensus \u2014 getting all nodes in a network to agree on the same state \u2014 without a central authority. Blockchain technology solves this with consensus algorithms, and <strong>Proof of Work (PoW)<\/strong> was the first and most famous solution, introduced by Bitcoin.<\/p>\n<h2>The Byzantine Generals Problem<\/h2>\n<p>The theoretical foundation for blockchain consensus is the Byzantine Generals Problem, described by Lamport, Shostak, and Pease in 1982. The problem: a group of generals must coordinate an attack, but some generals might be traitors who send conflicting messages. How do loyal generals reach consensus?<\/p>\n<p>In blockchain terms: how do nodes in a network agree on which transactions are valid when some nodes might be malicious?<\/p>\n<h2>What is Proof of Work?<\/h2>\n<p>Proof of Work is a consensus mechanism where nodes (miners) compete to solve a computationally difficult puzzle. The first to solve it gets to add the next block and receives a reward. This mechanism achieves several goals simultaneously:<\/p>\n<ul>\n<li><strong>Sybil resistance:<\/strong> Creating fake identities is worthless without computational power<\/li>\n<li><strong>Ordering:<\/strong> PoW creates a natural ordering of transactions<\/li>\n<li><strong>Incentive alignment:<\/strong> Honest mining is more profitable than attacking the network<\/li>\n<li><strong>Security through cost:<\/strong> Rewriting history requires redoing all the work<\/li>\n<\/ul>\n<h2>How PoW Works<\/h2>\n<p>The puzzle in Bitcoin PoW is finding a number (nonce) such that when combined with the block&#8217;s data, the resulting SHA-256 hash starts with a certain number of zeros.<\/p>\n<pre><code>import hashlib\r\n\r\ndef proof_of_work(block_data, difficulty):\r\n    \"\"\"\r\n    Find a nonce such that hash(block_data + nonce) starts with 'difficulty' zeros\r\n    \"\"\"\r\n    nonce = 0\r\n    target = \"0\" * difficulty\r\n    \r\n    while True:\r\n        data = f\"{block_data}{nonce}\".encode()\r\n        hash_result = hashlib.sha256(data).hexdigest()\r\n        \r\n        if hash_result.startswith(target):\r\n            return nonce, hash_result\r\n        \r\n        nonce += 1\r\n\r\n# Example: Find a hash starting with \"0000\"\r\nnonce, hash_val = proof_of_work(\"Hello, Blockchain!\", difficulty=4)\r\nprint(f\"Nonce found: {nonce}\")\r\nprint(f\"Hash: {hash_val}\")<\/code><\/pre>\n<h2>The Difficulty Adjustment<\/h2>\n<p>Bitcoin adjusts its mining difficulty every 2016 blocks (approximately 2 weeks) to maintain an average block time of 10 minutes. If blocks are being found too quickly, difficulty increases; if too slowly, it decreases.<\/p>\n<p>This self-regulating mechanism ensures that:<\/p>\n<ul>\n<li>Block production remains predictable regardless of how much mining power is on the network<\/li>\n<li>The supply of new Bitcoin follows the predetermined schedule<\/li>\n<li>The network automatically adapts to new hardware and changing conditions<\/li>\n<\/ul>\n<h2>The 51% Attack<\/h2>\n<p>Proof of Work&#8217;s security assumption is that no single entity controls more than 50% of the network&#8217;s hash rate. If an attacker controlled >50% of hash power, they could:<\/p>\n<ul>\n<li>Double-spend transactions (spend the same coins twice)<\/li>\n<li>Prevent certain transactions from being confirmed<\/li>\n<li>Rewrite recent transaction history<\/li>\n<\/ul>\n<p>However, they cannot:<\/p>\n<ul>\n<li>Create coins from nothing<\/li>\n<li>Steal funds from legitimate wallets<\/li>\n<li>Change the protocol rules<\/li>\n<\/ul>\n<p>The cost of such an attack on Bitcoin is enormous \u2014 requiring billions of dollars in hardware \u2014 making it economically irrational.<\/p>\n<h2>PoW vs. Other Consensus Mechanisms<\/h2>\n<p>While PoW pioneered blockchain consensus, other mechanisms have emerged:<\/p>\n<ul>\n<li><strong>Proof of Stake (PoS):<\/strong> Validators stake (lock up) cryptocurrency as collateral. Used by Ethereum after The Merge. Far more energy efficient.<\/li>\n<li><strong>Delegated Proof of Stake (DPoS):<\/strong> Token holders vote for delegates who validate transactions<\/li>\n<li><strong>Proof of Authority (PoA):<\/strong> Trusted validators in private\/consortium networks<\/li>\n<li><strong>Proof of Space:<\/strong> Miners prove they have allocated disk space (Chia)<\/li>\n<\/ul>\n<h2>The Energy Debate<\/h2>\n<p>PoW&#8217;s main criticism is its energy consumption. Bitcoin consumes roughly as much electricity as a small country. Proponents argue this energy secures a global financial network and can be sourced from renewables; critics argue the environmental cost is unjustifiable.<\/p>\n<p>Ethereum&#8217;s switch to Proof of Stake in 2022 reduced its energy consumption by ~99.95%, demonstrating that equally secure consensus can be achieved with far less energy.<\/p>\n<h2>Conclusion<\/h2>\n<p>Proof of Work was a revolutionary solution to the Byzantine Generals Problem in an open, permissionless network. It enabled the creation of Bitcoin and proved that decentralized consensus was possible. While newer consensus mechanisms offer improvements in efficiency and speed, PoW remains the most battle-tested approach and still secures the world&#8217;s largest blockchain network.<\/p>\n<p>Understanding PoW is fundamental to understanding blockchain technology and the tradeoffs involved in different consensus approaches.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the most fascinating problems in distributed systems is achieving consensus \u2014 getting all nodes in a network to agree on the same state \u2014 without a central authority. Blockchain technology solves this with consensus algorithms, and Proof of Work (PoW) was the first and most famous solution, introduced by Bitcoin. The Byzantine Generals [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[162,182],"tags":[270,244,184,186,272,274,276],"class_list":["post-221","post","type-post","status-publish","format-standard","hentry","category-blog-en","category-cripto-en","tag-algoritmos-de-consenso-en","tag-bitcoin-en","tag-blockchain-en","tag-cripto-en","tag-pow-en","tag-proof-of-work-en","tag-prueba-de-trabajo-en"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/posts\/221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/comments?post=221"}],"version-history":[{"count":1,"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/posts\/221\/revisions"}],"predecessor-version":[{"id":247,"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/posts\/221\/revisions\/247"}],"wp:attachment":[{"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/media?parent=221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/categories?post=221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/tags?post=221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}