diff --git a/contracts/BSCValidatorSet.sol b/contracts/BSCValidatorSet.sol index 9fb7bef56..4be32dd7f 100644 --- a/contracts/BSCValidatorSet.sol +++ b/contracts/BSCValidatorSet.sol @@ -93,7 +93,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica function init() external onlyNotInit{ (IbcValidatorSetPackage memory validatorSetPkg, bool valid)= decodeValidatorSetSynPackage(INIT_VALIDATORSET_BYTES); require(valid, "failed to parse init validatorSet"); - for(uint i = 0;i0){ + if (index>0) { Validator storage validator = currentValidatorSet[index-1]; - if(validator.jailed){ + if (validator.jailed) { emit deprecatedDeposit(valAddr,value); - }else{ + } else { totalInComing += value; validator.incoming += value; emit validatorDeposit(valAddr,value); } - }else{ + } else { // get incoming from deprecated validator; emit deprecatedDeposit(valAddr,value); } } - function jailValidator(Validator[] memory validatorSet) internal returns (uint32){ - if(validatorSet.length != 1){ + function jailValidator(Validator[] memory validatorSet) internal returns (uint32) { + if (validatorSet.length != 1) { emit failReasonWithStr("length of jail validators must be one"); return ERROR_LEN_OF_VAL_MISMATCH; } Validator memory v = validatorSet[0]; uint256 index = currentValidatorSetMap[v.consensusAddress]; - if (index<=0){ + if (index<=0) { emit validatorEmptyJailed(v.consensusAddress); return CODE_OK; } bool otherValid = false; uint n = currentValidatorSet.length; - for(uint i=0;i= DUSTY_INCOMING){ + for (uint i = 0;i= DUSTY_INCOMING) { crossSize ++; - }else if (currentValidatorSet[i].incoming > 0){ + } else if (currentValidatorSet[i].incoming > 0) { directSize ++; } } @@ -212,12 +212,12 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica delete directSize; Validator[] memory validatorSetTemp = validatorSet; // fix error: stack too deep, try removing local variables uint256 relayFee = ITokenHub(TOKEN_HUB_ADDR).getRelayFee(); - if(relayFee > DUSTY_INCOMING){ + if (relayFee > DUSTY_INCOMING) { emit failReasonWithStr("fee is larger than DUSTY_INCOMING"); return ERROR_RELAYFEE_TOO_LARGE; } - for(uint i = 0;i= DUSTY_INCOMING){ + for (uint i = 0;i= DUSTY_INCOMING) { crossAddrs[crossSize] = currentValidatorSet[i].BBCFeeAddress; uint256 value = currentValidatorSet[i].incoming - currentValidatorSet[i].incoming % PRECISION; crossAmounts[crossSize] = value.sub(relayFee); @@ -225,7 +225,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica crossIndexes[crossSize] = i; crossTotal = crossTotal.add(value); crossSize ++; - }else if (currentValidatorSet[i].incoming > 0){ + } else if (currentValidatorSet[i].incoming > 0) { directAddrs[directSize] = currentValidatorSet[i].feeAddress; directAmounts[directSize] = currentValidatorSet[i].incoming; directSize ++; @@ -234,11 +234,11 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica //step 2: do cross chain transfer bool failCross = false; - if(crossTotal > 0){ + if (crossTotal > 0) { try ITokenHub(TOKEN_HUB_ADDR).batchTransferOutBNB{value:crossTotal}(crossAddrs, crossAmounts, crossRefundAddrs, uint64(block.timestamp + expireTimeSecondGap)) returns (bool success) { if (success) { emit batchTransfer(crossTotal); - }else{ + } else { emit batchTransferFailed(crossTotal, "batch transfer return false"); } }catch Error(string memory reason) { @@ -250,38 +250,38 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } } - if(failCross){ - for(uint i = 0; i< crossIndexes.length;i++){ + if (failCross) { + for (uint i = 0; i< crossIndexes.length;i++) { uint idx = crossIndexes[i]; bool success = currentValidatorSet[idx].feeAddress.send(currentValidatorSet[idx].incoming); - if (success){ + if (success) { emit directTransfer(currentValidatorSet[idx].feeAddress, currentValidatorSet[idx].incoming); - }else{ + } else { emit directTransferFail(currentValidatorSet[idx].feeAddress, currentValidatorSet[idx].incoming); } } } // step 3: direct transfer - if(directAddrs.length>0){ - for(uint i = 0;i0) { + for (uint i = 0;i0){ + if (address(this).balance>0) { emit systemTransfer(address(this).balance); address(uint160(SYSTEM_REWARD_ADDR)).transfer(address(this).balance); } // step 5: do update validator set state totalInComing = 0; - if(validatorSetTemp.length>0){ + if (validatorSetTemp.length>0) { doUpdateState(validatorSetTemp); } @@ -294,15 +294,15 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica function getValidators()external view returns(address[] memory) { uint n = currentValidatorSet.length; uint valid = 0; - for(uint i = 0;i=100 && newExpireTimeSecondGap <= 1e5, "the expireTimeSecondGap is out of range"); expireTimeSecondGap = newExpireTimeSecondGap; - }else{ + } else { require(false, "unknown param"); } emit paramChange(key, value); @@ -394,10 +394,10 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica /*********************** Internal Functions **************************/ - function checkValidatorSet(Validator[] memory validatorSet) private pure returns(bool, string memory){ - for(uint i = 0;im){ - for(uint i = m;im) { + for (uint i = m;in){ - for(uint i = n;in) { + for (uint i = n;i0){ + if (index>0) { Validator storage validator = currentValidatorSet[index-1]; - if(validator.jailed){ + if (validator.jailed) { emit deprecatedDeposit(valAddr,value); - }else{ + } else { totalInComing += value; validator.incoming += value; emit validatorDeposit(valAddr,value); } - }else{ + } else { // get incoming from deprecated validator; emit deprecatedDeposit(valAddr,value); } } - function jailValidator(Validator[] memory validatorSet) internal returns (uint32){ - if(validatorSet.length != 1){ + function jailValidator(Validator[] memory validatorSet) internal returns (uint32) { + if (validatorSet.length != 1) { emit failReasonWithStr("length of jail validators must be one"); return ERROR_LEN_OF_VAL_MISMATCH; } Validator memory v = validatorSet[0]; uint256 index = currentValidatorSetMap[v.consensusAddress]; - if (index<=0){ + if (index<=0) { emit validatorEmptyJailed(v.consensusAddress); return CODE_OK; } bool otherValid = false; uint n = currentValidatorSet.length; - for(uint i=0;i= DUSTY_INCOMING){ + for (uint i = 0;i= DUSTY_INCOMING) { crossSize ++; - }else if (currentValidatorSet[i].incoming > 0){ + } else if (currentValidatorSet[i].incoming > 0) { directSize ++; } } @@ -212,12 +212,12 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica delete directSize; Validator[] memory validatorSetTemp = validatorSet; // fix error: stack too deep, try removing local variables uint256 relayFee = ITokenHub(TOKEN_HUB_ADDR).getRelayFee(); - if(relayFee > DUSTY_INCOMING){ + if (relayFee > DUSTY_INCOMING) { emit failReasonWithStr("fee is larger than DUSTY_INCOMING"); return ERROR_RELAYFEE_TOO_LARGE; } - for(uint i = 0;i= DUSTY_INCOMING){ + for (uint i = 0;i= DUSTY_INCOMING) { crossAddrs[crossSize] = currentValidatorSet[i].BBCFeeAddress; uint256 value = currentValidatorSet[i].incoming - currentValidatorSet[i].incoming % PRECISION; crossAmounts[crossSize] = value.sub(relayFee); @@ -225,7 +225,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica crossIndexes[crossSize] = i; crossTotal = crossTotal.add(value); crossSize ++; - }else if (currentValidatorSet[i].incoming > 0){ + } else if (currentValidatorSet[i].incoming > 0) { directAddrs[directSize] = currentValidatorSet[i].feeAddress; directAmounts[directSize] = currentValidatorSet[i].incoming; directSize ++; @@ -234,11 +234,11 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica //step 2: do cross chain transfer bool failCross = false; - if(crossTotal > 0){ + if (crossTotal > 0) { try ITokenHub(TOKEN_HUB_ADDR).batchTransferOutBNB{value:crossTotal}(crossAddrs, crossAmounts, crossRefundAddrs, uint64(block.timestamp + expireTimeSecondGap)) returns (bool success) { if (success) { emit batchTransfer(crossTotal); - }else{ + } else { emit batchTransferFailed(crossTotal, "batch transfer return false"); } }catch Error(string memory reason) { @@ -250,38 +250,38 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } } - if(failCross){ - for(uint i = 0; i< crossIndexes.length;i++){ + if (failCross) { + for (uint i = 0; i< crossIndexes.length;i++) { uint idx = crossIndexes[i]; bool success = currentValidatorSet[idx].feeAddress.send(currentValidatorSet[idx].incoming); - if (success){ + if (success) { emit directTransfer(currentValidatorSet[idx].feeAddress, currentValidatorSet[idx].incoming); - }else{ + } else { emit directTransferFail(currentValidatorSet[idx].feeAddress, currentValidatorSet[idx].incoming); } } } // step 3: direct transfer - if(directAddrs.length>0){ - for(uint i = 0;i0) { + for (uint i = 0;i0){ + if (address(this).balance>0) { emit systemTransfer(address(this).balance); address(uint160(SYSTEM_REWARD_ADDR)).transfer(address(this).balance); } // step 5: do update validator set state totalInComing = 0; - if(validatorSetTemp.length>0){ + if (validatorSetTemp.length>0) { doUpdateState(validatorSetTemp); } @@ -294,15 +294,15 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica function getValidators()external view returns(address[] memory) { uint n = currentValidatorSet.length; uint valid = 0; - for(uint i = 0;i=100 && newExpireTimeSecondGap <= 1e5, "the expireTimeSecondGap is out of range"); expireTimeSecondGap = newExpireTimeSecondGap; - }else{ + } else { require(false, "unknown param"); } emit paramChange(key, value); @@ -403,10 +403,10 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica /*********************** Internal Functions **************************/ - function checkValidatorSet(Validator[] memory validatorSet) private pure returns(bool, string memory){ - for(uint i = 0;im){ - for(uint i = m;im) { + for (uint i = m;in){ - for(uint i = n;in) { + for (uint i = n;i=batchSizeForOracle) { + if (txCounter>=batchSizeForOracle) { oracleSequence++; txCounter = 0; } @@ -260,11 +260,11 @@ function encodePayload(uint8 packageType, uint256 relayFee, bytes memory msgByte } function updateParam(string calldata key, bytes calldata value) onlyGov external override { - if (Memory.compareStrings(key, "batchSizeForOracle")){ + if (Memory.compareStrings(key, "batchSizeForOracle")) { uint256 newBatchSizeForOracle = BytesToTypes.bytesToUint256(32, value); require(newBatchSizeForOracle <= 10000 && newBatchSizeForOracle >= 10, "the newBatchSizeForOracle should be in [10, 10000]"); batchSizeForOracle = newBatchSizeForOracle; - } else if (Memory.compareStrings(key, "addChannel")){ + } else if (Memory.compareStrings(key, "addChannel")) { bytes memory valueLocal = value; require(valueLocal.length == 22, "length of value for addChannel should be 22, channelId:isFromSystem:handlerAddress"); uint8 channelId; diff --git a/contracts/CrossChain.template b/contracts/CrossChain.template index 555d04e56..0bcebe9d3 100644 --- a/contracts/CrossChain.template +++ b/contracts/CrossChain.template @@ -204,7 +204,7 @@ function encodePayload(uint8 packageType, uint256 relayFee, bytes memory msgByte if (packageType == SYN_PACKAGE) { address handlerContract = channelHandlerContractMap[channelIdLocal]; try IApplication(handlerContract).handleSynPackage(channelIdLocal, msgBytes) returns (bytes memory responsePayload) { - if(responsePayload.length!=0){ + if (responsePayload.length!=0) { sendPackage(channelSendSequenceMap[channelIdLocal], channelIdLocal, encodePayload(ACK_PACKAGE, 0, responsePayload)); channelSendSequenceMap[channelIdLocal] = channelSendSequenceMap[channelIdLocal] + 1; } @@ -244,7 +244,7 @@ function encodePayload(uint8 packageType, uint256 relayFee, bytes memory msgByte previousTxHeight=block.number; } else { txCounter++; - if(txCounter>=batchSizeForOracle) { + if (txCounter>=batchSizeForOracle) { oracleSequence++; txCounter = 0; } @@ -261,11 +261,11 @@ function encodePayload(uint8 packageType, uint256 relayFee, bytes memory msgByte } function updateParam(string calldata key, bytes calldata value) onlyGov external override { - if (Memory.compareStrings(key, "batchSizeForOracle")){ + if (Memory.compareStrings(key, "batchSizeForOracle")) { uint256 newBatchSizeForOracle = BytesToTypes.bytesToUint256(32, value); require(newBatchSizeForOracle <= 10000 && newBatchSizeForOracle >= 10, "the newBatchSizeForOracle should be in [10, 10000]"); batchSizeForOracle = newBatchSizeForOracle; - } else if (Memory.compareStrings(key, "addChannel")){ + } else if (Memory.compareStrings(key, "addChannel")) { bytes memory valueLocal = value; require(valueLocal.length == 22, "length of value for addChannel should be 22, channelId:isFromSystem:handlerAddress"); uint8 channelId; diff --git a/contracts/GovHub.sol b/contracts/GovHub.sol index 2316c1b71..b9236ba4d 100644 --- a/contracts/GovHub.sol +++ b/contracts/GovHub.sol @@ -27,15 +27,15 @@ contract GovHub is System, IApplication{ address target; } - function handleSynPackage(uint8, bytes calldata msgBytes) onlyCrossChainContract external override returns(bytes memory responsePayload){ + function handleSynPackage(uint8, bytes calldata msgBytes) onlyCrossChainContract external override returns(bytes memory responsePayload) { (ParamChangePackage memory proposal, bool success) = decodeSynPackage(msgBytes); - if(!success){ + if (!success) { return CmnPkg.encodeCommonAckPackage(ERROR_FAIL_DECODE); } uint32 resCode = notifyUpdates(proposal); - if(resCode == CODE_OK){ + if (resCode == CODE_OK) { return new bytes(0); - }else{ + } else { return CmnPkg.encodeCommonAckPackage(resCode); } } @@ -52,11 +52,11 @@ contract GovHub is System, IApplication{ function notifyUpdates(ParamChangePackage memory proposal) internal returns(uint32) { - if (!isContract(proposal.target)){ + if (!isContract(proposal.target)) { emit failReasonWithStr("the target is not a contract"); return ERROR_TARGET_NOT_CONTRACT; } - try IParamSubscriber(proposal.target).updateParam(proposal.key, proposal.value){ + try IParamSubscriber(proposal.target).updateParam(proposal.key, proposal.value) { }catch Error(string memory reason) { emit failReasonWithStr(reason); return ERROR_TARGET_CONTRACT_FAIL; @@ -74,12 +74,12 @@ contract GovHub is System, IApplication{ RLPDecode.Iterator memory iter = msgBytes.toRLPItem().iterator(); bool success = false; uint256 idx=0; - while(iter.hasNext()) { - if ( idx == 0 ) { + while (iter.hasNext()) { + if (idx == 0) { pkg.key = string(iter.next().toBytes()); - }else if (idx == 1) { + } else if (idx == 1) { pkg.value = iter.next().toBytes(); - }else if (idx == 2){ + } else if (idx == 2) { pkg.target = iter.next().toAddress(); success = true; } else { diff --git a/contracts/MerkleProof.sol b/contracts/MerkleProof.sol index 7d1c47971..1856f2502 100644 --- a/contracts/MerkleProof.sol +++ b/contracts/MerkleProof.sol @@ -3,7 +3,7 @@ pragma solidity 0.6.4; import "./lib/Memory.sol"; library MerkleProof { - function validateMerkleProof(bytes32 appHash, string memory storeName, bytes memory key, bytes memory value, bytes memory proof ) + function validateMerkleProof(bytes32 appHash, string memory storeName, bytes memory key, bytes memory value, bytes memory proof) internal view returns (bool) { if (appHash == bytes32(0)) { return false; diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 7c4f7de05..83fe8bfb9 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -68,23 +68,23 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ /*********************** Param update ********************************/ function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov{ - if (Memory.compareStrings(key,"requiredDeposit")){ + if (Memory.compareStrings(key,"requiredDeposit")) { require(value.length == 32, "length of requiredDeposit mismatch"); uint256 newRequiredDeposit = BytesToTypes.bytesToUint256(32, value); require(newRequiredDeposit >= 1 && newRequiredDeposit <= 1e21, "the requiredDeposit out of range"); requiredDeposit = newRequiredDeposit; - }else if(Memory.compareStrings(key,"dues")){ + } else if (Memory.compareStrings(key,"dues")) { require(value.length == 32, "length of dues mismatch"); uint256 newDues = BytesToTypes.bytesToUint256(32, value); require(newDues > 0 && newDues < requiredDeposit, "the dues out of range"); dues = newDues; - }else{ + } else { require(false, "unknown param"); } emit paramChange(key, value); } - function isRelayer(address sender) external override view returns (bool){ + function isRelayer(address sender) external override view returns (bool) { return relayersExistMap[sender]; } } diff --git a/contracts/RelayerIncentivize.sol b/contracts/RelayerIncentivize.sol index d52d40495..225a51acf 100644 --- a/contracts/RelayerIncentivize.sol +++ b/contracts/RelayerIncentivize.sol @@ -68,17 +68,17 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { collectedRewardForHeaderRelayer = collectedRewardForHeaderRelayer.add(reward); collectedRewardForTransferRelayer = collectedRewardForTransferRelayer.add(actualAmount).sub(reward); - if (headerRelayersSubmitCount[headerRelayerAddr]==0){ + if (headerRelayersSubmitCount[headerRelayerAddr]==0) { headerRelayerAddressRecord.push(headerRelayerAddr); } headerRelayersSubmitCount[headerRelayerAddr]++; - if (transferRelayersSubmitCount[packageRelayer]==0){ + if (transferRelayersSubmitCount[packageRelayer]==0) { transferRelayerAddressRecord.push(packageRelayer); } transferRelayersSubmitCount[packageRelayer]++; - if (countInRound==ROUND_SIZE){ + if (countInRound==ROUND_SIZE) { emit LogDistributeCollectedReward(roundSequence, collectedRewardForHeaderRelayer, collectedRewardForTransferRelayer); distributeHeaderRelayerReward(packageRelayer); @@ -103,7 +103,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { uint256 totalWeight=0; address payable[] memory relayers = headerRelayerAddressRecord; uint256[] memory relayerWeight = new uint256[](relayers.length); - for(uint256 index = 0; index < relayers.length; index++) { + for (uint256 index = 0; index < relayers.length; index++) { address relayer = relayers[index]; uint256 weight = calculateHeaderRelayerWeight(headerRelayersSubmitCount[relayer]); relayerWeight[index] = weight; @@ -113,7 +113,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { uint256 callerReward = totalReward.mul(moleculeCallerCompensation).div(denominatorCallerCompensation); totalReward = totalReward.sub(callerReward); uint256 remainReward = totalReward; - for(uint256 index = 1; index < relayers.length; index++) { + for (uint256 index = 1; index < relayers.length; index++) { uint256 reward = relayerWeight[index].mul(totalReward).div(totalWeight); relayers[index].send(reward); remainReward = remainReward.sub(reward); @@ -122,7 +122,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { packageRelayer.send(callerReward); collectedRewardForHeaderRelayer = 0; - for (uint256 index = 0; index < relayers.length; index++){ + for (uint256 index = 0; index < relayers.length; index++) { delete headerRelayersSubmitCount[relayers[index]]; } delete headerRelayerAddressRecord; @@ -134,7 +134,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { uint256 totalWeight=0; address payable[] memory relayers = transferRelayerAddressRecord; uint256[] memory relayerWeight = new uint256[](relayers.length); - for(uint256 index = 0; index < relayers.length; index++) { + for (uint256 index = 0; index < relayers.length; index++) { address relayer = relayers[index]; uint256 weight = calculateTransferRelayerWeight(transferRelayersSubmitCount[relayer]); relayerWeight[index] = weight; @@ -144,7 +144,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { uint256 callerReward = totalReward.mul(moleculeCallerCompensation).div(denominatorCallerCompensation); totalReward = totalReward.sub(callerReward); uint256 remainReward = totalReward; - for(uint256 index = 1; index < relayers.length; index++) { + for (uint256 index = 1; index < relayers.length; index++) { uint256 reward = relayerWeight[index].mul(totalReward).div(totalWeight); relayers[index].send(reward); remainReward = remainReward.sub(reward); @@ -153,7 +153,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { packageRelayer.send(callerReward); collectedRewardForTransferRelayer = 0; - for (uint256 index = 0; index < relayers.length; index++){ + for (uint256 index = 0; index < relayers.length; index++) { delete transferRelayersSubmitCount[relayers[index]]; } delete transferRelayerAddressRecord; @@ -164,7 +164,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { return count; } else if (MAXIMUM_WEIGHT < count && count <= 2*MAXIMUM_WEIGHT) { return MAXIMUM_WEIGHT; - } else if (2*MAXIMUM_WEIGHT < count && count <= (2*MAXIMUM_WEIGHT + 3*MAXIMUM_WEIGHT/4 )) { + } else if (2*MAXIMUM_WEIGHT < count && count <= (2*MAXIMUM_WEIGHT + 3*MAXIMUM_WEIGHT/4)) { return 3*MAXIMUM_WEIGHT - count; } else { return count/4; @@ -181,25 +181,25 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { function updateParam(string calldata key, bytes calldata value) override external onlyGov{ require(alreadyInit, "contract has not been initialized"); - if (Memory.compareStrings(key,"moleculeHeaderRelayer")){ + if (Memory.compareStrings(key,"moleculeHeaderRelayer")) { require(value.length == 32, "length of moleculeHeaderRelayer mismatch"); uint256 newMoleculeHeaderRelayer = BytesToTypes.bytesToUint256(32, value); moleculeHeaderRelayer = newMoleculeHeaderRelayer; - } else if (Memory.compareStrings(key,"denominatorHeaderRelayer")){ + } else if (Memory.compareStrings(key,"denominatorHeaderRelayer")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newDenominatorHeaderRelayer = BytesToTypes.bytesToUint256(32, value); require(newDenominatorHeaderRelayer != 0, "the newDenominatorHeaderRelayer must not be zero"); denominatorHeaderRelayer = newDenominatorHeaderRelayer; - }else if (Memory.compareStrings(key,"moleculeCallerCompensation")){ + } else if (Memory.compareStrings(key,"moleculeCallerCompensation")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newMoleculeCallerCompensation = BytesToTypes.bytesToUint256(32, value); moleculeCallerCompensation = newMoleculeCallerCompensation; - } else if (Memory.compareStrings(key,"denominatorCallerCompensation")){ + } else if (Memory.compareStrings(key,"denominatorCallerCompensation")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newDenominatorCallerCompensation = BytesToTypes.bytesToUint256(32, value); require(newDenominatorCallerCompensation != 0, "the newDenominatorCallerCompensation must not be zero"); denominatorCallerCompensation = newDenominatorCallerCompensation; - }else{ + } else { require(false, "unknown param"); } emit paramChange(key, value); diff --git a/contracts/RelayerIncentivize.template b/contracts/RelayerIncentivize.template index fdff36c01..a1e22274e 100644 --- a/contracts/RelayerIncentivize.template +++ b/contracts/RelayerIncentivize.template @@ -70,17 +70,17 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { collectedRewardForHeaderRelayer = collectedRewardForHeaderRelayer.add(reward); collectedRewardForTransferRelayer = collectedRewardForTransferRelayer.add(actualAmount).sub(reward); - if (headerRelayersSubmitCount[headerRelayerAddr]==0){ + if (headerRelayersSubmitCount[headerRelayerAddr]==0) { headerRelayerAddressRecord.push(headerRelayerAddr); } headerRelayersSubmitCount[headerRelayerAddr]++; - if (transferRelayersSubmitCount[packageRelayer]==0){ + if (transferRelayersSubmitCount[packageRelayer]==0) { transferRelayerAddressRecord.push(packageRelayer); } transferRelayersSubmitCount[packageRelayer]++; - if (countInRound==ROUND_SIZE){ + if (countInRound==ROUND_SIZE) { emit LogDistributeCollectedReward(roundSequence, collectedRewardForHeaderRelayer, collectedRewardForTransferRelayer); distributeHeaderRelayerReward(packageRelayer); @@ -105,7 +105,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { uint256 totalWeight=0; address payable[] memory relayers = headerRelayerAddressRecord; uint256[] memory relayerWeight = new uint256[](relayers.length); - for(uint256 index = 0; index < relayers.length; index++) { + for (uint256 index = 0; index < relayers.length; index++) { address relayer = relayers[index]; uint256 weight = calculateHeaderRelayerWeight(headerRelayersSubmitCount[relayer]); relayerWeight[index] = weight; @@ -115,7 +115,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { uint256 callerReward = totalReward.mul(moleculeCallerCompensation).div(denominatorCallerCompensation); totalReward = totalReward.sub(callerReward); uint256 remainReward = totalReward; - for(uint256 index = 1; index < relayers.length; index++) { + for (uint256 index = 1; index < relayers.length; index++) { uint256 reward = relayerWeight[index].mul(totalReward).div(totalWeight); relayers[index].send(reward); remainReward = remainReward.sub(reward); @@ -124,7 +124,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { packageRelayer.send(callerReward); collectedRewardForHeaderRelayer = 0; - for (uint256 index = 0; index < relayers.length; index++){ + for (uint256 index = 0; index < relayers.length; index++) { delete headerRelayersSubmitCount[relayers[index]]; } delete headerRelayerAddressRecord; @@ -136,7 +136,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { uint256 totalWeight=0; address payable[] memory relayers = transferRelayerAddressRecord; uint256[] memory relayerWeight = new uint256[](relayers.length); - for(uint256 index = 0; index < relayers.length; index++) { + for (uint256 index = 0; index < relayers.length; index++) { address relayer = relayers[index]; uint256 weight = calculateTransferRelayerWeight(transferRelayersSubmitCount[relayer]); relayerWeight[index] = weight; @@ -146,7 +146,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { uint256 callerReward = totalReward.mul(moleculeCallerCompensation).div(denominatorCallerCompensation); totalReward = totalReward.sub(callerReward); uint256 remainReward = totalReward; - for(uint256 index = 1; index < relayers.length; index++) { + for (uint256 index = 1; index < relayers.length; index++) { uint256 reward = relayerWeight[index].mul(totalReward).div(totalWeight); relayers[index].send(reward); remainReward = remainReward.sub(reward); @@ -155,7 +155,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { packageRelayer.send(callerReward); collectedRewardForTransferRelayer = 0; - for (uint256 index = 0; index < relayers.length; index++){ + for (uint256 index = 0; index < relayers.length; index++) { delete transferRelayersSubmitCount[relayers[index]]; } delete transferRelayerAddressRecord; @@ -166,7 +166,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { return count; } else if (MAXIMUM_WEIGHT < count && count <= 2*MAXIMUM_WEIGHT) { return MAXIMUM_WEIGHT; - } else if (2*MAXIMUM_WEIGHT < count && count <= (2*MAXIMUM_WEIGHT + 3*MAXIMUM_WEIGHT/4 )) { + } else if (2*MAXIMUM_WEIGHT < count && count <= (2*MAXIMUM_WEIGHT + 3*MAXIMUM_WEIGHT/4)) { return 3*MAXIMUM_WEIGHT - count; } else { return count/4; @@ -183,25 +183,25 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { function updateParam(string calldata key, bytes calldata value) override external onlyGov{ require(alreadyInit, "contract has not been initialized"); - if (Memory.compareStrings(key,"moleculeHeaderRelayer")){ + if (Memory.compareStrings(key,"moleculeHeaderRelayer")) { require(value.length == 32, "length of moleculeHeaderRelayer mismatch"); uint256 newMoleculeHeaderRelayer = BytesToTypes.bytesToUint256(32, value); moleculeHeaderRelayer = newMoleculeHeaderRelayer; - } else if (Memory.compareStrings(key,"denominatorHeaderRelayer")){ + } else if (Memory.compareStrings(key,"denominatorHeaderRelayer")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newDenominatorHeaderRelayer = BytesToTypes.bytesToUint256(32, value); require(newDenominatorHeaderRelayer != 0, "the newDenominatorHeaderRelayer must not be zero"); denominatorHeaderRelayer = newDenominatorHeaderRelayer; - }else if (Memory.compareStrings(key,"moleculeCallerCompensation")){ + } else if (Memory.compareStrings(key,"moleculeCallerCompensation")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newMoleculeCallerCompensation = BytesToTypes.bytesToUint256(32, value); moleculeCallerCompensation = newMoleculeCallerCompensation; - } else if (Memory.compareStrings(key,"denominatorCallerCompensation")){ + } else if (Memory.compareStrings(key,"denominatorCallerCompensation")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newDenominatorCallerCompensation = BytesToTypes.bytesToUint256(32, value); require(newDenominatorCallerCompensation != 0, "the newDenominatorCallerCompensation must not be zero"); denominatorCallerCompensation = newDenominatorCallerCompensation; - }else{ + } else { require(false, "unknown param"); } emit paramChange(key, value); diff --git a/contracts/SlashIndicator.sol b/contracts/SlashIndicator.sol index 558566108..8d3b751f9 100644 --- a/contracts/SlashIndicator.sol +++ b/contracts/SlashIndicator.sol @@ -52,15 +52,15 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication } /*********************** Implement cross chain app ********************************/ - function handleSynPackage(uint8, bytes calldata) external onlyCrossChainContract override returns(bytes memory){ + function handleSynPackage(uint8, bytes calldata) external onlyCrossChainContract override returns(bytes memory) { require(false, "receive unexpected syn package"); } function handleAckPackage(uint8, bytes calldata msgBytes) external override { (CmnPkg.CommonAckPackage memory response, bool ok) = CmnPkg.decodeCommonAckPackage(msgBytes); - if(ok){ + if (ok) { emit knownResponse(response.code); - }else{ + } else { emit unKnownResponse(response.code); } return; @@ -74,19 +74,19 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication /*********************** External func ********************************/ function slash(address validator) external onlyCoinbase onlyInit onlyOnce{ Indicator memory indicator = indicators[validator]; - if (indicator.exist){ + if (indicator.exist) { indicator.count++; - }else{ + } else { indicator.exist = true; indicator.count = 1; validators.push(validator); } indicator.height = block.number; indicators[validator] = indicator; - if(indicator.count % felonyThreshold == 0){ + if (indicator.count % felonyThreshold == 0) { IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).felony(validator); ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeSlashPackage(validator), 0); - }else if (indicator.count % misdemeanorThreshold == 0){ + } else if (indicator.count % misdemeanorThreshold == 0) { IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).misdemeanor(validator); } emit validatorSlashed(validator); @@ -94,7 +94,7 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication function clean() external override(ISlashIndicator) onlyValidatorContract onlyInit{ uint n = validators.length; - for(uint i = 0; i < n; i++){ + for (uint i = 0; i < n; i++) { delete indicators[validators[n-i-1]]; validators.pop(); } @@ -104,24 +104,24 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication /*********************** Param update ********************************/ function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov{ - if (Memory.compareStrings(key,"misdemeanorThreshold")){ + if (Memory.compareStrings(key,"misdemeanorThreshold")) { require(value.length == 32, "length of misdemeanorThreshold mismatch"); uint256 newMisdemeanorThreshold = BytesToTypes.bytesToUint256(32, value); require(newMisdemeanorThreshold >= 10 && newMisdemeanorThreshold < felonyThreshold, "the misdemeanorThreshold out of range"); misdemeanorThreshold = newMisdemeanorThreshold; - }else if(Memory.compareStrings(key,"felonyThreshold")){ + } else if (Memory.compareStrings(key,"felonyThreshold")) { require(value.length == 32, "length of felonyThreshold mismatch"); uint256 newFelonyThreshold = BytesToTypes.bytesToUint256(32, value); require(newFelonyThreshold > 20 && newFelonyThreshold <= 1000, "the felonyThreshold out of range"); felonyThreshold = newFelonyThreshold; - }else{ + } else { require(false, "unknown param"); } emit paramChange(key,value); } /*********************** query api ********************************/ - function getSlashIndicator(address validator) external view returns (uint256,uint256){ + function getSlashIndicator(address validator) external view returns (uint256,uint256) { Indicator memory indicator = indicators[validator]; return (indicator.height, indicator.count); } diff --git a/contracts/SystemReward.sol b/contracts/SystemReward.sol index 2d6a92c28..dbfca72de 100644 --- a/contracts/SystemReward.sol +++ b/contracts/SystemReward.sol @@ -10,7 +10,7 @@ contract SystemReward is System, ISystemReward{ modifier doInit() { - if(!alreadyInit){ + if (!alreadyInit) { operators[LIGHT_CLIENT_ADDR] = true; operators[INCENTIVIZE_ADDR] = true; numOperator = 2; @@ -31,7 +31,7 @@ contract SystemReward is System, ISystemReward{ receive() external payable{ - if (msg.value>0){ + if (msg.value>0) { emit receiveDeposit(msg.sender, msg.value); } } @@ -39,19 +39,19 @@ contract SystemReward is System, ISystemReward{ function claimRewards(address payable to, uint256 amount) external override(ISystemReward) doInit onlyOperator returns(uint256) { uint256 actualAmount = amount < address(this).balance ? amount : address(this).balance; - if(actualAmount > MAX_REWARDS){ + if (actualAmount > MAX_REWARDS) { actualAmount = MAX_REWARDS; } - if(actualAmount>0){ + if (actualAmount>0) { to.transfer(actualAmount); emit rewardTo(to, actualAmount); - }else{ + } else { emit rewardEmpty(); } return actualAmount; } - function isOperator(address addr) external view returns (bool){ + function isOperator(address addr) external view returns (bool) { return operators[addr]; } } \ No newline at end of file diff --git a/contracts/SystemReward.template b/contracts/SystemReward.template index cbdd930ca..bc5054789 100644 --- a/contracts/SystemReward.template +++ b/contracts/SystemReward.template @@ -10,7 +10,7 @@ contract SystemReward is System, ISystemReward{ modifier doInit() { - if(!alreadyInit){ + if (!alreadyInit) { operators[LIGHT_CLIENT_ADDR] = true; operators[INCENTIVIZE_ADDR] = true; numOperator = 2; @@ -34,7 +34,7 @@ contract SystemReward is System, ISystemReward{ receive() external payable{ - if (msg.value>0){ + if (msg.value>0) { emit receiveDeposit(msg.sender, msg.value); } } @@ -50,13 +50,13 @@ contract SystemReward is System, ISystemReward{ _; } - function addOperator(address operator) external doInit onlyOperatorNotExist(operator){ + function addOperator(address operator) external doInit onlyOperatorNotExist(operator) { operators[operator] = true; numOperator ++; emit newOperator(operator); } - function removeOperator(address operator) external doInit onlyOperatorExist(operator){ + function removeOperator(address operator) external doInit onlyOperatorExist(operator) { delete operators[operator]; numOperator --; emit deleteOperator(operator); @@ -64,19 +64,19 @@ contract SystemReward is System, ISystemReward{ {% endif %} function claimRewards(address payable to, uint256 amount) external override(ISystemReward) doInit onlyOperator returns(uint256) { uint256 actualAmount = amount < address(this).balance ? amount : address(this).balance; - if(actualAmount > MAX_REWARDS){ + if (actualAmount > MAX_REWARDS) { actualAmount = MAX_REWARDS; } - if(actualAmount>0){ + if (actualAmount>0) { to.transfer(actualAmount); emit rewardTo(to, actualAmount); - }else{ + } else { emit rewardEmpty(); } return actualAmount; } - function isOperator(address addr) external view returns (bool){ + function isOperator(address addr) external view returns (bool) { return operators[addr]; } } \ No newline at end of file diff --git a/contracts/TendermintLightClient.sol b/contracts/TendermintLightClient.sol index cf1b6d6cc..827c161e7 100644 --- a/contracts/TendermintLightClient.sol +++ b/contracts/TendermintLightClient.sol @@ -63,7 +63,7 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ uint64 preValidatorSetChangeHeight = latestHeight; ConsensusState memory cs = lightClientConsensusStates[preValidatorSetChangeHeight]; - for(; preValidatorSetChangeHeight >= initialHeight;) { + for (; preValidatorSetChangeHeight >= initialHeight;) { if (preValidatorSetChangeHeight < height) { // find nearest previous height break; @@ -259,12 +259,12 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ } function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov{ - if (Memory.compareStrings(key,"rewardForValidatorSetChange")){ + if (Memory.compareStrings(key,"rewardForValidatorSetChange")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newRewardForValidatorSetChange = BytesToTypes.bytesToUint256(32, value); require(newRewardForValidatorSetChange > 0 && newRewardForValidatorSetChange <= 1e18, "the newRewardForValidatorSetChange out of range"); rewardForValidatorSetChange = newRewardForValidatorSetChange; - }else{ + } else { require(false, "unknown param"); } emit paramChange(key, value); diff --git a/contracts/TendermintLightClient.template b/contracts/TendermintLightClient.template index fcb9c407c..6e560c74c 100644 --- a/contracts/TendermintLightClient.template +++ b/contracts/TendermintLightClient.template @@ -63,7 +63,7 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ uint64 preValidatorSetChangeHeight = latestHeight; ConsensusState memory cs = lightClientConsensusStates[preValidatorSetChangeHeight]; - for(; preValidatorSetChangeHeight >= initialHeight;) { + for (; preValidatorSetChangeHeight >= initialHeight;) { if (preValidatorSetChangeHeight < height) { // find nearest previous height break; @@ -259,12 +259,12 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ } function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov{ - if (Memory.compareStrings(key,"rewardForValidatorSetChange")){ + if (Memory.compareStrings(key,"rewardForValidatorSetChange")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newRewardForValidatorSetChange = BytesToTypes.bytesToUint256(32, value); require(newRewardForValidatorSetChange > 0 && newRewardForValidatorSetChange <= 1e18, "the newRewardForValidatorSetChange out of range"); rewardForValidatorSetChange = newRewardForValidatorSetChange; - }else{ + } else { require(false, "unknown param"); } emit paramChange(key, value); diff --git a/contracts/TokenHub.sol b/contracts/TokenHub.sol index 4a27c92d0..967128006 100644 --- a/contracts/TokenHub.sol +++ b/contracts/TokenHub.sol @@ -98,14 +98,14 @@ contract TokenHub is ITokenHub, System, IParamSubscriber, IApplication, ISystemR } receive() external payable{ - if (msg.value>0){ + if (msg.value>0) { emit receiveDeposit(msg.sender, msg.value); } } function claimRewards(address payable to, uint256 amount) onlyInit onlyRelayerIncentivize external override returns(uint256) { uint256 actualAmount = amount < address(this).balance ? amount : address(this).balance; - if(actualAmount>0){ + if (actualAmount>0) { to.transfer(actualAmount); emit rewardTo(to, actualAmount); } @@ -116,7 +116,7 @@ contract TokenHub is ITokenHub, System, IParamSubscriber, IApplication, ISystemR return relayFee; } - function handleSynPackage(uint8 channelId, bytes calldata msgBytes) onlyInit onlyCrossChainContract external override returns(bytes memory){ + function handleSynPackage(uint8 channelId, bytes calldata msgBytes) onlyInit onlyCrossChainContract external override returns(bytes memory) { if (channelId == TRANSFER_IN_CHANNELID) { return handleTransferInSynPackage(msgBytes); } else { @@ -148,13 +148,13 @@ contract TokenHub is ITokenHub, System, IParamSubscriber, IApplication, ISystemR RLPDecode.Iterator memory iter = msgBytes.toRLPItem().iterator(); bool success = false; uint256 idx=0; - while(iter.hasNext()) { - if ( idx == 0 ) transInSynPkg.bep2TokenSymbol = bytes32(iter.next().toUint()); - else if ( idx == 1 ) transInSynPkg.contractAddr = iter.next().toAddress(); - else if ( idx == 2 ) transInSynPkg.amount = iter.next().toUint(); - else if ( idx == 3 ) transInSynPkg.recipient = ((iter.next().toAddress())); - else if ( idx == 4 ) transInSynPkg.refundAddr = iter.next().toAddress(); - else if ( idx == 5 ) { + while (iter.hasNext()) { + if (idx == 0) transInSynPkg.bep2TokenSymbol = bytes32(iter.next().toUint()); + else if (idx == 1) transInSynPkg.contractAddr = iter.next().toAddress(); + else if (idx == 2) transInSynPkg.amount = iter.next().toUint(); + else if (idx == 3) transInSynPkg.recipient = ((iter.next().toAddress())); + else if (idx == 4) transInSynPkg.refundAddr = iter.next().toAddress(); + else if (idx == 5) { transInSynPkg.expireTime = uint64(iter.next().toUint()); success = true; } @@ -216,7 +216,7 @@ contract TokenHub is ITokenHub, System, IParamSubscriber, IApplication, ISystemR return TRANSFER_IN_FAILURE_INSUFFICIENT_BALANCE; } bool success = IBEP2E(transInSynPkg.contractAddr).transfer{gas: MAX_GAS_FOR_CALLING_BEP2E}(transInSynPkg.recipient, transInSynPkg.amount); - if (success){ + if (success) { emit transferInSuccess(transInSynPkg.contractAddr, transInSynPkg.recipient, transInSynPkg.amount); return TRANSFER_IN_SUCCESS; } else { @@ -231,25 +231,25 @@ contract TokenHub is ITokenHub, System, IParamSubscriber, IApplication, ISystemR RLPDecode.Iterator memory iter = msgBytes.toRLPItem().iterator(); bool success = false; uint256 idx=0; - while(iter.hasNext()) { - if ( idx == 0 ) { + while (iter.hasNext()) { + if (idx == 0) { transOutAckPkg.contractAddr = iter.next().toAddress(); } - else if ( idx == 1 ) { + else if (idx == 1) { RLPDecode.RLPItem[] memory list = iter.next().toList(); transOutAckPkg.refundAmounts = new uint256[](list.length); - for(uint256 index=0; index0){ + if (msg.value>0) { emit receiveDeposit(msg.sender, msg.value); } } function claimRewards(address payable to, uint256 amount) onlyInit onlyRelayerIncentivize external override returns(uint256) { uint256 actualAmount = amount < address(this).balance ? amount : address(this).balance; - if(actualAmount>0){ + if (actualAmount>0) { to.transfer(actualAmount); emit rewardTo(to, actualAmount); } @@ -116,7 +116,7 @@ contract TokenHub is ITokenHub, System, IParamSubscriber, IApplication, ISystemR return relayFee; } - function handleSynPackage(uint8 channelId, bytes calldata msgBytes) onlyInit onlyCrossChainContract external override returns(bytes memory){ + function handleSynPackage(uint8 channelId, bytes calldata msgBytes) onlyInit onlyCrossChainContract external override returns(bytes memory) { if (channelId == TRANSFER_IN_CHANNELID) { return handleTransferInSynPackage(msgBytes); } else { @@ -148,13 +148,13 @@ contract TokenHub is ITokenHub, System, IParamSubscriber, IApplication, ISystemR RLPDecode.Iterator memory iter = msgBytes.toRLPItem().iterator(); bool success = false; uint256 idx=0; - while(iter.hasNext()) { - if ( idx == 0 ) transInSynPkg.bep2TokenSymbol = bytes32(iter.next().toUint()); - else if ( idx == 1 ) transInSynPkg.contractAddr = iter.next().toAddress(); - else if ( idx == 2 ) transInSynPkg.amount = iter.next().toUint(); - else if ( idx == 3 ) transInSynPkg.recipient = ((iter.next().toAddress())); - else if ( idx == 4 ) transInSynPkg.refundAddr = iter.next().toAddress(); - else if ( idx == 5 ) { + while (iter.hasNext()) { + if (idx == 0) transInSynPkg.bep2TokenSymbol = bytes32(iter.next().toUint()); + else if (idx == 1) transInSynPkg.contractAddr = iter.next().toAddress(); + else if (idx == 2) transInSynPkg.amount = iter.next().toUint(); + else if (idx == 3) transInSynPkg.recipient = ((iter.next().toAddress())); + else if (idx == 4) transInSynPkg.refundAddr = iter.next().toAddress(); + else if (idx == 5) { transInSynPkg.expireTime = uint64(iter.next().toUint()); success = true; } @@ -216,7 +216,7 @@ contract TokenHub is ITokenHub, System, IParamSubscriber, IApplication, ISystemR return TRANSFER_IN_FAILURE_INSUFFICIENT_BALANCE; } bool success = IBEP2E(transInSynPkg.contractAddr).transfer{gas: MAX_GAS_FOR_CALLING_BEP2E}(transInSynPkg.recipient, transInSynPkg.amount); - if (success){ + if (success) { emit transferInSuccess(transInSynPkg.contractAddr, transInSynPkg.recipient, transInSynPkg.amount); return TRANSFER_IN_SUCCESS; } else { @@ -231,25 +231,25 @@ contract TokenHub is ITokenHub, System, IParamSubscriber, IApplication, ISystemR RLPDecode.Iterator memory iter = msgBytes.toRLPItem().iterator(); bool success = false; uint256 idx=0; - while(iter.hasNext()) { - if ( idx == 0 ) { + while (iter.hasNext()) { + if (idx == 0) { transOutAckPkg.contractAddr = iter.next().toAddress(); } - else if ( idx == 1 ) { + else if (idx == 1) { RLPDecode.RLPItem[] memory list = iter.next().toList(); transOutAckPkg.refundAmounts = new uint256[](list.length); - for(uint256 index=0; index 0) stack_size++; + if (_input.length % 32 > 0) stack_size++; assembly { stack_size := add(stack_size,1)//adding because of 32 first bytes memory as the length - for { let index := 0 } lt(index,stack_size){ index := add(index ,1) } { + for { let index := 0 } lt(index,stack_size) { index := add(index ,1) } { mstore(add(_output, _offst), mload(add(_input,mul(index,32)))) _offst := sub(_offst , 32) } diff --git a/contracts/mock/MerkleProof.sol b/contracts/mock/MerkleProof.sol index 13645f246..b021ce34b 100644 --- a/contracts/mock/MerkleProof.sol +++ b/contracts/mock/MerkleProof.sol @@ -1,7 +1,7 @@ pragma solidity 0.6.4; library MerkleProof { - function validateMerkleProof(bytes32 , string memory , bytes memory, bytes memory , bytes memory ) internal pure returns (bool) { + function validateMerkleProof(bytes32 , string memory , bytes memory, bytes memory , bytes memory) internal pure returns (bool) { return true; } } \ No newline at end of file diff --git a/contracts/mock/MockLightClient.sol b/contracts/mock/MockLightClient.sol index f7af91a2e..4629c5c42 100644 --- a/contracts/mock/MockLightClient.sol +++ b/contracts/mock/MockLightClient.sol @@ -6,7 +6,7 @@ contract MockLightClient is ILightClient{ bool blockNotSynced; bool stateNotVerified; - function isHeaderSynced(uint64) external override(ILightClient) view returns (bool){ + function isHeaderSynced(uint64) external override(ILightClient) view returns (bool) { return !blockNotSynced; } diff --git a/contracts/mock/MockRelayerHub.sol b/contracts/mock/MockRelayerHub.sol index 4dcc002b9..ec1520f6e 100644 --- a/contracts/mock/MockRelayerHub.sol +++ b/contracts/mock/MockRelayerHub.sol @@ -4,7 +4,7 @@ import "../interface/IRelayerHub.sol"; contract MockRelayerHub is IRelayerHub { - function isRelayer(address) external override view returns (bool){ + function isRelayer(address) external override view returns (bool) { return true; } } diff --git a/contracts/mock/MockSystemReward.sol b/contracts/mock/MockSystemReward.sol index 7d01f57f3..8069d7582 100644 --- a/contracts/mock/MockSystemReward.sol +++ b/contracts/mock/MockSystemReward.sol @@ -11,10 +11,10 @@ contract MockSystemReward { function claimRewards(address payable to, uint256 amount) public payable { uint256 actualAmount = amount < address(this).balance ? amount : address(this).balance; - if(actualAmount>0){ + if (actualAmount>0) { to.transfer(actualAmount); emit RewardTo(to, actualAmount); - }else{ + } else { emit RewardEmpty(); } } diff --git a/contracts/mock/MockTokenHub.sol b/contracts/mock/MockTokenHub.sol index a2a8d96bd..89e63c6f4 100644 --- a/contracts/mock/MockTokenHub.sol +++ b/contracts/mock/MockTokenHub.sol @@ -10,17 +10,17 @@ contract MockTokenHub is ITokenHub { return (1e16); } - function getContractAddrByBEP2Symbol(bytes32 bep2Symbol) external view override(ITokenHub) returns(address){ + function getContractAddrByBEP2Symbol(bytes32 bep2Symbol) external view override(ITokenHub) returns(address) { return address(0x0); } - function getBep2SymbolByContractAddr(address contractAddr) external view override(ITokenHub) returns(bytes32){ + function getBep2SymbolByContractAddr(address contractAddr) external view override(ITokenHub) returns(bytes32) { return bytes32(0x0); } - function bindToken(bytes32 bep2Symbol, address contractAddr, uint256 decimals) external override(ITokenHub){} + function bindToken(bytes32 bep2Symbol, address contractAddr, uint256 decimals) external override(ITokenHub) {} - function unbindToken(bytes32 bep2Symbol, address contractAddr) external override(ITokenHub){} + function unbindToken(bytes32 bep2Symbol, address contractAddr) external override(ITokenHub) {} function transferOut(address, address, uint256, uint64) external override(ITokenHub) payable returns (bool) { diff --git a/contracts/tool/BSCValidatorSetTool.sol b/contracts/tool/BSCValidatorSetTool.sol index 6f6302b0e..d39fd0f00 100644 --- a/contracts/tool/BSCValidatorSetTool.sol +++ b/contracts/tool/BSCValidatorSetTool.sol @@ -10,7 +10,7 @@ contract BSCValidatorSetTool { using RLPDecode for *; - struct Validator{ + struct Validator { address consensusAddress; address payable feeAddress; address BBCFeeAddress; @@ -33,21 +33,21 @@ contract BSCValidatorSetTool { RLPDecode.Iterator memory iter = msgBytes.toRLPItem().iterator(); bool success = false; uint256 idx=0; - while(iter.hasNext()) { - if ( idx == 0 ) { + while (iter.hasNext()) { + if (idx == 0) { validatorSetPkg.packageType = uint8(iter.next().toUint()); - }else if (idx == 1) { + } else if (idx == 1) { RLPDecode.RLPItem[] memory items = iter.next().toList(); validatorSetPkg.validatorSet =new Validator[](items.length); - for(uint j = 0;j