Possible infinite loop in _decrementWeightUntilFree()
#698
Labels
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-152
edited-by-warden
grade-b
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/main/src/tokens/ERC20Gauges.sol#L515-L536
Vulnerability details
Impact
In
_decrementWeightUntilFree()
there is a great possibility of an Infinite loop. This is becausei++
is an increment insideif
condition. This can lead to excessive gas consumption, causing the Ethereum transaction to fail due to the gas limit.Proof of Concept
In
ERC20Gauges.sol
we have_decrementWeightUntilFree()
which use greedy algorithm for freeing weight.In the loop of the
_decrementWeightUntilFree()
method, the position ofi++
is wrong, which may lead to an infinite loop:As we can see
i++
is incremented only whenuserGaugeWeight != 0
is true.If we don't enter the
if
condition,i
won't increase and so we get an infinite loop.Tools Used
Visual Studio Code
Recommended Mitigation Steps
To avoid this potential infinite loop, move the unchecked box outside the
if
condition.Assessed type
Loop
The text was updated successfully, but these errors were encountered: