Omniscia Evergon Labs Audit

RateBasedOpenRewardDistributionFacetStorage Code Style Findings

RateBasedOpenRewardDistributionFacetStorage Code Style Findings

RBD-01C: Inefficient Loop Structure

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:

packages/contracts/contracts/rewardsDistribution/rateBasedRewardDistribution/rateBasedOpenRewardDistribution/RateBasedOpenRewardDistributionFacetStorage.sol
231// Rate has never been updated while position was active
232if (currentIndex == i) {
233 reward = _calculateReward(campaignInfoLocal.campaignRates[i], nftId, block.timestamp - lastRewardTimestamp);
234} else {
235 // The first one can be calculated externally to save gas upon the rest of execution.
236 reward = _calculateReward(
237 campaignInfoLocal.campaignRates[i],
238 nftId,
239 campaignInfoLocal.rateChangeSnapshots[i + 1] - lastRewardTimestamp
240 );
241 i++;
242
243 while (i <= currentIndex) {
244 // if they have no difference, then `block.timestamp` is used as endingTimestamp,
245 // as it is the last iteration
246 if (currentIndex == i) {
247 reward += _calculateReward(
248 campaignInfoLocal.campaignRates[i],
249 nftId,
250 block.timestamp - campaignInfoLocal.rateChangeSnapshots[i]
251 );
252 break;
253 } else {
254 reward += _calculateReward(
255 campaignInfoLocal.campaignRates[i],
256 nftId,
257 campaignInfoLocal.rateChangeSnapshots[i + 1] - campaignInfoLocal.rateChangeSnapshots[i]
258 );
259 i++;
260 }
261 }
262}

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 referenced while structure was converted to a do-while loop optimizing its gas cost.

RBD-02C: Non-Standard Storage Slot Definition

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:

packages/contracts/contracts/rewardsDistribution/rateBasedRewardDistribution/rateBasedOpenRewardDistribution/RateBasedOpenRewardDistributionFacetStorage.sol
41/// @dev Unique identifier for the storage slot where the Layout struct is stored.
42bytes32 internal constant STORAGE_SLOT =
43 keccak256("evergonlabs.Staking.rewardDistribution.storage.RateBasedOpenRewardDistributionFacetStorage");

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.

RBD-03C: Repetitive Value Literal

Description:

The linked value literal is repeated across the codebase multiple times.

Example:

packages/contracts/contracts/rewardsDistribution/rateBasedRewardDistribution/rateBasedOpenRewardDistribution/RateBasedOpenRewardDistributionFacetStorage.sol
99if (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.