[BUG]: One blocked recipient makes distributeFunds revert and locks all vault funds

Open
#90 0 comments 0 reactions 0 assignees View on GitHub

@Deepak-negi11 is already working on this.

Since Nov 13, 2026.

  • #91 by @Deepak-negi11 — open

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

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
Bug Description

FundingVault.distributeFunds() pays every winning proposal and the platform fee in one transaction.

https://github.com/StabilityNexus/FairFund/blob/4f8d67655362367fbfb0b444a7ab28bc6cdb4e44/app/blockchain/src/FundingVault.sol#L286-L316

Each payout reverts the whole call if the transfer fails.

https://github.com/StabilityNexus/FairFund/blob/4f8d67655362367fbfb0b444a7ab28bc6cdb4e44/app/blockchain/src/FundingVault.sol#L301-L304

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.

https://github.com/StabilityNexus/FairFund/blob/4f8d67655362367fbfb0b444a7ab28bc6cdb4e44/app/blockchain/src/FundingVault.sol#L345-L348

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.

  1. An honest recipient is blocked by the token issuer after the vote.
  2. Anyone can do it on purpose. submitProposal() only checks that _recipient is not zero, and the recipient can never be changed.

https://github.com/StabilityNexus/FairFund/blob/4f8d67655362367fbfb0b444a7ab28bc6cdb4e44/app/blockchain/src/FundingVault.sol#L211-L215

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.

https://github.com/StabilityNexus/FairFund/blob/4f8d67655362367fbfb0b444a7ab28bc6cdb4e44/app/blockchain/src/FundingVault.sol#L309-L315

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.

  1. 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.
  2. The platform fee works the same way with retryPlatformFee().
  3. 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
  1. Create a vault whose funding token can block addresses (for example USDC).
  2. Two users deposit. Two proposals get votes and win.
  3. The token blocks one winning recipient. Or an attacker submits a proposal with a blocked recipient and votes for it with a tiny amount.
  4. After the tally date call distributeFunds(). It reverts.
  5. Each depositor calls withdrawRemaining(). It reverts with FundingVault__FundsNotDistributedYet.
  6. 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: 4f8d676 on main
  • 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from StabilityNexus/FairFund

All issues in StabilityNexus/FairFund

Similar issues

More Blockchain issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.