(dex-v1) BasePool.mint() function can be frontrun
The BasePool.mint() function does not verify that the caller deposited the assets, so an attacker can frontrun a victim's mint call and receive the NFT representing the victim's deposited tokens. The attacker can then burn the NFT to withdraw the victim's native and foreign assets.
Submitted by Reigada
Impact
In the contract BasePool the mint function can be frontrun. This will assign the NFT to the attacker which later on he can burn it retrieving the corresponding \_nativeAsset and \_foreignAsset initially deposited by the frontrun victim. https://github.com/code-423n4/2021-11-vader/blob/main/contracts/dex/pool/BasePool.sol#L149-L194
Proof of Concept
User1 transfers 1000 \_nativeAsset tokens and 1000 \_foreignAsset tokens into the BasePool contract. User1 calls the BasePool.mint() function to retrieve his NFT. Attacker is constantly polling for an increase of the balance of \_nativeAsset and \_foreignAsset of the contract OR attacker is constantly scanning the mempool for mint() function calls. Attacker detects an increase of balance of \_nativeAsset and \_foreignAsset OR attacker detects a mint() function call in the mempool. Attacker frontruns the mint call and retrieves the NFT. Gets a NFT that is worth 1000 \_nativeAssets and 1000 \_foreignAssets. User1 gets a NFT that is worth 0 \_nativeAssets and 0 \_foreignAssets. Attacker burns the NFT retrieving the corresponding \_nativeAsset and \_foreignAsset initially deposited by the victim.
Tools Used
Manual testing
Recommended Mitigation Steps
Include in the mint() function the transfer of \_nativeAssets and \_foreignAssets to the smart contract.
The pool is meant to be utilized via the router or smart contracts and is not meant to be utilized directly. The exact same “flaw” exists in Uniswap V2 whereby if you transfer assets directly someone else can claim them on your behalf.
Ah, so this how you prevent direct access to the pools. The issue is valid due to lack of documentation on the usage of the router.
Firstly, documentation related issues cannot constitute a high risk vulnerability. Secondly, this type of documentation does not exist in Uniswap V2 either. We advise this finding to be set to no risk.
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
Likely the mint function does not verify that the caller is the one who transferred the underlying assets, allowing anyone to mint an NFT for any deposit.
Impact
An attacker could steal the assets deposited by a victim who calls mint directly, though the pool is intended to be used via a router and the same behaviour exists in Uniswap V2.
What the attacker needed
Victim transfers assets directly to the pool; victim calls mint directly; attacker can frontrun transactions
How it was found
- User1 transfers 1000 _nativeAsset tokens and 1000 _foreignAsset tokens into the BasePool contract.
- User1 calls the BasePool.mint() function to retrieve his NFT.
- Attacker detects the deposit or the mint call in the mempool.
- Attacker frontruns the mint call and retrieves the NFT.
- Attacker burns the NFT to retrieve the deposited assets.
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 deposit tokens into a pool, you get an NFT that proves your share. Here, the mint function does not check who made the deposit, so someone else can call mint first and get the NFT for your deposit. They can then burn that NFT to take your tokens.
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.