Snowman Merkle Airdrop

First Flight #42
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Severity: low
Valid

[H-1] Buying Snow tokens resets the earning timer everytime and user has to wait for a week to earn everytime someone buys the token

[H-1] Buying Snow tokens resets the earning timer everytime and user has to wait for a week to earn everytime someone buys the token

Description

  • Inside the Snow::buySnow() function, the s_earnTimer is updated to the current time at the end of the function.

  • The s_earnTimer acts as a flag for keeping track of the time the last earni has been taken place.

  • Updating the variable while buying the token will result in the reste of the timer, and now the user has to wait a week for earning a token

  • This is not the expected behaviour, as users can buy tokens anytime and earn once a week.

  • A "Denial of Service" can be performed by calling this function repeatedly every 1 week so that nobody is able to earn tokens

function buySnow(uint256 amount) external payable canFarmSnow {
if (msg.value == (s_buyFee * amount)) {
_mint(msg.sender, amount);
} else {
i_weth.safeTransferFrom(msg.sender, address(this), (s_buyFee * amount));
_mint(msg.sender, amount);
}
@> s_earnTimer = block.timestamp;
emit SnowBought(msg.sender, amount);
}

Risk

Likelihood:

  • Whenever someone buys the token

Impact:

  • Nobody will be able to earn tokens

Proof of Concept

Add the following test case to the test suite of Snow

function test_earnRevert() public {
vm.startPrank(ashley);
vm.warp(block.timestamp + 1 weeks);
weth.mint(ashley, 5e18);
weth.approve(address(snow), 5e18);
snow.buySnow(1);
vm.expectRevert();
snow.earnSnow();
}

Now run the following command:

forge test --mt test_earnRevert

Recommended Mitigation

Remove the timer updation logic in buySnow(). Now the timer will not be updated by buying the token and the timer won't be reset while buying.

- s_earnTimer = block.timestamp;
Updates

Lead Judging Commences

yeahchibyke Lead Judge 5 months ago
Submission Judgement Published
Validated
Assigned finding tags:

buying of snow resets global timer thus affecting earning of free snow

When buySnow is successfully called, the global timer is reset. This inadvertently affects the earning of snow as that particular action also depends on the global timer.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.