Tokens with multiple entry points can lead to loss of funds in rageQuit()
The rageQuit() function in PartyGovernanceNFT.sol allows a party member to withdraw their share of tokens by passing an array of token addresses. If a token has multiple entry points (i.e., multiple addresses representing the same underlying token), an attacker can include all addresses in the array to withdraw more than their fair share, leading to loss of funds for other party members.
adriro Follow with hansfriese
Originally disclosed on Code4rena
Submitted by adriro, also found by hansfriese
ERC20 tokens with multiple entry points (also known as double entry tokens or two address tokens) can be used to exploit the rageQuit() function and steal funds from the party.
The rageQuit() function can be used by a party member to exit their position and claim their share of tokens present in the party. The implementation takes an arbitrary array of tokens and transfers the corresponding amount of each to the given receiver:
323: IERC20 prevToken;
324: for (uint256 j; j < withdrawTokens.length; ++j) {
325: IERC20 token = withdrawTokens[j];
326:
327: // Prevent null and duplicate transfers.
328: if (prevToken >= token) revert InvalidTokenOrderError();
329:
330: prevToken = token;
331:
332: // Check if token is ETH.
333: if (address(token) == ETH_ADDRESS) {
334: // Transfer fair share of ETH to receiver.
335: uint256 amount = (address(this).balance * shareOfVotingPower) / 1e18;
336: if (amount != 0) {
337: payable(receiver).transferEth(amount);
338: }
339: } else {
340: // Transfer fair share of tokens to receiver.
341: uint256 amount = (token.balanceOf(address(this)) * shareOfVotingPower) / 1e18;
342: if (amount != 0) {
343: token.compatTransfer(receiver, amount);
344: }
345: }
346: }
The function correctly considers potential duplicate elements in the array. Line 328 validates that token addresses are in ascending order and that the address from the previous iteration is different from the address of the current iteration, effectively disallowing duplicates.
However, this isn’t enough protection against tokens with multiple addresses. If the token has more than one entry point, then a bad actor can submit all of them to the rageQuit() function in order to execute the withdrawal multiple times, one for each available entry point. This will lead to the loss of funds to other party members, as this vulnerability can be exploited by an attacker to withdraw more tokens than deserved.
Proof of concept
Let’s assume there is a token with two entry points in address A and address B. The party holds 100 of these tokens and Alice, a party member, has an NFT corresponding to 50% of the total voting power.
Alice decides to exit her position by calling rageQuit(). Under normal circumstances, she would get 50 tokens, as she has 50% of the share in the party. However, Alice calls rageQuit() passing both address A and address B in the withdrawTokens array. As these are different addresses, the implementation will consider the argument valid, and execute the withdrawal two times. For the first address, Alice will be transferred 50 tokens (100 * 50% = 50), and for the other address, she will be transferred an additional of 25 tokens (50 * 50% = 25).
Recommendation
There is no easy solution for the issue. The usual recommendation in these cases is to implement a whitelist of supported tokens, but this will bring complexity and undermine the flexibility of the Party implementation.
Another alternative would be to first do a “snapshot” of available balances for the given tokens, and then, while executing the withdrawals, compare the current balance with the snapshot in order to detect changes:
- Loop through each token and store the balance of the party contract, i.e.
previousBalances[i] = withdrawTokens[i].balanceOf(address(this)). - Loop again through each token to execute withdrawals, but first check that the current balance matches the previous balance, i.e.
require(previousBalances[i] == withdrawTokens[i].balanceOf(address(this))).
If balances don’t match, this means that a previous withdrawal affected the balance of the current token, which may indicate and prevent a potential case of a token with multiple entry points.
Assessed type
Token-Transfer
Feel like this should be a QA, it can lead to loss of funds but only under the specific circumstance that a party holds two address tokens, which practically is very rare.
cccz (judge) decreased severity to Medium and commented:
TrueUSD is an example and has a fairly high market volume: https://medium.com/chainsecurity/trueusd-compound-vulnerability-bc5b696d29e2
Similar issues can be found in https://github.com/code-423n4/2023-04-frankencoin-findings/issues/886
But the difference is that in #886 the attacker is actively depositing TrueUSD to make the attack, while this issue requires the victim to deposit TrueUSD, and then the attacker can get more TrueUSD, so I would consider this to be M
Worth mentioning, the secondary entry to TrueUSD was disabled as a response to this type of vulnerability, so this is no longer possible. Not sure if any other notable tokens implement this pattern.
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
Impact
A party member could withdraw more tokens than their fair share, causing a loss of funds to other party members, but this only occurs if the party holds a token with multiple entry points, which is rare; the secondary entry for TrueUSD was disabled, making this no longer possible for that token.
What the attacker needed
Party holds a token with multiple entry points; attacker is a party member with voting power
The fix
The report suggests implementing a whitelist of supported tokens or taking a snapshot of balances before withdrawals and checking that balances remain unchanged to detect tokens with multiple entry points.
How it was found
- A party holds 100 tokens that have two entry points at addresses A and B.
- Alice, a party member with 50% voting power, calls rageQuit() passing both address A and address B in the withdrawTokens array.
- The contract processes address A first, transferring 50 tokens (100 * 50%) to Alice.
- The contract then processes address B, transferring an additional 25 tokens (50 * 50%) to Alice, because the balance has decreased but the share is still 50%.
- Alice ends up with 75 tokens instead of the 50 she deserved, causing a loss to other party members.
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.
Some digital tokens can be accessed through more than one address on the blockchain, like having two different keys to the same bank account. The party contract's exit function lets a member list token addresses to withdraw their share, but it only checks that the addresses are different, not that they represent the same token. So a member can list both addresses of the same token and get paid twice, taking more than their fair share and leaving less for others.
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.