Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: low
Invalid

Events should be emitted in the E following the CEI pattern

The contract Staking.sol frequently emits events after external calls, which is considered poor practice. It's advisable to emit events before executing external calls to ensure accurate event logging. For instance, in the Staking.sol::withdraw() function, this pattern is observed:

function withdraw(uint256 amount) public updateReward(msg.sender) {
// No require needed because of overflow protection
userStakes[msg.sender] -= amount;
+ emit Withdrew(msg.sender, amount);
loveToken.transfer(msg.sender, amount);
- emit Withdrew(msg.sender, amount);
}

Impact: While emitting information after it has occurred might seem rational, it can introduce vulnerabilities. This approach can be exploited, potentially leading to manipulation and incorrect data being registered by monitoring systems. Ultimately, this could necessitate a code migration to rectify the issues caused by inaccurate event logging.

Recommended Mitigation: Place the events in the effects part of the function after the state variables have been updated but before the interactions with external elements.

Updates

Lead Judging Commences

0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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