CumulativeEarmarked is not updated at _forceRepay
The _forceRepay function reduces an account's earmarked balance but fails to reduce the global cumulativeEarmarked total, so the global figure becomes inflated after liquidations. An attacker could exploit the inflated state to redeem more than intended and to distort debt calculations that depend on the unearmarked total.
Originally disclosed on Immunefi
- Disclosed after under an hour
58723 sc high cumulativeearmarked is not updated at forcerepay
Submitted on Nov 4th 2025 at 09:31:01 UTC by @farismaulana for Audit Comp | Alchemix V3
- Report ID: #58723
- Report Type: Smart Contract
- Report severity: High
- Target: https://github.com/alchemix-finance/v3-poc/blob/immunefi\\_audit/src/AlchemistV3.sol
- Impacts:
- Protocol insolvency
Description
Brief/Intro
in a healthy state, cumulativeEarmarked should equal the sum of all account.earmarked balances. but in the forceRepay function, while the account.earmarked is deducted by earmarkToRemove it is not the case for global cumulativeEarmarked . a frequent liquidation where forceRepay would actually inflates this state, leading to incorrect global state used by the protocol.
Vulnerability Details
function _forceRepay(uint256 accountId, uint256 amount) internal returns (uint256) {
...
// Repay debt from earmarked amount of debt first
uint256 earmarkToRemove = credit > account.earmarked ? account.earmarked : credit;
account.earmarked -= earmarkToRemove;
on the snippet above, the _forceRepay is deducting from account.earmarked. the amount is based on how much the account can repay their debt where it would prioritize the earmarked amount first.
this is intended but there are oversight on how it should also reduce the global state of cumulativeEarmarked but it is not. this issue would make the whole protocol use wrong global state.
Impact Details
given how cumulativeEarmarked is now inflated, various issue would arise. example:
- in redeem function, the amount is capped by
cumulativeEarmarkedthat can be inflated, resulting in more amount than intended can be redeemed unfairly. _earmarkand_calculateUnrealizedDebtrelies onliveUnearmarked = totalDebt - cumulativeEarmarkedthat now would be understated resulting in inaccuracy for the rest of the function
References
Proof of Concept
Proof of Concept
add this to src/test/AlchemistV3.t.sol:
function testForceRepayDoesNotUpdateCumulativeEarmark() external {
vm.startPrank(someWhale);
IMockYieldToken(mockStrategyYieldToken).mint(whaleSupply, someWhale);
vm.stopPrank();
// just ensureing global alchemist collateralization stays above the minimum required for regular liquidations
// no need to mint anything
vm.startPrank(yetAnotherExternalUser);
SafeERC20.safeApprove(address(vault), address(alchemist), depositAmount * 2);
uint256 sharesBalance = IERC20(address(vault)).balanceOf(address(yetAnotherExternalUser));
alchemist.deposit(depositAmount, yetAnotherExternalUser, 0);
vm.stopPrank();
vm.startPrank(address(0xbeef));
SafeERC20.safeApprove(address(vault), address(alchemist), depositAmount + 100e18);
alchemist.deposit(depositAmount, address(0xbeef), 0);
// a single position nft would have been minted to 0xbeef
uint256 tokenIdFor0xBeef = AlchemistNFTHelper.getFirstTokenId(address(0xbeef), address(alchemistNFT));
uint256 mintAmount = alchemist.totalValue(tokenIdFor0xBeef) * FIXED_POINT_SCALAR / minimumCollateralization;
alchemist.mint(tokenIdFor0xBeef, mintAmount, address(0xbeef));
// create redemption and go half maturation
SafeERC20.safeApprove(address(alToken), address(transmuterLogic), mintAmount);
transmuterLogic.createRedemption(mintAmount);
vm.roll(block.number + 5_256_000 / 2);
vm.stopPrank();
// interact first so cumulativeEarmarked would be populated here
// can be anything that trigger _earmark()
alchemist.poke(tokenIdFor0xBeef);
// modify yield token price via modifying underlying token supply
(uint256 prevCollateral, uint256 prevDebt,) = alchemist.getCDP(tokenIdFor0xBeef);
uint256 initialVaultSupply = IERC20(address(mockStrategyYieldToken)).totalSupply();
IMockYieldToken(mockStrategyYieldToken).updateMockTokenSupply(initialVaultSupply);
// increasing yeild token suppy by 59 bps or 5.9% while keeping the unederlying supply unchanged
uint256 modifiedVaultSupply = (initialVaultSupply * 590 / 10_000) + initialVaultSupply;
IMockYieldToken(mockStrategyYieldToken).updateMockTokenSupply(modifiedVaultSupply);
// let another user liquidate the previous user position
vm.startPrank(externalUser);
uint256 earmarkBeforeForceRepay = alchemist.cumulativeEarmarked();
alchemist.liquidate(tokenIdFor0xBeef);
uint256 earmarkAfterForceRepay = alchemist.cumulativeEarmarked();
vm.stopPrank();
// assert the cumualtive earmarked before and after force repay happen
console.log("earmark before force repay: ", earmarkBeforeForceRepay);
console.log("earmark after force repay: ", earmarkAfterForceRepay);
assertEq(earmarkBeforeForceRepay, earmarkAfterForceRepay);
}
the test would pass because the earmark before and after force repay indeed does not change.
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 _forceRepay function updates the per-account earmarked balance but omits the matching decrement of the global cumulativeEarmarked counter.
Impact
The inflated cumulativeEarmarked could let users redeem more than intended and understates liveUnearmarked, making earmark and unrealised debt calculations inaccurate and risking protocol insolvency.
What the attacker needed
A position that can be liquidated; yield token price can be moved
How it was found
- Set up a position and trigger _earmark so cumulativeEarmarked is populated
- Change the yield token supply to move the collateral price
- Have another user liquidate the position, which calls _forceRepay
- Compare cumulativeEarmarked before and after and observe it is unchanged
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.
The protocol tracks two numbers: how much each individual account has set aside (earmarked) and a running total of all earmarked amounts across the protocol. When a liquidation repays debt from an account's set-aside funds, the per-account number goes down but the running total does not, so the total drifts higher than reality. Other parts of the protocol trust that total, so they can behave incorrectly.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.