🕑 Estimated reading time: 5 minutes | Last updated: September 17, 2024
Smart contracts are programs on blockchains like Ethereum that hold and move funds automatically. Common vulnerabilities include reentrancy (exploited in The DAO hack of 2016), broken access control, oracle and price manipulation using flash loans, arithmetic errors, unsafe external calls, front-running and flawed upgrade mechanisms. Because deployed code is often immutable and transactions are irreversible, developers rely on secure design patterns, well-tested libraries, extensive testing and fuzzing, independent audits, bug bounties, timelocks and real-time monitoring.

In traditional finance, a bug in a banking app is embarrassing. In decentralised finance, a single bug in a smart contract can drain millions of dollars in seconds, with no way to reverse the transactions.
A smart contract is a program stored on a blockchain that executes automatically when its conditions are met. Smart contracts power decentralised exchanges, lending platforms, stablecoins, NFTs and much more, and together they hold tens of billions of dollars. Because their code is public, anyone can study it, including attackers. And because blockchain transactions are irreversible, a single exploitable bug can lead to an instant and permanent loss.
Below, we explain the most common categories of smart contract vulnerabilities and how developers defend against them. It is written for non-specialists as well as aspiring Web3 developers.
Table of Contents
Why Smart Contract Security Is Different
- Code is public, so attackers can analyse it at leisure.
- Contracts often hold funds directly, so bugs translate immediately into theft.
- Deployment is often permanent; fixing a bug may require migrating to a new contract.
- Contracts interact with each other in complex ways, creating unexpected attack paths.
- Attackers can use flash loans to borrow huge sums within a single transaction, amplifying the impact of small logic errors.
The Most Common Vulnerabilities
1. Reentrancy
A reentrancy bug occurs when a contract sends funds or calls another contract before updating its own records. The receiving contract can call back (“re-enter”) the original function repeatedly, withdrawing funds again and again before the balance is updated. The most famous example is The DAO hack in 2016, in which an attacker drained around 3.6 million ether from an early Ethereum investment fund. The response, a controversial hard fork to reverse the theft, split the community and created Ethereum Classic. Developers prevent reentrancy by following the “checks-effects-interactions” pattern, updating state before making external calls, and by using reentrancy guards.
2. Broken access control
Functions that should be restricted to administrators, such as minting tokens, upgrading contracts or withdrawing treasury funds, are sometimes left callable by anyone, or protected by flawed checks. In 2017, a user accidentally triggered a vulnerability in a shared Parity wallet library that made it possible to take ownership of the library and disable it, permanently freezing more than 500,000 ether held in dependent multi-signature wallets.
3. Oracle and price manipulation
Many decentralised finance (DeFi) protocols need price data. If a contract uses the spot price from a single, thinly traded market, an attacker can use a flash loan to distort that price temporarily, borrow or withdraw assets at the manipulated price, and repay the loan in the same transaction. Robust protocols use decentralised oracle networks, time-weighted average prices and sanity checks.
4. Arithmetic errors
Older versions of Solidity, Ethereum’s main programming language, allowed integers to overflow or underflow silently, turning a tiny balance into an enormous one. Since version 0.8, Solidity checks arithmetic by default, but rounding errors and precision issues in complex financial calculations still cause problems.
5. Unchecked external calls and unsafe token assumptions
Contracts that assume every token behaves according to the standard, or ignore return values from external calls, can be tricked by malicious or non-standard tokens.
6. Front-running and MEV
Pending transactions are visible before they are confirmed. Bots can see a large trade and insert their own transactions before and after it to profit, known as front-running or “sandwich” attacks, part of a broader phenomenon called maximal extractable value (MEV). Protocols mitigate this with slippage limits, commit-reveal schemes and private transaction channels.
7. Flawed upgrade and proxy patterns
Upgradeable contracts separate logic from storage using proxies. Mistakes in initialisation, storage layout or upgrade permissions can let attackers seize control or corrupt data.
8. Signature and replay issues
Contracts that accept signed messages must ensure signatures cannot be reused on another chain or for another purpose. Missing nonces or chain identifiers can allow replay attacks.
9. Business logic errors
Some of the most expensive exploits involve no classic “bug” at all, just a flaw in how a protocol’s rules interact. In March 2023, for example, lending protocol Euler Finance lost around $197 million through a logic flaw in a donation function, although the attacker later returned most of the funds.
10. Compiler and toolchain bugs
In July 2023, a bug in certain versions of the Vyper compiler disabled reentrancy protections in several Curve Finance pools, leading to losses. Even well-written code depends on the security of its tools.
How Developers Prevent Exploits
- Use battle-tested libraries, such as OpenZeppelin’s audited contracts, instead of writing standard components from scratch.
- Keep contracts simple and modular; complexity is the enemy of security.
- Test extensively, including unit tests, integration tests, fuzzing and invariant testing that checks properties that must always hold.
- Use static analysis tools to catch common issues early.
- Commission independent audits from reputable firms, ideally more than one for high-value contracts, and fix findings before launch.
- Run bug bounty programmes that reward researchers for responsibly disclosing vulnerabilities.
- Add safety controls, such as pause functions, rate limits, withdrawal caps and timelocks on upgrades, controlled by multi-signature wallets.
- Monitor in real time for suspicious transactions and have an incident response plan.
- Launch gradually, with deposit caps that increase as confidence grows.
What This Means for Users
An audit does not guarantee safety, but its absence is a red flag. Before depositing funds into a DeFi protocol, check its audit history, time in operation, total value locked, bug bounty and governance controls, and never invest more than you can afford to lose.
Test the assumptions your contracts rely on
Smart contracts promise trustless finance, but they replace trust in institutions with trust in code. The history of DeFi shows that code must be designed, tested and monitored with extreme care. For developers, security is not a final checklist item but a discipline that runs through every stage of the project.
Frequently Asked Questions
Can a hacked smart contract be fixed?
If it is upgradeable or pausable, the team may be able to stop further losses. Otherwise, users may need to migrate to a new contract. Stolen funds are rarely recovered.
What is a flash loan?
A loan that is borrowed and repaid within a single blockchain transaction, without collateral. It is legitimate, but attackers use it to amplify exploits.
How much does a smart contract audit cost?
It varies widely with code size and complexity, from a few thousand dollars for simple contracts to six figures for large protocols.