Omniscia KlimaDAO Audit
KlimaLPStaking Code Style Findings
KlimaLPStaking Code Style Findings
KLP-01C: Inexistent Opportunistic Transfer
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | KlimaLPStaking.sol:L754 |
Description:
The KLIMAToken
transfer performed within unstakeLP
may be a no-op if the _pendingRewards
are zero.
Example:
contracts/staking/regular/KlimaLPStaking.sol
736// Function that lets user unstake KLIMA/VCU20 LP in system737function unstakeLP() external returns ( bool ) {738
739 updatePool();740
741 User storage user = userDetails[msg.sender];742 require(user._LPDeposited > 0, "User has no stake");743
744 uint256 _pendingRewards = user._LPDeposited.mul(accKLIMAPerShare).div(1e18).sub(user._rewardDebt);745
746 uint256 beingWithdrawn = user._LPDeposited;747
748 user._LPDeposited = 0;749 user._rewardDebt = 0;750
751 totalStaked = totalStaked.sub(beingWithdrawn);752
753 LPToken.safeTransfer(msg.sender, beingWithdrawn);754 KLIMAToken.safeTransfer(msg.sender, _pendingRewards);755
756 emit WithdrawCompleted(msg.sender, beingWithdrawn, block.timestamp);757 emit RewardsClaimed(msg.sender, _pendingRewards, block.timestamp);758
759 return true;760}
Recommendation:
We advise a proper if
block to surround the transfer
instruction to optimize gas cost.
Alleviation:
The KlimaDAO team considered this exhibit but opted to retain the codebase in its current state.
KLP-02C: Variable Mutability Specifiers
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | KlimaLPStaking.sol:L606, L607, L609 |
Description:
The linked variables are assigned to only once during the contract's constructor
.
Example:
contracts/staking/regular/KlimaLPStaking.sol
620constructor(address _LPToken, address _KLIMAToken, address _rewardPool, uint256 _rewardPerBlock, uint _blocksToWait) {621 LPToken = IERC20(_LPToken);622 KLIMAToken = IERC20(_KLIMAToken);623 rewardPool = _rewardPool;624 lastRewardBlock = block.number.add( _blocksToWait );625 rewardPerBlock = _rewardPerBlock;626 accKLIMAPerShare;627 owner = msg.sender;628}
Recommendation:
We advise them to be set as immutable
greatly optimizing the codebase.
Alleviation:
The KlimaDAO team considered this exhibit but opted to retain the codebase in its current state.