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

2 stars 0 forks source link

Gas: Cache `_withdawable[_target]` in `Parameters.sol:getWithdrawable()` #325

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

Dravee

Vulnerability details

Impact

SLOADs are expensive

Proof of Concept

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

343:     function getWithdrawable(address _target)
344:         external
345:         view
346:         override
347:         returns (uint256)
348:     {
349:         if (_withdawable[_target] == 0) {
350:             return _withdawable[address(0)];
351:         } else {
352:             return _withdawable[_target];
353:         }
354:     }

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