Blockchain Smart Contract Vulnerabilities — Questions and Answers
Question 1: What is a common vulnerability that allows repeated withdrawals in smart contracts?
- Race condition
- Integer overflow
- Reentrancy (Correct answer)
- DoS attack
Correct answer: Reentrancy
Reentrancy attacks occur when a function makes an external call to another untrusted contract before it resolves its own logic.
Question 2: Why is input validation critical in smart contracts?
- To improve transaction speed
- To prevent contract duplication
- To ensure logical correctness and safety (Correct answer)
- To optimize gas usage
Correct answer: To ensure logical correctness and safety
Without input validation, contracts can be tricked into performing unintended actions or altering expected outcomes.
Question 3: Which vulnerability can allow funds to be locked indefinitely in a contract?
- Reentrancy
- Fallback function flaw (Correct answer)
- Timestamp dependency
- Short address attack
Correct answer: Fallback function flaw
A contract with a missing or broken fallback mechanism may prevent fund retrieval, leading to permanent fund loss.
Question 4: What is the purpose of using the 'checks-effects-interactions' pattern?
- To save gas
- To handle overflow errors
- To defend against reentrancy attacks (Correct answer)
- To improve test coverage
Correct answer: To defend against reentrancy attacks
This pattern reduces the risk of reentrancy by ensuring that all internal logic updates occur before calling external contracts.
Question 5: Which tool is commonly used to audit smart contracts for vulnerabilities?
- GasNow
- MythX (Correct answer)
- Chainlink
- Metamask
Correct answer: MythX
MythX is a widely used security analysis tool for detecting smart contract vulnerabilities through automated testing.
Question 6: How can smart contracts defend against integer overflows?
- Avoiding arithmetic operations
- Using SafeMath libraries (Correct answer)
- Adding more gas to transactions
- Limiting contract size
Correct answer: Using SafeMath libraries
Using safe math libraries like OpenZeppelin helps prevent overflow errors by checking calculations before performing them.
What is a common vulnerability that allows repeated withdrawals in smart contracts?