Skip to content
DoS Audit finding Intermediate

Users’s tokens stuck in AutoCompound after Vault is deactivated

When the owner deactivates a vault in the AutoCompound contract, users who deposited their position into that vault can no longer withdraw their leftover token balances. The withdraw function checks vault status to determine the true owner, so deactivation makes the check fail and the withdrawal reverts.

ktg Follow

Originally disclosed on Code4rena

Submitted by ktg

https://github.com/code-423n4/2024-03-revert-lend/blob/main/src/automators/Automator.sol#L79-L82

https://github.com/code-423n4/2024-03-revert-lend/blob/main/src/transformers/AutoCompound.sol#L201-L207

Proof of Concept

Contract AutoCompound inherits Automator contract and it contains a function allowing the owner to disable a vault:

function setVault(address _vault, bool _active) public onlyOwner {
        emit VaultChanged(_vault, _active);
        vaults[_vault] = _active;
    }

Unlike AutoExit and AutoRange in which disabling Vault has no effect, if vault is disabled in AutoCompound then user cannot withdraw their balances:

function withdrawLeftoverBalances(uint256 tokenId, address to) external nonReentrant {
        address owner = nonfungiblePositionManager.ownerOf(tokenId);
        if (vaults[owner]) {
            owner = IVault(owner).ownerOf(tokenId);
        }
        if (owner != msg.sender) {
            revert Unauthorized();
        }

        (,, address token0, address token1,,,,,,,,) = nonfungiblePositionManager.positions(tokenId);

        uint256 balance0 = positionBalances[tokenId][token0];
        if (balance0 > 0) {
            _withdrawBalanceInternal(tokenId, token0, to, balance0, balance0);
        }
        uint256 balance1 = positionBalances[tokenId][token1];
        if (balance1 > 0) {
            _withdrawBalanceInternal(tokenId, token1, to, balance1, balance1);
        }
    }

As you can see in the first lines, if vaults[owner] = false, then owner must equal msg.sender, this will not be the case if the user has deposited their position to the Vault and hence cannot withdraw their balances.

Below is a POC for the above issue. Save this test case to file test/integration/automators/AutoCompound.t.sol and run it using command:

forge test --match-path test/integration/automators/AutoCompound.t.sol --match-test testTokenStuck -vvvv

function testTokenStuck() external {
        vm.prank(TEST_NFT_2_ACCOUNT);
        NPM.approve(address(autoCompound), TEST_NFT_2);

        (,,,,,,, uint128 liquidity,,,,) = NPM.positions(TEST_NFT_2);
        assertEq(liquidity, 80059851033970806503);
         vm.prank(OPERATOR_ACCOUNT);
        autoCompound.execute(AutoCompound.ExecuteParams(TEST_NFT_2, false, 0));
         (,,,,,,, liquidity,,,,) = NPM.positions(TEST_NFT_2);
        assertEq(liquidity, 99102324844935209920);

        // Mock call to  nonfungiblePositionManager.ownerOf to simulate
        // vault change
        // 0xC36442b4a4522E871399CD717aBDD847Ab11FE88 is the address of nonfungiblePositionManager
        // 0x6352211e is ERC721 function signature of `ownerOf`

        address vault = address(0x123);
        vm.mockCall(
            0xC36442b4a4522E871399CD717aBDD847Ab11FE88,(abi.encodeWithSelector(
            0x6352211e,TEST_NFT_2)
        ),
            abi.encode(vault)
        );

        // Withdraw leftover
        vm.prank(TEST_NFT_2_ACCOUNT);
        vm.expectRevert();
        autoCompound.withdrawLeftoverBalances(TEST_NFT_2, TEST_NFT_2_ACCOUNT);

    }

In this test case, I simulate the disabling of vault by mockCall the result of nonfungiblePositionManager.ownerOf(tokenId) to address(0x123), since this address is not vault then the condition vaults[owner] is false.

Recommended Mitigation Steps

I recommend checking the total user left tokens in variable positionBalances and only allow deactivating the current Vault if the number if zero.

Assessed type

Invalid Validation

kalinbas (Revert) confirmed and commented:

Agree this to be an issue. Probably will make whitelisting vaults in automators be a non-reversible action.

ronnyx2017 (judge) commented:

A temporary, mitigable DoS caused by normal administrative operations, so a valid Medium.

Revert mitigated:

Fixed here.

Status: Mitigation confirmed. Full details in reports from thank_you, b0g0 and ktg.


The original report as published on Code4rena, by ktg. 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

The withdraw function uses the vault's active status to decide whether to resolve the real owner through the vault, so deactivating the vault breaks ownership checks for deposited positions.

Impact

Users with positions in a deactivated vault cannot withdraw their leftover tokens, causing a temporary denial of service that can be mitigated.

What the attacker needed

User has deposited position in vault; owner deactivates the vault

The fix

The project fixed it by making vault whitelisting in automators a non-reversible action, as confirmed in the mitigation.

How it was found

  1. Approve the AutoCompound contract to manage the test NFT.
  2. Run AutoCompound execute on the NFT to create leftover balances.
  3. Mock the position manager's ownerOf to return a non-vault address, simulating vault deactivation.
  4. Call withdrawLeftoverBalances as the NFT owner 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.

A vault is a shared contract where users deposit positions. The AutoCompound contract lets the owner turn a vault off. If a user's position is in that vault, the contract normally asks the vault who really owns the position. When the vault is off, it skips that step and compares the wrong address, so the user is rejected and their tokens stay stuck.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by ktg

View all

10 more disclosed reports, best first.

More from Revert Lend

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.