From 18a588cb895731327da554c7202ec34eb3f7c89b Mon Sep 17 00:00:00 2001 From: kautukkundan Date: Tue, 1 Feb 2022 02:34:15 +0530 Subject: [PATCH] refactored repetitive subtraction into a local var + use inline call https://github.com/code-423n4/2022-01-livepeer-findings/issues/146 https://github.com/code-423n4/2022-01-livepeer-findings/issues/131 --- contracts/L2/pool/DelegatorPool.sol | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/contracts/L2/pool/DelegatorPool.sol b/contracts/L2/pool/DelegatorPool.sol index 8d5bba1..951637d 100644 --- a/contracts/L2/pool/DelegatorPool.sol +++ b/contracts/L2/pool/DelegatorPool.sol @@ -74,15 +74,14 @@ contract DelegatorPool is Initializable { // are owed to the delegator proportional to _stake / (initialStake - claimedInitialStake) // where claimedInitialStake is the stake of the contract that has already been claimed + // stake remaining with the pool + uint256 diff = initialStake - claimedInitialStake; + // Calculate stake owed to delegator - uint256 currTotalStake = pendingStake(); - uint256 owedStake = (currTotalStake * _stake) / - (initialStake - claimedInitialStake); + uint256 owedStake = (pendingStake() * _stake) / diff; // Calculate fees owed to delegator - uint256 currTotalFees = pendingFees(); - uint256 owedFees = (currTotalFees * _stake) / - (initialStake - claimedInitialStake); + uint256 owedFees = (pendingFees() * _stake) / diff; // update claimed balance claimedInitialStake += _stake;