-
Notifications
You must be signed in to change notification settings - Fork 992
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
107 additions
and
112 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,14 @@ pragma solidity 0.4.24; | |
import "./interfaces/ERC20Token.sol"; | ||
import "./GnosisSafe.sol"; | ||
import "./MasterCopy.sol"; | ||
import "./SignatureValidator.sol"; | ||
|
||
|
||
/// @title Gnosis Safe Personal Edition - A multisignature wallet with support for confirmations using signed messages based on ERC191. | ||
/// @author Stefan George - <[email protected]> | ||
/// @author Richard Meissner - <[email protected]> | ||
/// @author Ricardo Guilherme Schmidt - (Status Research & Development GmbH) - Gas Token Payment | ||
contract GnosisSafePersonalEdition is MasterCopy, GnosisSafe { | ||
contract GnosisSafePersonalEdition is MasterCopy, GnosisSafe, SignatureValidator { | ||
|
||
string public constant NAME = "Gnosis Safe Personal Edition"; | ||
string public constant VERSION = "0.0.1"; | ||
|
@@ -17,7 +18,8 @@ contract GnosisSafePersonalEdition is MasterCopy, GnosisSafe { | |
|
||
uint256 public nonce; | ||
|
||
/// @dev Allows to execute a Safe transaction confirmed by required number of owners. | ||
/// @dev Allows to execute a Safe transaction confirmed by required number of owners and then pays the account that submitted the transaction. | ||
/// Note: The fees are always transfered, even if the user transaction fails. | ||
/// @param to Destination address of Safe transaction. | ||
/// @param value Ether value of Safe transaction. | ||
/// @param data Data payload of Safe transaction. | ||
|
@@ -26,10 +28,8 @@ contract GnosisSafePersonalEdition is MasterCopy, GnosisSafe { | |
/// @param dataGas Gas costs for data used to trigger the safe transaction and to pay the payment transfer | ||
/// @param gasPrice Gas price that should be used for the payment calculation. | ||
/// @param gasToken Token address (or 0 if ETH) that is used for the payment. | ||
/// @param v Array of signature V values sorted by owner addresses. | ||
/// @param r Array of signature R values sorted by owner addresses. | ||
/// @param s Array of signature S values sorted by owner addresses. | ||
function execAndPayTransaction( | ||
/// @param signatures Packed signature data ({bytes32 r}{bytes32 s}{uint8 v}) | ||
function execTransactionAndPaySubmitter( | ||
address to, | ||
uint256 value, | ||
bytes data, | ||
|
@@ -38,19 +38,19 @@ contract GnosisSafePersonalEdition is MasterCopy, GnosisSafe { | |
uint256 dataGas, | ||
uint256 gasPrice, | ||
address gasToken, | ||
uint8[] v, | ||
bytes32[] r, | ||
bytes32[] s | ||
bytes signatures | ||
) | ||
public | ||
returns (bool success) | ||
{ | ||
uint256 startGas = gasleft(); | ||
bytes32 txHash = getTransactionHash(to, value, data, operation, safeTxGas, dataGas, gasPrice, gasToken, nonce); | ||
checkHash(txHash, v, r, s); | ||
checkHash(txHash, signatures); | ||
// Increase nonce and execute transaction. | ||
nonce++; | ||
require(gasleft() >= safeTxGas, "Not enough gas to execute safe transaction"); | ||
if (!execute(to, value, data, operation, safeTxGas)) { | ||
success = execute(to, value, data, operation, safeTxGas); | ||
if (!success) { | ||
emit ExecutionFailed(txHash); | ||
} | ||
|
||
|
@@ -73,7 +73,7 @@ contract GnosisSafePersonalEdition is MasterCopy, GnosisSafe { | |
/// 1.) The method can only be called from the safe itself | ||
/// 2.) The response is returned with a revert | ||
/// When estimating set `from` to the address of the safe. | ||
/// Since the `estimateGas` function includes refunds, call this method to get an estimated of the costs that are deducted from the safe with `execAndPayTransaction` | ||
/// Since the `estimateGas` function includes refunds, call this method to get an estimated of the costs that are deducted from the safe with `execTransactionAndPaySubmitter` | ||
/// @param to Destination address of Safe transaction. | ||
/// @param value Ether value of Safe transaction. | ||
/// @param data Data payload of Safe transaction. | ||
|
@@ -92,7 +92,7 @@ contract GnosisSafePersonalEdition is MasterCopy, GnosisSafe { | |
revert(string(abi.encodePacked(requiredGas))); | ||
} | ||
|
||
function checkHash(bytes32 hash, uint8[] v, bytes32[] r, bytes32[] s) | ||
function checkHash(bytes32 txHash, bytes signatures) | ||
internal | ||
view | ||
{ | ||
|
@@ -102,7 +102,7 @@ contract GnosisSafePersonalEdition is MasterCopy, GnosisSafe { | |
uint256 i; | ||
// Validate threshold is reached. | ||
for (i = 0; i < threshold; i++) { | ||
currentOwner = ecrecover(hash, v[i], r[i], s[i]); | ||
currentOwner = recoverKey(txHash, signatures, i); | ||
require(owners[currentOwner] != 0, "Signature not provided by owner"); | ||
require(currentOwner > lastOwner, "Signatures are not ordered by owner address"); | ||
lastOwner = currentOwner; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
pragma solidity 0.4.24; | ||
|
||
|
||
/// @title SignatureValidator - recovers a sender from a signature | ||
/// @author Ricardo Guilherme Schmidt (Status Research & Development GmbH) | ||
/// @author Richard Meissner - <[email protected]> | ||
contract SignatureValidator { | ||
|
||
/// @dev Recovers address who signed the message | ||
/// @param txHash operation ethereum signed message hash | ||
/// @param messageSignature message `txHash` signature | ||
/// @param pos which signature to read | ||
function recoverKey ( | ||
bytes32 txHash, | ||
bytes messageSignature, | ||
uint256 pos | ||
) | ||
pure | ||
public | ||
returns (address) | ||
{ | ||
uint8 v; | ||
bytes32 r; | ||
bytes32 s; | ||
(v, r, s) = signatureSplit(messageSignature, pos); | ||
return ecrecover(txHash, v, r, s); | ||
} | ||
|
||
/// @dev divides bytes signature into `uint8 v, bytes32 r, bytes32 s` | ||
/// @param pos which signature to read | ||
/// @param signatures concatenated rsv signatures | ||
function signatureSplit(bytes signatures, uint256 pos) | ||
pure | ||
public | ||
returns (uint8 v, bytes32 r, bytes32 s) | ||
{ | ||
// The signature format is a compact form of: | ||
// {bytes32 r}{bytes32 s}{uint8 v} | ||
// Compact means, uint8 is not padded to 32 bytes. | ||
// solium-disable-next-line security/no-inline-assembly | ||
assembly { | ||
let signaturePos := mul(0x41, pos) | ||
r := mload(add(signatures, add(signaturePos, 0x20))) | ||
s := mload(add(signatures, add(signaturePos, 0x40))) | ||
// Here we are loading the last 32 bytes, including 31 bytes | ||
// of 's'. There is no 'mload8' to do this. | ||
// | ||
// 'byte' is not working due to the Solidity parser, so lets | ||
// use the second best option, 'and' | ||
v := and(mload(add(signatures, add(signaturePos, 0x41))), 0xff) | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
pragma solidity 0.4.24; | ||
import "../Module.sol"; | ||
import "../OwnerManager.sol"; | ||
import "../SignatureValidator.sol"; | ||
|
||
|
||
/// @title Gnosis Safe State Module - A module that allows interaction with statechannels. | ||
/// @author Stefan George - <[email protected]> | ||
/// @author Richard Meissner - <[email protected]> | ||
contract StateChannelModule is Module { | ||
contract StateChannelModule is Module, SignatureValidator { | ||
|
||
string public constant NAME = "State Channel Module"; | ||
string public constant VERSION = "0.0.1"; | ||
|
@@ -27,30 +28,26 @@ contract StateChannelModule is Module { | |
/// @param data Data payload of Safe transaction. | ||
/// @param operation Operation type of Safe transaction. | ||
/// @param nonce Nonce used for this Safe transaction. | ||
/// @param v Array of signature V values sorted by owner addresses. | ||
/// @param r Array of signature R values sorted by owner addresses. | ||
/// @param s Array of signature S values sorted by owner addresses. | ||
/// @param signatures Packed signature data ({bytes32 r}{bytes32 s}{uint8 v}) | ||
function execTransaction( | ||
address to, | ||
uint256 value, | ||
bytes data, | ||
Enum.Operation operation, | ||
uint256 nonce, | ||
uint8[] v, | ||
bytes32[] r, | ||
bytes32[] s | ||
bytes signatures | ||
) | ||
public | ||
{ | ||
bytes32 transactionHash = getTransactionHash(to, value, data, operation, nonce); | ||
require(isExecuted[transactionHash] == 0, "Transaction already executed"); | ||
checkHash(transactionHash, v, r, s); | ||
checkHash(transactionHash, signatures); | ||
// Mark as executed and execute transaction. | ||
isExecuted[transactionHash] = 1; | ||
require(manager.execTransactionFromModule(to, value, data, operation), "Could not execute transaction"); | ||
} | ||
|
||
function checkHash(bytes32 transactionHash, uint8[] v, bytes32[] r, bytes32[] s) | ||
function checkHash(bytes32 transactionHash, bytes signatures) | ||
internal | ||
view | ||
{ | ||
|
@@ -61,7 +58,7 @@ contract StateChannelModule is Module { | |
uint8 threshold = OwnerManager(manager).getThreshold(); | ||
// Validate threshold is reached. | ||
for (i = 0; i < threshold; i++) { | ||
currentOwner = ecrecover(transactionHash, v[i], r[i], s[i]); | ||
currentOwner = recoverKey(transactionHash, signatures, i); | ||
require(OwnerManager(manager).isOwner(currentOwner), "Signature not provided by owner"); | ||
require(currentOwner > lastOwner, "Signatures are not ordered by owner address"); | ||
lastOwner = currentOwner; | ||
|
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
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
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
942968d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.