Submitted by Shaheen, also found by mt030d, _karanel (1, 2), bigtone, ilchovski, Fortis_audits, Team_RockSolid, Svetoslavb, Heba-Elhasan, Greed, 0xAadi, and shaflow2
https://github.com/code-423n4/2024-06-thorchain/blob/e3fd3c75ff994dce50d6eb66eb290d467bd494f5/ethereum/contracts/THORChain_Router.sol#L196https://github.com/code-423n4/2024-06-thorchain/blob/e3fd3c75ff994dce50d6eb66eb290d467bd494f5/ethereum/contracts/THORChain_Router.sol#L206
One of the main invariant of the protocol is:
In short, this means that all the events ThorChain_Router emits, should be correct.
This invariants breaks in the edge cases of the transferOut(), _transferOutV5(), transferOutAndCall() and _transferOutAndCallV5()
For the sake of simplicity, we will only gonna take a look at the transferOut() function.
transferOut() function is used by the vaults to transfer Native Tokens (ethers) or ERC20 Tokens to any address to. It first transfers the funds to the specified to address and then emits the TransferOut event for ThorChain. In case the Native Tokens transfer to the to address fails, it just refunds or bounce back the ethers to the vault address (msg.sender). Transfer to to address can fail often, as the function uses soliditys .send to transfer the funds. If the to address is a contract which takes more than 2300 gas to complete the execution, then .send will return false and the ethers will be bounced back to the vault address.
The problem is, in the case when the .send will fail and the ethers will bounce back to the vault address, the event TransferOut will be wrong. As we can see, when the ethers receiver will be in vault, not the input to address, the to doesnt get updated to the vaults address and the function in the end emits the same to, ThorChain is getting informed that the ether receiver is still input to:
Technically, the ETH transfer is unsuccessful, but the ThorChain is informed that its successful and the funds are successfully transferred to the specified to address. Also, the smartcontract_log_parsers GetTxInItem() function doesnt ignore these trxs at all, as it doesnt check if txInItem.To is equal to the calling vault or not.
The network believes the outbound was successful and updates the vaults accordingly, but the outbound was not successful; resulting in loss of funds for the users.
Add this test in the 1_Router.js:Fund Yggdrasil, Yggdrasil Transfer Out. Also make sure to deploy the Navich Contract:
Shaheen Vision
There are multiple solutions to this issue:
Context
the-eridanus (Thorchain) confirmed and commented:
