Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/npm_and_yarn/deploy/lodash-4.1…
Browse files Browse the repository at this point in the history
…7.15
  • Loading branch information
akolotov committed Aug 7, 2019
2 parents 28b68b7 + b219246 commit 72dff2d
Show file tree
Hide file tree
Showing 63 changed files with 11,480 additions and 5,773 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ node_js:
cache:
yarn: true
env:
- SOLIDITY_COVERAGE=false
- SOLIDITY_COVERAGE=true
script:
- yarn lint
- yarn test
- $TASK=lint
- $TASK=test
- $TASK=coverage
- $TASK=test:gasreport:ci
script: "npm run $TASK"
6 changes: 6 additions & 0 deletions codechecks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
checks:
- name: eth-gas-reporter/codechecks
settings:
branches:
- develop
- master
16 changes: 5 additions & 11 deletions contracts/ERC677BridgeToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.4.24;
import "openzeppelin-solidity/contracts/token/ERC20/BurnableToken.sol";
import "openzeppelin-solidity/contracts/token/ERC20/MintableToken.sol";
import "openzeppelin-solidity/contracts/token/ERC20/DetailedERC20.sol";
import "openzeppelin-solidity/contracts/AddressUtils.sol";
import "./interfaces/IBurnableMintableERC677Token.sol";
import "./upgradeable_contracts/Claimable.sol";

Expand All @@ -16,20 +17,21 @@ contract ERC677BridgeToken is IBurnableMintableERC677Token, DetailedERC20, Burna
}

function setBridgeContract(address _bridgeContract) external onlyOwner {
require(isContract(_bridgeContract));
require(AddressUtils.isContract(_bridgeContract));
bridgeContract = _bridgeContract;
}

modifier validRecipient(address _recipient) {
require(_recipient != address(0) && _recipient != address(this));
/* solcov ignore next */
_;
}

