The Standard

The Standard
DeFiHardhat
20,000 USDC
View results
Submission Details
Severity: low
Invalid

Usage of nested loops in distributeAssets()

Summary

The purpose of distributeAssets() is to allocate assets to holders based on specific parameters like _collateralRate. The function iterates through all the holders and assets provided in its parameters to distribute them accordingly.

However, this process can be highly gas-intensive, particularly when dealing with a substantial number of holders and assets.

The gas consumption of this function is influenced by various factors, including the array size of ILiquidationPoolManager.Asset[] _assets and the number of holders in the system. With two nested loops, the function's gas usage significantly increases, posing potential issues with certain input sizes.

Vulnerability Details

For example, if the holder array is 30 and _assets.length is 5 the function will be executed 30*5 times.

The formula for calculating the number of times the loop executes is the number of times the outer loop repeats multiplied by the number of times the inner loop repeats.

Which means that the function can grow large in an exponential way , the function can become also extremely gas-intensive.

Impact

The main consequence of such a potential issue is that the function may not distribute enough assets to the holder, resulting in partial fulfillment of requests.

Tools Used

Manual Analysis

Recommendations

To address this, consider decoupling the transaction requirements. Encapsulate the retrieval of _positionStake for all holders in specific, streamlined function. Additionally, contemplate restricting the input of _assets[].

Updates

Lead Judging Commences

hrishibhat Lead Judge almost 2 years ago
Submission Judgement Published
Invalidated
Reason: Known issue
Assigned finding tags:

informational/invalid

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!