Dria

Swan
NFTHardhat
21,000 USDC
View results
Submission Details
Severity: medium
Invalid

Potential Gas Inefficiency with Large Arrays

  • Location: contracts/libraries/Statistics.sol

for (uint256 i = 0; i < data.length; i++) {
sum += data[i];
}
  • Problem: Each function iterates over the entire array, which may result in high gas usage for large datasets. Since each loop iteration consumes gas, the complexity of these calculations can lead to prohibitive costs if the library is used with large on-chain data arrays.

  • Recommendation: Limit the array size for on-chain use, or consider off-chain computations if the dataset is large. Alternatively, aggregate values as they are collected to avoid recalculating for large datasets.

  • Tools used: Github and VSC

  • POC:

    uint256;
    for (uint256 i = 0; i < largeArray.length; i++) {
    largeArray[i] = i + 1;
    }
    uint256 avgResult = Statistics.avg(largeArray); // Gas inefficiency for large datasets
  • Expected Outcome: This will consume a high amount of gas, potentially causing the transaction to fail on-chain due to gas limits. It demonstrates that this library may not be suitable for large arrays in an on-chain environment.

  • Impact: Makes the library impractical for large datasets, leading to increased costs and potential for transaction failure due to exceeding gas limits, especially if used on-chain.

Updates

Lead Judging Commences

inallhonesty Lead Judge 8 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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