hats-finance / Fenix--0x9d7765a7ebd5b6322a30797a44a5428531970d3d

0 stars 1 forks source link

`CompoundVeFNXManagedNFTStrategyUpgradeable` is vulnerable to a race condition #22

Open hats-bug-reporter[bot] opened 1 month ago

hats-bug-reporter[bot] commented 1 month ago

Github username: -- Twitter username: -- Submission hash (on-chain): 0x12e486dfb70cddd958580ce0f417546069a9be6728a736928f8d107355394357 Severity: medium

Description: https://github.com/hats-finance/Fenix--0x9d7765a7ebd5b6322a30797a44a5428531970d3d/blob/353c8e8e24454336e805e5c0e11e4e9ae1491d03/contracts/nest/CompoundVeFNXManagedNFTStrategyUpgradeable.sol#l129-L139

Description

The ERC20 approval mechanism in CompoundVeFNXManagedNFTStrategyUpgradeable is vulnerable to a race condition. This vulnerability occurs when an allowance is changed directly from one non-zero value to another non-zero value. An attacker can exploit this situation by front-running transactions, leading to unintended token transfers.

Attack Scenario

Imagine a scenario where:

The transactions are mined in the following sequence:

Attachments

Proof of Concept (PoC) File

    function compound() external {
        IERC20 fenixCache = IERC20(fenix);
        uint256 currentBalance = fenixCache.balanceOf(address(this));
        if (currentBalance > 0) {
            address votingEscrowCache = votingEscrow;
            fenixCache.safeApprove(votingEscrowCache, currentBalance);
            IVotingEscrowV1_2(votingEscrowCache).deposit_for_without_boost(managedTokenId, currentBalance);
            ISingelTokenVirtualRewarder(virtualRewarder).notifyRewardAmount(currentBalance);
            emit Compound(msg.sender, currentBalance);
        }
    }

Recomendation:

Always do safeApprove(0) if the allowance is being changed, or use safeIncreaseAllowance().

0xmahdirostami commented 1 month ago

Invalid