Open code423n4 opened 3 years ago
Agree with the finding, this should save at least 2000 gas as you're reading from storage
Actually: the first read will always cost 2100 - cannot be reduced But the second one, which would cost 100 (hot storage read ) would cost just 6 gas (3 to store, 3 to read)
Handle
pauliax
Vulnerability details
Impact
Here basketAsERC20.totalSupply() does not change inside the loop so it can be called outside the loop to avoid multiple duplicate external calls: uint256 tokensNeeded = basketAsERC20.totalSupply() pendingWeights[i] newRatio / BASE / BASE;
Recommended Mitigation Steps
Cache basketAsERC20.totalSupply() in a temporary variable and re-use it.