Module 16: Postmortems

The DAO (2016): When Code Was Law, and Then Wasn't

Chapter 3 of 12 · about 4 minutes

3.1 What it was

In 2016, a project called The DAO launched on Ethereum, which was barely a year old. It was designed as a decentralised venture fund: people sent ETH to a smart contract, received tokens, and could vote on which projects the fund would invest in. No company, no managers, just code.

It raised ETH worth roughly $150 million at the time, a substantial share of all ETH in existence, making it one of the largest crowdfunding efforts ever at that point.

People trusted it because the code was public, the idea was exciting, and the slogan of the moment was "code is law": whatever the smart contract allowed was, by definition, legitimate.

3.2 What happened

DateEvent
April to May 2016The DAO raises a large amount of ETH
Before June 2016Researchers publicly raise concerns about potential vulnerabilities
June 2016An attacker exploits a flaw in the withdrawal function, repeatedly withdrawing funds before the contract updated its balance, a type of bug called reentrancy
June 2016About a third of The DAO's ETH is moved into a separate contract controlled by the attacker, with a waiting period before it could be withdrawn
July 2016After intense debate, the Ethereum community adopts a hard fork that moves the affected funds to a recovery contract, letting investors reclaim their ETH
July 2016 onwardsA minority who rejected the fork continued the original chain, now known as Ethereum Classic

3.3 The reentrancy bug, simply

Imagine a cash machine that gives you money first and updates your balance afterwards. If you could press "withdraw" again in the split second before the balance updated, you'd get paid again from the same balance, repeatedly.

That's essentially what happened. The DAO's code sent ETH before updating the attacker's balance, and the attacker's contract called back into the withdrawal function again and again.

In numbers, a third of the roughly $150 million raised was about $50 million, drained into a separate contract the attacker controlled.

Chapter 3 · The DAO reentrancy bug

The DAO's withdraw function sent ether to the caller before updating the caller's recorded balance. A malicious contract used its receive function to call withdraw again before the first call finished, repeating the loop and draining funds while its balance still showed the original amount.

The DAO sent ether before updating its ledger, so a malicious contract could call back into the withdraw function again and again, draining funds before its balance was ever reduced. It is the classic reentrancy pattern.

3.4 Warning signs

Warning signModule
Brand new, unproven code holding a huge amount of valueModule 9, Chapter 13
Public warnings from security researchers before the attackModule 5, Chapter 2
A young ecosystem with immature tools and few auditsModule 9, Chapter 13
Enthusiasm and speed outrunning cautionModule 11, Chapter 2

3.5 Aftermath

The DAO hack shaped Ethereum and DeFi in lasting ways:

  1. A permanent split. Ethereum and Ethereum Classic still exist as separate chains (Module 1, Chapter 4).
  2. The "code is law" debate. The fork showed that communities can intervene in extreme cases, which some see as pragmatic and others as a betrayal of immutability (Module 3, Chapter 13).
  3. Security practices matured. Reentrancy became one of the first vulnerabilities that every smart contract developer learns to prevent, and audits became standard for serious projects.
  4. Regulatory attention. In 2017, the US SEC issued a report concluding that DAO tokens were securities, an early sign of how regulators might view token sales (Module 14, Chapter 7).

"So a single bug changed the whole ecosystem," said Node.

"And nearly every later smart contract hack is a variation on the same theme," said Hash. "New code, lots of money, not enough scrutiny."

3.6 Lessons

  1. New code holding large funds is risky, no matter how exciting the idea. Time without incident is one of the best safety signals (Module 9, Chapter 13).
  2. Read the security warnings. Researchers often flag risks before they're exploited.
  3. Size positions in new protocols to survive total loss (Module 9, Chapter 13).
  4. "Decentralised" doesn't mean "safe" (Module 1, Chapter 15).
  5. Don't count on a rescue. The DAO fork was exceptional; most hacked protocols never return funds.

3.7 Try it yourself

Find a DeFi protocol you're interested in. Look up how long its core contracts have held significant value, how many audits it has had, and whether it has a bug bounty. Then search for any public security concerns raised about it. Would you have invested in The DAO in 2016, knowing what you know now?

Key takeaways from this chapter

  1. The DAO was a 2016 smart contract investment fund on Ethereum that raised a large share of all ETH.
  2. A reentrancy bug let an attacker drain about a third of its funds.
  3. Ethereum hard-forked to return funds, creating the split with Ethereum Classic.
  4. Warning signs included new unproven code, large value, and public security concerns.
  5. The episode shaped audit practices, the "code is law" debate, and regulatory views of tokens.
  6. Treat new code holding large funds with caution and size positions to survive total loss.