Lesson 1 of 5 Smart Contract Vulnerabilities

Smart Contract Security Fundamentals

Smart contract security starts with understanding the environment. This lesson explains why contracts are high-value targets, what attackers can and cannot do, how real incidents happened and how vulnerability classes are catalogued.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain why smart contracts are high-value targets.
  • Describe the capabilities an attacker has.
  • Describe lessons from major incidents.
  • Identify the main catalogues of vulnerability classes.

Why contracts are different targets

A smart contract is an open server that holds money, runs code that anyone can read, accepts calls from anyone and cannot be patched. The following terms describe the properties that make security central to every Ethereum project.

Value at stake
Contracts directly hold ether and tokens, often worth millions, so a single bug can be monetised immediately.
Transparency
Source (once verified), bytecode and every transaction are public, so attackers can study the code and rehearse attacks on a forked chain.
Immutability
Deployed code cannot be fixed; a vulnerability stays exploitable unless an upgrade or pause mechanism exists.
Composability
Contracts call other contracts, so a flaw or a manipulated value in one protocol can be exploited through another.
Irreversibility
Finalised transactions cannot be undone; stolen funds are rarely recovered.

The attacker's capabilities

When reviewing a contract, assume an attacker who can do everything the protocol allows. The following list describes those capabilities.

  • Call any public or external function, in any order, with any arguments.
  • Deploy their own contracts that call yours and run code when they receive ether or tokens.
  • Read all storage, including private variables, and every pending transaction in the mempool.
  • Submit transactions with higher priority fees to be included before others, or bundle several transactions in one block.
  • Borrow huge amounts for the duration of one transaction with flash loans, so capital is not a limit.

What attackers cannot do is break the cryptography, forge signatures or make the EVM execute code differently. Almost every loss comes from logic that allows something its author did not intend.

Sort into groups

What can an attacker do?

Exam skills 3.1.1 · 3.1.2

Decide whether each action is within an attacker's reach on Ethereum.

Log in to try this activity Interactive activities are free with an account.

Lessons from incidents

A few incidents shaped today's practices. The following table summarises them.

IncidentYearCauseLesson
The DAO2016Reentrancy in a withdrawal functionUpdate state before external calls; the incident led to the Ethereum/Ethereum Classic split
Parity multisig2017An unprotected initialisation function in a shared library, then its self-destructionProtect initialisers; beware shared code that many contracts depend on
Integer overflow tokens2018Unchecked arithmetic allowed huge balances to be createdChecked arithmetic, now default in Solidity 0.8
Oracle manipulation attacks2020 onwardsPrices taken from a single pool were moved with flash loansUse robust oracles and time-weighted prices
Match the pairs

Incidents and their lessons

Exam skills 3.1.1 · 3.1.2

Match each well-known incident with its cause.

Log in to try this activity Interactive activities are free with an account.

Cataloguing vulnerabilities

The OWASP Smart Contract Top 10 (2025 edition) lists the most damaging vulnerability classes, including access control flaws, price oracle manipulation, logic errors, lack of input validation, reentrancy, unchecked external calls, flash-loan attacks, integer overflow and denial of service. Older material refers to the Smart Contract Weakness Classification (SWC) registry, which is no longer maintained but still provides useful names. The rest of this module covers the classes the exam emphasises.

Worked example

Thinking like an attacker

A lottery contract lets anyone call pickWinner(), which selects a winner using block.timestamp % players.length. List the attacker capabilities that make this unsafe.

The attacker can read players from storage, can compute the result for the current block in their own contract before calling, and can call pickWinner() from a contract only when the computed winner is themselves, reverting otherwise. A validator could also choose when to include the call. The design relies on a value the attacker can predict and on a function anyone can time, both of which the lesson on randomness addresses.

Worked example

An "unreachable" function

A developer argues that function emergencyWithdraw() public is safe without access control because "the front end has no button for it". Is that true?

No. Anyone can call any public function directly with web3.js, a block explorer or their own contract, regardless of the front end. The ABI is public, and even without it the selector can be guessed or read from the bytecode. Every sensitive function needs on-chain access control.

Check yourself

Why is hiding a function from the front end not access control?

Show answer

Anyone can call any public or external function directly with a library, a block explorer or their own contract. Only checks enforced in the contract's code restrict who can call it.

Exam Tips

Remember for the exam

  • Contracts hold value, are public, immutable and composable, and their losses are irreversible.
  • Assume attackers can call anything in any order, deploy contracts, read all data and use flash loans.
  • The front end is not a security boundary; on-chain checks are.
  • The DAO (2016) is the classic reentrancy incident.