Skip to content

Commit

Permalink
refactor: transfer fail revert
Browse files Browse the repository at this point in the history
  • Loading branch information
kupermind committed Nov 7, 2024
1 parent abb5c88 commit 7d3b603
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions contracts/bridges/WormholeRelayer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 - <[email protected]>
/// @author Andrey Lebedev - <[email protected]>
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 7d3b603

Please sign in to comment.