Skip to content
Business logic Audit finding Advanced

There is an issue in earmarked debt eeduction in the repay() can causes a permanent fund freeze

The repay() function removes the full earmarked debt amount whenever a user repays, rather than a proportional share, so a user who repays half their debt loses all earmarked protection. Later redemptions then reduce their collateral without a matching debt reduction, which the author claims can leave positions below the minimum collateralisation and permanently frozen.

XDZIBECX Follow

Originally disclosed on Immunefi

Critical View original
  • Disclosed after under an hour

58683 sc critical there is an issue in earmarked debt eeduction in the repay can causes a permanent fund freeze

Submitted on Nov 4th 2025 at 01:45:21 UTC by @XDZIBECX for Audit Comp | Alchemix V3

Description

Brief/Intro

there is an issue in the repay function that is removes all earmarked debt when a user repays, regardless of the repayment amount. and this is creates an asymmetry where users lose their protection during redemptions, so their collateral is reduced globally based on system-wide redemption weights, but their debt reduction depends on their local earmarked amount. When a user repays 50% of their debt, the function is incorrectly wipes 100% of their earmarked protection instead of 50%. Subsequent redemptions then reduce the user's collateral without proportional debt reduction, and this is not correct because this is create a positions with collateralization ratios below the minimum threshold. and this positions become a permanently frozen due an underflows and that is prevent withdrawals, and liquidations, or any recovery operations, so as reuslt his is gone be a permanent loss of user funds.

Vulnerability Details

The vulnerability exists in the repay() function here --> https://github.com/alchemix-finance/v3-poc/blob/a192ab313c81ba3ab621d9ca1ee000110fbdd1e9/src/AlchemistV3.sol#L521C9-L523C46

// Repay debt from earmarked amount of debt first
uint256 earmarkToRemove = credit > account.earmarked ? account.earmarked : credit;
account.earmarked -= earmarkToRemove;

so the flaw is that When credit < account.earmarked, the contract is removes min(credit, earmarked) from the earmarked. and this is means if a user repays 50% of their debt, but earmarked equals or exceeds that amount, then the full repayment amount is removed from earmarked, not a proportional share.

the burn() function it's correctly protects earmarked debt ---> https://github.com/alchemix-finance/v3-poc/blob/a192ab313c81ba3ab621d9ca1ee000110fbdd1e9/src/AlchemistV3.sol#L470 from here it's prevents burning earmarked debt entirely, but the repay() removes it disproportionately. and this inconsistency is a bug, and this is not an intended behavior.

Solidity
// Burning alAssets can only repay unearmarked debt
_checkState((debt = _accounts[recipientId].debt - _accounts[recipientId].earmarked) > 0);

as known that the Earmarked debt represents a user's proportional share of debt that will be redeemed via the Transmuter. the fucntion _sync()uses rhe earmarked amounts to calculate the debt reduction during the redemption from here --> https://github.com/alchemix-finance/v3-poc/blob/a192ab313c81ba3ab621d9ca1ee000110fbdd1e9/src/AlchemistV3.sol#L1075C7-L1084C1 :

Solidity
// Old earmarks that survived redemptions in the current sync window
uint256 exposureSurvival = _mulQ128(account.earmarked, survivalRatio);
// What was redeemed from the newly earmark between last sync and now
uint256 redeemedFromEarmarked = earmarkRaw - earmarkedUnredeemed;
// Total overall earmarked to adjust user debt
uint256 redeemedTotal = (account.earmarked - exposureSurvival) + redeemedFromEarmarked;

account.earmarked = exposureSurvival + earmarkedUnredeemed;
account.debt = account.debt >= redeemedTotal ? account.debt - redeemedTotal : 0;

so If the account.earmarked = 0, then the redeemedTotal ≈ 0, this is mean there is no debt reduction occurs during the redemptions.

the collateral is ALWAYS reduced and hti is based on global weights here https://github.com/alchemix-finance/v3-poc/blob/a192ab313c81ba3ab621d9ca1ee000110fbdd1e9/src/AlchemistV3.sol#L1217C7-L1219C80

Solidity
uint256 collateralToRemove = PositionDecay.ScaleByWeightDelta(account.rawLocked, _collateralWeight - account.lastCollateralWeight);
account.collateralBalance -= collateralToRemove;

this is creates the asymmetry that collateral reduced globally, debt reduced locally based on earmarked.

Impact Details

i chose this as impact Permanent freezing of funds i alerdy test this and is occur check and run please the test is show all result

