From d5d6079b673d0a6d311f349dba291da18c846d9e Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Thu, 1 Feb 2018 15:48:06 -0800 Subject: Rename directories --- .../multisig/MultiSigWallet/MultiSigWallet.sol | 366 +++++++++++++++++++++ .../MultiSigWalletWithTimeLock.sol | 132 ++++++++ ...etWithTimeLockExceptRemoveAuthorizedAddress.sol | 82 +++++ 3 files changed, 580 insertions(+) create mode 100644 packages/contracts/src/current/multisig/MultiSigWallet/MultiSigWallet.sol create mode 100644 packages/contracts/src/current/multisig/MultiSigWalletWithTimeLock/MultiSigWalletWithTimeLock.sol create mode 100644 packages/contracts/src/current/multisig/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.sol (limited to 'packages/contracts/src/current/multisig') diff --git a/packages/contracts/src/current/multisig/MultiSigWallet/MultiSigWallet.sol b/packages/contracts/src/current/multisig/MultiSigWallet/MultiSigWallet.sol new file mode 100644 index 000000000..ae7ef06fd --- /dev/null +++ b/packages/contracts/src/current/multisig/MultiSigWallet/MultiSigWallet.sol @@ -0,0 +1,366 @@ +pragma solidity ^0.4.11; + +/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution. +/// @author Stefan George - +contract MultiSigWallet { + + uint constant public MAX_OWNER_COUNT = 50; + + event Confirmation(address indexed sender, uint indexed transactionId); + event Revocation(address indexed sender, uint indexed transactionId); + event Submission(uint indexed transactionId); + event Execution(uint indexed transactionId); + event ExecutionFailure(uint indexed transactionId); + event Deposit(address indexed sender, uint value); + event OwnerAddition(address indexed owner); + event OwnerRemoval(address indexed owner); + event RequirementChange(uint required); + + mapping (uint => Transaction) public transactions; + mapping (uint => mapping (address => bool)) public confirmations; + mapping (address => bool) public isOwner; + address[] public owners; + uint public required; + uint public transactionCount; + + struct Transaction { + address destination; + uint value; + bytes data; + bool executed; + } + + modifier onlyWallet() { + if (msg.sender != address(this)) + throw; + _; + } + + modifier ownerDoesNotExist(address owner) { + if (isOwner[owner]) + throw; + _; + } + + modifier ownerExists(address owner) { + if (!isOwner[owner]) + throw; + _; + } + + modifier transactionExists(uint transactionId) { + if (transactions[transactionId].destination == 0) + throw; + _; + } + + modifier confirmed(uint transactionId, address owner) { + if (!confirmations[transactionId][owner]) + throw; + _; + } + + modifier notConfirmed(uint transactionId, address owner) { + if (confirmations[transactionId][owner]) + throw; + _; + } + + modifier notExecuted(uint transactionId) { + if (transactions[transactionId].executed) + throw; + _; + } + + modifier notNull(address _address) { + if (_address == 0) + throw; + _; + } + + modifier validRequirement(uint ownerCount, uint _required) { + if ( ownerCount > MAX_OWNER_COUNT + || _required > ownerCount + || _required == 0 + || ownerCount == 0) + throw; + _; + } + + /// @dev Fallback function allows to deposit ether. + function() + payable + { + if (msg.value > 0) + Deposit(msg.sender, msg.value); + } + + /* + * Public functions + */ + /// @dev Contract constructor sets initial owners and required number of confirmations. + /// @param _owners List of initial owners. + /// @param _required Number of required confirmations. + function MultiSigWallet(address[] _owners, uint _required) + public + validRequirement(_owners.length, _required) + { + for (uint i=0; i<_owners.length; i++) { + if (isOwner[_owners[i]] || _owners[i] == 0) + throw; + isOwner[_owners[i]] = true; + } + owners = _owners; + required = _required; + } + + /// @dev Allows to add a new owner. Transaction has to be sent by wallet. + /// @param owner Address of new owner. + function addOwner(address owner) + public + onlyWallet + ownerDoesNotExist(owner) + notNull(owner) + validRequirement(owners.length + 1, required) + { + isOwner[owner] = true; + owners.push(owner); + OwnerAddition(owner); + } + + /// @dev Allows to remove an owner. Transaction has to be sent by wallet. + /// @param owner Address of owner. + function removeOwner(address owner) + public + onlyWallet + ownerExists(owner) + { + isOwner[owner] = false; + for (uint i=0; i owners.length) + changeRequirement(owners.length); + OwnerRemoval(owner); + } + + /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. + /// @param owner Address of owner to be replaced. + /// @param owner Address of new owner. + function replaceOwner(address owner, address newOwner) + public + onlyWallet + ownerExists(owner) + ownerDoesNotExist(newOwner) + { + for (uint i=0; i +contract MultiSigWalletWithTimeLock is MultiSigWallet { + + event ConfirmationTimeSet(uint indexed transactionId, uint confirmationTime); + event TimeLockChange(uint secondsTimeLocked); + + uint public secondsTimeLocked; + + mapping (uint => uint) public confirmationTimes; + + modifier notFullyConfirmed(uint transactionId) { + require(!isConfirmed(transactionId)); + _; + } + + modifier fullyConfirmed(uint transactionId) { + require(isConfirmed(transactionId)); + _; + } + + modifier pastTimeLock(uint transactionId) { + require(block.timestamp >= confirmationTimes[transactionId] + secondsTimeLocked); + _; + } + + /* + * Public functions + */ + + /// @dev Contract constructor sets initial owners, required number of confirmations, and time lock. + /// @param _owners List of initial owners. + /// @param _required Number of required confirmations. + /// @param _secondsTimeLocked Duration needed after a transaction is confirmed and before it becomes executable, in seconds. + function MultiSigWalletWithTimeLock(address[] _owners, uint _required, uint _secondsTimeLocked) + public + MultiSigWallet(_owners, _required) + { + secondsTimeLocked = _secondsTimeLocked; + } + + /// @dev Changes the duration of the time lock for transactions. + /// @param _secondsTimeLocked Duration needed after a transaction is confirmed and before it becomes executable, in seconds. + function changeTimeLock(uint _secondsTimeLocked) + public + onlyWallet + { + secondsTimeLocked = _secondsTimeLocked; + TimeLockChange(_secondsTimeLocked); + } + + /// @dev Allows an owner to confirm a transaction. + /// @param transactionId Transaction ID. + function confirmTransaction(uint transactionId) + public + ownerExists(msg.sender) + transactionExists(transactionId) + notConfirmed(transactionId, msg.sender) + notFullyConfirmed(transactionId) + { + confirmations[transactionId][msg.sender] = true; + Confirmation(msg.sender, transactionId); + if (isConfirmed(transactionId)) { + setConfirmationTime(transactionId, block.timestamp); + } + } + + /// @dev Allows an owner to revoke a confirmation for a transaction. + /// @param transactionId Transaction ID. + function revokeConfirmation(uint transactionId) + public + ownerExists(msg.sender) + confirmed(transactionId, msg.sender) + notExecuted(transactionId) + notFullyConfirmed(transactionId) + { + confirmations[transactionId][msg.sender] = false; + Revocation(msg.sender, transactionId); + } + + /// @dev Allows anyone to execute a confirmed transaction. + /// @param transactionId Transaction ID. + function executeTransaction(uint transactionId) + public + notExecuted(transactionId) + fullyConfirmed(transactionId) + pastTimeLock(transactionId) + { + Transaction storage tx = transactions[transactionId]; + tx.executed = true; + if (tx.destination.call.value(tx.value)(tx.data)) + Execution(transactionId); + else { + ExecutionFailure(transactionId); + tx.executed = false; + } + } + + /* + * Internal functions + */ + + /// @dev Sets the time of when a submission first passed. + function setConfirmationTime(uint transactionId, uint confirmationTime) + internal + { + confirmationTimes[transactionId] = confirmationTime; + ConfirmationTimeSet(transactionId, confirmationTime); + } +} diff --git a/packages/contracts/src/current/multisig/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.sol b/packages/contracts/src/current/multisig/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.sol new file mode 100644 index 000000000..8cc8372c1 --- /dev/null +++ b/packages/contracts/src/current/multisig/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.sol @@ -0,0 +1,82 @@ +/* + + Copyright 2017 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.4.11; + +import { MultiSigWalletWithTimeLock } from "../MultiSigWalletWithTimeLock/MultiSigWalletWithTimeLock.sol"; + +contract MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress is MultiSigWalletWithTimeLock { + + address public TOKEN_TRANSFER_PROXY_CONTRACT; + + modifier validRemoveAuthorizedAddressTx(uint transactionId) { + Transaction storage tx = transactions[transactionId]; + require(tx.destination == TOKEN_TRANSFER_PROXY_CONTRACT); + require(isFunctionRemoveAuthorizedAddress(tx.data)); + _; + } + + /// @dev Contract constructor sets initial owners, required number of confirmations, time lock, and tokenTransferProxy address. + /// @param _owners List of initial owners. + /// @param _required Number of required confirmations. + /// @param _secondsTimeLocked Duration needed after a transaction is confirmed and before it becomes executable, in seconds. + /// @param _tokenTransferProxy Address of TokenTransferProxy contract. + function MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress( + address[] _owners, + uint _required, + uint _secondsTimeLocked, + address _tokenTransferProxy) + public + MultiSigWalletWithTimeLock(_owners, _required, _secondsTimeLocked) + { + TOKEN_TRANSFER_PROXY_CONTRACT = _tokenTransferProxy; + } + + /// @dev Allows execution of removeAuthorizedAddress without time lock. + /// @param transactionId Transaction ID. + function executeRemoveAuthorizedAddress(uint transactionId) + public + notExecuted(transactionId) + fullyConfirmed(transactionId) + validRemoveAuthorizedAddressTx(transactionId) + { + Transaction storage tx = transactions[transactionId]; + tx.executed = true; + if (tx.destination.call.value(tx.value)(tx.data)) + Execution(transactionId); + else { + ExecutionFailure(transactionId); + tx.executed = false; + } + } + + /// @dev Compares first 4 bytes of byte array to removeAuthorizedAddress function signature. + /// @param data Transaction data. + /// @return Successful if data is a call to removeAuthorizedAddress. + function isFunctionRemoveAuthorizedAddress(bytes data) + public + constant + returns (bool) + { + bytes4 removeAuthorizedAddressSignature = bytes4(sha3("removeAuthorizedAddress(address)")); + for (uint i = 0; i < 4; i++) { + require(data[i] == removeAuthorizedAddressSignature[i]); + } + return true; + } +} -- cgit v1.2.3 From 05aae368132a81ddb9fd6a04ac5b0ff1cbb24691 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Thu, 1 Feb 2018 18:43:04 -0800 Subject: Update contract versions, fix tests --- .../contracts/src/current/multisig/MultiSigWallet/MultiSigWallet.sol | 2 +- .../multisig/MultiSigWalletWithTimeLock/MultiSigWalletWithTimeLock.sol | 2 +- .../MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.sol | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/contracts/src/current/multisig') diff --git a/packages/contracts/src/current/multisig/MultiSigWallet/MultiSigWallet.sol b/packages/contracts/src/current/multisig/MultiSigWallet/MultiSigWallet.sol index ae7ef06fd..997bb86c0 100644 --- a/packages/contracts/src/current/multisig/MultiSigWallet/MultiSigWallet.sol +++ b/packages/contracts/src/current/multisig/MultiSigWallet/MultiSigWallet.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.11; +pragma solidity ^0.4.10; /// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution. /// @author Stefan George - diff --git a/packages/contracts/src/current/multisig/MultiSigWalletWithTimeLock/MultiSigWalletWithTimeLock.sol b/packages/contracts/src/current/multisig/MultiSigWalletWithTimeLock/MultiSigWalletWithTimeLock.sol index 46c152035..a545d9813 100644 --- a/packages/contracts/src/current/multisig/MultiSigWalletWithTimeLock/MultiSigWalletWithTimeLock.sol +++ b/packages/contracts/src/current/multisig/MultiSigWalletWithTimeLock/MultiSigWalletWithTimeLock.sol @@ -16,7 +16,7 @@ */ -pragma solidity ^0.4.11; +pragma solidity ^0.4.10; import { MultiSigWallet } from "../MultiSigWallet/MultiSigWallet.sol"; diff --git a/packages/contracts/src/current/multisig/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.sol b/packages/contracts/src/current/multisig/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.sol index 8cc8372c1..3c6a3d2ef 100644 --- a/packages/contracts/src/current/multisig/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.sol +++ b/packages/contracts/src/current/multisig/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.sol @@ -16,7 +16,7 @@ */ -pragma solidity ^0.4.11; +pragma solidity ^0.4.10; import { MultiSigWalletWithTimeLock } from "../MultiSigWalletWithTimeLock/MultiSigWalletWithTimeLock.sol"; -- cgit v1.2.3