ChainScore Labs
All Guides

Common DeFi Design Assumptions That Lead to Exploits

LABS

Common DeFi Design Assumptions That Lead to Exploits

Chainscore © 2025

Core Flawed Assumptions in DeFi

Many DeFi exploits stem from foundational design assumptions that fail to hold under adversarial conditions. This section examines the critical, often implicit, beliefs about user behavior, market dynamics, and system interactions that, when proven false, lead to vulnerabilities.

The Honest Majority

The honest majority assumption posits that most participants act in good faith, securing the system. This fails in DeFi where a single rational, well-capitalized adversary can dominate.

  • Reliance on social consensus over cryptographic guarantees
  • Example: Governance attacks where a malicious proposal passes due to voter apathy
  • This matters as it exposes protocols to low-cost takeover and fund theft.

Price Oracle Correctness

Assumes oracle price feeds are always accurate, timely, and manipulation-resistant. In reality, oracles have single points of failure and latency.

  • Dependency on a narrow set of data sources or DEX pools
  • Example: Flash loan attacks that artificially skew a pool's price to drain lending protocols
  • This matters because incorrect pricing leads to undercollateralized loans and bad debt.

Atomic Composability

The assumption that composability—the seamless interaction of protocols—is always safe and atomic. Nested calls can create unexpected state changes and reentrancy vectors.

  • Unchecked interactions between independent smart contracts
  • Example: A yield farming strategy that deposits into a vulnerable vault, enabling a reentrancy attack on the original caller
  • This matters as it turns a feature into an attack amplifier across the ecosystem.

Economic Finality

Assumes that economic incentives alone guarantee finality and correct execution. Miners/validators can reorder or censor transactions for profit, breaking state assumptions.

  • MEV extraction that front-runs or sandwiches user transactions
  • Example: A decentralized auction where the winning bid is stolen via a malicious block inclusion
  • This matters because it undermines fairness and can invalidate protocol mechanics.

Permissionless Safety

The belief that permissionless access does not compromise security. Open participation allows attackers to deploy malicious contracts that interact with the system.

  • Inability to blacklist known malicious actor addresses or contracts
  • Example: A fake token designed to exploit specific allowance checks in a DEX router
  • This matters as it forces protocols to defend against an infinite set of adversarial inputs.

Liquidity Immutability

Assumes that liquidity providers (LPs) are passive and locked capital is static. LPs can withdraw instantly, causing volatility and breaking constant-function market maker models.

  • Sudden liquidity withdrawal during market stress (a 'bank run')
  • Example: An attacker borrows assets to drain a pool, triggering massive LP losses from impermanent loss
  • This matters as it can render a protocol insolvent or unusable during critical moments.

Categories of Risky Assumptions

Understanding Economic Vulnerabilities

Economic assumptions often fail by incorrectly modeling user behavior or market conditions. These flaws create openings for arbitrage, manipulation, and protocol insolvency.

Common Pitfalls

  • Static pricing models: Assuming oracle prices reflect true market value can lead to exploits, as seen when attackers manipulate a Curve pool's price to drain funds via a flash loan.
  • Unbounded leverage: Protocols like early lending markets assumed users would self-regulate borrowing, but recursive borrowing loops can collapse the system if collateral value drops.
  • Fixed fee structures: Assuming transaction fees will always cover operational costs ignores high gas environments, leading to unprofitable liquidations on networks like Ethereum during congestion.
  • Infinite liquidity: Designing systems that assume liquidity pools (e.g., Uniswap v2) cannot be drained ignores the impact of large, single trades on price slippage and pool health.

Real-World Impact

The 2022 Mango Markets exploit stemmed from an economic assumption that oracle prices from a DEX with low liquidity could not be artificially inflated, allowing an attacker to borrow far more than their collateral's true worth.

How to Identify Dangerous Assumptions

A systematic process for auditing smart contracts by challenging their core operational premises.

1

Map the Protocol's Core Logic Flow

Deconstruct the contract into its primary state transitions and dependencies.

Detailed Instructions

Begin by creating a state transition diagram or a detailed flowchart. Identify the key functions that move assets or change critical state variables. For each function, trace the control flow and document all external calls, including to oracles, other contracts, and token transfers. Pay special attention to functions that update pricing, calculate rewards, or mint/burn tokens. This map reveals the foundational assumptions about how data and value move through the system.

  • Sub-step 1: Use a tool like Slither to generate a function dependency graph.
  • Sub-step 2: Manually trace the path of a user deposit through to withdrawal, noting every conditional check.
  • Sub-step 3: List all external dependencies (e.g., IWETH(address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2)).
solidity
// Example: Identify a core pricing function function getAssetPrice(address asset) public view returns (uint256) { // Assumption: This oracle is always available and correct return IAggregatorV3(oracle).latestAnswer(); }

Tip: Focus on the 'happy path' first; the assumptions become most visible in the expected normal operation.

