Skip to content
Tech Interview Prep
Technical interview guide

Smart Contract Security & Common Vulnerabilities

Why smart contract bugs are uniquely costly (immutable, public, and directly holding funds) and the vulnerability classes that recur across major exploits.

Minutes to read
4
Practice MCQs
25
Interview Q&A
25
Edition
v4
Editorial status
Reviewed

Scope: OWASP Smart Contract Security Verification Standard and Smart Contract Top 10:2026 reviewed 2026-09-04; Solidity latest security guidance; OpenZeppelin Contracts 5.x and Upgrades documentation; Chainlink Data Feeds documentation.

Overview

Curated: · Written: · Reviewed:

Smart Contract Security & Common Vulnerabilities

In one line

Smart contract security means showing that a contract's invariants (solvency, conservation, authorization) still hold when anyone can call any function, in any order, from a contract the attacker wrote. Reach for it whenever a contract holds value, is upgradeable, or depends on prices, signatures, randomness or external tokens.

Key definitions

  • Invariant: a predicate that must hold in every reachable state, such as assets >= outstanding claims.
  • Reentrancy: control returns to a caller through a callback before the contract has restored its state.
  • Trust boundary: any input you do not control: a token, an oracle, an admin key, a signature, a callee.
  • msg.sender vs tx.origin: the immediate caller vs the original transaction signer.
  • Storage collision: a proxy and its implementation disagree on slot layout under delegatecall.
  • Read-only reentrancy: a view returns intermediate state that another protocol trusts and acts on.

Formulas and complexity

shares=assets⋅totalSupplytotalAssets\text{shares} = \frac{\text{assets} \cdot \text{totalSupply}}{\text{totalAssets}} ∑ubalanceu=assets(conservation, the invariant reentrancy breaks)\sum_{u} \text{balance}_u = \text{assets} \quad \text{(conservation, the invariant reentrancy breaks)} forwarded gas≤6364⋅gasremaining(EIP-150)\text{forwarded gas} \le \frac{63}{64} \cdot \text{gas}_{\text{remaining}} \quad \text{(EIP-150)}

transfer and send forward a fixed 2300 gas.

How it works

A CALL hands control to the callee, which can run arbitrary code and call back into your contract. If the contract updates its state after that call, the callee sees the old state and can repeat the action. The fix is to restore the invariant before control leaves.

no yes withdraw reads balance external call to attacker receive re-enters withdraw balance already zeroed? inner withdraw reverts outer call returns

In the vulnerable order, the balance is zeroed after the transfer, so each re-entry pays out again. In the fixed order (effect before interaction), the inner call reads zero, fails its check, and the outer require(ok) reverts the whole transaction.

When to use and when not to

DecisionChooseAvoidWhat decides it
Ether transfercall with return check, or pull paymentstransfer / send to logic-bearing recipientsthe 2300-gas stipend breaks any recipient with logic
Price sourceTWAP or independent feedspot pool reservescost to move the price within one transaction
Upgradeabilityproxy with timelocked adminproxy with no upgrade paththe upgrade authority is itself a trust boundary
RandomnessVRF with callbackprevrandao, block.timestamp for valuevalue at stake vs proposer bias window
Pausescoped pause on the risky pathglobal freeze that traps userswhether the incident outruns governance

Traps interviewers probe

  1. Authorization on tx.origin. An intermediary contract preserves the victim as tx.origin, so a phished user's call passes the check. Fix: check msg.sender, and enforce roles at the state-changing entry point.
  2. Trusting a reentrancy guard. Guards are per function and per contract, so they miss sibling functions, other contracts sharing state, and read-only reentrancy. Fix: checks-effects-interactions first, then guard, then test malicious callbacks across the whole call graph.
  3. Trusting call success or return values. A true from a low-level call only means no revert at the EVM boundary, and some tokens return false or take fees. Fix: check the balance delta your invariant needs.
  4. Leaving the initializer open. Proxy constructors do not initialize proxy storage, so the first caller of an exposed initialize becomes owner. Fix: initialize atomically in the deployment transaction, lock the implementation, and test an already-initialized state.
  5. Pricing collateral from a spot pool. A flash loan can move the reserves inside one transaction. Fix: use a TWAP or an independently governed feed, with staleness checks, decimal normalization and a defined fallback.

Interview tips

Open with the three questions: which invariant, who can trigger the break, and what bounds the damage. Then name the attack and the mitigation with its trade-off.

Follow-ups to expect:

  • Why is tx.origin unsafe but msg.sender fine?
  • Can reentrancy happen without Ether? Yes: ERC-777 hooks, onERC721Received, any callback.
  • Why is read-only reentrancy dangerous if nothing is written?
  • call vs transfer, and why?
  • How do you test this? Stateful invariant fuzzing with malicious callbacks and fork tests against real integrations.
  • What is your maximum credible loss?

30-second answer outline:

  1. Name the invariant the contract must keep (for example, conservation of balances).
  2. Name the adversary and the callback or input that breaks it.
  3. Trace the two or three calls that reach the broken state.
  4. State the fix: effect before interaction, msg.sender, a balance-delta check, or a TWAP.
  5. State the residual risk and what bounds it: a timelock, a scoped pause, or a cap.

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.