# What is a governance attack?

URL: https://shield.quillaudits.com/learn/vulnerabilities/governance-attack/

A governance attack is when someone gets enough voting power, for one block or for good, to pass a proposal that drains the treasury, upgrades the contracts or hands them control. The usual way in is a governor that counts votes from balances at the moment of voting and executes as soon as a proposal passes, so a flash loan can buy the vote. Count votes at a snapshot block after the proposal is public, put a delay between the vote and execution, and keep a way to cancel.

Last updated 3 December 2026. 6 minute read. By the QuillAudits Team.

## How does a governance attack work?

On-chain governance turns token balances into authority over the protocol. Whoever controls most of the votes counted on a proposal controls what the governor executes, and that is often everything: the treasury, upgrades and every admin role. The attacks differ in how the votes are obtained:

- Borrowed votes. If voting power is read from the current balance, a flash loan of the governance token, or of anything that can be swapped or deposited for it, buys a majority for one transaction.
- Counted twice. Without a snapshot, the same tokens vote from one address, move to another and vote again.
- Cheap quorum. When turnout is low, an attacker only needs more votes than the few holders paying attention, and those can be bought on the open market.
- A proposal that isn't what it says. The description reads one way and the calldata does another, or the code it calls changes between the vote and execution, for example through a proxy upgrade.
- Shortcuts. Emergency paths that execute without the normal delay, or a guardian that the same vote it should stop can replace.

## What does vulnerable code look like?

This governor counts each voter's current balance and executes the moment a proposal has a majority.

**Vulnerable: votes read from current balances and executed in the same block (illustrative, not audited code)** `InstantGovernor.sol`

```
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

interface IToken {
    function balanceOf(address account) external view returns (uint256);
    function totalSupply() external view returns (uint256);
}

contract InstantGovernor {
    struct Proposal {
        address target;
        bytes data;
        uint256 forVotes;
        bool executed;
    }

    IToken public immutable token;
    Proposal[] public proposals;
    mapping(uint256 => mapping(address => bool)) public voted;

    constructor(IToken token_) {
        token = token_;
    }

    function propose(address target, bytes calldata data) external returns (uint256) {
        proposals.push(Proposal(target, data, 0, false));
        return proposals.length - 1;
    }

    function vote(uint256 id) external {
        require(!voted[id][msg.sender], "already voted");
        voted[id][msg.sender] = true;
        // Voting power is whatever the caller holds right now, borrowed or not.
        // The same tokens can also vote again from a second address.
        proposals[id].forVotes += token.balanceOf(msg.sender);
    }

    function execute(uint256 id) external {
        Proposal storage p = proposals[id];
        require(!p.executed, "already executed");
        // Passes the moment it has a majority, even in the block it was proposed.
        require(p.forVotes * 2 > token.totalSupply(), "no majority");
        p.executed = true;
        (bool ok, ) = p.target.call(p.data);
        require(ok, "call failed");
    }
}
```

An attacker who can borrow more than half the supply for one transaction proposes a call that sends the treasury to themselves, votes with the borrowed balance, executes and repays the loan, all in one transaction. In a Foundry test this governor proposed, passed and executed a call in a single block. Even without a loan, `voted` is keyed by address, so the same tokens can vote again after a transfer.

## How do you fix it?

**Fixed: votes at a snapshot block, a voting delay, a quorum, an execution delay and a guardian who can cancel (illustrative, not audited code)** `TimelockedGovernor.sol`

