Skip to content
Business logic Audit finding Beginner

Fix unit mismatch in _doLiquidation: collateralInUnderlying -> collateralInDebt

A parameter in the liquidation function is named as if it holds an underlying-token amount, but the code and its documentation treat it as a debt-token amount. The report says current callers appear correct, so there is no live exploit, but a future developer could pass the wrong unit and cause mispriced liquidations or wrong fees.

wylis Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

58076 sc insight fix unit mismatch in doliquidation collateralinunderlying collateralindebt

#58076 [SC-Insight] Fix unit mismatch in _doLiquidation: collateralInUnderlying -> collateralInDebt

Submitted on Oct 30th 2025 at 13:05:06 UTC by @wylis for Audit Comp | Alchemix V3

Description

Brief

The liquidation path mixes up parameter naming/units in AlchemistV3._doLiquidation(). The argument named collateralInUnderlying is actually expected to be expressed in debt tokens. While current call sites may be correct, the inconsistency creates a high risk of future regressions where a developer passes an underlying-denominated value, leading to mispriced liquidations and incorrect fee calculations.

Details

Current code reads:

Solidity

    /// @param collateralInUnderlying The total collateral value of the account in debt tokens.

The parameter name is wrong, but the NatSpec is right.

The name collateralInUnderlying indicates “in underlying tokens,” but the doc string says “in debt tokens.” The function downstream (calculateLiquidation) expects a debt-denominated value, so the parameter name is misleading.

Impact

This is submitted as an Insight (documentation/naming inconsistency). However, if a future change misuses the parameter due to the name, realistic downstream impacts include: under- or over-liquidation, incorrect fee routing, or invariant breaks under market moves.

Recommendation

Solidity
-    /// @param collateralInUnderlying The total collateral value of the account in debt tokens.
+    /// @param collateralInDebt The total collateral value of the account in debt tokens.
     /// @param repaidAmountInYield The amount of debt repaid in yield tokens.
-    function _doLiquidation(uint256 accountId, uint256 collateralInUnderlying, uint256 repaidAmountInYield)
+    function _doLiquidation(uint256 accountId, uint256 collateralInDebt, uint256 repaidAmountInYield)
         internal
         returns (uint256 amountLiquidated, uint256 feeInYield, uint256 feeInUnderlying)
     {
         Account storage account = _accounts[accountId];

         (uint256 liquidationAmount, uint256 debtToBurn, uint256 baseFee, uint256 outsourcedFee) = calculateLiquidation(
-            collateralInUnderlying,
+            collateralInDebt,
             ...
         );

Proof of Concept

Proof of Concept

N/A for doc report.

The original report as published on Immunefi, by wylis. 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 a naming inconsistency: the parameter is called collateralInUnderlying while the function and its documentation expect a value denominated in debt tokens.

Impact

No exploit is demonstrated; the report only warns that a future misuse of the misleadingly named parameter could cause under- or over-liquidation, incorrect fee routing, or broken invariants.

What the attacker needed

None; naming issue only

The fix

The parameter and its documentation should be renamed to collateralInDebt so the name matches the debt-token unit the function expects.

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 smart contract is a program that runs on a blockchain. This one has a function that liquidates a borrower's position, and one of its inputs is named in a way that suggests a different unit of value than the code actually expects. Nothing is broken today, but the confusing name could lead a future programmer to supply the wrong kind of number.

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 wylis

View all

4 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.