TOFT triggerSendFrom can be used to steal all the balance
Originally disclosed on Code4rena
Submitted by windhustler
triggerSendFrom -> sendFromDestination message pathway can be used to steal all the balance of the TapiocaOFT and mTapiocaOFT` tokens in case when their underlying tokens is native gas token. 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 flow is the following:
- Attacker calls
triggerSendFromwithairdropAdapterParamsof type airdropAdapterParamsV1 which don’t airdrop any value on the remote chain but just deliver the message. - On the other hand lzCallParams are of type
adapterParamsV2which are used to airdrop the balance from the destination chain to another chain to the attacker.
struct LzCallParams {
address payable refundAddress; // => address of the attacker
address zroPaymentAddress; // => doesn't matter
bytes adapterParams; //=> airdropAdapterParamsV2
}
- Whereby the
sendFromData.adapterParamswould be encoded in the following way:
function encodeAdapterParamsV2() public {
// https://layerzero.gitbook.io/docs/evm-guides/advanced/relayer-adapter-parameters#airdrop
uint256 gasLimit = 250_000; // something enough to deliver the message
uint256 airdroppedAmount = max airdrop cap defined at https://layerzero.gitbook.io/docs/evm-guides/advanced/relayer-adapter-parameters#airdrop. => 0.24 for ethereum, 1.32 for bsc, 681 for polygon etc.
address attacker = makeAddr("attacker"); // => address of the attacker
bytes memory adapterParams = abi.encodePacked(uint16(2), gasLimit, airdroppedAmount, attacker);
}
- When this is received on the remote inside the
sendFromDestinationISendFrom(address(this)).sendFrom{value: address(this).balance}is instructed by the maliciousISendFrom.LzCallParams memory callParamsto actually airdrop the max amount allowed by LayerZero to the attacker on thelzDstChainId. - Since there is a cap on the maximum airdrop amount this type of attack would need to be executed multiple times to drain the balance of the TOFT.
The core issue at play here is that BaseTOFT delegatecalls into the BaseTOFTOptionsModule and thus the BaseTOFT is the msg.sender for sendFrom function.
There is also another simpler attack flow possible:
- Since
sendFromDestinationpasses as value whole balance of the TapiocaOFT it is enough to specify the refundAddress in callParams as the address of the attacker. - This way the whole balance will be transferred to the _lzSend and any excess will be refunded to the
_refundAddress. - This is how layer zero works.
Tools Used
Foundry
Recommended Mitigation Steps
One of the ways of tackling this issue is during the triggerSendFrom to:
- Not allowing
airdropAdapterParamsandsendFromData.adapterParamsparams to be passed as bytes but rather asgasLimitandairdroppedAmount, from which you would encode eitheradapterParamsV1oradapterParamsV2. - And then on the receiving side check and send with value only the amount the user has airdropped.
// Only allow the airdropped amount to be used for another message
ISendFrom(address(this)).sendFrom{value: aidroppedAmount}(
from,
lzDstChainId,
LzLib.addressToBytes32(from),
amount,
callParams
);
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A high-severity business logic bug in Tapioca Invitational. Code4rena made it public on 16 November 2023. Found in the 2023-07-tapioca audit contest (finding H-13).
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.