code-423n4 / 2022-01-sherlock-findings

0 stars 0 forks source link

Gas: Non-strict inequalities are cheaper than strict ones #193

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

Dravee

Vulnerability details

Impact

Strict inequalities add a check of non equality which costs around 3 gas.

Proof of Concept

The following should use an inclusive inequality to save gas:

contracts\managers\SherlockProtocolManager.sol:801:    if (_secondsOfCoverageLeft(_protocol) < MIN_SECONDS_LEFT) revert InsufficientBalance(_protocol);
contracts\SherClaim.sol:42:    if (_claimableAt < block.timestamp + CLAIM_PERIOD_SANITY_BOTTOM) revert InvalidState();
contracts\SherClaim.sol:43:    if (_claimableAt > block.timestamp + CLAIM_PERIOD_SANITY_CEILING) revert InvalidState();
contracts\Sherlock.sol:438:    if (lockupEnd_[_id] > block.timestamp) revert InvalidConditions();

Tools Used

VS Code

Recommended Mitigation Steps

Use >= or <= instead of > and < when possible. Here, it's on time comparisons. As the averable block time in Ethereum is 14 seconds: the gas cost gain from this optimization might be worth the slim difference