TOFT removeCollateral
can be used to steal all the balance
#1293
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
edited-by-warden
H-12
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/tapiocaz-audit/blob/master/contracts/tOFT/modules/BaseTOFTMarketModule.sol#L239
Vulnerability details
Impact
removeCollateral
->remove
message pathway can be used to steal all the balance of theTapiocaOFT
andmTapiocaOFT
tokens in case when their underlying tokens is native.TOFTs that hold native tokens are deployed with erc20 address set to address zero, so while minting you need to transfer value.
Proof of Concept
The attack needs to be executed by invoking the
removeCollateral
function from any chain to chain on which the underlying balance resides, e.g. host chain of the TOFT.When the message is received on the remote chain, I have placed in the comments below what are the params that need to be passed to execute the attack.
Neither
removeParams.marketHelper
orwithdrawParams.withdrawLzFeeAmount
are validated on the sending side so the former can be the address of a malicious contract and the latter can be the TOFT's balance of gas token.This type of attack is possible because the
msg.sender
inIMagnetar(removeParams.marketHelper).withdrawToChain
is the address of the TOFT contract which holds all the balances.This is because:
lzReceive
so he is themsg.sender
._blockingLzReceive
there is a call into its own public function so themsg.sender
is the address of the contract._nonBlockingLzReceive
there is delegatecall into a corresponding module which preserves themsg.sender
which is the address of the TOFT.msg.sender
is the address of the TOFT contract, so we can maliciously transfer all the balance of the TOFT.Tools Used
Recommended Mitigation Steps
It's hard to recommend a simple fix since as I pointed out in my other issues the airdropping logic has many flaws.
One of the ways of tackling this issue is during the
removeCollateral
to:adapterParams
params to be passed as bytes but rather asgasLimit
andairdroppedAmount
, from which you would encode eitheradapterParamsV1
oradapterParamsV2
.Assessed type
ETH-Transfer
The text was updated successfully, but these errors were encountered: