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

2 stars 0 forks source link

Gas: Cache `_maxList[_target]` in `Parameters.sol:getMaxList()` #327

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

Dravee

Vulnerability details

Impact

SLOADs are expensive

Proof of Concept

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

397:     function getMaxList(address _target)
398:         external
399:         view
400:         override
401:         returns (uint256)
402:     {
403:         if (_maxList[_target] == 0) {
404:             return _maxList[address(0)];
405:         } else {
406:             return _maxList[_target];
407:         }
408:     }

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

0xean commented 2 years ago

dupe of #320