Omniscia Kyo Finance Audit
StakingMath Code Style Findings
StakingMath Code Style Findings
SMH-01C: Redundant Interim Pointer
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | StakingMath.sol:L134 |
Description:
The referenced reward
pointer is redundant as it is solely utilized in the ensuing statement.
Example:
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
Type | Severity | Location |
---|---|---|
Code Style | ![]() | StakingMath.sol:L42 |
Description:
The referenced statement is redundantly wrapped in parenthesis (()
).
Example:
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
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | StakingMath.sol:L70-L72, L116, L127, L145 |
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:
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.