Blockchain & Web3
Smart Contract Security: Common Vulnerabilities and How to Prevent Them
The most common smart contract vulnerabilities, based on the OWASP Smart Contract Top 10, with practical defenses, a code example and a pre-launch security checklist.

In shortMost smart contract losses come from a small set of mistakes: weak access control, manipulated price data, flawed business logic, missing input checks and unsafe external calls. Because deployed contracts are hard to change and often hold real value, security has to be designed in before launch, not patched afterwards.
This guide walks through the common vulnerability types using the OWASP Smart Contract Top 10 as a framework. It explains each risk in plain terms and gives the defense a development team should apply.
Why smart contract security is different
- Code is public. Anyone can read a deployed contract and look for weaknesses.
- Code holds value directly. A bug can let an attacker move funds in a single transaction.
- Changes are hard. Contracts cannot simply be patched. Upgrades need patterns planned in advance, and those patterns bring their own risks.
- Contracts call each other. Your contract may be safe on its own but vulnerable through a token, oracle or protocol it depends on.
The OWASP Smart Contract Top 10 (2025)
The 2025 edition, archived on the OWASP Smart Contract Security site, lists these categories. OWASP has since published a 2026 edition that adds categories such as proxy and upgradeability vulnerabilities, so check the current list when planning an audit.
| ID | Vulnerability | What goes wrong | Main defense |
|---|---|---|---|
| SC01 | Access control vulnerabilities | Sensitive functions can be called by anyone, or roles are set up incorrectly | Explicit role checks on every privileged function; multi-signature admin wallets |
| SC02 | Price oracle manipulation | An attacker distorts the price data a contract relies on | Use robust, decentralized price feeds and time-weighted prices; avoid single-pool spot prices |
| SC03 | Logic errors | The code does what was written, not what was intended | Clear specifications, thorough tests and independent review |
| SC04 | Lack of input validation | Unexpected values break assumptions | Validate every parameter and reject invalid states early |
| SC05 | Reentrancy attacks | An external call re-enters the contract before its state is updated | Checks-effects-interactions pattern and reentrancy guards |
| SC06 | Unchecked external calls | A failed call is ignored and the contract continues as if it succeeded | Always check return values; use well-tested libraries |
| SC07 | Flash loan attacks | Huge borrowed sums are used within one transaction to exploit other weaknesses | Design so that no single-transaction state can be abused; protect oracles |
| SC08 | Integer overflow and underflow | Numbers wrap around their limits | Use Solidity 0.8 or later, which checks arithmetic by default; review any unchecked blocks |
| SC09 | Insecure randomness | Values like block timestamps are predictable or influenceable | Use a verifiable randomness service rather than on-chain values |
| SC10 | Denial of service | A contract can be blocked, for example by unbounded loops or a failing recipient | Avoid unbounded loops; let users withdraw funds themselves |
Example: preventing reentrancy
Reentrancy is one of the best-known smart contract bugs. The vulnerable version below sends funds before setting the user’s balance to zero, so a malicious contract receiving the funds can call withdraw again before the balance changes.
// Vulnerable: external call happens before the state update
function withdraw() external {
uint256 amount = balances[msg.sender];
(bool ok, ) = msg.sender.call{value: amount}("");
require(ok, "Transfer failed");
balances[msg.sender] = 0;
}
// Safer: checks, then effects, then interactions,
// plus a reentrancy guard (for example OpenZeppelin's ReentrancyGuard)
function withdraw() external nonReentrant {
uint256 amount = balances[msg.sender];
require(amount > 0, "Nothing to withdraw");
balances[msg.sender] = 0;
(bool ok, ) = msg.sender.call{value: amount}("");
require(ok, "Transfer failed");
}The same principle, update your own state before talking to anything external, prevents a whole class of bugs. The Solidity documentation’s security considerations page covers it and other pitfalls in more depth.
Upgradeable contracts bring their own risks
Proxy patterns let teams upgrade contract logic after deployment. They also create new failure points: storage layout clashes between versions, uninitialised implementation contracts, and upgrade keys held by a single person. If you use upgradeability, protect the upgrade function with a multi-signature wallet and a time delay, and test every upgrade against the existing storage layout.
A security process that works
- Write a specification that states exactly who can do what, and what must never happen.
- Use audited libraries such as OpenZeppelin for tokens, access control and guards instead of writing your own.
- Test thoroughly: unit tests, fuzz testing with tools such as Foundry or Echidna, and invariant tests for rules that must always hold.
- Run static analysis with tools such as Slither on every change.
- Deploy to a test network first and run realistic scenarios.
- Get an independent audit before mainnet launch, and fix every finding before deploying.
- Monitor after launch and consider a bug bounty, so researchers report issues to you rather than exploiting them.
Pre-launch checklist
- Every privileged function has an explicit access check.
- State is updated before any external call.
- All external call results are checked.
- No price comes from a single manipulable source.
- No loop can grow without limit.
- Admin and upgrade keys sit in a multi-signature wallet.
- An independent audit is complete and all findings are resolved.
Frequently asked questions
Is an audit enough to make a contract safe?
No single step is enough. An audit is a time-limited review. It works best on top of a clear specification, strong tests and static analysis, followed by monitoring after launch.
Does Solidity 0.8 remove overflow risk?
Solidity 0.8 and later revert on arithmetic overflow and underflow by default. The risk returns inside unchecked blocks and in precision or rounding errors, which still need careful review.
Do we need blockchain at all?
Often not. If one organization controls the data, a normal database with a well-designed API is simpler, cheaper and easier to secure. Our guide to API design best practices covers that route.
Building on blockchain?
VisionColab builds smart contracts and Web3 applications with security planned from the start, and connects them to web and mobile front ends. See our blockchain development services or book a free consultation.
Written by the VisionColab team
VisionColab designs and builds AI, web, mobile and cloud software for businesses. Our guides explain the decisions, costs and trade-offs involved in planning a software project.


