Skip to content

fix: enforce voting snapshots to prevent flash-loan attacks - #746

Open
emarkees wants to merge 1 commit into
ThinkLikeAFounder:mainfrom
emarkees:feat/fix-dao-voting-snapshots
Open

fix: enforce voting snapshots to prevent flash-loan attacks#746
emarkees wants to merge 1 commit into
ThinkLikeAFounder:mainfrom
emarkees:feat/fix-dao-voting-snapshots

Conversation

@emarkees

@emarkees emarkees commented Jul 29, 2026

Copy link
Copy Markdown

Closes #730

Title

Fix: Enforce strict voting snapshots to prevent flash-loan voting attacks

Description

Summary
This PR addresses a critical vulnerability detailed in #709 where users could artificially magnify their voting power by temporarily borrowing governance tokens (flash loans) within the exact transaction they cast a vote. It implements and strictly enforces the VotingSnapshot mechanism to determine voter eligibility based on balances held at the time of proposal creation, rather than instantaneous balances.

What was done

  • DAO Snapshot Integration: Refactored cast_vote in governance-dao to remove the live balance query. It now cross-calls get_voting_snapshot on the token contract using the proposal's start_ledger. Votes submitted without a valid snapshot for that ledger are explicitly rejected.
  • Token Snapshot Security: Hardened the take_snapshot function in governance-token to require ledger_sequence == env.ledger().sequence(). This strictly prohibits retroactive snapshot generation, effectively destroying the attack vector where an attacker flash-loans tokens and immediately attempts to backdate a snapshot.
  • Testing Enhancements:
    • Updated MockGovToken in the test suite to support get_voting_snapshot for backward compatibility in standard tests.
    • Added a new integration test (test_flash_loan_vote_rejected) that accurately simulates a flash-loan scenario and asserts that the governance contract correctly panics and rejects the malicious vote.
    • Added take_snapshot strict-ledger validations in governance-token tests.

@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@emarkees Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] governance-token: governance-dao casts votes using live token balance — no flash-loan protection without voting snapshots

1 participant