Skip to content
Business logic Audit finding Intermediate

Colition between approve and _isApprovedOrOwner

A user who has been approved for two NFTs cannot call merge() because the internal burn step calls approve(address(0), tokenId), which reverts when the caller is not the owner or an operator. The approved user is therefore blocked from merging the tokens.

Ch301 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

31087 - [SC - Low] Colition between approve and _isApprovedOrOwner...

Submitted on May 12th 2024 at 14:40:44 UTC by @Ch301 for Boost | Alchemix

Report ID: #31087

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

Users with approve() can't trigger merge() function.

Vulnerability Details

When a user (has the approve) triggers VotingEscrow.sol#merge() the _burn() function will sub-call to approve()

Solidity
File: VotingEscrow.sol

1601:     function _burn(uint256 _tokenId, uint256 _value) internal {
             /***/
1609:         // Clear approval
1610:         approve(address(0), _tokenId);

However, the approve() will revert if: msg.sender is not the owner and (ownerToOperators[owner])[msg.sender] returns false.

Solidity
File: VotingEscrow.sol
501:     function approve(address _approved, uint256 _tokenId) public {
        /***/
507:         // Check requirements
508:         bool senderIsOwner = (owner == msg.sender);
509:         bool senderIsApprovedForAll = (ownerToOperators[owner])[msg.sender];
510: 
511:         require(senderIsOwner || senderIsApprovedForAll, "sender is not owner or approved");

Impact Details

The owner sets both the NFTs approve() to the user. however, he cannot call merge() successfully.

References

non

Proof of Concept

Foundry PoC:

  1. Please copy the following POC in VotingEscrow.t.sol
Solidity
 function test_poc() public {
        uint256 tokenId1 = createVeAlcx(admin, TOKEN_1, MAXTIME, false);
        uint256 tokenId2 = createVeAlcx(admin, TOKEN_100K, MAXTIME / 2, false);

        hevm.startPrank(admin);
        // Vote to trigger flux accrual
        hevm.warp(newEpoch());

        address[] memory pools = new address[](1);
        pools[0] = alETHPool;
        uint256[] memory weights = new uint256[](1);
        weights[0] = 5000;
        voter.vote(tokenId1, pools, weights, 0);
        voter.vote(tokenId2, pools, weights, 0);

        voter.distribute();

        hevm.warp(newEpoch());

        // Reset to allow merging of tokens
        voter.reset(tokenId1);
        //voter.reset(tokenId2); No needs
        veALCX.approve(beef, tokenId1);
        veALCX.approve(beef, tokenId2);
        hevm.stopPrank();

        hevm.prank(beef);
        hevm.expectRevert(abi.encodePacked("sender is not owner or approved"));
        veALCX.merge(tokenId1, tokenId2);
    }
  1. Test result:
Diff
Ran 1 test for src/test/VotingEscrow.t.sol:VotingEscrowTest
[PASS] test_poc() (gas: 4059754)
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 93.81s (68.85s CPU time)

Ran 1 test suite in 96.06s (93.81s CPU time): 1 tests passed, 0 failed, 0 skipped 
(1 total tests)

The original report as published on Immunefi, by Ch301. 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 internal _burn function calls the public approve function, which enforces that the caller is the owner or an operator, so an approved user cannot complete merge().

Impact

An approved user cannot merge tokens, so the contract fails to deliver the expected merge functionality, but no funds are lost.

What the attacker needed

Owner approves another address for two tokens; approved address calls merge()

How it was found

  1. Create two veALCX tokens owned by the admin.
  2. Vote with both tokens and distribute rewards.
  3. Reset the first token to allow merging.
  4. Approve a third-party address for both tokens.
  5. Call merge() from the approved address and observe the revert.

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, an NFT owner can give another person permission to act on their token using approve. That person is then supposed to be able to merge two tokens, but the merge code tries to clear the approval by calling approve itself. The approve function only allows the owner or a special operator to call it, so the approved person's 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 Ch301

View all

1 more disclosed report, 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.