Normal behavior: withdrawFees() is intended to allow the owner to withdraw accumulated protocol fees only when there are no active players (i.e. the contract balance equals exactly the fees owed). The check address(this).balance == uint256(totalFees) is meant to prevent withdrawal while a raffle is in progress.
The issue: In Solidity, a contract's ETH balance can be forcibly increased without calling any function by using selfdestruct. When a contract self-destructs, it sends all its ETH to a target address — and the target contract's receive() or fallback() functions are NOT called. There is no way to reject this ETH.
An attacker can deploy a minimal contract funded with even 1 wei and call selfdestruct(payable(address(puppyRaffle))). This permanently increases address(this).balance by 1 wei, making it permanently unequal to totalFees. The strict equality check then always reverts, and the owner can never withdraw fees again — they are locked in the contract forever.
This is a well-known Solidity anti-pattern: using == instead of >= for balance checks.
Likelihood:
Any attacker can deploy a self-destructing contract and send 1 wei to PuppyRaffle at any time — no special permissions required.
The cost to execute this attack is negligible: one contract deployment + 1 wei + gas.
The attack is irreversible once executed — there is no recovery mechanism
Impact:
withdrawFees() is permanently bricked — the owner can never recover any accumulated protocol fees.
All future raffle rounds will also be unable to withdraw fees, making the protocol economically non-viable.
The locked fees grow with every raffle round but are permanently inaccessible
Replace the strict equality check with a greater-than-or-equal check. This allows withdrawal whenever the balance covers the fees owed, regardless of any extra ETH force-sent to the contract:
This change ensures that any excess ETH force-sent to the contract does not prevent fee withdrawal. The excess ETH will remain in the contract but fees can always be recovered by the owner.
## Description An attacker can slightly change the eth balance of the contract to break the `withdrawFees` function. ## Vulnerability Details The withdraw function contains the following check: ``` require(address(this).balance == uint256(totalFees), "PuppyRaffle: There are currently players active!"); ``` Using `address(this).balance` in this way invites attackers to modify said balance in order to make this check fail. This can be easily done as follows: Add this contract above `PuppyRaffleTest`: ``` contract Kill { constructor (address target) payable { address payable _target = payable(target); selfdestruct(_target); } } ``` Modify `setUp` as follows: ``` function setUp() public { puppyRaffle = new PuppyRaffle( entranceFee, feeAddress, duration ); address mAlice = makeAddr("mAlice"); vm.deal(mAlice, 1 ether); vm.startPrank(mAlice); Kill kill = new Kill{value: 0.01 ether}(address(puppyRaffle)); vm.stopPrank(); } ``` Now run `testWithdrawFees()` - ` forge test --mt testWithdrawFees` to get: ``` Running 1 test for test/PuppyRaffleTest.t.sol:PuppyRaffleTest [FAIL. Reason: PuppyRaffle: There are currently players active!] testWithdrawFees() (gas: 361718) Test result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 3.40ms ``` Any small amount sent over by a self destructing contract will make `withdrawFees` function unusable, leaving no other way of taking the fees out of the contract. ## Impact All fees that weren't withdrawn and all future fees are stuck in the contract. ## Recommendations Avoid using `address(this).balance` in this way as it can easily be changed by an attacker. Properly track the `totalFees` and withdraw it. ```diff function withdrawFees() external { -- require(address(this).balance == uint256(totalFees), "PuppyRaffle: There are currently players active!"); uint256 feesToWithdraw = totalFees; totalFees = 0; (bool success,) = feeAddress.call{value: feesToWithdraw}(""); require(success, "PuppyRaffle: Failed to withdraw fees"); } ```
The contest is live. Earn rewards by submitting a finding.
Submissions are being reviewed by our AI judge. Results will be available in a few minutes.
View all submissionsThe contest is complete and the rewards are being distributed.