The _getMintFertilizerOut
function, although labeled as a view
function, is publicly accessible and does not have reentrancy guards or rate limiting. This function performs potentially costly computations based on external data inputs, leading to concerns about unnecessary gas consumption when accessed excessively.
The function is marked as public
, and although it does not alter state directly, its public accessibility allows it to be invoked by any external actor, including malicious contracts. The function's dependence on external data fetches from Chainlink could lead to high computational costs if the external fetch involves complex calculations or if the function itself is called within loops by external contracts.
Vulnerable Code:
Set Visibility to Internal(most easy way): Change the visibility of _getMintFertilizerOut
from public to internal to prevent direct calls from external contracts.
Currently, no contracts needs to use _getMintFertilizerOut
directly, and the function name starts with an underscore (_)
, which is usually used to indicate that the function is for internal use, meaning it should have private or internal visibility. The Beanstalk Farm team should also use this naming convention to remind developers that this function should not be directly accessed by external contracts or callers, and we can see that other functions with similar names are all internal
.
Rate Limiting: Implement rate limiting to control the frequency of function calls, reducing the risk of infinite call.
For example, we can use a timestamp-based mechanism.
Solution 1: Rate Limiting with 1-Second Delay
To implement a rate limiting mechanism that enforces a 1-second delay between calls, we can modify the CALL_DELAY
constant accordingly.
Solution 2: Rate Limiting to 100 Calls per Minute
To limit the number of calls to 100 per minute, we can track the number of calls made within the last minute and reset it every minute. Here’s an implementation of that approach:
Log, protect successfully:
By implementing rate limiting, either with a time delay or a maximum call count within a time window, we can mitigate the risk of excessive resource consumption and potential DoS attacks. These strategies ensure that the function cannot be called excessively in a short period, protecting gas resources.
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.