2

Enumerate All External Dependencies

Catalog every point where the contract relies on an outside actor or data source.

Detailed Instructions

Systematically list every call, delegatecall, staticcall, and interface interaction. For each, document the trust assumption. Common categories include: price oracles (Chainlink, Uniswap TWAP), token contracts (especially non-standard ERC-20s like fee-on-transfer), governance contracts, and keeper networks. Ask: "What happens if this call reverts, returns stale data, or is malicious?" Quantify the value at risk if the dependency fails or is manipulated.

  • Sub-step 1: Use cast or a static analyzer to find all CALL opcodes and their targets.
  • Sub-step 2: For each oracle, check its heartbeat and deviation thresholds (e.g., maxAnswer/minAnswer).
  • Sub-step 3: Verify token compliance; check for hooks in transferFrom or balance-changing callbacks.
solidity
// Example: A dependency with implicit trust ERC20(token).transferFrom(msg.sender, address(this), amount); // Assumption: `token` is a well-behaved ERC-20 and `transferFrom` returns a boolean.

Tip: Assume all external contracts are adversarial. The safest assumption is that any external call can fail or behave unexpectedly.

3

Stress-Test Economic Invariants

Challenge the mathematical and economic rules the protocol believes will always hold.

Detailed Instructions

Identify the protocol's invariants—conditions that should always be true, such as "total shares <= total assets" or "collateral value > debt value." Formulate these as precise mathematical statements. Then, construct edge-case scenarios to break them. Consider extreme market volatility (e.g., 100x price moves), zero-fee token swaps, or sudden interest rate spikes. Use a framework like fuzzing (with Foundry's forge test --invariant) to automatically search for invariant violations by randomly manipulating state and inputs.

  • Sub-step 1: Write a Solidity test that asserts the invariant, e.g., assert(vault.totalAssets() >= vault.totalSupply()).
  • Sub-step 2: Run invariant tests with a high number of runs (--invariant-runs 10000).
  • Sub-step 3: Manually simulate a flash loan attack to manipulate an oracle price and break collateral ratios.
solidity
// Example: An invariant test in Foundry function invariant_protocolSolvent() public { assert( getTotalCollateralValue() >= getTotalDebtValue() ); }

Tip: The most dangerous assumptions are often about asset pricing and the continuous liquidity of underlying markets.

4

Analyze Privileged Roles and Upgrade Paths

Audit the trust placed in administrators, governance, and upgrade mechanisms.

Detailed Instructions

Locate all addresses with special permissions: owners, governors, multisigs, and whitelisted keepers. Map their capabilities, such as pausing, upgrading implementations, changing fee parameters, or minting unlimited tokens. Evaluate the time-locks and governance thresholds guarding these actions. A critical assumption is that these actors will never act maliciously or have their keys compromised. Scrutinize upgradeable contracts (UUPS/Transparent Proxy) for initialization vulnerabilities and storage collisions that could break invariants post-upgrade.

  • Sub-step 1: Review the contract's constructor and initialize function for one-time role assignments.
  • Sub-step 2: Check all require(msg.sender == owner) or AccessControl checks to list privileged functions.
  • Sub-step 3: Verify the delay on a TimelockController (e.g., 48 hours) and the governance proposal quorum.
solidity
// Example: A powerful owner function with a dangerous assumption function setOracle(address newOracle) external onlyOwner { // Assumption: The owner will only set a secure, non-malicious oracle. oracle = newOracle; }

Tip: The security of the protocol often reduces to the security of the private keys controlling these roles.

5

Review Time and Sequencing Assumptions

Examine dependencies on block timestamps, transaction ordering, and state consistency.

Detailed Instructions

Smart contracts operate in a discrete, block-based environment. Identify assumptions about block timing (e.g., block.timestamp for interest accrual), transaction ordering (front-running), and state consistency across multiple calls. A common flaw is assuming two transactions will be processed in the same block or that an oracle update occurs before a liquidation. Check for reliance on block.number for time periods, which can be unreliable due to variable block times. Analyze functions that can be sandwiched or have their expected outcome changed by a state-altering transaction in the same block.

  • Sub-step 1: Search for all uses of block.timestamp and block.number. Assess if they are manipulable by miners/validators.
  • Sub-step 2: Look for functions that read a storage value, perform logic, then write back, creating a reentrancy or front-running risk.
  • Sub-step 3: Check if critical actions (like settling a trade) depend on a specific order of off-chain events.
solidity
// Example: A timing assumption for rewards function claimRewards() external { require(block.timestamp >= lastClaimTime[msg.sender] + 1 weeks, "Wait 1 week"); // Assumption: One week in seconds is a safe measure of real time. _claim(); }

Tip: Validators have some ability to manipulate block.timestamp within a small range, which can be exploited in precise timing logic.

Assumption-to-Exploit Case Matrix

