56801 sc insight function burn could be gas optimized

Submitted on Oct 20th 2025 at 20:16:30 UTC by @PotEater for Audit Comp | Alchemix V3arrow-up-right

  • Report ID: #56801

  • Report Type: Smart Contract

  • Report severity: Insight

  • Target: https://github.com/alchemix-finance/v3-poc/blob/immunefi_audit/src/AlchemistV3.sol

  • Impacts:

Description

Brief/Intro

The function burn uses the same calculations redundantly, these calculations could be gas optimized by creating one variable.

Vulnerability Details

Code snippet:

        // Debt is subject to protocol fee similar to redemptions
        _accounts[recipientId].collateralBalance -= convertDebtTokensToYield(credit) * protocolFee / BPS;

        TokenUtils.safeTransfer(myt, protocolFeeReceiver, convertDebtTokensToYield(credit) * protocolFee / BPS);
        _mytSharesDeposited -= convertDebtTokensToYield(credit) * protocolFee / BPS;

As seen in the code, the function performs the same calculation three times:

This could be optimized by simply creating a uint256 variable optimizedAmount and using this variable instead of calculating each time. This means the calculation would be needed just once. Which saves significant gas.

Impact Details

This is a gas optimization. This would save roughly 45,000 gas per call. Which is significant.

References

https://github.com/alchemix-finance/v3-poc/blob/a192ab313c81ba3ab621d9ca1ee000110fbdd1e9/src/AlchemistV3.sol#L483

Proof of Concept

Proof of Concept

Add this function in the AlchemistV3.t.sol test file:

Running this function without any optimization shows cost of 829412 gas:

Now, let's optimize the function burn: Optimized version:

Result after optimization:

Was this helpful?