TempleGold

TempleDAO
Foundry
25,000 USDC
View results
Submission Details
Severity: low
Invalid

The `TempleGold::mint` function reads `distributionParams` from storage before carrying out a check that is independent of `distributionParams` which could cost more gas than necessary when it reverts

Summary

TempleGold::mint function does not follow CEI which could cost more gas than necessary when it reverts

Vulnerability Details

The TempleGold::mint function reads the distributionParams variable from storage before carrying out the check

if (vestingFactorCache.numerator == 0) { revert ITempleGold.MissingParameter(); }

which does not depend on the distributionParams variable. Where the condition fails the function reverts, the contract would have paid gas for reading distributionParams from storage needlessly.

Impact

Because the TempleGold::mint function does not follow CEI, the function will cost more gas than necessary when it reverts.

Tools Used

Manual review

Recommendations

Since the check

if (vestingFactorCache.numerator == 0) { revert ITempleGold.MissingParameter(); }

does not depend on distributionParams variable, the section of the TempleGold::mint function that reads distributionParams from storage can be rearranged as follows

function mint() external override onlyArbitrum {
VestingFactor memory vestingFactorCache = vestingFactor;
- DistributionParams storage distributionParamsCache = distributionParams;
if (vestingFactorCache.numerator == 0) { revert ITempleGold.MissingParameter(); }
uint256 mintAmount = _getMintAmount(vestingFactorCache);
/// @dev no op silently
if (!_canDistribute(mintAmount)) { return; }
lastMintTimestamp = uint32(block.timestamp);
+ DistributionParams memory distributionParamsCache = distributionParams;
_distribute(distributionParamsCache, mintAmount);
}
Updates

Lead Judging Commences

inallhonesty Lead Judge about 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.