These two checks are correct when adding delegation. However, when encountering the situation of updating or deleting the delegate, these two checks are too strict, because updating the delegate will not change the array length, while deleting the delegate will reduce the array length.
Please consider this situation, that is, if the user wants to update delegatedMgCvg[_tokenId] when delegatedMgCvg[_tokenId].length is exactly equal to maxMgDelegatees, he or she will have to call cleanDelegatees first to remove all delegatees and then add them one by one, which is extremely cumbersome. Also, it will consume much more gas. I believe this issue affects normal functionality, albeit less severely.
Impact
Normal functions are limited, which causes users spend much more gas.
zraxx
medium
When
delegateMgCvg
is used for update or remove, it will be reverted due to improper require checks.Summary
When
delegateMgCvg
is used for update or remove, it will be reverted due to improper require checks.Vulnerability Detail
In function
delegateMgCvg
from LockingPositionDelegate.sol, there are two require checks to prevent the array length from exceeding the setting.These two checks are correct when adding delegation. However, when encountering the situation of updating or deleting the delegate, these two checks are too strict, because updating the delegate will not change the array length, while deleting the delegate will reduce the array length.
Please consider this situation, that is, if the user wants to update
delegatedMgCvg[_tokenId]
whendelegatedMgCvg[_tokenId].length
is exactly equal tomaxMgDelegatees
, he or she will have to callcleanDelegatees
first to remove all delegatees and then add them one by one, which is extremely cumbersome. Also, it will consume much more gas. I believe this issue affects normal functionality, albeit less severely.Impact
Normal functions are limited, which causes users spend much more gas.
Code Snippet
https://github.com/sherlock-audit/2023-11-convergence/blob/main/sherlock-cvg/contracts/Locking/LockingPositionDelegate.sol#L278
Tool used
Manual Review
Recommendation
Check the array length based on the value of _isUpdate