Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade modules and wallet contracts to solidity 0.6.10 #114

Merged
merged 64 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
63c3478
Fix function visibility in ens contracts
elenadimitrova Apr 16, 2020
b88217d
Upgrade solc to 0.6.8
elenadimitrova May 18, 2020
d5025a8
Switch pragma to 0.6.8 on modules
elenadimitrova May 18, 2020
b877966
Switch etherlime coverage to use defult solc version
elenadimitrova May 18, 2020
c6ab6ed
Fix brackets in assembly calls
elenadimitrova May 18, 2020
9dfb82f
Add legacy contract dependencies to folder to keep compiling with sol…
elenadimitrova May 19, 2020
bb54a96
Abstract IModuleRegistry and ICompoundRegistry to allow them to be re…
elenadimitrova May 19, 2020
40d09b8
Set SPDX-License-Identifier to GPL-3.0-only
elenadimitrova May 19, 2020
18c2f16
Abstract IMakerRegistry contract
elenadimitrova May 20, 2020
65812a7
Upgrade openzeppelin-solidity library and move legacy SafeMath copy t…
elenadimitrova May 20, 2020
1a6064e
Move all test contracts and lib dependencies to solc 0.6.8
elenadimitrova May 20, 2020
d9d7d37
solc 0.6.8 fixes to the test contracts
elenadimitrova May 21, 2020
9db59ba
Make modules compile with 0.6.8
elenadimitrova May 26, 2020
3f1cdae
Update DSMath to actual latest copy from dappsys
elenadimitrova May 26, 2020
6d24376
Instantiate modules with the IModuleRegistry interface
elenadimitrova May 26, 2020
e4d78df
Fix DocstringParsingError set of errors in upgraded contracts
elenadimitrova May 26, 2020
abb12eb
Make legacy and test contracts compile
elenadimitrova May 26, 2020
b4f7e56
Add virtual,override,abstract where needed in module contracts for 0.6.8
elenadimitrova May 26, 2020
2478462
Convert MakerInterfaces contracts to interfaces
elenadimitrova May 26, 2020
7ed930d
Make getRequiredSignatures virtual and override in modules
elenadimitrova May 26, 2020
e33bbe0
Make checkAndUpdateUniqueness virtual and override in modules
elenadimitrova May 27, 2020
099defc
Remove multiple inheritance instances
elenadimitrova May 27, 2020
cba2a2b
Update reference to call{value: ...} in BaseWallet
elenadimitrova May 27, 2020
d2f52b3
Resolve inheritance issues in maker module
elenadimitrova May 27, 2020
c73970b
Override interface implementation explicitely
elenadimitrova May 27, 2020
b0f918f
Add explicit overrides for IGuardianStorage interface implementations
elenadimitrova May 27, 2020
440bffe
Fix array management calls in GuardianStorage
elenadimitrova May 27, 2020
e0492d9
Assorted fixes to virtual and override modifiers in modules
elenadimitrova May 27, 2020
9e0233b
Fix compilation errors with test, legacy and lib contracts
elenadimitrova May 28, 2020
7e569d9
Get test contracts to compile with solc 0.6.8
elenadimitrova May 28, 2020
2476bf3
Remove explicit npm run compile for test contracts as that's part of …
elenadimitrova May 28, 2020
96b8c56
Ignore upgraded contracts from solium which doesn't support 0.6 yet
elenadimitrova May 28, 2020
173493e
Split the fallback function to receive
elenadimitrova May 28, 2020
81e57ff
Remove compile:lib from generic compile command
elenadimitrova May 28, 2020
bc58e85
Make BaseModule non-abstract so we can instantiate it
elenadimitrova May 28, 2020
a633ad3
Re-add mistakenly removed transfer function
elenadimitrova May 29, 2020
722d259
Add missing mint function to ERC721 token test contract
elenadimitrova May 29, 2020
1433990
Shuffle compilation contract groups and change slither to not compile…
elenadimitrova May 29, 2020
7e26cc7
Move SafaMath 0.5.4 lib to legacy folder
elenadimitrova Jun 1, 2020
077ddb3
Revert changes to ENS infrastructure contracts
elenadimitrova Jun 1, 2020
75b972b
Switch openzeppelin package we target to newly introduced one
elenadimitrova Jun 3, 2020
4e7878f
Move legacy contracts out of contracts folder and their build artefac…
elenadimitrova Jun 4, 2020
113ad66
Separated hard dependencies between storage contracts, BaseWallet and…
elenadimitrova Jun 5, 2020
0d46744
Update circle ci config with the new build instructions
elenadimitrova Jun 5, 2020
6e0a37b
Use 0.6 syntax for create2 calls
elenadimitrova Jun 5, 2020
faeaaed
Update ganache-cli version
elenadimitrova Jun 8, 2020
6657a18
Make etherlime coverage work with more complex compilation setup
elenadimitrova Jun 8, 2020
56c4c5b
Remove fixed gasLimit in transactions
elenadimitrova Jun 9, 2020
40bfa7a
Fix slither run
elenadimitrova Jun 9, 2020
01aa8fa
Log Received event for non zero msg transfers only
elenadimitrova Jun 10, 2020
6537489
Adjust coverage thresholds for the new contracts folder structure
elenadimitrova Jun 10, 2020
8d389f2
Remove todo in code
elenadimitrova Jun 10, 2020
815b2b7
Switch to latest solidity 0.6.9
elenadimitrova Jun 10, 2020
07514f3
Upgrade etherlime-argent
elenadimitrova Jun 11, 2020
1cf397f
Fix storage contracts references in modules deployment
elenadimitrova Jun 12, 2020
d4cda69
Make addModule function public and override external interface defini…
elenadimitrova Jun 12, 2020
8d56f4d
Remove event from BaseWallet receive function
elenadimitrova Jun 12, 2020
77fe198
Reshuffle legacy contracts to dedicated release folders
elenadimitrova Jun 12, 2020
7dd2952
Emit Received event in Proxy on 0 value transfers
elenadimitrova Jun 12, 2020
eb486ae
Switch to solc 0.6.10
elenadimitrova Jun 12, 2020
92c4209
Stop overriding BaseWallet.invoke to make it non-virtual
elenadimitrova Jun 15, 2020
65e4074
Use Proxy when testing Wallet logic
elenadimitrova Jun 15, 2020
a585e98
Rename 1.5 to 1.6 to match respective release number
elenadimitrova Jun 15, 2020
1cd7ef8
Replace legacy transfer manager for tests with one version earlier - 1.6
elenadimitrova Jun 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ jobs:
- run:
name: "Compiling external library contracts"
command: npm run compile:lib
- run:
name: "Compiling legacy contracts"
command: npm run compile:legacy
- run:
name: "Compiling contracts"
command: npm run compile
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
build
build-legacy
tmp
bin
.outputParameter
Expand Down
4 changes: 3 additions & 1 deletion .soliumignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ migrations
openzeppelin-solidity
lib
contracts-test
contracts/legacy/LegacyBaseWallet.sol
contracts-legacy
contracts/modules
contracts/wallet
158 changes: 158 additions & 0 deletions contracts-legacy/v1.3.0/BaseModule.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
// Copyright (C) 2018 Argent Labs Ltd. <https://argent.xyz>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.5.4;
import "./SafeMath.sol";
import "./BaseWallet.sol";
import "../../contracts/infrastructure/ModuleRegistry.sol";
import "./GuardianStorage.sol";
import "./Module.sol";

