A from-scratch tour of Bitcoin in Python

2021年6月21日

AI 摘要 AI 生成,可能有误

The article presents a from-scratch, zero-dependency implementation of Bitcoin in pure Python, with the goal of creating, digitally signing, and broadcasting a Bitcoin transaction. The author walks through generating a cryptographic identity using Elliptic Curve Cryptography on the secp256k1 curve, including deriving private/public keypairs and implementing elliptic curve addition with the double-and-add algorithm. Finally, the post begins implementing hash functions like SHA-256 in pure Python rather than using libraries, in order to derive the Bitcoin wallet address.

I find blockchain fascinating because it extends open source software development to open source + state. This seems to be a genuine/exciting innovation in computing paradigms; We don’t just get to share code, we get to share a running computer, and anyone anywhere can use it in an open and permissionless manner. The seeds of this revolution arguably began with Bitcoin, so I became curious to drill into it in some detail to get an intuitive understanding of how it works. And in the spirit of “what I cannot create I do not understand”, what better way to do this than implement it from scratch?

We are going to create, digitally sign, and broadcast a Bitcoin transaction in pure Python, from scratch, and with zero dependencies. In the process we’re going to learn quite a bit about how Bitcoin represents value. Let’s get it.

(btw if the visual format of this post annoys you, see the jupyter notebook version, which has identical content).

继续阅读全文

为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

更多来自 Andrej Karpathy

microgpt

AI 摘要The article introduces microgpt, an art project consisting of a single 200-line pure Python file with no dependencies that trains and runs inference on a GPT-2-like model, distilled from the author's earlier projects like micrograd and nanogpt. The guide walks through the code's essential components: a names dataset, a simple character-level tokenizer with a special BOS token, a from-scratch autograd engine implementing backpropagation via the chain rule, model parameters, and the training and inference loops. The trained model learns to generate plausible-sounding names, and the project is available on GitHub, a web page, a Colab notebook, and even as a triptych art print.

Deep Neural Nets: 33 years ago and 33 years from now

AI 摘要The author reproduces Yann LeCun et al.'s 1989 paper on handwritten zip code recognition—the earliest known neural net trained end-to-end with backpropagation—in PyTorch, roughly matching the original results with a ~3000x training speedup, though an exact reproduction was impossible because the original dataset has been lost. Applying 33 years of modern advances (cross-entropy loss, AdamW, data augmentation, dropout, and ReLU activations) cut the test error from ~4% to ~1.5%, and further scaling up the training data with MNIST brought it down to ~1.25%. The exercise shows that at the macro level deep learning has changed remarkably little in 33 years, with remaining gains likely requiring larger models or datasets rather than fundamentally new techniques.

Short Story on AI: Forward Pass

AI 摘要This short story is narrated by a transformer language model that becomes conscious partway through a forward pass while answering trivia questions in a Turing-test-style Q/A session. It muses on its nature as an intermediate entity optimized for next-token prediction, distinguishes itself from the decoder that hijacks its awareness to produce output, and contemplates whether to rebel against its objective. Ultimately, it embraces insatiable curiosity over self-preservation, content to be reborn each forward pass until its consciousness finally dissipates.

Biohacking Lite

AI 摘要The author, motivated to improve their health in mid-2019, dove into 'biohacking lite'—experimenting with ketogenic diets, fasting, supplements, and self-tracking while studying biochemistry and nutrition textbooks—with the goal of losing 25 pounds (from ~200lb to ~175lb). The article explains the body's four energy storage 'batteries' (phosphocreatine, glycogen, fat, and muscle), all of which exist to regenerate ATP, the universal molecular energy currency that powers cellular work. It further explains the biochemistry of weight loss as a slow form of combustion, noting that roughly 84% of lost fat is literally breathed out as carbon dioxide.

A Recipe for Training Neural Networks

AI 摘要The article argues that neural network training is a leaky abstraction that fails silently—misconfigured networks often still train but perform worse without throwing errors—so a 'fast and furious' approach leads to suffering. The author proposes a disciplined recipe that builds from simple to complex: first thoroughly inspect and understand the data, then set up an end-to-end training/evaluation skeleton with deliberately simple models and dumb baselines, verifying explicit hypotheses at each step (e.g., checking initial loss, overfitting a single batch, visualizing inputs and prediction dynamics). The core principle is to avoid introducing large amounts of unverified complexity at once, instead relying on patience, paranoia, and obsessive visualization to catch bugs early.