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

0 stars 0 forks source link

Gas: `DelegatorPool.sol:claim()`'s `currTotalStake` variable is only used once #147

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

Dravee

Vulnerability details

Impact

Increased gas cost (1 MSTORE and 1 MLOAD)

Proof of Concept

File: DelegatorPool.sol
71:         uint256 currTotalStake = pendingStake();
72:         uint256 owedStake = (currTotalStake * _stake) /
73:             (initialStake - claimedInitialStake);

Tools Used

VS Code

Recommended Mitigation Steps

As there aren't any gain (one can argue: not even in readability) in having this variable: use pendingStake() directly in the calculation:

        uint256 owedStake = (pendingStake() * _stake) /
            (initialStake - claimedInitialStake);
yondonfu commented 2 years ago

Duplicate of https://github.com/code-423n4/2022-01-livepeer-findings/issues/131