The getTranches function in the SablierV2LockupTranched contract retrieves all tranches associated with a given stream ID. Prior to the implementation of pagination, this function attempted to return all tranches in a single call. This design could lead to excessive gas consumption when dealing with streams that have a large number of tranches, potentially causing the function call to fail due to block gas limit constraints. This issue impacts the usability and scalability of the contract, particularly for streams with a significant number of tranches.
To illustrate the impact, consider a scenario where a stream has 1000 tranches. A user calling the getTranches function to retrieve all tranches would incur high gas costs due to the large amount of data being processed and returned. In contrast, if pagination were supported, the user could retrieve tranches in smaller, more manageable chunks, significantly reducing gas costs and improving efficiency.
Without pagination, users may be unable to retrieve tranche information for streams with many tranches. This could prevent users from interacting with the contract as intended, leading to a suboptimal user experience and limiting the contract's functionality.
Manual Review
Implement pagination in the getTranches function by introducing parameters for the starting index and the number of tranches to retrieve. Here is the modified function:
Explanation:
Parameters: Introduces startIndex and count to specify the range of tranches to retrieve.
Bounds Checking: Ensures the requested range is within the bounds of the array.
Return Subset: Returns a subset of tranches based on the specified range.
Benefits of the Proposed Solution:
By retrieving smaller subsets of tranches, users can significantly reduce gas costs.
The contract can handle large datasets more efficiently, enhancing its scalability and performance.
Users can interact with the contract more cost-effectively and efficiently, even when dealing with large numbers of tranches.
https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.