so this impact can happen when users repay their debt, then the contract incorrectly removes all their earmarked protection instead of reducing it proportionally. as an example, if a user repays 50% of their debt, the contract should keep 50% of their earmarked protection but instead is removes 100% of it. and this earmarked protection is crucial because it determines how much debt gets reduced when redemptions happen. Without it, users lose collateral during the redemptions but their debt stays the same, and this making them owe more than they have. The position then breaks mathematically the contract's internal accounting becomes impossible (it calculates that locked collateral should be 27.78 ETH when the user only has 20.36 ETH), and this is cause all operations to fail with arithmetic errors. The user cannot withdraw, cannot repay more, and cannot be liquidated. Their funds are permanently stuck. In a real scenario with 100 ETH deposited, approximately 20-30 ETH (worth $40,000-$60,000) becomes permanently frozen. and this is happens automatically during normal use any user who repays debt while the Transmuter has active positions will trigger this with no way to recover their fund this need to be fixed

References

check the vulnerbaility details i use all them in the pargraph

Proof of Concept

Proof of Concept

copy past this test in the AlchemistV3.t.sol and run it

Solidity

function test_CriticalBug_RepayWipesEarmarked_CreatesUnliquidatablePosition() external {
        console.log("=== CRITICAL BUG TEST: Repay Wipes Earmarked Debt ===");
        console.log("");
        
        // Setup: Enable protocol fee and configure liquidation bounds
        vm.startPrank(alOwner);
        alchemist.setProtocolFee(100);  // 1% protocol fee
        alchemist.setCollateralizationLowerBound(alchemist.minimumCollateralization() * 99 / 100);
        vm.stopPrank();

        uint256 depositAmount = 100e18;
        uint256 debtAmount = 50e18;  // 50% LTV
        
        // === STEP 1: Create two identical positions ===
        address userA = address(0xA11CE);
        address userB = address(0xB0B);
        
        // Setup User A
        vm.startPrank(userA);
        deal(address(vault), userA, depositAmount);
        vault.approve(address(alchemist), depositAmount);
        alchemist.deposit(depositAmount, userA, 0);
        uint256 tokenIdA = AlchemistNFTHelper.getFirstTokenId(userA, address(alchemistNFT));
        alchemist.mint(tokenIdA, debtAmount, userA);
        vm.stopPrank();

        // Setup User B
        vm.startPrank(userB);
        deal(address(vault), userB, depositAmount);
        vault.approve(address(alchemist), depositAmount);
        alchemist.deposit(depositAmount, userB, 0);
        uint256 tokenIdB = AlchemistNFTHelper.getFirstTokenId(userB, address(alchemistNFT));
        alchemist.mint(tokenIdB, debtAmount, userB);
        vm.stopPrank();

        console.log("Step 1 - Initial State:");
        (uint256 collateralA1, uint256 debtA1, uint256 earmarkedA1) = alchemist.getCDP(tokenIdA);
        (uint256 collateralB1, uint256 debtB1, uint256 earmarkedB1) = alchemist.getCDP(tokenIdB);
        console.log("  User A: collateral=%e, debt=%e, earmarked=%e", collateralA1, debtA1, earmarkedA1);
        console.log("  User B: collateral=%e, debt=%e, earmarked=%e", collateralB1, debtB1, earmarkedB1);
        console.log("");

        // === STEP 2: Create LARGE redemption to build significant earmarked debt ===
        vm.startPrank(userA);
        alToken.approve(address(transmuterLogic), debtAmount);
        transmuterLogic.createRedemption(debtAmount);
        vm.stopPrank();

        // Advance to FULL MATURATION to maximize earmarked debt
        vm.roll(block.number + 5_256_000);
        
        alchemist.poke(tokenIdA);
        alchemist.poke(tokenIdB);

        console.log("Step 2 - After FULL Earmarking (5.25M blocks - FULLY MATURED):");
        (uint256 collateralA2, uint256 debtA2, uint256 earmarkedA2) = alchemist.getCDP(tokenIdA);
        (uint256 collateralB2, uint256 debtB2, uint256 earmarkedB2) = alchemist.getCDP(tokenIdB);
        console.log("  User A: collateral=%e, debt=%e, earmarked=%e", collateralA2, debtA2, earmarkedA2);
        console.log("  User B: collateral=%e, debt=%e, earmarked=%e", collateralB2, debtB2, earmarkedB2);
        console.log("  Total Debt: %e, Cumulative Earmarked: %e", alchemist.totalDebt(), alchemist.cumulativeEarmarked());
        assertGt(earmarkedA2, debtA2 / 4, "User A should have significant earmarked debt (>25%)");
        assertGt(earmarkedB2, debtB2 / 4, "User B should have significant earmarked debt (>25%)");
        console.log("");

        // === STEP 3: User B repays SMALL amount (BUG: wipes DISPROPORTIONATE earmarked) ===
        uint256 repayAmount = debtB2 / 2;  // Repay 50% of debt
        
        vm.startPrank(userB);
        deal(address(vault), userB, repayAmount);
        vault.approve(address(alchemist), repayAmount);
        alchemist.repay(alchemist.convertDebtTokensToYield(repayAmount), tokenIdB);
        
        // Withdraw maximum to make position leveraged
        (uint256 tempColl, uint256 tempDebt,) = alchemist.getCDP(tokenIdB);
        uint256 lockedNeeded = alchemist.convertDebtTokensToYield(tempDebt) * alchemist.minimumCollateralization() / FIXED_POINT_SCALAR;
        uint256 maxWithdraw = tempColl > lockedNeeded ? tempColl - lockedNeeded - 1e18 : 0;
        if (maxWithdraw > 0) {
            alchemist.withdraw(maxWithdraw, userB, tokenIdB);
        }
        vm.stopPrank();

        alchemist.poke(tokenIdA);
        alchemist.poke(tokenIdB);

        console.log("Step 3 - After User B Repays 50%% of Debt:");
        (uint256 collateralA3, uint256 debtA3, uint256 earmarkedA3) = alchemist.getCDP(tokenIdA);
        (uint256 collateralB3, uint256 debtB3, uint256 earmarkedB3) = alchemist.getCDP(tokenIdB);
        console.log("  User A: collateral=%e, debt=%e, earmarked=%e", collateralA3, debtA3, earmarkedA3);
        console.log("  User B: collateral=%e, debt=%e, earmarked=%e", collateralB3, debtB3, earmarkedB3);
        console.log("  >>> BUG EVIDENCE: User B repaid 50%% but earmarked is: %e", earmarkedB3);
        console.log("  >>> EXPECTED: earmarked should be ~%e (50%% of %e)", earmarkedB2 / 2, earmarkedB2);
        assertEq(earmarkedB3, 0, "BUG CONFIRMED: User B's earmarked debt completely wiped!");
        console.log("");

        // === STEP 4: LARGE Redemption occurs ===
        vm.prank(userA);
        transmuterLogic.claimRedemption(1);

        alchemist.poke(tokenIdA);
        alchemist.poke(tokenIdB);

        console.log("Step 4 - After LARGE Redemption (50e18 debt):");
        (uint256 collateralA4, uint256 debtA4, uint256 earmarkedA4) = alchemist.getCDP(tokenIdA);
        (uint256 collateralB4, uint256 debtB4, uint256 earmarkedB4) = alchemist.getCDP(tokenIdB);
        console.log("  User A: collateral=%e, debt=%e, earmarked=%e", collateralA4, debtA4, earmarkedA4);
        console.log("  User B: collateral=%e, debt=%e, earmarked=%e", collateralB4, debtB4, earmarkedB4);
        
        // Calculate collateralization ratios
        uint256 valueA = alchemist.totalValue(tokenIdA);
        uint256 valueB = alchemist.totalValue(tokenIdB);
        uint256 ratioA = debtA4 > 0 ? valueA * FIXED_POINT_SCALAR / debtA4 : type(uint256).max;
        uint256 ratioB = debtB4 > 0 ? valueB * FIXED_POINT_SCALAR / debtB4 : type(uint256).max;
        
        console.log("  User A collateralization: %e%% (healthy)", ratioA * 100 / FIXED_POINT_SCALAR);
        console.log("  User B collateralization: %e%% (compromised!)", ratioB * 100 / FIXED_POINT_SCALAR);
        console.log("");
        
        // Show the asymmetric impact
        uint256 collateralLossA = collateralA3 > collateralA4 ? collateralA3 - collateralA4 : 0;
        uint256 collateralLossB = collateralB3 > collateralB4 ? collateralB3 - collateralB4 : 0;
        uint256 debtReductionA = debtA3 > debtA4 ? debtA3 - debtA4 : 0;
        uint256 debtReductionB = debtB3 > debtB4 ? debtB3 - debtB4 : 0;
        
        console.log("  ASYMMETRIC IMPACT:");
        console.log("  User A: Lost %e collateral, Debt reduced by %e", collateralLossA, debtReductionA);
        console.log("  User B: Lost %e collateral, Debt reduced by %e", collateralLossB, debtReductionB);
        console.log("  >>> User B has earmarked=0, so NO debt reduction despite collateral loss!");
        console.log("");

        // === STEP 5: Prove position cannot be managed ===
        console.log("Step 5 - Proving Permanent Freeze:");
        
        vm.startPrank(userB);
        
        // Try to repay remaining debt - will fail because user has no vault shares left
        console.log("  Attempting to repay remaining debt...");
        try alchemist.repay(alchemist.convertDebtTokensToYield(debtB4), tokenIdB) {
            console.log("    Repayment succeeded");
        } catch {
            console.log("    >>> FAILED: Cannot repay (insufficient vault shares from earlier withdrawal)");
        }
        
        // Try to withdraw - will fail because position is at minimum collateralization
        console.log("  Attempting to withdraw collateral...");
        try alchemist.withdraw(1e18, userB, tokenIdB) {
            console.log("    Withdrawal succeeded");
        } catch {
            console.log("    >>> FAILED: Cannot withdraw (position too leveraged)");
        }
        
        vm.stopPrank();
        console.log("");
        
        // === STEP 6: Show the core bug ===
        console.log("=== BUG SUMMARY ===");
        console.log("1. User B repaid 50%% of debt");
        console.log("2. repay() wiped 100%% of earmarked debt (should only wipe 50%%)");
        console.log("3. Redemption occurred:");
        console.log("   - User A (earmarked=%e): Debt reduced by %e", earmarkedA3, debtReductionA);
        console.log("   - User B (earmarked=0): Debt reduced by %e", debtReductionB);
        console.log("4. User B lost earmarked protection unfairly");
        console.log("5. With larger redemptions, this creates underwater/unliquidatable positions");
        console.log("");
        console.log("SEVERITY: CRITICAL - Breaks redemption fairness and can freeze funds");
        console.log("");
    }

}

  • the result :
