Beanstalk Notion
Beanstalk Notion
/
🪲
Bug Reports
/
BIC Notes
/
📄
Report #34951
📄

Report #34951

Report Date
September 1, 2024
Status
Closed
Payout

ARRAY LENGTH CACHING

‣
Report Info

Report ID

#34951

Report type

Smart Contract

Has PoC?

Yes

Target

https://etherscan.io/address/0xBA51AaaAa95bA1d5efB3cB1A3f50a09165315A17

Impacts

  • Unbounded gas consumption

Description

During each iteration of the loop, reading the length of the array uses more gas than is necessary. In the most favorable scenario, in which the length is read from a memory variable, storing the array length in the stack can save about 3 gas per iteration. In the least favorable scenario, in which external calls are made during each iteration, the amount of gas wasted can be significant.

The following array was detected to be used inside loop without caching it's value in memory: cumulativeReserves.

Remediation: Cache the length of the array cumulativeReserves in a local variable before entering the loop.

Fixed code uint256 length = cumulativeReserves.length; for (uint256 i; i < length; ++i) { cumulativeReserves[i] = cumulativeReserves[i].add(lastReserves[i].fromUIntToLog2().mul(deltaTimestampBytes)); }

Proof of concept

https://etherscan.io/address/0xBA51AaaAa95bA1d5efB3cB1A3f50a09165315A17#code

Immunefi Response

Unfortunately, after reviewing your report, Immunefi has decided to close it as it does not meet our project requirements.
Your submission falls under one of the following categories:
  • Non-Vulnerability Issues: These include issues such as typos, layout issues, and other non-security-related problems that do not pose any security threat.
  • Spam Issues: These include reports that are intended to advertise a product or service, to mislead users or defame the company, or are irrelevant to the program.
  • UI/UX Issues: These include issues related to user interface and user experience that do not pose any security threat.