A comparison of common DeFi design assumptions, their flawed implementations, and resulting exploit cases.

Design AssumptionFlawed ImplementationResulting VulnerabilityExample Exploit

Price is always from a trusted source

Using a single DEX pool's spot price as an oracle

Price manipulation via flash loan

Harvest Finance (2020), $34M loss

Token transfers are atomic and revert on failure

Using transfer()/send() with fixed 2300 gas stipend

DoS via gas griefing or reentrancy

King of the Ether (2016), contract frozen

Only the contract owner can call privileged functions

Using tx.origin for authorization instead of msg.sender

Phishing attack via intermediary contract

Unknown (common pattern), wallet draining

ERC-20 balanceOf is immutable during a transaction

Checking balances before and after a transfer for fees

Fee bypass via flash mint and self-transfer

Fei Protocol (2022), $80M in losses

A user's token balance is sufficient for a withdrawal

Checking balance but not reducing it before external call

Reentrancy allowing repeated withdrawals

The DAO (2016), $60M drained

Liquidity pool reserves follow a constant product formula

Using balanceOf for reserves instead of stored reserve variables

Reserve manipulation via direct token transfer

Uniswap V1/V2 (multiple instances), arbitrage distortion

A smart contract's code is immutable and final

Using delegatecall to a potentially upgradeable logic contract

Logic hijack if admin privileges are compromised

Poly Network (2021), $611M exploited

Design Patterns to Mitigate Assumption Risk

Proactive architectural strategies to harden DeFi protocols against flawed assumptions about user behavior, market conditions, and external dependencies.

Time-Weighted Average Pricing (TWAP)

Oracle manipulation resistance is achieved by using price feeds averaged over a significant time window, rather than instantaneous spot prices. This design counters the assumption that on-chain oracles are always accurate and manipulation-proof.

  • Uses a moving average (e.g., 30-minute TWAP) from a DEX like Uniswap V2/V3
  • Significantly increases the capital cost for an attacker to skew the price
  • Critical for lending protocols to prevent undercollateralized loans and for derivatives for fair settlement
  • This matters because it transforms a security assumption into a verifiable, costly-to-break economic barrier.

Circuit Breakers & Grace Periods

Emergency state transitions allow a protocol to pause specific functions or enter a recovery mode when predefined risk thresholds are breached, countering the assumption of continuous, normal operation.

  • Can halt deposits/borrows if collateral value drops too rapidly
  • Grace periods for liquidation give users time to top up collateral before forced sales
  • Implemented via timelocks or multi-sig guardian roles for controlled activation
  • This matters as it provides a safety buffer during extreme volatility or oracle failure, preventing instantaneous cascading liquidations.

Two-Step Commit-Reveal Schemes

Information leakage prevention is designed to counter the assumption that all transactions and their intents are private until execution. This pattern hides sensitive data like bids, votes, or random numbers until a later phase.

  • Users first submit a hashed commitment of their action (e.g., a bid amount with a salt)
  • In a second transaction, they reveal the original data, which is verified against the hash
  • Used in fair auctions, on-chain gaming, and decentralized sequencer selection
  • This matters because it prevents front-running and ensures fair, unpredictable outcomes in competitive environments.

Explicit, Bounded Token Approvals

Principle of least privilege directly counters the dangerous assumption that users will only interact with trusted contracts. It limits the potential damage from a compromised or malicious dApp.

  • Users approve a specific token amount for a specific contract, not an infinite allowance
  • Approval can be scoped to a single function call via permit2 or EIP-2612 signatures
  • Wallets and aggregators like Revoke.cash promote this practice
  • This matters for user security, as it contains the blast radius of phishing attacks or buggy contract integrations.

Fail-Safe Withdrawal Mechanisms

Escape hatch design assumes that core protocol logic may fail or become permanently frozen, providing users a direct path to recover their assets without relying on standard operations.

  • Implements a separate, simple function allowing users to withdraw their deposited tokens after a long timelock
  • Often activated only if a governance vote fails or a security incident is declared
  • Seen in staking contracts and complex yield vaults
  • This matters because it ensures user funds are not permanently locked due to a bug or governance deadlock.

Economic Finality via Slashing

Costly signaling replaces the assumption that participants will act honestly with a mechanism that makes malicious behavior financially irrational through bonded stakes.

  • Validators or keepers post collateral that can be destroyed (slashed) for provably incorrect actions
  • Used in Proof-of-Stake consensus, optimistic oracle systems (e.g., UMA), and cross-chain messaging
  • Creates strong incentives for data validity and protocol adherence
  • This matters as it aligns economic incentives with desired system behavior, securing critical functions without relying on altruism.
SECTION-FAQ

Assumptions and Auditing FAQ

Ready to Start Building?

Let's bring your Web3 vision to life.

From concept to deployment, ChainScore helps you architect, build, and scale secure blockchain solutions.