Skip to content

Instantly share code, notes, and snippets.

@stonecoldpat
Created June 24, 2020 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stonecoldpat/933e1f2b37b5bdee7eb3c6fa42d3d4d0 to your computer and use it in GitHub Desktop.
Save stonecoldpat/933e1f2b37b5bdee7eb3c6fa42d3d4d0 to your computer and use it in GitHub Desktop.
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);
}
}
@mohamedhayibor
Copy link

What's the rational behind this contract? Is it a stepping stone to a fully fledged forwarder contract?

@stonecoldpat
Copy link
Author

stonecoldpat commented Jul 8, 2020

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