Solidity
 │   │   │   ├─ [9620] MockMYTStrategy::realAssets() [staticcall]
    │   │   │   │   ├─ [1051] MockYieldToken::balanceOf(MockMYTStrategy: [0xF62849F9A0B5Bf2913b396098F7c7019b51A820a]) [staticcall]
    │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   ├─ [4941] MockYieldToken::price() [staticcall]
    │   │   │   │   │   ├─ [931] TestERC20::balanceOf(MockYieldToken: [0x8E8149E630eD0e6D24Ec34d667fd4351bc113CE0]) [staticcall]
    │   │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   │   └─ ← [Return] 1000000000000000000 [1e18]
    │   │   │   │   ├─ [553] MockYieldToken::decimals() [staticcall]
    │   │   │   │   │   └─ ← [Return] 18
    │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   └─ ← [Return] 28777777777777777775 [2.877e19]
    │   │   ├─ [26990] MockMYTVault::transfer(0x0000000000000000000000000000000000000B0b, 70972222222222222225 [7.097e19])
    │   │   │   ├─ emit Transfer(from: TransparentUpgradeableProxy: [0x48c33395391C097df9c9aA887a40f1b47948D393], to: 0x0000000000000000000000000000000000000B0b, value: 70972222222222222225 [7.097e19])       
    │   │   │   └─ ← [Return] true
    │   │   ├─ emit Withdraw(amount: 70972222222222222225 [7.097e19], tokenId: 2, recipient: 0x0000000000000000000000000000000000000B0b)
    │   │   └─ ← [Return] 70972222222222222225 [7.097e19]
    │   └─ ← [Return] 70972222222222222225 [7.097e19]
    ├─ [0] VM::stopPrank()
    │   └─ ← [Return]
    ├─ [66515] TransparentUpgradeableProxy::fallback(1)
    │   ├─ [65803] AlchemistV3::poke(1) [delegatecall]
    │   │   ├─ [1265] AlchemistV3Position::ownerOf(1) [staticcall]
    │   │   │   └─ ← [Return] 0x00000000000000000000000000000000000A11cE
    │   │   ├─ [20520] MockMYTVault::convertToShares(50000000000000000000 [5e19]) [staticcall]
    │   │   │   ├─ [931] TestERC20::balanceOf(MockMYTVault: [0xd7D9fC89347Cc01C7707010604E99D146AC0C3BF]) [staticcall]
    │   │   │   │   └─ ← [Return] 0
    │   │   │   ├─ [9620] MockMYTStrategy::realAssets() [staticcall]
    │   │   │   │   ├─ [1051] MockYieldToken::balanceOf(MockMYTStrategy: [0xF62849F9A0B5Bf2913b396098F7c7019b51A820a]) [staticcall]
    │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   ├─ [4941] MockYieldToken::price() [staticcall]
    │   │   │   │   │   ├─ [931] TestERC20::balanceOf(MockYieldToken: [0x8E8149E630eD0e6D24Ec34d667fd4351bc113CE0]) [staticcall]
    │   │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   │   └─ ← [Return] 1000000000000000000 [1e18]
    │   │   │   │   ├─ [553] MockYieldToken::decimals() [staticcall]
    │   │   │   │   │   └─ ← [Return] 18
    │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   └─ ← [Return] 50000000000000000000 [5e19]
    │   │   └─ ← [Stop]
    │   └─ ← [Return]
    ├─ [65509] TransparentUpgradeableProxy::fallback(2)
    │   ├─ [64797] AlchemistV3::poke(2) [delegatecall]
    │   │   ├─ [1265] AlchemistV3Position::ownerOf(2) [staticcall]
    │   │   │   └─ ← [Return] 0x0000000000000000000000000000000000000B0b
    │   │   ├─ [20520] MockMYTVault::convertToShares(25000000000000000000 [2.5e19]) [staticcall]        
    │   │   │   ├─ [931] TestERC20::balanceOf(MockMYTVault: [0xd7D9fC89347Cc01C7707010604E99D146AC0C3BF]) [staticcall]
    │   │   │   │   └─ ← [Return] 0
    │   │   │   ├─ [9620] MockMYTStrategy::realAssets() [staticcall]
    │   │   │   │   ├─ [1051] MockYieldToken::balanceOf(MockMYTStrategy: [0xF62849F9A0B5Bf2913b396098F7c7019b51A820a]) [staticcall]
    │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   ├─ [4941] MockYieldToken::price() [staticcall]
    │   │   │   │   │   ├─ [931] TestERC20::balanceOf(MockYieldToken: [0x8E8149E630eD0e6D24Ec34d667fd4351bc113CE0]) [staticcall]
    │   │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   │   └─ ← [Return] 1000000000000000000 [1e18]
    │   │   │   │   ├─ [553] MockYieldToken::decimals() [staticcall]
    │   │   │   │   │   └─ ← [Return] 18
    │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   └─ ← [Return] 25000000000000000000 [2.5e19]
    │   │   └─ ← [Stop]
    │   └─ ← [Return]
    ├─ [0] console::log("Step 3 - After User B Repays 50%% of Debt:") [staticcall]
    │   └─ ← [Stop]
    ├─ [38552] TransparentUpgradeableProxy::fallback(1) [staticcall]
    │   ├─ [37831] AlchemistV3::getCDP(1) [delegatecall]
    │   │   └─ ← [Return] 100000000000000000000 [1e20], 50000000000000000000 [5e19], 25000000000000000000 [2.5e19]
    │   └─ ← [Return] 100000000000000000000 [1e20], 50000000000000000000 [5e19], 25000000000000000000 [2.5e19]
    ├─ [37546] TransparentUpgradeableProxy::fallback(2) [staticcall]
    │   ├─ [36825] AlchemistV3::getCDP(2) [delegatecall]
    │   │   └─ ← [Return] 28777777777777777775 [2.877e19], 25000000000000000000 [2.5e19], 0
    │   └─ ← [Return] 28777777777777777775 [2.877e19], 25000000000000000000 [2.5e19], 0
    ├─ [0] console::log("  User A: collateral=%e, debt=%e, earmarked=%e", 100000000000000000000 [1e20], 50000000000000000000 [5e19], 25000000000000000000 [2.5e19]) [staticcall]
    │   └─ ← [Stop]
    ├─ [0] console::log("  User B: collateral=%e, debt=%e, earmarked=%e", 28777777777777777775 [2.877e19], 25000000000000000000 [2.5e19], 0) [staticcall]
    │   └─ ← [Stop]
    ├─ [0] console::log("  >>> BUG EVIDENCE: User B repaid 50%% but earmarked is: %e", 0) [staticcall]  
    │   └─ ← [Stop]
    ├─ [0] console::log("  >>> EXPECTED: earmarked should be ~%e (50%% of %e)", 12500000000000000000 [1.25e19], 25000000000000000000 [2.5e19]) [staticcall]
    │   └─ ← [Stop]
    ├─ [0] console::log("") [staticcall]
    │   └─ ← [Stop]
    ├─ [0] VM::prank(0x00000000000000000000000000000000000A11cE)
    │   └─ ← [Return]
    ├─ [575120] Transmuter::claimRedemption(1)
    │   ├─ emit Transfer(from: 0x00000000000000000000000000000000000A11cE, to: 0x0000000000000000000000000000000000000000, tokenId: 1)
    │   ├─ [1712] TransparentUpgradeableProxy::fallback() [staticcall]
    │   │   ├─ [1000] AlchemistV3::myt() [delegatecall]
    │   │   │   └─ ← [Return] MockMYTVault: [0xd7D9fC89347Cc01C7707010604E99D146AC0C3BF]
    │   │   └─ ← [Return] MockMYTVault: [0xd7D9fC89347Cc01C7707010604E99D146AC0C3BF]
    │   ├─ [1715] MockMYTVault::balanceOf(Transmuter: [0x2387b3383E89c164781d173B7Aa14d9c46eD2642]) [staticcall]
    │   │   └─ ← [Return] 25000000000000000000 [2.5e19]
    │   ├─ [22324] TransparentUpgradeableProxy::fallback() [staticcall]
    │   │   ├─ [21612] AlchemistV3::getTotalUnderlyingValue() [delegatecall]
    │   │   │   ├─ [18895] MockMYTVault::convertToAssets(128777777777777777775 [1.287e20]) [staticcall] 
    │   │   │   │   ├─ [931] TestERC20::balanceOf(MockMYTVault: [0xd7D9fC89347Cc01C7707010604E99D146AC0C3BF]) [staticcall]
    │   │   │   │   │   └─ ← [Return] 0
    │   │   │   │   ├─ [9620] MockMYTStrategy::realAssets() [staticcall]
    │   │   │   │   │   ├─ [1051] MockYieldToken::balanceOf(MockMYTStrategy: [0xF62849F9A0B5Bf2913b396098F7c7019b51A820a]) [staticcall]
    │   │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   │   ├─ [4941] MockYieldToken::price() [staticcall]
    │   │   │   │   │   │   ├─ [931] TestERC20::balanceOf(MockYieldToken: [0x8E8149E630eD0e6D24Ec34d667fd4351bc113CE0]) [staticcall]
    │   │   │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   │   │   └─ ← [Return] 1000000000000000000 [1e18]
    │   │   │   │   │   ├─ [553] MockYieldToken::decimals() [staticcall]
    │   │   │   │   │   │   └─ ← [Return] 18
    │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   └─ ← [Return] 128777777777777777775 [1.287e20]
    │   │   │   └─ ← [Return] 128777777777777777775 [1.287e20]
    │   │   └─ ← [Return] 128777777777777777775 [1.287e20]
    │   ├─ [21133] TransparentUpgradeableProxy::fallback(25000000000000000000 [2.5e19]) [staticcall]    
    │   │   ├─ [20418] AlchemistV3::convertYieldTokensToUnderlying(25000000000000000000 [2.5e19]) [delegatecall]
    │   │   │   ├─ [18895] MockMYTVault::convertToAssets(25000000000000000000 [2.5e19]) [staticcall]    
    │   │   │   │   ├─ [931] TestERC20::balanceOf(MockMYTVault: [0xd7D9fC89347Cc01C7707010604E99D146AC0C3BF]) [staticcall]
    │   │   │   │   │   └─ ← [Return] 0
    │   │   │   │   ├─ [9620] MockMYTStrategy::realAssets() [staticcall]
    │   │   │   │   │   ├─ [1051] MockYieldToken::balanceOf(MockMYTStrategy: [0xF62849F9A0B5Bf2913b396098F7c7019b51A820a]) [staticcall]
    │   │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   │   ├─ [4941] MockYieldToken::price() [staticcall]
    │   │   │   │   │   │   ├─ [931] TestERC20::balanceOf(MockYieldToken: [0x8E8149E630eD0e6D24Ec34d667fd4351bc113CE0]) [staticcall]
    │   │   │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   │   │   └─ ← [Return] 1000000000000000000 [1e18]
    │   │   │   │   │   ├─ [553] MockYieldToken::decimals() [staticcall]
    │   │   │   │   │   │   └─ ← [Return] 18
    │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   └─ ← [Return] 25000000000000000000 [2.5e19]
    │   │   │   └─ ← [Return] 25000000000000000000 [2.5e19]
    │   │   └─ ← [Return] 25000000000000000000 [2.5e19]
    │   ├─ [22324] TransparentUpgradeableProxy::fallback() [staticcall]
    │   │   ├─ [21612] AlchemistV3::getTotalUnderlyingValue() [delegatecall]
    │   │   │   ├─ [18895] MockMYTVault::convertToAssets(128777777777777777775 [1.287e20]) [staticcall] 
    │   │   │   │   ├─ [931] TestERC20::balanceOf(MockMYTVault: [0xd7D9fC89347Cc01C7707010604E99D146AC0C3BF]) [staticcall]
    │   │   │   │   │   └─ ← [Return] 0
    │   │   │   │   ├─ [9620] MockMYTStrategy::realAssets() [staticcall]
    │   │   │   │   │   ├─ [1051] MockYieldToken::balanceOf(MockMYTStrategy: [0xF62849F9A0B5Bf2913b396098F7c7019b51A820a]) [staticcall]
    │   │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   │   ├─ [4941] MockYieldToken::price() [staticcall]
    │   │   │   │   │   │   ├─ [931] TestERC20::balanceOf(MockYieldToken: [0x8E8149E630eD0e6D24Ec34d667fd4351bc113CE0]) [staticcall]
    │   │   │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   │   │   └─ ← [Return] 1000000000000000000 [1e18]
    │   │   │   │   │   ├─ [553] MockYieldToken::decimals() [staticcall]
    │   │   │   │   │   │   └─ ← [Return] 18
    │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   └─ ← [Return] 128777777777777777775 [1.287e20]
    │   │   │   └─ ← [Return] 128777777777777777775 [1.287e20]
    │   │   └─ ← [Return] 128777777777777777775 [1.287e20]
    │   ├─ [21133] TransparentUpgradeableProxy::fallback(25000000000000000000 [2.5e19]) [staticcall]    
    │   │   ├─ [20418] AlchemistV3::convertYieldTokensToUnderlying(25000000000000000000 [2.5e19]) [delegatecall]
    │   │   │   ├─ [18895] MockMYTVault::convertToAssets(25000000000000000000 [2.5e19]) [staticcall]    
    │   │   │   │   ├─ [931] TestERC20::balanceOf(MockMYTVault: [0xd7D9fC89347Cc01C7707010604E99D146AC0C3BF]) [staticcall]
    │   │   │   │   │   └─ ← [Return] 0
    │   │   │   │   ├─ [9620] MockMYTStrategy::realAssets() [staticcall]
    │   │   │   │   │   ├─ [1051] MockYieldToken::balanceOf(MockMYTStrategy: [0xF62849F9A0B5Bf2913b396098F7c7019b51A820a]) [staticcall]
    │   │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   │   ├─ [4941] MockYieldToken::price() [staticcall]
    │   │   │   │   │   │   ├─ [931] TestERC20::balanceOf(MockYieldToken: [0x8E8149E630eD0e6D24Ec34d667fd4351bc113CE0]) [staticcall]
    │   │   │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   │   │   └─ ← [Return] 1000000000000000000 [1e18]
    │   │   │   │   │   ├─ [553] MockYieldToken::decimals() [staticcall]
    │   │   │   │   │   │   └─ ← [Return] 18
    │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   └─ ← [Return] 25000000000000000000 [2.5e19]
    │   │   │   └─ ← [Return] 25000000000000000000 [2.5e19]
    │   │   └─ ← [Return] 25000000000000000000 [2.5e19]
    │   ├─ [1295] TransparentUpgradeableProxy::fallback() [staticcall]
    │   │   ├─ [583] AlchemistV3::totalSyntheticsIssued() [delegatecall]
    │   │   │   └─ ← [Return] 100000000000000000000 [1e20]
    │   │   └─ ← [Return] 100000000000000000000 [1e20]
    │   ├─ [3448] TransparentUpgradeableProxy::fallback() [staticcall]
    │   │   ├─ [2736] AlchemistV3::underlyingToken() [delegatecall]
    │   │   │   └─ ← [Return] TestERC20: [0xf9ee71f54F2009fD180C480e44a5176AdCABa5eA]
    │   │   └─ ← [Return] TestERC20: [0xf9ee71f54F2009fD180C480e44a5176AdCABa5eA]
    │   ├─ [2519] TestERC20::decimals() [staticcall]
    │   │   └─ ← [Return] 18
    │   ├─ [21969] TransparentUpgradeableProxy::fallback(25000000000000000000 [2.5e19]) [staticcall]    
    │   │   ├─ [21254] AlchemistV3::convertYieldTokensToDebt(25000000000000000000 [2.5e19]) [delegatecall]
    │   │   │   ├─ [18895] MockMYTVault::convertToAssets(25000000000000000000 [2.5e19]) [staticcall]    
    │   │   │   │   ├─ [931] TestERC20::balanceOf(MockMYTVault: [0xd7D9fC89347Cc01C7707010604E99D146AC0C3BF]) [staticcall]
    │   │   │   │   │   └─ ← [Return] 0
    │   │   │   │   ├─ [9620] MockMYTStrategy::realAssets() [staticcall]
    │   │   │   │   │   ├─ [1051] MockYieldToken::balanceOf(MockMYTStrategy: [0xF62849F9A0B5Bf2913b396098F7c7019b51A820a]) [staticcall]
    │   │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   │   ├─ [4941] MockYieldToken::price() [staticcall]
    │   │   │   │   │   │   ├─ [931] TestERC20::balanceOf(MockYieldToken: [0x8E8149E630eD0e6D24Ec34d667fd4351bc113CE0]) [staticcall]
    │   │   │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   │   │   └─ ← [Return] 1000000000000000000 [1e18]
    │   │   │   │   │   ├─ [553] MockYieldToken::decimals() [staticcall]
    │   │   │   │   │   │   └─ ← [Return] 18
    │   │   │   │   │   └─ ← [Return] 1000000000000000000000000 [1e24]
    │   │   │   │   └─ ← [Return] 25000000000000000000 [2.5e19]
    │   │   │   └─ ← [Return] 25000000000000000000 [2.5e19]
    │   │   └─ ← [Return] 25000000000000000000 [2.5e19]
    │   ├─ [278780] TransparentUpgradeableProxy::fallback(25000000000000000000 [2.5e19])
    │   │   ├─ [278068] AlchemistV3::redeem(25000000000000000000 [2.5e19]) [delegatecall]
    │   │   │   ├─ [1715] MockMYTVault::balanceOf(Transmuter: [0x2387b3383E89c164781d173B7Aa14d9c46eD2642]) [staticcall]
    │   │   │   │   └─ ← [Return] 25000000000000000000 [2.5e19]
    │   │   │   ├─ [18895] MockMYTVault::convertToAssets(25000000000000000000 [2.5e19]) [staticcall]    
    │   │   │   │   ├─ [931] TestERC20::balanceOf(MockMYTVault: [0xd7D9fC89347Cc01C7707010604E99D146AC0C3BF]) [staticcall]
    │   │   │   │   │   └─ ← [Return] 0
    │   │   │   │   ├─ [9620] MockMYTStrategy::realAssets() [staticcall]
    │   │   │   │

