Skip to content
Business logic Audit finding Intermediate

transferVaultBalance function is unusable and mistransfers user's funds due to hardcoded asset ID

The admin vault migration function uses a hardcoded asset ID (80085) instead of the user's actual asset ID, so it typically reverts because that ID has no shares. If a user is later assigned that ID, the function could move that user's funds unintentionally.

0xpinkman Follow with 8olidity, ARMoh and 22 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-09-ammplify-judging/issues/133

Found by

0xpinkman, 8olidity, ARMoh, CasinoCompiler, DSbeX, KlosMitSoss, Mishkat6451, Motomoto, Razkky, Sa1ntRobi, Slayer, TheSavageTeddy, _Ranjan2003, aster, holtzzx, jayjoshix, panprog, r1ver, rubencrxz, tedox, tinnohofficial, uuzall, volleyking, vtim, yungjoky

Summary

The admin migration tool uses a hardcoded id (80085) when moving balances between vaults, so it targets a single arbitrary account instead of user's real assetIds. Because balances are accounted per position assetId elsewhere, the migration withdraw for id 80085 usually finds no shares and the entire admin call reverts. assetId will eventually collide with the hardcoded value, and when it does, this flaw will escalate to a vector for direct, unintentional theft of user funds.

Root Cause

AdminFacet.transferVaultBalance imports TAKER_VAULT_ID and calls VaultLib.transfer(fromVault, toVault, TAKER_VAULT_ID, amount), forcing both withdraw and deposit to run against id 80085.

https://github.com/sherlock-audit/2025-09-ammplify/blob/main/Ammplify/src/facets/Admin.sol#L133 https://github.com/sherlock-audit/2025-09-ammplify/blob/main/Ammplify/src/facets/Taker.sol#L18

The system’s taker and view flows key balances by each position’s assetId, so the migration’s single‑id pathway is incompatible with the storage model.

Internal Pre-conditions

Nil

External Pre-conditions

Nil

Attack Path

  • Register an active and a backup ERC4626 vault for a token via AdminFacet.addVault so there is a source and destination vault to migrate between.
  • Call AdminFacet.transferVaultBalance(fromVault, toVault, amount) with any nonzero amount to initiate migration.
  • The function imports TAKER_VAULT_ID and forwards it to VaultLib.transfer as the userId, so the library executes withdraw(userId=80085, amount) from the source vault and then tries to deposit the same id into the destination.
  • Because balances are tracked per real position assetId , userId 80085 typically has zero shares, withdraw fails, and the whole transaction reverts.
  • Also, this assetId will eventually collide with the hardcoded value, and when it does, this flaw will escalate to a vector for direct, unintentional theft of user funds.

Impact

  • The admin's vault migration function is non-functional. Because it targets a single, hardcoded assetId instead of actual user balances, any attempt to perform a vault rotation or emergency migration will revert.

  • As the protocol assigns assetIds sequentially, a user position will inevitably be assigned the hardcoded ID. At that point, the same administrative function will unintentionally move that specific user's funds, creating a direct risk of non-consensual fund movement and asset misappropriation.

PoC

Solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.27;

import { ERC20 } from "a@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { VaultType } from "src/vaults/Vault.sol";
import { MultiSetupTest } from "test/MultiSetup.u.sol";
import { MockERC20 } from "test/mocks/MockERC20.sol";
import { MockERC4626 } from "test/mocks/MockERC4626.sol";

contract PoC_Migration is MultiSetupTest {
    MockERC20 private mockToken;
    MockERC4626 private activeVault;
    MockERC4626 private backupVault;

    function setUp() public {
        _newDiamond(); // deploys diamond and facets (adminFacet available) [MultiSetup.u.sol]
        mockToken   = new MockERC20("Mock", "MOCK", 18);
        activeVault = new MockERC4626(ERC20(address(mockToken)), "Active", "ACT");
        backupVault = new MockERC4626(ERC20(address(mockToken)), "Backup", "BKP");

        // Register active and backup vaults for token at index 0 [Admin.sol]
        adminFacet.addVault(address(mockToken), 0, address(activeVault), VaultType.E4626);
        adminFacet.addVault(address(mockToken), 0, address(backupVault), VaultType.E4626);
    }

    function test_transferVaultBalance_reverts_when80085HasNoShares() public {
        // Because AdminFacet.transferVaultBalance hardcodes TAKER_VAULT_ID=80085, and 80085 has no shares,
        // withdrawing on that id reverts during VaultLib.transfer [Admin.sol][Vault.sol].
        uint256 amount = 1e6;
        vm.expectRevert();
        adminFacet.transferVaultBalance(address(activeVault), address(backupVault), amount);
    }
}

