CCA Smart Contract Auditing Questions and Answers 1 — Questions and Answers
Question 1: An auditor is reviewing a smart contract's token distribution function, which iterates through a large, externally-provided array of recipient addresses to execute transfers. As the number of recipients grows, transactions calling this function begin to fail consistently. What is the most likely vulnerability?
- Reentrancy attack
- Denial of Service (DoS) due to block gas limit (Correct answer)
- Timestamp dependence
- Integer underflow
Correct answer: Denial of Service (DoS) due to block gas limit
This design is vulnerable to a Denial of Service (DoS) attack. Each operation within the loop consumes gas. If the array of recipients becomes too large, the total gas required to complete the loop will exceed the block's gas limit, causing any transaction that calls this function to fail. An attacker could potentially exploit this by adding many addresses to the distribution list to render the function unusable, trapping the funds.
Question 2: Which of the following tools is an auditor most likely to use for static analysis of Solidity code, which involves examining the contract's code without executing it to find common vulnerabilities and bad practices?
- Ganache
- Hardhat
- Slither (Correct answer)
- Foundry
Correct answer: Slither
Slither is a widely-used static analysis framework for Solidity that detects a broad range of vulnerabilities and code quality issues by converting the source code into an intermediate representation and running a suite of detectors. Ganache, Hardhat, and Foundry are primarily development environments and testing frameworks, not specialized static analysis tools.
Question 3: While auditing a system using a transparent proxy for upgradability, an auditor discovers the implementation contract's `initialize` function is public and lacks protection. Why does this represent a critical security risk?
- It allows anyone to bypass the proxy and mint new tokens directly.
- It can be exploited to perform a flash loan attack against the proxy's balance.
- It violates ERC-721 standards, causing incompatibility with marketplaces.
- An attacker could call `initialize` on the implementation contract directly, take ownership, and potentially self-destruct it, bricking the proxy. (Correct answer)
Correct answer: An attacker could call `initialize` on the implementation contract directly, take ownership, and potentially self-destruct it, bricking the proxy.
Even though users interact with the proxy, the implementation contract is still a deployed contract on the blockchain. If its `initialize` function is unprotected, an attacker can call it directly on the implementation contract's address. If the attacker becomes the owner of the implementation contract, they could then call a privileged function like `selfdestruct`, which would destroy the logic contract and render the proxy non-functional.
Question 4: An auditing firm is engaged to provide the highest possible level of assurance for a critical DeFi protocol's core logic. The technique they plan to use involves creating a formal specification of the contract's desired properties and using mathematical methods to prove that the code adheres to this specification under all possible conditions. What is this technique called?
- Formal verification (Correct answer)
- Fuzz testing
- Dynamic analysis
- Manual code review
Correct answer: Formal verification
Formal verification is a rigorous process that uses mathematical proofs to verify the correctness of a smart contract's code against a precise specification. Unlike testing or manual review which can find bugs, formal verification aims to prove the absence of specific types of bugs, offering the highest level of security assurance for critical properties.
Question 5: A smart contract written in an older version of Solidity (pre-0.8.0) calculates a user's reward by multiplying their stake amount by a `rewardRate`. An auditor flags a potential vulnerability where a user with a very large stake could interact with a high `rewardRate` and receive a near-zero reward. This is a classic example of what vulnerability?
- Access control violation
- Unchecked external call
- Integer overflow (Correct answer)
- Gas griefing
Correct answer: Integer overflow
This scenario describes an integer overflow. Solidity integer types have a fixed size (e.g., uint256). If an arithmetic operation's result exceeds the maximum value for that type, it 'wraps around' to zero. In this case, a massive multiplication result could overflow the uint256 limit, resulting in a very small, incorrect value. Versions of Solidity 0.8.0 and newer have built-in checks to prevent this by reverting the transaction.
Question 6: When delivering a final smart contract audit report to a client's development team, which of the following sections is the most critical for enabling them to fix the identified security flaws?
- A summary of the total person-hours spent on the audit engagement.
- Detailed findings that include a vulnerability description, severity rating, code location, and actionable remediation guidance. (Correct answer)
- The names and qualifications of the auditors who performed the review.
- A list of the automated static and dynamic analysis tools that were used during the audit process.
Correct answer: Detailed findings that include a vulnerability description, severity rating, code location, and actionable remediation guidance.
The most crucial part of an audit report for developers is the detailed findings section. This provides everything needed to understand and fix the problem: what the vulnerability is, how severe its impact could be, exactly where it is in the code, and clear advice on how to resolve it. While other sections provide context, the detailed findings are the core actionable output of the audit.
An auditor is reviewing a smart contract's token distribution function, which iterates through a large, externally-provided array of recipient addresses to execute transfers.
As the number of recipients grows, transactions calling this function begin to fail consistently.
What is the most likely vulnerability?