ERC721Votes’s delegation disables NFT transfers and burning
A user who delegates their votes to themselves and then to another address causes their NFT transfers and burns to revert. This freezes the tokens because the transfer callback tries to subtract votes from the original owner, whose checkpoint balance is zero.
Submitted by hyh
If Alice the NFT owner first delegates her votes to herself, second delegates to anyone else with delegate() or delegateBySig() then all her NFT ids will become stuck: their transfers and burning will be disabled.
The issue is _afterTokenTransfer() callback running the _moveDelegateVotes() with an owner instead of her delegate. As Alice’s votes in the checkpoint is zero after she delegated them, the subtraction _moveDelegateVotes() tries to perform during the move of the votes will be reverted.
As ERC721Votes is parent to Token and delegate is a kind of common and frequent operation, the impact is governance token moves being frozen in a variety of use cases, which interferes with governance voting process and can be critical for the project.
Proof of Concept
Suppose Alice delegated all her votes to herself and then decided to delegate them to someone else with either delegate() or delegateBySig() calling _delegate():
function _delegate(address _from, address _to) internal {
// Get the previous delegate
address prevDelegate = delegation[_from];
// Store the new delegate
delegation[_from] = _to;
emit DelegateChanged(_from, prevDelegate, _to);
// Transfer voting weight from the previous delegate to the new delegate
_moveDelegateVotes(prevDelegate, _to, balanceOf(_from));
}
_moveDelegateVotes() will set her votes to 0 as _from == Alice and prevTotalVotes = _amount = balanceOf(Alice) (as _afterTokenTransfer() incremented Alice’s vote balance on each mint to her):
function _moveDelegateVotes(
address _from,
address _to,
uint256 _amount
) internal {
unchecked {
// If voting weight is being transferred:
if (_from != _to && _amount > 0) {
// If this isn't a token mint:
if (_from != address(0)) {
// Get the sender's number of checkpoints
uint256 nCheckpoints = numCheckpoints[_from]++;
// Used to store the sender's previous voting weight
uint256 prevTotalVotes;
// If this isn't the sender's first checkpoint: Get their previous voting weight
if (nCheckpoints != 0) prevTotalVotes = checkpoints[_from][nCheckpoints - 1].votes;
// Update their voting weight
_writeCheckpoint(_from, nCheckpoints, prevTotalVotes, prevTotalVotes - _amount);
}
After that her votes in the checkpoint become zero. She will not be able to transfer the NFT as _afterTokenTransfer will revert on _moveDelegateVotes’s attempt to move 1 vote from Alice to _to, while checkpoints[Alice][nCheckpoints - 1].votes is 0:
function _afterTokenTransfer(
address _from,
address _to,
uint256 _tokenId
) internal override {
// Transfer 1 vote from the sender to the recipient
_moveDelegateVotes(_from, _to, 1);
Recommended Mitigation Steps
The root issue is _afterTokenTransfer() dealing with Alice instead of Alice’s delegate.
Consider including delegates() call as a fix:
function _afterTokenTransfer(
address _from,
address _to,
uint256 _tokenId
) internal override {
// Transfer 1 vote from the sender to the recipient
- _moveDelegateVotes(_from, _to, 1);
+ _moveDelegateVotes(delegates(_from), delegates(_to), 1);
As delegates(address(0)) == address(0) the burning/minting flow will persist:
/// @notice The delegate for an account
/// @param _account The account address
function delegates(address _account) external view returns (address) {
address current = delegation[_account];
return current == address(0) ? _account : current;
}
tbtstl (Nouns Builder) confirmed
Alex the Entreprenerd (judge) commented:
The Warden has shown how, due to the overlapping system handling delegation and balances, it is possible for a user to brick their own
transferabilityof their tokens.This POC shows that any delegation will cause the issues as when dealing with a transfer, their currently zero-vote-balance will further be deducted instead of the delegated votes they have.
Because the finding shows a broken invariant, in that any delegation will brick transfers, as the invariants offered by ERC721Votes have been broken; I believe High Severity to be appropriate.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the _afterTokenTransfer callback calls _moveDelegateVotes with the token owner instead of the owner's delegate, so it subtracts from a zero checkpoint balance.
Impact
Governance token transfers and burns are frozen for any user who has delegated, which interferes with governance voting and could be critical for the project.
What the attacker needed
User owns an NFT; User delegates votes to self; User delegates votes to another address
The fix
The _afterTokenTransfer function should use the delegates() of the sender and recipient instead of the raw addresses.
How it was found
- Alice delegates her votes to herself.
- Alice delegates her votes to someone else using delegate() or delegateBySig().
- Alice's vote checkpoint becomes zero.
- Alice tries to transfer or burn her NFT, but the transfer reverts.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
This is a smart contract bug in a voting-enabled NFT. When you delegate your votes, the contract moves your voting weight to someone else. Later, when you try to transfer the NFT, the contract mistakenly tries to take votes from you instead of your delegate, but you have zero votes, so the transfer fails and the NFT is stuck.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.