DeFi / 12 min read
DeFi for Beginners: How Applications Work and What Can Go Wrong
A practical beginner’s guide explaining DeFi building blocks (lending pools, AMMs, collateral, flash loans, approvals, oracles, governance), how funds flow, common failure modes, step‑by‑step safety practices, comparisons of key mechanisms, and a concise FAQ for everyday users.
Educational guide · Sources checked before publication
What is DeFi and why it’s different
Decentralized finance (DeFi) refers to financial products and services built on blockchains—commonly Ethereum—that let anyone with an internet connection lend, borrow, trade and provide liquidity without trusting a central institution. Unlike a bank, DeFi systems are composed of smart contracts: open programs deployed to blockchain addresses that hold funds and execute code according to predefined rules. Ethereum.org describes these as composable building blocks: protocols can interoperate because contracts are public and callable by other contracts.
Because smart contracts execute deterministically onchain, all interactions are visible and irreversible once mined. That transparency and composability create powerful innovation but also concentrated technical and operational risks: a mistake or exploit in one protocol can affect many others that depend on it.
How smart contracts power DeFi
Smart contracts are programs deployed to a blockchain address that store state (balances, variables) and define functions users and other contracts can call. When you interact with a DeFi app you send a transaction that invokes a contract function; the contract then updates state or moves tokens according to its code. Ethereum.org explains that contracts are immutable by default: the deployed code is what runs, and behavior follows that code unless the contract was designed to permit upgrades.
Because contracts and transactions are public, anyone can read the code and the onchain history. Composability means protocols reuse each other’s interfaces or call each other directly: for example, a lending protocol may accept tokens minted by another protocol, or an automated market maker (AMM) price feed could be used by a borrowing protocol. This interconnection improves efficiency but increases systemic risk: a bug in one widely used contract can cascade to others.
Lending pools, collateral and liquidations
Many DeFi lending platforms use pooled liquidity. Lenders deposit assets into a pool and receive tokens representing their share; borrowers draw from that pool by locking collateral. To protect lenders from default, most DeFi loans require over‑collateralization: borrowers lock collateral with a higher value than the loan principal. This design removes the need to verify identities but introduces automatic collateral management mechanics.
If the value of a borrower's collateral falls relative to the borrowed amount (for example because the collateral price drops), the protocol may trigger an automatic liquidation: the collateral is sold or partially sold to repay the loan. Liquidation protects the pool but can produce losses for the borrower and sometimes for liquidity providers if prices move quickly or liquidation mechanisms produce slippage.
Understanding liquidation thresholds, collateral factors, and maintenance margins for any lending protocol you use is essential. These parameters determine how much buffer your collateral has before liquidation and how partial liquidations are executed.
- Lenders add funds to a shared pool; borrowers draw from the pool using collateral.
- Borrowers are usually required to over‑collateralize; liquidation occurs automatically if collateral falls below protocol ratios.
AMMs (automated market makers) and liquidity provision
Automated market makers (AMMs) replace traditional order books with liquidity pools where pricing is governed by a deterministic formula (such as the constant product formula used by many AMMs). Liquidity providers deposit token pairs into a pool and earn trading fees proportional to their share, but they face impermanent loss: the divergence in value compared with simply holding the tokens when relative prices change.
AMMs make swapping tokens permissionless and composable—contracts can route trades through multiple pools to find liquidity. However, pool contracts hold user funds, so any bug, front‑end mismatch, or incorrect contract address can expose deposits to theft or keep them locked.
- Liquidity providers deposit token pairs into pools and earn fees.
- Pricing follows a formula, which can cause impermanent loss when token prices diverge.
Flash loans: how they work and why they matter
Flash loans are uncollateralized loans that must be borrowed and repaid within a single blockchain transaction. If repayment does not occur by the end of that transaction, the entire transaction reverts so the loan never happened. This atomic property enables legitimate uses—arbitrage, collateral swaps, and complex onchain transactions—but also enables attackers to combine rapid capital with manipulative actions within the same transaction to exploit weak protocols.
A common flash‑loan attack pattern is to borrow a large amount, use it to manipulate an onchain price or oracle-dependent market, execute trades that profit from the manipulated state, and then repay the loan, all inside one transaction. Because everything happens atomically, the attacker leaves the system with profit and the protocol with losses if protections are insufficient. Flash loans thus highlight the importance of robust oracle design, slippage limits, and composability-aware security.
- Flash loans must be repaid within the same transaction or the transaction reverts.
- Attackers use flash loans to manipulate prices or exploit protocol assumptions in a single atomic operation.
Oracles: feeding off‑chain data to smart contracts
Smart contracts cannot natively access external data (like market prices or interest rates). Oracles are the systems or services that supply off‑chain information to contracts. Because many DeFi mechanisms—liquidations, collateral valuation, price‑dependent settling—depend on accurate feeds, oracle failures or manipulation are frequent vectors for exploits.
Oracles can be implemented in different ways (single source, aggregated networks, time‑weighted averages). Each approach has trade‑offs between timeliness, decentralization, and attack surface. Protocol designers must choose oracle models appropriate to their use case and implement safeguards like oracle price bounds, fallback mechanisms, or multi‑source aggregation to reduce manipulation risk.
- Contracts rely on oracles to import external prices; oracle failures can lead to wrongful liquidations or exploitable states.
- Using multiple aggregated sources or time‑weighted averages helps reduce single‑source manipulation but introduces complexity.
Approvals, allowances and wallet safety
How to check and revoke token approvals
ERC‑20 token standards require users to grant an allowance (approval) for a contract to transfer tokens on their behalf. Approvals are powerful: a malicious contract with an allowance can move approved tokens from your wallet. Ethereum.org warns that granting unlimited allowances increases exposure because a compromised or malicious contract can drain funds up to the allowed amount.
Safe practices include granting minimal or single‑use approvals when possible, checking and revoking allowances regularly, and verifying the exact contract address and intended action before signing. Because blockchain transactions are irreversible, once you approve or send tokens, you cannot undo the onchain action.
- Open a reputable allowance-checking tool or your wallet provider’s permissions page (verify you are using the official interface).
- Review the list of contracts with allowances and note large or unlimited approvals.
- For unwanted approvals, use the wallet or the allowance tool to set the allowance to zero or to a minimal amount and confirm the revocation in a signed transaction.
- After revocation, verify onchain that the allowance has been updated. Keep in mind revocation itself is an onchain transaction that costs gas.
Multisignature wallets, hardware wallets and custody choices
Multisignature (multisig) smart contracts require multiple keys to approve a transaction (for example, 2‑of‑3). Multisigs reduce single‑key risk but are themselves smart contracts and therefore subject to contract bugs, upgradeability risks, or admin keys if misconfigured. Ethereum.org highlights multisig as a useful tool for shared custody, governance treasuries, and higher‑value accounts—while noting contract security must be assessed.
Hardware wallets keep private keys off general‑purpose devices and sign transactions in a secure element, reducing the risk of key exfiltration from malware. They do not remove the need to verify transaction details on the hardware device display. Choosing between self‑custody (hardware wallet, multisig) and custodial services depends on your threat model; each option shifts risk rather than eliminates it.
- Multisig reduces single‑key failure but adds smart‑contract and coordination complexity.
- Hardware wallets protect keys from online compromise but require user diligence to verify recipients and amounts.
Composability: power and systemic fragility
Composability—the ability for contracts to call each other and reuse code—is often cited as DeFi’s greatest strength: it enables fast innovation and complex financial primitives. However, composability also creates systemic fragility. When protocols depend on one another’s tokens, price oracles, and liquidity, a failure (bug, governance attack, oracle manipulation) in one protocol can propagate losses to others that rely on it.
Assess risks across the dependency graph when interacting with DeFi: Which protocols provide price data? Which tokens are used as collateral elsewhere? Are there trusted admin keys or upgrade mechanisms? Knowing these dependencies helps you estimate how an external failure could affect your positions.
Comparison: key DeFi mechanisms and their trade‑offs
This table summarizes core mechanisms, where risk concentrates, and practical precautions to reduce exposure.
| Mechanism | How it works | Primary risks | Practical precautions |
|---|---|---|---|
| Lending pools | Pooled liquidity where lenders earn interest and borrowers post collateral | Liquidations, protocol bugs, oracle errors | Understand collateral factors, set alerts, diversify across protocols |
| AMMs / liquidity pools | Automated pricing via formulas; LPs earn fees but bear impermanent loss | Smart contract bugs, front‑end spoofing, impermanent loss | Use audited pools, verify contract addresses, limit exposure size |
| Flash loans | Uncollateralized loan repaid within one transaction | Price/oracle manipulation, composability attacks | Protocols should use robust oracle designs and slippage limits; users should be cautious when composing contracts |
| Oracles / price feeds | Off‑chain data fed onchain | Manipulation, single‑source failures | Prefer aggregated/time‑weighted oracles; protocol-level bounds and monitors |
| Approvals (token allowances) | User grants contract permission to transfer tokens | Malicious/compromised contracts draining approved tokens | Grant minimal allowances, check and revoke permissions regularly |
| Multisig / hardware custody | Requires multiple signatures; hardware keeps keys offline | Contract bugs in multisig, human coordination errors | Use well-audited multisig implementations; verify hardware device displays |
Practical, cautious step‑by‑step processes for common tasks
The following step‑by‑step procedures describe safe processes for interacting with DeFi. These are operational tips—not exhaustive security guarantees—but they reduce common human error vectors and follow best practices described by Ethereum.org.
- Connecting a wallet to a DeFi app:
- 1. Confirm you are on the correct network (e.g., Ethereum mainnet) and open the official frontend; verify the site's identity using trusted sources rather than search results alone.
- 2. Use a hardware wallet or a secure browser profile without unrelated extensions when interacting with high‑value contracts.
- 3. Check the contract address the frontend targets (the transaction’s 'to' address) and the function call data in your wallet prompt; confirm amounts and recipient addresses on your hardware device screen before approving.
- 4. For approvals, prefer explicit single‑use approvals when available; otherwise set the minimum required allowance and schedule periodic revocations.
- Swapping tokens on a DEX safely:
- 1. Verify you’re interacting with the official DEX contract, not a cloned frontend.
- 2. Set maximum slippage tolerances appropriate for the tokens and expected liquidity; higher slippage opens you to sandwich attacks or price manipulation.
- 3. Check gas price and confirm the exact token addresses and amounts in your signing device before approving.
- Revoking approvals:
- 1. Use a reputable allowance-checking interface (confirm you are using the official site or an audited tool).
- 2. Identify unlimited or large allowances and revoke them by setting the allowance to zero in a signed transaction.
- 3. Remember revocation costs gas and is itself an onchain action; periodically re‑check allowances.
Limitations of smart contract safety and remaining uncertainties
Smart contracts enforce code, not intent. If contract logic contains a bug, rules are executed exactly as written; immutability means that unless a contract was designed with a secure, transparent upgrade mechanism, the only remedy may be external governance, a hard fork, or developer intervention—none of which are guaranteed. Ethereum.org emphasizes that immutability and composability create irreversible interactions and dependencies.
Similarly, multisig and upgradeable patterns introduce governance and admin keys that must be trusted to act correctly. Oracles are critical but imperfect: they add offchain trust anchors; their design determines how resilient the system is to manipulation. Finally, public, pseudonymous ledgers make positions visible—privacy is limited and can allow attackers to target large positions.
Frequently asked questions (FAQ)
Más preguntas frecuentes
Q: What is the single most important thing to remember when using DeFi?
A: Understand that transactions and contract approvals are irreversible onchain. Verify addresses, contract destinations, and approvals before signing and use hardware wallets or multisigs for significant funds.
Q: How do liquidations work and can I avoid them?
A: Liquidations occur when collateral value falls below protocol thresholds; avoid liquidation by keeping collateralization ratios well above maintenance levels, diversifying collateral, and setting price alerts or automatic top-ups where supported.
Q: Are flash loans inherently malicious?
A: No. Flash loans are neutral tools enabling legitimate atomic operations (arbitrage, collateral swaps). However, attackers use them to perform complex manipulations within one transaction; protocol designers must assume attackers can access flash capital.
Q: Should I grant unlimited token approvals?
A: Granting unlimited allowances increases exposure because a compromised or malicious contract can transfer the approved amount. Prefer minimal, single‑use approvals and revoke allowances you no longer need.
Q: Do hardware wallets remove all risk?
A: Hardware wallets significantly reduce key-exfiltration risk but do not remove risks from malicious contracts, phishing frontends, or user errors. Always verify transaction data on the device and confirm the contract address and function.
Q: Can a multisig be safer than a single key?
A: Multisigs reduce single-key compromise risk but are still smart contracts that may have bugs or admin controls; use audited multisig implementations and understand governance/upgrade paths.
Conclusion: cautious participation and ongoing learning
DeFi opens powerful, permissionless financial primitives enabled by smart contracts, composability and open liquidity. That same openness concentrates technical and operational risks: immutable code, oracle dependencies, composability cascades, approvals, and human error are recurring causes of loss. Ethereum.org’s guidance emphasizes recognizing these architectural limits and applying practical defenses—hardware wallets, minimal approvals, verified frontends, and cautious exposure sizing.
For beginners the safest path is to learn the mechanisms, practice with small amounts, use hardware or multisig custody for meaningful funds, and treat any protocol dependency map as part of your risk assessment. No single control eliminates all risks: safety is a layered approach combining secure key custody, careful approval management, verified contracts, and awareness of oracle and composability risks.
Sources & further reading
Sources and methodology · Report a correction
For information only. Not financial advice.