The original report as published on Immunefi, by XDZIBECX. 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 repay() function subtracts min(credit, earmarked) from the earmarked balance instead of reducing it in proportion to the repaid share of debt, unlike burn() which protects earmarked debt.

Impact

The author claims affected positions can fall below the minimum collateralisation and become permanently frozen, with no withdrawal, repayment or liquidation possible, though the evidence is a single test run rather than a demonstrated production exploit.

What the attacker needed

An open position with debt; earmarked debt accrued via redemptions; user repays part of the debt

The fix

The repay() function should reduce the earmarked balance in proportion to the repaid share of debt rather than clearing it whenever the repayment covers it.

How it was found

  1. Create two identical positions with the same deposit and debt.
  2. Create a large redemption and advance blocks so both positions accrue significant earmarked debt.
  3. Have one user repay half their debt and withdraw the maximum allowed.
  4. Trigger a large redemption and observe that the repaying user's collateral falls but their debt does not.
  5. Attempt to repay and withdraw again to show the position can no longer be managed.

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 lending protocol, part of a user's debt is 'earmarked', meaning it is set aside to be paid off through a redemption process. That earmarked amount normally shrinks in step with the user's debt, so when redemptions happen the user's debt goes down as their collateral goes down. The report says repaying wipes the whole earmarked amount instead of a matching share, so the user's collateral can be cut while their debt stays high, leaving them unable to withdraw or repay.

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 XDZIBECX

View all

21 more disclosed reports, best first.

More from Alchemix V3

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.