56561 sc insight fee amount is recomputed multiple times when the initial value has already been cached

Submitted on Oct 17th 2025 at 16:49:54 UTC by @Josh4324 for Audit Comp | Alchemix V3arrow-up-right

  • Report ID: #56561

  • 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 fee amount is being calculated in every place that it is used, despite it being cached earlier. This results in additional gas usage and is also prone to errors.

Vulnerability Details

Check the repay function in the Alchemix V3.

  1. The feeAmount is calculated and stored.

  2. The feeAmount variable is used.

    1. and 5. The feeAmount is recomputed 3 times, thus wasting gas and increasing the error surface.

Impact Details

  1. More gas is consumed.

  2. The error surface is increased, especially when updating the code.

References

https://github.com/alchemix-finance/v3-poc/blob/immunefi_audit/src/AlchemistV3.sol?utm_source=immunefi#L530C4-L541C66

Proof of Concept

Proof of Concept

Please run this on Remix.

It has two functions repeat and noRepeat. The repeat function repeats the fee calculation three times, the same as the above function, while the no repeat uses the cached value instead.

output repeat cost: 9759 to execute. noRepeat cost: 8204 to execute

Was this helpful?