setVoteFactor() does not change existing supply of votes. As a result, some may be unable to withdraw
The setVoteFactor function changes the vote factor without adjusting the existing supply of vote tokens, so users who initialised their distribution records before the change may have too few vote tokens to burn when claiming, causing their withdrawal to revert. An attacker could not directly exploit this, but the owner's action could lock funds for affected users.
0xDjango Follow with 0xbranded, AkshaySrivastav and 10 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-06-tokensoft-judging/issues/55
Found by
0xDjango, 0xbranded, AkshaySrivastav, BenRai, Czar102, Yuki, auditsea, caventa, jkoppel, mau, p12473, pengun, r0bert
Summary
AdvancedDistributor.setVoteFactor() does not change existing supply of vote tokens. If it is called before all distribution records have been initialized, there will be a skew between those who initialized before and those who initialized after. Further, if it is increased, those who initialized before will not have enough vote tokens to withdraw.
Vulnerability Detail
Increase scenario (very bad):
- Owner makes airdrop and sets vote factor to 1. Many people get a claim to 1000 airdrop tokens.
- People initialize their distribution records. They are minted 1000 vote tokens.
- Owner sets vote factor to 2
- The airdrop tokens vest
- No-one who already initialized their distribution record can withdraw anything because they don't have enough vote tokens. (Vote tokens are burned when executing a claim.)
Decrease scenario (less bad):
- Owner makes an airdrop for 1000 people managed by a CrosschainMerkleDistribution and sets vote factor to 1000
- User Speedy Gonzalez calls initializeDistributionRecord() for himself
- Owner decides to change the vote factor to 1 instead
- All other users only get 1 voting token, but Speedy still has 1000
Impact
Increase scenario
If the vote factor is increased after deploying the contract, some people will not be able to withdraw, period.
It is still possible, however, for the owner of the contract to sweep the contract and manually give people their airdrop.
Decrease scenario
Cannot change vote factor after deploying contract without skewing existing votes.
Note there is no other mechanism to mint or burn vote tokens to correct this.
There is no code that currently uses voting, so this is potentially of no consequence.
However, presumably the voting functionality exists for a reason, and will be used by other code. In particular, the implementation of adjust() takes care to preserve people's number of voting tokens. As the distributor contracts are not upgradeable, this means no fair elections can be run atop airdrops deployed with the current code after setVoteFactor is called.
Code Snippet
function setVoteFactor(uint256 _voteFactor) external onlyOwner {
voteFactor = _voteFactor;
emit SetVoteFactor(voteFactor);
}
setVoteFactor does not change supply
function _initializeDistributionRecord(
address beneficiary,
uint256 totalAmount
) internal virtual override {
super._initializeDistributionRecord(beneficiary, totalAmount);
// add voting power through ERC20Votes extension
_mint(beneficiary, tokensToVotes(totalAmount));
}
Voting tokens are minted at distribution record initialization time.
function _executeClaim(
address beneficiary,
uint256 totalAmount
) internal virtual override returns (uint256 _claimed) {
_claimed = super._executeClaim(beneficiary, totalAmount);
// reduce voting power through ERC20Votes extension
_burn(beneficiary, tokensToVotes(_claimed));
}
tokensToVotes uses the current voteFactor. If it has increased since someone's vote tokens were minted, they will not have enough tokens to burn, and so executeClaim will revert.
Tool used
Manual Review
Recommendation
Do not use separate voting tokens for votes; just use the amount of unclaimed token
Discussion
cr-walker
This is a valid issue.
The admin functions like setVoteFactor() should only be called by admins who know what they are doing, but I agree that this would result in unexpected behavior like locking funds due to burning too many vote tokens.
Proposed solution:
- The reason we are using an internal votes token is to allow delegation, but I agree that using the unclaimed token would be simpler and generally better
- we will either remove the
setVoteFactormethod or allow users to reset their voting power, e.g. using something like the solution to: https://github.com/sherlock-audit/2023-06-tokensoft-judging/issues/188
cr-walker
Fixed by https://github.com/SoftDAO/contracts/pull/10
maarcweiss
Fixed by adding a function to update the voting power when claiming and initializing the distribution.
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 vote factor is applied at claim time using the current value, while vote tokens were minted at initialisation using the old value, creating a mismatch.
Impact
If the vote factor is increased after some users have initialised, those users may be unable to withdraw their airdrop at all; the owner could still sweep the contract and distribute manually.
What the attacker needed
Owner calls setVoteFactor after some initialisations; affected user has already initialised
The fix
The issue was fixed by adding a function to update voting power when claiming and initialising the distribution.
How it was found
- Owner sets a vote factor and users initialise their distribution records, receiving vote tokens based on that factor.
- Owner changes the vote factor to a higher value.
- Airdrop tokens vest.
- A user who initialised before the change tries to claim, but the contract attempts to burn more vote tokens than they have, so the claim reverts.
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.
When people join an airdrop, the contract gives them special 'vote tokens' based on a multiplier called the vote factor. If the owner later increases that multiplier, new joiners get more vote tokens, but existing users still have the old amount. When those existing users try to claim their airdrop, the contract tries to burn vote tokens at the new higher rate, which fails because they don't have enough, so they cannot withdraw.
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.