/**
* @title BaseModule
* @dev Basic module that contains some methods common to all modules.
* @author Julien Niset - <julien@argent.im>
*/
contract BaseModule is Module {

// Empty calldata
bytes constant internal EMPTY_BYTES = "";

// The adddress of the module registry.
ModuleRegistry internal registry;
// The address of the Guardian storage
GuardianStorage internal guardianStorage;

/**
* @dev Throws if the wallet is locked.
*/
modifier onlyWhenUnlocked(BaseWallet _wallet) {
verifyUnlocked(_wallet);
_;
}

event ModuleCreated(bytes32 name);
event ModuleInitialised(address wallet);

constructor(ModuleRegistry _registry, GuardianStorage _guardianStorage, bytes32 _name) public {
registry = _registry;
guardianStorage = _guardianStorage;
emit ModuleCreated(_name);
}

/**
* @dev Throws if the sender is not the target wallet of the call.
*/
modifier onlyWallet(BaseWallet _wallet) {
require(msg.sender == address(_wallet), "BM: caller must be wallet");
_;
}

/**
* @dev Throws if the sender is not the owner of the target wallet or the module itself.
*/
modifier onlyWalletOwner(BaseWallet _wallet) {
// Wrapping in an internal method reduces deployment cost by avoiding duplication of inlined code
verifyWalletOwner(_wallet);
_;
}

/**
* @dev Throws if the sender is not the owner of the target wallet.
*/
modifier strictOnlyWalletOwner(BaseWallet _wallet) {
require(isOwner(_wallet, msg.sender), "BM: msg.sender must be an owner for the wallet");
_;
}

/**
* @dev Inits the module for a wallet by logging an event.
* The method can only be called by the wallet itself.
* @param _wallet The wallet.
*/
function init(BaseWallet _wallet) public onlyWallet(_wallet) {
emit ModuleInitialised(address(_wallet));
}

/**
* @dev Adds a module to a wallet. First checks that the module is registered.
* @param _wallet The target wallet.
* @param _module The modules to authorise.
*/
function addModule(BaseWallet _wallet, Module _module) external strictOnlyWalletOwner(_wallet) {
require(registry.isRegisteredModule(address(_module)), "BM: module is not registered");
_wallet.authoriseModule(address(_module), true);
}

/**
* @dev Utility method enbaling anyone to recover ERC20 token sent to the
* module by mistake and transfer them to the Module Registry.
* @param _token The token to recover.
*/
function recoverToken(address _token) external {
uint total = ERC20(_token).balanceOf(address(this));
bool success = ERC20(_token).transfer(address(registry), total);
require(success, "BM: recover token transfer failed");
}

/**
* @dev Verify that the wallet is unlocked.
* @param _wallet The target wallet.
*/
function verifyUnlocked(BaseWallet _wallet) internal view {
require(!guardianStorage.isLocked(_wallet), "BM: wallet locked");
}

/**
* @dev Verify that the caller is the module or the wallet owner.
* @param _wallet The target wallet.
*/
function verifyWalletOwner(BaseWallet _wallet) internal view {
require(msg.sender == address(this) || isOwner(_wallet, msg.sender), "BM: must be wallet owner");
}

/**
* @dev Helper method to check if an address is the owner of a target wallet.
* @param _wallet The target wallet.
* @param _addr The address.
*/
function isOwner(BaseWallet _wallet, address _addr) internal view returns (bool) {
return _wallet.owner() == _addr;
}

/**
* @dev Helper method to invoke a wallet.
* @param _wallet The target wallet.
* @param _to The target address for the transaction.
* @param _value The value of the transaction.
* @param _data The data of the transaction.
*/
function invokeWallet(address _wallet, address _to, uint256 _value, bytes memory _data) internal returns (bytes memory _res) {
bool success;
// solium-disable-next-line security/no-call-value
(success, _res) = _wallet.call(abi.encodeWithSignature("invoke(address,uint256,bytes)", _to, _value, _data));
if (success && _res.length > 0) { //_res is empty if _wallet is an "old" BaseWallet that can't return output values
(_res) = abi.decode(_res, (bytes));
} else if (_res.length > 0) {
// solium-disable-next-line security/no-inline-assembly
assembly {
returndatacopy(0, 0, returndatasize)
revert(0, returndatasize)
}
} else if (!success) {
revert("BM: wallet invoke reverted");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
pragma solidity ^0.5.4;

import "./Module.sol";

/**
* @title LegacyBaseWallet
* @title BaseWallet
* @dev Simple modular wallet that authorises modules to call its invoke() method.
* Based on https://gist.github.com/Arachnid/a619d31f6d32757a4328a428286da186 by
* @author Julien Niset - <julien@argent.im>
*/

interface LegacyModule {

/**
* @dev Inits a module for a wallet by e.g. setting some wallet specific parameters in storage.
* @param _wallet The wallet.
*/
function init(LegacyBaseWallet _wallet) external;

/**
* @dev Adds a module to a wallet.
* @param _wallet The target wallet.
* @param _module The modules to authorise.
*/
function addModule(LegacyBaseWallet _wallet, LegacyModule _module) external;

/**
* @dev Utility method to recover any ERC20 token that was sent to the
* module by mistake.
* @param _token The token to recover.
*/
function recoverToken(address _token) external;
}

contract LegacyBaseWallet {
contract BaseWallet {

// The implementation of the proxy
address public implementation;
Expand Down Expand Up @@ -70,7 +48,7 @@ contract LegacyBaseWallet {
for(uint256 i = 0; i < _modules.length; i++) {
require(authorised[_modules[i]] == false, "BW: module is already added");
authorised[_modules[i]] = true;
LegacyModule(_modules[i]).init(this);
Module(_modules[i]).init(this);
emit AuthorisedModule(_modules[i], true);
}
}
Expand All @@ -85,7 +63,7 @@ contract LegacyBaseWallet {
if(_value == true) {
modules += 1;
authorised[_module] = true;
LegacyModule(_module).init(this);
Module(_module).init(this);
}
else {
modules -= 1;
Expand Down
14 changes: 14 additions & 0 deletions contracts-legacy/v1.3.0/ERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pragma solidity ^0.5.4;

/**
* ERC20 contract interface.
*/
contract ERC20 {
function totalSupply() public view returns (uint);
function decimals() public view returns (uint);
function balanceOf(address tokenOwner) public view returns (uint balance);
function allowance(address tokenOwner, address spender) public view returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.5.4;
import "../../wallet/BaseWallet.sol";
import "./BaseWallet.sol";
import "./Storage.sol";
import "./IGuardianStorage.sol";

Expand Down
88 changes: 88 additions & 0 deletions contracts-legacy/v1.3.0/GuardianUtils.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (C) 2018 Argent Labs Ltd. <https://argent.xyz>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.5.4;

library GuardianUtils {

/**
* @dev Checks if an address is an account guardian or an account authorised to sign on behalf of a smart-contract guardian
* given a list of guardians.
* @param _guardians the list of guardians
* @param _guardian the address to test
* @return true and the list of guardians minus the found guardian upon success, false and the original list of guardians if not found.
*/
function isGuardian(address[] memory _guardians, address _guardian) internal view returns (bool, address[] memory) {
if (_guardians.length == 0 || _guardian == address(0)) {
return (false, _guardians);
}
bool isFound = false;
address[] memory updatedGuardians = new address[](_guardians.length - 1);
uint256 index = 0;
for (uint256 i = 0; i < _guardians.length; i++) {
if (!isFound) {
// check if _guardian is an account guardian
if (_guardian == _guardians[i]) {
isFound = true;
continue;
}
// check if _guardian is the owner of a smart contract guardian
if (isContract(_guardians[i]) && isGuardianOwner(_guardians[i], _guardian)) {
isFound = true;
continue;
}
}
if (index < updatedGuardians.length) {
updatedGuardians[index] = _guardians[i];
index++;
}
}
return isFound ? (true, updatedGuardians) : (false, _guardians);
}

/**
* @dev Checks if an address is a contract.
* @param _addr The address.
*/
function isContract(address _addr) internal view returns (bool) {
uint32 size;
// solium-disable-next-line security/no-inline-assembly
assembly {
size := extcodesize(_addr)
}
return (size > 0);
}

/**
* @dev Checks if an address is the owner of a guardian contract.
* The method does not revert if the call to the owner() method consumes more then 5000 gas.
* @param _guardian The guardian contract
* @param _owner The owner to verify.
*/
function isGuardianOwner(address _guardian, address _owner) internal view returns (bool) {
address owner = address(0);
bytes4 sig = bytes4(keccak256("owner()"));
// solium-disable-next-line security/no-inline-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr,sig)
let result := staticcall(5000, _guardian, ptr, 0x20, ptr, 0x20)
if eq(result, 1) {
owner := mload(ptr)
}
}
return owner == _owner;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.5.4;
import "../../wallet/BaseWallet.sol";
import "./BaseWallet.sol";

interface IGuardianStorage{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.5.4;
import "../../wallet/BaseWallet.sol";
import "./BaseWallet.sol";

/**
* @title Module
Expand Down
Loading