Core Contracts

Regnum Aurum Acquisition Corp
HardhatReal World AssetsNFT
77,280 USDC
View results
Submission Details
Severity: low
Invalid

Storage variables in a loop should be cached

Summary

The function getTotalWeight() iterates through _gaugeList and repeatedly accesses storage variables gauges[_gaugeList[i]].isActive and gauges[_gaugeList[i]].weight. This results in multiple expensive SLOAD operations, increasing gas consumption.

Vulnerability Details

  • Each iteration of the loop fetches gauges[_gaugeList[i]].isActive and gauges[_gaugeList[i]].weight directly from storage.

  • Storage reads (SLOAD) are significantly more expensive than memory reads.

  • The repeated access to storage in a loop leads to unnecessary gas costs.

Impact

Excessive gas usage due to multiple redundant storage reads, leading to higher transaction costs.

Tools Used

Manual Review

Recommendations

Cache the storage variable into memory before the loop to minimize repeated SLOAD operations:

function getTotalWeight() public view override returns (uint256) {
uint256 total = 0;
uint256 length = _gaugeList.length;
for (uint256 i = 0; i < length; i++) {
address gaugeAddress = _gaugeList[i];
Gauge memory gauge = gauges[gaugeAddress]; // Load into memory
if (gauge.isActive) {
total += gauge.weight;
}
}
return total;
}
Updates

Lead Judging Commences

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