The setAmbRewards function contains a gas exhaustion vulnerability that could potentially lead to a denial-of-service (DoS) attack.
Malicious actors can exploit this vulnerability by specifying a large difference between the weekFrom and weekTo parameters, causing an unbounded loop that consumes excessive gas. As a result, legitimate transactions may be delayed or prevented from execution, disrupting the normal operation of the contract and affecting its availability.
The function accepts parameters weekFrom and weekTo to specify a range of weeks.
It uses a while loop to iterate through each week within the specified range.
It executes instructions for each week.
The issue here is that there is no limit on the range of weeks that can be specified.
If a user specifies a very large difference between weekFrom and weekTo, it can cause the while loop to iterate for an extended period, consuming an excessive amount of gas.
Eventually, the transaction may run out of gas, effectively halting the contract execution.
Tools Used
Manual review
Recommended Mitigation Steps
Set a reasonable gas limit for transactions that call the setAmbRewards function to prevent excessive gas consumption. Carefully choose the gas limit to balance security and functionality.
Lines of code
https://github.com/code-423n4/2023-10-canto/blob/main/canto_ambient/contracts/callpaths/LiquidityMiningPath.sol#L77 https://github.com/code-423n4/2023-10-canto/blob/main/canto_ambient/contracts/callpaths/LiquidityMiningPath.sol#L68
Vulnerability details
Impact
The setAmbRewards function contains a gas exhaustion vulnerability that could potentially lead to a denial-of-service (DoS) attack. Malicious actors can exploit this vulnerability by specifying a large difference between the weekFrom and weekTo parameters, causing an unbounded loop that consumes excessive gas. As a result, legitimate transactions may be delayed or prevented from execution, disrupting the normal operation of the contract and affecting its availability.
Proof of Concept
The function accepts parameters weekFrom and weekTo to specify a range of weeks. It uses a while loop to iterate through each week within the specified range. It executes instructions for each week. The issue here is that there is no limit on the range of weeks that can be specified. If a user specifies a very large difference between weekFrom and weekTo, it can cause the while loop to iterate for an extended period, consuming an excessive amount of gas. Eventually, the transaction may run out of gas, effectively halting the contract execution.
Tools Used
Manual review
Recommended Mitigation Steps
Set a reasonable gas limit for transactions that call the setAmbRewards function to prevent excessive gas consumption. Carefully choose the gas limit to balance security and functionality.
Assessed type
DoS