Omniscia Evergon Labs Audit
RateBasedLockRewardDistributionFacetStorage Code Style Findings
RateBasedLockRewardDistributionFacetStorage Code Style Findings
RBR-01C: Inefficient Loop Structure
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | RateBasedLockRewardDistributionFacetStorage.sol:L336-L356 |
Description:
Per the conditionals that surround it, the while loop is guaranteed to iterate at least once. Additionally, the conditional that it evaluates on each iteration is unnecessary as the loop is guaranteed to break before its conditional invalidates.
Example:
315if (checkingIndex + 1 <= length) {316 // Rate has either changed since last rewards provision occurred or changed during position's lock cycle317
318 if (length - checkingIndex == 1) {319 // Only one rate to account for the whole active period (since last rewards provision occurred)320 reward = _calculateRewardNoLock(321 campaignInfoLocal.campaignRates[checkingIndex],322 virtualPacketBalance,323 block.timestamp - startingTimestamp324 );325 } else {326 // More than one rate to account for the whole active period (since last rewards provision occurred).327 // The first one (first part of the whole active period) can be calculated externally328 // to save gas upon the rest of execution.329 reward = _calculateRewardNoLock(330 campaignInfoLocal.campaignRates[checkingIndex],331 virtualPacketBalance,332 campaignInfoLocal.rateChangeSnapshots[checkingIndex + 1] - startingTimestamp333 );334 checkingIndex++;335
336 // Continue with the remaining parts of the whole active period337 while (checkingIndex < length) {338 // if they have difference of 1, then block.timestamp is used as endingTimestamp339 // as it is the last iteration340 if (length - checkingIndex == 1) {341 reward += _calculateRewardNoLock(342 campaignInfoLocal.campaignRates[checkingIndex],343 virtualPacketBalance,344 block.timestamp - campaignInfoLocal.rateChangeSnapshots[checkingIndex]345 );346 break;347 } else {348 reward += _calculateRewardNoLock(349 campaignInfoLocal.campaignRates[checkingIndex],350 virtualPacketBalance,351 campaignInfoLocal.rateChangeSnapshots[checkingIndex + 1] -352 campaignInfoLocal.rateChangeSnapshots[checkingIndex]353 );354 checkingIndex++;355 }356 }Recommendation:
We advise the loop to be converted to a do-while loop with a true condition, optimizing its gas cost on each iteration.
Alleviation (b64b659786cf3c84bea52feb3a69f546ba3601f0):
The code has been refactored as advised, optimizing the code's gas cost significantly.
RBR-02C: Non-Standard Storage Slot Definition
| Type | Severity | Location |
|---|---|---|
| Standard Conformity | ![]() | RateBasedLockRewardDistributionFacetStorage.sol:L46 |
Description:
The referenced declaration will define a storage slot for use by a facet of the system's main EIP-2535 Diamond, however, the way it is declared does not adhere to the latest standards.
Example:
44/// @dev Unique identifier for the storage slot where the Layout struct is stored.45bytes32 internal constant STORAGE_SLOT =46 keccak256("evergonlabs.Staking.rewardDistribution.storage.RateBasedLockRewardDistributionFacetStorage.V1");Recommendation:
We advise the EIP-7201 name-spaced layout approach to be adhered to similarly to OpenZeppelin and other relevant standard libraries, ensuring consistency among the ecosystem's widely utilized libraries and conforming to the latest standards.
Alleviation (b64b659786cf3c84bea52feb3a69f546ba3601f0):
The referenced slot definition has been updated to its standardized EIP-7201 representation, addressing this exhibit.
RBR-03C: Repetitive Value Literal
| Type | Severity | Location |
|---|---|---|
| Code Style | ![]() | RateBasedLockRewardDistributionFacetStorage.sol:L106 |
Description:
The linked value literal is repeated across the codebase multiple times.
Example:
106if (GeneralStorage.layout().campaignsInfo[campaignId].state != 1) {Recommendation:
We advise it to be set to a constant variable instead, optimizing the legibility of the codebase.
In case the constant has already been declared, we advise it to be properly re-used across the code.
Alleviation (b64b659786cf3c84bea52feb3a69f546ba3601f0):
The referenced literal has been properly introduced as part of the GeneralStakingStorage declarations and specifically as an ON_CREATION state, addressing this exhibit.
