Description
The contract defines events but doesn't emit them in the corresponding functions, creating gaps in the event log that prevent proper tracking of contract activities.
function earnSnow() external canFarmSnow {
if (s_earnTimer != 0 && block.timestamp < (s_earnTimer + 1 weeks)) {
revert S__Timer();
}
_mint(msg.sender, 1);
s_earnTimer = block.timestamp;
}
function collectFee() external onlyCollector {
uint256 collection = i_weth.balanceOf(address(this));
i_weth.transfer(s_collector, collection);
(bool collected,) = payable(s_collector).call{value: address(this).balance}("");
require(collected, "Fee collection failed!!!");
}
Risk
Likelihood:
Impact:
-
Impact 1 : Off-chain applications cannot track token earning activities, breaking monitoring systems
-
Impact 2 : Fee collection operations are invisible on-chain, reducing transparency and auditability
Proof of Concept
Add these test functions to test/TestSnow.t.sol:
function testMissingSnowEarnedEvent() public {
vm.expectEmit(false, false, false, true);
emit SnowEarned(ashley, 1);
vm.prank(ashley);
snow.earnSnow();
assert(snow.balanceOf(ashley) == 1);
}
function testMissingFeeCollectedEvent() public {
vm.startPrank(jerry);
weth.approve(address(snow), FEE);
snow.buySnow(1);
vm.stopPrank();
vm.prank(victory);
snow.buySnow{value: FEE}(1);
vm.expectEmit(false, false, false, true);
emit FeeCollected();
vm.prank(collector);
snow.collectFee();
assert(weth.balanceOf(collector) == FEE);
assert(collector.balance == FEE);
}
Recommended Mitigation
function earnSnow() external canFarmSnow {
if (s_earnTimer != 0 && block.timestamp < (s_earnTimer + 1 weeks)) {
revert S__Timer();
}
_mint(msg.sender, 1);
s_earnTimer = block.timestamp;
+ emit SnowEarned(msg.sender, 1);
}
function collectFee() external onlyCollector {
uint256 collection = i_weth.balanceOf(address(this));
i_weth.transfer(s_collector, collection);
(bool collected,) = payable(s_collector).call{value: address(this).balance}("");
require(collected, "Fee collection failed!!!");
+ emit FeeCollected();
}