ERC20Gauges.sol
: infinite loop if one of the user's gauges has a zero weight
#260
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
duplicate-735
edited-by-warden
satisfactory
satisfies C4 submission criteria; eligible for awards
Lines of code
https://github.com/code-423n4/2023-05-maia/blob/main/src/erc-20/ERC20Gauges.sol#L548
Vulnerability details
Impact
When a user transfers or burns his tokens, the algorithm is freeing weights from the gauges that belong to him. This is done inside a for loop that iterates over the list of user's gauges
_userGauges[user].values()
, if the gauge has a non-zero weight we remove it, unfortunately loop counter is placed inside the if blockif (userGaugeWeight != 0)
making it impossible to proceed if gauge weight is zero, therefore transfer/burn will fail out of gas.I'm putting this bug in medium because the only way for this to happen is when the user increments his gauge with a zero value.
Proof of Concept
Test case in
ERC20GaugesTest.t.sol
Tools Used
Forge
Recommended Mitigation Steps
Put i++ outside of the if block
Assessed type
DoS
The text was updated successfully, but these errors were encountered: