Satoshi Against Himself: How His Code Changed
Was Satoshi Nakamoto one person, or a group of people writing under one name? It's one of the oldest questions in Bitcoin, and I've heard both sides argued with total confidence: some are sure that nobody could have pulled off the paper, the code and two years of support alone, others that Bitcoin has a lone genius written all over it. Most of that debate is about the emails and forum posts. I think the code is a better witness, because programmers leave habits all over their work (where the braces go, how variables are named, how often they print a debug line), and those habits are hard to keep up by accident for two years straight. So here's the test I've set up: if several people wrote Bitcoin, the style should wobble from release to release, or jump when a new hand takes over. If it was one programmer, it should hold steady.
Before the numbers, here's what code style can and can't tell us. It can tell whether two pieces of code look like they came from the same hands. It can't put a name on those hands, and it can't catch a disciplined team that agrees on one house style (Bitcoin had one, as you'll see further down). So this chapter is about consistency, not identity, and nothing on this page says who Satoshi was.
The short answer, after I've had every version measured from the preview Satoshi sent to a few cypherpunks in November 2008 to his last commit on December 15th 2010: it looks like one consistent hand. Every release stays between 0.021 and 0.163 from v0.1.0 (the release he announced on January 8th 2009) on a scale where the closest Satoshi suspect sits at 1.02. Of the 189 commits up to his last one, 159 are his, and the code other people wrote (between 4.8% and 9.6% of what was there when he left) follows his style so closely that the numbers can't tell it apart. What did change, and a lot, is what the code does: a Windows-only program became a Linux, Mac and headless server program, it got checkpoints, disabled opcodes and an overflow fix, three other people got commit access, and his commit messages credit patches, fixes or bug reports from more than a dozen people by name.
Everything below comes from the code itself: the four preview files Ray Dillinger posted on bitcointalk in December 2013, the v0.1.0 to v0.1.5 archives, and the SourceForge SVN history, which survives commit by commit in the bitcoin/bitcoin repository (each imported commit still carries its trunk@ revision number). Every code snippet is copied line for line and links to the exact file and lines it came from, and where I speculate, I say so.
How Do You Measure a Programmer's Style?
The tool is a style distance, the same one behind every number in the code fingerprint chapter. It counts 29 habits in a code base: 13 about layout (tabs or spaces, where the braces go, how long the lines run, whether short functions fit on one line), 8 about naming (Satoshi's Hungarian prefixes like nValue, fSpent and strAccount, but also snake_case, camelCase and m_ members) and 8 about comments and idioms (// or /* */, how often printf shows up, goto, #define). Each habit is scaled by how much it varies across a frozen pool of eight code bases (Satoshi's two earliest versions, Wei Dai's Crypto++, Hal Finney's RPOW, Adam Back's hashcash, Paul Le Roux's E4M, Mixmaster and Jed McCaleb's code), and the differences are rolled into one number.
Here's how to read it: 0 means the habits are identical, and 1 means that, habit for habit, two code bases differ about as much as the programs in that pool typically differ from each other. The closest suspect, Wei Dai's Crypto++, scores 1.02 against Bitcoin v0.1.0, Hal Finney 1.41, Adam Back 1.58 and Gavin Andresen's pre-Bitcoin C++ 2.59 (every row is in the suspects table). Why bother with a number instead of eyeballing the code? Because it's reproducible (the scripts and every file are in the research mirror), it's frozen (adding a new suspect can't move anybody's old score), and it puts everyone on the same scale, Satoshi included.
Did Satoshi's Coding Style Change Over Time?
Barely. Here's every version I could get the full source for, measured against v0.1.0, with Wei Dai at the bottom for scale:
From January to February 2009 the style barely moves (0.021 and 0.026). The biggest single step comes with v0.2.0 in December 2009, the first release with a Linux version, at 0.111, and from there it drifts up slowly to 0.163 with v0.3.19, still more than six times closer to v0.1.0 than Wei Dai is. The November 2008 preview, compared with the same four files in v0.1.0, sits at 0.108, in the same band. Nothing jumps the way I'd expect if a new author had taken over a release.
The commit log points the same way. Up to Satoshi's last commit (SVN r202), 189 commits landed on trunk:
Gavin's 16 commits all landed in the last two months, Martti's 13 between August 2009 and February 2010, and Laszlo's single commit was a small fix for the Mac build. Counting the lines still in the code when Satoshi left, others wrote between 4.8% and 9.6% of it (the range depends on how much of the patches Satoshi committed in other people's names was really theirs). And when I measure those lines on their own, they can't be told apart from Satoshi's (once a habit counted on just five ++ operators is left out), and in November 2010 he even asked everyone in writing to stick to the existing style. So the variances are real, but they're small, gradual and explained by the code growing up, not by a change of author.
(If you've read an earlier version of this article, you might remember 0.295 as “Satoshi against himself”. That number compared the 4 preview files with all 22 files of v0.1.0, so it mostly measured the different mix of files rather than a change in Satoshi; file for file it's 0.108. The details are in the method notes.)
How Did Bitcoin's Code Change From v0.1 to Satoshi's Last Commit?
Here's every version I could get the full source for, measured exactly like the suspects. “Lines” counts only the C++ files written by Satoshi and, later, his contributors; borrowed libraries (Wei Dai's SHA-256, OpenBSD's strlcpy, JSON Spirit, a subset of Crypto++ 5.6.0 and tcatm's 4-way SHA-256) and the generated interface code are counted separately. Release dates are Satoshi's announcements for v0.1.x and the SVN commit for later versions (UTC).
| Version | Date | Source | Files | Lines | Borrowed or generated lines | Builds | Distance to v0.1.0 |
|---|---|---|---|---|---|---|---|
| November 2008 preview | November 2008 | four files Ray Dillinger posted on December 23rd 2013 | 4 | 5,005 | none in the 4 files | not known | 0.108 (same 4 files) |
| v0.1.0 | January 8th 2009 | release archive | 22 | 16,563 | 3,257 | Windows | 0.000 |
| v0.1.3 | January 12th 2009 | release archive | 22 | 16,644 | 3,257 | Windows | 0.021 |
| v0.1.5 | February 4th 2009 | SVN r1, uploaded August 30th 2009 | 22 | 16,831 | 3,279 | Windows | 0.026 |
| v0.2.0 | December 14th 2009 | SVN r49 | 22 | 18,816 | 3,264 | Windows, Linux | 0.111 |
| v0.3.0 | July 4th 2010 | SVN r97 | 24 | 18,961 | 4,256 | Windows, Linux, Mac, bitcoind | 0.128 |
| v0.3.10 | August 15th 2010 | SVN r134 | 25 | 19,779 | 9,436 | Windows, Linux, Mac, bitcoind | 0.140 |
| v0.3.19 | December 13th 2010 | SVN r201 | 25 | 22,418 | 9,491 | Windows, Linux, Mac, bitcoind | 0.163 |
| r202 (his last commit) | December 15th 2010 | SVN r202 | 25 | 22,450 | 9,491 | Windows, Linux, Mac, bitcoind | 0.161 |
Two things jump out. First, the hand-written code only grew by about a third in two years (16,563 to 22,450 lines), while borrowed library code went from 731 lines to almost 8,000, mostly for JSON-RPC (JSON Spirit, r58, February 10th 2010) and faster mining (Crypto++ in r114 and tcatm's SSE2 SHA-256 in r131, July and August 2010). Second, the program slowly moved away from its Windows roots. It was never an MFC program, by the way: v0.1.0 already used wxWidgets (a cross-platform interface toolkit), it just only shipped for Windows, with a MinGW makefile and one for Microsoft's compiler. Calls into wxWidgets then fell from 41.36 to 24.61 per 1,000 lines as the node logic was pulled away from the interface for bitcoind, and Boost went from 1.8 to 6.5 per 1,000 lines. And yet the style distance only crept from 0.021 to 0.161, with the biggest single step (0.085) between v0.1.5 and v0.2.0, the release that added Linux.
Satoshi's own announcements tell the same story: v0.2 (December 16th 2009) was the first with a Linux version, which he credited to Martti Malmi, and for v0.3 he promised 32-bit and 64-bit Linux builds, a bitcoind with JSON-RPC and a Mac release built by Laszlo.
Satoshi's Code, Side by Side
Eight pairs, oldest first. The left column is the before, the right column is the after, and the line under each one links to the exact file and lines (on GitHub for the SVN commits, and to the copy in my research mirror for the preview and v0.1.0). I've only normalized line endings; nothing else is touched.
static const unsigned int MAX_SIZE = 0x02000000;
static const int64 COIN = 1000000;
static const int64 CENT = 10000;
static const int64 TRANSACTIONFEE = 1 * CENT; /// change this to a user options setting, optional fee can be zero
///static const unsigned int MINPROOFOFWORK = 40; /// need to decide the right difficulty to start with
static const unsigned int MINPROOFOFWORK = 20; /// ridiculously easy for testing static const unsigned int MAX_SIZE = 0x02000000;
static const int64 COIN = 100000000;
static const int64 CENT = 1000000;
static const int COINBASE_MATURITY = 100;
static const CBigNum bnProofOfWorkLimit(~uint256(0) >> 32); In the preview, one coin was 1,000,000 units, the fee was hardcoded at one cent and the difficulty was set “ridiculously easy for testing”, with Satoshi's /// notes to himself. By v0.1.0, a coin is 100,000,000 units (the satoshi as we know it today), the fee had become a user setting (nTransactionFee, which the options dialog in ui.cpp edits) and the testing difficulty was replaced by bnProofOfWorkLimit. That's a programmer turning a prototype into a release, and it's the most important change on this whole page that the style distance can't see.
void print() const
{
printf("COutPoint(%s, %d)", hash.ToString().substr(0,6).c_str(), n);
} string ToString() const
{
return strprintf("COutPoint(%s, %d)", hash.ToString().substr(0,6).c_str(), n);
}
void print() const
{
printf("%s\n", ToString().c_str());
} Across main.h, the preview's print() methods, which wrote straight to the console, became ToString() methods that return a string, with print() kept as a one-line wrapper. It's a small refactor, but it's exactly what the distance picks up: fewer printf calls and more one-line bodies. My guess (and it's only a guess) is that v0.1.0 needed those strings for its interface and debug log: its ui.cpp calls ToString() on 10 lines, and none of the four preview files contains interface code.
// Wrapper to automatically initialize critical section
// Could use wxCriticalSection for portability, but it doesn't support TryEnterCriticalSection
class CCriticalSection
{
protected:
CRITICAL_SECTION cs;
public:
char* pszFile;
int nLine;
explicit CCriticalSection() { InitializeCriticalSection(&cs); }
~CCriticalSection() { DeleteCriticalSection(&cs); }
void Enter() { EnterCriticalSection(&cs); }
void Leave() { LeaveCriticalSection(&cs); }
bool TryEnter() { return TryEnterCriticalSection(&cs); }
CRITICAL_SECTION* operator&() { return &cs; }
}; // Wrapper to automatically initialize critical section
// Could use wxCriticalSection for portability, but it doesn't support TryEnterCriticalSection
class CCriticalSection
{
#ifdef __WXMSW__
protected:
CRITICAL_SECTION cs;
public:
explicit CCriticalSection() { InitializeCriticalSection(&cs); }
~CCriticalSection() { DeleteCriticalSection(&cs); }
void Enter() { EnterCriticalSection(&cs); }
void Leave() { LeaveCriticalSection(&cs); }
bool TryEnter() { return TryEnterCriticalSection(&cs); }
#else
protected:
wxMutex mutex;
public:
explicit CCriticalSection() { }
~CCriticalSection() { }
void Enter() { mutex.Lock(); }
void Leave() { mutex.Unlock(); }
bool TryEnter() { return mutex.TryLock() == wxMUTEX_NO_ERROR; }
#endif
public:
char* pszFile;
int nLine;
}; v0.1.0 locked its threads with raw Windows calls, and the comment shows Satoshi already knew why he couldn't simply use wxWidgets for it. On October 29th 2009, getting ready for the Linux port with Martti Malmi, he wrapped the Windows code in #ifdef __WXMSW__ and mapped everything else to wxMutex, then explained it to Malmi less than an hour after the commit: “They just mapped it to wxMutex on non-MSW, which does have TryEnter, so that mapped in perfectly.” (email, 29 October 2009, 06:38 UTC). By his last commit, the non-Windows half had moved again, to Boost's interprocess_recursive_mutex. Same class, same names, same braces, and the old comment about wxCriticalSection stayed on top of the new code.
// Check proof of work
if (nBits != GetNextWorkRequired(pindexPrev))
return error("AcceptBlock() : incorrect proof of work");
// Write block to history file
if (!CheckDiskSpace(::GetSerializeSize(*this, SER_DISK)))
return error("AcceptBlock() : out of disk space"); // Check proof of work
if (nBits != GetNextWorkRequired(pindexPrev))
return error("AcceptBlock() : incorrect proof of work");
// Check that the block chain matches the known block chain up to a checkpoint
if (pindexPrev->nHeight+1 == 11111 && hash != uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d"))
return error("AcceptBlock() : rejected by checkpoint lockin at 11111");
if (pindexPrev->nHeight+1 == 33333 && hash != uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6"))
return error("AcceptBlock() : rejected by checkpoint lockin at 33333");
if (pindexPrev->nHeight+1 == 68555 && hash != uint256("0x00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a"))
return error("AcceptBlock() : rejected by checkpoint lockin at 68555");
// Write block to history file On July 17th 2010, v0.3.2 hardcoded the hashes of blocks 11111, 33333 and 68555, so the chain before them couldn't be rewritten, as Satoshi put it, “even if someone does have more than 50% of the network's CPU power”. He added: “I'll probably put a checkpoint in each version from now on.” (bitcointalk, 17 July 2010, 21:35 UTC). It's also worth noting the form: the same if, return error() pattern he used everywhere, with the reason spelled out in the error string.
else
pc = pend;
}
break;
case OP_RETURN:
{
pc = pend;
}
break; else
return false;
}
break;
case OP_RETURN:
{
return false;
}
break; Before v0.3.6, OP_RETURN (and a failed OP_VERIFY, at the top of each column) jumped to the end of the script with pc = pend, so the script stopped early and whatever was on the stack decided the result. After it, both simply fail. On July 29th 2010 Satoshi asked everyone to upgrade to 0.3.6 ASAP, because bogus transactions could be displayed as accepted, yet the commit that carries the fix is titled “reverted makefile.unix wx-config -- version 0.3.6”. Notice the indentation too: every case moved four spaces to the right, because the whole interpreter loop was wrapped in a new try block in the same commit.
opcodetype opcode;
valtype vchPushValue;
if (!script.GetOp(pc, opcode, vchPushValue))
return false;
if (vchPushValue.size() > 5000)
return false;
if (opcode > OP_16 && nOpCount++ > 200)
return false;
if (fExec && opcode <= OP_PUSHDATA4)
stack.push_back(vchPushValue); opcodetype opcode;
valtype vchPushValue;
if (!script.GetOp(pc, opcode, vchPushValue))
return false;
if (vchPushValue.size() > 520)
return false;
if (opcode > OP_16 && nOpCount++ > 200)
return false;
if (opcode == OP_CAT ||
opcode == OP_SUBSTR ||
opcode == OP_LEFT ||
opcode == OP_RIGHT ||
opcode == OP_INVERT ||
opcode == OP_AND ||
opcode == OP_OR ||
opcode == OP_XOR ||
opcode == OP_2MUL ||
opcode == OP_2DIV ||
opcode == OP_MUL ||
opcode == OP_DIV ||
opcode == OP_MOD ||
opcode == OP_LSHIFT ||
opcode == OP_RSHIFT)
return false;
if (fExec && opcode <= OP_PUSHDATA4)
stack.push_back(vchPushValue); On August 15th 2010 at 21:05 UTC, in a commit called “misc changes”, Satoshi switched off OP_CAT and 14 other opcodes, cut the largest allowed push from 5,000 bytes to 520 and limited script numbers to 4 bytes. Both the 520 and the disabled list are still in Bitcoin Core today (MAX_SCRIPT_ELEMENT_SIZE in script.h, and the same list in interpreter.cpp, which cites CVE-2010-5137), which is why BIP 347 and the OP_CAT debate I had with Andrew Poelstra in S15 E17 exist at all.
bool CheckTransaction() const
{
// Basic checks that don't depend on any context
if (vin.empty() || vout.empty())
return error("CTransaction::CheckTransaction() : vin or vout empty");
// Check for negative values
foreach(const CTxOut& txout, vout)
if (txout.nValue < 0)
return error("CTransaction::CheckTransaction() : txout.nValue negative");
bool CheckTransaction() const
{
// Basic checks that don't depend on any context
if (vin.empty() || vout.empty())
return error("CTransaction::CheckTransaction() : vin or vout empty");
// Check for negative or overflow output values
int64 nValueOut = 0;
foreach(const CTxOut& txout, vout)
{
if (txout.nValue < 0)
return error("CTransaction::CheckTransaction() : txout.nValue negative");
if (txout.nValue > MAX_MONEY)
return error("CTransaction::CheckTransaction() : txout.nValue too high");
nValueOut += txout.nValue;
if (nValueOut > MAX_MONEY)
return error("CTransaction::CheckTransaction() : txout total too high");
}
This is the fix for the overflow bug in block 74638. At 20:38 UTC, Satoshi told the mailing list not to trust any transaction after 17:05 UTC (block 74638), and he committed this fix less than an hour later, thirty minutes after the opcode commit above. Before, CheckTransaction() only rejected negative outputs; after, every output and the running total have to stay under MAX_MONEY, a new constant of 21 million coins. v0.3.10 shipped the patch the same night. Written under pressure, it's still pure Satoshi: Allman braces, nValueOut Hungarian naming and a descriptive error string.
// Minimum confirmations
int nMinDepth = 1;
if (params.size() > 1)
nMinDepth = params[1].get_int();
// Tally
int64 nAmount = 0;
CRITICAL_BLOCK(cs_mapWallet)
{
for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
if (wtx.IsCoinBase() || !wtx.IsFinal())
continue;
foreach(const CTxOut& txout, wtx.vout)
if (txout.scriptPubKey == scriptPubKey)
if (wtx.GetDepthInMainChain() >= nMinDepth)
nAmount += txout.nValue;
}
} void ListAccountTransactions(CWalletDB& walletdb, const string& strAccount, int nMinDepth, multimap<int64, Object>& ret)
{
set<CScript> setPubKey;
GetAccountPubKeys(strAccount, setPubKey);
CRITICAL_BLOCK(cs_mapWallet)
{
// Wallet: generate/send/receive transactions
for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
if (!wtx.IsFinal())
continue;
int64 nGenerated, nReceived, nSent, nFee;
wtx.GetAccountAmounts(strAccount, setPubKey, nGenerated, nReceived, nSent, nFee); Both functions were still in the code at Satoshi's last commit, and git blame says every line on the left comes from Satoshi's r60 (February 12th 2010, the first JSON-RPC draft) and every line on the right from Gavin Andresen's r193 (November 30th 2010). Same CRITICAL_BLOCK macro, same iterator loop, same wtx naming, same early continue. A week before Gavin's commit, Satoshi had checked in a file called coding.txt (SVN r189, November 23rd 2010), which starts like this:
Please be consistent with the existing coding style.
Block style:
bool Function(char* psz, int n)
{
// Comment summarising what this section of code does
for (int i = 0; i < n; i++)
{
// When something fails, return early
if (!Something())
return false;
...
}
// Success return is usually at the end
return true;
} So when Gavin's code looks like Satoshi's, it's because Satoshi asked for it in writing. That's the “inherited conventions” effect from the code chapter, caught in the act.
Who Else Wrote Bitcoin's Code Before Satoshi Left?
The SVN log is the closest thing we have to a sign-in sheet. Up to Satoshi's last commit (r202), 189 commits landed on trunk: 159 by s_nakamoto, 16 by gavinandresen, 13 by sirius-m and one by laszloh. Nobody else had commit access, so everyone else's code went through Satoshi, and he usually said so in the commit message.
- Martti Malmi (sirius-m)
- 13 commits, from r1 on August 30th 2009 (he uploaded v0.1.5 as the very first revision, seven weeks before Satoshi's own first commit, r15) to r56 on February 4th 2010: the tray icon, autostart, the Windows installer script and the first Linux replacements for Windows headers (r23, October 31st 2009). Satoshi credited him with the Linux version in the v0.2 announcement, and Martti remembered it the same way when I interviewed him in S16 E12: “And also worked on the Linux port, although Satoshi did some of that as well.” (00:11:40). His last commit, an IPC feature, was reverted by Satoshi six days later in r57, “going in different direction with boost::asio and JSON-RPC”.
- Gavin Andresen (gavinandresen)
- Patches through Satoshi from July 9th 2010 (Linux autostart, r101), then JSON-RPC HTTP authentication (r109, v0.3.3), standard JSON-RPC error codes and
backupwallet(r147), a clean shutdown on SIGTERM (r149), the test network (r168) and a multiple-instance check (r170). His own commit access starts with r165 on October 11th 2010 (-rpcssl), and his 16 commits before Satoshi's last one include the account-based RPC calls (r188 and r193) andIsStandard()(r197, December 7th 2010), the rule that a node only relays transaction types it understands. - Laszlo Hanyecz (laszloh)
- The Mac port: build fixes in r76 (May 19th 2010, v0.2.8),
makefile.osxand build instructions in r77, a fix that runs the mining threads at idle priority on Linux in r99, and one direct commit (r123, August 4th 2010): “correct typo for mac compile, update makefile to use llvm”. GPU mining never went into the official client before Satoshi left: there's no GPU code in the tree at r202, and when he checked in his redesign of m0mchil'sgetworkfor external miners in November 2010, Satoshi explained why: “GPU programming is immature and hard to compile, and I didn't want to add additional dependencies to the build.” (bitcointalk, 23 November 2010, 19:50 UTC). - Hal Finney
- Never committed a line. His contribution was the very first bug reports: he ran v0.1.0 in its first days, it crashed, and the emails show Satoshi debugging with him and sending him a fix for the “select failed” error on January 11th 2009, which went out to everyone as v0.1.3 the next day. That's the smallest step in the table (0.021).
- Credited by name in Satoshi's own commits
- madhatter (FreeBSD header changes, r51), Lachesis (Base64 newlines, r110), tcatm (the cached SHA-256 state idea, r113, and the 4-way SSE2 SHA-256 in
sha256.cpp, whose header carries a 2010 copyright line for Nils Schneider), BlackEye (the Crypto++ alignment problem, r114), Fredrik Roubert (a simplermakefile.unix, r118), jgarzik (a build fix in r129 and the initial download speedup in r195), teknohog (non-Intel builds, r152), dkaparis (build fixes, r159 and r164), Dean Gores (bug fixes, r173), m0mchil (a bug report in r102, and the external miner idea behindgetwork) and Martti himself (a 64-bit memory bug he found, r74), plus the translators.
So how much of the code was Satoshi's? I've counted it two ways, only in the hand-written C++ files and ignoring whitespace-only changes (otherwise the August 29th 2010 line-ending change in r146 would count as Satoshi rewriting everything). The first row counts every line added or removed between r2 and r202; the second asks git blame who wrote each line still there at r202, counting r1 as Satoshi's because it's his v0.1.5 release.
| Measure | Satoshi's own commits | Satoshi's commits crediting someone | Commits by others |
|---|---|---|---|
| Lines changed, r2 to r202 (22,363) | 18,478 (82.6%) | 1,924 (8.6%) | 1,961 (8.8%): Gavin 1,367, Martti 592, Laszlo 2 |
| Lines still there at r202 (22,450) | 20,285 (90.4%), of which 12,426 from v0.1.5 | 1,085 (4.8%) | 1,080 (4.8%): Gavin 980, Martti 99, Laszlo 1 |
Depending on how much of each credited commit was really the other person's work (the log doesn't say, and several of those commits also contain Satoshi's own changes), between 4.8% and 9.6% of the code at Satoshi's last commit came from someone else. Until v0.2.0, the only other hand was Martti's; the v0.3.10 window (July and August 2010) had the most credited work, and all of Gavin's direct commits fall in the last two months.
I've also measured the style of those lines. Since they're fragments rather than whole files (no file headers, fewer function signatures), their distances aren't comparable to the table above: even Satoshi's own lines score between 0.47 and 0.67 against his full v0.1.0.
| Lines still in the code at r202 | Lines | Distance to v0.1.0 |
|---|---|---|
| Satoshi's lines written for v0.2.0 (r2 to r49) | 2,324 | 0.669 |
| Satoshi's lines written for v0.3.0 (r50 to r97) | 2,329 | 0.614 |
| Satoshi's lines written for v0.3.10 (r98 to r134) | 875 | 0.656 |
| Satoshi's lines written after v0.3.10 (r135 to r202) | 2,331 | 0.662 |
| All of the above together | 7,859 | 0.466 |
| Satoshi's commits that credit someone else | 1,085 | 0.514 |
| Commits by Gavin Andresen, Martti Malmi and Laszlo Hanyecz | 1,080 | 1.803 |
Satoshi's lines from four different periods are all about equally far from v0.1.0 (0.61 to 0.67), which is what one consistent hand looks like. The lines by Gavin, Martti and Laszlo look much farther (1.80), but most of that gap comes from one habit counted on a tiny sample: whether you write ++it or it++, which shows up only 5 times in their 1,080 lines. Leave that habit out and their lines sit 0.596 from Satoshi's SVN lines, about as far as Satoshi's own lines for v0.2.0 (2009) sit from the ones he wrote after v0.3.10 (late 2010) (0.586). In other words, on style alone you can't tell them apart, which is exactly what coding.txt asked for.
Why Did Satoshi's Code Change? My Theories
- 1. The code grew up (the strongest theory)
- The big changes of 2010 are about what the code does, and each one followed a real problem or a real fear: checkpoints on July 17th, the script fix on July 29th, the disabled opcodes and the overflow fix on August 15th, the alert system on August 25th and DoS limits on December 12th (r199). All of them were written in the same
if,return error()style he used in 2009. Verdict: this explains almost everything that changed in what Bitcoin does, and nothing about the style, which barely changed. - 2. Windows to everywhere (strong, for the structure)
- Satoshi resisted a Linux port in August 2009 (he thought autorun might bring 300% more nodes and Linux maybe 3%) and warned Malmi in October that it would double his testing and building work, then did it anyway, along with
bitcoindand the Mac build. Platform#iflines went from 33 in v0.1.0 to 88 at r202, even though he'd written: “I want to avoid #ifdefing up the code if we can.” (email, 27 October 2009, 04:45 UTC). The interface was split out (init.cpp,noui.h), and wxWidgets gave way to Boost. Verdict: this explains the new files and the biggest single step in the distance (v0.1.5 to v0.2.0), but the step is still small. - 3. New hands (real, but small)
- Others wrote between 4.8% and 9.6% of the final code, and their style can't be told apart from his once the tiny
++sample is left out. Verdict: contributors changed what the code does more than how it looks, and they can't explain the gap between the preview and v0.1.0 either: the SVN log, the only record of who touched what, starts with v0.1.5, so there's nothing that would let me pin the changes between the preview and v0.1.0 on anyone but Satoshi. - 4. More than one Satoshi (no support in the code)
- The whole releases stay within 0.163 of v0.1.0 for two years, and Satoshi's own lines from four periods are equally far from it. A team writing under one name would probably show more variation, unless it followed a strict house style, and Gavin's code shows that a house style can do exactly that. Verdict: the code doesn't support it, but style alone can't rule it out either.
- 5. A deliberate change of style (the weakest)
- The drifts I can measure are small and gradual: one-line bodies fell from 23.83 to 15.44 per 1,000 lines as the code filled up with long functions. Three weeks before his last commit, he wrote
coding.txt, asking everyone to stay consistent with the existing style. Verdict: I can't find any sign of it in the code, and it's hard to square with a programmer who asks everyone to copy the style he already had.
If I had to bet, the small gap between the preview and v0.1.0 is a pre-release cleanup (Satoshi turning a test build into a product: print() into ToString(), test coins into real ones), and what happened after January 2009 is the story of one very consistent programmer hardening his code under fire, porting it to platforms he didn't want to support and, right before he left, teaching other people to write like him. Admittedly, that makes for a worse movie than three anonymous cypherpunks taking turns at the keyboard.
How I Measured It
- Sources. The November 2008 preview is the copy in XertroV/bitcoin_src1 (commit ad627bb2), v0.1.0 is jhuboo/satoshi (commit 6ac25d1e), v0.1.3 is trottier/original-bitcoin, and everything from v0.1.5 (SVN r1) to r202 comes from the git import of the SourceForge SVN trunk in bitcoin/bitcoin, where each commit keeps its
git-svn-id ... trunk@Nline. The preview and v0.1.0 files are also in my research mirror. - Distance. The same three scripts as the rest of the article (
style_metrics.py,extra_metrics.pyandsimilarity.pyfrom the mirror), unchanged, with the same frozen pool, so the run still gives 0.295 for the four preview files against all of v0.1.0 and 1.023 for Wei Dai. Left out of every version:sha.cpp/sha.h,sha256.cpp,strlcpy.h,json/,cryptopp/and the generateduibase.cpp/uibase.h. - The 0.295. The earlier “Satoshi against himself” figure compares the four preview files (
main.cpp,main.h,node.cppandnode.h, 5,005 lines) with the 22 files of v0.1.0 (16,563 lines). Almost half of it (47%) comes from one habit, one-line function bodies like{ return x; }(4.53 per 1,000 lines in the preview against 23.83 in v0.1.0), which mostly live in headers such asuint256.h,serialize.handbignum.hthat aren't among the preview files. Against the same four files in v0.1.0 (main.cpp,main.h,net.cppandnet.h, wherenodebecamenet), it's 0.108. The 0.295 stays in the ranking because it's the published, reproducible control. - Who wrote what.
git log -w --numstatover the 189 trunk commits up to r202, grouped by SVN author and by whether Satoshi's commit message credits someone else's code or patch by name (20 commits do; thanks for bug reports, alignment tips and translations don't count), andgit blame -wat r202 for the lines still there. An SVN author is the person who committed, not necessarily the one who wrote it, which is why the credited commits get their own column. - Limits. This is style, not identity. Small samples (like the 1,080 lines by others) are noisy, and fragment distances aren't comparable to whole-file ones.
- Who did the measuring. As with the rest of the article, an AI research assistant (Grok Bot) collected the sources, ran the scripts and git commands and checked every snippet against its file, and I've written up what it found. The numbers are in a CSV (CC BY 4.0).