Omniscia DappRadar Audit

RadarStakingLogic Code Style Findings

RadarStakingLogic Code Style Findings

RSL-01C: Ineffectual Usage of Safe Arithmetics

TypeSeverityLocation
Language SpecificRadarStakingLogic.sol:L116

Description:

The linked mathematical operation is guaranteed to be performed safely by surrounding conditionals evaluated in either require checks or if-else constructs.

Example:

contracts/RadarStakingLogic.sol
115require(myStake.totalStaked >= amount, "RadarStakingLogic: Amount you want to unstake exceeds your staked amount");
116require((myStake.totalStaked - amount >= stakeForDappRadarPro) || (myStake.totalStaked - amount == 0), "RadarStakingLogic: Either unstake all or keep more than the minimum stake required");

Recommendation:

Given that safe arithmetics are toggled on by default in pragma versions of 0.8.X, we advise the linked statement to be wrapped in an unchecked code block thereby optimizing its execution cost.

Alleviation (8614454f02ec2934ccfdc3f17974be01ca6c1709):

The DappRadar team has not provided any remediation for this exhibit instead opting to acknowledge it.

RSL-02C: Loop Iterator Optimizations

TypeSeverityLocation
Gas OptimizationRadarStakingLogic.sol:L144, L183

Description:

The linked for loops increment / decrement their iterator "safely" due to Solidity's built - in safe arithmetics (post-0.8.X).

Example:

contracts/RadarStakingLogic.sol
144for (uint256 i = 0; i < allAprs.length; i++) {

Recommendation:

We advise the increment / decrement operations to be performed in an unchecked code block as the last statement within each for loop to optimize their execution cost.

Alleviation (8614454f02ec2934ccfdc3f17974be01ca6c1709):

The DappRadar team has not provided any remediation for this exhibit instead opting to acknowledge it.

RSL-03C: Redundant EIP-20 Token Evaluations

TypeSeverityLocation
Gas OptimizationRadarStakingLogic.sol:L54, L56

Description:

The referenced require statements within RadarStakingLogic::stake are redundant as their failure would cause the ensuing ERC20::transferFrom operation to fail regardless.

Example:

contracts/RadarStakingLogic.sol
47function stake(uint256 amount) external nonReentrant {
48 require(amount >= 0, "RadarStakingLogic: Amount must be above 0");
49
50 iRadarStake.Stake memory myStake = radarStakeContract.getStake(_msgSender());
51 require(myStake.totalStaked + amount >= stakeForDappRadarPro, "RadarStakingLogic: You cannot stake less than the minimum");
52
53 // check if the user owns the amount of tokens he wants to stake
54 require(radarTokenContract.balanceOf(_msgSender()) >= amount, "RadarStakingLogic: Not enough tokens to stake");
55 // check if this contract is allowed to move users RADAR to the staking contract
56 require(radarTokenContract.allowance(_msgSender(), address(this)) >= amount, "RadarStakingLogic: This contact is not allowed to move the amount of tokens you want to stake");
57
58 // move tokens from the user to the staking contract
59 radarTokenContract.transferFrom(_msgSender(), address(radarStakeContract), amount);
60
61 // calculate reward in case the user already had a stake and now added to it
62 uint256 tokenReward = calculateReward(_msgSender());
63
64 // move additional tokens to the staking contract so it can later pay out the already accrued rewards
65 if (tokenReward > 0) {
66 radarTokenContract.transferFrom(rewardAddress, address(radarStakeContract), tokenReward);
67 }
68
69 // add to stake, which updates totals and timestamps
70 radarStakeContract.addToStake(amount + tokenReward, _msgSender());
71
72 emit TokensStaked(_msgSender(), amount + tokenReward);
73}

Recommendation:

We advise them to be safely omitted from the codebase, optimizing its gas cost significantly.

Alleviation (8614454f02ec2934ccfdc3f17974be01ca6c1709):

The DappRadar team has not provided any remediation for this exhibit instead opting to acknowledge it.

RSL-04C: Redundant Parenthesis Statements

TypeSeverityLocation
Code StyleRadarStakingLogic.sol:L116, L150, L151, L168

Description:

The referenced statements are redundantly wrapped in parenthesis' (()).

Example:

contracts/RadarStakingLogic.sol
116require((myStake.totalStaked - amount >= stakeForDappRadarPro) || (myStake.totalStaked - amount == 0), "RadarStakingLogic: Either unstake all or keep more than the minimum stake required");

Recommendation:

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

Alleviation (8614454f02ec2934ccfdc3f17974be01ca6c1709):

The DappRadar team has not provided any remediation for this exhibit instead opting to acknowledge it.

RSL-05C: Variable Mutability Specifiers (Immutable)

TypeSeverityLocation
Gas OptimizationRadarStakingLogic.sol:L27, L29, L31

Description:

The linked variables are assigned to only once during the contract's constructor.

Example:

contracts/RadarStakingLogic.sol
13constructor(address rewardAddr, address radarTokenContractAddr, address radarStakeContractAddr) {
14 rewardAddress = rewardAddr;
15 radarTokenContract = iRadarToken(radarTokenContractAddr);
16 radarStakeContract = iRadarStake(radarStakeContractAddr);
17}

Recommendation:

We advise them to be set as immutable greatly optimizing their read-access gas cost.

Alleviation (8614454f02ec2934ccfdc3f17974be01ca6c1709):

The DappRadar team has not provided any remediation for this exhibit instead opting to acknowledge it.