Sitemap
Coinmonks

Coinmonks is a non-profit Crypto Educational Publication. Other Project — https://coincodecap.com/ & Email — gaurav@coincodecap.com

How Hackers Think in DeFi: A Deep Dive into Attacker Mindsets

5 min readApr 10, 2026

--

Press enter or click to view image in full size

How hackers think in DeFi: learn attacker mental models, exploit strategies, and how to design secure smart contracts against real world threats.

Introduction:

Security Is Not About Code It’s About Adversaries

Most DeFi security failures are not caused by unknown bugs. They are caused by predictable blind spots in how systems are designed and reasoned about.

Auditors review code. Hackers model systems.

This distinction matters.

A seasoned attacker does not ask:

Is there a vulnerability?

They ask:

What assumptions does this system rely on and how can I violate them?

DeFi security is adversarial, composable, and economic. If you are not thinking like an attacker, you are defending against the wrong threat model.

Core Thesis: Hackers Don’t Break Code They Break Assumptions

Smart contracts are deterministic. Their failure modes are not.

Every protocol embeds implicit assumptions:

  • Prices reflect reality
  • Liquidity is bounded
  • Users behave honestly
  • State transitions follow intended flows

Attackers systematically identify and invalidate these assumptions.

Key Insight: Every exploit is an assumption mismatch between designers and adversaries.

The Attacker’s First Principle: Where Is the Money?

Before analyzing code, attackers map capital flows:

  • Where does value enter?
  • Where is it stored?
  • What mechanisms guard it?
  • What external dependencies influence it?

They build a capital flow graph, not a call graph.

Attacker heuristics:

  • Maximize extractable value per transaction
  • Minimize capital at risk (flash loans solve this)
  • Prefer atomic execution paths
  • Target weak invariants protecting large TVL

If a function moves money, it is an attack surface.

Thinking in Invariants (and How Hackers Break Them)

Protocols rely on invariants such as:

  • Collateralization ratios
  • Supply balances
  • Pricing relationships
  • Accounting consistency

Attackers don’t look for bugs they look for ways to temporarily violate invariants.

Common invariant-breaking strategies:

  • Manipulate inputs (oracles, reserves)
  • Exploit timing (reentrancy, sequencing)
  • Abuse rounding and precision
  • Force unexpected state transitions

Hackers don’t need to permanently break invariants only long enough to extract value.

Composability as an Attack Surface

DeFi’s strength composability is also its biggest liability.

Protocols assume:

  • External integrations behave correctly
  • State dependencies remain stable
  • Interactions are well behaved

Attackers chain protocols to create emergent attack surfaces.

Example mindset:

  • If Protocol A trusts Protocol B’s price
  • And Protocol B can be manipulated via Protocol C
  • Then Protocol A is indirectly exploitable via C.

Composable systems create non-local vulnerabilities.

Economic Exploits vs Technical Exploits

Traditional audits over-index on technical bugs:

  • Reentrancy
  • Overflow/underflow
  • Access control

Modern exploits are increasingly economic:

  • Price manipulation
  • Liquidity distortion
  • Incentive abuse

Attacker framing:

  • Can I make the system misprice assets?
  • Can I extract value without violating code correctness?
  • Can I arbitrage protocol logic itself?

The most dangerous exploits are valid executions of flawed economic design.

Flash Loans: Weaponized Liquidity

Flash loans removed the primary constraint attackers faced: capital.

Now attackers can:

  • Borrow massive liquidity
  • Execute complex strategies
  • Repay within a single transaction

Attacker advantages:

  • Zero upfront capital
  • Infinite scaling potential
  • Atomic execution eliminates risk

Flash loans transform:

Is this exploitable? → Is this exploitable with infinite capital?

Oracle Manipulation Mindset

Oracles are not truth they are inputs.

Attackers ask:

  • How is price derived?
  • What markets feed it?
  • Can liquidity be skewed?

Techniques:

  • Low liquidity pool manipulation
  • Time weighted oracle distortion
  • Cross market arbitrage loops

If a protocol trusts a price, attackers will try to control it.

Reentrancy Revisited (Beyond the Textbook)

Reentrancy is no longer just “call before state update.”

Get Abraham’s stories in your inbox

Join Medium for free to get updates from this writer.

Modern attackers use:

  • Cross function reentrancy
  • Cross contract reentrancy
  • Callback based logic manipulation

Attacker framing:

  • Can I re-enter into a different logical path?
  • Can I observe inconsistent intermediate state?

Reentrancy is fundamentally about violating assumptions of linear execution.

State Manipulation & Edge Cases

Protocols often fail at boundaries:

  • Empty pools
  • First deposits
  • Extreme ratios
  • Precision loss

Attackers actively search for:

  • Uninitialized states
  • Rounding asymmetries
  • Off by-one conditions

Edge cases are not rare they are engineered by attackers.

MEV as an Attack Tool

MEV is not just extraction it’s a weapon.

Attackers leverage:

  • Transaction ordering
  • Sandwiching
  • Backrunning exploit paths

Example:

  • Manipulate price
  • Execute exploit
  • Restore price

All within controlled ordering.

If your protocol assumes fair ordering, it is already broken.

Cross Chain and Bridge Exploit Thinking

Bridges introduce:

  • Trust assumptions
  • Signature verification logic
  • State replication complexity

Attackers target:

  • Validator compromise
  • Signature validation flaws
  • Replay conditions

Bridges fail where consensus assumptions diverge.

Case Studies: How Attackers Actually Think

1. Euler Finance (2023)

Failure: Liquidation logic + donation mechanism

Attacker reasoning:

  • Can I manipulate my own health factor?
  • Can I donate to alter internal accounting?
  • Can I trigger liquidation under distorted conditions?

Outcome: $197M exploit

Insight: Internal accounting assumptions were exploitable without breaking external constraints.

2. Mango Markets (2022)

Failure: Oracle manipulation via low liquidity market

Attacker reasoning:

  • Can I inflate collateral value artificially?
  • Can I borrow against manipulated valuation?

Outcome: $110M extracted

Insight: The system behaved correctly based on false inputs.

3. Nomad Bridge (2022)

Failure: Improper initialization

Attacker reasoning:

  • Can I replay a valid transaction with modified parameters?

Outcome: $190M drained (crowd exploit)

Insight: Once the invariant broke, exploitation became permissionless.

Mental Models Hackers Use

1. What Can I Control?

  • Inputs
  • Timing
  • Liquidity
  • Execution order

2. What Assumptions Can I Violate?

  • Price correctness
  • State consistency
  • User behavior

3. Can I Make the System Lie to Itself?

  • Feed false data
  • Distort internal accounting
  • Trigger incorrect logic paths

Attackers don’t attack functions they attack beliefs embedded in systems.

Defensive Takeaways: Auditing Like an Attacker

Ask Better Questions

  • What assumptions does this protocol rely on?
  • Are those assumptions enforceable onchain?
  • What happens under extreme conditions?

Design Principles

  • Minimize trust in external inputs
  • Enforce invariants explicitly
  • Simulate adversarial scenarios
  • Assume infinite capital attackers

Audit Mindset Shift

From:

  • “Is this function safe?”

To:

  • “How would I break this system if I had unlimited resources?”

Conclusion: Security Is an Adversarial Discipline

DeFi security is not about preventing bugs it is about anticipating intelligent adversaries.

The best auditors:

  • Think in systems, not functions
  • Model incentives, not just logic
  • Assume hostility, not cooperation

If you don’t think like a hacker, you are relying on luck not security.

--

--

Abraham
Abraham
Coinmonks
Coinmonks