<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title>Chemaclass - cryptography</title><subtitle>Tech Lead sharing practical insights on software craftsmanship, TDD, leadership, Bitcoin, and AI. Blog posts, book summaries, and conference talks.</subtitle><link rel="self" type="application/atom+xml" href="https://chemaclass.com/tags/cryptography/atom.xml"/><link rel="alternate" type="text/html" href="https://chemaclass.com"/><generator uri="https://www.getzola.org/">Zola</generator><updated>2025-12-22T00:00:00+00:00</updated><id>https://chemaclass.com/tags/cryptography/atom.xml</id><entry xml:lang="en"><title>How Bitcoin Works</title><subtitle>Blockchain, cryptography, and consensus</subtitle><category term="bitcoin" scheme="https://chemaclass.com/tags/bitcoin/" label="Bitcoin"/><category term="cryptography" scheme="https://chemaclass.com/tags/cryptography/" label="Cryptography"/><category term="tutorial" scheme="https://chemaclass.com/tags/tutorial/" label="Tutorial"/><published>2025-12-22T00:00:00+00:00</published><updated>2025-12-22T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/how-bitcoin-works/"/><id>https://chemaclass.com/blog/how-bitcoin-works/</id><summary type="html">Transactions, blocks, mining, the UTXO model, and Lightning Network: how Bitcoin actually works under the hood, explained in plain terms.</summary><content type="html">&lt;p>This post explains how Bitcoin works under the hood. If you’re looking for why Bitcoin matters, start with &lt;a href="/blog/bitcoin-fundamentals/">Bitcoin Fundamentals&lt;/a>.&lt;/p>
&lt;span id="continue-reading">&lt;/span>
&lt;p>&lt;em>For the technically curious.&lt;/em>&lt;/p>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/bBC-nXj3Ng4"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div>
&lt;h2 id="the-blockchain">The Blockchain
&lt;a class="heading-anchor" href="#the-blockchain" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;h3 id="the-double-spend-problem">The Double-Spend Problem
&lt;a class="heading-anchor" href="#the-double-spend-problem" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Digital money has a fundamental problem: how do you prevent someone from copying their coins and spending them twice? Traditional systems solve this with a central authority (banks, PayPal) that tracks who owns what. Bitcoin’s breakthrough was solving this without any central party.&lt;/p>
&lt;p>The solution: a shared ledger that everyone can verify but no one controls.&lt;/p>
&lt;h3 id="how-it-works">How It Works
&lt;a class="heading-anchor" href="#how-it-works" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Bitcoin uses a blockchain: a chain of blocks where each block contains transactions and links to the previous block through cryptographic hashes.&lt;/p>
&lt;p>A &lt;strong>hash function&lt;/strong> takes any input and produces a fixed-size fingerprint. Change one bit of input, and the output changes completely. This makes tampering obvious. Bitcoin uses SHA-256, which produces a 256-bit output.&lt;/p>
&lt;p>Each block contains:&lt;/p>
&lt;ul>
&lt;li>A list of transactions&lt;/li>
&lt;li>A hash of the previous block header&lt;/li>
&lt;li>A proof-of-work solution (more below)&lt;/li>
&lt;/ul>
&lt;p>Before transactions get into a block, they wait in the mempool. Miners pick transactions from this pool, prioritizing those with higher fees. Watch this in real-time at &lt;a rel="external" href="https://mempool.space/">mempool.space&lt;/a>.&lt;/p>
&lt;p>Every node keeps a complete copy of the blockchain. No single server to hack, no central database to corrupt. To change history, you’d need to rewrite blocks on the majority of nodes worldwide.&lt;/p>
&lt;details class="deep-dive">
&lt;summary class="deep-dive__header">
&lt;span class="deep-dive__icon">&lt;/span>
&lt;span class="deep-dive__title">Deep Dive: Block Structure&lt;/span>
&lt;/summary>
&lt;div class="deep-dive__content">
&lt;p>A block has two parts: the &lt;strong>header&lt;/strong> (80 bytes) and the &lt;strong>body&lt;/strong> (transactions).&lt;/p>
&lt;p>The header contains:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Version&lt;/strong>: Protocol version&lt;/li>
&lt;li>&lt;strong>Previous block hash&lt;/strong>: Links to the chain&lt;/li>
&lt;li>&lt;strong>Merkle root&lt;/strong>: Hash of all transactions in the block&lt;/li>
&lt;li>&lt;strong>Timestamp&lt;/strong>: When the block was created&lt;/li>
&lt;li>&lt;strong>Difficulty target&lt;/strong>: How hard the puzzle was&lt;/li>
&lt;li>&lt;strong>Nonce&lt;/strong>: The solution miners found&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Merkle trees&lt;/strong> organize transactions efficiently. Each transaction is hashed, then pairs of hashes are combined and hashed again, building up to a single root hash. This allows proving a transaction exists in a block without downloading all transactions. Useful for lightweight wallets.&lt;/p>
&lt;p>Block weight is measured in virtual bytes (vB). The limit is 4 million weight units, roughly 1-1.5 MB of data per block.&lt;/p>
&lt;/div>
&lt;/details>
&lt;h2 id="transactions-cryptography">Transactions &amp;amp; Cryptography
&lt;a class="heading-anchor" href="#transactions-cryptography" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;h3 id="the-utxo-model">The UTXO Model
&lt;a class="heading-anchor" href="#the-utxo-model" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Bitcoin doesn’t use accounts with balances. Instead, it tracks &lt;strong>Unspent Transaction Outputs (UTXOs)&lt;/strong>. Think of them as digital coins of varying sizes.&lt;/p>
&lt;p>When you receive bitcoin, you get a UTXO. When you spend, you consume entire UTXOs as inputs and create new ones as outputs. If you have a 1 BTC UTXO and want to send 0.3 BTC, you spend the whole UTXO and create two outputs: 0.3 BTC to the recipient and ~0.7 BTC back to yourself (minus fees).&lt;/p>
&lt;p>Your “balance” is the sum of all UTXOs you can spend.&lt;/p>
&lt;h3 id="public-key-cryptography">Public-Key Cryptography
&lt;a class="heading-anchor" href="#public-key-cryptography" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Bitcoin transactions use public-key cryptography:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Private key&lt;/strong>: A secret 256-bit number. This proves ownership.&lt;/li>
&lt;li>&lt;strong>Public key&lt;/strong>: Derived mathematically from the private key. Shared publicly.&lt;/li>
&lt;/ul>
&lt;p>When you send bitcoin, you sign the transaction with your private key. This signature proves you own the UTXOs being spent without revealing the private key. Anyone can verify the signature using your public key.&lt;/p>
&lt;h3 id="programmable-money">Programmable Money
&lt;a class="heading-anchor" href="#programmable-money" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Bitcoin isn’t just digital cash. It has its own programming language called &lt;strong>Script&lt;/strong>. Every transaction includes a small program that defines the conditions for spending.&lt;/p>
&lt;p>Most transactions use simple scripts: “whoever can prove they own this public key can spend these coins.” But Script enables much more: multi-signature wallets requiring multiple keys, time-locked transactions that can’t be spent until a certain date, and complex conditions combining multiple requirements.&lt;/p>
&lt;p>This makes Bitcoin programmable money. For a deeper dive into Script and address types, see &lt;a href="/blog/programmable-money/">Programmable Money&lt;/a>.&lt;/p>
&lt;details class="deep-dive">
&lt;summary class="deep-dive__header">
&lt;span class="deep-dive__icon">&lt;/span>
&lt;span class="deep-dive__title">Deep Dive: Elliptic Curve Cryptography&lt;/span>
&lt;/summary>
&lt;div class="deep-dive__content">
&lt;p>Bitcoin uses &lt;strong>ECDSA&lt;/strong> (Elliptic Curve Digital Signature Algorithm) with the &lt;strong>secp256k1&lt;/strong> curve. This curve was chosen for efficiency and because it wasn’t designed by any government agency (unlike NIST curves), reducing backdoor concerns.&lt;/p>
&lt;p>A private key is a random 256-bit integer. The public key is derived by multiplying this number by a generator point on the curve. Easy to compute forward, practically impossible to reverse.&lt;/p>
&lt;p>&lt;strong>Transaction signing&lt;/strong> involves:&lt;/p>
&lt;ol>
&lt;li>Hashing the transaction data&lt;/li>
&lt;li>Creating a signature using the private key&lt;/li>
&lt;li>Including the signature and public key in the transaction&lt;/li>
&lt;/ol>
&lt;p>&lt;strong>SIGHASH flags&lt;/strong> control what parts of a transaction the signature covers:&lt;/p>
&lt;ul>
&lt;li>&lt;code>SIGHASH_ALL&lt;/code>: Signs all inputs and outputs (most common)&lt;/li>
&lt;li>&lt;code>SIGHASH_NONE&lt;/code>: Signs inputs only&lt;/li>
&lt;li>&lt;code>SIGHASH_SINGLE&lt;/code>: Signs one specific output&lt;/li>
&lt;li>These can be combined with &lt;code>ANYONECANPAY&lt;/code> for advanced use cases&lt;/li>
&lt;/ul>
&lt;/div>
&lt;/details>
&lt;h2 id="mining-consensus">Mining &amp;amp; Consensus
&lt;a class="heading-anchor" href="#mining-consensus" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>How does a decentralized network agree on which transactions are valid? Through proof-of-work mining.&lt;/p>
&lt;h3 id="the-puzzle">The Puzzle
&lt;a class="heading-anchor" href="#the-puzzle" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Miners race to find a number (the &lt;strong>nonce&lt;/strong>) that, when combined with the block header and hashed, produces a result below a target value. It’s like rolling dice until you get a number under 100, except with 2^256 possible outcomes.&lt;/p>
&lt;p>The work is:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Hard to find&lt;/strong>: Requires trillions of guesses&lt;/li>
&lt;li>&lt;strong>Easy to verify&lt;/strong>: One hash check proves the solution&lt;/li>
&lt;/ul>
&lt;p>This asymmetry is key. Anyone can verify a block instantly, but creating one requires real computational work.&lt;/p>
&lt;h3 id="why-it-matters">Why It Matters
&lt;a class="heading-anchor" href="#why-it-matters" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Mining serves three purposes:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Secures the network&lt;/strong>: Rewriting history means redoing all hash work&lt;/li>
&lt;li>&lt;strong>Issues new coins&lt;/strong>: Following a predictable schedule (halving every 210,000 blocks)&lt;/li>
&lt;li>&lt;strong>Processes transactions&lt;/strong>: Including them in the permanent record&lt;/li>
&lt;/ol>
&lt;p>Every 2016 blocks (~2 weeks), the network adjusts difficulty to maintain ~10 minute block times. More hashpower joins? Puzzles get harder. Hashpower leaves? Puzzles get easier.&lt;/p>
&lt;p>Explore mining pools and hashrate at &lt;a rel="external" href="https://mempool.space/mining">mempool.space/mining&lt;/a>.&lt;/p>
&lt;details class="deep-dive">
&lt;summary class="deep-dive__header">
&lt;span class="deep-dive__icon">&lt;/span>
&lt;span class="deep-dive__title">Deep Dive: Difficulty and Game Theory&lt;/span>
&lt;/summary>
&lt;div class="deep-dive__content">
&lt;p>&lt;strong>Difficulty calculation&lt;/strong>: The target is a 256-bit number. A valid block hash must be below this target. Lower target = harder puzzle. The network adjusts every 2016 blocks based on how long those blocks actually took vs. the expected 20,160 minutes.&lt;/p>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/S9JGmA5_unY"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div>
&lt;p>&lt;strong>Hashrate and security&lt;/strong>: Bitcoin’s security comes from the cost to rewrite history. With ~500 EH/s (exahashes per second) of hashrate, attacking the network would require controlling majority hashpower. That means billions in hardware and electricity, plus the attack would crash the asset’s value.&lt;/p>
&lt;p>&lt;strong>Economic incentives&lt;/strong>: Miners spend real resources (electricity, hardware). They only profit if they play by the rules. A miner who creates invalid blocks wastes their work because nodes reject invalid blocks. This aligns individual profit motive with network security.&lt;/p>
&lt;p>&lt;strong>51% attacks&lt;/strong>: If an attacker controlled majority hashrate, they could theoretically double-spend by mining an alternative chain. But the economics make this irrational for large values: the attack destroys the value of what you’re stealing.&lt;/p>
&lt;/div>
&lt;/details>
&lt;h2 id="addresses-wallets">Addresses &amp;amp; Wallets
&lt;a class="heading-anchor" href="#addresses-wallets" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Bitcoin addresses are derived from public keys. Different formats have evolved:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>P2PKH&lt;/strong>: Legacy addresses starting with “1”&lt;/li>
&lt;li>&lt;strong>P2SH&lt;/strong>: Script addresses starting with “3”&lt;/li>
&lt;li>&lt;strong>P2WPKH&lt;/strong>: Native SegWit addresses starting with “bc1q”&lt;/li>
&lt;li>&lt;strong>P2TR&lt;/strong>: Taproot addresses starting with “bc1p”&lt;/li>
&lt;/ul>
&lt;p>For technical details on each type, see &lt;a href="/blog/programmable-money/#common-bitcoin-address-types">Programmable Money&lt;/a>.&lt;/p>
&lt;h3 id="wallets">Wallets
&lt;a class="heading-anchor" href="#wallets" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>A wallet manages your keys and constructs transactions. It doesn’t hold your coins. Coins exist on the blockchain. The wallet holds keys that prove you can spend them.&lt;/p>
&lt;p>&lt;strong>Hot wallets&lt;/strong> connect to the internet. Convenient for daily use, more vulnerable. Examples: phone apps, browser extensions.&lt;/p>
&lt;p>&lt;strong>Cold wallets&lt;/strong> stay offline. More secure for savings. Examples: hardware wallets (Ledger, Trezor), paper wallets.&lt;/p>
&lt;h3 id="hd-wallets-and-seed-phrases">HD Wallets and Seed Phrases
&lt;a class="heading-anchor" href="#hd-wallets-and-seed-phrases" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Modern wallets are &lt;strong>Hierarchical Deterministic (HD)&lt;/strong>. One master seed generates unlimited keys in a tree structure. Back up the seed once, recover everything.&lt;/p>
&lt;p>&lt;strong>BIP-39&lt;/strong> defines the 12 or 24-word seed phrase most wallets use. These words encode entropy that derives all your keys. Lose the phrase, lose access. Anyone with the phrase controls the funds.&lt;/p>
&lt;blockquote>
&lt;p>Never store seed phrases digitally. Write them down. Store securely offline.&lt;/p>
&lt;/blockquote>
&lt;p>How big is the BIP-39 keyspace, really? I built &lt;a rel="external" href="https://github.com/Chemaclass/seed-hunter">seed-hunter&lt;/a>, an open-source educational Go CLI that tries to brute-force a 12-word seed against the real Bitcoin network. It logs every attempt and shows live progress with ETAs spanning 10²⁹ to 10³⁹ years. A burglar checking one trillion seed phrases per second since the Big Bang would have completed 0.000_000_008% of the search by now. The point isn’t to break Bitcoin, it’s to make the math viscerally obvious: thermodynamics, not just computation, forbids the attack.&lt;/p>
&lt;h2 id="the-network">The Network
&lt;a class="heading-anchor" href="#the-network" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Bitcoin is a peer-to-peer network. No central servers. Nodes connect to each other, share transactions and blocks, and enforce rules independently.&lt;/p>
&lt;h3 id="node-types">Node Types
&lt;a class="heading-anchor" href="#node-types" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>&lt;strong>Full nodes&lt;/strong> download and validate every block and transaction. They enforce all consensus rules and don’t trust anyone. Running a full node means you verify everything yourself.&lt;/p>
&lt;p>&lt;strong>SPV (light) clients&lt;/strong> only download block headers. They trust that miners validated the transactions. Less security, but works on phones and low-power devices.&lt;/p>
&lt;p>&lt;strong>Mining nodes&lt;/strong> are full nodes that also compete to create new blocks.&lt;/p>
&lt;h3 id="how-transactions-propagate">How Transactions Propagate
&lt;a class="heading-anchor" href="#how-transactions-propagate" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>When you broadcast a transaction:&lt;/p>
&lt;ol>
&lt;li>Your wallet sends it to connected nodes&lt;/li>
&lt;li>Each node validates and forwards to its peers&lt;/li>
&lt;li>Within seconds, the transaction reaches most of the network&lt;/li>
&lt;li>Miners include it in their candidate blocks&lt;/li>
&lt;/ol>
&lt;p>Blocks propagate similarly. When a miner finds a valid block, it spreads across the network in seconds.&lt;/p>
&lt;details class="deep-dive">
&lt;summary class="deep-dive__header">
&lt;span class="deep-dive__icon">&lt;/span>
&lt;span class="deep-dive__title">Deep Dive: Network Architecture&lt;/span>
&lt;/summary>
&lt;div class="deep-dive__content">
&lt;p>&lt;strong>Peer discovery&lt;/strong>: Nodes find each other through DNS seeds (hardcoded addresses that return active node IPs) and by sharing peer addresses with connected nodes.&lt;/p>
&lt;p>&lt;strong>Gossip protocol&lt;/strong>: Information spreads through “inv” (inventory) messages. A node announces it has something new, peers request it if interested. This prevents bandwidth waste from duplicate data.&lt;/p>
&lt;p>&lt;strong>Compact blocks&lt;/strong> (BIP-152) speed up block propagation. Since nodes already have most transactions in their mempool, blocks can be transmitted as just the header plus short transaction IDs.&lt;/p>
&lt;/div>
&lt;/details>
&lt;h2 id="security-confirmations">Security &amp;amp; Confirmations
&lt;a class="heading-anchor" href="#security-confirmations" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;h3 id="why-confirmations-matter">Why Confirmations Matter
&lt;a class="heading-anchor" href="#why-confirmations-matter" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>When a transaction is included in a block, it has 1 confirmation. Each subsequent block adds another confirmation.&lt;/p>
&lt;p>More confirmations = harder to reverse. To undo a confirmed transaction, an attacker would need to mine an alternative chain faster than the honest network. Each block makes this exponentially harder.&lt;/p>
&lt;p>&lt;strong>General guidelines:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>0 confirmations: Transaction broadcast but not yet in a block. Can be double-spent.&lt;/li>
&lt;li>1 confirmation: In a block. Reversal requires significant hashpower.&lt;/li>
&lt;li>6 confirmations: Standard for large amounts. Reversal practically impossible.&lt;/li>
&lt;/ul>
&lt;details class="deep-dive">
&lt;summary class="deep-dive__header">
&lt;span class="deep-dive__icon">&lt;/span>
&lt;span class="deep-dive__title">Deep Dive: Confirmation Security&lt;/span>
&lt;/summary>
&lt;div class="deep-dive__content">
&lt;p>Satoshi’s whitepaper includes the probability calculation. With an attacker controlling fraction &lt;code>q&lt;/code> of hashpower:&lt;/p>
&lt;ul>
&lt;li>If &lt;code>q &amp;lt; 0.5&lt;/code>: Probability of catching up decreases exponentially with each confirmation&lt;/li>
&lt;li>At 6 confirmations with &lt;code>q = 0.1&lt;/code> (10% hashpower): Success probability &amp;lt; 0.1%&lt;/li>
&lt;/ul>
&lt;p>The “6 confirmations” rule assumes a well-funded attacker with substantial but minority hashpower. For smaller transactions, fewer confirmations are often acceptable.&lt;/p>
&lt;p>&lt;strong>Finality in Bitcoin&lt;/strong> is probabilistic, not absolute. But after enough confirmations, the probability of reversal approaches zero for any realistic attacker.&lt;/p>
&lt;/div>
&lt;/details>
&lt;h2 id="incentive-alignment">Incentive Alignment
&lt;a class="heading-anchor" href="#incentive-alignment" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Bitcoin isn’t just a clever technology. It’s a system where every participant’s self-interest reinforces the network.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>Miners&lt;/strong> invest in hardware and electricity. They only profit by producing valid blocks. Cheating wastes their investment because nodes reject invalid blocks instantly.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Nodes&lt;/strong> enforce the rules to protect their own holdings. A node operator who accepts invalid transactions devalues their own bitcoin. Self-interest makes them honest validators.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Users&lt;/strong> pay fees to get transactions processed. Higher fees mean faster confirmation. This creates demand for block space and funds network security.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Developers&lt;/strong> contribute to software they themselves use. Bugs hurt their own holdings. Improvements benefit everyone, including them.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Holders&lt;/strong> benefit from network security and adoption. The more secure and useful Bitcoin becomes, the more valuable their holdings. They’re incentivized to support the ecosystem.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>No central coordinator. No trust required. Everyone acts in their own interest, and the system benefits everyone.&lt;/p>
&lt;blockquote>
&lt;p>“Don’t trust, verify.” Anyone can run a node and verify every transaction, every block, every rule. You don’t need to trust banks, governments, or even other Bitcoin users. The math proves itself.&lt;/p>
&lt;/blockquote>
&lt;h2 id="scaling-the-lightning-network">Scaling: The Lightning Network
&lt;a class="heading-anchor" href="#scaling-the-lightning-network" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Bitcoin’s base layer processes about 7 transactions per second. That’s by design: keeping things decentralized requires blocks small enough for anyone to verify. But this limits how many transactions it can handle.&lt;/p>
&lt;p>The Lightning Network solves this with a second layer built on top of Bitcoin. It enables:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Instant payments&lt;/strong>: No waiting for block confirmations&lt;/li>
&lt;li>&lt;strong>Near-zero fees&lt;/strong>: Fractions of a cent&lt;/li>
&lt;li>&lt;strong>High capacity&lt;/strong>: Millions of transactions per second&lt;/li>
&lt;/ul>
&lt;p>Lightning works by opening “payment channels” between parties. Transactions within a channel happen off-chain, instantly. Only the opening and closing of channels require on-chain transactions. You can visualize the network topology and statistics at &lt;a rel="external" href="https://mempool.space/lightning">mempool.space/lightning&lt;/a>.&lt;/p>
&lt;blockquote>
&lt;p>Bitcoin’s base layer provides security and final settlement. Lightning provides speed and scale. Different tools for different jobs.&lt;/p>
&lt;/blockquote>
&lt;p>If you want to run your own Lightning node and take full control of your payments, I wrote a guide on how to &lt;a href="/blog/run-your-ln-node/">Run your LN node on a Raspberry Pi&lt;/a>.&lt;/p>
&lt;details class="deep-dive">
&lt;summary class="deep-dive__header">
&lt;span class="deep-dive__icon">&lt;/span>
&lt;span class="deep-dive__title">Deep Dive: How Lightning Works&lt;/span>
&lt;/summary>
&lt;div class="deep-dive__content">
&lt;p>Payment channels use &lt;strong>2-of-2 multisig&lt;/strong> addresses. Both parties must sign to move funds. This creates a shared account that neither can steal from.&lt;/p>
&lt;p>&lt;strong>HTLCs (Hash Time-Locked Contracts)&lt;/strong> enable multi-hop payments. The mechanism:&lt;/p>
&lt;ol>
&lt;li>Alice wants to pay Carol through Bob&lt;/li>
&lt;li>Carol generates a secret and gives Alice the hash&lt;/li>
&lt;li>Alice creates an HTLC: “Bob gets paid if he reveals the secret within 24 hours”&lt;/li>
&lt;li>Bob creates a similar HTLC with Carol&lt;/li>
&lt;li>Carol reveals the secret to Bob, claiming payment&lt;/li>
&lt;li>Bob uses the same secret to claim from Alice&lt;/li>
&lt;/ol>
&lt;p>If anyone fails to cooperate, the timelock expires and funds return. The secret travels backward, payments travel forward.&lt;/p>
&lt;p>&lt;strong>Watchtowers&lt;/strong> monitor the blockchain for cheating attempts. If your counterparty tries to broadcast an old channel state, the watchtower can penalize them, even while you’re offline.&lt;/p>
&lt;/div>
&lt;/details>
&lt;h2 id="the-bigger-picture">The Bigger Picture
&lt;a class="heading-anchor" href="#the-bigger-picture" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>What makes Bitcoin remarkable isn’t any single component. It’s how they fit together into a self-reinforcing system.&lt;/p>
&lt;p>Cryptography proves ownership without trusted authorities. Proof-of-work makes history expensive to rewrite. Economic incentives turn individual greed into collective security. Decentralization removes single points of failure. And the fixed supply creates digital scarcity for the first time in history.&lt;/p>
&lt;p>Every piece supports every other piece. Remove one, and the system weakens. Together, they create something that has never existed before: money that can’t be inflated, transactions that can’t be censored, and property that can’t be confiscated.&lt;/p>
&lt;blockquote>
&lt;p>No banks. No governments. No trusted third parties. Just math, code, and a global network of nodes all enforcing the same rules.&lt;/p>
&lt;/blockquote>
&lt;p>Whether that matters to you depends on where you live and how much you trust your institutions. But the option exists now. And no one can take it away.&lt;/p>
&lt;details class="deep-dive">
&lt;summary class="deep-dive__header">
&lt;span class="deep-dive__icon">&lt;/span>
&lt;span class="deep-dive__title">Deep Dive: Rabbit Holes&lt;/span>
&lt;/summary>
&lt;div class="deep-dive__content">
&lt;p>Bitcoin’s technical depth goes far beyond what fits in one post. Here are topics worth exploring if you want to go deeper:&lt;/p>
&lt;p>&lt;strong>&lt;a rel="external" href="https://bitcoinops.org/en/topics/segregated-witness/">SegWit&lt;/a>&lt;/strong> (Segregated Witness) was Bitcoin’s 2017 upgrade that moved signature data outside the main transaction structure. This fixed transaction malleability (a bug that prevented Lightning), introduced block weight for more efficient space usage, and did it all while staying backwards-compatible with old nodes.&lt;/p>
&lt;p>&lt;strong>&lt;a rel="external" href="https://bitcoinops.org/en/topics/taproot/">Taproot &amp;amp; Schnorr&lt;/a>&lt;/strong> landed in 2021, upgrading Bitcoin’s cryptography. Schnorr signatures are smaller and enable aggregation (multiple signatures become one). Taproot makes complex spending conditions look identical to simple payments on-chain, improving both privacy and efficiency.&lt;/p>
&lt;p>&lt;strong>&lt;a rel="external" href="https://bitcoin.stackexchange.com/questions/30817/what-is-a-soft-fork">Soft forks vs hard forks&lt;/a>&lt;/strong>: How does Bitcoin upgrade without a central authority? Soft forks add new rules that old nodes still accept. Hard forks change rules in ways old nodes reject. Understanding this distinction explains why Bitcoin evolves slowly and why contentious changes are rare.&lt;/p>
&lt;p>&lt;strong>&lt;a rel="external" href="https://mempool.space/docs/faq#what-is-rbf">Fee mechanics&lt;/a>&lt;/strong>: The fee market is more nuanced than “pay more, confirm faster.” Replace-By-Fee (RBF) lets you bump a stuck transaction’s fee. Child-Pays-For-Parent (CPFP) lets recipients accelerate incoming payments by spending them with high fees.&lt;/p>
&lt;p>&lt;strong>&lt;a rel="external" href="https://bitcoinops.org/en/topics/timelocks/">Timelocks&lt;/a>&lt;/strong>: Bitcoin can lock funds until conditions are met. &lt;code>CLTV&lt;/code> (CheckLockTimeVerify) locks until a specific block height or timestamp. &lt;code>CSV&lt;/code> (CheckSequenceVerify) locks for a relative time after confirmation. These primitives enable Lightning channels, inheritance schemes, and atomic swaps.&lt;/p>
&lt;p>&lt;strong>&lt;a rel="external" href="https://learnmeabitcoin.com/technical/mining/coinbase-transaction/">Coinbase transactions&lt;/a>&lt;/strong>: The only way new bitcoin enters circulation. Every block begins with a special transaction that pays the miner the block reward plus all fees. These newly minted coins can’t be spent for 100 blocks, a rule that protects against chain reorganizations.&lt;/p>
&lt;p>The deeper you go, the more you find.&lt;/p>
&lt;/div>
&lt;/details></content></entry><entry xml:lang="en"><title>The Cypherpunks</title><subtitle>Pioneers of privacy in the digital age</subtitle><category term="privacy" scheme="https://chemaclass.com/tags/privacy/" label="Privacy"/><category term="bitcoin" scheme="https://chemaclass.com/tags/bitcoin/" label="Bitcoin"/><category term="cryptography" scheme="https://chemaclass.com/tags/cryptography/" label="Cryptography"/><category term="security" scheme="https://chemaclass.com/tags/security/" label="Security"/><category term="philosophy" scheme="https://chemaclass.com/tags/philosophy/" label="Philosophy"/><published>2024-12-11T00:00:00+00:00</published><updated>2024-12-11T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/the-cypherpunks/"/><id>https://chemaclass.com/blog/the-cypherpunks/</id><summary type="html">In the early '90s, with the internet on the rise, a group called the Cypherpunks emerged to defend digital privacy. They pushed for encryption and privacy tech, shaping our digital world with their vision and ideals.</summary><content type="html">&lt;p>In the early ’90s, with the internet on the rise, a group called the Cypherpunks emerged to defend digital privacy. They pushed for encryption and privacy, shaping our digital world with their vision.&lt;/p>
&lt;span id="continue-reading">&lt;/span>&lt;h2 id="who-were-the-cypherpunks">Who were the Cypherpunks?
&lt;a class="heading-anchor" href="#who-were-the-cypherpunks" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>The term “Cypherpunk” combines “cipher” (a reference to encryption) with “punk”, reflecting the group’s rebellious and anti-establishment spirit.&lt;/p>
&lt;p>Far from being a formal organization, the Cypherpunks were a diverse assembly of visionaries, technologists, and activists bonded by shared principles. The movement started in 1992 when Eric Hughes, Timothy May, and John Gilmore founded the cypherpunks mailing list. Some key figures:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Eric Hughes&lt;/strong> who wrote “A Cypherpunk’s Manifesto,” laying out the philosophical foundation for the movement.&lt;/li>
&lt;li>&lt;strong>Timothy C. May&lt;/strong> authored “The Crypto Anarchist Manifesto,” which imagined a society where cryptography could foster a new anarchistic order.&lt;/li>
&lt;li>&lt;strong>John Gilmore&lt;/strong>, a co-founder of the Electronic Frontier Foundation (EFF), was pivotal in early internet privacy advocacy.&lt;/li>
&lt;li>&lt;strong>Julian Assange&lt;/strong>, later known for WikiLeaks, participated in these discussions.&lt;/li>
&lt;li>&lt;strong>Phil Zimmermann&lt;/strong> revolutionized email privacy with his creation of PGP.&lt;/li>
&lt;li>&lt;strong>Jude Milhon&lt;/strong> (St. Jude), a hacker and writer, coined the term “cypherpunk” together with Eric Hughes.&lt;/li>
&lt;li>&lt;strong>Nick Szabo&lt;/strong> contributed significantly to digital contracts and currencies, conceptualizing “bit gold” before Bitcoin.&lt;/li>
&lt;li>&lt;strong>Hal Finney&lt;/strong>, an early Bitcoin developer, worked on cryptographic software including PGP, influencing the privacy tech landscape.&lt;/li>
&lt;li>&lt;strong>Adam Back&lt;/strong> introduced Hashcash, which later inspired Bitcoin’s proof-of-work, while actively engaging in cypherpunk dialogues on privacy.&lt;/li>
&lt;li>&lt;strong>Wei Dai&lt;/strong> proposed “b-money,” an early idea for anonymous digital cash systems, which influenced Bitcoin’s development.&lt;/li>
&lt;li>&lt;strong>Zooko Wilcox-O’Hearn&lt;/strong>, with his work on Zcash, brought advanced privacy to cryptocurrencies, having roots in cypherpunk discussions.&lt;/li>
&lt;li>&lt;strong>David Chaum&lt;/strong>, often called the “godfather of cypherpunks”, pioneered digital cash with DigiCash (1989). His work on electronic privacy predates and inspired the movement.&lt;/li>
&lt;li>&lt;strong>Bram Cohen&lt;/strong> developed BitTorrent, showcasing the cypherpunk ethos of decentralization in file sharing.&lt;/li>
&lt;/ul>
&lt;p>Their work built on foundational cryptographic research by &lt;strong>Whitfield Diffie&lt;/strong> and &lt;strong>Martin Hellman&lt;/strong>, who invented public-key cryptography in 1976, making secure communication between strangers possible.&lt;/p>
&lt;p>They gathered online on the cypherpunks mailing list, which at its peak had around 2000 subscribers exchanging 30+ messages per day. Their motto: &lt;strong>“Cypherpunks write code.”&lt;/strong> They didn’t just talk about privacy. They built it.&lt;/p>
&lt;p>&lt;img src="/images/blog/2024-12-11/manifesto.jpg" alt="a cypherpunk’s manifesto" />&lt;/p>
&lt;h2 id="philosophy-and-goals">Philosophy and goals
&lt;a class="heading-anchor" href="#philosophy-and-goals" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>The core philosophy of the Cypherpunks was centered around privacy, freedom of speech, and the potential of cryptography to protect these rights. Their main tenets included:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Privacy as a fundamental right&lt;/strong>: They believed that privacy was essential for personal freedom and that digital communication should be private.&lt;/li>
&lt;li>&lt;strong>Decentralization&lt;/strong>: Suspicious of centralized control over information, they pushed for decentralized systems where individuals could control their own data.&lt;/li>
&lt;li>&lt;strong>Cryptography as a tool&lt;/strong>: They saw encryption not just as a means of securing data but as a political tool against surveillance and oppressive regimes.&lt;/li>
&lt;/ul>
&lt;h3 id="their-goals-were">Their goals were
&lt;a class="heading-anchor" href="#their-goals-were" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ol>
&lt;li>To create and promote tools for encryption, anonymity, and digital cash.&lt;/li>
&lt;li>To educate the public on the importance of cryptography.&lt;/li>
&lt;li>To resist governmental and corporate efforts to control or monitor digital communications.&lt;/li>
&lt;/ol>
&lt;h2 id="impact-nowadays">Impact nowadays
&lt;a class="heading-anchor" href="#impact-nowadays" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;h3 id="development-of-key-technologies">Development of key technologies
&lt;a class="heading-anchor" href="#development-of-key-technologies" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Cypherpunks built tools, not just theories:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>PGP&lt;/strong> (1991): Email encryption for everyone&lt;/li>
&lt;li>&lt;strong>Tor&lt;/strong> (2002): Anonymous browsing through onion routing&lt;/li>
&lt;li>&lt;strong>BitTorrent&lt;/strong> (2001): Decentralized file sharing&lt;/li>
&lt;li>&lt;strong>Bitcoin&lt;/strong> (2009): Digital money without banks&lt;/li>
&lt;li>&lt;strong>Signal Protocol&lt;/strong>: The encryption behind Signal, WhatsApp, and other messengers&lt;/li>
&lt;/ul>
&lt;p>When you send an encrypted message today, you’re using cypherpunk technology.&lt;/p>
&lt;h3 id="cultural-shift">Cultural shift
&lt;a class="heading-anchor" href="#cultural-shift" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>They changed how society views privacy. Before them, encryption was mostly for governments or experts. Today, it’s a standard part of tools like messaging apps and web browsers. By promoting encryption and anonymity, they made privacy a priority and encouraged people to take control of their data.&lt;/p>
&lt;h3 id="legal-and-policy-influence-the-crypto-wars">Legal and policy influence: The Crypto Wars
&lt;a class="heading-anchor" href="#legal-and-policy-influence-the-crypto-wars" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>The 1990s saw a real battle between cypherpunks and governments, known as the “Crypto Wars.” The US classified strong encryption as a weapon and banned its export. When Phil Zimmermann released PGP, he was investigated for “exporting munitions” because the software spread globally via the internet.&lt;/p>
&lt;p>The cypherpunks fought back creatively. They printed PGP source code in books, since books were protected speech. They wore t-shirts with encryption code. Eventually, they won. Export restrictions were relaxed in 2000. Today’s encrypted messaging exists because of that fight.&lt;/p>
&lt;h2 id="challenges-and-criticisms">Challenges and Criticisms
&lt;a class="heading-anchor" href="#challenges-and-criticisms" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>The Cypherpunks face these main criticisms:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Accessibility&lt;/strong>: Their tools are too complex for many people, so only tech-savvy individuals can use them, leaving others behind.&lt;/li>
&lt;li>&lt;strong>Misuse Risk&lt;/strong>: There’s concern that their encryption tech could be used by bad actors. While Cypherpunks believe privacy is a right for all, this view conflicts with security concerns from authorities who fear these tools could hide illegal acts.&lt;/li>
&lt;/ul>
&lt;p>This shows the ongoing struggle between promoting privacy and maintaining safety in the digital world.&lt;/p>
&lt;p>&lt;img src="/images/blog/2024-12-11/btc-p2p.webp" alt="bitcoin peer-to-peer cash" />&lt;/p>
&lt;h2 id="precursors-to-bitcoin">Precursors to Bitcoin
&lt;a class="heading-anchor" href="#precursors-to-bitcoin" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Bitcoin is the most well-known outcome of the cypherpunk philosophy, embodying their values of decentralization, privacy, and independence from government control over money. Created by the mysterious Satoshi Nakamoto, Bitcoin was first shared with the world through the cypherpunks’ mailing list in 2008.&lt;/p>
&lt;p>However, it is the result of many trials of other technologies also created within this group of people. It uses ideas like proof-of-work from Hashcash, and concepts from b-money and bit gold, all reflecting the cypherpunks’ dream of a currency not controlled by any single entity.&lt;/p>
&lt;h3 id="digicash-ecash">DigiCash (eCash)
&lt;a class="heading-anchor" href="#digicash-ecash" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Developed by David Chaum in the late 1980s and implemented in 1990, DigiCash was one of the earliest attempts at an electronic payment system. It used cryptography to ensure privacy in transactions but struggled with adoption and eventually failed due to issues like centralization and the double-spending problem.&lt;/p>
&lt;h3 id="b-money">B-Money
&lt;a class="heading-anchor" href="#b-money" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Proposed by Wei Dai in 1998, B-Money was a conceptual framework for anonymous, distributed electronic cash. It aimed to solve issues like double-spending without a central authority but was never implemented. Its ideas influenced Bitcoin’s design.&lt;/p>
&lt;h3 id="bit-gold">Bit Gold
&lt;a class="heading-anchor" href="#bit-gold" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Also conceptualized in 1998 by Nick Szabo, Bit Gold proposed a currency with properties similar to gold, using cryptographic proof-of-work. Like B-Money, it was never fully realized but contributed to Bitcoin’s development, particularly its proof-of-work system.&lt;/p>
&lt;h3 id="hashcash">Hashcash
&lt;a class="heading-anchor" href="#hashcash" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Introduced by Adam Back in 1997, Hashcash was not a currency but a system to counter email spam using proof-of-work. This concept was later adopted by Bitcoin for mining.&lt;/p>
&lt;blockquote>
&lt;p>These earlier projects and ideas, while not successful in creating a functional digital currency, were critical in laying the theoretical groundwork for Bitcoin. They tackled issues like double-spending, privacy, and decentralization, which were key problems Bitcoin aimed to solve.&lt;/p>
&lt;/blockquote>
&lt;h2 id="cypherpunk-legacy">Cypherpunk legacy
&lt;a class="heading-anchor" href="#cypherpunk-legacy" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Bitcoin has revolutionized our understanding of money, privacy, and security:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Decentralized Control&lt;/strong>: Bitcoin isn’t run by any bank or government, which fits perfectly with the cypherpunk’s skepticism of centralized power.&lt;/li>
&lt;li>&lt;strong>Privacy&lt;/strong>: While not completely anonymous, Bitcoin transactions use pseudonyms, offering some protection from financial oversight.&lt;/li>
&lt;li>&lt;strong>Immutable Transactions&lt;/strong>: Once a transaction is on the blockchain, it’s nearly unchangeable, fostering trust in digital dealings.&lt;/li>
&lt;/ul>
&lt;p>Bitcoin has brought cypherpunk ideals to life, sparking global discussions on financial privacy, money’s nature, and cryptography’s transformative power. With developments like the &lt;a rel="external" href="https://en.wikipedia.org/wiki/Lightning_Network">Lightning Network&lt;/a> for faster, private transactions and &lt;a href="/blog/programmable-money/#p2tr-pay-to-taproot-taproot-up">Taproot&lt;/a> for enhanced transaction privacy, Bitcoin continues to evolve.&lt;/p>
&lt;h2 id="what-the-cypherpunks-left-behind">What the cypherpunks left behind
&lt;a class="heading-anchor" href="#what-the-cypherpunks-left-behind" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>The cypherpunks proved that a small group of people who write code can change the world. Every encrypted message you send, every Bitcoin transaction, every anonymous browse: their legacy.&lt;/p>
&lt;p>Privacy isn’t dead. They made sure of that.&lt;/p>
&lt;hr />
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/9vM0oIEhMag"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div>
&lt;hr />
&lt;p>&lt;strong>Related links&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Learn more: &lt;a href="/pgp">What is PGP encryption?&lt;/a> &lt;small>A 3-minute tutorial for beginners&lt;/small>&lt;/li>
&lt;li>Wikipedia Article: &lt;a rel="external" href="https://en.wikipedia.org/wiki/Cypherpunk">wikipedia.org/Cypherpunk&lt;/a>&lt;/li>
&lt;/ul></content></entry><entry xml:lang="en"><title>Verified Git Commits</title><subtitle>Boosting trust and security in your codebase</subtitle><category term="git" scheme="https://chemaclass.com/tags/git/" label="Git"/><category term="security" scheme="https://chemaclass.com/tags/security/" label="Security"/><category term="cryptography" scheme="https://chemaclass.com/tags/cryptography/" label="Cryptography"/><category term="open-source" scheme="https://chemaclass.com/tags/open-source/" label="Open Source"/><published>2024-11-17T00:00:00+00:00</published><updated>2024-11-17T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/verified-git-commits/"/><id>https://chemaclass.com/blog/verified-git-commits/</id><summary type="html">Sign your Git commits with GPG to prove they're really from you. Without signatures, anyone can fake commits using your email. It takes 5 minutes to set up and adds real trust to your codebase.</summary><content type="html">&lt;p>When it comes to software development, trust and security are very important. One easy way to level up both is by using verified commits.&lt;/p>
&lt;span id="continue-reading">&lt;/span>
&lt;p>Whether you’re working on an open-source project or in a private company, verified commits can make sure your contributions are legit. Let’s break down what they are, why they’re important, and how to start using them.&lt;/p>
&lt;h2 id="what-are-verified-commits">What are verified commits?
&lt;a class="heading-anchor" href="#what-are-verified-commits" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>A verified commit is basically a Git commit that is signed by the author using a digital signature. This signature proves that the commit actually came from the person who says they made it. Tools like &lt;a rel="external" href="https://gnupg.org/">GPG (GNU Privacy Guard)&lt;/a> let you attach this signature to your commits.&lt;/p>
&lt;p>If you’re using platforms like GitHub, you’ll notice a little “Verified” badge next to commits that are signed properly. It’s a quick way to show that the commit is authentic.&lt;/p>
&lt;p>&lt;img src="/images/blog/2024-11-17/verified-commit-example.jpg" alt="blog-cover" />&lt;/p>
&lt;h2 id="why-are-they-important">Why Are They Important?
&lt;a class="heading-anchor" href="#why-are-they-important" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Signed commits help keep your contributions authentic and trustworthy. By adding a cryptographic signature to your commits, you prove that the changes came from you. This is especially important in collaborative environments, where maintaining trust and accountability is key.&lt;/p>
&lt;p>Without signed commits, anyone could fake a commit using someone else’s email. For example, they could use your email, and platforms like GitHub would link it to your profile, making it look like you made the changes, even if you didn’t… not good!&lt;/p>
&lt;p>&lt;img src="/images/blog/2024-11-17/impersonating-commit.jpg" alt="blog-cover" />&lt;/p>
&lt;p>&lt;img src="/images/blog/2024-11-17/impersonating-commit4.webp" alt="blog-cover" />&lt;/p>
&lt;p>By signing your commits, you show that the work is genuinely yours. It stops impersonation, builds trust in what you’ve done, and keeps everything transparent and accountable.&lt;/p>
&lt;blockquote>
&lt;p>&lt;small>Note: For this demo, I used a public email address belonging to Linus Torvalds. After pushing the commit to this repository, GitHub recognized the email and linked it to his profile. This impersonation is purely for demo purposes to highlight potential risks. Always use your own email for commits.&lt;/small>&lt;/p>
&lt;/blockquote>
&lt;hr />
&lt;h2 id="how-to-get-started-with-verified-commits">How to get started with verified commits
&lt;a class="heading-anchor" href="#how-to-get-started-with-verified-commits" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;h3 id="set-up-a-gpg-key">Set up a GPG key
&lt;a class="heading-anchor" href="#set-up-a-gpg-key" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>First, you’ll need a GPG key to start signing commits. Here’s how:&lt;/p>
&lt;p>Generate a GPG key:&lt;/p>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="shellscript">&lt;span class="giallo-l">&lt;span style="color: light-dark(#6F42C1, #B392F0);">gpg&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> -&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">-full-generate-key&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;p>Find your key ID:&lt;/p>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="shellscript">&lt;span class="giallo-l">&lt;span style="color: light-dark(#6F42C1, #B392F0);">gpg&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> -&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">-list-secret-keys&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> -&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">-keyid-format=long&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;p>Tell Git to use your key:&lt;/p>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="shellscript">&lt;span class="giallo-l">&lt;span style="color: light-dark(#6F42C1, #B392F0);">git&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);"> config&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> -&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">-global&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);"> user.signingkey&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">your-key-i&lt;/span>&lt;span>d&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;p>Make signing commits the default:&lt;/p>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="shellscript">&lt;span class="giallo-l">&lt;span style="color: light-dark(#6F42C1, #B392F0);">git&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);"> config&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> -&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">-global&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);"> commit.gpgsign&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> true&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;h3 id="add-your-key-to-github-gitlab">Add your key to &lt;a rel="external" href="https://github.com/settings/keys">GitHub&lt;/a>/&lt;a rel="external" href="https://docs.gitlab.com/user/project/repository/signed_commits/gpg/">GitLab&lt;/a>
&lt;a class="heading-anchor" href="#add-your-key-to-github-gitlab" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Export your public key:&lt;/p>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="shellscript">&lt;span class="giallo-l">&lt;span style="color: light-dark(#6F42C1, #B392F0);">gpg&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> -&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">-armor&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> -&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">-export&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">your-key-i&lt;/span>&lt;span>d&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;p>Navigate to “Settings &amp;gt; SSH and GPG keys,” and paste your key.&lt;/p>
&lt;p>&lt;img src="/images/blog/2024-11-17/gpg-keys.jpg" alt="blog-cover" />&lt;/p>
&lt;h3 id="start-signing-commits">Start signing commits
&lt;a class="heading-anchor" href="#start-signing-commits" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>From now on, Git will automatically sign your commits.&lt;/p>
&lt;p>If you want to sign a commit manually, just use the &lt;code>-S&lt;/code> flag:&lt;/p>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="shellscript">&lt;span class="giallo-l">&lt;span style="color: light-dark(#6F42C1, #B392F0);">git&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);"> commit&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> -&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">S&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> -&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">m&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);"> &amp;quot;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">Your commit message&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;quot;&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;p>You can &lt;strong>verify&lt;/strong> the commit signature with:&lt;/p>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="shellscript">&lt;span class="giallo-l">&lt;span style="color: light-dark(#6F42C1, #B392F0);">git&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);"> log&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> -&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">-show-signature&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;p>And also when clicking on the “Verified” badge on GitHub directly.&lt;/p>
&lt;p>&lt;img src="/images/blog/2024-11-17/gpg-verify.jpg" alt="blog-cover" />&lt;/p>
&lt;p>Verified commits might seem like a small step, but they make your code more trustworthy. It’s an easy way to add an extra layer of protection to your work, and it’s worth it. Give it a try!&lt;/p>
&lt;hr />
&lt;h3 id="extra-full-setup-in-spanish-es">Extra: Full setup in Spanish 🇪🇸
&lt;a class="heading-anchor" href="#extra-full-setup-in-spanish-es" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/0DzQBu7U2f4"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div>
&lt;hr />
&lt;p>&lt;strong>Related links&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Learn more: &lt;a href="/pgp">What is PGP encryption?&lt;/a> &lt;small>A 3-minute tutorial for beginners&lt;/small>&lt;/li>
&lt;/ul></content></entry><entry xml:lang="en"><title>Pretty Good Privacy</title><subtitle>How PGP secures your digital communication</subtitle><category term="security" scheme="https://chemaclass.com/tags/security/" label="Security"/><category term="privacy" scheme="https://chemaclass.com/tags/privacy/" label="Privacy"/><category term="cryptography" scheme="https://chemaclass.com/tags/cryptography/" label="Cryptography"/><published>2024-07-13T00:00:00+00:00</published><updated>2024-07-13T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/pretty-good-privacy/"/><id>https://chemaclass.com/blog/pretty-good-privacy/</id><summary type="html">PGP is an encryption program that ensures privacy and authentication for data communication. It is used for signing, encrypting, and decrypting texts, emails, files, directories, and whole disk partitions, enhancing the security of email communications.</summary><content type="html">&lt;p>PGP (&lt;em>Pretty Good Privacy&lt;/em>) is an encryption program that ensures privacy and authentication for data communication. It is used for signing, encrypting, and decrypting texts, emails, files, directories, and whole disk partitions.&lt;/p>
&lt;span id="continue-reading">&lt;/span>&lt;h2 id="history">History
&lt;a class="heading-anchor" href="#history" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>PGP was developed by &lt;a rel="external" href="https://en.wikipedia.org/wiki/Phil_Zimmermann">Phil Zimmermann&lt;/a> out of concern for the lack of privacy in digital communications. He aimed to provide individuals with strong encryption tools. In 1991, PGP was released to the public for free, marking the beginning of a new era in digital security.&lt;/p>
&lt;h3 id="legal-challenges">Legal Challenges
&lt;a class="heading-anchor" href="#legal-challenges" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>In the early 1990s, strong encryption was classified as a weapon under U.S. export law. When PGP spread globally via the internet, Zimmermann faced a criminal investigation for “exporting munitions.”&lt;/p>
&lt;p>His defense was clever: he published the PGP source code in a book. Books are protected speech. The case was dropped in 1996, and encryption export restrictions were eventually relaxed in 2000.&lt;/p>
&lt;hr />
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/1-MPcUHhXoc"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div>
&lt;h2 id="key-features">Key Features
&lt;a class="heading-anchor" href="#key-features" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;ul>
&lt;li>Encrypts and decrypts data to ensure secure communication&lt;/li>
&lt;li>Provides authentication to verify the identity of senders and receivers&lt;/li>
&lt;li>Generates public and private keys for secure key exchange&lt;/li>
&lt;li>Supports various encryption algorithms and hash functions&lt;/li>
&lt;/ul>
&lt;p>Today, PGP lives on as &lt;strong>OpenPGP&lt;/strong> (the standard) and &lt;strong>GPG&lt;/strong> (GNU Privacy Guard, the free implementation). When you verify a software download or sign a git commit, you’re often using GPG.&lt;/p>
&lt;h2 id="how-it-works">How it works
&lt;a class="heading-anchor" href="#how-it-works" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>PGP uses a combination of &lt;a rel="external" href="https://en.wikipedia.org/wiki/Public-key_cryptography">public-key&lt;/a> and &lt;a rel="external" href="https://en.wikipedia.org/wiki/Symmetric-key_algorithm">symmetric-key&lt;/a> to ensure secure data transmission. It generates a keypair consisting of a public key and a private key. The public key is shared with others, while the private key is kept secret. When data is encrypted, it is encrypted with the public key, and only the corresponding private key can decrypt it.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>Symmetric Key Encryption&lt;/strong>: PGP generates a unique, one-time-use session key to encrypt the message. This method is fast and efficient but requires the sender and recipient to share the same key securely.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Asymmetric Key Encryption&lt;/strong>: PGP solves the key exchange problem with asymmetric encryption. Each user has a public key and a private key. The session key is encrypted with the recipient’s public key and can only be decrypted by the recipient’s private key.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Digital Signatures&lt;/strong>: PGP provides authentication through digital signatures. The sender signs the message with their private key, allowing the recipient to verify the sender’s identity using the sender’s public key, ensuring the message has not been tampered with.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/Lq-yKJFHJpk"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div>
&lt;hr />
&lt;h2 id="my-public-key">My public key
&lt;a class="heading-anchor" href="#my-public-key" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;h3 id="fingerprint">Fingerprint
&lt;a class="heading-anchor" href="#fingerprint" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="plain">&lt;span class="giallo-l">&lt;span>56D5 D60B 0934 0999 199C 3750 E51B 5BF4 5F85 D160&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;h3 id="import-directly">Import directly
&lt;a class="heading-anchor" href="#import-directly" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="shellscript">&lt;span class="giallo-l">&lt;span style="color: light-dark(#6F42C1, #B392F0);">curl&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);"> https://chemaclass.com/pgp.asc&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> |&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);"> gpg&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> -&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">-import&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;h3 id="download-the-asc-file">Download the .asc file
&lt;a class="heading-anchor" href="#download-the-asc-file" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>&lt;a href="/pgp.asc" id="download-link">Download public PGP key&lt;/a>&lt;/p></content></entry><entry xml:lang="en"><title>Programmable Money</title><subtitle>The power of Bitcoin's Script</subtitle><category term="bitcoin" scheme="https://chemaclass.com/tags/bitcoin/" label="Bitcoin"/><category term="software" scheme="https://chemaclass.com/tags/software/" label="Software"/><category term="cryptography" scheme="https://chemaclass.com/tags/cryptography/" label="Cryptography"/><category term="security" scheme="https://chemaclass.com/tags/security/" label="Security"/><published>2024-07-06T00:00:00+00:00</published><updated>2024-07-06T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/programmable-money/"/><id>https://chemaclass.com/blog/programmable-money/</id><summary type="html">Bitcoin is often referred to as programmable money because it allows for the execution of programmable transactions through its scripting language, leveraging each bit for precision and functionality.</summary><content type="html">&lt;p>Bitcoin is often referred to as “programmable money” because it allows for the execution of programmable transactions through its scripting language.&lt;/p>
&lt;span id="continue-reading">&lt;/span>&lt;h2 id="understanding-programmable-money">Understanding Programmable Money
&lt;a class="heading-anchor" href="#understanding-programmable-money" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Programmable money is the ability to embed logic and conditions into financial transactions. This programmability allows transactions to be executed automatically based on predefined rules without intermediaries or manual intervention. It transforms money from a static medium of exchange into a dynamic tool capable of executing complex agreements and automating financial operations.&lt;/p>
&lt;h2 id="the-script-language">The Script Language
&lt;a class="heading-anchor" href="#the-script-language" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Bitcoin’s programmability is powered by its built-in scripting language, &lt;a rel="external" href="https://en.bitcoin.it/wiki/Script">&lt;strong>Script&lt;/strong>&lt;/a>. Unlike traditional programming languages, Script is a stack-based, Forth-like language explicitly designed for Bitcoin transactions.&lt;/p>
&lt;p>It supports multi-signature, time-locked, and other conditional transfers that can be programmed into Bitcoin transactions. It is intentionally not Turing-complete, without loops.&lt;/p>
&lt;p>This video includes examples of the most commonly used locking/unlocking scripts.&lt;/p>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/6Fa04MnURhw"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div>
&lt;h2 id="key-features-of-bitcoin-s-script">Key Features of Bitcoin’s Script
&lt;a class="heading-anchor" href="#key-features-of-bitcoin-s-script" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;h3 id="stack-based-execution">Stack-Based Execution
&lt;a class="heading-anchor" href="#stack-based-execution" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Script operates on a stack-based execution model where commands and data are pushed onto a stack and processed in a Last-In-First-Out (&lt;a rel="external" href="https://en.wikipedia.org/wiki/Stack_(abstract_data_type)">LIFO&lt;/a>) manner.&lt;/p>
&lt;h3 id="conditional-spending">Conditional Spending
&lt;a class="heading-anchor" href="#conditional-spending" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>A transaction that can only be spent if certain data is provided or specific criteria are met. This can be used for:&lt;/p>
&lt;ul>
&lt;li>escrow services&lt;/li>
&lt;li>atomic swaps&lt;/li>
&lt;li>and other complex financial arrangements&lt;/li>
&lt;/ul>
&lt;h3 id="multisignature">Multisignature
&lt;a class="heading-anchor" href="#multisignature" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Transactions can be set up to require multiple signatures from different private keys before they can be spent. Useful for:&lt;/p>
&lt;ul>
&lt;li>joint accounts&lt;/li>
&lt;li>corporate funds&lt;/li>
&lt;li>and enhancing security, as no single party can unilaterally spend the funds&lt;/li>
&lt;/ul>
&lt;h3 id="timelocking">Timelocking
&lt;a class="heading-anchor" href="#timelocking" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Transactions can include time-based conditions that prevent them from being spent until a certain time or block height is reached. This feature is useful for various purposes:&lt;/p>
&lt;ul>
&lt;li>delayed payments&lt;/li>
&lt;li>smart contracts&lt;/li>
&lt;li>and ensuring that funds are not spent prematurely (eg: with &lt;a rel="external" href="https://en.bitcoin.it/wiki/Lightning_Network">Lightning Network&lt;/a>)&lt;/li>
&lt;/ul>
&lt;h3 id="operation-codes">Operation Codes
&lt;a class="heading-anchor" href="#operation-codes" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Bitcoin’s Script performs specific operations within transactions with its &lt;a rel="external" href="https://en.bitcoin.it/wiki/Script#Opcodes">OP_Codes&lt;/a>. Here are some of them:&lt;/p>
&lt;ul>
&lt;li>&lt;code>OP_DUP&lt;/code>: &lt;small>Duplicates the top stack item.&lt;/small>&lt;/li>
&lt;li>&lt;code>OP_HASH160&lt;/code>: &lt;small>Hashes the top stack item twice (SHA-256 followed by RIPEMD-160).&lt;/small>&lt;/li>
&lt;li>&lt;code>OP_EQUALVERIFY&lt;/code>: &lt;small>Verifies that the top two items are equal and removes them.&lt;/small>&lt;/li>
&lt;li>&lt;code>OP_CHECKSIG&lt;/code>: &lt;small>Verifies a signature against a public key.&lt;/small>&lt;/li>
&lt;li>&lt;a rel="external" href="https://en.bitcoin.it/wiki/OP_RETURN">&lt;code>OP_RETURN&lt;/code>&lt;/a>: &lt;small>Marks the transaction output as invalid, often used to store data.&lt;/small>&lt;/li>
&lt;/ul>
&lt;hr />
&lt;h2 id="common-bitcoin-address-types">Common Bitcoin address types
&lt;a class="heading-anchor" href="#common-bitcoin-address-types" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>In Bitcoin, different address types correspond to various ways to script transactions. Here, we’ll explore examples of Bitcoin Script for each major address type. Each address type has its own specific script format.&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://chemaclass.com/blog/programmable-money/#p2pk-pay-to-pubkey-earliest-legacy-address-up">&lt;strong>P2PK&lt;/strong>&lt;/a>: Earliest legacy transactions using full public keys directly.&lt;/li>
&lt;li>&lt;a href="https://chemaclass.com/blog/programmable-money/#p2pkh-pay-to-pubkey-hash-legacy-address-up">&lt;strong>P2PKH&lt;/strong>&lt;/a>: Begins with &lt;code>1&lt;/code>. &lt;strong>Legacy&lt;/strong> transactions using public key hashes.&lt;/li>
&lt;li>&lt;a href="https://chemaclass.com/blog/programmable-money/#p2sh-pay-to-script-hash-up">&lt;strong>P2SH&lt;/strong>&lt;/a>: Begins with &lt;code>3&lt;/code>. &lt;strong>Legacy&lt;/strong>, encapsulates complex scripts like multisig.&lt;/li>
&lt;li>&lt;a href="https://chemaclass.com/blog/programmable-money/#p2ms-pay-to-multisig-up">&lt;strong>P2MS&lt;/strong>&lt;/a>: It is typically a type of P2SH or P2WSH address.&lt;/li>
&lt;li>&lt;a href="https://chemaclass.com/blog/programmable-money/#p2wpkh-pay-to-witness-public-key-hash-segwit-up">&lt;strong>P2WPKH&lt;/strong>&lt;/a>: Begins with &lt;code>bc1&lt;/code>. Native &lt;strong>SegWit&lt;/strong>, more efficient transactions.&lt;/li>
&lt;li>&lt;a href="https://chemaclass.com/blog/programmable-money/#p2wsh-pay-to-witness-script-hash-segwit-up">&lt;strong>P2WSH&lt;/strong>&lt;/a>: Begins with &lt;code>bc1&lt;/code>. &lt;strong>SegWit&lt;/strong> for complex scripts.&lt;/li>
&lt;li>&lt;a href="https://chemaclass.com/blog/programmable-money/#p2tr-pay-to-taproot-taproot-up">&lt;strong>P2TR&lt;/strong>&lt;/a>: Begins with &lt;code>bc1p&lt;/code>. SegWit &lt;strong>Taproot&lt;/strong> addresses, improving privacy and efficiency for complex transactions.&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>Using native SegWit (P2WPKH and P2WSH) is preferable when possible, as it maximizes the benefits of the SegWit upgrade, but P2SH-SegWit can be useful for compatibility with older systems.&lt;/p>
&lt;/blockquote>
&lt;h3 id="p2pk-pay-to-pubkey-earliest-legacy-address-up">P2PK (Pay-to-PubKey) - Earliest Legacy Address &lt;small>&lt;a href="https://chemaclass.com/blog/programmable-money/#common-bitcoin-address-types">up&lt;/a>&lt;/small>
&lt;a class="heading-anchor" href="#p2pk-pay-to-pubkey-earliest-legacy-address-up" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;div class="status info">
Begins with "1" (e.g., 1A1zP1eP5QGefi2DMPTf...v7DivfNa)
&lt;/div>
&lt;p>Before P2PKH and P2SH became standard, Bitcoin addresses were not as flexible or feature-rich. Here are some considerations:&lt;/p>
&lt;ul>
&lt;li>Addresses starting with 1 but without hashing the public key.&lt;/li>
&lt;li>Not common in modern practice due to lack of privacy and efficiency.&lt;/li>
&lt;li>The P2PK format is largely &lt;strong>obsolete&lt;/strong> in favor of (at very least) P2PKH.&lt;/li>
&lt;/ul>
&lt;hr />
&lt;h3 id="p2pkh-pay-to-pubkey-hash-legacy-address-up">P2PKH (Pay-to-PubKey-Hash) - Legacy Address &lt;small>&lt;a href="https://chemaclass.com/blog/programmable-money/#common-bitcoin-address-types">up&lt;/a>&lt;/small>
&lt;a class="heading-anchor" href="#p2pkh-pay-to-pubkey-hash-legacy-address-up" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;div class="status info">
Begins with "1" (e.g., 1A1zP1eP5QGefi2DMPTf...v7DivfNa)
&lt;/div>
&lt;p>A typical P2PKH script consists of two main parts:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>ScriptPubKey&lt;/strong>: The locking script (also known as the output script) that specifies how funds can be spent.&lt;/li>
&lt;li>&lt;strong>ScriptSig&lt;/strong>: The unlocking script (also known as the input script) that provides the necessary data to unlock the funds.&lt;/li>
&lt;/ol>
&lt;h3 id="scriptpubkey-locking-script">ScriptPubKey (Locking Script)
&lt;a class="heading-anchor" href="#scriptpubkey-locking-script" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);">OP_DUP&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> OP_HASH160&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">PubKHash&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> OP_EQUALVERIFY&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> OP_CHECKSIG&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;ul>
&lt;li>&lt;code>OP_DUP&lt;/code>: Duplicates the top stack item (the public key).&lt;/li>
&lt;li>&lt;code>OP_HASH160&lt;/code>: Hashes the public key with SHA-256 followed by RIPEMD-160.&lt;/li>
&lt;li>&lt;code>&amp;lt;PubKHash&amp;gt;&lt;/code>: The hashed public key (a 20-byte value).&lt;/li>
&lt;li>&lt;code>OP_EQUALVERIFY&lt;/code>: Checks if the hashed public key matches the hash in the script.&lt;/li>
&lt;li>&lt;code>OP_CHECKSIG&lt;/code>: Verifies the provided signature against the public key.&lt;/li>
&lt;/ul>
&lt;h3 id="scriptsig-unlocking-script">ScriptSig (Unlocking Script)
&lt;a class="heading-anchor" href="#scriptsig-unlocking-script" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">sig&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">PubK&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;ul>
&lt;li>&lt;code>&amp;lt;sig&amp;gt;&lt;/code>: The digital signature generated by the private key.&lt;/li>
&lt;li>&lt;code>&amp;lt;PubK&amp;gt;&lt;/code>: The public key corresponding to the address.&lt;/li>
&lt;/ul>
&lt;h3 id="execution-flow">Execution Flow
&lt;a class="heading-anchor" href="#execution-flow" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ol>
&lt;li>The &lt;code>ScriptSig&lt;/code> (unlocking script) is pushed onto the stack.&lt;/li>
&lt;li>The &lt;code>ScriptPubKey&lt;/code> (locking script) is executed.&lt;/li>
&lt;/ol>
&lt;p>&lt;img src="https://raw.githubusercontent.com/bitcoinbook/bitcoinbook/develop/images/mbc3_0703.png" alt="p2pkh script execution step 1" />
&lt;img src="https://raw.githubusercontent.com/bitcoinbook/bitcoinbook/develop/images/mbc3_0704.png" alt="p2pkh script execution step 2" />&lt;/p>
&lt;hr />
&lt;h3 id="p2sh-pay-to-script-hash-up">P2SH (Pay-to-Script-Hash) &lt;small>&lt;a href="https://chemaclass.com/blog/programmable-money/#common-bitcoin-address-types">up&lt;/a>&lt;/small>
&lt;a class="heading-anchor" href="#p2sh-pay-to-script-hash-up" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;div class="status info">
Begins with "3" (e.g., 3J2BtwzN2GEr6FCP.....81T2eiX8PVHh)
&lt;/div>
&lt;p>P2SH scripts are used for more complex scripts. The primary feature is that the address itself encodes a hash of a script, which will be used in the transaction.&lt;/p>
&lt;h3 id="scriptpubkey-locking-script-1">ScriptPubKey (Locking Script)
&lt;a class="heading-anchor" href="#scriptpubkey-locking-script-1" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);">OP_HASH160&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">ScriptHash&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> OP_EQUAL&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;ul>
&lt;li>&lt;code>OP_HASH160&lt;/code>: Hashes the script with SHA-256 followed by RIPEMD-160.&lt;/li>
&lt;li>&lt;code>&amp;lt;ScriptHash&amp;gt;&lt;/code>: The hashed script (a 20-byte value).&lt;/li>
&lt;li>&lt;code>OP_EQUAL&lt;/code>: Checks if the hash matches the provided script hash.&lt;/li>
&lt;/ul>
&lt;h3 id="scriptsig-unlocking-script-1">ScriptSig (Unlocking Script)
&lt;a class="heading-anchor" href="#scriptsig-unlocking-script-1" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">sig&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">PubK&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> ...&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">ScriptSig&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;ul>
&lt;li>&lt;code>&amp;lt;sig&amp;gt;&lt;/code>: The digital signature.&lt;/li>
&lt;li>&lt;code>&amp;lt;PubK&amp;gt;&lt;/code>: The public key.&lt;/li>
&lt;li>&lt;code>&amp;lt;ScriptSig&amp;gt;&lt;/code>: The actual script that matches the script hash, which itself will be executed by the Bitcoin network.&lt;/li>
&lt;/ul>
&lt;hr />
&lt;h3 id="p2ms-pay-to-multisig-up">P2MS (Pay-to-Multisig) &lt;small>&lt;a href="https://chemaclass.com/blog/programmable-money/#common-bitcoin-address-types">up&lt;/a>&lt;/small>
&lt;a class="heading-anchor" href="#p2ms-pay-to-multisig-up" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;h3 id="script-format">Script Format
&lt;a class="heading-anchor" href="#script-format" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);">OP_M&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">M&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">PubK1&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">PubK2&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> ...&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">PubKN&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> OP_N&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> OP_CHECKMULTISIG&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;ul>
&lt;li>&lt;code>OP_M&lt;/code>: The minimum number of signatures required.&lt;/li>
&lt;li>&lt;code>&amp;lt;PubK1&amp;gt;, &amp;lt;PubK2&amp;gt;, ..., &amp;lt;PubKN&amp;gt;&lt;/code>: The public keys involved in the multisignature scheme.&lt;/li>
&lt;li>&lt;code>OP_N&lt;/code>: The total number of public keys provided.&lt;/li>
&lt;li>&lt;code>OP_CHECKMULTISIG&lt;/code>: The opcode that verifies the signatures against the provided public keys.&lt;/li>
&lt;/ul>
&lt;h3 id="scriptpubkey-locking-script-2">ScriptPubKey (Locking Script)
&lt;a class="heading-anchor" href="#scriptpubkey-locking-script-2" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);">OP_2&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">PubK1&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">PubK2&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">PubK3&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> OP_3&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> OP_CHECKMULTISIG&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;p>This script means that any 2 out of 3 provided public keys are required to sign the transaction for it to be valid.&lt;/p>
&lt;h3 id="scriptsig-unlocking-script-2">ScriptSig (Unlocking Script)
&lt;a class="heading-anchor" href="#scriptsig-unlocking-script-2" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">sig1&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">sig2&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> ...&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">sigN&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">SerializedScript&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;ul>
&lt;li>&lt;code>&amp;lt;sig1&amp;gt;, &amp;lt;sig2&amp;gt;, ..., &amp;lt;sigN&amp;gt;&lt;/code>: The public keys.&lt;/li>
&lt;li>&lt;code>&amp;lt;SerializedScript&amp;gt;&lt;/code>: The serialized script (the same as the locking script but without the &lt;code>OP_M&lt;/code> and &lt;code>OP_N&lt;/code>).&lt;/li>
&lt;/ul>
&lt;div class="status warning-orange">
&lt;b>NOTE&lt;/b>: There is an oddity in CHECKMULTISIG execution.
&lt;small>&lt;a href="#there-is-an-oddity-in-checkmultisig-execution-up">See note at the bottom.&lt;/a>&lt;/small>
&lt;/div>
&lt;hr />
&lt;h3 id="p2wpkh-pay-to-witness-public-key-hash-segwit-up">P2WPKH (Pay-to-Witness-Public-Key-Hash) - Segwit &lt;small>&lt;a href="https://chemaclass.com/blog/programmable-money/#common-bitcoin-address-types">up&lt;/a>&lt;/small>
&lt;a class="heading-anchor" href="#p2wpkh-pay-to-witness-public-key-hash-segwit-up" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;div class="status info">
Begins with "bc1q" (e.g., bc1qf0r2m0ck4psv6yrk9w.....kw8v5rj7ph3)
&lt;/div>
&lt;p>P2WPKH is a Segregated Witness (SegWit) address type that uses a different scripting format compared to legacy and P2SH addresses. Simplifies transactions by reducing data size and fees compared to legacy formats.&lt;/p>
&lt;h3 id="scriptpubkey-locking-script-3">ScriptPubKey (Locking Script)
&lt;a class="heading-anchor" href="#scriptpubkey-locking-script-3" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);">OP_0&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> OP_PUSHBYTES_20&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">PubKHash&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;ul>
&lt;li>&lt;code>OP_0&lt;/code>: A single byte (0x00) indicating the version of the script.&lt;/li>
&lt;li>&lt;code>OP_PUSHBYTES_20&lt;/code>: Pushes 20 bytes (the public key hash) onto the stack.&lt;/li>
&lt;li>&lt;code>&amp;lt;PubKHash&amp;gt;&lt;/code>: The 20-byte hash of the public key.&lt;/li>
&lt;/ul>
&lt;h3 id="witness-data">Witness Data
&lt;a class="heading-anchor" href="#witness-data" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>For P2WPKH, the unlocking script is not required in the traditional sense (i.e., inside the unlocking script explicitly included in the transaction input). Instead, the unlocking information is provided as part of the witness data in the SegWit transaction format.&lt;/p>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">sig&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">PubK&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;ul>
&lt;li>&lt;code>&amp;lt;sig&amp;gt;&lt;/code>: Digital signature for the transaction.&lt;/li>
&lt;li>&lt;code>&amp;lt;PubK&amp;gt;&lt;/code>: Public key used to generate the public key hash.&lt;/li>
&lt;/ul>
&lt;hr />
&lt;h3 id="p2wsh-pay-to-witness-script-hash-segwit-up">P2WSH (Pay-to-Witness-Script-Hash) - Segwit &lt;small>&lt;a href="https://chemaclass.com/blog/programmable-money/#common-bitcoin-address-types">up&lt;/a>&lt;/small>
&lt;a class="heading-anchor" href="#p2wsh-pay-to-witness-script-hash-segwit-up" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;div class="status info">
Begins with bc1q (e.g.: bc1q4a3h5sdg4cfkhftgd24tj9g2sg...yj57jmfckhkrw5gslr9g59)
&lt;/div>
&lt;h3 id="scriptpubkey-locking-script-4">ScriptPubKey (Locking Script)
&lt;a class="heading-anchor" href="#scriptpubkey-locking-script-4" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);">OP_0&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> OP_PUSHBYTES_32&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">ScriptHash&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;ul>
&lt;li>&lt;code>OP_0&lt;/code>: Indicates a witness version 0 (SegWit).&lt;/li>
&lt;li>&lt;code>OP_PUSHBYTES_32&lt;/code>: Pushes the next 32 bytes (the script hash) onto the stack.&lt;/li>
&lt;li>&lt;code>&amp;lt;ScriptHash&amp;gt;&lt;/code>: 32-byte hash of the redeem script.&lt;/li>
&lt;/ul>
&lt;h3 id="witness-data-1">Witness Data
&lt;a class="heading-anchor" href="#witness-data-1" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">sig1&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">sig2&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> ...&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">RedeemScript&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;ul>
&lt;li>&lt;code>&amp;lt;sig1&amp;gt;, &amp;lt;sig2&amp;gt;&lt;/code>: Signatures required to unlock the transaction.&lt;/li>
&lt;li>&lt;code>&amp;lt;RedeemScript&amp;gt;&lt;/code>: The actual script that matches the script hash. This script will be executed as part of the witness data.&lt;/li>
&lt;/ul>
&lt;hr />
&lt;h3 id="p2tr-pay-to-taproot-taproot-up">P2TR (Pay-to-Taproot) - Taproot &lt;small>&lt;a href="https://chemaclass.com/blog/programmable-money/#common-bitcoin-address-types">up&lt;/a>&lt;/small>
&lt;a class="heading-anchor" href="#p2tr-pay-to-taproot-taproot-up" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;div class="status info">
Begins with bc1p (e.g.: bc1pl9dfv7kvj4hj9s3a8l.....gjstmrpjl09g8ks3ukds70q4r2j5h)
&lt;/div>
&lt;p>Taproot combines &lt;a rel="external" href="https://en.bitcoin.it/wiki/Schnorr">Schnorr&lt;/a> signatures with &lt;a rel="external" href="https://en.bitcoin.it/wiki/BIP_0114#Merkelized_Abstract_Syntax_Tree">MAST&lt;/a>, enabling private, efficient spending conditions and making complex transactions &lt;strong>&lt;em>appear standard&lt;/em>&lt;/strong> unless conditions are revealed. It allows the efficient execution of complex transactions while hiding their details.&lt;/p>
&lt;h3 id="scriptpubkey-locking-script-5">ScriptPubKey (Locking Script)
&lt;a class="heading-anchor" href="#scriptpubkey-locking-script-5" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);">OP_1&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">x&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">-&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">only&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> PubK&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;ul>
&lt;li>&lt;code>OP_1&lt;/code>: Indicates a witness version 1 (Taproot).&lt;/li>
&lt;li>&lt;code>&amp;lt;x-only PubK&amp;gt;&lt;/code>: A 32-byte Schnorr public key (without the y-coordinate).&lt;/li>
&lt;/ul>
&lt;h3 id="witness-data-2">Witness Data
&lt;a class="heading-anchor" href="#witness-data-2" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">sig&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;ul>
&lt;li>&lt;code>&amp;lt;sig&amp;gt;&lt;/code>: A Schnorr signature proving possession of the private key corresponding to the x-only pubkey.&lt;/li>
&lt;/ul>
&lt;hr />
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/yU3Sr07Qnxg"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div>
&lt;hr />
&lt;h3 id="there-is-an-oddity-in-checkmultisig-execution-up">*There is an oddity in CHECKMULTISIG execution &lt;small>&lt;a href="https://chemaclass.com/blog/programmable-money/#scriptsig-unlocking-script-2">up&lt;/a>&lt;/small>
&lt;a class="heading-anchor" href="#there-is-an-oddity-in-checkmultisig-execution-up" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>The implementation of &lt;code>OP_CHECKMULTISIG&lt;/code> pops one more item than it should. The extra item is disregarded when checking the signatures, so it has no direct effect on the OP itself. It must be present because if &lt;code>OP_CHECKMULTISIG&lt;/code> attempts to pop on an empty stack, it will cause a stack error and script failure.&lt;/p>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);">OP_0&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">sig2&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">sig3&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> 2&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">PubK1&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">PubK2&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> &amp;lt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">PubK3&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">&amp;gt;&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> 3&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> OP_CHECKMULTISIG&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;p>The input script in this multisig is not &lt;code>&amp;lt;sig2&amp;gt; &amp;lt;sig3&amp;gt;&lt;/code> but &lt;code>OP_0 &amp;lt;sig2&amp;gt; &amp;lt;sig3&amp;gt;&lt;/code>.&lt;/p>
&lt;p>It became the custom early on to use &lt;code>OP_0&lt;/code>, which later became a relay policy rule and eventually a consensus rule (&lt;a rel="external" href="https://github.com/bitcoin/bips/blob/master/bip-0147.mediawiki">BIP147&lt;/a>).&lt;/p>
&lt;p>It is possible that the original developer added the extra element in the original version of Bitcoin, so they could add a feature for allowing a map to be passed in a later soft fork (for performance reasons). However, that feature was never implemented, and the BIP147 update to the consensus rules in 2017 makes it impossible to add that feature in the future.&lt;/p>
&lt;p>Only Bitcoin’s original developer could tell whether the dummy stack element was the result of a bug or a plan for a future upgrade. From now on, if you see a multisig script, you should expect to see an extra &lt;code>OP_O&lt;/code> in the beginning, whose only purpose is as a workaround to an oddity in the consensus rules.&lt;/p>
&lt;hr />
&lt;h2 id="follow-ups">Follow-ups
&lt;a class="heading-anchor" href="#follow-ups" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;ul>
&lt;li>Official docs of &lt;a rel="external" href="https://en.bitcoin.it/wiki/Script">Script&lt;/a> in the Bitcoin Wiki.&lt;/li>
&lt;li>&lt;a rel="external" href="https://siminchen.github.io/bitcoinIDE/build/editor.html">Bitcoin IDE&lt;/a> is an online Bitcoin Script visual emulator. Great for learning purposes.&lt;/li>
&lt;li>&lt;a rel="external" href="https://coins.github.io/bitcoin-scripts/script-editor/">Script Editor&lt;/a> is product-driven research on Bitcoin scalability and usability.&lt;/li>
&lt;li>&lt;a rel="external" href="https://bitcoin.sipa.be/miniscript/">Miniscript&lt;/a> is a language for writing (a subset of) Bitcoin Scripts in a structured way, enabling analysis, composition, generic signing, and more.&lt;/li>
&lt;/ul></content></entry></feed>