[BUG]: with a proposal and no registered voters distributeFunds always reverts and deposits get locked forever
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- solidity
- Domain
- blockchain
Research direction
Start in app/blockchain/src/FundingVault.sol at calculateFundingToBeReceived(), around lines 249-252, where it reverts when no voting power tokens exist, then check its callers in distributeFunds() (around lines 294-295) and withdrawRemaining() (around lines 345-348). Run the reproduction with cd app/blockchain && forge test --match-contract FundingVaultNoVotersTest -vvv in test/unit/FundingVaultNoVoters.t.sol. Done means the lock case no longer reverts, depositors can withdraw, and the existing test suite still passes.
Written by the indexing model from the issue text.
Description
Bug Description
if nobody calls register() before the tally date and the vault has at least one proposal then distributeFunds() reverts every time and no depositor can ever withdraw
calculateFundingToBeReceived() reverts when no voting power tokens exist
distributeFunds() calls it for every proposal so one proposal is enough
and withdrawRemaining() only works after distribution
voting power tokens only come from register() because VotingPowerToken.mint is onlyOwner and the owner is the vault (FairFund.sol L112). the vault only mints in register() (L183). register() stops working once block.timestamp > tallyDate
so after the tally date nothing can fix it and all deposits stay in the vault forever. the vault has no owner and no rescue function
anyone can do this since submitProposal() needs no deposit or voting tokens only gas (L196). it can also happen by accident in a quiet vault where people submit proposals but nobody registers
with no proposals the loop never runs and depositors get everything back. one registration before the tally date also avoids the lock. the test below shows all 3 cases
possible fix: make calculateFundingToBeReceived() return 0 instead of reverting when no voting power tokens exist (L250-L252). no proposal can win without votes so distributeFunds() pays nobody and marks the funds as distributed and depositors can withdraw everything. its a one line change and it also stops the frontend tally route from failing for these vaults. i tried it locally and all existing tests still pass
Steps to Reproduce
- create a vault and have two users deposit
- anyone submits one proposal
- nobody calls
register()before the tally date - after the tally date call
distributeFunds()and it reverts withFundingVault__NoVotingPowerTokenMinted - depositors call
withdrawRemaining()and it reverts withFundingVault__FundsNotDistributedYet register()now reverts withFundingVault__TallyDatePassedand 10 years later it all still reverts
test file is below (app/blockchain/test/unit/FundingVaultNoVoters.t.sol)
cd app/blockchain
forge test --match-contract FundingVaultNoVotersTest -vvv
Logs and Screenshots
Ran 3 tests for test/unit/FundingVaultNoVoters.t.sol:FundingVaultNoVotersTest
[PASS] test_NoProposalsNoVoters_DepositorsWithdrawAll() (gas: 127256)
[PASS] test_OneProposalNoVoters_LocksDepositsForever() (gas: 375278)
[PASS] test_OneRegistrationBeforeTally_AvoidsLock() (gas: 416212)
Suite result: ok. 3 passed; 0 failed; 0 skipped; finished in 4.79ms (1.41ms CPU time)
Ran 1 test suite in 108.33ms (4.79ms CPU time): 3 tests passed, 0 failed, 0 skipped (3 total tests)
trace for test_OneProposalNoVoters_LocksDepositsForever
├─ [37040] FundingVault::distributeFunds()
│ ├─ [2482] FairFund::getPlatformFee() [staticcall]
│ │ └─ ← [Return] 5
│ ├─ [2505] VotingPowerToken::totalSupply() [staticcall]
│ │ └─ ← [Return] 0
│ └─ ← [Revert] FundingVault__NoVotingPowerTokenMinted()
├─ [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()
FundingVaultNoVoters.t.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import {Test} from "forge-std/Test.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";
contract FundingVaultNoVotersTest is Test {
FairFund fairFund;
FundingVault vault;
MockERC20 fundingToken;
MockERC20 votingToken;
VotingPowerToken votingPowerToken;
address alice = makeAddr("alice"); // depositor
address bob = makeAddr("bob"); // depositor
address attacker = makeAddr("attacker"); // holds no tokens at all
address voter = makeAddr("voter");
uint256 constant ALICE_DEPOSIT = 60 ether;
uint256 constant BOB_DEPOSIT = 40 ether;
function setUp() external {
fairFund = new FairFund(5);
fundingToken = new MockERC20("FundingToken", "FTK");
votingToken = new MockERC20("VotingToken", "VTK");
votingPowerToken = new VotingPowerToken("VotingPowerToken", "VOTE", votingToken.decimals());
vault = new FundingVault(
address(fundingToken),
address(votingToken),
address(votingPowerToken),
1,
50 ether,
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();
}
// Baseline: with no proposals and no voters, depositors get everything back.
function test_NoProposalsNoVoters_DepositorsWithdrawAll() public {
vm.warp(block.timestamp + 2 days);
vault.distributeFunds();
vm.prank(alice);
vault.withdrawRemaining();
vm.prank(bob);
vault.withdrawRemaining();
assertEq(fundingToken.balanceOf(alice), ALICE_DEPOSIT);
assertEq(fundingToken.balanceOf(bob), BOB_DEPOSIT);
assertEq(fundingToken.balanceOf(address(vault)), 0);
}
// One proposal from anyone, and nobody registers voting tokens before the tally date.
function test_OneProposalNoVoters_LocksDepositsForever() public {
vm.prank(attacker);
vault.submitProposal("any proposal", 1, 1 ether, attacker);
vm.warp(block.timestamp + 2 days);
vm.expectRevert(FundingVault.FundingVault__NoVotingPowerTokenMinted.selector);
vault.distributeFunds();
vm.prank(alice);
vm.expectRevert(FundingVault.FundingVault__FundsNotDistributedYet.selector);
vault.withdrawRemaining();
vm.prank(bob);
vm.expectRevert(FundingVault.FundingVault__FundsNotDistributedYet.selector);
vault.withdrawRemaining();
// Nobody can fix it after the tally date: register is closed.
votingToken.mint(alice, 1 ether);
vm.startPrank(alice);
votingToken.approve(address(vault), 1 ether);
vm.expectRevert(FundingVault.FundingVault__TallyDatePassed.selector);
vault.register(1 ether);
vm.stopPrank();
// Still locked 10 years later.
vm.warp(block.timestamp + 3650 days);
vm.expectRevert(FundingVault.FundingVault__NoVotingPowerTokenMinted.selector);
vault.distributeFunds();
vm.prank(alice);
vm.expectRevert(FundingVault.FundingVault__FundsNotDistributedYet.selector);
vault.withdrawRemaining();
assertEq(fundingToken.balanceOf(address(vault)), ALICE_DEPOSIT + BOB_DEPOSIT);
}
// The lock only happens when nobody registers. One registration before the tally date avoids it.
function test_OneRegistrationBeforeTally_AvoidsLock() public {
vm.prank(attacker);
vault.submitProposal("any proposal", 1, 1 ether, attacker);
votingToken.mint(voter, 1);
vm.startPrank(voter);
votingToken.approve(address(vault), 1);
vault.register(1);
vm.stopPrank();
vm.warp(block.timestamp + 2 days);
vault.distributeFunds();
vm.prank(alice);
vault.withdrawRemaining();
assertEq(fundingToken.balanceOf(alice), ALICE_DEPOSIT);
}
}
Environment Details
- commit
4f8d676onmain - forge 1.5.1 with solc 0.8.33 and evm Paris
- macOS
Impact
high. one proposal and zero registrations lock every deposit in the vault forever and anyone can submit that proposal
no live vault is affected right now since FairFund on Polygon mainnet has 0 vaults
related to #90 (same symptom but a different cause). PR #91 does not touch this
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
-
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 ·
-
[BUG]: One blocked recipient makes distributeFunds revert and locks all vault fundsPossibly taken @Deepak-negi11 claimed this 9 days ago. Openbug
Difficulty 4/5 3-5 days Newbie friendliness 18/100
StabilityNexus/FairFund#90 ·
-
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