Submitted by dirk_y, also found by bin2chen, carrotsmuggler, 0x73696d616f, and chaduke
The TapiocaOFT.sol contract allows users to wrap ERC20 tokens into an OFTV2 type contract to allow for seamless cross-chain use.
As with most ERC20 tokens, owners of tokens have the ability to give an allowance to another address to spend their tokens. This allowance should be decremented every time a user spends the owners tokens. However the TapiocaOFT.sol _wrap method contains a bug that allows a user with a non-zero allowance to keep using the same allowance to spend the owners tokens.
For example, if an owner had 100 tokens and gave an allowance of 10 to a spender, that spender would be able to spend all 100 tokens in 10 transactions.
When a user wants to wrap a non-native ERC20 token into a TapiocaOFT they call wrap which calls _wrap under the hood:
If the sender isnt the owner of the ERC20 tokens being wrapped, the allowance of the user is checked. However this isnt checking the underlying ERC20 allowance, but the allowance of the current contract (the TapiocaOFT).
Next, the underlying ERC20 token is transferred from the owner to this address. This decrements the allowance of the sender, however the sender isnt the original message sender, but this contract.
In order to use this contract as an owner (Alice) I would have to approve the TapiocaOFT contract to spend my ERC20 tokens, and it is common to approve this contract to spend all my tokens if I trust the contract. Now lets say I approved another user (Bob) to spend some (lets say 5) of my TapiocaOFT tokens. Bob can now call wrap(aliceAddress, bobAddress, 5) as many times as he wants to steal all of Alices tokens.
In my opinion you shouldnt be able to wrap another users ERC20 tokens into a different token, because this is a different action to spending. Also, there is no way to decrement the allowance of the user (of the TapiocaOFT token) in the same call as we arent actually transferring any tokens; there is no function selector in the ERC20 spec to decrease an allowance from another contract.
Therefore I would suggest the following change:
0xRektora (Tapioca) confirmed
