From 7d3b60396e62a7888a9a8172f384c23078db966c Mon Sep 17 00:00:00 2001 From: Aleksandr Kuperman Date: Thu, 7 Nov 2024 06:06:13 +0000 Subject: [PATCH] refactor: transfer fail revert --- contracts/bridges/WormholeRelayer.sol | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/contracts/bridges/WormholeRelayer.sol b/contracts/bridges/WormholeRelayer.sol index 2cbc60a..0fc7e42 100644 --- a/contracts/bridges/WormholeRelayer.sol +++ b/contracts/bridges/WormholeRelayer.sol @@ -60,6 +60,11 @@ error ZeroValue(); /// @param expected Expected value. error LowerThan(uint256 provided, uint256 expected); +/// @dev Failure of a native token transfer. +/// @param to Address `to`. +/// @param amount Token amount. +error TransferFailed(address to, uint256 amount); + /// @title WormholeRelayer - Smart contract for the contract interaction with wormhole relayer with any msg.value /// @author Aleksandr Kuperman - /// @author Andrey Lebedev - @@ -119,9 +124,11 @@ contract WormholeRelayer { // Send leftover amount back to the sender, if any if (leftovers > 0) { - // If the call fails, ignore to avoid the attack that would prevent this function from executing // solhint-disable-next-line avoid-low-level-calls - tx.origin.call{value: leftovers}(""); + (bool success, ) = tx.origin.call{value: leftovers}(""); + if (!success) { + revert TransferFailed(tx.origin, leftovers); + } emit LeftoversRefunded(tx.origin, leftovers); }