Delegated votes are locked when owner lock is expired
A user who delegated their locked votes could not undelegate after their lock expired, because the undelegate function required the lock to still be active. This meant the user could not withdraw their tokens, effectively locking them forever.
ltyu Follow with qpzm, RED-LOTUS-REACH and 15 others
Originally disclosed on Code4rena
Submitted by ltyu, also found by qpzm, RED-LOTUS-REACH, bart1e, 0xDING99YA, zhaojie, popular00, MrPotatoMagic, carrotsmuggler, pep7siup, 3docSec, mert_eren, kaden, Yuki, seerether, KmanOfficial, cducrest (1, 2), Tendency, and bin2chen
In delegate() of VoteEscrow.sol, a user is able to delegate their locked votes to someone else, and undelegate (i.e. delegate back to themselves). When the user tries to re-delegate, either to someone else or themselves, the lock must not be expired. This is problematic because if a user forgets and lets their lock become expired, they cannot undelegate. This blocks withdrawal, which means their tokens are essentially locked forever.
Proof of Concept
To exit the system, Alice must call withdraw(). However, since they’ve delegated, they will not be able to.
function withdraw() external nonReentrant {
...
require(locked_.delegatee == msg.sender, "Lock delegated");
...
}
To re-delegate to themselves (undelegate), they call delegate(alice.address). However, there is a check to see if toLocked.end has expired, which would be true since it would point to Alice’s lock.
function delegate(address _addr) external nonReentrant {
LockedBalance memory locked_ = locked[msg.sender];
...
LockedBalance memory fromLocked;
LockedBalance memory toLocked;
locked_.delegatee = _addr;
if (delegatee == msg.sender) {
...
// @audit this else if will execute
} else if (_addr == msg.sender) {
// Undelegate
fromLocked = locked[delegatee]; // @audit Delegatee
toLocked = locked_; // @audit Alice's lock
}
...
require(toLocked.end > block.timestamp, "Delegatee lock expired");
This is a test to be added into VoteEscrow.t.sol. It can be manually run by executing forge test --match-test testUnSuccessUnDelegate.
function testUnSuccessUnDelegate() public {
testSuccessDelegate();
vm.warp(ve.LOCKTIME() + 1 days);
// Try to undelegate
vm.startPrank(user1);
vm.expectRevert("Delegatee lock expired");
ve.delegate(user1);
// Still user2
(, , , address delegatee) = ve.locked(user1);
assertEq(delegatee, user2);
}
Recommended Mitigation Steps
Consider refactoring the code to skip toLocked.end > block.timestamp if undelegating. For example, adding a small delay (e.g., 1 second) to the lock end time when a user undelegates.
This vulnerability, if not found, would have meant that some users would have permanently lost assets in the form of voting power. While at that point the application owners would certainly warn users to not let their locks expire without undelegating, many users would not get the warning, as it is not that easy to make sure that every user is aware of something. The result is that time and again, users would get their tokens locked forever.
OpenCoreCH (veRWA) confirmed on duplicate 112
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The undelegate function incorrectly checks that the delegatee's lock has not expired, even when the caller is undelegating to themselves.
Impact
Users who delegated and let their lock expire could permanently lose access to their locked tokens.
What the attacker needed
User has locked tokens; user has delegated votes; lock has expired
The fix
The code should be refactored to skip the lock expiry check when a user is undelegating.
How it was found
- Alice delegates her votes to Bob.
- Alice's lock expires.
- Alice tries to undelegate by calling delegate with her own address.
- The transaction reverts with 'Delegatee lock expired'.
- Alice cannot withdraw her tokens.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In this voting system, users lock tokens and can let someone else use their voting power. If they later want to take that power back, they must do so before their lock expires. If they forget, the system won't let them take it back, and they can't get their tokens out.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.