Back to courses
Crypto & Web3 Deep Dives beginner

DeFi hacks and security

Duration0 hours
Modules7
ForGeneral public, lifelong learners
Video1-2min
Get started — free →

Course outline

Module 1 Module 1: Understanding DeFi Architecture

Understanding DeFi Architecture

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. What is a key component of DeFi architecture that allows for trustless transactions?
  • A. Centralized exchanges
  • B. Smart contracts ✓
  • C. Regulatory oversight
  • D. Traditional banking systems

Why: Smart contracts are self-executing contracts with the terms of the agreement directly written into code, enabling trustless transactions.

Q2. Which of the following is NOT a characteristic of DeFi platforms?
  • A. Permissionless access
  • B. Centralized control ✓
  • C. Transparency
  • D. Open source code

Why: DeFi platforms are designed to be decentralized, so centralized control is not a characteristic of them.

Q3. What does the term 'immutability' refer to in the context of blockchain and DeFi?
  • A. The ability to change transaction records
  • B. The ability to delete transaction records
  • C. The inability to alter transaction records once they are added to the blockchain ✓
  • D. The ability to hide transaction records

Why: Immutability means that once a transaction is recorded on the blockchain, it cannot be altered or deleted.

Q4. Which of the following is a common use case for DeFi protocols?
  • A. Issuing traditional bank loans
  • B. Providing decentralized lending and borrowing services ✓
  • C. Managing centralized investment funds
  • D. Processing credit card payments

Why: DeFi protocols commonly provide decentralized lending and borrowing services without the need for intermediaries.

Q5. What is the primary purpose of oracles in DeFi systems?
  • A. To execute smart contracts
  • B. To provide real-world data to smart contracts ✓
  • C. To secure the blockchain network
  • D. To manage user identities

Why: Oracles act as bridges between smart contracts and the outside world by providing real-world data to the blockchain.

Module 2 Module 2: Common DeFi Vulnerabilities

Common DeFi Vulnerabilities

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. What is a common vulnerability in DeFi protocols that allows attackers to drain funds by exploiting reentrancy in smart contracts?
  • A. Integer Overflow
  • B. Reentrancy ✓
  • C. Front Running
  • D. Timestamp Dependency

Why: Reentrancy is a vulnerability where a contract calls an external contract before completing its own execution, allowing an attacker to drain funds.

Q2. Which of the following is a vulnerability caused by incorrect use of external calls and not properly checking the state of the contract before sending ether?
  • A. Front Running
  • B. Reentrancy
  • C. Integer Underflow
  • D. Unchecked External Calls ✓

Why: Unchecked External Calls occur when a contract sends ether to an external contract without verifying its state, which can lead to loss of funds.

Q3. Which of the following vulnerabilities can be exploited by an attacker who submits a transaction before a user's transaction, thereby manipulating the outcome?
  • A. Reentrancy
  • B. Front Running ✓
  • C. Integer Overflow
  • D. Timestamp Dependency

Why: Front Running is a vulnerability where an attacker submits a transaction before a user's transaction to manipulate the outcome, often seen in decentralized exchanges.

Q4. Which vulnerability occurs when a contract uses the block.timestamp for critical logic and is susceptible to manipulation by miners?
  • A. Integer Overflow
  • B. Timestamp Dependency ✓
  • C. Reentrancy
  • D. Unchecked External Calls

Why: Timestamp Dependency is a vulnerability where the contract's logic depends on block.timestamp, which can be manipulated by miners to exploit the protocol.

Q5. What type of vulnerability occurs when a contract does not properly validate inputs, leading to unexpected behavior or overflow/underflow in calculations?
  • A. Unchecked External Calls
  • B. Integer Overflow/Underflow ✓
  • C. Reentrancy
  • D. Front Running

Why: Integer Overflow/Underflow occurs when a contract does not validate inputs, leading to incorrect calculations and potential loss of funds.

Module 3 Module 3: Smart Contract Auditing

Smart Contract Auditing

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. What is the primary goal of smart contract auditing?
  • A. To increase the gas fees
  • B. To identify and mitigate security vulnerabilities ✓
  • C. To improve the user interface
  • D. To increase the number of users

Why: Smart contract auditing focuses on finding and fixing security issues before deployment to ensure the contract is safe and reliable.

