-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
23 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,9 @@ error LowerThan(uint256 provided, uint256 expected); | |
/// @param amount Token amount. | ||
error TransferFailed(address to, uint256 amount); | ||
|
||
// @dev Reentrancy guard. | ||
error ReentrancyGuard(); | ||
|
||
/// @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]> | ||
|
@@ -74,6 +77,9 @@ contract WormholeRelayer { | |
// L1 Wormhole Relayer address that sends the message across the bridge | ||
address public immutable wormholeRelayer; | ||
|
||
// Reentrancy lock | ||
uint256 internal _locked = 1; | ||
|
||
/// @dev WormholeRelayer constructor. | ||
/// @param _wormholeRelayer Wormhole relayer address. | ||
constructor(address _wormholeRelayer) { | ||
|
@@ -100,7 +106,12 @@ contract WormholeRelayer { | |
uint256 gasLimit, | ||
uint16 refundChain, | ||
address refundAddress | ||
) external payable returns (uint64) { | ||
) external payable returns (uint64 sequence) { | ||
if (_locked > 1) { | ||
revert ReentrancyGuard(); | ||
} | ||
_locked = 2; | ||
|
||
// Check for zero addresses | ||
if (targetAddress == address(0) || refundAddress == address(0)) { | ||
revert ZeroAddress(); | ||
|
@@ -134,7 +145,9 @@ contract WormholeRelayer { | |
} | ||
|
||
// Send payload via the Wormhole relayer with exact required cost | ||
return IWormhole(wormholeRelayer).sendPayloadToEvm{value: cost}(targetChain, targetAddress, payload, | ||
sequence = IWormhole(wormholeRelayer).sendPayloadToEvm{value: cost}(targetChain, targetAddress, payload, | ||
receiverValue, gasLimit, refundChain, refundAddress); | ||
|
||
_locked = 1; | ||
} | ||
} |