TempleGold

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

Gas Optimization in `findAuctionForSpiceToken` Function

Summary

The findAuctionForSpiceToken function in the SpiceAuctionFactory contract can be optimized for gas efficiency by using an inline return statement, eliminating unnecessary storage reads and variable assignments.
https://github.com/Cyfrin/2024-07-templegold/blob/57a3e597e9199f9e9e0c26aab2123332eb19cc28/protocol/contracts/templegold/SpiceAuctionFactory.sol#L55-L58

Vulnerability Details

The current implementation of findAuctionForSpiceToken reads from storage twice and uses an unnecessary local variable:

function findAuctionForSpiceToken(address spiceToken) external override view returns (address) {
bytes32 pairId = _getPairHash(spiceToken);
return deployedAuctions[pairId];
}

Impact

While this is a low-severity issue as it doesn't affect the functionality or security of the contract, it does present an opportunity for gas optimization. The proposed change would slightly reduce the gas cost for calling this function, which could lead to cumulative savings over multiple transactions, especially if this function is frequently called.

Tools Used

Manual review

Recommendations

Implement the optimized version of the function using the inline return statement:

function findAuctionForSpiceToken(address spiceToken) external override view returns (address deployedAuctions[_getPairHash(spiceToken)]) {
}

This change will:

  1. Reduce gas costs by eliminating an unnecessary storage read and local variable assignment.

  2. Simplify the function, making it more concise and easier to read.

  3. Potentially provide cumulative gas savings for users interacting with the contract, especially if this function is called frequently.

Updates

Lead Judging Commences

inallhonesty Lead Judge 12 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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