Zealynx AcademyZealynx Academy
ZLX-Check

Spot the Bug: voting power you can rent

Question 1 of 3Score 0/3

A DAO computes your voting power by calling token.balanceOf(msg.sender) at the moment you vote. What is still wrong?

Review and apply

Worked answers

Try the quiz above first, then open an answer to compare your reasoning. These notes are also available to read without completing an attempt.

  1. 1. A DAO computes your voting power by calling token.balanceOf(msg.sender) at the moment you vote. What is still wrong?

    • A.Nothing, balanceOf is the real token holding
    • B.It reads a live balance, which a flash loan can inflate for one block
    • C.external view wastes gas on a state read
    • D.It should return uint256 instead of uint
    Answer and explanation

    B. It reads a live balance, which a flash loan can inflate for one block

    The live balance is a value an attacker can move. Flash-loan a huge amount into the account, call vote in the same transaction, and return the loan before the block ends. balanceOf is honest about the current holding, but the current holding is not conviction.

  2. 2. How does a flash loan actually turn one transaction into a majority vote?

    • A.It steals other holders' private keys to vote for them
    • B.It borrows a whale-sized balance, votes while holding it, and repays the loan atomically before the transaction ends
    • C.It mints new governance tokens out of nothing
    • D.It reorders the block so the vote lands first
    Answer and explanation

    B. It borrows a whale-sized balance, votes while holding it, and repays the loan atomically before the transaction ends

    A flash loan is borrow, use, and repay inside a single transaction. For the instant the contract reads balanceOf, the attacker holds the whale balance. The vote is cast against that balance, then the loan is returned. A whale for one block is still a whale, and the vote is already recorded.

  3. 3. Which fix actually removes the flash-loan vote, not just makes it harder?

    • A.Add a require that msg.sender is not a contract
    • B.Snapshot voting power at proposal creation and read a checkpointed past block, then add a timelock on execution
    • C.Charge a small fee to vote
    • D.Cap the number of votes per address per day
    Answer and explanation

    B. Snapshot voting power at proposal creation and read a checkpointed past block, then add a timelock on execution

    Read voting power from a fixed past block that no flash loan can influence, for example getPastVotes at proposal creation, and compare quorum against the same snapshot. A timelock on execution gives honest holders time to react. The tx-origin check is bypassable and does nothing about a snapshot read at vote time.

Read alongside: See it in real audits