Omniscia Kyo Finance Audit

StakingMath Code Style Findings

StakingMath Code Style Findings

SMH-01C: Redundant Interim Pointer

Description:

The referenced reward pointer is redundant as it is solely utilized in the ensuing statement.

Example:

contracts/lib/StakingMath.sol
133function claimable(Ledger storage self, address rewardToken, address account) internal view returns (uint128) {
134 Reward storage reward = self.rewards[rewardToken];
135 Account storage acc = reward.accounts[account];
136
137 return acc.rewardsOwed;
138}

Recommendation:

We advise the variable to be omitted and its expression to replace its mention in the ensuing line, optimizing the code's gas cost.

Alleviation (17c8d4e59f398021156f6f9657ff278aae0462ae):

The Kyo Finance team evaluated this exhibit but opted to acknowledge it in the current iteration of the codebase.

SMH-02C: Redundant Parenthesis Statement

TypeSeverityLocation
Code StyleStakingMath.sol:L42

Description:

The referenced statement is redundantly wrapped in parenthesis (()).

Example:

contracts/lib/StakingMath.sol
42return ((uint256(newRewardsAmount) << 128) / totalStakes);

Recommendation:

We advise them to be safely omitted, increasing the legibility of the codebase.

Alleviation (17c8d4e59f398021156f6f9657ff278aae0462ae):

The Kyo Finance team evaluated this exhibit but opted to acknowledge it in the current iteration of the codebase.

SMH-03C: Redundant Relay of Rewards Owed

Description:

The current StakingMath::_calculateRewardsOwed function is inefficient as it will accept an input argument that is simply added to its equation and yielded back.

Example:

contracts/lib/StakingMath.sol
70function _calculateRewardsOwed(uint128 userStakes, uint128 rewardsOwedBefore, uint256 rewardGrowthX128, uint256 rewardGrowthLastX128) internal pure returns (uint128 rewardsOwed) {
71 return rewardsOwedBefore + uint128(Math.mulDiv(userStakes, rewardGrowthX128 - rewardGrowthLastX128, 1 << 128));
72}

Recommendation:

We advise the code to instead calculate the resulting increase and delegating any mathematical operation to the function's caller, optimizing its gas cost.

Alleviation (17c8d4e59f398021156f6f9657ff278aae0462ae):

The input argument is no longer relayed to the function itself, addressing this exhibit.