Q2. Which of the following is a common vulnerability in smart contracts?
  • A. High gas efficiency
  • B. Reentrancy ✓
  • C. Optimized code
  • D. Well-documented functions

Why: Reentrancy is a well-known vulnerability where a contract can be attacked by a malicious contract calling back into the original contract before the initial transaction is completed.

Q3. What tool is commonly used for static analysis in smart contract auditing?
  • A. Truffle
  • B. Slither ✓
  • C. Remix
  • D. Hardhat

Why: Slither is a popular static analysis tool that helps detect common vulnerabilities in Solidity code.

Q4. Which of the following is NOT a best practice for smart contract security?
  • A. Using well-audited libraries
  • B. Keeping the contract logic simple
  • C. Hardcoding sensitive information ✓
  • D. Implementing access control

Why: Hardcoding sensitive information is a bad practice as it can expose critical data and make the contract vulnerable to attacks.

Q5. What does a 'reentrancy guard' help prevent in a smart contract?
  • A. Gas limit overflow
  • B. Reentrancy attacks ✓
  • C. Integer overflow
  • D. Front-running

Why: A reentrancy guard is a mechanism used to prevent reentrancy attacks by ensuring that a function cannot be called again before the initial execution is completed.

Module 4 Module 4: Reentrancy Attacks in DeFi

Reentrancy Attacks in DeFi

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. What is a reentrancy attack in DeFi?
  • A. A type of phishing attack
  • B. An attack where a contract is called multiple times before the initial call completes ✓
  • C. An attack that exploits a vulnerability in the blockchain protocol
  • D. An attack that steals private keys

Why: A reentrancy attack occurs when a contract is called recursively before the initial call has completed, often leading to unexpected behavior or loss of funds.

Q2. Which of the following is a common example of a reentrancy attack in DeFi?
  • A. The DAO hack ✓
  • B. The Mt. Gox hack
  • C. The Bitfinex hack
  • D. The Parity wallet hack

Why: The DAO hack was a well-known example of a reentrancy attack, where attackers exploited a recursive call vulnerability to drain funds.

Q3. What is the main vulnerability that reentrancy attacks exploit?
  • A. Integer overflow
  • B. Unprotected external calls ✓
  • C. Missing access control
  • D. Improper error handling

Why: Reentrancy attacks typically exploit unprotected external calls, where a contract calls another contract without ensuring that the call has completed before proceeding.

Q4. Which design pattern is commonly used to prevent reentrancy attacks in Solidity?
  • A. Modifier pattern
  • B. Reentrancy guard pattern ✓
  • C. Factory pattern
  • D. Proxy pattern

Why: The reentrancy guard pattern is used to prevent reentrancy attacks by ensuring that a contract cannot be reentered during a function call.

Q5. What is the purpose of using the 'Checks-Effects-Interactions' pattern in Solidity?
  • A. To improve gas efficiency
  • B. To prevent reentrancy attacks ✓
  • C. To increase code readability
  • D. To optimize contract storage

Why: The 'Checks-Effects-Interactions' pattern helps prevent reentrancy attacks by ensuring that state changes are made before external calls are made.

Module 5 Module 5: Flash Loan Exploits

Flash Loan Exploits

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. What is a flash loan?
  • A. A loan that requires collateral
  • B. A loan that is repaid within the same blockchain transaction ✓
  • C. A loan that is taken out over multiple blocks
  • D. A loan that requires a credit check

Why: Flash loans are unique to DeFi and allow users to borrow assets without collateral, as long as the loan is repaid within the same transaction.

Q2. Which of the following is a common use case for flash loans?
  • A. Paying taxes
  • B. Arbitrage ✓
  • C. Buying groceries
  • D. Saving for retirement

Why: Flash loans are often used for arbitrage opportunities, where traders can exploit price differences across different DeFi platforms.

Q3. What is the main risk associated with flash loans?
  • A. High interest rates
  • B. Exploitation by hackers ✓
  • C. Lack of liquidity
  • D. Regulatory issues

Why: Flash loans can be exploited by hackers if there are vulnerabilities in the smart contracts or if the borrower fails to repay the loan within the same transaction.

Q4. What is the primary requirement for a successful flash loan?
  • A. High collateral
  • B. Repaying the loan within the same transaction ✓
  • C. Approval from a bank
  • D. A long-term credit history

Why: The key requirement for a flash loan is that the loan must be repaid within the same blockchain transaction, ensuring no loss to the lender.

Q5. Which of the following is NOT a characteristic of flash loans?
  • A. No collateral required
  • B. Used for liquidity mining
  • C. Repaid in the same transaction
  • D. Require a long-term loan agreement ✓

Why: Flash loans are typically short-term and do not require long-term agreements, making option D incorrect.

Module 6 Module 6: Governance Hacks and Risks

Governance Hacks and Risks

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. What is a common risk associated with decentralized governance in DeFi projects?
  • A. Centralized control by a single entity
  • B. Vote manipulation through token concentration ✓
  • C. High transaction fees on the blockchain
  • D. Lack of user participation

Why: Token concentration can allow a small group of holders to dominate voting outcomes, leading to potential manipulation of governance decisions.

Q2. Which of the following is a potential consequence of a governance hack?
  • A. Increased liquidity in the market
  • B. Loss of user trust and funds ✓
  • C. Improved transparency in decision-making
  • D. Higher token prices

Why: A governance hack can result in unauthorized changes to project parameters, leading to loss of user trust and potentially funds if exploited.

Q3. What is a DAO (Decentralized Autonomous Organization)?
  • A. A traditional company with a board of directors
  • B. A decentralized organization governed by smart contracts ✓
  • C. A centralized financial institution
  • D. A government regulatory body

Why: A DAO is a decentralized organization that operates through smart contracts and is governed by its members, typically via token voting.

Q4. Which of the following is a best practice for secure governance in DeFi?
  • A. Allowing unlimited voting power to large token holders
  • B. Implementing time locks for proposal execution ✓
  • C. Ignoring community feedback in decision-making
  • D. Using unverified smart contracts for governance

Why: Time locks help prevent rushed or malicious changes by introducing a delay between proposal approval and execution.

Q5. What is a 'governance token' typically used for in DeFi projects?
  • A. To purchase goods and services
  • B. To vote on project decisions and proposals ✓
  • C. To pay for transaction fees
  • D. To store value like a traditional currency

Why: Governance tokens grant holders the right to participate in decision-making processes, such as voting on proposals and changes to the project.

Module 7 Module 7: Secure Coding Practices for DeFi

Secure Coding Practices for DeFi

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. What is a common practice to prevent reentrancy attacks in DeFi contracts?
  • A. Using only view functions
  • B. Using checks-effects-interactions pattern ✓
  • C. Using only external functions
  • D. Using only internal functions

Why: The checks-effects-interactions pattern ensures that state changes are made before any external calls, reducing the risk of reentrancy attacks.

Q2. Which of the following is a recommended practice for managing user funds in DeFi contracts?
  • A. Allowing direct transfers to user addresses
  • B. Using a centralized wallet to hold user funds
  • C. Using a multi-signature wallet for fund management ✓
  • D. Using a single private key for all transactions

Why: Using a multi-signature wallet adds an extra layer of security and control over fund management in DeFi contracts.

Q3. What is the purpose of using a 'require' statement in Solidity?
  • A. To log events
  • B. To enforce conditions and revert transactions if not met ✓
  • C. To create a new contract
  • D. To send Ether to a specific address

Why: The 'require' statement is used to enforce conditions and revert transactions if those conditions are not met, ensuring the contract behaves as intended.

Q4. Which of the following is a good practice for handling errors in DeFi contracts?
  • A. Ignoring errors to avoid gas costs
  • B. Using revert statements with descriptive error messages ✓
  • C. Allowing errors to propagate without handling them
  • D. Using unchecked arithmetic operations

Why: Using revert statements with descriptive error messages helps in debugging and provides clarity on what went wrong in the contract execution.

Q5. What is the main benefit of using OpenZeppelin's SafeMath library in DeFi contracts?
  • A. It reduces gas costs
  • B. It prevents integer overflow and underflow issues ✓
  • C. It allows for faster transaction processing
  • D. It increases the size of the contract

Why: The SafeMath library prevents integer overflow and underflow, which are common vulnerabilities in DeFi contracts.

Stay in the loop on this course.

We’ll email you when new modules or related material drops. No spam.

Built with Fragment Language. Sovereign architecture — no third-party trackers.
FragRun.mfgAFImemoryFGOwnership: B-Systems.ee