The 1-second overlap between the during- and after-allocation periods may cause funds to become stuck, permanently
A one-second overlap between the allocation and post-allocation periods in the QV and DonationVotingMerkle strategies allows a vote to be cast after funds have been distributed, causing some funds to become permanently stuck. An attacker could exploit this timing to manipulate vote totals and leave undistributed funds locked.
alexxander Follow with jkoppel and shirochan
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/261
Found by
alexxander, jkoppel, shirochan There is a 1-second overlap between the during- and after-allocation periods of both the QV strategy and the DonationVotingMerkle strategies. In the QV strategy, this can lead to funds permanently becoming stuck.
Vulnerability Detail
- A QVSimpleStrategy pool is created. Alice is the Pool manager. 10 people are given voting rights. The pool is funded for 100k USDC.
- Everyone except Bob votes, giving Carol and Dan each 50% of the votes.
- Carol tells Alice she really needs the money, and asks her to distribute ASAP. Alice schedules a distribute() transaction to occur the moment allocation ends.
- At the last minute, the Bob votes, casting all his votes for Carol.
- It so happens that Alice and Bob's transaction occur in the same block. Further, it so happens that this block is scheduled with block.timestamp exactly equal to
allocationEndTime. (Note that, other some comments talk about the registration and allocation period times being in milliseconds, they are actually in seconds.) - For this second, both
onlyActiveAllocationandonlyAfterAllocationpass - Bob's vote gets scheduled within the block after the call to distribute()
- The call to distribute gives 50% of the funds to Carol, or 50k USDC. Bob's vote changes the total so that 55% of votes are for Carol, and 45% for Dan.
- Dan can now be given his $45k. But the remaining $5k is stuck in the pool forever.
If there is one block every 40 seconds, then there is a 2.5% chance that a block will run on the exact second of overlap. However, the contest page says it should run on any EVM-compatible chain. If there is a rollup that has blocks every second, then the conditions for this bug to occur has a 100% chance
If there is collusion from the miner, then there is also a significantly higher chance.
Impact
A chance of permanent loss of funds
Code Snippet
When block.timestamp == allocationEndTime, then both _checkOnlyAfterRegistration and _checkOnlyActiveAllocation pass.
I am guessing that the protocol authors thought block.timestamp was in milliseconds, when it is actually in seconds. That makes this problem 1000x more likely to occur without miner collusion.
function _checkOnlyActiveAllocation() internal view virtual {
if (allocationStartTime > block.timestamp || block.timestamp > allocationEndTime) {
revert ALLOCATION_NOT_ACTIVE();
}
}
/// @notice Check if the allocation has ended
/// @dev Reverts if the allocation has not ended
function _checkOnlyAfterAllocation() internal view virtual {
if (block.timestamp < allocationEndTime) revert ALLOCATION_NOT_ENDED();
}
Tool used
Manual Review
Recommendation
- Don't have this 1-second overlap
- Add a withdraw function to QVBaseStrategy
Discussion
jack-the-pug
@neeksec https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/656 is a dup of this.
jack-the-pug
Fixed: https://github.com/allo-protocol/allo-v2/pull/337
neeksec
@Evert0x
I agree with @jack-the-pug 's https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/261#issuecomment-1778751023. #656 should be a dup of this one.
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
Likely the allocation period end time is inclusive in both the active allocation check and the after allocation check, creating a one-second overlap where both conditions are true.
Impact
A chance of permanent loss of funds, with the likelihood depending on block time and miner collusion.
What the attacker needed
A QV or DonationVotingMerkle pool; ability to vote near allocation end; transaction timed to allocationEndTime; miner collusion or fast blocks increases chance
The fix
The overlap should be removed by ensuring the allocation end time is exclusive in one of the checks, and a withdraw function should be added to recover stuck funds.
How it was found
- A QVSimpleStrategy pool is created with Alice as manager, 10 voters, and 100k USDC funded.
- Everyone except Bob votes, giving Carol and Dan each 50% of the votes.
- Alice schedules a distribute() transaction to occur exactly when allocation ends.
- At the last moment, Bob votes for Carol, and his transaction is included in the same block as the distribute() call, with block.timestamp equal to allocationEndTime.
- The distribute() call executes first, giving Carol 50k USDC based on the old vote totals.
- Bob's vote then changes the totals to 55% for Carol and 45% for Dan, leaving 5k USDC that cannot be distributed.
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 some blockchain-based funding pools, there is a tiny window of time (one second) where two different rules both apply: one that says 'voting is still open' and another that says 'voting has ended'. If someone manages to vote in that exact second after the money has already been paid out, the totals no longer match and some money can get stuck forever. This is like a shop that accepts returns both before and after closing time, causing the cash register to be off.
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.