Skip to content

Commit

Permalink
Merge branch 'develop' release 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
elenadimitrova committed Oct 9, 2020
2 parents 63aefca + f08c325 commit 91e0dcf
Show file tree
Hide file tree
Showing 358 changed files with 33,542 additions and 9,178 deletions.
53 changes: 46 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ version: 2

job_common: &job_common
docker:
- image: circleci/node:10.12-stretch
- image: circleci/node:10.21-stretch
working_directory: ~/argent-contracts
job_python: &job_python
docker:
- image: circleci/python:3.8.0b1-stretch-node
working_directory: ~/argent-contracts
step_save_cache: &step_save_cache
save_cache:
Expand All @@ -18,7 +22,14 @@ step_setup_global_packages: &step_setup_global_packages
name: "Set up global packages"
command: |
npm install
step_setup_slither: &step_setup_slither
run:
name: "Setup slither analyser https://github.com/crytic/slither"
command: |
wget https://github.com/ethereum/solidity/releases/download/v0.5.4/solc-static-linux
chmod +x solc-static-linux
sudo mv solc-static-linux /usr/local/bin/solc
sudo pip3 install slither-analyzer
jobs:
unit-test:
<<: *job_common
Expand All @@ -29,31 +40,59 @@ jobs:
- run:
name: "Lint Solidity contracts"
command: npm run lint:contracts
- run:
name: "Testing deployment scripts and benchmark gas costs"
command: npm run ganache >/dev/null 2>&1 & npm run test:deployment && npm run test:benchmark
- 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
- run:
name: "Compiling test contracts"
command: npm run compile:test
- run:
name: "Lint JavaScript"
command: npm run lint:js
- run:
name: "Running unit tests"
command: npm run ganache >/dev/null 2>&1 & npm run test
- run:
name: "Testing deployment scripts"
command: npm run ganache >/dev/null 2>&1 & npm run test:deployment
- run:
name: "Running coverage"
command: npm run test:coverage
command: |
npm run compile
npm run compile:test
npm run test:coverage
- <<: *step_save_cache
# Save coverage artifacts
- store_artifacts:
path: coverage

security-test:
<<: *job_python
steps:
- checkout
- <<: *step_restore_cache
- <<: *step_setup_global_packages
- <<: *step_setup_slither
- run:
name: "Run slither"
command: npm run security:slither
workflows:
version: 2
commit:
jobs:
- unit-test
nightly:
triggers:
- schedule:
cron: "0 1 * * *" # 1am UTC
filters:
branches:
only:
- develop
jobs:
- security-test
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

build/*
contracts/*
contracts-test/*
coverage/*
lib/*
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
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.12.0
10.21.0
14 changes: 14 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "solhint:recommended",
"plugins": [],
"rules": {
"compiler-version": ["off"],
"no-inline-assembly": ["error"],
"not-rely-on-time": ["off"],
"avoid-low-level-calls": ["off"],
"max-line-length": ["error", 150],
"func-param-name-mixedcase": "error",
"modifier-name-mixedcase": "error",
"reason-string": ["warn", { "maxLength":32 }]
}
}
5 changes: 5 additions & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
lib
contracts-test
contracts-legacy
contracts/infrastructure_0.5
6 changes: 0 additions & 6 deletions .soliumignore

This file was deleted.

14 changes: 0 additions & 14 deletions .soliumrc.json

This file was deleted.

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ Compile the contracts:
npm run compile
```

Compile the test contracts:
```
npm run compile:test
```

## Test

Launch ganache:
Expand All @@ -39,6 +44,12 @@ Run the tests:
npm run test
```

To run coverage testing:
```
npm run test:coverage
```
You need to not have `ganache` running with this as it uses own instance.

## License

Released under [GPL-3.0](LICENSE)
Binary file added audit/ArgentUpdateSep2020.pdf
Binary file not shown.
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 "./ModuleRegistry.sol";
import "./GuardianStorage.sol";
import "./Module.sol";

/**
* @title BaseModule
* @dev Basic module that contains some methods common to all modules.
* @author Julien Niset - <[email protected]>
*/
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");
}
}
}
Loading

0 comments on commit 91e0dcf

Please sign in to comment.