sherlock-audit / 2023-02-gmx-judging

17 stars 11 forks source link

float-audits - User deposits can be lost if deposits are not crafted carefully #201

Closed sherlock-admin closed 1 year ago

sherlock-admin commented 1 year ago

float-audits

high

User deposits can be lost if deposits are not crafted carefully

Summary

A user depositing ERC20 tokens into strict bank, then subsequently calling createDeposit can be front run by a malicious party taking all of their deposit.

Vulnerability Detail

In exchangeRouter, the createDeposit function states the following: @dev Creates a new deposit with the given long token, short token, long token amount, short token

Impact

A user who tried to transfer ERC20 tokens to the deposit store then subsequently call create deposit without carefully crafting a multicall will have their entire deposit lost by a front runner who claims the deposit on their behalf.

Code Snippet

One can see that recordTranferIn simply checks the balance increased in the contracts and credits that to whoever first calls createDeposit. If sending of the ERC20 tokens to this deposit store ever happens non-atomically with the createDeposit call, the user stands to lose all their deposit. This is not stated clearly anywhere and its a conceivable scenario for a user to first transfer their ERC20 tokens before calling create deposit.

LoC: https://github.com/sherlock-audit/2023-02-gmx/blob/main/gmx-synthetics/contracts/bank/StrictBank.sol#L36-L45

Tool used

Manual Review

Recommendation

The createDeposit code could call the ERC20 transfers within the scope of the function to avoid this ever being a nasty scenario that could take place.