DeFi architecture

DeFi Protocol Threat Modeling Before Implementation

Threat modeling before implementation helps a team decide what must remain true even when contracts, oracles, governance, infrastructure, or markets behave unexpectedly.

By RStorm LabsPublished 3 min read

Map the system and its assets

Start with a system map that includes contracts, wallets, keepers, governance, frontends, APIs, signers, oracles, bridges, and external protocols. Identify what can be lost or corrupted: user funds, collateral, accounting state, protocol fees, governance power, private keys, and the integrity of public data.

The map should show where trust changes hands. A call from a protocol contract to an oracle, bridge, or upgrade administrator crosses a boundary that the local contract code cannot fully control.

Define actors, privileges, and invariants

List every role that can change value or behavior, including indirect roles such as oracle operators, relayers, liquidators, and governance delegates. Record what each role can do, how its authority is granted, and how that authority can be revoked.

Invariants describe conditions that must hold across valid operations. Examples might include “total accounted shares cannot exceed the asset claims represented by the system” or “a user cannot withdraw more collateral than their finalized position permits.” A useful invariant is specific enough to test and includes documented exceptions.

  • Identify privileged functions and the effective path to calling them.
  • Specify who can pause, upgrade, reprice, mint, burn, or withdraw.
  • Write invariants for normal operation, upgrades, and recovery procedures.

Develop abuse cases across layers

For each asset flow and privilege, ask how a malicious or compromised actor could benefit. Include manipulated oracle inputs, stale prices, reentrant integrations, unexpected token behavior, governance capture, malicious upgrades, blocked liquidations, bridge message failures, and transaction-ordering effects.

Abuse cases should also cover honest failures. An unavailable RPC provider, a congested network, or a delayed keeper can create losses without an attacker writing a single exploit transaction. Market conditions such as thin liquidity and rapid collateral movement can turn a technical assumption into an economic vulnerability.

Prioritize by impact and realistic exposure

A threat register should record the scenario, affected assets, preconditions, impact, existing controls, detection method, residual risk, and owner. Numeric scores can help ordering, but they should not hide uncertainty or create false precision. A low-likelihood event with irreversible system-wide impact still needs explicit treatment.

Prefer controls that reduce entire classes of exposure: minimized privileges, bounded minting, explicit trust assumptions, time delays, independent monitoring, and safe failure modes. A warning in documentation is not equivalent to a technical control.

Turn the model into verification

The threat model should influence implementation specifications, unit and invariant tests, deployment checks, monitoring, and incident response. If a threat cannot be tested before launch, the team should document how it will be detected and contained in production.

Threat modeling is not a one-time workshop. New integrations, oracle changes, governance proposals, upgrades, and asset listings can invalidate earlier assumptions and should trigger a focused review.

To carry these invariants and abuse cases into implementation review, see Smart Contract Audit Scope: What Teams Should Prepare.

Primary documentation and further reading

These sources describe the underlying protocols and tools. They are provided for technical verification and further study.

Related engineering experience

Explore Roman Storm’s project roles and contributions in these areas.

Tornado Cash: privacy protocol

Co-Founder & Lead Developer

Project profile covering Roman Storm’s role in the architecture and development of the open-source Tornado Cash privacy protocol.

Multisender.app: web3 tooling

Founder & Architect

Project profile covering the architecture of Multisender.app, a Web3 utility for batch token and NFT transfers.