```
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

interface IVotes {
    function getPastVotes(address account, uint256 blockNumber) external view returns (uint256);
    function getPastTotalSupply(uint256 blockNumber) external view returns (uint256);
}

contract TimelockedGovernor {
    struct Proposal {
        address target;
        bytes data;
        uint256 snapshot; // the block whose balances count, after the proposal is public
        uint256 voteEnd;
        uint256 eta; // earliest execution time, set when the proposal is queued
        uint256 forVotes;
        uint256 againstVotes;
        bool executed;
        bool canceled;
    }

    IVotes public immutable token;
    address public immutable guardian;
    uint256 public constant VOTING_DELAY = 7200; // blocks between proposing and the snapshot
    uint256 public constant VOTING_PERIOD = 50400; // blocks the vote stays open
    uint256 public constant QUORUM_BPS = 400; // 4% of the supply at the snapshot must vote for
    uint256 public constant EXECUTION_DELAY = 2 days;

    Proposal[] internal proposals;
    mapping(uint256 => mapping(address => bool)) public hasVoted;

    constructor(IVotes token_, address guardian_) {
        token = token_;
        guardian = guardian_;
    }

    function propose(address target, bytes calldata data) external returns (uint256) {
        uint256 snapshot = block.number + VOTING_DELAY;
        proposals.push(Proposal(target, data, snapshot, snapshot + VOTING_PERIOD, 0, 0, 0, false, false));
        return proposals.length - 1;
    }

    function castVote(uint256 id, bool support) external {
        Proposal storage p = proposals[id];
        require(block.number > p.snapshot && block.number <= p.voteEnd, "voting closed");
        require(!hasVoted[id][msg.sender], "already voted");
        // Counted at a block that is already in the past, so tokens borrowed or
        // moved after it add nothing.
        uint256 weight = token.getPastVotes(msg.sender, p.snapshot);
        require(weight > 0, "no votes");
        hasVoted[id][msg.sender] = true;
        if (support) p.forVotes += weight;
        else p.againstVotes += weight;
    }

    function queue(uint256 id) external {
        Proposal storage p = proposals[id];
        require(block.number > p.voteEnd && p.eta == 0 && !p.canceled, "cannot queue");
        uint256 quorum = token.getPastTotalSupply(p.snapshot) * QUORUM_BPS / 10_000;
        require(p.forVotes > p.againstVotes && p.forVotes >= quorum, "defeated");
        p.eta = block.timestamp + EXECUTION_DELAY;
    }

    function execute(uint256 id) external {
        Proposal storage p = proposals[id];
        require(p.eta != 0 && block.timestamp >= p.eta, "not ready");
        require(!p.executed && !p.canceled, "closed");
        p.executed = true;
        (bool ok, ) = p.target.call(p.data);
        require(ok, "call failed");
    }

    // The delay gives holders time to react, and the guardian can stop a hostile proposal.
    function cancel(uint256 id) external {
        require(msg.sender == guardian, "only guardian");
        Proposal storage p = proposals[id];
        require(!p.executed, "already executed");
        p.canceled = true;
    }
}
```

- Count votes at a snapshot. The fixed governor reads `getPastVotes` at a block that is already in the past when voting opens, from a token that keeps a checkpoint of each account's votes. Tokens bought, borrowed or moved after that block add nothing.
- Open the vote after a delay. `VOTING_DELAY` gives holders time to read the proposal and delegate before the snapshot block, and no flash loan lasts that long.
- Require a quorum from the snapshot supply. A proposal needs more votes for than against and a minimum share of the supply at the snapshot, so a quiet week isn't enough to pass it.
- Delay execution. A passed proposal waits `EXECUTION_DELAY` before it can run, so holders who disagree can exit and the guardian can cancel.
- Keep the guardian narrow. It can cancel, not execute, and replacing it should take the same delay as any other change.
- Use a tested timelock. OpenZeppelin's `TimelockController` gives scheduling, executing and cancelling to separate roles, and a change to its own minimum delay has to wait out that delay too ([OpenZeppelin](https://docs.openzeppelin.com/contracts/4.x/api/governance)).
- Watch markets in your own token. A snapshot defeats flash loans, but votes can still be borrowed for a few blocks from a lending market that lists the governance token, so size the quorum and delays with that in mind.

In the same Foundry test, the fixed governor refused votes before the snapshot block, refused to queue the proposal while voting was open, and refused to execute it until the delay had passed.

## How have governance attacks happened?

