Expected : The collectFee
function should securely transfer ETH from the contract to the collector without allowing reentry attacks.
Bug : The function uses call{value: address(this).balance}
to send ETH, which forwards all remaining gas and allows the recipient to reenter the contract before the state is updated, potentially draining funds.
Likelihood :
Medium : Requires the collector address to be a malicious contract with a fallback/receive function to exploit reentrancy.
Impact :
Medium : Attackers could drain ETH balances by reentering collectFee
before the state is updated, leading to fund loss.
Explanation :
When collectFee
sends ETH via call
, the malicious collector’s fallback function reenters collectFee
before the contract’s balance is updated. This repeats until the ETH balance is drained.
Steps :
Limit Gas in Call : Add a gas stipend (e.g., gas: 30000) to prevent complex reentry logic in the fallback function.
Use Address.sendValue : Replace call with OpenZeppelin’s Address.sendValue, which enforces a 2300 gas forward (safe for ETH transfers):
Address.sendValue(payable(s_collector), address(this).balance);
Apply Checks-Effects-Interactions Pattern : Update state variables before external calls to prevent reentry on stale data.
Rationale :
Limiting gas or using sendValue blocks reentrancy by restricting execution in the recipient’s fallback function. This ensures secure ETH transfers without fund loss risks.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.
The contest is complete and the rewards are being distributed.