Skip to content

Commit

Permalink
Merge branch 'develop' into arbitrary-message-bridging-#73
Browse files Browse the repository at this point in the history
# Conflicts:
#	deploy/src/loadEnv.js
#	package-lock.json
  • Loading branch information
patitonar committed Jul 17, 2019
2 parents 0cb5c23 + a747842 commit d3e319f
Show file tree
Hide file tree
Showing 18 changed files with 277 additions and 105 deletions.
7 changes: 2 additions & 5 deletions contracts/ERC677BridgeToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ contract ERC677BridgeToken is

function callAfterTransfer(address _from, address _to, uint256 _value) internal {
if (isContract(_to) && !contractFallback(_from, _to, _value, new bytes(0))) {
if (_to == bridgeContract) {
revert();
} else {
emit ContractFallbackCallFailed(_from, _to, _value);
}
require(_to != bridgeContract);
emit ContractFallbackCallFailed(_from, _to, _value);
}
}

Expand Down
4 changes: 1 addition & 3 deletions contracts/libraries/Message.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ library Message {
for (uint256 i = 0; i < requiredSignatures; i++) {
address recoveredAddress = ecrecover(hash, _vs[i], _rs[i], _ss[i]);
require(_validatorContract.isValidator(recoveredAddress));
if (addressArrayContains(encounteredAddresses, recoveredAddress)) {
revert();
}
require(!addressArrayContains(encounteredAddresses, recoveredAddress));
encounteredAddresses[i] = recoveredAddress;
}
}
Expand Down
9 changes: 3 additions & 6 deletions contracts/upgradeable_contracts/BaseBridgeValidators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ contract BaseBridgeValidators is EternalStorage, Ownable {
using SafeMath for uint256;

address public constant F_ADDR = 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF;
uint256 internal constant MAX_VALIDATORS = 100;

event ValidatorAdded (address indexed validator);
event ValidatorRemoved (address indexed validator);
Expand Down Expand Up @@ -43,9 +44,7 @@ contract BaseBridgeValidators is EternalStorage, Ownable {
nextValidator = getNextValidator(nextValidator);
counter++;

if (nextValidator == address(0) ) {
revert();
}
require(nextValidator != address(0));
}

return list;
Expand Down Expand Up @@ -74,9 +73,7 @@ contract BaseBridgeValidators is EternalStorage, Ownable {
index = next;
next = getNextValidator(index);

if (next == F_ADDR || next == address(0) ) {
revert();
}
require(next != F_ADDR && next != address(0));
}

setNextValidator(index, validatorsNext);
Expand Down
1 change: 1 addition & 0 deletions contracts/upgradeable_contracts/BridgeValidators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ contract BridgeValidators is BaseBridgeValidators {
setOwner(_owner);
require(_requiredSignatures != 0);
require(_initialValidators.length >= _requiredSignatures);
require(_initialValidators.length <= MAX_VALIDATORS);

for (uint256 i = 0; i < _initialValidators.length; i++) {
require(_initialValidators[i] != address(0) && _initialValidators[i] != F_ADDR);
Expand Down
1 change: 1 addition & 0 deletions contracts/upgradeable_contracts/RewardableValidators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ contract RewardableValidators is BaseBridgeValidators {
setOwner(_owner);
require(_requiredSignatures != 0);
require(_initialValidators.length >= _requiredSignatures);
require(_initialValidators.length <= MAX_VALIDATORS);
require(_initialValidators.length == _initialRewards.length);

for (uint256 i = 0; i < _initialValidators.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ contract HomeBridgeErcToErc is ERC677Receiver, EternalStorage, BasicHomeBridge,
{
require(!isInitialized());
require(isContract(_validatorContract));
require(_homeGasPrice > 0);
require(_requiredBlockConfirmations > 0);
require(_minPerTx > 0 && _maxPerTx > _minPerTx && _dailyLimit > _maxPerTx);
require(_foreignMaxPerTx < _foreignDailyLimit);
Expand Down
6 changes: 4 additions & 2 deletions deploy/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ const { BRIDGE_MODE, ERC20_TOKEN_ADDRESS } = env
const deployResultsPath = path.join(__dirname, './bridgeDeploymentResults.json')

async function deployNativeToErc() {
const preDeploy = require('./src/native_to_erc/preDeploy')
const deployHome = require('./src/native_to_erc/home')
const deployForeign = require('./src/native_to_erc/foreign')

await preDeploy()
const { homeBridge } = await deployHome()
const { foreignBridge, erc677 } = await deployForeign()
console.log('\nDeployment has been completed.\n\n')
Expand Down Expand Up @@ -79,9 +80,10 @@ async function deployErcToErc() {
}

async function deployErcToNative() {
const preDeploy = require('./src/erc_to_native/preDeploy')
const deployHome = require('./src/erc_to_native/home')
const deployForeign = require('./src/erc_to_native/foreign')

await preDeploy()
const { homeBridge } = await deployHome()
const { foreignBridge } = await deployForeign()
console.log('\nDeployment has been completed.\n\n')
Expand Down
8 changes: 7 additions & 1 deletion deploy/src/deploymentUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ function getSendTxMethod(url) {
return url === HOME_RPC_URL ? sendRawTxHome : sendRawTxForeign
}

async function isContract(web3, address) {
const code = await web3.eth.getCode(address)
return code !== '0x' && code !== '0x0'
}

module.exports = {
deployContract,
sendRawTxHome,
Expand All @@ -307,5 +312,6 @@ module.exports = {
transferProxyOwnership,
transferOwnership,
setBridgeContract,
assertStateWithRetry
assertStateWithRetry,
isContract
}
31 changes: 29 additions & 2 deletions deploy/src/erc_to_erc/preDeploy.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
const { web3Foreign } = require('../web3')
const { ERC20_TOKEN_ADDRESS, ERC20_EXTENDED_BY_ERC677 } = require('../loadEnv')
const { web3Home, web3Foreign } = require('../web3')
const {
ERC20_TOKEN_ADDRESS,
ERC20_EXTENDED_BY_ERC677,
HOME_REWARDABLE,
BLOCK_REWARD_ADDRESS,
DEPLOY_REWARDABLE_TOKEN,
DPOS_STAKING_ADDRESS
} = require('../loadEnv')
const { isContract } = require('../deploymentUtils')
const {
foreignContracts: {
ERC677BridgeToken: { abi }
}
} = require('../loadContracts')

async function preDeploy() {
const isERC20AContract = await isContract(web3Foreign, ERC20_TOKEN_ADDRESS)
if (!isERC20AContract) {
throw new Error(`ERC20_TOKEN_ADDRESS should be a contract address`)
}

if (DEPLOY_REWARDABLE_TOKEN) {
const isDPOSStakingAContract = await isContract(web3Foreign, DPOS_STAKING_ADDRESS)
if (!isDPOSStakingAContract) {
throw new Error(`DPOS_STAKING_ADDRESS should be a contract address`)
}
}

if (HOME_REWARDABLE === 'BOTH_DIRECTIONS') {
const isBlockRewardAContract = await isContract(web3Home, BLOCK_REWARD_ADDRESS)
if (!isBlockRewardAContract) {
throw new Error(`BLOCK_REWARD_ADDRESS should be a contract address`)
}
}

if (ERC20_EXTENDED_BY_ERC677) {
const tokenContract = new web3Foreign.eth.Contract(abi, ERC20_TOKEN_ADDRESS)
try {
Expand Down
12 changes: 12 additions & 0 deletions deploy/src/erc_to_native/preDeploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { web3Foreign } = require('../web3')
const { ERC20_TOKEN_ADDRESS } = require('../loadEnv')
const { isContract } = require('../deploymentUtils')

async function preDeploy() {
const isERC20AContract = await isContract(web3Foreign, ERC20_TOKEN_ADDRESS)
if (!isERC20AContract) {
throw new Error(`ERC20_TOKEN_ADDRESS should be a contract address`)
}
}

module.exports = preDeploy
Loading

0 comments on commit d3e319f

Please sign in to comment.