The claimCut function in the Pot contract transfers tokens to a player based on the reward amount stored in playersToRewards. However, there is no explicit check to verify whether the contract has enough tokens to fulfill the transfer request.
This test case is designed to simulate an exploit scenario where a player attempts to claim more tokens than the contract currently holds.
The setUp function initializes the Pot contract with a player and sets an initial reward of 1000 tokens for this player.
Only 500 tokens are transferred to the Pot contract, which is deliberately less than the player's reward of 1000 tokens. This simulates a scenario where the contract has insufficient funds to fulfill the reward claim.
The testClaimCutRevertsIfInsufficientFunds function starts by transferring only 500 tokens to the Pot contract, explicitly setting up the test condition where the contract has insufficient funds.
The vm.startPrank(player) function simulates the player's actions. The player attempts to claim their reward using the claimCut function of the Pot contract.
The testClaimCutRevertsIfInsufficientFunds function starts by transferring only 500 tokens to the Pot contract, explicitly setting up the test condition where the contract has insufficient funds.
The vm.startPrank(player) function simulates the player's actions. The player attempts to claim their reward using the claimCut function of the Pot contract.
The test case uses vm.expectRevert() to expect the transaction to fail because the Pot contract does not have enough tokens to fulfill the reward.
The contract fails to revert the transaction when it has insufficient funds, it indicates a vulnerability that could be exploited by players to drain funds or cause incorrect behavior.
Below is POC PotTest.sol and run forge test --match-path PotTest.sol
This is the output
.
Impact: If the contract does not hold sufficient tokens, the transfer operation will fail, and the player will not receive their reward. This could lead to a situation where users are unable to claim their rewards due to insufficient funds in the contract.
Foundry
Before claiming, check that the contract (Pot) has enough tokens to cover the reward amount. This can prevent claims from failing due to insufficient funds.
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.