Smart Contract Security: A Practical Guide

Date
Category
Smart Contract
Reading time
5 min
Illustration of a smart contract protected by a shield, connected to code review, blockchain blocks, an attacker and an audit checklist

Picture a lending protocol that launches with two audit reports, full line coverage and a bug bounty. Eight months later it is drained through its price oracle. Both audit firms had the oracle adapter in the repository. Neither reviewed it, because the scope said "core contracts" and the adapter lived in another folder.

That story is a composite, but every part of it has happened somewhere. Smart contract security rarely fails because nobody looked. It fails because the looking was aimed at the wrong place, or stopped too early. This guide is about aiming: what breaks on each major chain, what each audit technique is good at, and the work a team should finish before and after an auditor sees the code. For the catalogue of classic bug classes, see the 7 most common DeFi vulnerabilities.

Where the money actually leaves

Exotic compiler bugs are rare. The expensive failures cluster around assumptions: who may call a function, where a price comes from, what happens to storage during an upgrade, and who holds the keys that can change any of it. Code that is locally correct can still be globally wrong when it trusts an input it should have verified.

So the most useful security question is "what does this contract believe, and who can make it believe something false?" Reentrancy guards are easy to add. Wrong beliefs are harder to find, because they live in the gap between the code and the design document, assuming there is a design document.

The chain changes the bug

Teams that move between ecosystems tend to carry the wrong checklist with them.

EVM and Solidity. Reentrancy still matters, though modern code mostly fails at its cross-function and read-only variants rather than the textbook withdraw loop. Upgradeable proxies bring storage layout collisions, uninitialized implementations and delegatecall into code nobody on the team wrote. Fee-on-transfer and rebasing tokens quietly break any accounting that assumes the amount sent equals the amount received.

Solana and Anchor. A Solana program receives the accounts it operates on from the caller. That one design choice produces most Solana-specific losses: missing owner checks, missing signer checks, a look-alike account passed where the program expected its own PDA. Rust's memory safety is irrelevant here. A perfectly memory-safe program can still accept a forged account. Anchor's constraints close most of these holes, until someone reaches for UncheckedAccount to save an afternoon.

Cosmos and CosmWasm. The actor model removes classic reentrancy, since messages a contract dispatches execute after it finishes. The risk moves elsewhere: reply handlers that assume a submessage succeeded, unbounded iteration over storage that becomes a gas-exhaustion denial of service as state grows, IBC packets that time out with nobody handling the refund, and migration rights held by an admin key nobody rotates.

What each audit method actually catches

A serious audit combines techniques because each one is blind somewhere.

  • Manual review finds logic that does what it says but not what the business needs. It is slow and only as good as the reader.
  • Static analysis flags known patterns across a codebase in minutes. It is cheap and noisy, and it has no idea what the code is for.
  • Fuzzing and invariant testing throw long random call sequences at the system and check that stated properties still hold, provided someone wrote the properties down.
  • Formal verification proves the code matches a specification. The proof is exactly as good as the specification, and specifications have bugs too.
  • Model-based review simulates the protocol's state machine or economics, which is where incentive problems and multi-step manipulations show up.
  • AI-assisted review widens coverage and speeds up triage, while producing confident false positives. Treat it as an extra reviewer, never the one that signs off. Attackers have the same tools, as our piece on AI-driven attacks in crypto explains.

Before you book the audit

Most of an audit's value is decided before it starts.

  1. Freeze the scope to a commit hash and list every contract, library and external integration it touches. Whatever you leave out, nobody checked.
  2. Write the invariants in plain language. "Total shares never exceed total assets" is a test, a fuzzing target and a review checklist in one sentence.
  3. Document every privileged role: what it can do, who holds it, and whether a timelock or multisig stands in front of it.
  4. Run the static analyzers yourself. Paying an auditor to report unused variables is an expensive way to run a linter.
  5. Add fork tests against real deployed dependencies. Mocks agree with whatever you assumed.

Many findings at this stage are design-level, the kind covered in common smart contract design mistakes, and they are far cheaper to fix in a workshop than in a report.

After the report

An audit describes one commit at one moment. Deployment adds configuration, keys and integrations the report never saw, and every upgrade resets the clock. The minimum post-launch setup is on-chain monitoring for unusual flows and privileged calls, a pause mechanism someone has actually tested, admin keys behind a multisig with a timelock, and an incident runbook that says who decides what at 3 a.m.

We monitor and support contracts for the first 30 days after deployment, because that is when configuration mistakes surface. Our smart contract audit page describes how we scope a review. Whoever does yours, start with the invariants document. It takes about a day, and every later security step, from fuzzing to formal verification to incident response, depends on it.

Photo of Leo Park

Leo Park

Blockchain Expert

Blockchain expert with over 15 years of experience, combining strong technical expertise with educational and editorial work. Specializes in smart contracts, DeFi, and Web3 trend analysis, regularly publishing in-depth articles and industry reports.

Share post

Frequently asked questions

01

How long does a smart contract audit take?

It depends on the size and complexity of the code rather than a fixed schedule. A single token or vesting contract can be reviewed in days. A lending protocol, DEX or cross-chain bridge with several thousand lines and external integrations usually needs several weeks, plus time to review the fixes. A frozen scope and written invariants shorten the process noticeably, because the auditor spends less time reconstructing what the code is supposed to do.

02

Is one audit enough before launching on mainnet?

One audit of a frozen commit is the minimum, and it only covers that commit. Protocols holding significant value often add a second independent review, an invariant-based fuzzing campaign and a bug bounty, since different reviewers and methods find different bugs. Any change made after the audit, including an "only small" fix, should be reviewed again before deployment.

03

Does Rust make Solana or CosmWasm contracts safer than Solidity?

Rust removes memory corruption bugs, which were never the main cause of losses in smart contracts. The costly bugs are logical: missing signer or owner checks on Solana, unhandled submessage failures or unbounded loops in CosmWasm. Each ecosystem has its own failure modes, so a Rust codebase needs the same depth of review as a Solidity one.

See all