Open code423n4 opened 2 years ago
Dravee
SLOADs are expensive (~100 gas) compared to MLOADs/MSTOREs (~3 gas). Minimizing them can save gas.
The code is as such (see @audit comments):
@audit
File: LaunchEvent.sol 580: function pairBalance(address _user) public view returns (uint256) { 581: UserInfo memory user = getUserInfo[_user]; 582: if (wavaxAllocated == 0 || user.hasWithdrawnPair) { //@audit wavaxAllocated SLOAD 1 583: return 0; 584: } 585: return (user.balance * lpSupply) / wavaxAllocated / 2; //@audit wavaxAllocated SLOAD 2 586: }
By caching this in memory and using it, it's possible to save 1 SLOAD
VS Code
Cache the value in a variable
Handle
Dravee
Vulnerability details
Impact
SLOADs are expensive (~100 gas) compared to MLOADs/MSTOREs (~3 gas). Minimizing them can save gas.
Proof of Concept
The code is as such (see
@audit
comments):By caching this in memory and using it, it's possible to save 1 SLOAD
Tools Used
VS Code
Recommended Mitigation Steps
Cache the value in a variable