Cannot remove delegation from a token to another token
The removeDelegation function in a vote-escrow contract removes the token from its own list of delegators instead of from the delegatee's list, so a user cannot undo a delegation. The delegatee permanently keeps the voting power, which could enable governance attacks.
Submitted by Bahurum, also found by 0x52, 0xA5DF, 0xsanson, berndartmueller, cccz, CertoraInc, dipp, GalloDaSballo, GimelSec, Green, IllIllI, kenzo, MEP, panprog, and scaraven
A user who has delegated the vote of a veGolom token (that he/she owns) to another veGolom token cannot remove the delegation, so the delegatee token will permanently hold the voting power of the delegator token.
Proof of Concept
A user tries to remove the delegation from tokenId he/she owns to the delegated token, calling removeDelegation(uint256 tokenId).
The delegation should be removed at the lines:
Checkpoint storage checkpoint = checkpoints[tokenId][nCheckpoints - 1];
removeElement(checkpoint.delegatedTokenIds, tokenId);
but the array checkpoint.delegatedTokenIds is the list of delegators to tokenId itself. So, unless the delegation was from the token to itself, removeDelegation does nothing.
Recommended Mitigation Steps
Two fixes are proposed:
- Add the delegatee as an argument to
removeDelegationand removetokenIdfrom its list of delegators:
- function removeDelegation(uint256 tokenId) external {
+ function removeDelegation(uint256 tokenId, uint256 toTokenId) external {
require(ownerOf(tokenId) == msg.sender, 'VEDelegation: Not allowed');
uint256 nCheckpoints = numCheckpoints[tokenId];
- Checkpoint storage checkpoint = checkpoints[tokenId][nCheckpoints - 1];
+ Checkpoint storage checkpoint = checkpoints[toTokenId][nCheckpoints - 1];
removeElement(checkpoint.delegatedTokenIds, tokenId);
_writeCheckpoint(tokenId, nCheckpoints, checkpoint.delegatedTokenIds);
}
or
- Load the delegatee from the mapping
delegateswhich maps each delegator to its current delegatee:
function removeDelegation(uint256 tokenId) external {
require(ownerOf(tokenId) == msg.sender, 'VEDelegation: Not allowed');
+ uint256 toTokenId = delegates[tokenId];
uint256 nCheckpoints = numCheckpoints[tokenId];
- Checkpoint storage checkpoint = checkpoints[tokenId][nCheckpoints - 1];
+ Checkpoint storage checkpoint = checkpoints[toTokenId][nCheckpoints - 1];
removeElement(checkpoint.delegatedTokenIds, tokenId);
_writeCheckpoint(tokenId, nCheckpoints, checkpoint.delegatedTokenIds);
}
Note that in the mitigation,
nCheckpointsshould accesstoTokenIdinstead oftokenId.
Fixed. https://github.com/golom-protocol/contracts/commit/4b19fce83ad53bc56b1bad058e1e88d90acda444
LSDan (judge) increased severity to High and commented:
I agree with the other wardens who rated this high risk. It has a direct impact on the functioning of the protocol and allows for a myriad of governance attacks.
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 function reads the checkpoint for the delegator token instead of the delegatee token, so it removes the token from its own delegator list rather than the delegatee's.
Impact
The delegatee token permanently holds the voting power of the delegator token, which could enable governance attacks.
What the attacker needed
Own a veGolom token; have delegated its vote to another token
The fix
The issue was fixed by loading the delegatee token ID and using its checkpoint when removing the delegation.
How it was found
- A user owns a veGolom token and delegates its vote to another veGolom token.
- The user calls removeDelegation with their token ID.
- The function loads the checkpoint for the user's own token, not the delegatee.
- It removes the token from its own delegator list, which does not contain it, so nothing changes.
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 system, a token holder can lend their voting power to another token. The function meant to take that power back looks in the wrong place, so the loan never ends. The borrower keeps the votes forever, which could let them control decisions.
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.