The one-line mental model
A DAO is a treasury and a set of contracts in which token holders propose changes, vote under a stated rule, and wait out a timelock before anything executes â which makes governance an auditable state machine rather than a meeting.
Prerequisites
- !ERC-20 tokens and how balance snapshots work
- !Why a timelock exists between approval and execution
What You'll Learn
- 1Walk a proposal through voting delay, voting period, quorum, and timelock
- 2Wire an OpenZeppelin Governor to a votes-enabled token
- 3Compute quadratic voting power and explain its resistance to whale dominance
- 4Recognize flash-loan governance and low-turnout capture as distinct attack classes
What a DAO is, and what it is not
The formal definition is narrow: a DAO is a contract-controlled entity whose rules cannot be changed except by the rules themselves. In practice the label covers everything from a two-person multisig guarding a shared wallet to a protocol where thousands of token holders argue about fee switches. Both share one property that a company does not â the ability of any observer to verify what was proposed, how each address voted, and whether the executed calldata matched the approved description.
What a DAO is not is automatically efficient or automatically fair. Token-weighted voting concentrates power proportional to capital, which is a design decision rather than a law of nature, and it is the first thing most governance papers try to improve. The interesting engineering question is therefore never whether to have governance, but which rule converts holdings into influence, and which time delays stand between a passing vote and a drained treasury.
The proposal lifecycle, end to end
Every serious governance system runs the same four phases in the same order, and each phase exists to close a specific attack:
| Phase | Duration (example) | What happens | Attack it closes |
|---|---|---|---|
| Voting delay | 1 day | Snapshot the token balances before discussion peaks | Buying votes after reading the proposal text |
| Active voting | 5 days | For and against votes recorded, no execution | Surprise execution before holders notice |
| Timelock queue | 2 days | Passed proposal waits, publicly visible | Instant rug by a majority coalition |
| Execution | Anytime after delay | Calldata runs against target contracts | â ; paired with the delay it makes exits possible |
The voting delay matters more than it appears. Because voting power is measured at a block chosen at proposal creation, an attacker who acquires tokens after the proposal is posted gains no influence over it. The timelock matters just as much for the opposite reason: it gives dissenters time to exit, to rally a counter-proposal, or to coordinate a veto before value actually moves.
Wiring a Governor in OpenZeppelin
The reference implementation packages those phases into composable modules. The token must expose a vote snapshot, and the Governor consumes it:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "@openzeppelin/contracts/governance/Governor.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorSettings.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorCountingSimple.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorVotes.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorVotesQuorumFraction.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorTimelockControl.sol";
import "@openzeppelin/contracts/governance/TimelockController.sol";
contract CommunityGovernor is
Governor,
GovernorSettings,
GovernorCountingSimple,
GovernorVotes,
GovernorVotesQuorumFraction,
GovernorTimelockControl
{
constructor(IVotes token, TimelockController timelock)
Governor("CommunityGovernor")
GovernorSettings(1, 50400, 0)
GovernorVotes(token)
GovernorVotesQuorumFraction(4)
GovernorTimelockControl(timelock)
{}
function quorum(uint256 blockNumber)
public
view
override(Governor, GovernorVotesQuorumFraction)
returns (uint256)
{
return super.quorum(blockNumber);
}
function state(uint256 proposalId)
public
view
override(Governor, GovernorTimelockControl)
returns (ProposalState)
{
return super.state(proposalId);
}
function _execute(
uint256 proposalId,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal override(Governor, GovernorTimelockControl) {
super._execute(proposalId, targets, values, calldatas, descriptionHash);
}
}
The constructor arguments encode policy as data: a one-block voting delay, a seven-day voting period measured in blocks, no proposal threshold in the settings (set it once your token distribution is stable), and a quorum of four percent of supply. The timelock contract itself holds administrative rights over the protocols the DAO controls, which means the Governor can only act through it, and the delay applies to every action including emergency patches.
Choosing a voting rule
One-token-one-vote is simple and sybil-proof, and it hands the outcome to whichever address holds the most. Quadratic voting instead charges the square of the number of votes a holder wants to cast, so four votes cost sixteen units of power:
def linear_power(tokens, votes_wanted):
return min(tokens, votes_wanted)
def quadratic_cost(tokens, votes_wanted):
"""Cost in tokens to cast n votes under a QV scheme with identity-per-voter."""
cost = votes_wanted ** 2
return cost if cost <= tokens else int(tokens ** 0.5)
def quadratic_max_votes(tokens):
return int(tokens ** 0.5)
holdings = 10_000
print(linear_power(holdings, 10_000)) # 10,000 votes: whale decides alone
print(quadratic_max_votes(holdings)) # 100 votes: far more voices can compete
| Rule | Sybil resistance | Whale influence | Implementation cost | Best fit |
|---|---|---|---|---|
| Token-weighted | Strong | Total | Trivial | Early stage, low stakes |
| Quadratic | Weak without identity | Dampened | Moderate; needs identity layer | Community decisions |
| Conviction voting | Strong | Gradual | Higher; continuous tallying | Funding public goods |
| Delegation | Strong | Indirect | Moderate; needs delegation registry | Technical protocols with passive holders |
| Multi-sig | Strong (named parties) | Total by design | Trivial | Foundations and emergency response |
Quadratic voting is only as sybil-resistant as its identity layer, which is why most implementations gate it with a proof-of-personhood service or a soulbound credential. Without that, splitting holdings across many wallets is the cheapest way to game the square-root math.
Delegation: making participation affordable
Most token holders will never read a governance forum thread, and a design that assumes otherwise ends up with quorums that only a handful of whales clear. Delegation is the pragmatic answer: a holder transfers voting power to an active participant without giving up the underlying tokens, which means the delegate votes with weight while the holder keeps custody and can re-delegate at any time.
Delegation has three properties worth naming explicitly. It is non-custodial â the delegate cannot transfer or sell the delegated tokens. It is revocable in one transaction, which keeps delegates accountable even without a formal election. And it is usually transitive only one level deep, so a delegate cannot silently re-delegate onward and concentrate power further without being noticed in the registry.
The failure mode is apathy compounding. If most holders delegate to the same three addresses because those addresses run good newsletters, governance has effectively become a representative system with worse accountability than a corporate board, and it inherits the same risks: conflicts of interest, regulatory exposure of the delegates, and quiet concentration. The counterweight is a delegation market in which protocol teams, service providers, and community groups all compete for power, plus transparency tooling that shows who delegated to whom and how each delegate voted on every proposal.
A useful operational check for any DAO you participate in: look at the distribution of delegated power before the voting period begins. If the top three delegates could pass a proposal alone, your quorum and threshold settings are decorative, and the real governance conversation is about who those three are.
How DAOs actually get captured
The history of governance failures is short and repetitive, and each pattern has a signature you can check for in a proposal review:
| Attack | Mechanism | Defense |
|---|---|---|
| Flash-loan governance | Borrow tokens, vote, repay within one transaction | Snapshot voting power at proposal creation, or earlier |
| Low-turnout takeover | Proposal passes with tiny participation far below real support | Quorum plus a high enough threshold that apathy is expensive |
| Vote buying | Off-chain payment for on-chain votes | Timelock gives time to detect and respond; conviction voting blurs it |
| Malicious proposal | Passed proposal whose calldata drains the treasury | Multisig veto, scope limits on what the Governor may call |
| Proposal spam | Costless proposals bury meaningful ones | Deposit requirements and per-address thresholds |
The flash-loan pattern is the one that surprises newcomers most, because it needs no stolen keys and leaves no obvious forensic trail. The fix is baked into the lifecycle: measure voting power at a block before the voting period begins, so borrowed tokens that are repaid an hour later never existed as far as the tally is concerned.
đĄThe timelock is your incident response plan
When a hostile proposal passes onchain, the only lever left is usually exit pressure plus social coordination during the timelock. Keep the delay long enough for that to work: two days is minimal, a week is comfortable, and an emergency multisig with a scope limit is the pragmatic compromise most large DAOs settled on.
Common Mistakes
Measuring voting power at execution time instead of at proposal snapshot
Fix: Rely on the Governor's snapshot block so borrowed or acquired tokens after the proposal cannot flip the result
Setting quorum low enough that a handful of wallets pass anything
Fix: Calibrate quorum against realistic participation, and raise it as circulating supply broadens
Giving the Governor an unlimited admin right over every protocol contract
Fix: Scope permissions per protocol, keep emergency powers in a separate multisig, and document exactly which functions are governable
Publishing a proposal with a vague description and precise calldata
Fix: Require the description to match the calldata, and simulate the execution against a fork before the vote opens
Best Practices
- Simulate every proposal on a mainnet fork and post the simulation results with the vote
- Delegate voting power to active, accountable stewards instead of letting it sit idle in wallets
- Run a separate, smaller security council with a veto that can only delay, not rewrite, a proposal
- Keep treasury diversification decisions on a slower cadence than operational ones, because both use the same voting machinery
Interview Questions
Q1: Why snapshot voting power at proposal creation rather than counting live balances?
A live balance count lets an attacker borrow a large stake, vote, and repay within one transaction. Snapshotting at a fixed block means the attacker must hold the tokens before the proposal text is even known, which converts the attack into a capital-intensive bet.
Q2: What does a timelock protect against if the vote already passed?
It protects against surprise and against irreversibility. Holders who disagree can exit, exchanges can freeze deposits, and the community can coordinate a veto or a counter-proposal while the calldata sits unexecuted.
Q3: Is quadratic voting sybil-proof?
No. It assumes roughly one identity per voter. Without an identity layer, an attacker splits holdings across many wallets and pays the square-root price per wallet, which is cheaper than voting the same number of tokens from one address.
Key Takeaways
- Governance is a state machine: delay, vote, queue, execute, with each phase closing a specific attack
- OpenZeppelin's Governor packages that lifecycle, but quorum, thresholds, and delay are policy you must set deliberately
- Voting rules trade simplicity against fairness; quadratic and conviction schemes need identity or continuity assumptions to hold
- Flash-loan governance, low-turnout capture, and malicious calldata are the three failure modes to check in every design
- The timelock is not ceremony â it is the only window in which an on-chain incident response can still work