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

2 stars 0 forks source link

Gas: Cache `_upperSlack[_target]` in `Parameters.sol:getUpperSlack()` #321

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

Dravee

Vulnerability details

Impact

SLOADs are expensive

Proof of Concept

Here, _upperSlack[_target] can be loaded twice from storage:

289:     function getUpperSlack(address _target)
290:         external
291:         view
292:         override
293:         returns (uint256)
294:     {
295:         if (_upperSlack[_target] == 0) {
296:             return _upperSlack[address(0)];
297:         } else {
298:             return _upperSlack[_target];
299:         }
300:     }

Tools Used

VS Code

Recommended Mitigation Steps

Cache the storage reading in a memory variable

oishun1112 commented 2 years ago

https://github.com/code-423n4/2022-01-insure-findings/issues/320