Skip to content

Instantly share code, notes, and snippets.

@Arachnid
Last active January 21, 2019 08:56
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 Arachnid/6a5c8ff96869fbdf0736a3a7be91b84e to your computer and use it in GitHub Desktop.
Save Arachnid/6a5c8ff96869fbdf0736a3a7be91b84e to your computer and use it in GitHub Desktop.
// WHATEVER YOU DO, DON'T USE THIS.
// This is a bit of demo code posted to illustrate a principle. It is unaudited,
// probably full of bugs, and definintely not production ready.
// https://twitter.com/nicksdjohnson/status/1041642345467404291
import "./DumbWallet.sol";
contract WalletDelegator {
mapping(address=>uint) public nonces;
function callFor(DumbWallet wallet, address target, uint value, bytes data, bytes32 r, bytes32 s, uint8 v) payable {
bytes32 sigHash = keccak256(abi.encodePacked(wallet, target, value, data, nonces[wallet]));
address signer = ecrecover(sigHash, v, r, s);
require(wallet.authorised(signer));
wallet.invoke.value(msg.value)(target, value, data);
nonces[wallet]++;
}
}
@rmeissner
Copy link

This is not reentrancy safe, right?

@rmeissner
Copy link

I would call nonces[wallet]++; right after generating sigHash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment