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

gas optimisation on collectPresent

Summary

When we read thing from storage in Blockchain it will cost more, when we have some values which are going to used multiple time it is better to store them into one variable then used it

Vulnerability Details

extra gas us used on reading storage

Impact

waste of gas and money

Tools Used

manual

Recommendations

// | collectPresent | 254 | 54566 | 70250 | 120077 | 7 |. with multiple call
// | collectPresent | 254 | 54548 | 70294 | 119951 | 7 | with single call and used variable

Read once and store into variable and used multiple time

/*
* @notice Collect your present if you are nice or extra nice. You get extra presents if you are extra nice.
* - Nice: Collect an NFT
* - Extra Nice: Collect an NFT and a SantaToken
* This should not be callable until Christmas 2023 (give or take 24 hours), and addresses should not be able to collect more than once.
*/
function collectPresent() external {
if (block.timestamp < CHRISTMAS_2023_BLOCK_TIME) {
revert SantasList__NotChristmasYet();
}
address userAddress =msg.sender;
if (balanceOf(userAddress) > 0) {
revert SantasList__AlreadyCollected();
}
// @audit-info gas optimzation
Status checkFirstStatus =s_theListCheckedOnce[userAddress];
Status checkTwiceStatus =s_theListCheckedTwice[userAddress];
if (checkFirstStatus == Status.NICE && checkTwiceStatus == Status.NICE) {
_mintAndIncrement();
return;
} else if (
checkFirstStatus == Status.EXTRA_NICE
&& checkTwiceStatus == Status.EXTRA_NICE
) {
_mintAndIncrement();
i_santaToken.mint(userAddress);
return;
}
revert SantasList__NotNice();
}
Updates

Lead Judging Commences

inallhonesty 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.