Omniscia AllianceBlock Audit

LibFeeCalculator Code Style Findings

LibFeeCalculator Code Style Findings

LFC-01C: Potentially Inefficient Gain Accumulation

Description:

The LibFeeCalculator::claimReward will inefficiently read multiple state variables and increment the fcs.accumulator when the fcs.feesAccrued is equal to the fcs.previousAccrued.

Example:

contracts/libraries/LibFeeCalculator.sol
49/**
50 * @notice claimReward Make calculations based on fee distribution and returns the claimable amount
51 * @param claimer_ The address of the claimer
52 */
53function claimReward(address claimer_)
54 internal
55 returns (uint256)
56{
57 LibFeeCalculator.Storage storage fcs = feeCalculatorStorage();
58
59 uint256 gain = (fcs.feesAccrued - fcs.previousAccrued) / LibGovernance.membersCount();
60 fcs.previousAccrued = fcs.feesAccrued;
61 fcs.accumulator += gain;
62
63 uint256 claimableAmount = fcs.accumulator - fcs.claimedRewardsPerAccount[claimer_];
64
65 fcs.claimedRewardsPerAccount[claimer_] = fcs.accumulator;
66
67 return claimableAmount;
68}

Recommendation:

We advise the same approach as LibFeeCalculator::addNewMember to be utilized, calculating the diff and executing the sensitive statements solely if the diff is non-zero thereby optimizing the code's worst-case gas cost.

Alleviation (54fd570de24631ca65a7cea022aebe43225a08c7):

The code was updated per our recommendation, significantly optimizing its gas cost under the scenario described.