Omniscia Evergon Labs Audit

LendingOracleFacetStorage Code Style Findings

LendingOracleFacetStorage Code Style Findings

LOS-01C: Combination of Logical Clauses

Description:

The referenced conditional clauses can be combined into a single one, permitting the inner else statement to be omitted.

Example:

packages/contracts/contracts/oracleFacets/lendingOracle/LendingOracleFacetStorage.sol
213} else if (currentState != l.interferenceState) {
214 if (StateFacetStorage.layout().stateHooksInfo[currentState].isStateTransitionSupported[l.interferenceState]) {
215 // if the price is over the limit go to interference state and repeat all the checks.
216 StateFacetStorage.layout().changeState(campaignId, currentState, l.interferenceState);
217 currentState = l.interferenceState;
218 campaignDetails.lastIndexSet = 0;
219 index = length;
220 } else {
221 // else we stay forever in current state (should be final)
222 break;
223 }
224} else {
225 break;
226}

Recommendation:

We advise this optimization to be applied so as to reduce the code's gas cost.

Alleviation (71cda4ccfdcfa25fb96a4565f1f8143b350dd246):

The logical clauses have been collapsed as advised, optimizing the code's gas cost.

LOS-02C: Ineffectual Usage of Safe Arithmetics

TypeSeverityLocation
Language SpecificLendingOracleFacetStorage.sol:
I-1: L121
I-2: L129
I-3: L238

Description:

The linked mathematical operations are guaranteed to be performed safely by surrounding conditionals evaluated in either require checks or if-else constructs.

Example:

packages/contracts/contracts/oracleFacets/lendingOracle/LendingOracleFacetStorage.sol
123for (uint256 i; i < length; i++) {
124 if (i == 0) {
125 if (proportionsOverObligation[i] < l.minimumProportionOverObligation) {
126 revert BelowMinimumProportion(proportionsOverObligation[i], l.minimumProportionOverObligation);
127 }
128 } else {
129 if (proportionsOverObligation[i] < proportionsOverObligation[i - 1]) revert NonIncrementalProportions();
130 }
131}

Recommendation:

Given that safe arithmetics are toggled on by default in pragma versions of 0.8.X, we advise the linked statements to be wrapped in unchecked code blocks thereby optimizing their execution cost.

Alleviation (71cda4ccfdcfa25fb96a4565f1f8143b350dd246):

All referenced arithmetic operations have been wrapped in an unchecked code block as advised.

LOS-03C: Misleading Codebase Notions

Description:

The system defines that the LendingOracleFacetStorage::setPriceLimitsOnPostReceive function (i.e. post-receive) should be set as a before-hook of the buy back state.

Example:

packages/contracts/contracts/oracleFacets/lendingOracle/LendingOracleFacetStorage.sol
136// This function should be registered as a before state hook on `FUNDED` state
137// (i.e., after the creator (the address that gets the loan) receives the lended assets)
138// So, should be a before hook on buyBackState
139function setPriceLimitsOnPostReceive(Layout storage l, uint256 campaignId) internal {

Recommendation:

We advise the system to utilize uniform and non-contradicting terminology across the codebase so as to better aid developers in adopting the ecosystem.

Alleviation (71cda4ccfdcfa25fb96a4565f1f8143b350dd246):

The Evergon Labs team opted to remove the documentation line above the function declaration, ensuring that the function's description by itself is cohesive and thus addressing this exhibit.

LOS-04C: 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/oracleFacets/lendingOracle/LendingOracleFacetStorage.sol
36bytes32 internal constant STORAGE_SLOT = keccak256("Evergonlabs.Tmi-Tokenizer.storage.LendingOracleFacetStorage");

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.

LOS-05C: Repetitive Value Literal

Description:

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

Example:

packages/contracts/contracts/oracleFacets/lendingOracle/LendingOracleFacetStorage.sol
39uint256 internal constant _ONE_MILLION = 1_000_000;

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

The Evergon Labs team evaluated this recommendation to be invalid due to the constant appearing once across the codebase, however, the same value is present in the FixedInterestBuybackAmountFacetStorage implementation rendering it to remain valid albeit open and thus acknowledged.

Alleviation (d7b20c134f):

The constant literal has been relocated to a contract-level declaration within the GeneralStorage common dependency, addressing this exhibit.