Core Contracts

Regnum Aurum Acquisition Corp
HardhatReal World AssetsNFT
77,280 USDC
View results
Submission Details
Severity: low
Valid

Inefficient Fixed-Size Array Allocation in `_distributeToGauges`

Summary

The function _distributeToGauges creates a fixed-size array gaugeWeights with the length of _gaugeList, which leads to unnecessary memory allocation when only a subset of the list is active. This results in wasteful storage usage and increased gas costs.

Vulnerability Details

In _distributeToGauges, the following line initializes a fixed-size array:

uint256[] memory gaugeWeights = new uint256[](_gaugeList.length);

This means that memory is allocated for all elements in _gaugeList, even though only active gauges are used. If _gaugeList is large but has only a few active gauges, this results in unnecessary computational overhead.

Impact

  • Increased gas costs due to wasteful memory allocation.

  • Unoptimized resource usage, especially when _gaugeList contains many inactive gauges.

Tools Used

  • Manual code review

Recommendations

  • Use dynamic memory allocation by storing active gauge weights in a dynamically growing array, such as Array.push().

  • Alternatively, store weights in a mapping instead of an array, avoiding unnecessary memory allocation.

uint256[] memory gaugeWeights;
for (uint256 i = 0; i < _gaugeList.length; i++) {
address gauge = _gaugeList[i];
if (gauges[gauge].isActive && gauges[gauge].gaugeType == gaugeType) {
gaugeWeights.push(gauges[gauge].weight);
totalTypeWeight += gauges[gauge].weight;
}
}

By using push(), the function only allocates memory for active gauges, optimizing gas usage and execution efficiency.

Updates

Lead Judging Commences

inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Validated
Assigned finding tags:

GaugeController._distributeToGauges iterates twice over unbounded gauges list without error handling, causing DoS risk from out-of-gas or single gauge revert

inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Validated
Assigned finding tags:

GaugeController._distributeToGauges iterates twice over unbounded gauges list without error handling, causing DoS risk from out-of-gas or single gauge revert

Support

FAQs

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

Give us feedback!