function transferAndCall(address _to, uint256 _value, bytes _data) external validRecipient(_to) returns (bool) {
require(superTransfer(_to, _value));
emit Transfer(msg.sender, _to, _value, _data);

if (isContract(_to)) {
if (AddressUtils.isContract(_to)) {
require(contractFallback(msg.sender, _to, _value, _data));
}
return true;
Expand All @@ -56,7 +58,7 @@ contract ERC677BridgeToken is IBurnableMintableERC677Token, DetailedERC20, Burna
}

function callAfterTransfer(address _from, address _to, uint256 _value) internal {
if (isContract(_to) && !contractFallback(_from, _to, _value, new bytes(0))) {
if (AddressUtils.isContract(_to) && !contractFallback(_from, _to, _value, new bytes(0))) {
require(_to != bridgeContract);
emit ContractFallbackCallFailed(_from, _to, _value);
}
Expand All @@ -66,14 +68,6 @@ contract ERC677BridgeToken is IBurnableMintableERC677Token, DetailedERC20, Burna
return _to.call(abi.encodeWithSignature("onTokenTransfer(address,uint256,bytes)", _from, _value, _data));
}

function isContract(address _addr) internal view returns (bool) {
uint256 length;
assembly {
length := extcodesize(_addr)
}
return length > 0;
}

function finishMinting() public returns (bool) {
revert();
}
Expand Down
15 changes: 4 additions & 11 deletions contracts/ERC677BridgeTokenRewardable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@ contract ERC677BridgeTokenRewardable is ERC677BridgeToken {
}

function setBlockRewardContract(address _blockRewardContract) external onlyOwner {
require(isContract(_blockRewardContract));
require(AddressUtils.isContract(_blockRewardContract));
blockRewardContract = _blockRewardContract;
}

function setStakingContract(address _stakingContract) external onlyOwner {
require(isContract(_stakingContract));
require(AddressUtils.isContract(_stakingContract));
stakingContract = _stakingContract;
}

modifier onlyBlockRewardContract() {
require(msg.sender == blockRewardContract);
/* solcov ignore next */
_;
}

modifier onlyStakingContract() {
require(msg.sender == stakingContract);
/* solcov ignore next */
_;
}

Expand All @@ -49,20 +51,11 @@ contract ERC677BridgeTokenRewardable is ERC677BridgeToken {

function stake(address _staker, uint256 _amount) external onlyStakingContract {
// Transfer `_amount` from `_staker` to `stakingContract`
require(_amount <= balances[_staker]);
balances[_staker] = balances[_staker].sub(_amount);
balances[stakingContract] = balances[stakingContract].add(_amount);
emit Transfer(_staker, stakingContract, _amount);
}

function withdraw(address _staker, uint256 _amount) external onlyStakingContract {
// Transfer `_amount` from `stakingContract` to `_staker`
require(_amount <= balances[stakingContract]);
balances[stakingContract] = balances[stakingContract].sub(_amount);
balances[_staker] = balances[_staker].add(_amount);
emit Transfer(stakingContract, _staker, _amount);
}

function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != stakingContract);
return super.transfer(_to, _value);
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IBurnableMintableERC677Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pragma solidity 0.4.24;
import "../interfaces/ERC677.sol";

contract IBurnableMintableERC677Token is ERC677 {
function mint(address, uint256) public returns (bool);
function mint(address _to, uint256 _amount) public returns (bool);
function burn(uint256 _value) public;
function claimTokens(address _token, address _to) public;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ contract BlockReward {
uint256 public feeAmount = 0;
mapping(bytes32 => uint256) internal uintStorage;
bytes32 internal constant MINTED_TOTALLY_BY_BRIDGE = "mintedTotallyByBridge";
bytes4 internal constant MINT_REWARD = 0xe2f764a3; // mintReward(address[],uint256[])
address public token;

function() external payable {
Expand Down Expand Up @@ -86,7 +87,7 @@ contract BlockReward {
rewards[i] = feeToDistribute;
}

require(token.call(abi.encodeWithSignature("mintReward(address[],uint256[])", receivers, rewards)));
require(token.call(abi.encodeWithSelector(MINT_REWARD, receivers, rewards)));
}

function random(uint256 _count) public view returns (uint256) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
pragma solidity 0.4.24;

import "../../contracts/ERC677BridgeTokenRewardable.sol";
import "../ERC677BridgeTokenRewardable.sol";

contract ERC677BridgeTokenRewardableMock is ERC677BridgeTokenRewardable {
constructor(string _name, string _symbol, uint8 _decimals)
public
ERC677BridgeTokenRewardable(_name, _symbol, _decimals)
{}
{
// solhint-disable-previous-line no-empty-blocks
}

function setBlockRewardContractMock(address _blockRewardContract) public {
blockRewardContract = _blockRewardContract;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.4.19;
pragma solidity 0.4.24;

import "../../contracts/interfaces/ERC677Receiver.sol";
import "../interfaces/ERC677Receiver.sol";

contract ERC677ReceiverTest is ERC677Receiver {
address public from;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.4.19;
pragma solidity 0.4.24;

import "../../contracts/upgradeable_contracts/native_to_erc20/ForeignBridgeNativeToErc.sol";
import "../upgradeable_contracts/native_to_erc20/ForeignBridgeNativeToErc.sol";

interface OwnableToken {
function transferOwnership(address) external;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ contract NoReturnTransferTokenMock {
return balances[_owner];
}

// solhint-disable-next-line no-simple-event-func-name
function transfer(address _to, uint256 _value) public {
require(_value <= balances[msg.sender]);
require(_to != address(0));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity 0.4.24;

contract oldBlockReward {
contract OldBlockReward {
function bridgesAllowedLength() external view returns (uint256) {
return 3;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ contract RevertFallback {
revert();
}

function receiveEth() public payable {}
function receiveEth() public payable {
// solhint-disable-previous-line no-empty-blocks
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion contracts/upgradeability/EternalStorageProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ import "./OwnedUpgradeabilityProxy.sol";
* authorization control functionalities
*/
// solhint-disable-next-line no-empty-blocks
contract EternalStorageProxy is OwnedUpgradeabilityProxy, EternalStorage {}
contract EternalStorageProxy is EternalStorage, OwnedUpgradeabilityProxy {}
1 change: 1 addition & 0 deletions contracts/upgradeability/OwnedUpgradeabilityProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ contract OwnedUpgradeabilityProxy is UpgradeabilityOwnerStorage, UpgradeabilityP
*/
modifier onlyUpgradeabilityOwner() {
require(msg.sender == upgradeabilityOwner());
/* solcov ignore next */
_;
}

Expand Down
1 change: 1 addition & 0 deletions contracts/upgradeability/Proxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ contract Proxy {
* @dev Tells the address of the implementation where every call will be delegated.
* @return address of the implementation to which it will be delegated
*/
/* solcov ignore next */
function implementation() public view returns (address);

/**
Expand Down
2 changes: 2 additions & 0 deletions contracts/upgradeability/UpgradeabilityProxy.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pragma solidity 0.4.24;

import "openzeppelin-solidity/contracts/AddressUtils.sol";
import "./Proxy.sol";
import "./UpgradeabilityStorage.sol";

Expand All @@ -22,6 +23,7 @@ contract UpgradeabilityProxy is Proxy, UpgradeabilityStorage {
*/
function _upgradeTo(uint256 version, address implementation) internal {
require(_implementation != implementation);
require(AddressUtils.isContract(implementation));
require(version > _version);
_version = version;
_implementation = implementation;
Expand Down
2 changes: 1 addition & 1 deletion contracts/upgradeability/UpgradeabilityStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract UpgradeabilityStorage {

/**
* @dev Tells the version name of the current implementation
* @return string representing the name of the current version
* @return uint256 representing the name of the current version
*/
function version() external view returns (uint256) {
return _version;
Expand Down
26 changes: 8 additions & 18 deletions contracts/upgradeable_contracts/BaseBridgeValidators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ pragma solidity 0.4.24;

import "./Ownable.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "../upgradeability/EternalStorage.sol";
import "./Initializable.sol";

contract BaseBridgeValidators is EternalStorage, Ownable {
contract BaseBridgeValidators is Initializable, Ownable {
using SafeMath for uint256;

address public constant F_ADDR = 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF;
uint256 internal constant MAX_VALIDATORS = 100;
bytes32 internal constant REQUIRED_SIGNATURES = keccak256(abi.encodePacked("requiredSignatures"));
bytes32 internal constant VALIDATOR_COUNT = keccak256(abi.encodePacked("validatorCount"));

event ValidatorAdded(address indexed validator);
event ValidatorRemoved(address indexed validator);
Expand All @@ -17,7 +19,7 @@ contract BaseBridgeValidators is EternalStorage, Ownable {
function setRequiredSignatures(uint256 _requiredSignatures) external onlyOwner {
require(validatorCount() >= _requiredSignatures);
require(_requiredSignatures != 0);
uintStorage[keccak256(abi.encodePacked("requiredSignatures"))] = _requiredSignatures;
uintStorage[REQUIRED_SIGNATURES] = _requiredSignatures;
emit RequiredSignaturesChanged(_requiredSignatures);
}

Expand Down Expand Up @@ -74,25 +76,17 @@ contract BaseBridgeValidators is EternalStorage, Ownable {
}

function requiredSignatures() public view returns (uint256) {
return uintStorage[keccak256(abi.encodePacked("requiredSignatures"))];
return uintStorage[REQUIRED_SIGNATURES];
}

function validatorCount() public view returns (uint256) {
return uintStorage[keccak256(abi.encodePacked("validatorCount"))];
return uintStorage[VALIDATOR_COUNT];
}

function isValidator(address _validator) public view returns (bool) {
return _validator != F_ADDR && getNextValidator(_validator) != address(0);
}

function isInitialized() public view returns (bool) {
return boolStorage[keccak256(abi.encodePacked("isInitialized"))];
}

function deployedAtBlock() external view returns (uint256) {
return uintStorage[keccak256(abi.encodePacked("deployedAtBlock"))];
}

function getNextValidator(address _address) public view returns (address) {
return addressStorage[keccak256(abi.encodePacked("validatorsList", _address))];
}
Expand All @@ -102,14 +96,10 @@ contract BaseBridgeValidators is EternalStorage, Ownable {
}

function setValidatorCount(uint256 _validatorCount) internal {
uintStorage[keccak256(abi.encodePacked("validatorCount"))] = _validatorCount;
uintStorage[VALIDATOR_COUNT] = _validatorCount;
}

function setNextValidator(address _prevValidator, address _validator) internal {
addressStorage[keccak256(abi.encodePacked("validatorsList", _prevValidator))] = _validator;
}

function setInitialize() internal {
boolStorage[keccak256(abi.encodePacked("isInitialized"))] = true;
}
}
14 changes: 10 additions & 4 deletions contracts/upgradeable_contracts/BaseFeeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ contract BaseFeeManager is EternalStorage, FeeTypes {

// This is not a real fee value but a relative value used to calculate the fee percentage
uint256 internal constant MAX_FEE = 1 ether;
bytes32 internal constant HOME_FEE_STORAGE_KEY = keccak256(abi.encodePacked("homeFee"));
bytes32 internal constant FOREIGN_FEE_STORAGE_KEY = keccak256(abi.encodePacked("foreignFee"));

function calculateFee(uint256 _value, bool _recover, bytes32 _feeType) public view returns (uint256) {
uint256 fee = _feeType == HOME_FEE ? getHomeFee() : getForeignFee();
Expand All @@ -24,31 +26,35 @@ contract BaseFeeManager is EternalStorage, FeeTypes {

modifier validFee(uint256 _fee) {
require(_fee < MAX_FEE);
/* solcov ignore next */
_;
}

function setHomeFee(uint256 _fee) external validFee(_fee) {
uintStorage[keccak256(abi.encodePacked("homeFee"))] = _fee;
uintStorage[HOME_FEE_STORAGE_KEY] = _fee;
emit HomeFeeUpdated(_fee);
}

function getHomeFee() public view returns (uint256) {
return uintStorage[keccak256(abi.encodePacked("homeFee"))];
return uintStorage[HOME_FEE_STORAGE_KEY];
}

function setForeignFee(uint256 _fee) external validFee(_fee) {
uintStorage[keccak256(abi.encodePacked("foreignFee"))] = _fee;
uintStorage[FOREIGN_FEE_STORAGE_KEY] = _fee;
emit ForeignFeeUpdated(_fee);
}

function getForeignFee() public view returns (uint256) {
return uintStorage[keccak256(abi.encodePacked("foreignFee"))];
return uintStorage[FOREIGN_FEE_STORAGE_KEY];
}

/* solcov ignore next */
function distributeFeeFromAffirmation(uint256 _fee) external;

/* solcov ignore next */
function distributeFeeFromSignatures(uint256 _fee) external;

/* solcov ignore next */
function getFeeManagerMode() external pure returns (bytes4);

function random(uint256 _count) internal view returns (uint256) {
Expand Down

0 comments on commit 72dff2d

Please sign in to comment.