Book a free call

DAO Smart Contract Security: What to Protect and How

A DAO's contracts hold its treasury and its votes, so one flaw can drain funds or hand control to an attacker. Here is what to protect, and how teams do it.

Hertiv engineering teamReviewed by a senior engineer
8 min read
DAO Smart Contract Security: What to Protect and How
On this page

Short answer

DAO smart contract security means protecting the contracts that run a DAO's voting, treasury and membership rules from flaws and attacks. Because the code itself holds the funds and enforces decisions, a single bug can drain the treasury or let an attacker pass a malicious proposal, so teams combine careful voting rules, timelocks, treasury limits, testing and audits before launch.

What is DAO smart contract security?

DAO smart contract security is the practice of protecting the contracts that run a decentralised autonomous organisation: its voting, its treasury and its membership rules. These contracts hold the organisation's funds and enforce its decisions, so a flaw in them is a flaw in the organisation itself.

It differs from ordinary application security because there is no help desk and no undo button. Once a proposal passes and the timelock expires, the contract executes it automatically, and a mistaken transfer cannot be reversed by calling support. The code is also public, so anyone can read it and look for weaknesses, including attackers.

Four parts need protection:

  • Voting contract. Records proposals and votes, and decides when a proposal has passed.
  • Treasury contract. Holds the funds and releases them only on a passed proposal.
  • Timelock. Delays execution after a vote, so members have time to react.
  • Token contract. Tracks who holds voting power and how much each holder has.

Security here covers both the code and the rules around it: who can propose, how many votes a proposal needs, how long members have to react, and who can pause the system in an emergency.

Why is a DAO a bigger target than a normal contract?

A DAO is a bigger target than a normal contract because its contracts combine money and power in one public place. The treasury, the voting rules and the power to change them all live in code that anyone can read, and a successful attack can take both the funds and control of the organisation at once.

Three features make DAOs attractive to attackers:

  • Money and authority together. The same contracts that hold the funds also decide how they are spent, so one flaw can do double damage.
  • Public code. Every rule and balance is visible on chain, so an attacker can study the system for weeks before striking.
  • Automatic execution. A proposal that passes is carried out by the contract itself, with no human in the loop to stop a harmful one.

A normal company can freeze an account or reverse a payment when something goes wrong. A DAO cannot, unless its contracts were built with a pause or a veto. That is why the design choices made before launch matter more than any response after an attack. If you are new to the structure, start with what a DAO is and how it works.

Which attacks target DAO contracts?

Five attacks account for most DAO contract losses: flash-loan voting, proposal hijack, reentrancy, broken access control and oracle manipulation. Each one targets a different part of the system, so each needs a different defence.

AttackHow it worksWhat it puts at risk
Flash-loan votingBorrow governance tokens, vote, repay in one transactionControl of proposals
Proposal hijackHide a harmful action inside a normal-looking proposalTreasury funds
ReentrancyCall a payout function again before the balance updatesTreasury funds
Broken access controlCall a function anyone can reach to change a key settingVoting rules, treasury
Oracle manipulationPush a price feed so a treasury valuation reads wrongLending and payouts

Flash-loan voting is the attack most specific to DAOs. An attacker borrows a large amount of governance tokens, uses them to vote a proposal through, then returns the loan in the same transaction, so the vote costs almost nothing. In April 2022 an attacker used this method against the Beanstalk protocol, borrowing about $1 billion in stablecoins to gain a supermajority of voting power and pass proposals that drained about $182 million from the protocol.

Reentrancy is older but still dangerous. In 2016, an attack on The DAO used a reentrancy flaw to drain funds by calling a withdrawal function repeatedly before the balance was updated. Modern contracts guard against this by updating balances before sending funds and by using reentrancy locks, which an audit should confirm. The general defences are covered in smart contract security basics.

How do timelocks and voting rules protect a DAO?

A timelock protects a DAO by delaying execution after a vote passes, so members have time to spot a harmful proposal and react before any funds move. Voting rules protect it by setting who can propose, how many votes a proposal needs, and how long voting stays open.

Four settings do most of the work:

  • Proposal threshold. A minimum amount of voting power needed to create a proposal, so spam and joke proposals cannot reach a vote.
  • Quorum. A minimum share of total voting power that must take part, so a tiny group cannot pass a proposal while everyone else is away.
  • Voting delay. A gap between a proposal appearing and voting opening, so members can read it before anyone votes.
  • Timelock delay. A wait of a day or two between a vote passing and execution, so a harmful proposal can be challenged or the system paused.

Delegation also matters. Members who do not vote can delegate their power to someone they trust, which raises turnout and makes it harder for a small group to reach quorum alone. Some DAOs also cap how much voting power one address can hold. The trade-offs between these models are covered in DAO governance models compared.

How do you protect the DAO treasury?

You protect a DAO treasury by making the timelock contract its only owner, so funds move only through proposals that passed a vote and waited out the delay. No single person or wallet should be able to move treasury funds on their own.

Four controls keep the treasury safe:

  • Spending caps. A limit on how much any single proposal can move, so one bad vote cannot empty the treasury.
  • Recipient allowlist. A list of addresses the treasury can pay, checked by the contract, so a proposal cannot quietly redirect funds to a new address.
  • Separate operating wallet. A small balance for day-to-day costs, refilled by proposal, while the bulk of the funds stays in the timelock.
  • Emergency pause. A narrow power, held by a small trusted group, to pause payouts or veto a proposal, with a strict time limit on the power itself.

The pause power is a trade-off: it reintroduces trust into a trustless system, so its scope must be small and its holders must be named in advance. Monitoring closes the loop. Alerts on large transfers, new proposals and timelock queues let members react while the delay is still running, and a public treasury dashboard means many eyes catch what one reviewer misses.

