Last active
February 2, 2018 07:26
-
-
Save libertylocked/8100ee47f2e24cd62e1a803f6651a4bc to your computer and use it in GitHub Desktop.
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
/** | |
* A multisig wallet leveraging offchain communication channels | |
* to send signatures around that the owners don't have to | |
* pay any gas in the process. Only the recipient pays gas. | |
*/ | |
pragma solidity ^0.4.18; | |
contract Multisig { | |
event LogMoneySent(address to, uint amount); | |
address public alice; | |
address public bob; | |
address public carol; | |
uint public count; | |
/* Constructor */ | |
function Multisig(address _alice, address _bob, address _carol) | |
public | |
{ | |
alice = _alice; | |
bob = _bob; | |
carol = _carol; | |
} | |
function() public payable {} | |
function sendMoney(address to, uint amount, | |
bytes32 rA, bytes32 sA, uint8 vA, | |
bytes32 rB, bytes32 sB, uint8 vB, | |
bytes32 rC, bytes32 sC, uint8 vC) | |
public | |
{ | |
bytes32 message = keccak256(this, to, amount, count); | |
require(recover(message, rA, sA, vA) == alice); | |
require(recover(message, rB, sB, vB) == bob); | |
require(recover(message, rC, sC, vC) == carol); | |
to.transfer(amount); | |
count++; | |
LogMoneySent(to, amount); | |
} | |
function skip() public { | |
require(msg.sender == alice || msg.sender == bob || msg.sender == carol); | |
count++; | |
} | |
/* Constant functions */ | |
function recover(bytes32 message, bytes32 r, bytes32 s, uint8 v) | |
public pure returns (address) | |
{ | |
bytes memory prefix = "\x19Ethereum Signed Message:\n32"; | |
bytes32 prefixedHash = keccak256(prefix, message); | |
return ecrecover(prefixedHash, v, r, s); | |
} | |
function hashPermissionMessage(address to, uint amount) | |
public view returns (bytes32) | |
{ | |
return keccak256(this, to, amount, count); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment