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

2 stars 0 forks source link

Gas: Cache `attributions[_target]` in `Vault.sol:underlyingValue()` #343

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

Dravee

Vulnerability details

Impact

SLOADs are expensive

Proof of Concept

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

Vault.sol
400:     function underlyingValue(address _target)
401:         public
402:         view
403:         override
404:         returns (uint256)
405:     {
406:         if (attributions[_target] > 0) {
407:             return (valueAll() * attributions[_target]) / totalAttributions;
408:         } else {
409:             return 0;
410:         }
411:     }

Tools Used

VS Code

Recommended Mitigation Steps

Cache the loaded storage value in a memory variable

oishun1112 commented 2 years ago

implement with this together https://github.com/code-423n4/2022-01-insure-findings/issues/344