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

2 stars 0 forks source link

Gas: Cache `_lowerSlack[_target]` in `Parameters.sol:getLowerSlack()` #323

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

Dravee

Vulnerability details

Impact

SLOADs are expensive

Proof of Concept

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

307:     function getLowerSlack(address _target)
308:         external
309:         view
310:         override
311:         returns (uint256)
312:     {
313:         if (_lowerSlack[_target] == 0) {
314:             return _lowerSlack[address(0)];
315:         } else {
316:             return _lowerSlack[_target];
317:         }
318:     }

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