Skip to content

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.

VisionColab TeamSoftware engineering & AI 4 min read
Smart contract code block protected by a shield with warning markers on vulnerable lines

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.

IDVulnerabilityWhat goes wrongMain defense
SC01Access control vulnerabilitiesSensitive functions can be called by anyone, or roles are set up incorrectlyExplicit role checks on every privileged function; multi-signature admin wallets
SC02Price oracle manipulationAn attacker distorts the price data a contract relies onUse robust, decentralized price feeds and time-weighted prices; avoid single-pool spot prices
SC03Logic errorsThe code does what was written, not what was intendedClear specifications, thorough tests and independent review
SC04Lack of input validationUnexpected values break assumptionsValidate every parameter and reject invalid states early
SC05Reentrancy attacksAn external call re-enters the contract before its state is updatedChecks-effects-interactions pattern and reentrancy guards
SC06Unchecked external callsA failed call is ignored and the contract continues as if it succeededAlways check return values; use well-tested libraries
SC07Flash loan attacksHuge borrowed sums are used within one transaction to exploit other weaknessesDesign so that no single-transaction state can be abused; protect oracles
SC08Integer overflow and underflowNumbers wrap around their limitsUse Solidity 0.8 or later, which checks arithmetic by default; review any unchecked blocks
SC09Insecure randomnessValues like block timestamps are predictable or influenceableUse a verifiable randomness service rather than on-chain values
SC10Denial of serviceA contract can be blocked, for example by unbounded loops or a failing recipientAvoid 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

  1. Write a specification that states exactly who can do what, and what must never happen.
  2. Use audited libraries such as OpenZeppelin for tokens, access control and guards instead of writing your own.
  3. Test thoroughly: unit tests, fuzz testing with tools such as Foundry or Echidna, and invariant tests for rules that must always hold.
  4. Run static analysis with tools such as Slither on every change.
  5. Deploy to a test network first and run realistic scenarios.
  6. Get an independent audit before mainnet launch, and fix every finding before deploying.
  7. 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.

Have a project in mind?

Share your goals and constraints. We will suggest a realistic scope and the right technology approach.