# Quadratic voting tally done wrong

Ajna grant funding tally subtracts raw vote amounts instead of their squares, letting a minority of token holders capture grant distribution.

- Payout: Contest reward
- Severity: medium
- Program: Ajna
- Credited: cducrest-brainbot
- Disclosed: 2022-12-21
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2023-01-ajna-judging/issues/64
- Library page: https://bugbountylibrary.com/r/sherlock%3A2023-01-ajna%3AM-19
- Tags: domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:governance

**Target:** StandardFunding.sol _fundingVote / GrantFund voting budget
**Root cause:** Voter budget is decremented by the raw budgetAllocation_ rather than its square, so the sum-of-squares constraint from the spec is not enforced.
**Steps:**
1. Deploy GrantFund with Ajna token; distribute 2 tokens to holder1 and 1 token each to holders2-4.
2. Self-delegate all voters; start distribution period and create two proposals.
3. Screening: holder1 votes 1 on proposal1, holder2 votes 1 on proposal2.
4. Advance to funding stage; holder1 has voting power 4 (2^2), others 1 each.
5. Funding vote: holder1 casts 4 votes on proposal1; holders2-4 cast 1 each on proposal2.
6. Proposal1 wins with 4 votes vs 3, despite holder1 holding only 2 of 5 tokens.
**How found:** Compared the technical spec's sum-of-squares constraint against the code, noticing budgetRemaining is decremented by budgetAllocation_ directly rather than its square.
**Exploitation:** Attacker with a token minority deploys a contract that proposes funding to itself and bribes delegators; because budget is linear, 10 holders of 1 token yield 100 votes vs 90 for the remaining 90 holders, capturing the round.
**Insight:** When a spec defines a quadratic/sum-of-squares constraint, verify the code squares each vote before accumulating; linear subtraction silently converts quadratic voting into linear voting and lowers the bribe threshold from 50% to ~sqrt(n) holders.
