Commit 99575d28c5
Unsigned
Layout: unified · split
build.py +14 −1
| @@ -115,6 +115,7 @@ def get_recent_posts_html(content_dir="./content/blog", num_posts=3): | |||
| 115 | "date": re.compile(r"^#\+date:\s*<(\d{4}-\d{2}-\d{2})"), | 115 | "date": re.compile(r"^#\+date:\s*<(\d{4}-\d{2}-\d{2})"), |
| 116 | "slug": re.compile(r"^#\+slug:\s*(.+)$", re.IGNORECASE), | 116 | "slug": re.compile(r"^#\+slug:\s*(.+)$", re.IGNORECASE), |
| 117 | "filetags": re.compile(r"^#\+filetags:\s*(.+)$", re.IGNORECASE), | 117 | "filetags": re.compile(r"^#\+filetags:\s*(.+)$", re.IGNORECASE), |
| 118 | "draft": re.compile(r"^#\+draft:\s*(.+)$", re.IGNORECASE), | ||
| 118 | } | 119 | } |
| 119 | 120 | ||
| 120 | for org_path in Path(content_dir).glob("*.org"): | 121 | for org_path in Path(content_dir).glob("*.org"): |
| @@ -122,6 +123,7 @@ def get_recent_posts_html(content_dir="./content/blog", num_posts=3): | |||
| 122 | date_str = None | 123 | date_str = None |
| 123 | slug = None | 124 | slug = None |
| 124 | tags = [] | 125 | tags = [] |
| 126 | is_draft = False | ||
| 125 | 127 | ||
| 126 | with org_path.open("r", encoding="utf-8") as f: | 128 | with org_path.open("r", encoding="utf-8") as f: |
| 127 | for line in f: | 129 | for line in f: |
| @@ -153,17 +155,28 @@ def get_recent_posts_html(content_dir="./content/blog", num_posts=3): | |||
| 153 | tags = [t for t in raw.split(":") if t] | 155 | tags = [t for t in raw.split(":") if t] |
| 154 | continue | 156 | continue |
| 155 | 157 | ||
| 158 | m = header_patterns["draft"].match(line) | ||
| 159 | if m: | ||
| 160 | draft_value = m.group(1).strip().lower() | ||
| 161 | if draft_value != "nil": | ||
| 162 | is_draft = True | ||
| 163 | break | ||
| 164 | continue | ||
| 165 | |||
| 156 | # Stop scanning once we have all required fields | 166 | # Stop scanning once we have all required fields |
| 157 | if title and date_str and slug and tags: | 167 | if title and date_str and slug and tags: |
| 158 | break | 168 | break |
| 159 | 169 | ||
| 170 | if is_draft: | ||
| 171 | continue | ||
| 172 | |||
| 160 | if title and date_str and slug: | 173 | if title and date_str and slug: |
| 161 | try: | 174 | try: |
| 162 | date_obj = datetime.strptime(date_str, "%Y-%m-%d") | 175 | date_obj = datetime.strptime(date_str, "%Y-%m-%d") |
| 163 | except ValueError: | 176 | except ValueError: |
| 164 | # Skip files with invalid date format | 177 | # Skip files with invalid date format |
| 165 | continue | 178 | continue |
| 166 | 179 | ||
| 167 | posts.append( | 180 | posts.append( |
| 168 | { | 181 | { |
| 169 | "title": title, | 182 | "title": title, |
content/blog/2025-06-27-how-blockchain-works.org added +197
| @@ -0,0 +1,197 @@ | |||
| 1 | #+date: <2025-07-07 Mon 00:00:00> | ||
| 2 | #+title: Blockchain Series #1: How Blockchain Works Under the Hood: Hashes, Keys, and Signatures Explained | ||
| 3 | #+description: Dive into blockchain's cryptographic foundations. Explore how hash functions, Merkle trees, and digital signatures secure distributed, tamper-resistant ledgers. | ||
| 4 | #+slug: how-blockchain-works | ||
| 5 | #+filetags: :blockchain:encryption: | ||
| 6 | #+draft: t | ||
| 7 | |||
| 8 | /This is Part 1 of a series I'm writing on blockchain. Stay tuned for further | ||
| 9 | editions./ | ||
| 10 | |||
| 11 | Blockchain is one of those technologies that seems to generate more marketing | ||
| 12 | buzz than real understanding. Everywhere you look, people talk about | ||
| 13 | decentralization, trustless systems, and the next big disruption. But beneath | ||
| 14 | the hype, blockchain systems rely on well-understood cryptographic building | ||
| 15 | blocks to do something very specific: maintain a secure, tamper-resistant ledger | ||
| 16 | without needing a central authority. | ||
| 17 | |||
| 18 | If you're serious about understanding blockchain, it's critical to understand | ||
| 19 | the cryptographic primitives that make it work. Hash functions, digital | ||
| 20 | signatures, and public-key cryptography aren't just jargon—they're the core | ||
| 21 | mechanisms that let a distributed network agree on a shared history no one can | ||
| 22 | easily rewrite. | ||
| 23 | |||
| 24 | This post is Part 1 of a multi-part series on blockchain. Here, we'll focus on | ||
| 25 | these fundamental building blocks—how they work, why they're used, and how they | ||
| 26 | fit together to provide the security and trust that blockchain promises. | ||
| 27 | |||
| 28 | * What is Blockchain? | ||
| 29 | |||
| 30 | At its core, a blockchain is a distributed, append-only ledger shared among | ||
| 31 | participants in a network. | ||
| 32 | |||
| 33 | What does this mean? Essentially, we can think of a standard, non-technical | ||
| 34 | ledger (book of accounts where transactions are recorded against accounts). When | ||
| 35 | introductin the idea of a blockchain, let's extend the idea of a standard ledger | ||
| 36 | and make a few connections: | ||
| 37 | |||
| 38 | - Each block of transactions is connected cryptographically to the block before | ||
| 39 | it, via a [[https://en.wikipedia.org/wiki/Cryptographic_hash_function][cryptographic hash]]. This is what forms a =chain= of blocks, or | ||
| 40 | records. | ||
| 41 | - Each block consists of: | ||
| 42 | - A list of validated transactions | ||
| 43 | - A timestamp | ||
| 44 | - A cryptographic hash of the previous block (ensuring immutability) | ||
| 45 | - Each transaction within a block is initiated between addresses, signed with | ||
| 46 | cryptographic keys, and sent to the blockchain for validation (e.g., | ||
| 47 | proof-of-work, proof-of-staking, etc.). | ||
| 48 | - The blockchain is shared amongst nodes in the network, who agree on the state | ||
| 49 | of the blockchain through consensus mechanisms. | ||
| 50 | |||
| 51 | As we can see, the decentralized nature and cryptographic linking of | ||
| 52 | transactions and blocks ensures that modifying the history is infeasible. | ||
| 53 | |||
| 54 | If you're more of a visual person, here's a very basic diagram of a standard | ||
| 55 | blockchain structure. | ||
| 56 | |||
| 57 | #+begin_example | ||
| 58 | +------------+ +------------+ +------------+ | ||
| 59 | | Block 1 | -> | Block 2 | -> | Block 3 | | ||
| 60 | |------------| |------------| |------------| | ||
| 61 | | Data | | Data | | Data | | ||
| 62 | | Prev Hash: | | Prev Hash: | | Prev Hash: | | ||
| 63 | | 00000000 | | <hash1> | | <hash2> | | ||
| 64 | | Hash: | | Hash: | | Hash: | | ||
| 65 | | <hash1> | | <hash2> | | <hash3> | | ||
| 66 | +------------+ +------------+ +------------+ | ||
| 67 | #+end_example | ||
| 68 | |||
| 69 | * What Problems is Blockchain Trying to Solve? | ||
| 70 | |||
| 71 | I will be diving into the technical details of blockchains later in this post, | ||
| 72 | but what exactly is the reason blockchain exists? | ||
| 73 | |||
| 74 | You may know of cryptocurrencies, such as Bitcoin, but that is only one of many | ||
| 75 | use cases for blockchains. | ||
| 76 | |||
| 77 | As we learned in the section above, a blockchain can be equated to a ledger. | ||
| 78 | With this in mind, let's dive into a few interesting use cases: | ||
| 79 | |||
| 80 | ** Immutable record-keeping | ||
| 81 | |||
| 82 | If you simply need a ledger that cannot be modified easily and can establish a | ||
| 83 | decentralized network to support that, blockchain is a great technology. | ||
| 84 | |||
| 85 | ** Trust without central authority | ||
| 86 | |||
| 87 | The use of a decentralized system means that we do not need to rely on a | ||
| 88 | centralized authority (e.g., Social Security, a bank, etc.) to store and provide | ||
| 89 | access to information you need to record. | ||
| 90 | |||
| 91 | Think of the US Social Security Number (SSN) system. Each time you want to | ||
| 92 | perform actions that require verifying your identify (e.g., opening bank | ||
| 93 | accounts, investment accounts, child birth, etc.), you are currently required to | ||
| 94 | provide your SSN. | ||
| 95 | |||
| 96 | However, this is a singular number - which means that if someone learns it, they | ||
| 97 | can (essentially) now act as you. | ||
| 98 | |||
| 99 | Now imagine a scenario where the SSN system is a blockchain where you have both | ||
| 100 | your private key for providing evidence to people that you are you. For example, | ||
| 101 | you open a bank account and sign your form with your private key. Now, the bank | ||
| 102 | can take that and use your public key to decrypt the message and verify that you | ||
| 103 | are you, without needing to know your private key. | ||
| 104 | |||
| 105 | Another scenario is that, during a background check, a company could use your | ||
| 106 | public key and consult the related blockchain to validate specific pieces of | ||
| 107 | information. For example, if your identity alone is in one block, you could | ||
| 108 | provide that information to your employer without providing your full SSN and | ||
| 109 | all related personal information for as long as they keep your SSN on file. | ||
| 110 | |||
| 111 | ** Double-spending problem | ||
| 112 | |||
| 113 | With the introduction of digital assets, such as cryptocurrencies and | ||
| 114 | non-fungible tokens, a new risk is introduced: without control, these assets | ||
| 115 | could be copied and reused at-will. | ||
| 116 | |||
| 117 | To solve this problem, digital assets are transacted on a blockchain to ensure | ||
| 118 | that the decentralized system of nodes provide consensus on validating | ||
| 119 | transactions, transactions are recorded in a transparent and tamper-resistant | ||
| 120 | manner, and cryptographic functions are performed to order the transactions | ||
| 121 | logically on chain. | ||
| 122 | |||
| 123 | * The Role of Cryptography in Blockchain | ||
| 124 | - Why cryptography matters | ||
| 125 | - Confidentiality vs. integrity/authenticity | ||
| 126 | - Core goals: | ||
| 127 | - Tamper-evidence | ||
| 128 | - Secure identification | ||
| 129 | - Non-repudiation | ||
| 130 | |||
| 131 | * Hash Functions | ||
| 132 | - What is a cryptographic hash? | ||
| 133 | - Properties: | ||
| 134 | - Collision resistance | ||
| 135 | - Pre-image resistance | ||
| 136 | - How blockchain uses hashes: | ||
| 137 | - Chaining blocks together | ||
| 138 | - Block headers | ||
| 139 | - Transactions | ||
| 140 | - Example command: | ||
| 141 | #+begin_src bash | ||
| 142 | echo -n "Hello, Blockchain" | sha256sum | ||
| 143 | #+end_src | ||
| 144 | - Optional diagram: chain of blocks with hashes | ||
| 145 | |||
| 146 | * Merkle Trees | ||
| 147 | - Summarizing many transactions in a single root hash | ||
| 148 | - Use case: efficient inclusion proofs | ||
| 149 | - Example diagram (ASCII art if desired) | ||
| 150 | - Why Merkle roots are in block headers | ||
| 151 | |||
| 152 | * Public Key Cryptography | ||
| 153 | - Quick refresher | ||
| 154 | - Public/private keypairs | ||
| 155 | - Addresses derived from public keys | ||
| 156 | - Importance of keeping private keys secret | ||
| 157 | |||
| 158 | * Digital Signatures | ||
| 159 | - Purpose: proving authorship without revealing private key | ||
| 160 | - Mention ECDSA / EdDSA | ||
| 161 | - How transactions are signed | ||
| 162 | - Example snippet: | ||
| 163 | #+begin_example | ||
| 164 | Alice signs transaction with her private key | ||
| 165 | → Anyone can verify with her public key | ||
| 166 | #+end_example | ||
| 167 | - Why signatures prevent forgery | ||
| 168 | |||
| 169 | * Bringing it All Together: Blockchain Data Structures | ||
| 170 | - Block structure: | ||
| 171 | - Block header with previous block's hash | ||
| 172 | - Merkle root | ||
| 173 | - Timestamp, nonce | ||
| 174 | - How the chain ensures immutability | ||
| 175 | - Example flow: | ||
| 176 | 1. User creates a transaction | ||
| 177 | 2. Signs it | ||
| 178 | 3. Transaction included in block | ||
| 179 | 4. Block hash links to previous block | ||
| 180 | |||
| 181 | * Proof of Work (Optional) | ||
| 182 | - Hash puzzles to add blocks | ||
| 183 | - Why it's hard to modify history | ||
| 184 | - Keep this section simple | ||
| 185 | |||
| 186 | * Conclusion | ||
| 187 | - Summarize how these primitives work together | ||
| 188 | - Tease next post: "Next, we'll explore security threats and how blockchain | ||
| 189 | networks mitigate them." | ||
| 190 | - Optional links to further reading: | ||
| 191 | - Bitcoin whitepaper | ||
| 192 | - Ethereum docs | ||
| 193 | - Cryptography references | ||
| 194 | |||
| 195 | * Optional Extras | ||
| 196 | - Glossary box with terms (hash, signature, Merkle tree) | ||
| 197 | - External references (e.g., NIST docs on hashes) | ||