Omniscia Nexera Audit
LendingOracleFacetStorage Code Style Findings
LendingOracleFacetStorage Code Style Findings
LOS-01C: Inefficient Re-Evaluation of Price Limits
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | LendingOracleFacetStorage.sol:L291 |
Description:
The LendingOracleFacetStorage::removeMarginFromPriceLimits function will invoke the LendingOracleFacetStorage::setCollateralPrice function which will in turn reset the currentCollateralPrice to the same value.
Example:
packages/contracts/contracts/oracleFacets/lendingOracle/LendingOracleFacetStorage.sol
276function removeMarginFromPriceLimits(Layout storage l, uint256 campaignId, uint256 packetsMarginAmount) internal {277 CampaignDetails storage campaignDetails = l.campaignDetails[campaignId];278 if (campaignDetails.priceLimits[0] <= packetsMarginAmount) revert packetsMarginAmountEnoughForBuyback();279
280 uint256 length = campaignDetails.priceLimits.length;281
282 for (uint256 i; i < length; ) {283 // Derived after execution of `setPriceLimitsOnPostReceive()`:284 // priceLimits[i] >= priceLimits[0], ∀i ∈ {1, …, n} where n = dim(priceLimits) - 1285 unchecked {286 campaignDetails.priceLimits[i] -= packetsMarginAmount;287 i += 1;288 }289 }290
291 setCollateralPrice(l, campaignId, campaignDetails.currentCollateralPrice);292}Recommendation:
We advise the code of LendingOracleFacetStorage::setCollateralPrice to be refactored so as to split the assignment logic from the price limit iterations, permitting the price limits to be enforced efficiently when removing margin.
Alleviation (d682057ecb0e254069773d64f32c068cedb71e2a):
The recommended optimization has been applied to the codebase alongside a refactor of the price limit traversal mechanisms.
