Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

pontifex - Unexpected revert at the delegateMgCvg and delegateVeCvg when delegation removal #206

Closed
sherlock-admin2 opened this issue Nov 29, 2023 · 0 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin2
Copy link
Contributor

sherlock-admin2 commented Nov 29, 2023

pontifex

medium

Unexpected revert at the delegateMgCvg and delegateVeCvg when delegation removal

Summary

Token owners can't remove a percentage of the mgCvG delegation from a specified address _to via the delegateMgCvg function when the _to address has maxTokenIdsDelegated delegations. The only way to remove delegation is to clean all associated with _tokenId delegatees. The same issue at the delegateVeCvg function but the impact is less because veCVG can be delegated only to one address.

Vulnerability Detail

The LockingPositionDelegate.delegateMgCvg and LockingPositionDelegate.delegateVeCvg functions allow the token owner to delegate and undelegate to the selected address. If the number of delegations to the address reaches the maxTokenIdsDelegated value, no more delegations can be performed at this address. Due to the fact that the checks are in inappropriate places, they also prevent the cancellation of delegation from such addresses.

Impact

The delegateMgCvg and delegateVeCvg functions do not work as expected during the normal usage.

Code Snippet

https://github.com/sherlock-audit/2023-11-convergence/blob/e894be3e36614a385cf409dc7e278d5b8f16d6f2/sherlock-cvg/contracts/Locking/LockingPositionDelegate.sol#L285
https://github.com/sherlock-audit/2023-11-convergence/blob/e894be3e36614a385cf409dc7e278d5b8f16d6f2/sherlock-cvg/contracts/Locking/LockingPositionDelegate.sol#L249

Tool used

Manual Review

Recommendation

Consider using this check only for a new delegatee.
delegateMgCvg:

 284        uint256 tokenIdsDelegated = mgCvgDelegatees[_to].length;
-285        require(tokenIdsDelegated < maxTokenIdsDelegated, "TOO_MUCH_MG_TOKEN_ID_DELEGATED");

 299        /** @dev Delegating.*/
 300        if (_percentage > 0) {
 301            MgCvgDelegatee memory delegatee = MgCvgDelegatee({delegatee: _to, percentage: _percentage});
 302
 303            /** @dev Updating delegatee.*/
 304            if (_isUpdate) {
 305                delegatedMgCvg[_tokenId][_toIndex] = delegatee;
 306            } else {
 307                /** @dev Adding new delegatee.*/
+                   require(tokenIdsDelegated < maxTokenIdsDelegated, "TOO_MUCH_MG_TOKEN_ID_DELEGATED");
 308                delegatedMgCvg[_tokenId].push(delegatee);
 309                mgCvgDelegatees[_to].push(_tokenId);
 310            }
 311        } else {

delegateVeCvg:

    function delegateVeCvg(uint256 _tokenId, address _to) external onlyTokenOwner(_tokenId) {
-       require(veCvgDelegatees[_to].length < maxTokenIdsDelegated, "TOO_MUCH_VE_TOKEN_ID_DELEGATED");
        /** @dev Find if this tokenId is already delegated to an address. */
        address previousOwner = delegatedVeCvg[_tokenId];
        if (previousOwner != address(0)) {
            /** @dev If it is  we remove the previous delegation.*/
            uint256 _toIndex = getIndexForVeDelegatee(previousOwner, _tokenId);
            uint256 _delegateesLength = veCvgDelegatees[previousOwner].length;
            /** @dev Removing delegation.*/
            veCvgDelegatees[previousOwner][_toIndex] = veCvgDelegatees[previousOwner][_delegateesLength - 1];
            veCvgDelegatees[previousOwner].pop();
        }

        /** @dev Associate tokenId to a new delegated address.*/
        delegatedVeCvg[_tokenId] = _to;

        if (_to != address(0)) {
            /** @dev Add delegation to the new address.*/
+           require(veCvgDelegatees[_to].length < maxTokenIdsDelegated, "TOO_MUCH_VE_TOKEN_ID_DELEGATED");            
            veCvgDelegatees[_to].push(_tokenId);
        }
        emit DelegateVeCvg(_tokenId, _to);

Duplicate of #142

@github-actions github-actions bot closed this as completed Dec 2, 2023
@github-actions github-actions bot added Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Dec 2, 2023
@nevillehuang nevillehuang removed the Medium A valid Medium severity issue label Dec 22, 2023
@sherlock-admin2 sherlock-admin2 changed the title Main Shadow Hare - Unexpected revert at the delegateMgCvg and delegateVeCvg when delegation removal pontifex - Unexpected revert at the delegateMgCvg and delegateVeCvg when delegation removal Dec 24, 2023
@sherlock-admin2 sherlock-admin2 added Non-Reward This issue will not receive a payout and removed Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Dec 24, 2023
@Czar102 Czar102 added the Medium A valid Medium severity issue label Jan 12, 2024
@sherlock-admin sherlock-admin added Reward A payout will be made for this issue and removed Non-Reward This issue will not receive a payout labels Jan 12, 2024
@sherlock-admin2 sherlock-admin2 added the Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label label Jan 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

4 participants