code-423n4 / 2021-07-sherlock-findings

0 stars 0 forks source link

gas reduction in `calcUnderlying` #124

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

0xsanson

Vulnerability details

Impact

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).

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).

Evert0x commented 3 years ago

Thanks!