How do you secure a DAO contract before launch?

You secure a DAO contract before launch by building on audited libraries, testing the governance attacks as well as the happy path, rehearsing the full vote cycle, getting an external audit, and launching in stages with a small treasury first.

  1. Build on audited libraries. Use established voting and timelock contracts, such as OpenZeppelin Governor and TimelockController with ERC20Votes, instead of writing voting logic from scratch.
  2. Test the attacks, not just the features. Write unit and invariant tests for flash-loan votes, double execution, quorum edge cases and proposals that try to change the rules mid-vote.
  3. Rehearse the full cycle on a testnet. Propose, vote, queue and execute with real members, and check that the timelock delay and the pause work as designed.
  4. Get an external audit. Have independent reviewers check the contracts, fix every finding, and publish the report so members can read it. The process is explained in how to audit a smart contract.
  5. Launch in stages. Start with a small treasury and tight spending caps, and raise them only after months without incident.
  6. Offer a bug bounty. Pay researchers to report flaws instead of using them, and keep the bounty live after launch.

Each step catches a different class of problem. Libraries remove common coding errors, attack tests catch logic flaws, the rehearsal catches process gaps, the audit catches what the team missed, and staged launch limits the damage if something still slips through.

Example (hypothetical): a grants DAO catches a flaw

Example (hypothetical): a grants DAO holds 120,000 USDC in its treasury and has 1,000,000 governance tokens in circulation. Three grants of 10,000 USDC each are proposed, a total of 30,000 USDC, which would leave 90,000 USDC in the treasury after payment.

During the testnet rehearsal, a member notices that the payout function does not mark a proposal as executed before sending the funds. A second call to the same proposal would pay the same 30,000 USDC again, taking 60,000 USDC in total and leaving 60,000 USDC instead of 90,000 USDC.

The team fixes the flaw by marking the proposal as executed first, then sending the funds, and re-runs the rehearsal. This time the second call fails, the treasury pays exactly 30,000 USDC, and the balance reads 90,000 USDC. The fix costs a day of work; the same flaw on mainnet would have cost 30,000 USDC.

The rehearsal also catches a second problem: the quorum is set so low that two large holders could pass a proposal alone. The team raises the quorum before launch, so a proposal now needs a real share of the membership behind it.

What are the common mistakes?

The most common DAO security mistakes are skipping the timelock, setting the quorum too low, leaving admin keys with the deployer, and trusting the proposal text instead of reading the on-chain actions.

  • No timelock. A proposal that executes the moment it passes gives members no time to react to a harmful one.
  • Quorum too low. A handful of holders can pass anything, which is exactly the opening a flash-loan voter needs.
  • Admin keys left with the deployer. One compromised key can change the rules, so ownership must move to the timelock at launch.
  • Skipping the rehearsal. A vote cycle that has never run end to end will fail in the worst possible moment.
  • Reading the title, not the actions. A proposal's description can say one thing while its on-chain calls do another, so members must check the calls before voting.
  • No pause plan. A bug found after launch needs a response decided in advance, not invented during an attack.

Most of these mistakes are design choices, not coding errors, which is why they are cheap to fix before launch and expensive to fix after it. A short review of the voting rules and the treasury controls before deployment catches nearly all of them.

Key takeaways

  • A DAO's contracts hold both its funds and its power to decide, so one flaw can do double damage
  • Flash-loan voting lets an attacker borrow voting power, pass a proposal and repay the loan in one transaction
  • A timelock delays execution after a vote, giving members time to spot and stop a harmful proposal
  • The treasury should belong to the timelock contract, with spending caps and a recipient allowlist
  • Test the attacks as well as the features, rehearse the full vote cycle, audit, then launch in stages

Frequently asked questions

Can a DAO vote be bought with a flash loan?

Yes, if voting power is counted at vote time and execution follows immediately. An attacker borrows governance tokens, votes, and repays the loan in one transaction. A voting delay, a snapshot of voting power taken before the proposal, a quorum, and a timelock delay between the vote and execution each make this attack harder or useless.

What is a timelock in a DAO?

A timelock is a contract that holds approved proposals for a set delay, usually a day or two, before they can execute. It gives members time to read a passed proposal, check its on-chain actions, and pause the system or exit if the proposal is harmful. Without it, a bad proposal takes effect the moment voting ends.

Who should hold the DAO treasury?

The timelock contract should own the treasury, so funds move only through proposals that passed a vote and waited out the delay. No single wallet or person should be able to move treasury funds alone. A small separate operating wallet can hold day-to-day funds, refilled by proposal.

Do DAOs need a smart contract audit?

Yes. An independent audit checks the voting, treasury and timelock contracts for flaws the team missed, including governance attacks that unit tests rarely cover. Fix every finding and publish the report so members can read it. An audit does not guarantee safety, but skipping one leaves the treasury exposed.

What is the difference between DAO security and smart contract security?

Smart contract security covers code flaws such as reentrancy and access control in any contract. DAO security adds the governance layer: voting rules, quorum, timelocks, proposal checks and treasury controls. A DAO contract can be free of code bugs and still be attacked through its voting rules.

Can a DAO recover funds after an attack?

Usually not. Blockchain transfers are final, and a DAO has no bank to call. Recovery depends on the attacker returning funds, an exchange freezing an account, or a negotiated bounty. That is why prevention matters more for DAOs than for normal companies: timelocks, caps and audits must be in place before launch.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: blockchain systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Building a DAO and want its contracts reviewed? Talk to Hertiv.

A senior engineer replies within one business day. Or see our Smart Contract Audit service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to contact@hertiv.com.

Prefer email? Write to contact@hertiv.com
Estimate costBook a call