From aecd344d58830c3a7b0d877604c18181122d7f06 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Wed, 8 Nov 2017 17:36:15 -0200 Subject: [PATCH 01/16] fixed heritance --- contracts/MultiSigTokenWallet.sol | 350 +-------------------------- contracts/MultiSigWallet.sol | 378 ++++++++++++++++++++++++++++++ 2 files changed, 380 insertions(+), 348 deletions(-) create mode 100644 contracts/MultiSigWallet.sol diff --git a/contracts/MultiSigTokenWallet.sol b/contracts/MultiSigTokenWallet.sol index d1f12f9..bd1fedc 100644 --- a/contracts/MultiSigTokenWallet.sol +++ b/contracts/MultiSigTokenWallet.sol @@ -1,114 +1,21 @@ pragma solidity ^0.4.15; +import "./MultiSigWallet.sol"; import "./ERC20.sol"; -contract MultiSigTokenWallet { +contract MultiSigTokenWallet is MultiSigWallet { - address[] public owners; address[] public tokens; - mapping (uint => Transaction) public transactions; - mapping (uint => mapping (address => bool)) public confirmations; - uint public transactionCount; - mapping (address => uint) public tokenBalances; - mapping (address => bool) public isOwner; mapping (address => address[]) public userList; - uint public required; uint public nonce; - struct Transaction { - address destination; - uint value; - bytes data; - bool executed; - } - - 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 TokenDeposit(address _token, address indexed _sender, uint _value); - event OwnerAddition(address indexed _owner); - event OwnerRemoval(address indexed _owner); - event RequirementChange(uint _required); - - modifier onlyWallet() { - require (msg.sender == address(this)); - _; - } - - modifier ownerDoesNotExist(address owner) { - require (!isOwner[owner]); - _; - } - - modifier ownerExists(address owner) { - require (isOwner[owner]); - _; - } - - modifier transactionExists(uint transactionId) { - require (transactions[transactionId].destination != 0); - _; - } - - modifier confirmed(uint transactionId, address owner) { - require (confirmations[transactionId][owner]); - _; - } - - modifier notConfirmed(uint transactionId, address owner) { - require(!confirmations[transactionId][owner]); - _; - } - - modifier notExecuted(uint transactionId) { - require (!transactions[transactionId].executed); - _; - } - - modifier notNull(address _address) { - require (_address != 0); - _; - } - - modifier validRequirement(uint ownerCount, uint _required) { - require (ownerCount <= MAX_OWNER_COUNT && _required <= ownerCount && _required != 0 && ownerCount != 0); - _; - } - - /// @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 constructor(address[] _owners, uint _required) - public - validRequirement(_owners.length, _required) - { - require(owners.length == 0 && required == 0); - for (uint i = 0; i < _owners.length; i++) { - require(!isOwner[_owners[i]] && _owners[i] != 0); - isOwner[_owners[i]] = true; - } - owners = _owners; - required = _required; - } - /** * @notice deposit a ERC20 token. The amount of deposit is the allowance set to this contract. * @param _token the token contract address @@ -188,63 +95,6 @@ contract MultiSigTokenWallet { deposit(_from, _amount, _token, _data); } - - /// @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; - uint _len = owners.length - 1; - for (uint i = 0; i < _len; i++) { - if (owners[i] == owner) { - owners[i] = owners[owners.length - 1]; - break; - } - } - owners.length -= 1; - if (required > 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 < owners.length; i++) { - if (owners[i] == owner) { - owners[i] = newOwner; - break; - } - } - isOwner[owner] = false; - isOwner[newOwner] = true; - OwnerRemoval(owner); - OwnerAddition(newOwner); - } - /** * @dev gives full ownership of this wallet to `_dest` removing older owners from wallet * @param _dest the address of new controller @@ -263,73 +113,6 @@ contract MultiSigTokenWallet { } } - /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. - /// @param _required Number of required confirmations. - function changeRequirement(uint _required) - public - onlyWallet - validRequirement(owners.length, _required) - { - required = _required; - RequirementChange(_required); - } - - /// @dev Allows an owner to submit and confirm a transaction. - /// @param destination Transaction target address. - /// @param value Transaction ether value. - /// @param data Transaction data payload. - /// @return Returns transaction ID. - function submitTransaction(address destination, uint value, bytes data) - public - returns (uint transactionId) - { - transactionId = addTransaction(destination, value, data); - confirmTransaction(transactionId); - } - - /// @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) - { - confirmations[transactionId][msg.sender] = true; - Confirmation(msg.sender, transactionId); - executeTransaction(transactionId); - } - - /// @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) - { - 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) - { - if (isConfirmed(transactionId)) { - Transaction storage txx = transactions[transactionId]; - txx.executed = true; - if (txx.destination.call.value(txx.value)(txx.data)) { - Execution(transactionId); - } else { - ExecutionFailure(transactionId); - txx.executed = false; - } - } - } - /** * @dev withdraw all recognized tokens balances and ether to `_dest` * @param _dest the address of receiver @@ -387,47 +170,6 @@ contract MultiSigTokenWallet { bool result = ERC20(_tokenAddr).transfer(_dest, _amount); assert(result); } - - /// @dev Returns the confirmation status of a transaction. - /// @param transactionId Transaction ID. - /// @return Confirmation status. - function isConfirmed(uint transactionId) - public - constant - returns (bool) - { - uint count = 0; - for (uint i = 0; i < owners.length; i++) { - if (confirmations[transactionId][owners[i]]) - count += 1; - if (count == required) - return true; - } - } - - /* - * Internal functions - */ - /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. - /// @param destination Transaction target address. - /// @param value Transaction ether value. - /// @param data Transaction data payload. - /// @return Returns transaction ID. - function addTransaction(address destination, uint value, bytes data) - internal - notNull(destination) - returns (uint transactionId) - { - transactionId = transactionCount; - transactions[transactionId] = Transaction({ - destination: destination, - value: value, - data: data, - executed: false - }); - transactionCount += 1; - Submission(transactionId); - } /** * @dev register the deposit @@ -448,45 +190,6 @@ contract MultiSigTokenWallet { /* * Web3 call functions */ - /// @dev Returns number of confirmations of a transaction. - /// @param transactionId Transaction ID. - /// @return Number of confirmations. - function getConfirmationCount(uint transactionId) - public - constant - returns (uint count) - { - for (uint i = 0; i < owners.length; i++) { - if (confirmations[transactionId][owners[i]]) - count += 1; - } - } - - /// @dev Returns total number of transactions after filters are applied. - /// @param pending Include pending transactions. - /// @param executed Include executed transactions. - /// @return Total number of transactions after filters are applied. - function getTransactionCount(bool pending, bool executed) - public - constant - returns (uint count) - { - for (uint i = 0; i < transactionCount; i++) { - if (pending && !transactions[i].executed || executed && transactions[i].executed) - count += 1; - } - } - - /// @dev Returns list of owners. - /// @return List of owner addresses. - function getOwners() - public - constant - returns (address[]) - { - return owners; - } - /// @dev Returns list of tokens. /// @return List of token addresses. function getTokenList() @@ -497,53 +200,4 @@ contract MultiSigTokenWallet { return tokens; } - /// @dev Returns array with owner addresses, which confirmed transaction. - /// @param transactionId Transaction ID. - /// @return Returns array of owner addresses. - function getConfirmations(uint transactionId) - public - constant - returns (address[] _confirmations) - { - address[] memory confirmationsTemp = new address[](owners.length); - uint count = 0; - uint i; - for (i = 0; i < owners.length; i++) { - if (confirmations[transactionId][owners[i]]) { - confirmationsTemp[count] = owners[i]; - count += 1; - } - } - _confirmations = new address[](count); - for (i = 0; i < count; i++) { - _confirmations[i] = confirmationsTemp[i]; - } - } - - /// @dev Returns list of transaction IDs in defined range. - /// @param from Index start position of transaction array. - /// @param to Index end position of transaction array. - /// @param pending Include pending transactions. - /// @param executed Include executed transactions. - /// @return Returns array of transaction IDs. - function getTransactionIds(uint from, uint to, bool pending, bool executed) - public - constant - returns (uint[] _transactionIds) - { - uint[] memory transactionIdsTemp = new uint[](transactionCount); - uint count = 0; - uint i; - for (i = 0; i < transactionCount; i++) { - if (pending && !transactions[i].executed || executed && transactions[i].executed) { - transactionIdsTemp[count] = i; - count += 1; - } - } - _transactionIds = new uint[](to - from); - for (i = from; i < to; i++) { - _transactionIds[i - from] = transactionIdsTemp[i]; - } - } - } diff --git a/contracts/MultiSigWallet.sol b/contracts/MultiSigWallet.sol new file mode 100644 index 0000000..642aef3 --- /dev/null +++ b/contracts/MultiSigWallet.sol @@ -0,0 +1,378 @@ +pragma solidity ^0.4.17; + + +/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution. +/// @author Stefan George - +contract MultiSigWallet { + + /* + * Events + */ + 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); + + /* + * Constants + */ + uint constant public MAX_OWNER_COUNT = 50; + + /* + * Storage + */ + 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; + } + + /* + * Modifiers + */ + modifier onlyWallet() { + require (msg.sender == address(this)); + _; + } + + modifier ownerDoesNotExist(address owner) { + require (!isOwner[owner]); + _; + } + + modifier ownerExists(address owner) { + require (isOwner[owner]); + _; + } + + modifier transactionExists(uint transactionId) { + require (transactions[transactionId].destination != 0); + _; + } + + modifier confirmed(uint transactionId, address owner) { + require (confirmations[transactionId][owner]); + _; + } + + modifier notConfirmed(uint transactionId, address owner) { + require(!confirmations[transactionId][owner]); + _; + } + + modifier notExecuted(uint transactionId) { + require (!transactions[transactionId].executed); + _; + } + + modifier notNull(address _address) { + require (_address != 0); + _; + } + + modifier validRequirement(uint ownerCount, uint _required) { + require (ownerCount <= MAX_OWNER_COUNT && _required <= ownerCount && _required != 0 && ownerCount != 0); + _; + } + + /// @dev Fallback function allows to deposit ether. + function () + public + payable + { + if (msg.value > 0) + Deposit(msg.sender, msg.value); + } + + /* + * Public functions + */ + /// @dev Constructor calls function `constructor(address[],uint256)` + /// @param _owners List of initial owners. + /// @param _required Number of required confirmations. + function MultiSigWallet(address[] _owners, uint _required) + public + { + constructor(_owners, _required); + } + + /// @dev Contract constructor sets initial owners and required number of confirmations, can only be called once. + /// @param _owners List of initial owners. + /// @param _required Number of required confirmations. + function constructor(address[] _owners, uint _required) + public + validRequirement(_owners.length, _required) + { + require(owners.length == 0 && required == 0); + for (uint i = 0; i < _owners.length; i++) { + require(!isOwner[_owners[i]] && _owners[i] != 0); + 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 newOwner Address of new owner. + function replaceOwner(address owner, address newOwner) + public + onlyWallet + ownerExists(owner) + ownerDoesNotExist(newOwner) + { + for (uint i=0; i Date: Wed, 8 Nov 2017 17:53:38 -0200 Subject: [PATCH 02/16] remove internal balances, better handle bad tokens, better handle race conditions --- contracts/MultiSigTokenWallet.sol | 149 +++++++++++++++--------------- 1 file changed, 74 insertions(+), 75 deletions(-) diff --git a/contracts/MultiSigTokenWallet.sol b/contracts/MultiSigTokenWallet.sol index bd1fedc..8490f42 100644 --- a/contracts/MultiSigTokenWallet.sol +++ b/contracts/MultiSigTokenWallet.sol @@ -6,11 +6,11 @@ import "./ERC20.sol"; contract MultiSigTokenWallet is MultiSigWallet { address[] public tokens; - mapping (address => uint) public tokenBalances; + mapping (address => uint) watchedPos; mapping (address => address[]) public userList; uint public nonce; - event TokenDeposit(address _token, address indexed _sender, uint _value); + event TokenDeposit(address indexed token, address indexed sender, uint value); /** * Public functions @@ -47,41 +47,59 @@ contract MultiSigTokenWallet is MultiSigWallet { _deposited(_from, _amount, _token, _data); } } + /** * @notice watches for balance in a token contract * @param _tokenAddr the token contract address **/ function watch(address _tokenAddr) + public ownerExists(msg.sender) { - uint oldBal = tokenBalances[_tokenAddr]; - uint newBal = ERC20(_tokenAddr).balanceOf(this); - if (newBal > oldBal) { - _deposited(0x0, newBal-oldBal, _tokenAddr, new bytes(0)); - } + require(watchedPos[_tokenAddr] == 0); + require(ERC20(_tokenAddr).balanceOf(address(this)) > 0); + tokens.push(_tokenAddr); + watchedPos[_tokenAddr] = tokens.length; } + /** + * @notice watches for balance in a token contract + * @param _tokenAddr the token contract address + **/ + function unwatch(address _tokenAddr) + public + ownerExists(msg.sender) + { + require(watchedPos[_tokenAddr] > 0); + tokens[watchedPos[_tokenAddr] - 1] = tokens[tokens.length - 1]; + delete watchedPos[_tokenAddr]; + tokens.length--; + } + + /** + * @notice set token list that will be used at `withdrawEverything(msg.sender)` and `withdrawAllTokens(msg.sender)` function when sending to `msg.sender`. + **/ function setMyTokenList(address[] _tokenList) public { userList[msg.sender] = _tokenList; } - function setTokenList(address[] _tokenList) - onlyWallet - { - tokens = _tokenList; - } - /** * @notice ERC23 Token fallback * @param _from address incoming token * @param _amount incoming amount **/ - function tokenFallback(address _from, uint _amount, bytes _data) + function tokenFallback( + address _from, + uint _amount, + bytes _data + ) public + returns (bool) { _deposited(_from, _amount, msg.sender, _data); + return true; } /** @@ -91,49 +109,25 @@ contract MultiSigTokenWallet is MultiSigWallet { * @param _token the token contract address * @param _data (might be used by child classes) */ - function receiveApproval(address _from, uint256 _amount, address _token, bytes _data) { + function receiveApproval( + address _from, + uint256 _amount, + address _token, + bytes _data + ) + public + { deposit(_from, _amount, _token, _data); } /** - * @dev gives full ownership of this wallet to `_dest` removing older owners from wallet - * @param _dest the address of new controller - **/ - function releaseWallet(address _dest) - public - notNull(_dest) - ownerDoesNotExist(_dest) - onlyWallet - { - address[] memory _owners = owners; - uint numOwners = _owners.length; - addOwner(_dest); - for (uint i = 0; i < numOwners; i++) { - removeOwner(_owners[i]); - } - } - - /** - * @dev withdraw all recognized tokens balances and ether to `_dest` + * @dev withdraw all watched tokens balances and ether to `_dest` * @param _dest the address of receiver **/ function withdrawEverything(address _dest) public notNull(_dest) onlyWallet - { - withdrawAllTokens(_dest); - _dest.transfer(this.balance); - } - - /** - * @dev withdraw all recognized tokens balances to `_dest` - * @param _dest the address of receiver - **/ - function withdrawAllTokens(address _dest) - public - notNull(_dest) - onlyWallet { address[] memory _tokenList; if (userList[_dest].length > 0) { @@ -141,49 +135,54 @@ contract MultiSigTokenWallet is MultiSigWallet { } else { _tokenList = tokens; } + withdrawAllTokens(_dest, _tokenList); + _dest.transfer(this.balance); + } + + /** + * @dev withdraw all tokens in list and ether to `_dest` + * @param _dest the address of receiver + * @param _tokenList the list of tokens to withdraw all balance + **/ + function withdrawEverything(address _dest, address[] _tokenList) + public + notNull(_dest) + onlyWallet + { + withdrawAllTokens(_dest, _tokenList); + _dest.transfer(this.balance); + } + + /** + * @dev withdraw all listed tokens balances to `_dest` + * @param _dest the address of receiver + * @param _tokenList the list of tokens to withdraw all balance + **/ + function withdrawAllTokens(address _dest, address[] _tokenList) + public + notNull(_dest) + onlyWallet + { uint len = _tokenList.length; for (uint i = 0;i < len; i++) { address _tokenAddr = _tokenList[i]; - uint _amount = tokenBalances[_tokenAddr]; + uint _amount = ERC20(_tokenAddr).balanceOf(address(this)); if (_amount > 0) { - delete tokenBalances[_tokenAddr]; ERC20(_tokenAddr).transfer(_dest, _amount); } } } - /** - * @dev withdraw `_tokenAddr` `_amount` to `_dest` - * @param _tokenAddr the address of the token - * @param _dest the address of receiver - * @param _amount the number of tokens to send - **/ - function withdrawToken(address _tokenAddr, address _dest, uint _amount) - public - notNull(_dest) - onlyWallet - { - require(_amount > 0); - uint _balance = tokenBalances[_tokenAddr]; - require(_amount <= _balance); - tokenBalances[_tokenAddr] = _balance - _amount; - bool result = ERC20(_tokenAddr).transfer(_dest, _amount); - assert(result); - } - /** * @dev register the deposit **/ function _deposited(address _from, uint _amount, address _tokenAddr, bytes) internal { - TokenDeposit(_tokenAddr,_from,_amount); - nonce++; - if (tokenBalances[_tokenAddr] == 0) { + TokenDeposit(_tokenAddr, _from, _amount); + if (watchedPos[_tokenAddr] > 0) { tokens.push(_tokenAddr); - tokenBalances[_tokenAddr] = ERC20(_tokenAddr).balanceOf(this); - } else { - tokenBalances[_tokenAddr] += _amount; + watchedPos[_tokenAddr] = tokens.length; } } @@ -200,4 +199,4 @@ contract MultiSigTokenWallet is MultiSigWallet { return tokens; } -} +} \ No newline at end of file From 54fcbed51b879e0e3803072a15799b8494b7c9b9 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Wed, 8 Nov 2017 18:18:07 -0200 Subject: [PATCH 03/16] remove nonce and assert that withdrawAllTokens will not fail because bad tokens --- contracts/MultiSigTokenWallet.sol | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/contracts/MultiSigTokenWallet.sol b/contracts/MultiSigTokenWallet.sol index 8490f42..c017ac2 100644 --- a/contracts/MultiSigTokenWallet.sol +++ b/contracts/MultiSigTokenWallet.sol @@ -8,7 +8,6 @@ contract MultiSigTokenWallet is MultiSigWallet { address[] public tokens; mapping (address => uint) watchedPos; mapping (address => address[]) public userList; - uint public nonce; event TokenDeposit(address indexed token, address indexed sender, uint value); @@ -39,13 +38,10 @@ contract MultiSigTokenWallet is MultiSigWallet { { if (_from == address(this)) return; - uint _nonce = nonce; bool result = ERC20(_token).transferFrom(_from, this, _amount); - assert(result); - //ERC23 not executed _deposited tokenFallback by - if (nonce == _nonce) { - _deposited(_from, _amount, _token, _data); - } + require(result); + _deposited(_from, _amount, _token, _data); + } /** @@ -168,7 +164,7 @@ contract MultiSigTokenWallet is MultiSigWallet { address _tokenAddr = _tokenList[i]; uint _amount = ERC20(_tokenAddr).balanceOf(address(this)); if (_amount > 0) { - ERC20(_tokenAddr).transfer(_dest, _amount); + ERC20(_tokenAddr).call(bytes4(keccak256("transfer(address,uint256)")), _dest, _amount); } } } From 53cc9c2c0e776c185b7a6b692f2629a95aeef02c Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 9 Nov 2017 06:21:06 -0200 Subject: [PATCH 04/16] remove token watch related stuff --- contracts/MultiSigTokenWallet.sol | 89 +------------------------------ 1 file changed, 2 insertions(+), 87 deletions(-) diff --git a/contracts/MultiSigTokenWallet.sol b/contracts/MultiSigTokenWallet.sol index c017ac2..ebec928 100644 --- a/contracts/MultiSigTokenWallet.sol +++ b/contracts/MultiSigTokenWallet.sol @@ -5,10 +5,6 @@ import "./ERC20.sol"; contract MultiSigTokenWallet is MultiSigWallet { - address[] public tokens; - mapping (address => uint) watchedPos; - mapping (address => address[]) public userList; - event TokenDeposit(address indexed token, address indexed sender, uint value); /** @@ -40,47 +36,10 @@ contract MultiSigTokenWallet is MultiSigWallet { return; bool result = ERC20(_token).transferFrom(_from, this, _amount); require(result); - _deposited(_from, _amount, _token, _data); + TokenDeposit(_token, _from, _amount); } - /** - * @notice watches for balance in a token contract - * @param _tokenAddr the token contract address - **/ - function watch(address _tokenAddr) - public - ownerExists(msg.sender) - { - require(watchedPos[_tokenAddr] == 0); - require(ERC20(_tokenAddr).balanceOf(address(this)) > 0); - tokens.push(_tokenAddr); - watchedPos[_tokenAddr] = tokens.length; - } - - /** - * @notice watches for balance in a token contract - * @param _tokenAddr the token contract address - **/ - function unwatch(address _tokenAddr) - public - ownerExists(msg.sender) - { - require(watchedPos[_tokenAddr] > 0); - tokens[watchedPos[_tokenAddr] - 1] = tokens[tokens.length - 1]; - delete watchedPos[_tokenAddr]; - tokens.length--; - } - - /** - * @notice set token list that will be used at `withdrawEverything(msg.sender)` and `withdrawAllTokens(msg.sender)` function when sending to `msg.sender`. - **/ - function setMyTokenList(address[] _tokenList) - public - { - userList[msg.sender] = _tokenList; - } - /** * @notice ERC23 Token fallback * @param _from address incoming token @@ -94,7 +53,7 @@ contract MultiSigTokenWallet is MultiSigWallet { public returns (bool) { - _deposited(_from, _amount, msg.sender, _data); + TokenDeposit(msg.sender, _from, _amount); return true; } @@ -116,24 +75,6 @@ contract MultiSigTokenWallet is MultiSigWallet { deposit(_from, _amount, _token, _data); } - /** - * @dev withdraw all watched tokens balances and ether to `_dest` - * @param _dest the address of receiver - **/ - function withdrawEverything(address _dest) - public - notNull(_dest) - onlyWallet - { - address[] memory _tokenList; - if (userList[_dest].length > 0) { - _tokenList = userList[_dest]; - } else { - _tokenList = tokens; - } - withdrawAllTokens(_dest, _tokenList); - _dest.transfer(this.balance); - } /** * @dev withdraw all tokens in list and ether to `_dest` @@ -169,30 +110,4 @@ contract MultiSigTokenWallet is MultiSigWallet { } } - /** - * @dev register the deposit - **/ - function _deposited(address _from, uint _amount, address _tokenAddr, bytes) - internal - { - TokenDeposit(_tokenAddr, _from, _amount); - if (watchedPos[_tokenAddr] > 0) { - tokens.push(_tokenAddr); - watchedPos[_tokenAddr] = tokens.length; - } - } - - /* - * Web3 call functions - */ - /// @dev Returns list of tokens. - /// @return List of token addresses. - function getTokenList() - public - constant - returns (address[]) - { - return tokens; - } - } \ No newline at end of file From 1b2a941869d7e722146f3d3f1fc12f9981e42189 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 9 Nov 2017 06:21:31 -0200 Subject: [PATCH 05/16] abstract the DelegatedCall logic --- contracts/DelegatedCall.sol | 71 +++++++++++++++++++++++++++++++++++++ contracts/MultiSigStub.sol | 56 +++-------------------------- 2 files changed, 76 insertions(+), 51 deletions(-) create mode 100644 contracts/DelegatedCall.sol diff --git a/contracts/DelegatedCall.sol b/contracts/DelegatedCall.sol new file mode 100644 index 0000000..9155daf --- /dev/null +++ b/contracts/DelegatedCall.sol @@ -0,0 +1,71 @@ +pragma solidity ^0.4.12; + +/** + * @title DelegatedCall + * @author Ricardo Guilherme Schmidt (Status Research & Development GmbH) + * Abstract contract that delegates all calls to contract returned by abstract function `_getDelegatedContract` + */ +contract DelegatedCall { + + /** + * @dev delegates the call of this function + */ + modifier delegated + { + uint inSize = msg.data.length; + bytes32 inDataPtr = _malloc(inSize); + + assembly { + calldatacopy(inDataPtr, 0x0, inSize) + } + + uint256 outSize; + bytes32 outDataPtr; + + _delegatecall(inDataPtr, inSize); + _; + assembly { + return(0, outSize) + } + } + + /** + * @dev defines the address for delegation of calls + */ + function _getDelegatedContract() + internal + returns(address); + + /** + * @dev allocates memory to a pointer + */ + function _malloc(uint size) + internal + returns(bytes32 ptr) + { + assembly { + ptr := mload(0x40) + mstore(0x40, add(ptr, size)) + } + } + + /** + * @dev delegates the data in pointer + */ + function _delegatecall(bytes32 inDataPtr, uint inSize) + internal + returns(bytes32 outDataPtr, uint256 outSize) + { + outSize = 0x20; + address target = _getDelegatedContract(); + outDataPtr = _malloc(outSize); + bool failed; + + assembly { + failed := iszero(delegatecall(sub(gas, 10000), target, inDataPtr, inSize, outDataPtr, outSize)) + } + + assert(!failed); + } + +} diff --git a/contracts/MultiSigStub.sol b/contracts/MultiSigStub.sol index 4857129..1234adb 100644 --- a/contracts/MultiSigStub.sol +++ b/contracts/MultiSigStub.sol @@ -1,13 +1,14 @@ pragma solidity ^0.4.15; +import "./DelegatedCall.sol"; + /** * @title MultiSigStub * Contract that delegates calls to a library to build a full MultiSigWallet that is cheap to create. */ -contract MultiSigStub { +contract MultiSigStub is DelegatedCall { address[] public owners; - address[] public tokens; mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; uint public transactionCount; @@ -34,21 +35,6 @@ contract MultiSigStub { _delegatecall(mData, size); } - modifier delegated { - uint size = msg.data.length; - bytes32 mData = _malloc(size); - - assembly { - calldatacopy(mData, 0x0, size) - } - - bytes32 mResult = _delegatecall(mData, size); - _; - assembly { - return(mResult, 0x20) - } - } - function() payable delegated @@ -70,20 +56,7 @@ contract MultiSigStub { { } - - function watch(address _tokenAddr) - public - delegated - { - - } - - function setMyTokenList(address[] _tokenList) - public - delegated - { - } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. @@ -99,15 +72,6 @@ contract MultiSigStub { /* * Web3 call functions */ - function tokenBalances(address tokenAddress) - public - constant - delegated - returns (uint) - { - - } - /// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. @@ -144,16 +108,6 @@ contract MultiSigStub { return owners; } - /// @dev Returns list of tokens. - /// @return List of token addresses. - function getTokenList() - public - constant - returns (address[]) - { - return tokens; - } - /// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses. @@ -206,6 +160,7 @@ contract MultiSigStub { function _malloc(uint size) private + pure returns(bytes32 mData) { assembly { @@ -218,8 +173,7 @@ contract MultiSigStub { private returns(bytes32 mResult) { - address target = 0xc0FFeEE61948d8993864a73a099c0E38D887d3F4; //Multinetwork - mResult = _malloc(32); + address target = 0xCaFFE810d0dF52E27DC580AD4a3C6283B0094291; bool failed; assembly { From 5fe2bb9b5298f8140ec10b501b870c31c63a9a00 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 9 Nov 2017 06:26:05 -0200 Subject: [PATCH 06/16] explicitally set function as public --- contracts/MultiSigFactory.sol | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contracts/MultiSigFactory.sol b/contracts/MultiSigFactory.sol index 62bc00a..99e80ae 100644 --- a/contracts/MultiSigFactory.sol +++ b/contracts/MultiSigFactory.sol @@ -6,7 +6,10 @@ contract MultiSigFactory { event Create(address indexed caller, address createdContract); - function create(address[] owners, uint256 required) returns (address wallet) { + function create(address[] owners, uint256 required) + public + returns (address wallet) + { wallet = new MultiSigStub(owners, required); Create(msg.sender, wallet); } From 8d149a396b60d5c28475ba77d761cf71a0f32159 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 9 Nov 2017 06:43:00 -0200 Subject: [PATCH 07/16] fix stub to use parent methods --- contracts/MultiSigStub.sol | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/contracts/MultiSigStub.sol b/contracts/MultiSigStub.sol index 1234adb..3bec475 100644 --- a/contracts/MultiSigStub.sol +++ b/contracts/MultiSigStub.sol @@ -157,30 +157,11 @@ contract MultiSigStub is DelegatedCall { } } - - function _malloc(uint size) - private - pure - returns(bytes32 mData) + function _getDelegatedContract() + internal + returns(address) { - assembly { - mData := mload(0x40) - mstore(0x40, add(mData, size)) - } - } - - function _delegatecall(bytes32 mData, uint size) - private - returns(bytes32 mResult) - { - address target = 0xCaFFE810d0dF52E27DC580AD4a3C6283B0094291; - bool failed; - - assembly { - failed := iszero(delegatecall(sub(gas, 10000), target, mData, size, mResult, 0x20)) - } - - assert(!failed); + return 0xCaFFE810d0dF52E27DC580AD4a3C6283B0094291; } } \ No newline at end of file From 451984b55c937706e183187728243ed7da288a66 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 9 Nov 2017 08:17:08 -0200 Subject: [PATCH 08/16] fix fixed length returns at delegatedcall --- contracts/DelegatedCall.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/DelegatedCall.sol b/contracts/DelegatedCall.sol index 9155daf..9dc62ff 100644 --- a/contracts/DelegatedCall.sol +++ b/contracts/DelegatedCall.sol @@ -19,10 +19,10 @@ contract DelegatedCall { calldatacopy(inDataPtr, 0x0, inSize) } - uint256 outSize; bytes32 outDataPtr; + uint256 outSize; - _delegatecall(inDataPtr, inSize); + (outDataPtr, outSize) = _delegatecall(inDataPtr, inSize); _; assembly { return(0, outSize) From e43d1c5d78e6bb9b85b4abdfb66f335c521ef5cd Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 9 Nov 2017 13:05:57 -0200 Subject: [PATCH 09/16] support dynamic data return --- contracts/DelegatedCall.sol | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/contracts/DelegatedCall.sol b/contracts/DelegatedCall.sol index 9dc62ff..18b2851 100644 --- a/contracts/DelegatedCall.sol +++ b/contracts/DelegatedCall.sol @@ -25,7 +25,7 @@ contract DelegatedCall { (outDataPtr, outSize) = _delegatecall(inDataPtr, inSize); _; assembly { - return(0, outSize) + return(outDataPtr, outSize) } } @@ -56,16 +56,17 @@ contract DelegatedCall { internal returns(bytes32 outDataPtr, uint256 outSize) { - outSize = 0x20; address target = _getDelegatedContract(); - outDataPtr = _malloc(outSize); bool failed; - assembly { - failed := iszero(delegatecall(sub(gas, 10000), target, inDataPtr, inSize, outDataPtr, outSize)) + failed := iszero(delegatecall(sub(gas, 10000), target, inDataPtr, inSize, 0, 0)) + outSize := returndatasize + } + require(!failed); + outDataPtr = _malloc(outSize); + assembly { + returndatacopy(outDataPtr, 0, outSize) } - - assert(!failed); } } From fd75fc1ba2ad52bf41ebd762a45db2dca0fa2b6b Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 9 Nov 2017 13:06:24 -0200 Subject: [PATCH 10/16] Change to safecall into ERC20 --- contracts/MultiSigTokenWallet.sol | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/contracts/MultiSigTokenWallet.sol b/contracts/MultiSigTokenWallet.sol index ebec928..f7817d8 100644 --- a/contracts/MultiSigTokenWallet.sol +++ b/contracts/MultiSigTokenWallet.sol @@ -11,6 +11,15 @@ contract MultiSigTokenWallet is MultiSigWallet { * Public functions * **/ + /** + * @dev only call parent constructor + */ + function MultiSigTokenWallet(address[] _owners, uint _required) + MultiSigWallet(_owners,_required) + public + { + //does nothing + } /** * @notice deposit a ERC20 token. The amount of deposit is the allowance set to this contract. * @param _token the token contract address @@ -105,7 +114,7 @@ contract MultiSigTokenWallet is MultiSigWallet { address _tokenAddr = _tokenList[i]; uint _amount = ERC20(_tokenAddr).balanceOf(address(this)); if (_amount > 0) { - ERC20(_tokenAddr).call(bytes4(keccak256("transfer(address,uint256)")), _dest, _amount); + ERC20(_tokenAddr).transfer(_dest, _amount); } } } From 72574d00dd6d86416dcdad39d2f3020e87db74df Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 9 Nov 2017 13:07:07 -0200 Subject: [PATCH 11/16] simplified stub (only read ABI) --- contracts/MultiSigStub.sol | 62 +++++--------------------------------- 1 file changed, 7 insertions(+), 55 deletions(-) diff --git a/contracts/MultiSigStub.sol b/contracts/MultiSigStub.sol index 3bec475..9cf0d32 100644 --- a/contracts/MultiSigStub.sol +++ b/contracts/MultiSigStub.sol @@ -8,18 +8,6 @@ import "./DelegatedCall.sol"; */ contract MultiSigStub is DelegatedCall { - address[] public owners; - mapping (uint => Transaction) public transactions; - mapping (uint => mapping (address => bool)) public confirmations; - uint public transactionCount; - - struct Transaction { - address destination; - uint value; - bytes data; - bool executed; - } - function MultiSigStub(address[] _owners, uint256 _required) { //bytes4 sig = bytes4(sha3("constructor(address[],uint256)")); bytes4 sig = 0x36756a23; @@ -42,21 +30,6 @@ contract MultiSigStub is DelegatedCall { } - function submitTransaction(address destination, uint value, bytes data) - public - delegated - returns (uint) - { - - } - - function confirmTransaction(uint transactionId) - public - delegated - { - - } - /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. @@ -103,9 +76,10 @@ contract MultiSigStub is DelegatedCall { function getOwners() public constant + delegated returns (address[]) { - return owners; + } /// @dev Returns array with owner addresses, which confirmed transaction. @@ -114,21 +88,10 @@ contract MultiSigStub is DelegatedCall { function getConfirmations(uint transactionId) public constant + delegated returns (address[] _confirmations) { - address[] memory confirmationsTemp = new address[](owners.length); - uint count = 0; - uint i; - for (i = 0; i < owners.length; i++) { - if (confirmations[transactionId][owners[i]]) { - confirmationsTemp[count] = owners[i]; - count += 1; - } - } - _confirmations = new address[](count); - for (i = 0; i < count; i++) { - _confirmations[i] = confirmationsTemp[i]; - } + } /// @dev Returns list of transaction IDs in defined range. @@ -137,24 +100,13 @@ contract MultiSigStub is DelegatedCall { /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs. - function getTransactionIds(uint from, uint to, bool pending, bool executed) + function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant + delegated returns (uint[] _transactionIds) { - uint[] memory transactionIdsTemp = new uint[](transactionCount); - uint count = 0; - uint i; - for (i = 0; i < transactionCount; i++) { - if (pending && !transactions[i].executed || executed && transactions[i].executed) { - transactionIdsTemp[count] = i; - count += 1; - } - } - _transactionIds = new uint[](to - from); - for (i = from; i < to; i++) { - _transactionIds[i - from] = transactionIdsTemp[i]; - } + } function _getDelegatedContract() From 2442deada72763a382dea384b19926ebe9e21a49 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 9 Nov 2017 13:12:13 -0200 Subject: [PATCH 12/16] add comment about hardcoded address --- contracts/MultiSigStub.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/MultiSigStub.sol b/contracts/MultiSigStub.sol index 9cf0d32..6c7451b 100644 --- a/contracts/MultiSigStub.sol +++ b/contracts/MultiSigStub.sol @@ -113,7 +113,7 @@ contract MultiSigStub is DelegatedCall { internal returns(address) { - return 0xCaFFE810d0dF52E27DC580AD4a3C6283B0094291; + return 0xCaFFE810d0dF52E27DC580AD4a3C6283B0094291; //hardcoded multinetwork address } } \ No newline at end of file From 1ac4789bf709c3c70144652bcd6e89237b35508d Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 9 Nov 2017 13:50:54 -0200 Subject: [PATCH 13/16] fix solc version and comments --- contracts/MultiSigTokenWallet.sol | 7 ++++++- contracts/MultiSigWallet.sol | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/contracts/MultiSigTokenWallet.sol b/contracts/MultiSigTokenWallet.sol index f7817d8..c988fca 100644 --- a/contracts/MultiSigTokenWallet.sol +++ b/contracts/MultiSigTokenWallet.sol @@ -1,8 +1,13 @@ -pragma solidity ^0.4.15; +pragma solidity ^0.4.18; import "./MultiSigWallet.sol"; import "./ERC20.sol"; +/** + * @title MultiSigTokenWallet + * @author Ricardo Guilherme Schmidt (Status Research & Development GmbH) + * MultiSigWallet that supports withdrawing all ERC20 tokens at once. + */ contract MultiSigTokenWallet is MultiSigWallet { event TokenDeposit(address indexed token, address indexed sender, uint value); diff --git a/contracts/MultiSigWallet.sol b/contracts/MultiSigWallet.sol index 642aef3..a6a70b4 100644 --- a/contracts/MultiSigWallet.sol +++ b/contracts/MultiSigWallet.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.17; +pragma solidity ^0.4.18; /// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution. From 9aa000872d95c9c9b77ce1f888f13accdaef12f6 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 9 Nov 2017 14:00:06 -0200 Subject: [PATCH 14/16] Add legacy support --- contracts/MultiSigTokenWalletV1.sol | 203 ++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 contracts/MultiSigTokenWalletV1.sol diff --git a/contracts/MultiSigTokenWalletV1.sol b/contracts/MultiSigTokenWalletV1.sol new file mode 100644 index 0000000..4375daf --- /dev/null +++ b/contracts/MultiSigTokenWalletV1.sol @@ -0,0 +1,203 @@ +pragma solidity ^0.4.15; + +import "./MultiSigWallet.sol"; +import "./ERC20.sol"; +// @dev This contract is deprecated, use the new version. +contract MultiSigTokenWalletV1 is MultiSigWallet { + + address[] public tokens; + mapping (address => uint) public tokenBalances; + mapping (address => address[]) public userList; + uint public nonce; + + event TokenDeposit(address _token, address indexed _sender, uint _value); + + /** + * Public functions + * + **/ + /** + * @notice deposit a ERC20 token. The amount of deposit is the allowance set to this contract. + * @param _token the token contract address + * @param _data might be used by child implementations + **/ + function depositToken(address _token, bytes _data) + public + { + address sender = msg.sender; + uint amount = ERC20(_token).allowance(sender, this); + deposit(sender, amount, _token, _data); + } + + /** + * @notice deposit a ERC20 token. The amount of deposit is the allowance set to this contract. + * @param _token the token contract address + * @param _data might be used by child implementations + **/ + function deposit(address _from, uint256 _amount, address _token, bytes _data) + public + { + if (_from == address(this)) + return; + uint _nonce = nonce; + bool result = ERC20(_token).transferFrom(_from, this, _amount); + assert(result); + //ERC23 not executed _deposited tokenFallback by + if (nonce == _nonce) { + _deposited(_from, _amount, _token, _data); + } + } + /** + * @notice watches for balance in a token contract + * @param _tokenAddr the token contract address + **/ + function watch(address _tokenAddr) + ownerExists(msg.sender) + { + uint oldBal = tokenBalances[_tokenAddr]; + uint newBal = ERC20(_tokenAddr).balanceOf(this); + if (newBal > oldBal) { + _deposited(0x0, newBal-oldBal, _tokenAddr, new bytes(0)); + } + } + + function setMyTokenList(address[] _tokenList) + public + { + userList[msg.sender] = _tokenList; + } + + function setTokenList(address[] _tokenList) + onlyWallet + { + tokens = _tokenList; + } + + /** + * @notice ERC23 Token fallback + * @param _from address incoming token + * @param _amount incoming amount + **/ + function tokenFallback(address _from, uint _amount, bytes _data) + public + { + _deposited(_from, _amount, msg.sender, _data); + } + + /** + * @notice Called MiniMeToken approvesAndCall to this contract, calls deposit. + * @param _from address incoming token + * @param _amount incoming amount + * @param _token the token contract address + * @param _data (might be used by child classes) + */ + function receiveApproval(address _from, uint256 _amount, address _token, bytes _data) { + deposit(_from, _amount, _token, _data); + } + + /** + * @dev gives full ownership of this wallet to `_dest` removing older owners from wallet + * @param _dest the address of new controller + **/ + function releaseWallet(address _dest) + public + notNull(_dest) + ownerDoesNotExist(_dest) + onlyWallet + { + address[] memory _owners = owners; + uint numOwners = _owners.length; + addOwner(_dest); + for (uint i = 0; i < numOwners; i++) { + removeOwner(_owners[i]); + } + } + + /** + * @dev withdraw all recognized tokens balances and ether to `_dest` + * @param _dest the address of receiver + **/ + function withdrawEverything(address _dest) + public + notNull(_dest) + onlyWallet + { + withdrawAllTokens(_dest); + _dest.transfer(this.balance); + } + + /** + * @dev withdraw all recognized tokens balances to `_dest` + * @param _dest the address of receiver + **/ + function withdrawAllTokens(address _dest) + public + notNull(_dest) + onlyWallet + { + address[] memory _tokenList; + if (userList[_dest].length > 0) { + _tokenList = userList[_dest]; + } else { + _tokenList = tokens; + } + uint len = _tokenList.length; + for (uint i = 0;i < len; i++) { + address _tokenAddr = _tokenList[i]; + uint _amount = tokenBalances[_tokenAddr]; + if (_amount > 0) { + delete tokenBalances[_tokenAddr]; + ERC20(_tokenAddr).transfer(_dest, _amount); + } + } + } + + /** + * @dev withdraw `_tokenAddr` `_amount` to `_dest` + * @param _tokenAddr the address of the token + * @param _dest the address of receiver + * @param _amount the number of tokens to send + **/ + function withdrawToken(address _tokenAddr, address _dest, uint _amount) + public + notNull(_dest) + onlyWallet + { + require(_amount > 0); + uint _balance = tokenBalances[_tokenAddr]; + require(_amount <= _balance); + tokenBalances[_tokenAddr] = _balance - _amount; + bool result = ERC20(_tokenAddr).transfer(_dest, _amount); + assert(result); + } + + /** + * @dev register the deposit + **/ + function _deposited(address _from, uint _amount, address _tokenAddr, bytes) + internal + { + TokenDeposit(_tokenAddr,_from,_amount); + nonce++; + if (tokenBalances[_tokenAddr] == 0) { + tokens.push(_tokenAddr); + tokenBalances[_tokenAddr] = ERC20(_tokenAddr).balanceOf(this); + } else { + tokenBalances[_tokenAddr] += _amount; + } + } + + /* + * Web3 call functions + */ + /// @dev Returns list of tokens. + /// @return List of token addresses. + function getTokenList() + public + constant + returns (address[]) + { + return tokens; + } + +} \ No newline at end of file From fb2ed3d4007c7b8c18403e0f6bf38b0d5fe76771 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 9 Nov 2017 14:00:45 -0200 Subject: [PATCH 15/16] lint --- contracts/MultiSigTokenWallet.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/MultiSigTokenWallet.sol b/contracts/MultiSigTokenWallet.sol index c988fca..0a3a963 100644 --- a/contracts/MultiSigTokenWallet.sol +++ b/contracts/MultiSigTokenWallet.sol @@ -51,7 +51,6 @@ contract MultiSigTokenWallet is MultiSigWallet { bool result = ERC20(_token).transferFrom(_from, this, _amount); require(result); TokenDeposit(_token, _from, _amount); - } /** From 0678a18ec44ce902769f5c03dc23271fa7fbe4f8 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 9 Nov 2017 14:33:01 -0200 Subject: [PATCH 16/16] lint --- contracts/DelegatedCall.sol | 2 +- contracts/ERC20.sol | 12 ++++++------ contracts/MultiSigFactory.sol | 2 +- contracts/MultiSigStub.sol | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/contracts/DelegatedCall.sol b/contracts/DelegatedCall.sol index 18b2851..6ae754c 100644 --- a/contracts/DelegatedCall.sol +++ b/contracts/DelegatedCall.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.12; +pragma solidity ^0.4.18; /** * @title DelegatedCall diff --git a/contracts/ERC20.sol b/contracts/ERC20.sol index e82eabb..fb47128 100644 --- a/contracts/ERC20.sol +++ b/contracts/ERC20.sol @@ -1,12 +1,12 @@ -pragma solidity ^0.4.15; +pragma solidity ^0.4.18; contract ERC20 { uint256 public totalSupply; - function balanceOf(address who) constant returns (uint256); - function allowance(address owner, address spender) constant returns (uint256); - function transfer(address to, uint256 value) returns (bool ok); - function transferFrom(address from, address to, uint256 value) returns (bool ok); - function approve(address spender, uint256 value) returns (bool ok); + function balanceOf(address who) public constant returns (uint256); + function allowance(address owner, address spender) public constant returns (uint256); + function transfer(address to, uint256 value) public returns (bool ok); + function transferFrom(address from, address to, uint256 value) public returns (bool ok); + function approve(address spender, uint256 value) public returns (bool ok); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } \ No newline at end of file diff --git a/contracts/MultiSigFactory.sol b/contracts/MultiSigFactory.sol index 99e80ae..30a5ac3 100644 --- a/contracts/MultiSigFactory.sol +++ b/contracts/MultiSigFactory.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.15; +pragma solidity ^0.4.18; import "./MultiSigStub.sol"; diff --git a/contracts/MultiSigStub.sol b/contracts/MultiSigStub.sol index 6c7451b..709bda0 100644 --- a/contracts/MultiSigStub.sol +++ b/contracts/MultiSigStub.sol @@ -1,9 +1,10 @@ -pragma solidity ^0.4.15; +pragma solidity ^0.4.18; import "./DelegatedCall.sol"; /** * @title MultiSigStub + * @author Ricardo Guilherme Schmidt (Status Research & Development GmbH) * Contract that delegates calls to a library to build a full MultiSigWallet that is cheap to create. */ contract MultiSigStub is DelegatedCall {