Airdropped tokens can be stolen by a bot #1300
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
edited-by-warden
M-23
primary issue
Highest quality submission among a set of duplicates
selected for report
This submission will be included/highlighted in the audit report
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Lines of code
https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/usd0/modules/USDOLeverageModule.sol#L227
Vulnerability details
Impact
Most of the packetTypes, when received on the remote chain, are supposed to send a message to another chain.
To send that callback message usually a certain amount of gas is airdropped to a remote chain to execute that message.
If we look at the reception logic for
leverageUp
the airdropped amount is supposed to be transferred to the address of theTapiocaOFT
contract.This is an issue because if anything reverts here the airdropped amount is left sitting in the
USDO
contract and can be stolen by a bot.This is rather a common occurrence through the codebase and usually, in case of a revert the airdropped amount will be left in the
USDO
,TapOFT
, orMagnetarV2
contracts, and in all these places it can be stolen by a bot.There is a high likelihood of this occurring quite often because it takes (1-5 min. or more) for a Relayer to deliver a message to the remote chain during which the airdropped amount might not be sufficient to execute the callback message, or something else can revert.
Proof of Concept
I have already described the issue in the impact section and here I will describe how a bot can steal the airdropped amount.
The bot can use the same message pathway, e.g.
sendForLeverage
->leverageUp
to steal all the balance of theUSDO
contract.sendForLeverage
function with a very small amount ofUSDO
, e.g. that is his cost of attack.ISwapper(externalData.swapper).buildSwapData(..)
,ISwapper(externalData.swapper).swap(...)
,ITapiocaOFTBase(externalData.tOft).wrap(...)
.ITapiocaOFT(externalData.tOft).sendToYBAndBorrow{value: address(this).balance}
this would need to be the address of his malicious contract which implements thesendToYBAndBorrow
and would just receive theaddress(this).balance
.If speed is of importance here the attacker can even pull off a more sophisticated attack which would do the following:
leverageUp
function, and it would fail due to the following mechanism:setDrainGas(true)
on the malicious contract. And monitors if any of the user's transactions are failing, and then he can instantly on the same chain just retry his message through retryMessage and steal all the balance.Tools Used
Recommended Mitigation Steps
This is a more broad architectural issue of the codebase which I discussed in my analysis review, and it goes back to the fact that airdropped gas tokens do not belong to the user.
An immediate fix would be to in the case of function revert to send the airdropped amount back to the user. This can be inserted in the following [place]:(https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/usd0/BaseUSDO.sol#L375-L397)
Other occurrences
Anywhere in the code where
address{this}.balance
ormsg.value
is passed to the_lzSend
if it fails it will remain in that contract and can be stolen. I haven't set up a case for stealing airdropped balances of TOFT contracts, since there is a more serious attack there which I described in my other issues.https://github.com/Tapioca-DAO/tapiocaz-audit/blob/master/contracts/tOFT/modules/BaseTOFTMarketModule.sol#L192-L193 - if execution fails in the
MagnetarMarketModule
contract it will be left sitting in the TOFT or in the MagnetarV2 contract depending on where it was airdropped.https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/usd0/modules/USDOMarketModule.sol#L205 - This assumes that the airdropped value is inside the MagnetarV2 contract since there is a withdrawal to other chain option, and if everything fails the airdropped token is left in the
MagnetarV2
contract.https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/usd0/modules/USDOOptionsModule.sol#L127
https://github.com/Tapioca-DAO/tap-token-audit/blob/main/contracts/tokens/BaseTapOFT.sol#L229 - This same message pathway can be used to steal any balance of BaseTapOFT contract since
try twTap.claimAndSendRewards(tokenID, rewardTokens)
doesn't revert if rewardTokens are not valid tokens, e.g. are just some malicious contract.https://github.com/Tapioca-DAO/tap-token-audit/blob/main/contracts/tokens/BaseTapOFT.sol#L312
If the gas tokens remain as the balance of the MagnetarV2 contract the easiest way to steal them is to call
withdrawToChain
since it can be set up so asset is a malicious contract which just receives value.Assessed type
Other
The text was updated successfully, but these errors were encountered: