Blockchain Security Training DeFi Security and Audits 3 — Questions and Answers
Question 1: What is the danger of an unprotected 'delegatecall' to an attacker-controlled address?
- The attacker's code runs in the caller's storage context and can overwrite state (Correct answer)
- It only wastes gas
- It reverts automatically
- It can only read, never write
Correct answer: The attacker's code runs in the caller's storage context and can overwrite state
delegatecall executes external code using the caller's storage, so a malicious target can rewrite the caller's variables, including ownership.
Question 2: In an upgradeable proxy pattern, what is a common security risk?
- Storage slot collisions between proxy and implementation (Correct answer)
- Too many compiler warnings
- Lack of NatSpec comments
- Higher deployment gas
Correct answer: Storage slot collisions between proxy and implementation
If the proxy and implementation use overlapping storage layouts, an upgrade can corrupt critical variables like the admin slot.
Question 3: What is a sandwich attack against a DEX trader?
- An attacker front-runs and back-runs a victim swap to profit from induced price movement (Correct answer)
- A double-spend of stablecoins
- A reentrancy on the swap callback
- A governance takeover
Correct answer: An attacker front-runs and back-runs a victim swap to profit from induced price movement
The attacker buys before the victim's trade and sells after, exploiting the price impact, a classic MEV technique.
Question 4: How can a trader reduce exposure to sandwich attacks?
- Set a tight slippage tolerance and use private transaction relays (Correct answer)
- Increase the gas price only
- Disable token approvals
- Use a larger trade size
Correct answer: Set a tight slippage tolerance and use private transaction relays
Tight slippage limits the price movement an attacker can exploit, and private relays keep the transaction out of the public mempool.
Question 5: An audit flags integer arithmetic without SafeMath in a pre-0.8.0 Solidity contract. Why?
- Unchecked overflow/underflow can corrupt balances (Correct answer)
- It increases bytecode size
- It disables events
- It blocks contract verification
Correct answer: Unchecked overflow/underflow can corrupt balances
Before Solidity 0.8.0, arithmetic did not revert on overflow, allowing balances to wrap around and be manipulated.
Question 6: What risk does an unbounded loop over a user-controlled array introduce?
- A denial-of-service if the loop exceeds the block gas limit (Correct answer)
- Reentrancy
- Oracle manipulation
- Signature replay
Correct answer: A denial-of-service if the loop exceeds the block gas limit
If an array can grow large enough that iterating it exceeds gas limits, the function becomes permanently uncallable, a DoS condition.
Question 7: Why is using 'tx.origin' for authorization a vulnerability?
- A malicious intermediary contract can phish the original signer's authority (Correct answer)
- It costs more gas than msg.sender
- It returns a random address
- It is deprecated in all versions
Correct answer: A malicious intermediary contract can phish the original signer's authority
tx.origin is the original EOA, so a user tricked into calling a malicious contract grants that contract their authority; use msg.sender instead.
What is the danger of an unprotected 'delegatecall' to an attacker-controlled address?