Skip to content

Commit

Permalink
fix the SimpleForwarder by simplifying it
Browse files Browse the repository at this point in the history
  • Loading branch information
d10r committed Dec 17, 2024
1 parent 9a9589b commit 0cfcf0b
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions packages/ethereum-contracts/contracts/utils/SimpleForwarder.sol
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";

/**
* @title Forwards arbitrary calls
* @dev The purpose of this contract is to let accounts forward arbitrary calls,
* without themselves being the msg.sender from the perspective of the call target.
* This is necessary for security reasons if the calling account has privileged access anywhere.
*/
contract SimpleForwarder is Ownable {
contract SimpleForwarder {
/**
* @dev Forwards a call for which msg.sender doesn't matter
* @param target The target contract to call
* @param data The call data
* Note: restricted to `onlyOwner` in order to minimize attack surface
* If forwarded native tokens aren't "consumed" by the target, they are sent back to the caller.
* This will make the transaction revert if neither the target nor the caller take them.
*/
function forwardCall(address target, bytes calldata data)
external payable onlyOwner
external payable
returns (bool success, bytes memory returnData)
{
// solhint-disable-next-line avoid-low-level-calls
(success, returnData) = target.call{value: msg.value}(data);
}

/**
* @dev Allows to withdraw native tokens (ETH) which got stuck in this contract.
* This could happen if a call fails, but the caller doesn't revert the tx.
*/
function withdrawLostNativeTokens(address payable receiver) external onlyOwner {
receiver.transfer(address(this).balance);
if (address(this).balance != 0) {
msg.sender.transfer(address(this).balance);
}
}
}

0 comments on commit 0cfcf0b

Please sign in to comment.