Result:

Solidity
Ran 1 test for test/POC.t.sol:PoC_Migration
[PASS] test_transferVaultBalance_reverts_when80085HasNoShares() (gas: 46446)
Traces:
  [46446] PoC_Migration::test_transferVaultBalance_reverts_when80085HasNoShares()
    ├─ [0] VM::expectRevert(custom error 0xf4844814)
    │   └─ ← [Return]
    ├─ [33679] SimplexDiamond::fallback(MockERC4626: [0x5991A2dF15A8F6A256D3Ec51E99254Cd3fb576A9], MockERC4626: [0xc7183455a4C133Ae270771860664b6B7ec320bB1], 1000000 [1e6])
    │   ├─ [28765] AdminFacet::transferVaultBalance(MockERC4626: [0x5991A2dF15A8F6A256D3Ec51E99254Cd3fb576A9], MockERC4626: [0xc7183455a4C133Ae270771860664b6B7ec320bB1], 1000000 [1e6]) [delegatecall]
    │   │   ├─ [8308] MockERC4626::previewRedeem(0) [staticcall]
    │   │   │   ├─ [2484] MockERC20::balanceOf(MockERC4626: [0x5991A2dF15A8F6A256D3Ec51E99254Cd3fb576A9]) [staticcall]
    │   │   │   │   └─ ← [Return] 0
    │   │   │   └─ ← [Return] 0
    │   │   ├─ [2135] MockERC4626::previewDeposit(340282366920938463463374607431768211456 [3.402e38]) [staticcall]
    │   │   │   ├─ [484] MockERC20::balanceOf(MockERC4626: [0x5991A2dF15A8F6A256D3Ec51E99254Cd3fb576A9]) [staticcall]
    │   │   │   │   └─ ← [Return] 0
    │   │   │   └─ ← [Return] 340282366920938463463374607431768211456 [3.402e38]
    │   │   ├─ [1808] MockERC4626::previewRedeem(340282366920938463463374607431768211456 [3.402e38]) [staticcall]
    │   │   │   ├─ [484] MockERC20::balanceOf(MockERC4626: [0x5991A2dF15A8F6A256D3Ec51E99254Cd3fb576A9]) [staticcall]
    │   │   │   │   └─ ← [Return] 0
    │   │   │   └─ ← [Return] 340282366920938463463374607431768211456 [3.402e38]
    │   │   └─ ← [Revert] EvmError: Revert
    │   └─ ← [Revert] EvmError: Revert
    └─ ← [Return]

Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 49.29ms (7.15ms CPU time)

Mitigation

  • The AdminFacet.transferVaultBalance function is fundamentally flawed and should be removed entirely.
  • For vault migrations and upgrades, the protocol should exclusively use the existing VaultLib.hotSwap mechanism. This "hot-swap" or "lazy migration" approach is safer as it avoids direct, per-user fund transfers and eliminates both the Denial of Service and the fund-hijack risks.
  • The assetId 80085 should be explicitly reserved in the asset creation logic to prevent it from ever being assigned to a user, eliminating any future ID collision risk.

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/itos-finance/Ammplify/pull/37

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

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 function hardcodes the asset ID (80085) instead of using the actual user's asset ID, which is incompatible with the per-asset balance tracking used elsewhere.

Impact

The migration function is non-functional and reverts, and if a user is later assigned the hardcoded ID, the function could unintentionally move that user's funds.

What the attacker needed

Admin role; vaults registered

The fix

The function should be removed and replaced with the existing hotSwap mechanism, and the hardcoded ID should be reserved to prevent collisions; the text states the protocol team fixed this issue.

How it was found

  1. Register an active and a backup ERC4626 vault for a token via AdminFacet.addVault.
  2. Call AdminFacet.transferVaultBalance(fromVault, toVault, amount) with any nonzero amount.
  3. The function uses the hardcoded TAKER_VAULT_ID (80085) as the userId for VaultLib.transfer.
  4. Because balances are tracked per real position assetId, userId 80085 typically has zero shares, so the withdraw fails and the transaction 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.

A vault is a place where the protocol keeps user funds. The admin has a tool to move funds from one vault to another, but it always uses a fixed number (80085) to identify whose funds to move, instead of the real user's number. Because no user normally has that number, the tool fails; if a user ever gets that number, their funds could be moved by mistake.

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 0xpinkman

View all

1 more disclosed report, best first.

More from Ammplify

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.