Omniscia Moby Audit

RewardTracker Code Style Findings

RewardTracker Code Style Findings

RTR-01C: Deprecated Revert Pattern

Description:

The referenced revert statements will yield a textual description of the error which is an abandoned practice.

Example:

contracts/staking/RewardTracker.sol
137function stake(address _depositToken, uint256 _amount) external override nonReentrant {
138 if (inPrivateStakingMode) { revert("RewardTracker: action not enabled"); }
139 _stake(msg.sender, msg.sender, _depositToken, _amount);
140}

Recommendation:

We advise custom error declarations to be introduced to the RewardTracker and consequently utilized in place of the referenced messages, optimizing the code's gas cost as well as legibility.

Alleviation (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):

The first two revert instances have been omitted from the codebase as a result of remediative actions for other exhibits, and the final revert statement within the RewardTracker::claim function is now utilizing an ActionNotEnabled error declaration.

As such, we consider this exhibit fully alleviated.

RTR-02C: Ineffectual Usage of Safe Arithmetics

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/staking/RewardTracker.sol
276uint256 stakedAmount = stakedAmounts[_account];
277require(stakedAmounts[_account] >= _amount, "RewardTracker: _amount exceeds stakedAmount");
278
279stakedAmounts[_account] = stakedAmount - _amount;

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 (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):

All referenced arithmetic operations have been wrapped in an unchecked code block safely, optimizing their gas cost whilst retaining their security guarantees via preceding conditionals.

RTR-03C: Inefficient mapping Lookups

Description:

The linked statements perform key-based lookup operations on mapping declarations from storage multiple times for the same key redundantly.

Example:

contracts/staking/RewardTracker.sol
120require(allowances[_sender][msg.sender] >= _amount, "RewardTracker: transfer amount exceeds allowance");
121uint256 nextAllowance = allowances[_sender][msg.sender] - _amount;

Recommendation:

As the lookups internally perform an expensive keccak256 operation, we advise the lookups to be cached wherever possible to a single local declaration that either holds the value of the mapping in case of primitive types or holds a storage pointer to the struct contained.

Alleviation (a8720219a6):

The recommended optimization has not been applied as expected.

In detail, the optimization specifies that mapping lookups such as depositBalances[_account][_depositToken] should either be cached in value (i.e. uint256 depositBalance = depositBalances[_account][_depositToken]) or in data location (i.e. mapping(address => uint256) storage depositsOfAccount = depositBalances[_account]).

Neither pattern is observed in the latest state of the codebase, rendering this exhibit partially addressed.

Alleviation (a95db4124c):

The latter of the two aforementioned patterns have been applied to the codebase, rendering this exhibit addressed.

RTR-04C: Loop Iterator Optimization

Description:

The linked for loop increments / decrements the iterator "safely" due to Solidity's built-in safe arithmetics (post-0.8.X).

Example:

contracts/staking/RewardTracker.sol
71for (uint256 i = 0; i < _depositTokens.length; i++) {

Recommendation:

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

Alleviation (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):

The loop is no longer present in the codebase, rendering this optimization inapplicable.