Skip to content

Commit

Permalink
feat: reentrancy lock
Browse files Browse the repository at this point in the history
  • Loading branch information
kupermind committed Nov 7, 2024
1 parent 42efdea commit 277d860
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
11 changes: 8 additions & 3 deletions abis/0.8.28/WormholeRelayer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"name": "LowerThan",
"type": "error"
},
{
"inputs": [],
"name": "ReentrancyGuard",
"type": "error"
},
{
"inputs": [
{
Expand Down Expand Up @@ -117,7 +122,7 @@
"outputs": [
{
"internalType": "uint64",
"name": "",
"name": "sequence",
"type": "uint64"
}
],
Expand All @@ -138,8 +143,8 @@
"type": "function"
}
],
"bytecode": "0x60a0604052348015600e575f5ffd5b506040516107de3803806107de833981016040819052602b91603b565b6001600160a01b03166080526066565b5f60208284031215604a575f5ffd5b81516001600160a01b0381168114605f575f5ffd5b9392505050565b60805161075361008b5f395f8181606e015281816101c3015261039a01526107535ff3fe608060405260043610610028575f3560e01c80634b5ca6f41461002c578063da25b7251461005d575b5f5ffd5b61003f61003a366004610492565b6100b5565b60405167ffffffffffffffff90911681526020015b60405180910390f35b348015610068575f5ffd5b506100907f000000000000000000000000000000000000000000000000000000000000000081565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610054565b5f73ffffffffffffffffffffffffffffffffffffffff871615806100ed575073ffffffffffffffffffffffffffffffffffffffff8216155b15610124576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61ffff8816158061013457508551155b8061013d575083155b8061014a575061ffff8316155b15610181576040517f7c946ed700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517fc23ee3c300000000000000000000000000000000000000000000000000000000815261ffff8916600482015260248101869052604481018590525f907f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff169063c23ee3c3906064016040805180830381865afa15801561021c573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061024091906105d5565b5090503481111561028b576040517f491a2bb1000000000000000000000000000000000000000000000000000000008152346004820152602481018290526044015b60405180910390fd5b5f61029682346105f7565b9050801561035d576040515f90329083908381818185875af1925050503d805f81146102dd576040519150601f19603f3d011682016040523d82523d5f602084013e6102e2565b606091505b5050905080610326576040517f1c43b97600000000000000000000000000000000000000000000000000000000815232600482015260248101839052604401610282565b60405182815232907f8e49ed3e274fbea1556bdfaa9a37a0c28445bfe26d57beaf9f04fd517aa417419060200160405180910390a2505b6040517f4b5ca6f400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001690634b5ca6f49084906103dd908e908e908e908e908e908e908e90600401610635565b60206040518083038185885af11580156103f9573d5f5f3e3d5ffd5b50505050506040513d601f19601f8201168201806040525081019061041e91906106ef565b9a9950505050505050505050565b803561ffff8116811461043d575f5ffd5b919050565b803573ffffffffffffffffffffffffffffffffffffffff8116811461043d575f5ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f5f5f5f5f5f5f60e0888a0312156104a8575f5ffd5b6104b18861042c565b96506104bf60208901610442565b9550604088013567ffffffffffffffff8111156104da575f5ffd5b8801601f81018a136104ea575f5ffd5b803567ffffffffffffffff81111561050457610504610465565b6040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8501160116810181811067ffffffffffffffff8211171561057057610570610465565b6040528181528282016020018c1015610587575f5ffd5b816020840160208301375f9181016020019190915295505060608801359350608088013592506105b960a0890161042c565b91506105c760c08901610442565b905092959891949750929550565b5f5f604083850312156105e6575f5ffd5b505080516020909101519092909150565b8181038181111561062f577f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b92915050565b61ffff8816815273ffffffffffffffffffffffffffffffffffffffff8716602082015260e060408201525f86518060e0840152806020890161010085015e5f61010082850101526101007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f83011684010191505085606083015284608083015261ffff841660a08301526106e360c083018473ffffffffffffffffffffffffffffffffffffffff169052565b98975050505050505050565b5f602082840312156106ff575f5ffd5b815167ffffffffffffffff81168114610716575f5ffd5b939250505056fea2646970667358221220cdf4554f73cef611853522433444fb87bce53dfabf2ccaa91c92000d670204da64736f6c634300081c0033",
"deployedBytecode": "0x608060405260043610610028575f3560e01c80634b5ca6f41461002c578063da25b7251461005d575b5f5ffd5b61003f61003a366004610492565b6100b5565b60405167ffffffffffffffff90911681526020015b60405180910390f35b348015610068575f5ffd5b506100907f000000000000000000000000000000000000000000000000000000000000000081565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610054565b5f73ffffffffffffffffffffffffffffffffffffffff871615806100ed575073ffffffffffffffffffffffffffffffffffffffff8216155b15610124576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61ffff8816158061013457508551155b8061013d575083155b8061014a575061ffff8316155b15610181576040517f7c946ed700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517fc23ee3c300000000000000000000000000000000000000000000000000000000815261ffff8916600482015260248101869052604481018590525f907f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff169063c23ee3c3906064016040805180830381865afa15801561021c573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061024091906105d5565b5090503481111561028b576040517f491a2bb1000000000000000000000000000000000000000000000000000000008152346004820152602481018290526044015b60405180910390fd5b5f61029682346105f7565b9050801561035d576040515f90329083908381818185875af1925050503d805f81146102dd576040519150601f19603f3d011682016040523d82523d5f602084013e6102e2565b606091505b5050905080610326576040517f1c43b97600000000000000000000000000000000000000000000000000000000815232600482015260248101839052604401610282565b60405182815232907f8e49ed3e274fbea1556bdfaa9a37a0c28445bfe26d57beaf9f04fd517aa417419060200160405180910390a2505b6040517f4b5ca6f400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001690634b5ca6f49084906103dd908e908e908e908e908e908e908e90600401610635565b60206040518083038185885af11580156103f9573d5f5f3e3d5ffd5b50505050506040513d601f19601f8201168201806040525081019061041e91906106ef565b9a9950505050505050505050565b803561ffff8116811461043d575f5ffd5b919050565b803573ffffffffffffffffffffffffffffffffffffffff8116811461043d575f5ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f5f5f5f5f5f5f60e0888a0312156104a8575f5ffd5b6104b18861042c565b96506104bf60208901610442565b9550604088013567ffffffffffffffff8111156104da575f5ffd5b8801601f81018a136104ea575f5ffd5b803567ffffffffffffffff81111561050457610504610465565b6040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8501160116810181811067ffffffffffffffff8211171561057057610570610465565b6040528181528282016020018c1015610587575f5ffd5b816020840160208301375f9181016020019190915295505060608801359350608088013592506105b960a0890161042c565b91506105c760c08901610442565b905092959891949750929550565b5f5f604083850312156105e6575f5ffd5b505080516020909101519092909150565b8181038181111561062f577f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b92915050565b61ffff8816815273ffffffffffffffffffffffffffffffffffffffff8716602082015260e060408201525f86518060e0840152806020890161010085015e5f61010082850101526101007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f83011684010191505085606083015284608083015261ffff841660a08301526106e360c083018473ffffffffffffffffffffffffffffffffffffffff169052565b98975050505050505050565b5f602082840312156106ff575f5ffd5b815167ffffffffffffffff81168114610716575f5ffd5b939250505056fea2646970667358221220cdf4554f73cef611853522433444fb87bce53dfabf2ccaa91c92000d670204da64736f6c634300081c0033",
"bytecode": "0x60a060405260015f553480156012575f5ffd5b50604051610826380380610826833981016040819052602f91603f565b6001600160a01b0316608052606a565b5f60208284031215604e575f5ffd5b81516001600160a01b03811681146063575f5ffd5b9392505050565b60805161079761008f5f395f8181606e0152818161020301526103da01526107975ff3fe608060405260043610610028575f3560e01c80634b5ca6f41461002c578063da25b7251461005d575b5f5ffd5b61003f61003a3660046104d6565b6100b5565b60405167ffffffffffffffff90911681526020015b60405180910390f35b348015610068575f5ffd5b506100907f000000000000000000000000000000000000000000000000000000000000000081565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610054565b5f60015f5411156100f2576040517f8beb9d1600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60025f5573ffffffffffffffffffffffffffffffffffffffff8716158061012d575073ffffffffffffffffffffffffffffffffffffffff8216155b15610164576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61ffff8816158061017457508551155b8061017d575083155b8061018a575061ffff8316155b156101c1576040517f7c946ed700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517fc23ee3c300000000000000000000000000000000000000000000000000000000815261ffff8916600482015260248101869052604481018590525f907f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff169063c23ee3c3906064016040805180830381865afa15801561025c573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906102809190610619565b509050348111156102cb576040517f491a2bb1000000000000000000000000000000000000000000000000000000008152346004820152602481018290526044015b60405180910390fd5b5f6102d6823461063b565b9050801561039d576040515f90329083908381818185875af1925050503d805f811461031d576040519150601f19603f3d011682016040523d82523d5f602084013e610322565b606091505b5050905080610366576040517f1c43b976000000000000000000000000000000000000000000000000000000008152326004820152602481018390526044016102c2565b60405182815232907f8e49ed3e274fbea1556bdfaa9a37a0c28445bfe26d57beaf9f04fd517aa417419060200160405180910390a2505b6040517f4b5ca6f400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001690634b5ca6f490849061041d908e908e908e908e908e908e908e90600401610679565b60206040518083038185885af1158015610439573d5f5f3e3d5ffd5b50505050506040513d601f19601f8201168201806040525081019061045e9190610733565b60015f559a9950505050505050505050565b803561ffff81168114610481575f5ffd5b919050565b803573ffffffffffffffffffffffffffffffffffffffff81168114610481575f5ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f5f5f5f5f5f5f60e0888a0312156104ec575f5ffd5b6104f588610470565b965061050360208901610486565b9550604088013567ffffffffffffffff81111561051e575f5ffd5b8801601f81018a1361052e575f5ffd5b803567ffffffffffffffff811115610548576105486104a9565b6040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8501160116810181811067ffffffffffffffff821117156105b4576105b46104a9565b6040528181528282016020018c10156105cb575f5ffd5b816020840160208301375f9181016020019190915295505060608801359350608088013592506105fd60a08901610470565b915061060b60c08901610486565b905092959891949750929550565b5f5f6040838503121561062a575f5ffd5b505080516020909101519092909150565b81810381811115610673577f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b92915050565b61ffff8816815273ffffffffffffffffffffffffffffffffffffffff8716602082015260e060408201525f86518060e0840152806020890161010085015e5f61010082850101526101007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f83011684010191505085606083015284608083015261ffff841660a083015261072760c083018473ffffffffffffffffffffffffffffffffffffffff169052565b98975050505050505050565b5f60208284031215610743575f5ffd5b815167ffffffffffffffff8116811461075a575f5ffd5b939250505056fea2646970667358221220d6e1a3d1fe201bf16c4ed18bd81b481ca79ca4c0d03f37ce9852bc9ae063de3d64736f6c634300081c0033",
"deployedBytecode": "0x608060405260043610610028575f3560e01c80634b5ca6f41461002c578063da25b7251461005d575b5f5ffd5b61003f61003a3660046104d6565b6100b5565b60405167ffffffffffffffff90911681526020015b60405180910390f35b348015610068575f5ffd5b506100907f000000000000000000000000000000000000000000000000000000000000000081565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610054565b5f60015f5411156100f2576040517f8beb9d1600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60025f5573ffffffffffffffffffffffffffffffffffffffff8716158061012d575073ffffffffffffffffffffffffffffffffffffffff8216155b15610164576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61ffff8816158061017457508551155b8061017d575083155b8061018a575061ffff8316155b156101c1576040517f7c946ed700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517fc23ee3c300000000000000000000000000000000000000000000000000000000815261ffff8916600482015260248101869052604481018590525f907f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff169063c23ee3c3906064016040805180830381865afa15801561025c573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906102809190610619565b509050348111156102cb576040517f491a2bb1000000000000000000000000000000000000000000000000000000008152346004820152602481018290526044015b60405180910390fd5b5f6102d6823461063b565b9050801561039d576040515f90329083908381818185875af1925050503d805f811461031d576040519150601f19603f3d011682016040523d82523d5f602084013e610322565b606091505b5050905080610366576040517f1c43b976000000000000000000000000000000000000000000000000000000008152326004820152602481018390526044016102c2565b60405182815232907f8e49ed3e274fbea1556bdfaa9a37a0c28445bfe26d57beaf9f04fd517aa417419060200160405180910390a2505b6040517f4b5ca6f400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001690634b5ca6f490849061041d908e908e908e908e908e908e908e90600401610679565b60206040518083038185885af1158015610439573d5f5f3e3d5ffd5b50505050506040513d601f19601f8201168201806040525081019061045e9190610733565b60015f559a9950505050505050505050565b803561ffff81168114610481575f5ffd5b919050565b803573ffffffffffffffffffffffffffffffffffffffff81168114610481575f5ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f5f5f5f5f5f5f60e0888a0312156104ec575f5ffd5b6104f588610470565b965061050360208901610486565b9550604088013567ffffffffffffffff81111561051e575f5ffd5b8801601f81018a1361052e575f5ffd5b803567ffffffffffffffff811115610548576105486104a9565b6040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8501160116810181811067ffffffffffffffff821117156105b4576105b46104a9565b6040528181528282016020018c10156105cb575f5ffd5b816020840160208301375f9181016020019190915295505060608801359350608088013592506105fd60a08901610470565b915061060b60c08901610486565b905092959891949750929550565b5f5f6040838503121561062a575f5ffd5b505080516020909101519092909150565b81810381811115610673577f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b92915050565b61ffff8816815273ffffffffffffffffffffffffffffffffffffffff8716602082015260e060408201525f86518060e0840152806020890161010085015e5f61010082850101526101007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f83011684010191505085606083015284608083015261ffff841660a083015261072760c083018473ffffffffffffffffffffffffffffffffffffffff169052565b98975050505050505050565b5f60208284031215610743575f5ffd5b815167ffffffffffffffff8116811461075a575f5ffd5b939250505056fea2646970667358221220d6e1a3d1fe201bf16c4ed18bd81b481ca79ca4c0d03f37ce9852bc9ae063de3d64736f6c634300081c0033",
"linkReferences": {},
"deployedLinkReferences": {}
}
17 changes: 15 additions & 2 deletions contracts/bridges/WormholeRelayer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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]>
Expand All @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 277d860

Please sign in to comment.