Skip to content
Business logic Audit finding Intermediate

Users can call reset on their token even if the

The Voter contract's reset function updates the lastVoted timestamp for a token even when that token has no active votes. An attacker can call reset just before transferring a token, causing the buyer to be unable to vote with that token in the current epoch.

OxAlix2 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

31425 - [SC - Medium] Users can call reset on their token even if the...

Submitted on May 18th 2024 at 23:01:57 UTC by @OxAlix2 for Boost | Alchemix

Report ID: #31425

Report type: Smart Contract

Report severity: Medium

Target: https://github.com/alchemix-finance/alchemix-v2-dao/blob/main/src/Voter.sol

Impacts:

  • Contract fails to deliver promised returns, but doesn't lose value
  • Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol)

Description

Brief/Intro

Users can vote on certain gauges in the Voter contract, allowing them to "withdraw" their votes using the reset function, a note on this function, is that it sets lastVoted for that token ID. However, that function doesn't check if the token has active votes before allowing the user to reset them. This introduces an issue, especially when users move/transfer/sell their tokens, more below...

Vulnerability Details

A bit of context, in VotingEscrow::_transferFrom, there's a check to block the transferring of tokens in case that token has active votes.

require(!voted[_tokenId], "voting in progress for token");

This is not there to block users from voting multiple times using the same token, as the vote is saved per token and not per owner. So, this is there to allow a token receiver to immediately have the ability to use that token and vote on gauges.

So a user can use the missing check anomaly to grief NFT buyers (remember tokens are NFTs and are tradable), so a user puts his token for sale, and just before the transferal that user front runs the transfer TX and calls Voter::reset, this blocks the buyer from voting on any gauge in the current epoch.

Impact Details

Users can grief token buyers/receivers and block them from voting in the current epoch.

References

https://github.com/alchemix-finance/alchemix-v2-dao/blob/main/src/Voter.sol#L183-L192

Mitigation

Add the following in Voter::reset:

require(poolVote[_tokenId].length > 0, "No active votes");

This could be added in if (msg.sender != admin) just in case the admin wanted a higher authority in case of an error.

Proof of concept

function testBlockVotingForBuyers() public {
    // Admin creates lock
    uint256 tokenId = createVeAlcx(admin, TOKEN_1, MAXTIME, false);

    // Admin calls reset on his own token
    vm.prank(admin);
    voter.reset(tokenId);

    // token's `lastVoted` is now, this is wrong as there's no active vote
    assertEq(voter.lastVoted(tokenId), block.timestamp);

    // Admin sends/sells the token to beef
    vm.prank(admin);
    veALCX.safeTransferFrom(admin, beef, tokenId);

    address[] memory pools = new address[](1);
    pools[0] = alUsdPoolAddress;
    uint256[] memory weights = new uint256[](1);
    weights[0] = 5000;

    // Beef votes revert as he can't vote in this epoch (last voted was updated in `reset`)
    vm.prank(beef);
    vm.expectRevert(abi.encodePacked("TOKEN_ALREADY_VOTED_THIS_EPOCH"));
    voter.vote(tokenId, pools, weights, 0);
}

The original report as published on Immunefi, by OxAlix2. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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 reset function lacks a check that the token actually has active votes before updating lastVoted.

Impact

A token seller can grief the buyer by preventing them from voting with the purchased token during the current epoch.

What the attacker needed

Attacker owns a votable token; attacker can front-run the transfer; victim buys or receives the token

The fix

The reset function should require that the token has active votes before updating lastVoted, possibly only for non-admin callers.

How it was found

  1. Create a lock to obtain a token ID.
  2. Call reset on the token even though it has no active votes.
  3. Transfer the token to another user.
  4. The new owner attempts to vote and the transaction reverts because the token is marked as already voted this epoch.

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.

Tokens in this system are like tradable voting passes. The reset function is meant to clear votes, but it also marks the token as having voted recently even if it had no votes. So a seller can call reset right before selling, and the buyer is then told they already voted this round and cannot vote.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by OxAlix2

View all

6 more disclosed reports, best first.

More from Alchemix

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.