Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RE-DELEGATE AND UNDELEGATE CAN BE FRONT RUN IN VotinEscrow.sol #264

Closed
code423n4 opened this issue Aug 10, 2023 · 9 comments
Closed

RE-DELEGATE AND UNDELEGATE CAN BE FRONT RUN IN VotinEscrow.sol #264

code423n4 opened this issue Aug 10, 2023 · 9 comments
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-182 partial-50 Incomplete articulation of vulnerability; eligible for partial credit only (50%) upgraded by judge Original issue severity upgraded from QA/Gas by judge

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-08-verwa/blob/a693b4db05b9e202816346a6f9cada94f28a2698/src/VotingEscrow.sol#L390

Vulnerability details

Impact

User can not undelegate or redelegate is a malicius delegatee front run the user transaction increasing his amount of time to end calling increaseAmount.

Proof of Concept

We can explore this analyzing both functions:


file:src/VotingEscrow.sol
    function delegate(address _addr) external nonReentrant {
        
        ...
        } else if (_addr == msg.sender) {
            // Undelegate
            fromLocked = locked[delegatee];
            toLocked = locked_;
        } else {
            // Re-delegate
            fromLocked = locked[delegatee];
            toLocked = locked[_addr];
            // Update owner lock if not involved in delegation
            locked[msg.sender] = locked_;
        }
        ...
        require(toLocked.end >= fromLocked.end, "Only delegate to longer lock");
        ...
    }

https://github.com/code-423n4/2023-08-verwa/blob/a693b4db05b9e202816346a6f9cada94f28a2698/src/VotingEscrow.sol#L390C1-L409C6

This function require that old delegatee end be less than the new delegatee.

Now analyse the increaseAmount function:

file:src/VotingEscrow.sol
function increaseAmount(uint256 _value) external payable nonReentrant {
        LockedBalance memory locked_ = locked[msg.sender];
        ...
        LockedBalance memory newLocked = _copyLock(locked_);
        newLocked.amount += int128(int256(_value));
        newLocked.end = _floorToWeek(block.timestamp + LOCKTIME);
        if (delegatee == msg.sender) {
            // Undelegated lock
            action = LockAction.INCREASE_AMOUNT_AND_DELEGATION;
            newLocked.delegated += int128(int256(_value));
            locked[msg.sender] = newLocked;
            _checkpoint(msg.sender, locked_, newLocked);
        } else {
            // Delegated lock, update sender's lock first
            locked[msg.sender] = newLocked;
           ...
        }
        emit Deposit(msg.sender, _value, unlockTime, action, block.timestamp);
    }

https://github.com/code-423n4/2023-08-verwa/blob/a693b4db05b9e202816346a6f9cada94f28a2698/src/VotingEscrow.sol#L288C5-L324C1

This function is increasing the time of the end by 5 years, so if a delegatee see in the mempool that he is gonna be undelegate or re delegate, he can front run that transaction calling increaseAmount passing 1 wei and increasing his end for 5 years more breaking the require(toLocked.end >= fromLocked.end, "Only delegate to longer lock") in delegate function.

Tools Used

manual

Recommended Mitigation Steps

One recomendation is follow what FIAT DAO is doing in his VotingEscrow contract,
other approach that the project can take is eliminate the increasing of the time end when user call increasAmount, there is not incentive to the user to call that function if he is gonna lock for 5 years more

Assessed type

Other

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Aug 10, 2023
code423n4 added a commit that referenced this issue Aug 10, 2023
@c4-pre-sort
Copy link

141345 marked the issue as duplicate of #116

@c4-pre-sort
Copy link

141345 marked the issue as duplicate of #82

@c4-judge c4-judge added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value downgraded by judge Judge downgraded the risk level of this issue and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Aug 24, 2023
@c4-judge
Copy link

alcueca changed the severity to 2 (Med Risk)

@c4-judge c4-judge added duplicate-411 partial-50 Incomplete articulation of vulnerability; eligible for partial credit only (50%) and removed duplicate-82 labels Aug 24, 2023
@c4-judge
Copy link

alcueca marked the issue as partial-50

@c4-pre-sort
Copy link

141345 marked the issue as not a duplicate

@c4-pre-sort c4-pre-sort reopened this Aug 24, 2023
@c4-pre-sort c4-pre-sort removed partial-50 Incomplete articulation of vulnerability; eligible for partial credit only (50%) duplicate-411 labels Aug 24, 2023
@c4-pre-sort
Copy link

141345 marked the issue as duplicate of #375

@c4-judge
Copy link

alcueca marked the issue as partial-50

@c4-judge c4-judge added partial-50 Incomplete articulation of vulnerability; eligible for partial credit only (50%) duplicate-245 duplicate-182 and removed duplicate-375 duplicate-245 labels Aug 24, 2023
@c4-judge
Copy link

alcueca marked the issue as duplicate of #182

@c4-judge c4-judge added 3 (High Risk) Assets can be stolen/lost/compromised directly upgraded by judge Original issue severity upgraded from QA/Gas by judge and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value downgraded by judge Judge downgraded the risk level of this issue labels Aug 29, 2023
@c4-judge
Copy link

alcueca changed the severity to 3 (High Risk)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-182 partial-50 Incomplete articulation of vulnerability; eligible for partial credit only (50%) upgraded by judge Original issue severity upgraded from QA/Gas by judge
Projects
None yet
Development

No branches or pull requests

3 participants