Omniscia Colony Lab Audit
Staking Code Style Findings
Staking Code Style Findings
STA-01C: Inefficient Require Check
Type | Severity | Location |
---|---|---|
Gas Optimization | Staking.sol:L210 |
Description:
The linked require
check can be relocated in the else
conditional of the if
structure that follows it.
Example:
contracts/Staking/Staking.sol
203/**204 * @dev Unstake sends staked tokens back to the sender205 *206 * Emits a {StakeRemoved} event207 */208function unstake(uint256 amount) public whenNotPaused {209 require(amount > 0, "Staking: cannot unstake 0");210 require(depositSums[msg.sender] >= amount, "Staking: amount exceeds balance");211
212 if (depositSums[msg.sender] == amount) {213 stakeDeposits.removeAll(msg.sender);214 }215 else {216 stakeDeposits.removeValue(msg.sender, amount);217 }218 depositSums[msg.sender] -= amount;219
220 // will transfer tokens to the caller221 IERC20(stakedToken).safeTransfer(msg.sender, amount);222
223 emit StakeRemoved(msg.sender, amount);224}
Recommendation:
We advise it to be done so ensuring that depositSums[msg.sender]
is strictly greater-than (>
) the amount
requested optimizing the codebase.
Alleviation:
The Colony Lab team considered this exhibit but opted not to apply a remediation for it in the current iteration of the codebase.
STA-02C: Variable Mutability Specifiers
Type | Severity | Location |
---|---|---|
Gas Optimization | Staking.sol:L45, L49 |
Description:
The linked variables are assigned to only once during the contract's constructor
.
Example:
contracts/Staking/Staking.sol
39/**40 * @dev Constructor41 * @param supportedToken_ The address of token contract42 */43constructor(address supportedToken_, uint256 authorizedStakeAmount_, uint256 authorizedStakePeriod_) {44 require(supportedToken_ != address(0), "supported token cannot be 0x0");45 stakedToken = IERC20Metadata(supportedToken_);46 authorizedStakeAmount = authorizedStakeAmount_;47 authorizedStakePeriod = authorizedStakePeriod_;48
49 stakeDeposits = new TimedValuesStorage();50 stakeDeposits.setMaxDepositArrayLength(100);51}
Recommendation:
We advise them to be set as immutable
greatly optimizing the codebase.
Alleviation:
The Colony Lab team considered this exhibit but opted not to apply a remediation for it in the current iteration of the codebase.