Omniscia Evergon Labs Audit

TwoCapPurchaseAmountFacetStorage Code Style Findings

TwoCapPurchaseAmountFacetStorage Code Style Findings

TCA-01C: 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:

packages/contracts/contracts/internalFacets/purchasePhaseFacets/purchaseAmountFacets/twoCap/TwoCapPurchaseAmountFacetStorage.sol
98l.fractionsPurchasedByAccountForId[campaignId][account] += amountOfFractions;
99
100if (l.fractionsPurchasedByAccountForId[campaignId][account] > l.hardCapPerAccountForId[campaignId])

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.

As the compiler's optimizations may take care of these caching operations automatically at-times, we advise the optimization to be selectively applied, tested, and then fully adopted to ensure that the proposed caching model indeed leads to a reduction in gas costs.

Alleviation (71cda4ccfdcfa25fb96a4565f1f8143b350dd246):

All referenced inefficient mapping lookups have been optimized to the greatest extent possible, significantly reducing the gas cost of the functions the statements were located in.

TCA-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/internalFacets/purchasePhaseFacets/purchaseAmountFacets/twoCap/TwoCapPurchaseAmountFacetStorage.sol
39bytes32 internal constant STORAGE_SLOT = keccak256("Evergonlabs.Tmi-Tokenizer.storage.TwoCapPurchaseAmountFacetStorage");

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 (71cda4ccfdcfa25fb96a4565f1f8143b350dd246):

The referenced slot definition has been updated to its standardized EIP-7201 representation, addressing this exhibit.

TCA-03C: Redundant Conditional Structure

Description:

The referenced if-else structure will yield true if its condition is true and false otherwise.

Example:

packages/contracts/contracts/internalFacets/purchasePhaseFacets/purchaseAmountFacets/twoCap/TwoCapPurchaseAmountFacetStorage.sol
109if (infoForId.totalFractionsPurchased >= l.softCapForId[campaignId]) return true;
110return false;

Recommendation:

We advise the condition to be yielded directly, optimizing the code's gas cost.

Alleviation (71cda4ccfdcfa25fb96a4565f1f8143b350dd246):

The redundant conditional structure has been simplified as advised, optimizing its gas cost.