StandardFunding.fundingVote should not allow users who didn’t vote in screening stage to vote
The fundingVote function allows users who did not vote in the screening stage to vote in the funding stage, but claimDelegateReward rejects those users. As a result, the rewards allocated to those votes are locked and cannot be claimed, causing the contract's token balance to diverge from its recorded treasury.
Originally disclosed on Code4rena
Submitted by nobody2018
https://github.com/code-423n4/2023-05-ajna/blob/main/ajna-grants/src/grants/base/StandardFunding.sol#L519-L569 https://github.com/code-423n4/2023-05-ajna/blob/main/ajna-grants/src/grants/base/StandardFunding.sol#L519
Users who did not vote in the screening stage but voted in the funding stage are not allowed to claim rewards via claimDelegateReward. Voting in the funding stage will occupy the distribution ratio of rewards. Since these rewards cannot be claimed, in the long run, the ajnaToken balance of the GrantFund contract is inconsistent with treasury.
Proof of Concept
At the beginning of the StandardFunding.claimDelegateReward function, check whether the caller voted in the screening stage.
function claimDelegateReward(
uint24 distributionId_
) external override returns(uint256 rewardClaimed_) {
// Revert if delegatee didn't vote in screening stage
-> if(screeningVotesCast[distributionId_][msg.sender] == 0) revert DelegateRewardInvalid();
QuarterlyDistribution memory currentDistribution = _distributions[distributionId_];
...
}
StandardFunding.fundingVote is used to vote in the funding stage. This function does not check whether the caller voted in the screening stage. fundingVote subcalls _fundingVote, which affects the allocation of rewards. _getDelegateReward is used by claimDelegateReward to calculate the reward distributed to the caller.
function _getDelegateReward(
QuarterlyDistribution memory currentDistribution_,
QuadraticVoter memory voter_
) internal pure returns (uint256 rewards_) {
// calculate the total voting power available to the voter that was allocated in the funding stage
uint256 votingPowerAllocatedByDelegatee = voter_.votingPower - voter_.remainingVotingPower;
// if none of the voter's voting power was allocated, they receive no rewards
if (votingPowerAllocatedByDelegatee == 0) return 0;
// calculate reward
// delegateeReward = 10 % of GBC distributed as per delegatee Voting power allocated
-> rewards_ = Maths.wdiv(
Maths.wmul(
currentDistribution_.fundsAvailable, //total funds in current distribution
votingPowerAllocatedByDelegatee //voter's vote power
),
currentDistribution_.fundingVotePowerCast //total vote power in current distribution
) / 10; // 10% fundsAvailable
}
As long as fundingVote is successfully called, it means that the reward is locked to the caller. However, the caller cannot claim these rewards. There is no code to calculate the amount of these rewards that can never be claimed.
Recommended Mitigation Steps
Two ways to fix this problem:
FundingVotedoes not allow users who didn’t vote in screening stage.- Delete the code on line L240.
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 fundingVote function lacks the same screening-stage participation check that claimDelegateReward enforces, so votes can be cast that can never lead to a claimable reward.
Impact
Rewards allocated to funding-stage voters who skipped screening are permanently unclaimable, so the contract's token balance and its treasury record drift apart over time.
What the attacker needed
Attacker holds voting power; attacker skips screening stage; attacker votes in funding stage
The fix
The report recommends either blocking fundingVote for users who did not vote in screening, or removing the screening-vote check in claimDelegateReward.
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 this grant system, people vote in two rounds: first a screening round, then a funding round. Only people who voted in the first round are supposed to get a share of the reward pool. The code lets anyone vote in the second round, but then refuses to pay them, so that share of the reward pool is stuck in the contract forever.
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.