Created
June 24, 2020 12:10
-
-
Save stonecoldpat/933e1f2b37b5bdee7eb3c6fa42d3d4d0 to your computer and use it in GitHub Desktop.
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
pragma solidity ^0.6.2; | |
pragma experimental ABIEncoderV2; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/cryptography/ECDSA.sol"; | |
contract SimpleWallet { | |
mapping(bytes32 => bool) public prevCalls; // Guarantee one-time use | |
address public owner; | |
event Forward(bytes32 txHash, bool success); | |
constructor(address _owner) public { | |
owner = _owner; | |
} | |
function forward(address _to, bytes memory _data, uint _nonce, bytes memory _signature) public { | |
bytes32 h = keccak256(abi.encode(_to, _data, _nonce, address(this))); // add chainid | |
address signer = ECDSA.recover(ECDSA.toEthSignedMessageHash(h), _signature); | |
require(signer == owner, "Only the owner, SGX enclave, can authorise calls."); | |
require(!prevCalls[h], "Message was already sent"); | |
prevCalls[h] = true; // Store to prevent future use | |
(bool success,) = _to.call(abi.encodePacked(_data)); | |
emit Forward(h, success); | |
} | |
} |
Its just an extremely simple forwarder / wallet contract. minimal gas, storage, supports concurrent transactions, etc. if a new function that used delegatecall() was added & it was updated to send value, then it is essentially a fully fledged forwarder contract.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's the rational behind this contract? Is it a stepping stone to a fully fledged
forwarder
contract?