Skip to content
Access control Audit finding Intermediate

UniV3LiquidityAMO::recoverERC721 will cause ERC721 tokens to be permanently locked in rdpxV2Core

The recoverERC721 function in UniV3LiquidityAMO transfers ERC721 tokens to the RdpxV2Core contract, which has no way to transfer or approve them, so the tokens become permanently locked. An admin using this function would cause an irrecoverable loss of the NFTs.

bart1e Follow with rokinot, gkrastenov and 14 others

Originally disclosed on Code4rena

Submitted by bart1e, also found by rokinot, gkrastenov, HHK, bin2chen, jasonxiale, Aymen0909, josephdara, pep7siup, peakbolt, Inspex, kodyvim, tapir, 0x3b, 0xCiphky, rvierdiiev, and chaduke

https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/amo/UniV3LiquidityAmo.sol#L324-L334

https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/core/RdpxV2Core.sol#L1-L1308

UniV3LiquidityAMO::recoverERC721 is a function created in order to be able to recover ERC721 tokens from the UniV3LiquidityAMO contract. It can only be called by admin and will transfer all ERC721 tokens to the RdpxV2Core contract. The problem is, that it won’t be possible to do anything with these tokens after they are transferred to rdpxV2Core.

Indeed, RdpxV2Core inherits from the following contracts:

  • AccessControl,
  • ContractWhitelist,
  • ERC721Holder,
  • Pausable

and no contract from this list implement any logic allowing the NFT transfer (only ERC721Holder has something to do with NFTs, but it only allows to receive them, not to approve or transfer).

Moreover, rdpxV2Core also doesn’t have any logic allowing transfer or approval of NFTs:

  • there is no generic execute function there
  • no function implemented is related to ERC721 tokens (except for onERC721Received inherited from ERC721Holder)
  • it may seem possible to do a dirty hack and try to use approveContractToSpend in order to approve ERC721 token. Theoretically, one would have to specify ERC721 tokenId instead of ERC20 token amount, so that IERC20WithBurn(_token).approve(_spender, _amount); in fact approves ERC721 token with tokenId == _amount, but it fails with [FAIL. Reason: EvmError: Revert] and even if it didn’t, it still wouldn’t be possible to transfer ERC721 token with tokenId == 0 since there is _validate(_amount > 0, 17); inside approveContractToSpend

Impact

UniV3LiquidityAMO::recoverERC721 instead of recovering ERC721, locks all tokens in rdpxV2Core and it won’t be possible to recover them from that contract.

Any use of recoverERC721 will imply an irrecoverable loss for the protocol and this function was implemented in order to be used at some point after all (even if only on emergency situations). Because of that, I’m submitting this issue as High.

Proof of Concept

This PoC only shows that ERC721 token recovery will not be possible by calling RdpxV2Core::approveContractToSpend. Lack of functions doing transfer or approve or any other ERC721 related functions in RdpxV2Core may just be observed by looking at the contract’s code.

Please create the MockERC721.sol file in mocks directory and with the following code:

pragma solidity ^0.8.19;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract MockERC721 is ERC721
{
    constructor() ERC721("...", "...")
    {

    }

    function giveNFT() public
    {
        _mint(msg.sender, 1);
    }
}

It will just mint an ERC721 token with tokenId = 1. Please also run the following test:

  function testNFT() public
  {
    // needed `import "../../contracts/mocks/MockERC721.sol";` at the beginning of the file

    MockERC721 mockERC721 = new MockERC721();
    mockERC721.giveNFT();
    mockERC721.transferFrom(address(this), address(rdpxV2Core), 1);

    // approveContractToSpend won't be possible to use
    vm.expectRevert();
    rdpxV2Core.approveContractToSpend(address(mockERC721), address(this), 1);
  }

Tools Used

VS Code

Recommended Mitigation Steps

Either implement additional ERC721 recovery function in RdpxV2Core or change UniV3LiquidityAMO::recoverERC721 so that it transfers all NFTs to msg.sender instead of RdpxV2Core contract.

psytama (Dopex) confirmed and commented:

Change recover ERC721 function in uni v3 AMO.

Alex the Entreprenerd (Judge) commented:

The Warden has shown an incorrect hardcoded address in the recoverERC721 if used it would cause an irrevocable loss of funds

Technically speaking the Sponsor could use execute as a replacement, however the default function causes a loss so I’m inclined to agree with High Severity


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

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 recoverERC721 function hardcodes the RdpxV2Core address as the recipient, but RdpxV2Core lacks any function to transfer or approve ERC721 tokens.

Impact

Any use of recoverERC721 will cause an irrecoverable loss of the ERC721 tokens for the protocol.

What the attacker needed

Admin calls recoverERC721; ERC721 tokens held by UniV3LiquidityAMO

The fix

The recoverERC721 function should be changed to transfer NFTs to msg.sender instead of RdpxV2Core, or RdpxV2Core should implement an ERC721 recovery function.

How it was found

  1. Deploy a mock ERC721 contract and mint a token.
  2. Transfer the token to the RdpxV2Core contract.
  3. Attempt to call approveContractToSpend on RdpxV2Core for the NFT, which 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 where a function meant to rescue NFTs sends them to another contract that cannot move them out. Once the NFTs arrive there, nobody can transfer or approve them, so they are stuck forever. The mistake is like mailing a package to a building with no doors.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by bart1e

View all

8 more disclosed reports, best first.

More from Dopex

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.