Open code423n4 opened 3 years ago
0xsanson
In the calcUnderlying function of LibSherX.sol, the value gs.tokensSherX.length can be written down once to save gas (around 300-500 when called in the present tests).
calcUnderlying
gs.tokensSherX.length
https://github.com/code-423n4/2021-07-sherlock/blob/main/contracts/libraries/LibSherX.sol#L55-L60
hardhat gas calculator
Suggested adding uint256 SherXLength = gs.tokensSherX.length; and replacing this value throughout the function (three instances).
uint256 SherXLength = gs.tokensSherX.length;
Thanks!
Handle
0xsanson
Vulnerability details
Impact
In the
calcUnderlying
function of LibSherX.sol, the valuegs.tokensSherX.length
can be written down once to save gas (around 300-500 when called in the present tests).Proof of Concept
https://github.com/code-423n4/2021-07-sherlock/blob/main/contracts/libraries/LibSherX.sol#L55-L60
Tools Used
hardhat gas calculator
Recommended Mitigation Steps
Suggested adding
uint256 SherXLength = gs.tokensSherX.length;
and replacing this value throughout the function (three instances).