Solidity Solidity Security and Vulnerabilities 2 — Questions and Answers
Question 1: What vulnerability arises when Solidity arithmetic operations exceed the maximum or minimum value of the data type?
- Integer overflow/underflow (Correct answer)
- Reentrancy
- Access control flaw
- Timestamp dependence
Correct answer: Integer overflow/underflow
Integer overflow/underflow occurs when arithmetic results exceed the bounds of the integer type, wrapping around to unexpected values.
Question 2: In Solidity 0.8.x, what happens when an arithmetic overflow occurs by default?
- The transaction reverts automatically (Correct answer)
- The value wraps around silently
- A warning is emitted but execution continues
- The contract is paused
Correct answer: The transaction reverts automatically
Solidity 0.8 introduced built-in checked arithmetic, so overflow/underflow automatically reverts the transaction instead of wrapping values.
Question 3: What attack vector is created when a contract uses `block.timestamp` as a source of randomness?
- Miners can slightly manipulate the timestamp to influence the outcome (Correct answer)
- Timestamp values are always zero on testnet
- Block timestamps are always equal to block numbers
- Using timestamps causes integer overflow
Correct answer: Miners can slightly manipulate the timestamp to influence the outcome
Miners (or validators) have limited ability to adjust `block.timestamp`, allowing them to influence randomness-dependent outcomes like lotteries.
Question 4: What is a 'flash loan attack' in the context of DeFi smart contracts?
- Exploiting price oracles or governance by borrowing large sums within a single transaction (Correct answer)
- Stealing contract funds using delegatecall
- Bypassing access modifiers using assembly
- Depleting a contract's ETH balance with microtransactions
Correct answer: Exploiting price oracles or governance by borrowing large sums within a single transaction
Flash loan attacks use uncollateralized loans borrowed and repaid within one transaction to manipulate market prices or governance votes.
Question 5: What is the risk of using `delegatecall` to an untrusted contract?
- The callee can overwrite the caller's storage with malicious data (Correct answer)
- The callee receives the caller's ETH balance permanently
- The callee's storage layout is used instead of the caller's
- It always reverts when used in a loop
Correct answer: The callee can overwrite the caller's storage with malicious data
With `delegatecall`, the called contract's code runs in the caller's storage context, so a malicious callee can corrupt or drain the caller's state.
Question 6: What security issue arises from 'signature malleability' in Solidity ECDSA verification?
- An attacker can produce an alternate valid signature for the same message to bypass replay protection (Correct answer)
- Signatures expire after one block
- Only the contract owner can verify signatures
- ecrecover always returns address(0) for invalid sigs
Correct answer: An attacker can produce an alternate valid signature for the same message to bypass replay protection
ECDSA signatures have two valid forms per message; if a contract only tracks one form, an attacker can replay the alternate form to bypass nonce-based replay protection.
What vulnerability arises when Solidity arithmetic operations exceed the maximum or minimum value of the data type?