Submitted by ktg, also found by ktg, gkrastenov, Nikki, anshujalan, imare, gesha17, burhan_khaja, ether_sky, nonseodion (1, 2), HChang26, MrPotatoMagic, grearlake, santipu_, matejdb, jangle, th13vn, SovaSlava, para8956, merlinboii, jasonxiale, nuthan2x, Bobface, 0xPluto, y4y, and 0x0bserver
Function withdraw is used by contract Curves to allow users to withdraw tokens to external ERC20 tokens. The function is currently implemented as:
The function will check if externalToken == address(0), if so, they will deploy the token. This part of code stays behind the condition if (amount > curvesTokenBalance[curvesTokenSubject][msg.sender]) revert InsufficientBalance().
The problem is, the function does not check if the withdraw amount is 0. If withdraw is called with amount = 0, then the token is deployed with default name and symbol before token subject can do anything. The token once deployed cannot be redeployed and the name and symbol stays there forever. Also, since the token is already deployed, function mint, setNameAndSymbol and buyCurvesTokenWithName will all revert when the token subject call them.
Below is a POC for the above issue, save them to file test/curves-erc20.WithdrawFrontrun.ts and run it using command: npx hardhat test test/curves-erc20.WithdrawFrontrun.ts.
I recommend you forbid calling function withdraw with amount = 0.
andresaiello (Curves) acknowledged
