Skip to content
Business logic Audit finding Intermediate

The total community voting power is updated incorrectly when a user delegates

The total community voting power is updated incorrectly when a user delegates their staked tokens, because the update logic does not check whether the delegator or delegatee already had voting power. This can cause the total community voting power to be wrong.

curiousapple Follow with hansfriese and Trumpero

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-11-frankendao-judging/issues/91

Found by

curiousapple, hansfriese, Trumpero

Summary

When a user delegates their voting power from staked tokens, the total community voting power should be updated. But the update logic is not correct, the the total community voting power could be wrong values.

Vulnerability Detail

Solidity
    tokenVotingPower[currentDelegate] -= amount;
    tokenVotingPower[_delegatee] += amount; 

    // If a user is delegating back to themselves, they regain their community voting power, so adjust totals up
    if (_delegator == _delegatee) {
      _updateTotalCommunityVotingPower(_delegator, true);

    // If a user delegates away their votes, they forfeit their community voting power, so adjust totals down
    } else if (currentDelegate == _delegator) {
      _updateTotalCommunityVotingPower(_delegator, false);
    }

When the total community voting power is increased in the first if statement, _delegator's token voting power might be positive already and community voting power might be added to total community voting power before.

Also, currentDelegate's token voting power might be still positive after delegation so we shouldn't remove the communitiy voting power this time.

Impact

The total community voting power can be incorrect.

Code Snippet

https://github.com/sherlock-audit/2022-11-frankendao/blob/main/src/Staking.sol#L293-L313

Tool used

Manual Review

Recommendation

Add more conditions to check if the msg.sender delegated or not.

Solidity
    if (_delegator == _delegatee) {
        if(tokenVotingPower[_delegatee] == amount) {
            _updateTotalCommunityVotingPower(_delegator, true);
        }
        if(tokenVotingPower[currentDelegate] == 0) {
            _updateTotalCommunityVotingPower(currentDelegate, false);      
        }
    } else if (currentDelegate == _delegator) {
        if(tokenVotingPower[_delegatee] == amount) {
            _updateTotalCommunityVotingPower(_delegatee, true);
        }
        if(tokenVotingPower[_delegator] == 0) {
            _updateTotalCommunityVotingPower(_delegator, false);      
        }
    }

Discussion

zobront

Fixed: https://github.com/Solidity-Guild/FrankenDAO/pull/15

Note for JTP: Please double check this one, as I'm 99% confident but would love a second set of eyes on it.

jack-the-pug

Fix confirmed

The original report as published on Sherlock, by curiousapple. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 delegation logic updates the total community voting power without checking whether the delegator or delegatee already had a positive token voting power, leading to double counting or incorrect removal.

Impact

The total community voting power can be incorrect.

What the attacker needed

User must stake tokens; user must delegate voting power

The fix

The issue was fixed by adding conditions to check if the delegator or delegatee already had voting power before updating the total community voting power.

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, people stake tokens and can delegate their voting power to someone else. The total voting power of the community is supposed to change when someone delegates, but the code adds or removes that power without checking if it was already counted. This can make the total voting power incorrect.

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.

More by curiousapple

View all

1 more disclosed report, best first.

More from FrankenDAO

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.