PartyGovernanceNFT.sol : burn function does not reduce totalVotingPower making it impossible to reach unanimous votes
The burn function in PartyGovernanceNFT does not reduce totalVotingPower when a user burns their party card, so the sum of remaining voting power is less than totalVotingPower. This makes it impossible to reach a unanimous vote and reduces the relative value of remaining votes.
Originally disclosed on Code4rena
Submitted by HollaDieWaldfee
With the new version of the Party protocol the PartyGovernanceNFT.burn function has been introduced.
This function is used to burn party cards.
According to the sponsor the initial purpose of this function was to enable the InitialETHCrowdfund contract (the burn function is needed for refunds).
Later on they decided to allow any user to call this function and to burn their party cards.
The second use case when a regular user burns his party card is when the issue occurs.
The PartyGovernanceNFT.burn function does not decrease totalVotingPower which makes it impossible to reach an unanimous vote after a call to this function and it makes remaining votes of existing users less valuable than they should be.
Proof of Concept
Let’s look at the PartyGovernanceNFT.burn function:
function burn(uint256 tokenId) external onlyDelegateCall {
address owner = ownerOf(tokenId);
if (
msg.sender != owner &&
getApproved[tokenId] != msg.sender &&
!isApprovedForAll[owner][msg.sender]
) {
// Allow minter to burn cards if the total voting power has not yet
// been set (e.g. for initial crowdfunds) meaning the party has not
// yet started.
uint96 totalVotingPower = _governanceValues.totalVotingPower;
if (totalVotingPower != 0 || !isAuthority[msg.sender]) {
revert UnauthorizedToBurnError();
}
}
uint96 votingPower = votingPowerByTokenId[tokenId].safeCastUint256ToUint96();
mintedVotingPower -= votingPower;
delete votingPowerByTokenId[tokenId];
_adjustVotingPower(owner, -votingPower.safeCastUint96ToInt192(), address(0));
_burn(tokenId);
}
It burns the party card specified by the tokenId parameter and makes the appropriate changes to the voting power of the owner (by calling _adjustVotingPower) and to mintedVotingPower.
But it does not reduce totalVotingPower which remains untouched by this function.
In case this function is called by InitialETHCrowdfund it is intended that totalVotingPower is not reduced. In this case the burn function is only called when the initial crowdfund is lost and totalVotingPower hasn’t even been increased so it is still 0 (the initial value).
But why is it an issue when a regular user calls this function?
Let’s consider the following scenario:
Alice: 100 Votes
Bob: 100 Votes
Chris: 100 Votes
totalVotingPower = 300 Votes
Now Alice decides to burn half of her voting power:
Alice: 50 Votes
Bob: 100 Votes
Chris: 100 Votes
totalVotingPower = 300 Votes
Now it is easy to see why it is a problem that totalVotingPower is not reduced.
It is impossible to reach an unanimous vote because even if all users vote there is only a (250/300) = ~83% agreement.
One vote only represents 1/300 = ~ 0.33% of all votes even though it should represent 1/250 = 0.4% of all votes. And thereby votes are less valuable than they should be.
You can see in the following test that totalVotingPower stays unaffected even though voter1 burns his party card which represents a third of all votes.
(Add the test to the PartyGovernanceNFTUnit.sol test file and add this import: import "../../contracts/party/PartyGovernance.sol"; to access the GovernanceValues struct ).
function test_canntReachUnanimousVoteAfterBurning() external {
_initGovernance();
address voter1 = _randomAddress();
address voter2 = _randomAddress();
address voter3 = _randomAddress();
uint256 vp = defaultGovernanceOpts.totalVotingPower / 3;
uint256 token1 = nft.mint(voter1, vp, voter1);
uint256 token2 = nft.mint(voter2, vp, voter2);
uint256 token3 = nft.mint(voter3, vp, voter3);
assertEq(nft.mintedVotingPower(), vp*3);
assertEq(nft.getCurrentVotingPower(voter1), vp);
PartyGovernance.GovernanceValues memory gv = nft.getGovernanceValues();
console.log(gv.totalVotingPower);
vm.prank(voter1);
nft.burn(token1);
gv = nft.getGovernanceValues();
// totalVotingPower stays the same
console.log(gv.totalVotingPower);
}
The remaining two voters will not be able to reach unanimous vote since the _isUnanimousVotes function is called with totalVotingPower as the total votes with which to calculate the percentage.
if (_isUnanimousVotes(pv.votes, _governanceValues.totalVotingPower)) {
if (_isUnanimousVotes(pv.votes, gv.totalVotingPower)) {
Tools Used
VSCode
Recommended Mitigation Steps
It is important to understand that when InitialETHCrowdfund calls the burn function it is intended that totalVotingPower is not reduced.
So we need to differentiate these two cases.
Fix:
diff --git a/contracts/party/PartyGovernanceNFT.sol b/contracts/party/PartyGovernanceNFT.sol
index 9ccfa1f..d382d0e 100644
--- a/contracts/party/PartyGovernanceNFT.sol
+++ b/contracts/party/PartyGovernanceNFT.sol
@@ -200,6 +200,7 @@ contract PartyGovernanceNFT is PartyGovernance, ERC721, IERC2981 {
/// @param tokenId The ID of the NFT to burn.
function burn(uint256 tokenId) external onlyDelegateCall {
address owner = ownerOf(tokenId);
+ uint96 totalVotingPower = _governanceValues.totalVotingPower;
if (
msg.sender != owner &&
getApproved[tokenId] != msg.sender &&
@@ -208,7 +209,6 @@ contract PartyGovernanceNFT is PartyGovernance, ERC721, IERC2981 {
// Allow minter to burn cards if the total voting power has not yet
// been set (e.g. for initial crowdfunds) meaning the party has not
// yet started.
- uint96 totalVotingPower = _governanceValues.totalVotingPower;
if (totalVotingPower != 0 || !isAuthority[msg.sender]) {
revert UnauthorizedToBurnError();
}
@@ -218,6 +218,10 @@ contract PartyGovernanceNFT is PartyGovernance, ERC721, IERC2981 {
mintedVotingPower -= votingPower;
delete votingPowerByTokenId[tokenId];
+ if (totalVotingPower != 0 || !isAuthority[msg.sender]) {
+ _governanceValues.totalVotingPower = totalVotingPower - votingPower;
+ }
+
_adjustVotingPower(owner, -votingPower.safeCastUint96ToInt192(), address(0));
_burn(tokenId);
Also note that the || !isAuthority[msg.sender] part of the condition is important.
It ensures that if we are not yet in the governance phase, i.e. totalVotingPower == 0 and a user calls the burn function he cannot burn his party card. This is because the totalVotingPower - votingPower subtraction results in an underflow.
This ensures that in the pre-governance phase a user cannot accidentally burn his party card. He can only burn it via the InitialETHCrowdfund contract which ensures the user gets his ETH refund.
@HollaDieWaldfee - I like the recommended mitigation. Had a question, if there were snapshots of
totalVotingPowerfor each proposal is it fine that those are not updated? It is the same as if that an inactive user did not vote on a proposal, which can happen already. My concerns with updating it is that it seems like a riskier mitigation to implement that may cause unintended side-effects (if not now, later down the line). I also don’t want to add more storage to the contract to fix this (it is already at with the contract size limit with--via-irenabled).
HollaDieWaldfee (warden) commented:
@0xble - Yes I think it is ok to not update the snapshots. I have the same reasoning as you that it’s basically just an inactive user.
And I agree that updating instead is wrong because it gives remaining users higher voting power.
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 burn function updates the caller's voting power and mintedVotingPower but leaves totalVotingPower unchanged, so the denominator used for unanimity checks no longer matches the sum of remaining votes.
Impact
After a user burns their card, unanimous votes become impossible and each remaining vote represents a smaller share of the total than it should, weakening governance.
What the attacker needed
A party with governance started; a user who owns a party card; the user burns their card
The fix
The burn function should reduce totalVotingPower when the party is in the governance phase, while leaving it unchanged for the InitialETHCrowdfund refund case.
How it was found
- Set up governance with three voters each holding a third of the total voting power.
- Have one voter burn their party card.
- Observe that totalVotingPower is unchanged after the burn.
- Note that the remaining two voters cannot reach a unanimous vote because the unanimity check still uses the old total.
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 voting system, each member's voting power is a share of a total. When someone destroys their voting card, their own power is removed, but the total is not lowered. So the remaining members can never collectively reach 100% of the old total, even if all of them vote.
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.