UlyssesPool.setWeight() gets the logic wrong for the distribution of leftOverBandwidth. #246
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-766
edited-by-warden
satisfactory
satisfies C4 submission criteria; eligible for awards
upgraded by judge
Original issue severity upgraded from QA/Gas by judge
Lines of code
https://github.com/code-423n4/2023-05-maia/blob/54a45beb1428d85999da3f721f923cbf36ee3d35/src/ulysses-amm/UlyssesPool.sol#L223-L305
Vulnerability details
Impact
Detailed description of the impact of this finding.
setWeight() gets the logic wrong for the distribution of leftOverBandwidth. The main problem is that it gets the case of oldTotalWeights > newTotalWeights and the case of oldTotalWeights < newTotalWeights confused.
Proof of Concept
Provide direct links to all referenced code in GitHub. Add screenshots, logs, or any other relevant proof that illustrates the concept.
UlyssesPool.setWeight()
allows a user to set a new weight for an existingpoolId
. There are two cases:oldTotalWeights < newTotalWeights
, then some bandwith will be redistributed from the remaining bandwithStateLists to bandwidthStateList[poolIndex].bandwidth.oldTotalWeights > newTotalWeights
, then some bandwith will be redistributed from bandwidthStateList[poolIndex].bandwidth to the remaining bandwithStateLists.https://github.com/code-423n4/2023-05-maia/blob/54a45beb1428d85999da3f721f923cbf36ee3d35/src/ulysses-amm/UlyssesPool.sol#L223-L292
However, the implementation gets the logic wrong: it treats the first case as the second case and vice versa. For example, when
oldTotalWeights > newTotalWeights
, it uses the following logic:https://github.com/code-423n4/2023-05-maia/blob/54a45beb1428d85999da3f721f923cbf36ee3d35/src/ulysses-amm/UlyssesPool.sol#L252C13-L262
Since
oldTotalWeights > newTotalWeights
,bandwidthStateList[i].bandwidth > oldBandwidth
, as a result L260 will always revert due to underflow error. Therefore, the function setWeight() will revert as well.Tools Used
VSCode
Recommended Mitigation Steps
We need to exchange the logic of the two cases.
Assessed type
Math
The text was updated successfully, but these errors were encountered: