Chapter 12. Smart Contract Security

Being able to write a smart contract is only one aspect of blockchain development. In Ethereum development, writing secure code that has been thoroughly tested and audited is essential. If your contract is hacked, you can’t easily take it down and fix it. Smart contract security is a serious issue and it can be very costly if a mistake is made.

In this chapter, we’re going to talk about smart contract security and various techniques we can use to secure our contracts.

Why Do We Need to Worry About Security?

One reason why having a secure smart contract is so important is that you cannot edit your contract once it’s on the blockchain. Once it’s out there, it’s not possible to patch a fix like we can in other types of software development. Ether can become stuck in the blockchain and impossible to release.

As an example, Parity’s Multi-Sig contract was hacked on November 6, 2017. A hacker found a small bug in the contract and disabled it. The entirety of the $300 million is lost forever.

In 2016 there was a large hack of the Decentralized Autonomous Organization (DAO), which was created as a decentralized investment fund. A group of unknown hackers found security issues that could be exploited in the contract. The contract should have first removed the ability to call the contract again, but instead it allowed users to recursively call the contract, and the hacker was able to retrieve 3.6 million ether.

Let’s discuss a few ways your smart contract ...

Get Hands-On Smart Contract Development with Solidity and Ethereum now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.