Created
January 29, 2019 18:01
-
-
Save crazyrabbitLTC/2c48a5b449ca3404475b79a46b6ec415 to your computer and use it in GitHub Desktop.
MultiSig contract for executing arbitrary functions.
This file contains hidden or 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.4.24; | |
| //Source: https://programtheblockchain.com/posts/2018/08/02/contracts-calling-arbitrary-functions/ | |
| contract MultisigExecute { | |
| uint256 public nonce; // (only) mutable state | |
| address[] public owners; // immutable state | |
| constructor(address[] owners_) { | |
| owners = owners_; | |
| } | |
| function execute( | |
| address destination, | |
| uint256 value, | |
| bytes data, | |
| bytes32[] sigR, | |
| bytes32[] sigS, | |
| uint8[] sigV | |
| ) | |
| external | |
| { | |
| bytes32 hash = prefixed(keccak256(abi.encodePacked( | |
| address(this), destination, value, data, nonce | |
| ))); | |
| for (uint256 i = 0; i < owners.length; i++) { | |
| address recovered = ecrecover(hash, sigV[i], sigR[i], sigS[i]); | |
| require(recovered == owners[i]); | |
| } | |
| // If we make it here, all signatures are accounted for. | |
| nonce += 1; | |
| require(destination.call.value(value)(data)); | |
| } | |
| function () payable {} | |
| // Builds a prefixed hash to mimic the behavior of eth_sign. | |
| function prefixed(bytes32 hash) internal pure returns (bytes32) { | |
| return keccak256(abi.encodePacked( | |
| "\x19Ethereum Signed Message:\n32", hash)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment