Self-delgated users can have their delegation unknowingly hijacked during crowdfunding
A user who self-delegates by passing a zero address as delegate can have their delegation overwritten by anyone who contributes on their behalf, because the contract treats a zero delegate as 'use current delegate' and allows the caller to set any delegate when the contributor has not yet delegated. An attacker can therefore hijack the voting power of a self-delegated user, especially in ReraiseETHCrowdfund where NFTs are minted only after the crowdfund succeeds.
Submitted by 0x52
Self-delegation can be hijacked.
Proof of Concept
function _adjustVotingPower(address voter, int192 votingPower, address delegate) internal {
VotingPowerSnapshot memory oldSnap = _getLastVotingPowerSnapshotForVoter(voter);
address oldDelegate = delegationsByVoter[voter];
// If `oldDelegate` is zero and `voter` never delegated, then have
// `voter` delegate to themself.
oldDelegate = oldDelegate == address(0) ? voter : oldDelegate;
// If the new `delegate` is zero, use the current (old) delegate.
delegate = delegate == address(0) ? oldDelegate : delegate;
VotingPowerSnapshot memory newSnap = VotingPowerSnapshot({
timestamp: uint40(block.timestamp),
delegatedVotingPower: oldSnap.delegatedVotingPower,
intrinsicVotingPower: (oldSnap.intrinsicVotingPower.safeCastUint96ToInt192() +
votingPower).safeCastInt192ToUint96(),
isDelegated: delegate != voter
});
_insertVotingPowerSnapshot(voter, newSnap);
delegationsByVoter[voter] = delegate;
// Handle rebalancing delegates.
_rebalanceDelegates(voter, oldDelegate, delegate, oldSnap, newSnap);
}
Self-delegation is triggered when a user specifies their delegate as address(0). This means that if a user wishes to self-delegate they will can contribute to a crowdfund with delegate == address(0).
ETHCrowdfundBase.sol#L169-L181
function _processContribution(
address payable contributor,
address delegate,
uint96 amount
) internal returns (uint96 votingPower) {
address oldDelegate = delegationsByContributor[contributor];
if (msg.sender == contributor || oldDelegate == address(0)) {
// Update delegate.
delegationsByContributor[contributor] = delegate;
} else {
// Prevent changing another's delegate if already delegated.
delegate = oldDelegate;
}
This method of self-delegation is problematic when combined with _processContribution. When contributing for someone else, the caller is allowed to specify any delegate they wish. If that user is currently self delegated, then the newly specified delegate will overwrite their self delegation. This allows anyone to hijack the voting power of a self-delegated user.
This can create serious issues for ReraiseETHCrowdfund because party NFTs are not minted until after the entire crowdfund is successful. Unlike InitialETHCrowdfund, this allows the attacker to hijack all of the user’s newly minted votes.
Example:
minContribution = 1 and maxContribution = 100. User A contributes 100 to ReraiseETHCrowdfund. They wish to self-delegate so they call contribute with delegate == address(0). An attacker now contributes 1 on behalf of User A with themselves as the delegate. Now when the NFTs are claimed, they will be delegated to the attacker.
Recommended Mitigation Steps
Self-delegation should be automatically hardcoded:
+ if (msg.sender == contributor && delegate == address(0)) {
+ delegationsByContributor[contributor] = contributor;
+ }
address oldDelegate = delegationsByContributor[contributor];
if (msg.sender == contributor || oldDelegate == address(0)) {
// Update delegate.
delegationsByContributor[contributor] = delegate;
} else {
// Prevent changing another's delegate if already delegated.
delegate = oldDelegate;
}
This appears valid at first pass and allows anyone to steal self delegations.
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
Likely the contract treats a zero delegate as 'use current delegate' and allows a third party to set the delegate when the contributor has no existing delegation, so a self-delegated user's zero-address delegation is overwritten by any contributor.
Impact
An attacker could hijack the voting power of a self-delegated user, and in ReraiseETHCrowdfund this includes all newly minted votes after the crowdfund succeeds.
What the attacker needed
Victim self-delegates with zero address; attacker can contribute on behalf of victim; crowdfund succeeds
The fix
Self-delegation should be automatically hardcoded so that when a contributor sets delegate to zero, the delegation is explicitly set to the contributor themselves.
How it was found
- User A contributes to ReraiseETHCrowdfund with delegate set to address(0) to self-delegate.
- Attacker contributes a small amount on behalf of User A with the attacker as delegate.
- When NFTs are claimed, User A's voting power is delegated to the attacker.
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, users can delegate their voting power to themselves or to someone else. A user who wants to keep their own voting power passes a special empty value (zero address) to mean 'delegate to me'. But the code also lets anyone contribute on behalf of another user and choose a delegate. If the original user has not yet been recorded as delegated, the attacker's chosen delegate replaces the self-delegation, so the victim's votes go to the attacker.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.