The Standard

The Standard
DeFiHardhat
20,000 USDC
View results
Submission Details
Severity: low
Invalid

Optimize function

Summary

Immediately return the value found when searching for an element in an array saves gas and prevents from gas griefing attacks.

Vulnerability Details

Avoid wasting gas by returning in a for-loop used to find an item in a list.
Refactor the SmartVaultV3::getToken function as follows to save gas.

function getToken(bytes32 _symbol) private view returns (ITokenManager.Token memory _token) {
ITokenManager.Token[] memory tokens = getTokenManager().getAcceptedTokens();
for (uint256 i = 0; i < tokens.length; i++) {
- if (tokens[i].symbol == _symbol) _token = tokens[i];
- }
- require(_token.symbol != bytes32(0), "err-invalid-swap");
+ if (tokens[i].symbol == _symbol) {
+ _token = tokens[i];
+ require(_token.symbol != bytes32(0), "err-invalid-swap");
+ return;
}

Impact

Gas

Tools Used

Manual review

Recommendations

Change SmartVaultV3::getToken() as shown above.

Updates

Lead Judging Commences

hrishibhat Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

informational/invalid

Support

FAQs

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