Chapter 11

Security Basics

Smart contract security is about assuming the environment is adversarial. Any public function may be called in unexpected order, from unexpected contracts, and with incentives aligned against you rather than with you.

Reentrancy is a classic beginner example because it shows how a contract can hand control away too early. If external code runs before internal bookkeeping is finished, an attacker may re-enter and repeat the same action.

This lesson generalizes beyond reentrancy. Access control, oracle design, and emergency pauses all come from the same mindset: assume inputs can be hostile and design so a single mistake cannot cascade into full loss.

Simplicity is a security feature because fewer moving parts are easier to test, audit, and reason about under stress. Many expensive exploits come from code that tried to be clever before it was proven safe.