Smart contract security starts with the code itself: whether the contract behaves as intended, whether access controls are correct, whether accounting can be manipulated, and whether any known vulnerability class has been missed. These are important questions, but they only cover part of what makes a decentralized finance (DeFi) protocol secure.
A smart contract rarely operates in isolation. It may depend on an oracle returning a sensible price, sufficient liquidity being available, governance responding to an emergency, or another protocol continuing to behave in a particular way. A review can find that every function behaves exactly as intended, but if one of these assumptions stops being true, the wider system can still end up in an unsafe or economically harmful state.
Four areas shape the security of a protocol beyond the code itself: the assumptions it relies on, the invariants that must remain true, the risks introduced through composability, and the different forms of control that exist across the wider system.
The assumptions a protocol makes about its environment are just as important as the code itself. Some of these assumptions are explicit: relying on a particular oracle for pricing, or expecting blocks to be produced within a certain period of time. Others are less obvious: a protocol might assume that enough liquidity will be available when a trade is executed, that governance will intervene during an emergency, or that participants will behave rationally rather than maliciously.
The problem is that these assumptions are rarely specified, tested, or monitored in the same way as functions such as depositing or withdrawing. They are exactly that: assumptions. There is often nothing in the contract that enforces them. If one of them stops holding, nothing reverts and there may be no mechanism that stops the protocol from continuing to operate. The contract was written to behave correctly under a particular set of conditions, and it will keep executing even when those conditions are no longer true.
Moonwell is a good example of this. On November 4, 2025, an oracle serving its wrsETH market on Base briefly reported the asset at a massively inflated price. An attacker deposited a small amount of wrsETH as collateral, the protocol treated that collateral as being worth far more than it really was, and the attacker borrowed assets against that inflated value, walking away with roughly $1 million and leaving the protocol with roughly $3.7 million in bad debt.
The lending and borrowing logic itself did not fail. Given the price it received, the protocol behaved exactly as it was designed to. What failed was an assumption the system had been built around: that the oracle configuration would provide a reasonable and accurate value for the collateral. A system can execute perfectly according to its code and still fail because the world around that code no longer matches the one it was designed for.

Assumptions describe the conditions a protocol expects to operate under. Invariants are different: they describe the things that must always remain true, regardless of how the protocol is used. For example, a lending protocol may require that it always remains solvent, or that a user can never withdraw more value than they are entitled to. When these properties stop holding, the protocol has reached a state it was never supposed to reach, even if every individual function involved behaved correctly.
Reviewing functions in isolation can fall short here. Checking access controls, input validation, and individual state transitions will catch many implementation issues, but it does not always reveal what happens when those funpubctions are combined, repeated, or called in an unexpected order. Instead of only asking whether a function behaves correctly, invariant-driven reasoning asks a broader question: can any sequence of otherwise valid actions cause something that should never happen?
These invariants are often economic or operational rather than purely technical: the protocol must remain solvent, users should not be able to extract more value than they provide, or one participant should not be able to unfairly benefit at the expense of another. Making these properties explicit also makes tools such as invariant testing, property-based testing, and formal verification much more useful. Proving that code behaves correctly only matters if the properties being proved are the ones keeping the system secure.
Composability is one of the defining features of DeFi. Protocols integrate with each other, reuse existing primitives, and become building blocks for entirely new applications. This makes development faster and more flexible, but it also means that protocols combine more than functionality: they combine assumptions, invariants, and edge cases. A contract may be perfectly safe in the environment it was designed for, but small changes in how it is used by other systems can surface unexpected behavior.
Reasoning about this is difficult because an integration can change the economic meaning of otherwise normal behavior. For example, a vault that allows users to withdraw at any time may be perfectly safe on its own. But if another protocol starts accepting shares in that vault as collateral, the timing and availability of those withdrawals can suddenly become important to the solvency of an entirely different system. The vault's code has not changed, but the consequences of its behavior have.
.png)
Composability can also create feedback loops between protocols and the markets they depend on. A protocol might rely on an asset maintaining a certain level of liquidity, while actions taken by that same protocol during volatile conditions reduce that liquidity even further. A contract cannot be considered secure without context. Every new integration expands the environment the protocol operates in, and with it, the assumptions and risks that need to be considered.
Calling a protocol non-custodial is useful because it means users interact directly with smart contracts rather than handing control of their funds to an intermediary. But as protocols have become more complex, that distinction no longer tells us everything about who can influence the system. A protocol can be non-custodial while still giving significant control to administrators, governance, or other external actors.
For example, an administrator may be able to change important parameters, upgrade contracts, or pause the protocol during an emergency. Governance may be able to make similar changes through voting, while oracles, relayers, and sequencers can influence how the protocol behaves without ever directly holding user funds. These powers are not necessarily a problem and are often required for a protocol to operate safely. What matters is understanding exactly what each actor can control, when they can exercise that control, and what assumptions are being made about them.
Composability can extend these trust relationships even further. If one protocol depends on another protocol that can be upgraded by governance, users of the integrating protocol now indirectly depend on that governance as well. The code they interact with may not have changed, but the people and systems they rely on have. Rather than treating control as custodial or non-custodial, it is more useful to ask a straightforward question: who can influence the outcome, and what exactly can they do?
Security is a property of the system that code operates within, not of the code alone. A protocol can be free from obvious implementation bugs and still fail because an assumption no longer holds, an important invariant is broken, or an external integration introduces behavior that was never originally considered. Looking beyond the code means understanding these dependencies before they become problems, and asking whether the contracts work as intended and whether the wider system remains safe when conditions are less than ideal.
At Nethermind Security, this is the perspective we bring to our reviews. Alongside the code, we consider the assumptions, invariants, integrations, and trust boundaries that determine how a protocol will behave once it is deployed and interacting with the wider ecosystem. If you are preparing for an audit or want to take a broader look at your protocol's security model, you can learn more at Nethermind Security.