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

2 stars 0 forks source link

Gas: Cache `_fee[_target]` in `Parameters.sol:getFeeRate()` #320

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

Dravee

Vulnerability details

Impact

SLOADs are expensive

Proof of Concept

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

271:     function getFeeRate(address _target)
272:         external
273:         view
274:         override
275:         returns (uint256)
276:     {
277:         if (_fee[_target] == 0) {
278:             return _fee[address(0)];
279:         } else {
280:             return _fee[_target];
281:         }
282:     }

Tools Used

VS Code

Recommended Mitigation Steps

Cache the storage reading in a memory variable

oishun1112 commented 2 years ago

I've confirmed that this implementation

most of the cases, this tends to return the default value, so we want to keep the current implementation

oishun1112 commented 2 years ago

we confirm this issue to reduce gas cost in the future

oishun1112 commented 2 years ago

https://github.com/InsureDAO/pool-contracts/pull/49