| Protocol | Beanstalk |
| --- | --- |
| Date | 17 April 2022 |
| Chain | Ethereum |
| Loss | about $181M taken from the protocol, of which the attacker kept about $76M |
| What happened | Beanstalk's voting power came from deposits, which funds borrowed in the same transaction could create, and its `emergencyCommit` function executed a proposal at once when enough of that power voted for it. The attacker submitted two proposals, waited out the roughly one-day delay on governance actions, then in one transaction flash-borrowed DAI, USDC, USDT, BEAN and LUSD from Aave, Uniswap and SushiSwap, added them as liquidity to Curve pools with BEAN for voting power, voted for its proposal BIP-18 and called `emergencyCommit`, which moved the protocol's funds to the attacker. [rekt.news](https://rekt.news/beanstalk-rekt) describes it as a governance attack made possible by flash loans combined with no delay on proposal execution. |
| Sources | [rekt.news](https://rekt.news/beanstalk-rekt), [rekt.news](https://rekt.news/leaderboard/) |

Both halves of the fixed governor answer this attack: votes counted at a block before the vote make a one-transaction loan worthless, and a delay after the vote gives holders and a guardian time to act.

## What should a reviewer check?

- Where does voting power come from: a current balance, a snapshot or delegated checkpoints, and at which block?
- Can tokens vote, move and vote again from another address on the same proposal?
- Is there a voting delay, a voting period and a quorum, and are they set for the token's real turnout?
- Does every passed proposal wait in a timelock before execution, emergency paths included?
- Who can cancel a proposal, and can a vote remove that power faster than the timelock?
- Can the code a proposal calls change between the vote and execution, through a proxy upgrade or a new deployment at the same address?
- Is anything that converts into voting power, such as a staked or wrapped version of the token, available from a lending market or a flash loan?
- Is each proposal's calldata simulated against a fork before the vote ends, and does it match the description?

## How does QuillShield check for governance attacks?

Governance bugs depend on intent: which roles exist, how long each delay should be and who may cancel. Before an audit you can add context such as the whitepaper, trust assumptions, privileged roles and previous audit reports, and for a DAO that context should name every delay and every role the governor can grant. Put the governor, the timelock, the voting token and the contracts they control in scope together.

QuillShield runs a full audit of a Solidity codebase in a Foundry project. It builds a security graph of the code and lists the invariants the code must keep. Write the main one for a governor down yourself as well: nothing executes without votes counted at a past block and a delay.

A separate reviewer agent tries to disprove every finding before you see it, and each finding that holds up comes with the exact lines, the impact, a recommended fix and, on full audits, a proof of concept. It then checks every pull request on GitHub or GitLab.com against that graph. Changes to delays, quorum and emergency paths tend to arrive as small pull requests, so those reviews matter as much as the first audit.

[Run a full audit](https://shield.quillaudits.com/register) before your first proposal goes live. New accounts get $50 in credit, good for up to half of an order. You can also [request a manual audit from QuillAudits](https://www.quillaudits.com/smart-contract-audit).

## FAQ

### Does a snapshot stop flash loan governance attacks?

It stops votes borrowed for a single transaction, because balances are read at a block that has already passed. Votes borrowed for longer, from a lending market, still count, so quorum and delays have to assume that.

### Why put a delay between the vote and execution?

So a passed proposal can't run at once. The delay gives holders time to exit and a guardian time to cancel a hostile proposal before it executes.

### Can a governance proposal cause a loss without an attacker?

Yes. Moonwell executed governance proposal MIP-X43 on 15 February 2026, and one oracle configuration it enabled priced cbETH at about $1.12 instead of about $2,200, which left about $1.78M of bad debt, as [Decrypt reported](https://decrypt.co/358374/oracle-error-leaves-defi-lender-moonwell-1-8-million-bad-debt). Simulate every proposal against a fork before it executes.

### Is a guardian a centralization risk?

It can be. Limit it to cancelling proposals, keep it in a multisig, and make replacing it go through the same delay as any other change.

## Sources

- [Beanstalk REKT, rekt.news](https://rekt.news/beanstalk-rekt) · checked 3 December 2026
- [Leaderboard, rekt.news](https://rekt.news/leaderboard/) · checked 3 December 2026
- [Governance, OpenZeppelin docs](https://docs.openzeppelin.com/contracts/4.x/api/governance) · checked 3 December 2026
- [Oracle error leaves DeFi lender Moonwell with $1.8 million in bad debt, Decrypt](https://decrypt.co/358374/oracle-error-leaves-defi-lender-moonwell-1-8-million-bad-debt) · checked 24 November 2026
- [DeFi lending protocol Moonwell hit with $1.8 million bad debt after oracle misconfiguration, The Block](https://www.theblock.co/post/390302/defi-lending-protocol-moonwell-hit-with-1-8-million-bad-debt-after-oracle-misconfiguration) · checked 24 November 2026
