§01SPEC · DESIGNING-CONTRACTS-FOR-SECURITY-FROM-THE-START
Designing contracts for security from the start
A smart contract often controls real money and cannot easily be changed after deployment, so security must shape the design rather than being checked only at the end. Simple contracts with clear responsibilities are easier to reason about, test and audit than large contracts that try to do everything.
Reuse audited building blocks wherever possible. Libraries such as OpenZeppelin Contracts provide well-reviewed implementations of tokens, access control and upgrade patterns. Writing these components from scratch adds risk without adding value, because attackers study custom code closely for subtle mistakes.
Think about privileged roles early. Who can pause the contract, change parameters or upgrade code? Each privilege is a potential attack target and a trust assumption for users. Multisig wallets, timelocks and clearly documented permissions reduce both risk and user concern. Model what can go wrong: reentrancy, price manipulation through oracles or flash loans, rounding errors, front-running and unexpected interactions with other protocols. Writing these threats down before coding guides both implementation and testing.
