Omniscia Impact Market Audit
StakingImplementation Code Style Findings
StakingImplementation Code Style Findings
SIN-01C: Inefficient Loop Limit Evaluation
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | StakingImplementation.sol:L156 |
Description:
The linked for loop evaluates its limit inefficiently on each iteration.
Example:
156_index < _holder.unstakes.length &&Recommendation:
We advise the statements within the for loop limit to be relocated outside to a local variable declaration that is consequently utilized for the evaluation to significantly reduce the codebase's gas cost. We should note the same optimization is applicable for storage reads present in such limits as they are newly read on each iteration (i.e. length members of arrays in storage).
Alleviation:
The linked code has been update to store the state variable length into a local variable before the while loop thus avoiding reading it every time from storage.
SIN-02C: Inefficient mapping Lookups
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | StakingImplementation.sol:L112, L117 |
Description:
The linked statements perform key-based lookup operations on mapping declarations from storage multiple times for the same key redundantly.
Example:
112holders[_holderAddress].amount += _amount;113currentTotalAmount += _amount;114
115donationMiner.setStakingAmounts(116 _holderAddress,117 holders[_holderAddress].amount,118 currentTotalAmount119);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:
The linked statements have been updated to store the holder object into a local storage reference variable thus avoiding multiple mapping lookups.
