> For the complete documentation index, see [llms.txt](https://reports.immunefi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://reports.immunefi.com/alchemix-v3/56347-sc-insight-burn-contains-redundant-calculations.md).

# 56347 sc insight burn contains redundant calculations

**Submitted on Oct 14th 2025 at 19:13:07 UTC by @magtentic for** [**Audit Comp | Alchemix V3**](https://immunefi.com/audit-competition/alchemix-v3-audit-competition)

* **Report ID:** #56347
* **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 burn function performs the same calculation three times sequentially.\
This can be optimized by storing the result in a local variable and reusing it.

## Vulnerability Details

In the `burn` function, there is the below calculations :

```
    function burn(uint256 amount, uint256 recipientId) external returns (uint256) {
        ...
        _accounts[recipientId].collateralBalance -= convertDebtTokensToYield(credit) * protocolFee / BPS;
        TokenUtils.safeTransfer(myt, protocolFeeReceiver, convertDebtTokensToYield(credit) * protocolFee / BPS);
        _mytSharesDeposited -= convertDebtTokensToYield(credit) * protocolFee / BPS;
        ...
    }
```

This can be refactored to :

```
    function burn(uint256 amount, uint256 recipientId) external returns (uint256) {
        ...
        uint256 creditAmount = convertDebtTokensToYield(credit) * protocolFee / BPS;
        _accounts[recipientId].collateralBalance -= creditAmount;
        TokenUtils.safeTransfer(myt, protocolFeeReceiver, creditAmount);
        _mytSharesDeposited -= creditAmount;
        ...
    }
```

Which makes it avoid duplicate calculation and makes it more readable and maintainable.

## Impact Details

This is a code optimization issue. Benefits include:

* Reduced gas usage
* Improved readability and maintainability
* Lower risk of inconsistencies if the calculation changes in the future

## References

AlchemistV3 - <https://github.com/alchemix-finance/v3-poc/blob/immunefi\\_audit/src/AlchemistV3.sol>

## Proof of Concept

Insight submission, no PoC required as this is a code optimization.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://reports.immunefi.com/alchemix-v3/56347-sc-insight-burn-contains-redundant-calculations.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
