57793 sc high cumulativeearmarked variable is not updated in forcerepay function breaking core internal logic and leading to user funds being stuck
Submitted on Oct 28th 2025 at 22:28:02 UTC by @Tadev for Audit Comp | Alchemix V3
Report ID: #57793
Report Type: Smart Contract
Report severity: High
Target: https://github.com/alchemix-finance/v3-poc/blob/immunefi_audit/src/AlchemistV3.sol
Impacts:
Direct theft of any user funds, whether at-rest or in-motion, other than unclaimed yield
Description
Brief/Intro
The cumulativeEarmarked variable is used to store the system debt currently earmarked for redemption. This variable is updated as follows:
decremented in the
repayfunction and in theredeemfunctionincremented in the
_earmarkfunction.
The problem arises because the _forceRepay function used for liquidation doesn't update cumulativeEarmarked while it should.
This means that with the current design, every time a liquidation for a position with earmarked debt (triggering a force repay) occurs, cumulativeEarmarked won't be decremented and will be inflated. This has severe consequences for the protocol as it results in many other variables being wrongly computed.
Vulnerability Details
The _forceRepay function is defined as follows:
Contrary to repay function which updates cumulativeEarmarked after updating account.earmarked, _forceRepay doesn't update this variable. This is a severe vulnerability which breaks core internal logic.
Indeed, inflated value for cumulativeEarmarked will induce multiple consequences.
_earmarkfunction will be impacted: the line:
will underestimate the real unearmarked debt. This will lead to _survivalAccumulator and _earmarkWeight being also wrong.
In an extreme scenario, this line can systematically revert if cumulativeEarmarked > totalDebt. This means the whole protocol will be DOS.
_syncfunction will also be impacted. Because_survivalAccumulatorand_earmarkWeightvalues are wrong, many other variables in this function will have a wrong value. In the end, the user raw collateral, debt and earmarked debt will be incorrect.
This is very serious as it may lead to the user unable to withdraw their tokens while they should be able to do so. Also, excess debt could be counted for every user.
Impact Details
This vulnerability has serious impacts as it breaks the core mechanism of the protocol. cumulativeEarmarked being inflated, many other components of the protocol will be affected, leading to potential DOS of the _earmarked function which means that all funds in the protocol would be stuck. This vulnerability will also lead to wrong accounting for debt, collateral and earmarking for every user.
Proof of Concept
Proof of Concept
Please copy paste the following test in AlchemistV3.t.sol file:
This tests highlights the fact that when someone liquidates a user with earmarked debt, the user earmarked debt is repaid but the cumulativeEarmarked is not correctly updated.
The output is as follows:
This means liquidating positions with earmarked debt will always incorrectly leave cumulativeEarmarked unchanged, increasing its value over time.
Was this helpful?