Ethereum Smart Contracts Explained: The Programs That Run DeFi
Smart contracts are self-executing programs on Ethereum that power all of DeFi, NFTs, and DAOs. This guide explains what they are, how they work, and their risks.
A smart contract is a program stored on a blockchain that automatically executes when predefined conditions are met. No intermediary needed: the code enforces the agreement. Every DeFi protocol — Uniswap, Aave, Compound — is a set of smart contracts running on Ethereum.
How Smart Contracts Work
When you interact with Uniswap, you send a transaction to the Uniswap smart contract. The contract checks your balance, calculates the swap rate using the AMM formula, transfers tokens, and updates state — all atomically (either everything happens or nothing happens) and transparently on-chain.
Smart Contract Risks
- Code bugs: a flaw in contract logic can be exploited to drain funds (e.g. The DAO hack 2016)
- Immutability: once deployed, contracts cannot be changed (unless built with upgradeability)
- Oracle manipulation: contracts that rely on external price feeds can be manipulated
- Composability risks: protocols built on other protocols inherit their risks
Audits and Verification
Reputable DeFi protocols have their smart contracts audited by security firms (Certik, Trail of Bits, OpenZeppelin). Audits reduce but do not eliminate risk — they are a historical snapshot, not a guarantee. The best indicator of contract safety is time: protocols with $1B+ TVL and years without hacks have demonstrated resilience.