Skip to content
Business logic Audit finding Intermediate

Approved user cant merge tokens not approved fo

An approved user (not approved for all) cannot merge two tokens because the merge function calls approve(address(0), tokenId) to clear the approval, which reverts for regular approved users. This blocks approved users from merging tokens, contrary to the intended behaviour.

OxAlix2 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

31272 - [SC - Low] Approved user cant merge tokens not approved fo...

Submitted on May 16th 2024 at 01:14:43 UTC by @OxAlix2 for Boost | Alchemix

Report ID: #31272

Report type: Smart Contract

Report severity: Low

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

Impacts:

  • Contract fails to deliver promised returns, but doesn't lose value

Description

Brief/Intro

To merge 2 tokens into 2, a user must be either approved or owner of both tokens. This is obvious in the following checks in VotingEscrow::merge:

require(_isApprovedOrOwner(msg.sender, _from), "not approved or owner");
require(_isApprovedOrOwner(msg.sender, _to), "not approved or owner");

It also calls _burn which clears the approval of the "from" token, however, it's clearing it wrong as it calls approve(address(0), _tokenId);, which checks if the caller is the owner or approved for all, it doesn't allow "regular" approved users (which makes sense).

Vulnerability Details

This blocks approved users (not for all) from merging 2 tokens, as the TX will revert in approve, which is not intended. The protocol should use _clearApproval(owner, _tokenId); instead.

Impact Details

Approved users (not for all) aren't able to merge tokens.

References

https://github.com/alchemix-finance/alchemix-v2-dao/blob/main/src/VotingEscrow.sol#L1567

Proof of Concept

function testApprovedCantMerge() public {
    uint256 tokenId1 = createVeAlcx(admin, TOKEN_1, MAXTIME, false);
    uint256 tokenId2 = createVeAlcx(beef, TOKEN_100K, MAXTIME / 2, false);

    hevm.prank(admin);
    veALCX.approve(beef, tokenId1);

    assertEq(veALCX.getApproved(tokenId1), beef);
    assertEq(veALCX.ownerOf(tokenId2), beef);

    hevm.prank(beef);
    vm.expectRevert(abi.encodePacked("sender is not owner or approved"));
    veALCX.merge(tokenId1, tokenId2);
}

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 merge function uses approve(address(0), tokenId) to clear approval instead of the internal _clearApproval function, which does not require owner or full approval.

Impact

Approved users (not approved for all) are unable to merge tokens, which prevents them from using a core function of the contract.

What the attacker needed

Caller is approved (not for all) for one token; caller owns the other token

The fix

The protocol should use _clearApproval(owner, _tokenId) instead of approve(address(0), _tokenId) to clear the approval.

How it was found

  1. Create two tokens, one owned by admin and one owned by beef.
  2. Admin approves beef for the first token.
  3. Beef calls merge on the two tokens.
  4. The transaction reverts with 'sender is not owner or approved'.

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.

In this smart contract, tokens can be approved so someone else can manage them. When merging two tokens, the code tries to remove the approval on one token by calling a function that only the owner or a fully approved operator can use. A regular approved user is not allowed to call that function, so the merge fails.

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.