SolidityIn

The $100M Mistakes: 5 Solidity Vulnerabilities That Drained Protocols

November 2, 2026 · admin · Uncategorized


In Web3 development, “code is law”—and the law is unforgiving. A single misplaced line, unchecked calculation, or naive assumption in a smart contract can trigger an irreversible nine-figure bank run. Here is a technical breakdown of five of the costliest Solidity vulnerabilities in decentralized finance (DeFi) history and how to prevent them.


1. Reentrancy (Classic & Read-Only)

Notable Victims: The DAO ($60M at the time), Euler Finance ($197M), Curve-Vyper Pools ($61M+)

Reentrancy remains the most infamous smart contract exploit. It occurs when an external contract call interrupts the execution flow of the calling contract before the caller updates its internal state. The external actor re-enters the original function (or another function sharing state) recursively, draining funds.

The Vulnerable Pattern

// INSECURE: State updated AFTER external call
function withdraw(uint256 amount) external {
require(balances[msg.sender] >= amount, "Insufficient balance");
// 1. External call hands control to the attacker's fallback/receive
(bool success, ) = msg.sender.call{value: amount}("");
require(success, "Transfer failed");
// 2. State update occurs too late
balances[msg.sender] -= amount;
}

While classic reentrancy is largely mitigated using OpenZeppelin’s ReentrancyGuard, Read-Only Reentrancy has caused massive modern exploits. In read-only variants, a reentrant call reads an un-updated, temporary, out-of-balance state from an external protocol (such as an AMM pool) to calculate an inflated collateral value in a secondary protocol.

The Fix: Always follow the Checks-Effects-Interactions (CEI) pattern. Mutate internal state before executing external calls, and use mutual exclusion locks like OpenZeppelin’s nonReentrant modifier.


2. Spot-Price Oracle Manipulation via Flash Loans

Notable Victims: Mango Markets ($114M), bZx ($8M+), Cream Finance ($130M)

Many lending and synthetic asset protocols need to determine the real-time value of collateral assets. A catastrophic design mistake is querying the instantaneous (spot) reserves of an automated market maker (like a Uniswap v2 pair or Curve pool) directly inside the contract.

The Vulnerable Pattern

// INSECURE: Spot reserve price easily skewed within a single block
function getAssetPrice(address token) public view returns (uint256) {
(uint112 reserve0, uint112 reserve1, ) = IUniswapV2Pair(pair).getReserves();
// Easily skewed by an attacker borrowing millions via a Flash Loan!
return (uint256(reserve1) * 1e18) / uint256(reserve0);
}

Attackers borrow massive liquidity using uncollateralized flash loans, dump huge volume into the AMM to skew the spot reserve balance, trigger the target protocol to calculate the price using that distorted snapshot, borrow the protocol’s real reserves, and repay the flash loan in a single transaction.

The Fix: Never use instantaneous AMM reserves as a valuation oracle. Use decentralized, aggregated oracles like Chainlink Data Feeds, implement robust Time-Weighted Average Prices (TWAP) with sufficiently long time windows, and enforce slippage limits.


3. Uninitialized Storage & Zero-Address Fallbacks

Notable Victims: Nomad Bridge ($190M), Parity Multi-Sig ($150M+ locked)

Upgradeability via proxies separates a contract’s logic (implementation) from its state (proxy storage). Because constructors only execute on the implementation contract’s deployment and do not affect proxy storage, upgradeable contracts rely on custom initialize() functions.

If an initialize() function lacks access control or the initializer modifier, an attacker can invoke it to take ownership. Even worse, if variables default to empty state (zero values), contracts checking those variables might accidentally approve forged transactions.

The Nomad Case Study

During an update to the Nomad bridge, the team initialized a root variable to 0x00. A verification function inside the contract verified messages against accepted roots:

// Nomad Bridge Logic Bug
function isValidRoot(bytes32 root) public view returns (bool) {
return acceptedRoots[root]; // acceptedRoots[0x00] returned true due to configuration error!
}

Because uninitialized messages defaulted to 0x00, the contract treated every arbitrary payload as pre-validated. Attackers simply copied the original attacker’s transaction data, replaced the destination address with their own, and drained nearly $200 million within hours.

The Fix: Use OpenZeppelin’s _disableInitializers() in constructors for implementation contracts, apply the initializer modifier strictly, and explicitly prevent comparisons against default storage values (such as address(0) or bytes32(0)).


4. Arbitrary External Calls & delegatecall Injection

Notable Victims: Poly Network ($611M), Multichain ($126M)

Low-level operations such as address.call() and address.delegatecall() are powerful tools for proxies and meta-transactions, but exposing the target address or calldata to user-supplied input creates immediate system-level compromise.

The Mechanism

// INSECURE: Target and calldata entirely user-controlled
function execute(address target, bytes calldata data) external onlyOwnerOrManager {
(bool success, ) = target.call(data);
require(success, "Execution failed");
}

In the Poly Network exploit, the cross-chain manager contract allowed cross-chain transactions to trigger arbitrary internal calls. The attacker used this execution bridge to target the privileged EthCrossChainData contract and execute a function that replaced the consensus public keys with their own.

When combined with delegatecall, the situation is even deadlier: the invoked code executes in the context of the caller’s storage, allowing any storage slot (including ownership variables) to be rewritten directly.

The Fix: Avoid exposing arbitrary target execution. Maintain strict, immutable allowlists of permissible target contracts and explicit function selectors. Never execute dynamic user-provided byte arrays via delegatecall.


5. ERC-4626 Share Inflation & Precision Rounding

Notable Victims: Hundred Finance ($6.5M), Platypus Finance, Multiple Yield-Vault Forks

Standard tokenized vaults (ERC-4626) compute shares based on the ratio between deposited assets and the vault’s total supply of shares:

shares = (assets * totalShares) / totalAssets

The Inflation / First-Depositor Attack

  1. An attacker monitors a newly deployed vault with totalShares == 0.
  2. The attacker deposits 1 wei of assets to receive 1 wei of shares.
  3. The attacker directly donates (transfers without minting) 1,000,000 USDC to the vault contract address.
  4. Now: totalAssets = 1,000,000.000001 USDC, but totalShares = 1 wei.
  5. A legitimate user deposits 500,000 USDC.
  6. The math executes: shares = (500,000 * 1) / 1,000,000.000001 = 0 (due to integer truncation).
  7. The victim receives 0 shares, yet their 500,000 USDC is locked in the vault, immediately redeemable by the attacker’s single share.

The Fix: Implement virtual shares and virtual assets (as popularized by OpenZeppelin’s ERC-4626 v4.9+) to simulate initial liquidity, or burn dead shares permanently to address(0xdead) during deployment so the denominator can never be trivially skewed.


Defending Against Nine-Figure Errors

Writing secure Solidity requires abandoning traditional web development assumptions. Unit tests alone are insufficient. To build resilient decentralized infrastructure:

  • Implement property-based fuzzing (via Foundry/Echidna) and invariant testing.
  • Undergo multiple competitive audit contests alongside traditional firm reviews.
  • Set up defense-in-depth mechanisms: emergency pauses, circuit breakers, and rate-limiting contracts.

The blockchain does not forgive typos, logical fallacies, or unhandled edge cases. Treat every public and external function as an open door for an adversary holding a multi-million dollar bounty.

Tags: , , ,