Submitted by berndartmueller, also found by 0x52, 0xSky, bin2chen, cccz, Chom, davidbrai, elprofesor, izhuer, m9800, PwnPatrol, and rvierdiiev
Voting power for each NFT owner is persisted within timestamp-dependent checkpoints. Every voting power increase or decrease is recorded. However, the implementation of ERC721Votes creates separate checkpoints with the same timestamp for each interaction, even when the interactions happen in the same block/timestamp.
Checkpoints with the same timestamp will cause issues within the ERC721Votes.getPastVotes(..) function and will return incorrect votes for a given _timestamp.
lib/token/ERC721Votes.sol#L252-L253
Consider the following example and the votes checkpoint snapshots:
Note: Bob owns a smart contract used to interact with the protocol
Transaction 0: Bobs smart contract receives 1 NFT through minting (1 NFT equals 1 vote)
Transaction 1: Bobs smart contract receives one more NFT through minting
Transaction 1: Within the same transaction 1, Bobs smart-contract delegates 2 votes to Alice
Transaction 1: Again within the same transaction 1, Bobs smart contract decides to reverse the delegation and self-delegates
Transaction 1: Bobs smart contract buys one more NFT
Bob now wants to vote (via his smart contract) on a governance proposal that has been created on timeCreated = 1 (timestamp 1).
Internally, the Governor._castVote function determines the voters weight by calling getVotes(_voter, proposal.timeCreated).
governance/governor/Governor.sol#L275
getVotes calls ERC721.getPastVotes internally:
governance/governor/Governor.sol#L462
ERC721.getPastVotes(..., 1) tries to find the checkpoint within the while loop:
The middle checkpoint with index 2 matches the given timestamp 1 and returns 0 votes. This is incorrect, as Bob has 2 votes. Bob is not able to vote properly.
(Please be aware that this is just one of many examples of how this issue can lead to incorrect vote accounting. In other cases, NFT owners could have more voting power than they are entitled to)
Consider batching multiple checkpoints writes per block/timestamp similar to how NounsDAO records checkpoints.
Alex the Entreprenerd (judge) commented:
kulkarohan (Nouns Builder) confirmed
