diff --git a/abi/bscgovernor.abi b/abi/bscgovernor.abi index 93313dbe..601cb50a 100644 --- a/abi/bscgovernor.abi +++ b/abi/bscgovernor.abi @@ -1652,6 +1652,25 @@ ], "anonymous": false }, + { + "type": "event", + "name": "ProtectorChanged", + "inputs": [ + { + "name": "oldProtector", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "newProtector", + "type": "address", + "indexed": true, + "internalType": "address" + } + ], + "anonymous": false + }, { "type": "event", "name": "QuorumNumeratorUpdated", diff --git a/abi/stakehub.abi b/abi/stakehub.abi index 6c50cca1..a5f5f02b 100644 --- a/abi/stakehub.abi +++ b/abi/stakehub.abi @@ -1266,6 +1266,25 @@ "inputs": [], "anonymous": false }, + { + "type": "event", + "name": "ProtectorChanged", + "inputs": [ + { + "name": "oldProtector", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "newProtector", + "type": "address", + "indexed": true, + "internalType": "address" + } + ], + "anonymous": false + }, { "type": "event", "name": "Redelegated", diff --git a/contracts/BC_fusion/StakeHub.sol b/contracts/BC_fusion/StakeHub.sol index 09553aaf..b6da1111 100644 --- a/contracts/BC_fusion/StakeHub.sol +++ b/contracts/BC_fusion/StakeHub.sol @@ -351,7 +351,7 @@ contract StakeHub is System, Initializable, Protectable { ) revert InvalidCommission(); if (!_checkMoniker(description.moniker)) revert InvalidMoniker(); // proof-of-possession verify - if (!_checkVoteAddress(voteAddress, blsProof)) revert InvalidVoteAddress(); + if (!_checkVoteAddress(operatorAddress, voteAddress, blsProof)) revert InvalidVoteAddress(); // deploy stake credit proxy contract address creditContract = _deployStakeCredit(operatorAddress, description.moniker); @@ -458,12 +458,12 @@ contract StakeHub is System, Initializable, Protectable { bytes calldata blsProof ) external whenNotPaused notInBlackList validatorExist(msg.sender) { // proof-of-possession verify - if (!_checkVoteAddress(newVoteAddress, blsProof)) revert InvalidVoteAddress(); + address operatorAddress = msg.sender; + if (!_checkVoteAddress(operatorAddress, newVoteAddress, blsProof)) revert InvalidVoteAddress(); if (voteToOperator[newVoteAddress] != address(0) || _legacyVoteAddress[newVoteAddress]) { revert DuplicateVoteAddress(); } - address operatorAddress = msg.sender; Validator storage valInfo = _validators[operatorAddress]; if (valInfo.updateTime + BREATHE_BLOCK_INTERVAL > block.timestamp) revert UpdateTooFrequently(); @@ -1065,13 +1065,17 @@ contract StakeHub is System, Initializable, Protectable { return true; } - function _checkVoteAddress(bytes calldata voteAddress, bytes calldata blsProof) internal view returns (bool) { + function _checkVoteAddress( + address operatorAddress, + bytes calldata voteAddress, + bytes calldata blsProof + ) internal view returns (bool) { if (voteAddress.length != BLS_PUBKEY_LENGTH || blsProof.length != BLS_SIG_LENGTH) { return false; } // get msg hash - bytes32 msgHash = keccak256(abi.encodePacked(voteAddress, block.chainid)); + bytes32 msgHash = keccak256(abi.encodePacked(operatorAddress, voteAddress, block.chainid)); bytes memory msgBz = new bytes(32); assembly { mstore(add(msgBz, 32), msgHash) diff --git a/contracts/BC_fusion/extension/Protectable.sol b/contracts/BC_fusion/extension/Protectable.sol index bd949369..b7272803 100644 --- a/contracts/BC_fusion/extension/Protectable.sol +++ b/contracts/BC_fusion/extension/Protectable.sol @@ -21,6 +21,7 @@ abstract contract Protectable is Initializable { /*----------------- events -----------------*/ event Paused(); event Resumed(); + event ProtectorChanged(address indexed oldProtector, address indexed newProtector); event BlackListed(address indexed target); event UnBlackListed(address indexed target); @@ -96,6 +97,7 @@ abstract contract Protectable is Initializable { /*----------------- internal functions -----------------*/ function _setProtector(address protector) internal { + emit ProtectorChanged(_protector, protector); _protector = protector; } diff --git a/contracts/BSCValidatorSet.sol b/contracts/BSCValidatorSet.sol index 7a2e6a93..719e7d7a 100644 --- a/contracts/BSCValidatorSet.sol +++ b/contracts/BSCValidatorSet.sol @@ -847,7 +847,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } else if (Memory.compareStrings(key, "burnRatio")) { require(value.length == 32, "length of burnRatio mismatch"); uint256 newBurnRatio = BytesToTypes.bytesToUint256(32, value); - require(newBurnRatio + systemRewardRatio <= BLOCK_FEES_RATIO_SCALE, "the burnRatio plus systemRewardRatio must be no greater than 10000"); + require(newBurnRatio.add(systemRewardRatio) <= BLOCK_FEES_RATIO_SCALE, "the burnRatio plus systemRewardRatio must be no greater than 10000"); burnRatio = newBurnRatio; } else if (Memory.compareStrings(key, "maxNumOfMaintaining")) { require(value.length == 32, "length of maxNumOfMaintaining mismatch"); @@ -884,7 +884,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } else if (Memory.compareStrings(key, "systemRewardRatio")) { require(value.length == 32, "length of systemRewardRatio mismatch"); uint256 newSystemRewardRatio = BytesToTypes.bytesToUint256(32, value); - require(newSystemRewardRatio + burnRatio <= BLOCK_FEES_RATIO_SCALE, "the systemRewardRatio plus burnRatio must be no greater than 10000"); + require(newSystemRewardRatio.add(burnRatio) <= BLOCK_FEES_RATIO_SCALE, "the systemRewardRatio plus burnRatio must be no greater than 10000"); systemRewardRatio = newSystemRewardRatio; } else { require(false, "unknown param"); @@ -930,11 +930,11 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica validatorExtraSet[i].isMaintaining = false; validatorExtraSet[i].enterMaintenanceHeight = 0; } else { + currentValidatorSet[i].votingPower = newValidatorSet[i].votingPower; // update the vote address if it is different if (!BytesLib.equal(newVoteAddrs[i], validatorExtraSet[i].voteAddress)) { validatorExtraSet[i].voteAddress = newVoteAddrs[i]; } - currentValidatorSet[i].jailed = newValidatorSet[i].jailed; } } @@ -968,7 +968,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica * Vote address is not considered */ function isSameValidator(Validator memory v1, Validator memory v2) private pure returns(bool) { - return v1.consensusAddress == v2.consensusAddress && v1.feeAddress == v2.feeAddress && v1.BBCFeeAddress == v2.BBCFeeAddress && v1.votingPower == v2.votingPower; + return v1.consensusAddress == v2.consensusAddress && v1.feeAddress == v2.feeAddress && v1.BBCFeeAddress == v2.BBCFeeAddress; } function getVoteAddresses(address[] memory validators) internal view returns(bytes[] memory) { @@ -1074,11 +1074,11 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica uint256 averageDistribute = income / rest; if (averageDistribute != 0) { for (uint i; i