From a281daa398e0d55d29ee9664b8db579fc4814e60 Mon Sep 17 00:00:00 2001 From: Roshan <48975233+loverush@users.noreply.github.com> Date: Wed, 16 Mar 2022 14:06:50 +0800 Subject: [PATCH 01/15] [WIP]Fast Finality: reward distribution and slash parts (#8) * [WIP]Fast Finality: reward distribution and slash parts * Update codes * Fix review comments and update test * Fix code errors related contract SystemReward and BSCValidatorSet * Fix code errors related invalid opcode and add new api * Optimize gasused of updateValidator and update test * Optimize gasused of updateValidator and update test * Minor error fixed * Fix review comments and update scripts * Fix init issue * Fix external view issue and update test * Fix review comments --- contracts/RelayerIncentivize.sol | 78 ++++++++++++------------ contracts/RelayerIncentivize.template | 78 ++++++++++++------------ contracts/System.sol | 2 +- contracts/SystemReward.sol | 44 +++++++++---- contracts/SystemReward.template | 52 ++++++++++------ contracts/TendermintLightClient.sol | 52 ++++++++-------- contracts/TendermintLightClient.template | 52 ++++++++-------- contracts/interface/IBSCValidatorSet.sol | 5 +- truffle-config.js | 4 +- 9 files changed, 203 insertions(+), 164 deletions(-) diff --git a/contracts/RelayerIncentivize.sol b/contracts/RelayerIncentivize.sol index 5bad9ef9..a39a67e9 100644 --- a/contracts/RelayerIncentivize.sol +++ b/contracts/RelayerIncentivize.sol @@ -31,11 +31,11 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { mapping(address => uint256) public packageRelayersSubmitCount; address payable[] public packageRelayerAddressRecord; - uint256 public collectedRewardForHeaderRelayer=0; - uint256 public collectedRewardForTransferRelayer=0; + uint256 public collectedRewardForHeaderRelayer = 0; + uint256 public collectedRewardForTransferRelayer = 0; - uint256 public roundSequence=0; - uint256 public countInRound=0; + uint256 public roundSequence = 0; + uint256 public countInRound = 0; mapping(address => uint256) public relayerRewardVault; @@ -47,14 +47,14 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { function init() onlyNotInit external { require(!alreadyInit, "already initialized"); - headerRelayerRewardRateMolecule=HEADER_RELAYER_REWARD_RATE_MOLECULE; - headerRelayerRewardRateDenominator=HEADER_RELAYER_REWARD_RATE_DENOMINATOR; - callerCompensationMolecule=CALLER_COMPENSATION_MOLECULE; - callerCompensationDenominator=CALLER_COMPENSATION_DENOMINATOR; + headerRelayerRewardRateMolecule = HEADER_RELAYER_REWARD_RATE_MOLECULE; + headerRelayerRewardRateDenominator = HEADER_RELAYER_REWARD_RATE_DENOMINATOR; + callerCompensationMolecule = CALLER_COMPENSATION_MOLECULE; + callerCompensationDenominator = CALLER_COMPENSATION_DENOMINATOR; alreadyInit = true; } - receive() external payable{} + receive() external payable {} function addReward(address payable headerRelayerAddr, address payable packageRelayer, uint256 amount, bool fromSystemReward) onlyInit onlyCrossChainContract external override returns (bool) { uint256 actualAmount; @@ -63,7 +63,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { } else { actualAmount = ISystemReward(TOKEN_HUB_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), amount); if (dynamicExtraIncentiveAmount > 0) { - actualAmount = actualAmount.add(ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), dynamicExtraIncentiveAmount)); + actualAmount = actualAmount.add(ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), dynamicExtraIncentiveAmount)); } } @@ -73,17 +73,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 (packageRelayersSubmitCount[packageRelayer]==0) { + if (packageRelayersSubmitCount[packageRelayer] == 0) { packageRelayerAddressRecord.push(packageRelayer); } ++packageRelayersSubmitCount[packageRelayer]; - if (countInRound>=ROUND_SIZE) { + if (countInRound >= ROUND_SIZE) { emit distributeCollectedReward(roundSequence, collectedRewardForHeaderRelayer, collectedRewardForTransferRelayer); uint256 callerHeaderReward = distributeHeaderRelayerReward(); @@ -98,17 +98,17 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { } function claimRelayerReward(address relayerAddr) external { - uint256 reward = relayerRewardVault[relayerAddr]; - require(reward > 0, "no relayer reward"); - relayerRewardVault[relayerAddr] = 0; - address payable recipient = address(uint160(relayerAddr)); - if (!recipient.send(reward)) { - address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); - systemPayable.transfer(reward); - emit rewardToRelayer(SYSTEM_REWARD_ADDR, reward); - return; - } - emit rewardToRelayer(relayerAddr, reward); + uint256 reward = relayerRewardVault[relayerAddr]; + require(reward > 0, "no relayer reward"); + relayerRewardVault[relayerAddr] = 0; + address payable recipient = address(uint160(relayerAddr)); + if (!recipient.send(reward)) { + address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); + systemPayable.transfer(reward); + emit rewardToRelayer(SYSTEM_REWARD_ADDR, reward); + return; + } + emit rewardToRelayer(relayerAddr, reward); } function calculateRewardForHeaderRelayer(uint256 reward) internal view returns (uint256) { @@ -118,7 +118,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { function distributeHeaderRelayerReward() internal returns (uint256) { uint256 totalReward = collectedRewardForHeaderRelayer; - uint256 totalWeight=0; + uint256 totalWeight = 0; address payable[] memory relayers = headerRelayerAddressRecord; uint256[] memory relayerWeight = new uint256[](relayers.length); for (uint256 index = 0; index < relayers.length; ++index) { @@ -149,7 +149,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { function distributePackageRelayerReward() internal returns (uint256) { uint256 totalReward = collectedRewardForTransferRelayer; - uint256 totalWeight=0; + uint256 totalWeight = 0; address payable[] memory relayers = packageRelayerAddressRecord; uint256[] memory relayerWeight = new uint256[](relayers.length); for (uint256 index = 0; index < relayers.length; ++index) { @@ -177,19 +177,19 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { return callerReward; } - function calculateTransferRelayerWeight(uint256 count) public pure returns(uint256) { + function calculateTransferRelayerWeight(uint256 count) public pure returns (uint256) { if (count <= MAXIMUM_WEIGHT) { return count; - } else if (MAXIMUM_WEIGHT < count && count <= 2*MAXIMUM_WEIGHT) { + } 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)) { - return 3*MAXIMUM_WEIGHT - count; + } else if (2 * MAXIMUM_WEIGHT < count && count <= (2 * MAXIMUM_WEIGHT + 3 * MAXIMUM_WEIGHT / 4)) { + return 3 * MAXIMUM_WEIGHT - count; } else { - return count/4; + return count / 4; } } - function calculateHeaderRelayerWeight(uint256 count) public pure returns(uint256) { + function calculateHeaderRelayerWeight(uint256 count) public pure returns (uint256) { if (count <= MAXIMUM_WEIGHT) { return count; } else { @@ -197,32 +197,32 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { } } - function updateParam(string calldata key, bytes calldata value) override external onlyGov{ + function updateParam(string calldata key, bytes calldata value) override external onlyGov { require(alreadyInit, "contract has not been initialized"); - if (Memory.compareStrings(key,"headerRelayerRewardRateMolecule")) { + if (Memory.compareStrings(key, "headerRelayerRewardRateMolecule")) { require(value.length == 32, "length of headerRelayerRewardRateMolecule mismatch"); uint256 newHeaderRelayerRewardRateMolecule = BytesToTypes.bytesToUint256(32, value); require(newHeaderRelayerRewardRateMolecule <= headerRelayerRewardRateDenominator, "new headerRelayerRewardRateMolecule shouldn't be greater than headerRelayerRewardRateDenominator"); headerRelayerRewardRateMolecule = newHeaderRelayerRewardRateMolecule; - } else if (Memory.compareStrings(key,"headerRelayerRewardRateDenominator")) { + } else if (Memory.compareStrings(key, "headerRelayerRewardRateDenominator")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newHeaderRelayerRewardRateDenominator = BytesToTypes.bytesToUint256(32, value); require(newHeaderRelayerRewardRateDenominator != 0 && newHeaderRelayerRewardRateDenominator >= headerRelayerRewardRateMolecule, "the new headerRelayerRewardRateDenominator must not be zero and no less than headerRelayerRewardRateMolecule"); headerRelayerRewardRateDenominator = newHeaderRelayerRewardRateDenominator; - } else if (Memory.compareStrings(key,"callerCompensationMolecule")) { + } else if (Memory.compareStrings(key, "callerCompensationMolecule")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newCallerCompensationMolecule = BytesToTypes.bytesToUint256(32, value); require(newCallerCompensationMolecule <= callerCompensationDenominator, "new callerCompensationMolecule shouldn't be greater than callerCompensationDenominator"); callerCompensationMolecule = newCallerCompensationMolecule; - } else if (Memory.compareStrings(key,"callerCompensationDenominator")) { + } else if (Memory.compareStrings(key, "callerCompensationDenominator")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newCallerCompensationDenominator = BytesToTypes.bytesToUint256(32, value); require(newCallerCompensationDenominator != 0 && newCallerCompensationDenominator >= callerCompensationMolecule, "the newCallerCompensationDenominator must not be zero and no less than callerCompensationMolecule"); callerCompensationDenominator = newCallerCompensationDenominator; - } else if (Memory.compareStrings(key,"dynamicExtraIncentiveAmount")) { + } else if (Memory.compareStrings(key, "dynamicExtraIncentiveAmount")) { require(value.length == 32, "length of dynamicExtraIncentiveAmount mismatch"); uint256 newDynamicExtraIncentiveAmount = BytesToTypes.bytesToUint256(32, value); - require(newDynamicExtraIncentiveAmount >= 0 , "the newDynamicExtraIncentiveAmount must be no less than zero"); + require(newDynamicExtraIncentiveAmount >= 0, "the newDynamicExtraIncentiveAmount must be no less than zero"); dynamicExtraIncentiveAmount = newDynamicExtraIncentiveAmount; } else { require(false, "unknown param"); diff --git a/contracts/RelayerIncentivize.template b/contracts/RelayerIncentivize.template index e52c3740..eee982c3 100644 --- a/contracts/RelayerIncentivize.template +++ b/contracts/RelayerIncentivize.template @@ -31,11 +31,11 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { mapping(address => uint256) public packageRelayersSubmitCount; address payable[] public packageRelayerAddressRecord; - uint256 public collectedRewardForHeaderRelayer=0; - uint256 public collectedRewardForTransferRelayer=0; + uint256 public collectedRewardForHeaderRelayer = 0; + uint256 public collectedRewardForTransferRelayer = 0; - uint256 public roundSequence=0; - uint256 public countInRound=0; + uint256 public roundSequence = 0; + uint256 public countInRound = 0; mapping(address => uint256) public relayerRewardVault; @@ -47,14 +47,14 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { function init() onlyNotInit external { require(!alreadyInit, "already initialized"); - headerRelayerRewardRateMolecule=HEADER_RELAYER_REWARD_RATE_MOLECULE; - headerRelayerRewardRateDenominator=HEADER_RELAYER_REWARD_RATE_DENOMINATOR; - callerCompensationMolecule=CALLER_COMPENSATION_MOLECULE; - callerCompensationDenominator=CALLER_COMPENSATION_DENOMINATOR; + headerRelayerRewardRateMolecule = HEADER_RELAYER_REWARD_RATE_MOLECULE; + headerRelayerRewardRateDenominator = HEADER_RELAYER_REWARD_RATE_DENOMINATOR; + callerCompensationMolecule = CALLER_COMPENSATION_MOLECULE; + callerCompensationDenominator = CALLER_COMPENSATION_DENOMINATOR; alreadyInit = true; } - receive() external payable{} + receive() external payable {} function addReward(address payable headerRelayerAddr, address payable packageRelayer, uint256 amount, bool fromSystemReward) onlyInit onlyCrossChainContract external override returns (bool) { uint256 actualAmount; @@ -63,7 +63,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { } else { actualAmount = ISystemReward(TOKEN_HUB_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), amount); if (dynamicExtraIncentiveAmount > 0) { - actualAmount = actualAmount.add(ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), dynamicExtraIncentiveAmount)); + actualAmount = actualAmount.add(ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), dynamicExtraIncentiveAmount)); } } @@ -73,17 +73,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 (packageRelayersSubmitCount[packageRelayer]==0) { + if (packageRelayersSubmitCount[packageRelayer] == 0) { packageRelayerAddressRecord.push(packageRelayer); } ++packageRelayersSubmitCount[packageRelayer]; - if (countInRound>=ROUND_SIZE) { + if (countInRound >= ROUND_SIZE) { emit distributeCollectedReward(roundSequence, collectedRewardForHeaderRelayer, collectedRewardForTransferRelayer); uint256 callerHeaderReward = distributeHeaderRelayerReward(); @@ -98,17 +98,17 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { } function claimRelayerReward(address relayerAddr) external { - uint256 reward = relayerRewardVault[relayerAddr]; - require(reward > 0, "no relayer reward"); - relayerRewardVault[relayerAddr] = 0; - address payable recipient = address(uint160(relayerAddr)); - if (!recipient.send(reward)) { - address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); - systemPayable.transfer(reward); - emit rewardToRelayer(SYSTEM_REWARD_ADDR, reward); - return; - } - emit rewardToRelayer(relayerAddr, reward); + uint256 reward = relayerRewardVault[relayerAddr]; + require(reward > 0, "no relayer reward"); + relayerRewardVault[relayerAddr] = 0; + address payable recipient = address(uint160(relayerAddr)); + if (!recipient.send(reward)) { + address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); + systemPayable.transfer(reward); + emit rewardToRelayer(SYSTEM_REWARD_ADDR, reward); + return; + } + emit rewardToRelayer(relayerAddr, reward); } function calculateRewardForHeaderRelayer(uint256 reward) internal view returns (uint256) { @@ -118,7 +118,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { function distributeHeaderRelayerReward() internal returns (uint256) { uint256 totalReward = collectedRewardForHeaderRelayer; - uint256 totalWeight=0; + uint256 totalWeight = 0; address payable[] memory relayers = headerRelayerAddressRecord; uint256[] memory relayerWeight = new uint256[](relayers.length); for (uint256 index = 0; index < relayers.length; ++index) { @@ -149,7 +149,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { function distributePackageRelayerReward() internal returns (uint256) { uint256 totalReward = collectedRewardForTransferRelayer; - uint256 totalWeight=0; + uint256 totalWeight = 0; address payable[] memory relayers = packageRelayerAddressRecord; uint256[] memory relayerWeight = new uint256[](relayers.length); for (uint256 index = 0; index < relayers.length; ++index) { @@ -177,19 +177,19 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { return callerReward; } - function calculateTransferRelayerWeight(uint256 count) public pure returns(uint256) { + function calculateTransferRelayerWeight(uint256 count) public pure returns (uint256) { if (count <= MAXIMUM_WEIGHT) { return count; - } else if (MAXIMUM_WEIGHT < count && count <= 2*MAXIMUM_WEIGHT) { + } 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)) { - return 3*MAXIMUM_WEIGHT - count; + } else if (2 * MAXIMUM_WEIGHT < count && count <= (2 * MAXIMUM_WEIGHT + 3 * MAXIMUM_WEIGHT / 4)) { + return 3 * MAXIMUM_WEIGHT - count; } else { - return count/4; + return count / 4; } } - function calculateHeaderRelayerWeight(uint256 count) public pure returns(uint256) { + function calculateHeaderRelayerWeight(uint256 count) public pure returns (uint256) { if (count <= MAXIMUM_WEIGHT) { return count; } else { @@ -197,32 +197,32 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { } } - function updateParam(string calldata key, bytes calldata value) override external onlyGov{ + function updateParam(string calldata key, bytes calldata value) override external onlyGov { require(alreadyInit, "contract has not been initialized"); - if (Memory.compareStrings(key,"headerRelayerRewardRateMolecule")) { + if (Memory.compareStrings(key, "headerRelayerRewardRateMolecule")) { require(value.length == 32, "length of headerRelayerRewardRateMolecule mismatch"); uint256 newHeaderRelayerRewardRateMolecule = BytesToTypes.bytesToUint256(32, value); require(newHeaderRelayerRewardRateMolecule <= headerRelayerRewardRateDenominator, "new headerRelayerRewardRateMolecule shouldn't be greater than headerRelayerRewardRateDenominator"); headerRelayerRewardRateMolecule = newHeaderRelayerRewardRateMolecule; - } else if (Memory.compareStrings(key,"headerRelayerRewardRateDenominator")) { + } else if (Memory.compareStrings(key, "headerRelayerRewardRateDenominator")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newHeaderRelayerRewardRateDenominator = BytesToTypes.bytesToUint256(32, value); require(newHeaderRelayerRewardRateDenominator != 0 && newHeaderRelayerRewardRateDenominator >= headerRelayerRewardRateMolecule, "the new headerRelayerRewardRateDenominator must not be zero and no less than headerRelayerRewardRateMolecule"); headerRelayerRewardRateDenominator = newHeaderRelayerRewardRateDenominator; - } else if (Memory.compareStrings(key,"callerCompensationMolecule")) { + } else if (Memory.compareStrings(key, "callerCompensationMolecule")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newCallerCompensationMolecule = BytesToTypes.bytesToUint256(32, value); require(newCallerCompensationMolecule <= callerCompensationDenominator, "new callerCompensationMolecule shouldn't be greater than callerCompensationDenominator"); callerCompensationMolecule = newCallerCompensationMolecule; - } else if (Memory.compareStrings(key,"callerCompensationDenominator")) { + } else if (Memory.compareStrings(key, "callerCompensationDenominator")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newCallerCompensationDenominator = BytesToTypes.bytesToUint256(32, value); require(newCallerCompensationDenominator != 0 && newCallerCompensationDenominator >= callerCompensationMolecule, "the newCallerCompensationDenominator must not be zero and no less than callerCompensationMolecule"); callerCompensationDenominator = newCallerCompensationDenominator; - } else if (Memory.compareStrings(key,"dynamicExtraIncentiveAmount")) { + } else if (Memory.compareStrings(key, "dynamicExtraIncentiveAmount")) { require(value.length == 32, "length of dynamicExtraIncentiveAmount mismatch"); uint256 newDynamicExtraIncentiveAmount = BytesToTypes.bytesToUint256(32, value); - require(newDynamicExtraIncentiveAmount >= 0 , "the newDynamicExtraIncentiveAmount must be no less than zero"); + require(newDynamicExtraIncentiveAmount >= 0, "the newDynamicExtraIncentiveAmount must be no less than zero"); dynamicExtraIncentiveAmount = newDynamicExtraIncentiveAmount; } else { require(false, "unknown param"); diff --git a/contracts/System.sol b/contracts/System.sol index b86d845c..67677172 100644 --- a/contracts/System.sol +++ b/contracts/System.sol @@ -25,7 +25,7 @@ contract System { address public constant SYSTEM_REWARD_ADDR = 0x0000000000000000000000000000000000001002; address public constant LIGHT_CLIENT_ADDR = 0x0000000000000000000000000000000000001003; address public constant TOKEN_HUB_ADDR = 0x0000000000000000000000000000000000001004; - address public constant INCENTIVIZE_ADDR=0x0000000000000000000000000000000000001005; + address public constant INCENTIVIZE_ADDR = 0x0000000000000000000000000000000000001005; address public constant RELAYERHUB_CONTRACT_ADDR = 0x0000000000000000000000000000000000001006; address public constant GOV_HUB_ADDR = 0x0000000000000000000000000000000000001007; address public constant TOKEN_MANAGER_ADDR = 0x0000000000000000000000000000000000001008; diff --git a/contracts/SystemReward.sol b/contracts/SystemReward.sol index ffaa2a60..ed0c8df7 100644 --- a/contracts/SystemReward.sol +++ b/contracts/SystemReward.sol @@ -1,8 +1,11 @@ pragma solidity 0.6.4; + import "./System.sol"; +import "./lib/Memory.sol"; +import "./interface/IParamSubscriber.sol"; import "./interface/ISystemReward.sol"; -contract SystemReward is System, ISystemReward{ +contract SystemReward is System, IParamSubscriber, ISystemReward { uint256 public constant MAX_REWARDS = 1e18; uint public numOperator; @@ -19,30 +22,29 @@ contract SystemReward is System, ISystemReward{ _; } - - modifier onlyOperator() { - require(operators[msg.sender],"only operator is allowed to call the method"); - _; - } - event rewardTo(address indexed to, uint256 amount); event rewardEmpty(); event receiveDeposit(address indexed from, uint256 amount); + event updateOperator(address indexed operator); + event paramChange(string key, bytes value); - receive() external payable{ - if (msg.value>0) { + receive() external payable { + if (msg.value > 0) { emit receiveDeposit(msg.sender, msg.value); } } - - function claimRewards(address payable to, uint256 amount) external override(ISystemReward) doInit onlyOperator returns(uint256) { + function claimRewards(address payable to, uint256 amount) external override(ISystemReward) doInit returns (uint256) { + if (!operators[msg.sender]) { + return 0; + } + uint256 actualAmount = amount < address(this).balance ? amount : address(this).balance; if (actualAmount > MAX_REWARDS) { actualAmount = MAX_REWARDS; } - if (actualAmount>0) { + if (actualAmount > 0) { to.transfer(actualAmount); emit rewardTo(to, actualAmount); } else { @@ -54,4 +56,20 @@ contract SystemReward is System, ISystemReward{ function isOperator(address addr) external view returns (bool) { return operators[addr]; } -} \ No newline at end of file + + function updateParam(string calldata key, bytes calldata value) onlyGov external override { + if (Memory.compareStrings(key, "updateOperator")) { + bytes memory valueLocal = value; + require(valueLocal.length == 20, "length of value for updateOperator should be 20"); + address operatorAddr; + assembly { + operatorAddr := mload(add(valueLocal, 20)) + } + operators[operatorAddr] = true; + emit updateOperator(operatorAddr); + } else { + require(false, "unknown param"); + } + emit paramChange(key, value); + } +} diff --git a/contracts/SystemReward.template b/contracts/SystemReward.template index b5dec8a1..ca00f956 100644 --- a/contracts/SystemReward.template +++ b/contracts/SystemReward.template @@ -1,8 +1,11 @@ pragma solidity 0.6.4; + import "./System.sol"; +import "./lib/Memory.sol"; +import "./interface/IParamSubscriber.sol"; import "./interface/ISystemReward.sol"; -contract SystemReward is System, ISystemReward{ +contract SystemReward is System, IParamSubscriber, ISystemReward { uint256 public constant MAX_REWARDS = 1e18; uint public numOperator; @@ -18,28 +21,23 @@ contract SystemReward is System, ISystemReward{ } _; } - - - modifier onlyOperator() { - require(operators[msg.sender],"only operator is allowed to call the method"); - _; - } - {% if mock %} +{% if mock %} event newOperator(address indexed operator); event deleteOperator(address indexed operator); - {% endif %} +{% endif %} event rewardTo(address indexed to, uint256 amount); event rewardEmpty(); event receiveDeposit(address indexed from, uint256 amount); + event updateOperator(address indexed operator); + event paramChange(string key, bytes value); - receive() external payable{ - if (msg.value>0) { + receive() external payable { + if (msg.value > 0) { emit receiveDeposit(msg.sender, msg.value); } } - - {% if mock %} +{% if mock %} modifier onlyOperatorExist(address _operator) { require(operators[_operator], "the operator do not exist"); _; @@ -61,13 +59,17 @@ contract SystemReward is System, ISystemReward{ --numOperator; emit deleteOperator(operator); } - {% endif %} - function claimRewards(address payable to, uint256 amount) external override(ISystemReward) doInit onlyOperator returns(uint256) { +{% endif %} + function claimRewards(address payable to, uint256 amount) external override(ISystemReward) doInit returns (uint256) { + if (!operators[msg.sender]) { + return 0; + } + uint256 actualAmount = amount < address(this).balance ? amount : address(this).balance; if (actualAmount > MAX_REWARDS) { actualAmount = MAX_REWARDS; } - if (actualAmount>0) { + if (actualAmount > 0) { to.transfer(actualAmount); emit rewardTo(to, actualAmount); } else { @@ -79,4 +81,20 @@ contract SystemReward is System, ISystemReward{ function isOperator(address addr) external view returns (bool) { return operators[addr]; } -} \ No newline at end of file + + function updateParam(string calldata key, bytes calldata value) onlyGov external override { + if (Memory.compareStrings(key, "updateOperator")) { + bytes memory valueLocal = value; + require(valueLocal.length == 20, "length of value for updateOperator should be 20"); + address operatorAddr; + assembly { + operatorAddr := mload(add(valueLocal, 20)) + } + operators[operatorAddr] = true; + emit updateOperator(operatorAddr); + } else { + require(false, "unknown param"); + } + emit paramChange(key, value); + } +} diff --git a/contracts/TendermintLightClient.sol b/contracts/TendermintLightClient.sol index 8421a780..1df32a20 100644 --- a/contracts/TendermintLightClient.sol +++ b/contracts/TendermintLightClient.sol @@ -7,13 +7,13 @@ import "./interface/ISystemReward.sol"; import "./interface/IParamSubscriber.sol"; import "./System.sol"; -contract TendermintLightClient is ILightClient, System, IParamSubscriber{ +contract TendermintLightClient is ILightClient, System, IParamSubscriber { struct ConsensusState { - uint64 preValidatorSetChangeHeight; + uint64 preValidatorSetChangeHeight; bytes32 appHash; bytes32 curValidatorSetHash; - bytes nextValidatorSet; + bytes nextValidatorSet; } mapping(uint64 => ConsensusState) public lightClientConsensusStates; @@ -23,7 +23,7 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ bytes32 public chainID; bytes constant public INIT_CONSENSUS_STATE_BYTES = hex"42696e616e63652d436861696e2d4e696c650000000000000000000000000000000000000000000229eca254b3859bffefaf85f4c95da9fbd26527766b784272789c30ec56b380b6eb96442aaab207bc59978ba3dd477690f5c5872334fc39e627723daa97e441e88ba4515150ec3182bc82593df36f8abb25a619187fcfab7e552b94e64ed2deed000000e8d4a51000"; - uint256 constant public INIT_REWARD_FOR_VALIDATOR_SER_CHANGE = 1e16; + uint256 constant public INIT_REWARD_FOR_VALIDATOR_SER_CHANGE = 1e16; uint256 public rewardForValidatorSetChange; event initConsensusState(uint64 initHeight, bytes32 appHash); @@ -75,17 +75,17 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ //32 + 32 + 8 + 32 + 32 + cs.nextValidatorSet.length; uint256 length = 136 + cs.nextValidatorSet.length; - bytes memory input = new bytes(length+header.length); + bytes memory input = new bytes(length + header.length); uint256 ptr = Memory.dataPtr(input); require(encodeConsensusState(cs, preValidatorSetChangeHeight, ptr, length), "failed to serialize consensus state"); // write header to input uint256 src; - ptr = ptr+length; + ptr = ptr + length; (src, length) = Memory.fromBytes(header); Memory.copy(src, ptr, length); - length = input.length+32; + length = input.length + 32; // Maximum validator quantity is 99 bytes32[128] memory result; /* solium-disable-next-line */ @@ -103,11 +103,11 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ length := mload(add(result, 0)) } bool validatorChanged = false; - if ((length&(0x01<<248))!=0x00) { + if ((length & (0x01 << 248)) != 0x00) { validatorChanged = true; ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(msg.sender, rewardForValidatorSetChange); } - length = length&0xffffffffffffffff; + length = length & 0xffffffffffffffff; /* solium-disable-next-line */ assembly { @@ -145,7 +145,7 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ function getChainID() external view returns (string memory) { bytes memory chainIDBytes = new bytes(32); assembly { - mstore(add(chainIDBytes,32), sload(chainID_slot)) + mstore(add(chainIDBytes, 32), sload(chainID_slot)) } uint8 chainIDLength = 0; @@ -175,36 +175,36 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ uint256 length; (src, length) = Memory.fromBytes(cs.nextValidatorSet); Memory.copy(src, outputPtr, length); - outputPtr = outputPtr-32; + outputPtr = outputPtr - 32; bytes32 hash = cs.curValidatorSetHash; /* solium-disable-next-line */ assembly { mstore(outputPtr, hash) } - outputPtr = outputPtr-32; + outputPtr = outputPtr - 32; hash = cs.appHash; /* solium-disable-next-line */ assembly { mstore(outputPtr, hash) } - outputPtr = outputPtr-32; + outputPtr = outputPtr - 32; /* solium-disable-next-line */ assembly { mstore(outputPtr, height) } - outputPtr = outputPtr-8; + outputPtr = outputPtr - 8; /* solium-disable-next-line */ assembly { mstore(outputPtr, sload(chainID_slot)) } - outputPtr = outputPtr-32; + outputPtr = outputPtr - 32; // size doesn't contain length - size = size-32; + size = size - 32; /* solium-disable-next-line */ assembly { mstore(outputPtr, size) @@ -216,22 +216,22 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ // | chainID | height | appHash | curValidatorSetHash | [{validator pubkey, voting power}] | // | 32 bytes | 8 bytes | 32 bytes | 32 bytes | [{32 bytes, 8 bytes}] | /* solium-disable-next-line */ - function decodeConsensusState(uint256 ptr, uint256 size, bool leaveOutValidatorSet) internal pure returns(ConsensusState memory, uint64) { - ptr = ptr+8; + function decodeConsensusState(uint256 ptr, uint256 size, bool leaveOutValidatorSet) internal pure returns (ConsensusState memory, uint64) { + ptr = ptr + 8; uint64 height; /* solium-disable-next-line */ assembly { height := mload(ptr) } - ptr = ptr+32; + ptr = ptr + 32; bytes32 appHash; /* solium-disable-next-line */ assembly { appHash := mload(ptr) } - ptr = ptr+32; + ptr = ptr + 32; bytes32 curValidatorSetHash; /* solium-disable-next-line */ assembly { @@ -245,17 +245,17 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ if (!leaveOutValidatorSet) { uint256 dest; uint256 length; - cs.nextValidatorSet = new bytes(size-104); - (dest,length) = Memory.fromBytes(cs.nextValidatorSet); + cs.nextValidatorSet = new bytes(size - 104); + (dest, length) = Memory.fromBytes(cs.nextValidatorSet); - Memory.copy(ptr+32, dest, length); + Memory.copy(ptr + 32, dest, length); } return (cs, height); } - function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov{ - if (Memory.compareStrings(key,"rewardForValidatorSetChange")) { + function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov { + 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"); @@ -265,4 +265,4 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ } emit paramChange(key, value); } -} \ No newline at end of file +} diff --git a/contracts/TendermintLightClient.template b/contracts/TendermintLightClient.template index 51ceb63f..7145266d 100644 --- a/contracts/TendermintLightClient.template +++ b/contracts/TendermintLightClient.template @@ -7,13 +7,13 @@ import "./interface/ISystemReward.sol"; import "./interface/IParamSubscriber.sol"; import "./System.sol"; -contract TendermintLightClient is ILightClient, System, IParamSubscriber{ +contract TendermintLightClient is ILightClient, System, IParamSubscriber { struct ConsensusState { - uint64 preValidatorSetChangeHeight; + uint64 preValidatorSetChangeHeight; bytes32 appHash; bytes32 curValidatorSetHash; - bytes nextValidatorSet; + bytes nextValidatorSet; } mapping(uint64 => ConsensusState) public lightClientConsensusStates; @@ -23,7 +23,7 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ bytes32 public chainID; bytes constant public INIT_CONSENSUS_STATE_BYTES = hex"{{initConsensusStateBytes}}"; - uint256 constant public INIT_REWARD_FOR_VALIDATOR_SER_CHANGE = {{rewardForValidatorSetChange}}; + uint256 constant public INIT_REWARD_FOR_VALIDATOR_SER_CHANGE = {{rewardForValidatorSetChange}}; uint256 public rewardForValidatorSetChange; event initConsensusState(uint64 initHeight, bytes32 appHash); @@ -75,17 +75,17 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ //32 + 32 + 8 + 32 + 32 + cs.nextValidatorSet.length; uint256 length = 136 + cs.nextValidatorSet.length; - bytes memory input = new bytes(length+header.length); + bytes memory input = new bytes(length + header.length); uint256 ptr = Memory.dataPtr(input); require(encodeConsensusState(cs, preValidatorSetChangeHeight, ptr, length), "failed to serialize consensus state"); // write header to input uint256 src; - ptr = ptr+length; + ptr = ptr + length; (src, length) = Memory.fromBytes(header); Memory.copy(src, ptr, length); - length = input.length+32; + length = input.length + 32; // Maximum validator quantity is 99 bytes32[128] memory result; /* solium-disable-next-line */ @@ -103,11 +103,11 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ length := mload(add(result, 0)) } bool validatorChanged = false; - if ((length&(0x01<<248))!=0x00) { + if ((length & (0x01 << 248)) != 0x00) { validatorChanged = true; ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(msg.sender, rewardForValidatorSetChange); } - length = length&0xffffffffffffffff; + length = length & 0xffffffffffffffff; /* solium-disable-next-line */ assembly { @@ -145,7 +145,7 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ function getChainID() external view returns (string memory) { bytes memory chainIDBytes = new bytes(32); assembly { - mstore(add(chainIDBytes,32), sload(chainID_slot)) + mstore(add(chainIDBytes, 32), sload(chainID_slot)) } uint8 chainIDLength = 0; @@ -175,36 +175,36 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ uint256 length; (src, length) = Memory.fromBytes(cs.nextValidatorSet); Memory.copy(src, outputPtr, length); - outputPtr = outputPtr-32; + outputPtr = outputPtr - 32; bytes32 hash = cs.curValidatorSetHash; /* solium-disable-next-line */ assembly { mstore(outputPtr, hash) } - outputPtr = outputPtr-32; + outputPtr = outputPtr - 32; hash = cs.appHash; /* solium-disable-next-line */ assembly { mstore(outputPtr, hash) } - outputPtr = outputPtr-32; + outputPtr = outputPtr - 32; /* solium-disable-next-line */ assembly { mstore(outputPtr, height) } - outputPtr = outputPtr-8; + outputPtr = outputPtr - 8; /* solium-disable-next-line */ assembly { mstore(outputPtr, sload(chainID_slot)) } - outputPtr = outputPtr-32; + outputPtr = outputPtr - 32; // size doesn't contain length - size = size-32; + size = size - 32; /* solium-disable-next-line */ assembly { mstore(outputPtr, size) @@ -216,22 +216,22 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ // | chainID | height | appHash | curValidatorSetHash | [{validator pubkey, voting power}] | // | 32 bytes | 8 bytes | 32 bytes | 32 bytes | [{32 bytes, 8 bytes}] | /* solium-disable-next-line */ - function decodeConsensusState(uint256 ptr, uint256 size, bool leaveOutValidatorSet) internal pure returns(ConsensusState memory, uint64) { - ptr = ptr+8; + function decodeConsensusState(uint256 ptr, uint256 size, bool leaveOutValidatorSet) internal pure returns (ConsensusState memory, uint64) { + ptr = ptr + 8; uint64 height; /* solium-disable-next-line */ assembly { height := mload(ptr) } - ptr = ptr+32; + ptr = ptr + 32; bytes32 appHash; /* solium-disable-next-line */ assembly { appHash := mload(ptr) } - ptr = ptr+32; + ptr = ptr + 32; bytes32 curValidatorSetHash; /* solium-disable-next-line */ assembly { @@ -245,17 +245,17 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ if (!leaveOutValidatorSet) { uint256 dest; uint256 length; - cs.nextValidatorSet = new bytes(size-104); - (dest,length) = Memory.fromBytes(cs.nextValidatorSet); + cs.nextValidatorSet = new bytes(size - 104); + (dest, length) = Memory.fromBytes(cs.nextValidatorSet); - Memory.copy(ptr+32, dest, length); + Memory.copy(ptr + 32, dest, length); } return (cs, height); } - function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov{ - if (Memory.compareStrings(key,"rewardForValidatorSetChange")) { + function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov { + 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"); @@ -265,4 +265,4 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ } emit paramChange(key, value); } -} \ No newline at end of file +} diff --git a/contracts/interface/IBSCValidatorSet.sol b/contracts/interface/IBSCValidatorSet.sol index 513c9289..51f3e9fe 100644 --- a/contracts/interface/IBSCValidatorSet.sol +++ b/contracts/interface/IBSCValidatorSet.sol @@ -1,7 +1,10 @@ pragma solidity 0.6.4; +pragma experimental ABIEncoderV2; interface IBSCValidatorSet { function misdemeanor(address validator) external; - function felony(address validator)external; + function felony(address validator) external; function isCurrentValidator(address validator) external view returns (bool); + function getLivingValidators() external view returns(address[] memory, bytes[] memory); + function getMiningValidators() external view returns(address[] memory, bytes[] memory); } diff --git a/truffle-config.js b/truffle-config.js index 8c5be080..e2cf168c 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -45,8 +45,8 @@ module.exports = { development: { host: "127.0.0.1", // Localhost (default: none) port: 8545, // Standard Ethereum port (default: none) - network_id: "*", // Any network (default: none) - }, + network_id: "*" // Any network (default: none) + } // Another network with more advanced options... // advanced: { From 4dbe42426d69cb30227b1e0cb06f2388e0c27e9f Mon Sep 17 00:00:00 2001 From: Loverush Date: Mon, 25 Apr 2022 11:38:52 +0800 Subject: [PATCH 02/15] Update for new fast finality rules and related issues --- BLSkeystore.json | 45 + abi/bscvalidatorset.abi | 2386 +++++++++++++++++++-------------- abi/govhub.abi | 860 ++++++------ abi/relayerhub.abi | 888 ++++++------ abi/relayerincentivize.abi | 1532 ++++++++++----------- abi/slashindicator.abi | 1411 +++++++++---------- abi/systemreward.abi | 853 ++++++------ abi/tendermintlightclient.abi | 1239 ++++++++--------- abi/tokenmanager.abi | 2253 +++++++++++++++---------------- generate-validator.js | 25 +- validators.js | 30 +- validators.template | 32 +- 12 files changed, 5818 insertions(+), 5736 deletions(-) create mode 100644 BLSkeystore.json diff --git a/BLSkeystore.json b/BLSkeystore.json new file mode 100644 index 00000000..908cffe2 --- /dev/null +++ b/BLSkeystore.json @@ -0,0 +1,45 @@ +{ + "public_key": [ + "8f2bc5decb56ad5f88d4c704f6ad616d5038cf1bc068419f4d7f3457a853d74048b1ba3531185d6d36d6bd6881034505", + "83126cd32592a6be5e9658805c5da32db2f5d39f2f294a230cf1689b52f8b8be2135802f6b6ca6b11765331de2bb8def", + "b9cafd2354b57acadd88992fd9dc38986ec29d8efd793acb693f0d0f6b8397cb2a9f8d66e01253579c7d38242d3760f6", + "b373f6a4dfc54e625c2796da0789cbb243e6a285329c3c075ab1a9268db45951a2d6c2a2aafd558efc8c5857bd71dbc0", + "ac0646a7851a75f2d0d8239e717ed1874ed83906eff3845cc7a29abd6064adb8a48c221c3d12624f136292b19c0d92de", + "992354e0ff65e8cb4088a72a241992bf68a192ea685f810bda7a193dc056af3be4bf1f65073cf5e906676d32f2eabe60", + "95d8bb8660a34a374a05a3b9c59609f4a6f5598bba8240b59ef61e94ed6161e00108bac0b817bcb4cf13001924d19539", + "b4c030c9c012ab39aea3117fc96203b18ffb5e979ae44f17de64e212a1a97975d419e2060294940a285778e2100ff023", + "ac1e598ae0ccbeeaafa31bc6faefa85c2ae3138699cac79169cd718f1a38445201454ec092a86f200e08a15266bdc6e9", + "af3ca3f530c61bf7e6b82db58dc6bd4c75192044128004510290289330ae1d33269ec873e0a8e890c2619cf3868c8880", + "987c6c786c2d293f4b5337344c8d29ab0264f80851d5698e597e201f7743af3f848a1ffb7c4802a73e06696d99f95e45", + "97d9423cb780f6a09e759a7327fc5e2542ddc54f9d2cd1b836abf30948f45059709510e8421df03ceccf2ef2ecc9c594", + "b71f0d38cc1d05995126fa0ba311541f0ed3c5c7df64e33c8037afa5d72a5a38a83103433b204f1512502748656cf06f", + "b800c8a040b76946ca14470e7a67c9ca76bf9868730336be57235505e1786f3417a969587be2ac7e6aad1ab21db9cff9", + "a625e9aa0681a842091d9cbc26daa9497a9d305acc36d04f2cb42e9aed90a561514f607625fbf84b23f98ce4baadadb5", + "98a7250b7492047cdb0b388e094db5dc073bba5a4bfc9ed2fc0ec68cba5cec1aad06d72a91ed03211f583f52e5e5d221", + "a8fa139e60271c25de8d5c83a4d0d15107152c193897d2307d334425c40d31104b6ee507e5eb3402419bca0625b58835", + "905024253dae51eb1836a3da59e5883f48d768bb73b4c8be76fd3a124af6ed252941653619ab1e429253fc2586c65383", + "a52c02e1279cbadb974a02404d7cece18d70a2835d004a4e7a25c9e120d794f62e76b9728a13ee84bc6567716238c59f", + "aacd7b81831bc19de3a26f013d2bba8cf5a76cf3c6acee742bace02e2a809a96f72245fb6cb54874b72d300a42b14fe3", + "8f16d65d4898459265d237328b419fad130b2cf2ee381e0a0fc3d5898e81b577a0157d0b99b92eda8891b46ff62c9ea9", + "90ddfd09c9af4d0b693a4013b7e42595ea7bb60ee7fb942a8460d63cd5f0e4c3138467b7c2a50518fa26fe9a2450dbc0", + "a2ec2a7e46bb5d99e7307c39b9ba96e0ef245e2588658b5ccb9a8c2f682a111de5775fec6e7508d19e06be40a260cc7d", + "86d0488587c7dd682988d13c7db0bf9994dd21fa886244a1ddd24aea753de38d32d0c762bd6fbeb137b1ae3118c65885", + "b3e34b6aff02bf146faf47e27d813e3c1bcf2a9a424c2ec95da39ea9dd974aeb239e47bd183ac75e8502ca6e610caf7c", + "b45752f376347597826c52202dd5a4695b7f73b4a111d9a39f8bd43220984ecd428280779befa314f4b24ce537b7448b", + "83c96f5cab6a2d0fb3c4c96c7a1bf992c776f10aa6e321157df8b07359bbfdc111587f529d3ed867b1c69a98f57fea6b", + "9107b995298a0a2becc7a1feecc6d8a0cae95d66384ef08adb9dc74023357fb5c1dac1ce9de936eb4015d276150a4933", + "aa7049b3ce18e503b8546b08ef48056780cfeb4a48e50f30d0da8a2b6261e77ed19c40bc8050df874e992072db591575", + "b28f8221b85d07f04d6037a56d96e621d4c25bf3aaff3e745231bcf102dfa34508ca92814854019487b6dcecdaa0bab0", + "a75e47260f047889767fc8cc7121440afa2b4fc372ebc1ef39f72912247ad2efa1e0dc4022d4c44ecab95032fa30df49", + "a76daaa9e8741e7d9a5970f10bc585ce42a3e5ce4e53faadf3327a3b7759223e35aeb30214c0ecf2bca46a2ea1c45855", + "a031dcf5b47643630aba6e0625c21da9e0f76388ea6bcdd33ede31f51a1d080ba322ba0c9aaa5137b18fd3c47453aec9", + "a9be92a80b0909c491cd9475001cc34ee1a766b95109cdc32c8cdfcf7135c8d0e862b8612d0ea79e74d02a09d5403993", + "b490893e8eb5f101b5178e6ff8279fe14eb78b764290095e6e595dfcc11371925dc0af4b9d4bce8e69ac83ce57984e3a", + "89ca38e186e1378b0778cb8d4f0f6d4eef4a15db97a4596a44621548090dfb893f833689b580b0f60a934fd31c271bb3", + "8b20e24ad933b9af0a55a6d34a08e10b832a10f389154dc0dec79b63a38b79ea2f0d9f4fa664b3c06b1b2437cb58236f", + "a1484f2b97137fb957daad064ca6cbe5b99549249ceb51f42e928ec091f94fed642ddffe3a9916769538decd0a9937bf", + "89abcc45efe76bec679ca35c27adbd66fb9712a278e3c8530ab25cfaf997765aee574f5c5745dbb873dbf7e961684347", + "8addebd6ef7609df215e006987040d0a643858f3a4d791beaa77177d67529160e645fac54f0d8acdcd5a088393cb6681", + "85e6972fc98cd3c81d64d40e325acfed44365b97a7567a27939c14dbc7512ddcf54cb1284eb637cfa308ae4e00cb5588" + ] +} \ No newline at end of file diff --git a/abi/bscvalidatorset.abi b/abi/bscvalidatorset.abi index c3194b70..e1be421e 100644 --- a/abi/bscvalidatorset.abi +++ b/abi/bscvalidatorset.abi @@ -1,1016 +1,1374 @@ [ - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "batchTransfer", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "string", - "name": "reason", - "type": "string" - } - ], - "name": "batchTransferFailed", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "reason", - "type": "bytes" - } - ], - "name": "batchTransferLowerFailed", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "validator", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "deprecatedDeposit", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address payable", - "name": "validator", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "directTransfer", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address payable", - "name": "validator", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "directTransferFail", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "string", - "name": "message", - "type": "string" - } - ], - "name": "failReasonWithStr", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "value", - "type": "bytes" - } - ], - "name": "paramChange", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "systemTransfer", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - } - ], - "name": "unexpectedPackage", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "validator", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "validatorDeposit", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "validator", - "type": "address" - } - ], - "name": "validatorEmptyJailed", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "validator", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "validatorFelony", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "validator", - "type": "address" - } - ], - "name": "validatorJailed", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "validator", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "validatorMisdemeanor", - "type": "event" - }, - { - "anonymous": false, - "inputs": [], - "name": "validatorSetUpdated", - "type": "event" - }, - { - "constant": true, - "inputs": [], - "name": "BIND_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CODE_OK", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CROSS_CHAIN_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "DUSTY_INCOMING", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "ERROR_FAIL_CHECK_VALIDATORS", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "ERROR_FAIL_DECODE", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "ERROR_LEN_OF_VAL_MISMATCH", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "ERROR_RELAYFEE_TOO_LARGE", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "ERROR_UNKNOWN_PACKAGE_TYPE", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "EXPIRE_TIME_SECOND_GAP", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "GOV_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "GOV_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "INCENTIVIZE_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "INIT_VALIDATORSET_BYTES", - "outputs": [ - { - "internalType": "bytes", - "name": "", - "type": "bytes" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "JAIL_MESSAGE_TYPE", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "LIGHT_CLIENT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "MAX_NUM_OF_VALIDATORS", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "PRECISION", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "RELAYERHUB_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SLASH_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SLASH_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "STAKING_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SYSTEM_REWARD_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TOKEN_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TOKEN_MANAGER_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TRANSFER_IN_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TRANSFER_OUT_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "VALIDATORS_UPDATE_MESSAGE_TYPE", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "VALIDATOR_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "alreadyInit", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "bscChainID", - "outputs": [ - { - "internalType": "uint16", - "name": "", - "type": "uint16" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "currentValidatorSet", - "outputs": [ - { - "internalType": "address", - "name": "consensusAddress", - "type": "address" - }, - { - "internalType": "address payable", - "name": "feeAddress", - "type": "address" - }, - { - "internalType": "address", - "name": "BBCFeeAddress", - "type": "address" - }, - { - "internalType": "uint64", - "name": "votingPower", - "type": "uint64" - }, - { - "internalType": "bool", - "name": "jailed", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "incoming", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "currentValidatorSetMap", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "expireTimeSecondGap", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "numOfJailed", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "totalInComing", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [], - "name": "init", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - } - ], - "name": "handleSynPackage", - "outputs": [ - { - "internalType": "bytes", - "name": "responsePayload", - "type": "bytes" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - } - ], - "name": "handleAckPackage", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - } - ], - "name": "handleFailAckPackage", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "valAddr", - "type": "address" - } - ], - "name": "deposit", - "outputs": [], - "payable": true, - "stateMutability": "payable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "getValidators", - "outputs": [ - { - "internalType": "address[]", - "name": "", - "type": "address[]" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "validator", - "type": "address" - } - ], - "name": "getIncoming", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "validator", - "type": "address" - } - ], - "name": "misdemeanor", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "validator", - "type": "address" - } - ], - "name": "felony", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "internalType": "bytes", - "name": "value", - "type": "bytes" - } - ], - "name": "updateParam", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - } + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "batchTransfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "string", + "name": "reason", + "type": "string" + } + ], + "name": "batchTransferFailed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "reason", + "type": "bytes" + } + ], + "name": "batchTransferLowerFailed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "validator", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "deprecatedDeposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address payable", + "name": "validator", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "directTransfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address payable", + "name": "validator", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "directTransferFail", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "message", + "type": "string" + } + ], + "name": "failReasonWithStr", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "feeBurned", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "paramChange", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "systemTransfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "unexpectedPackage", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "validator", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "validatorDeposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "validatorEmptyJailed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "validatorEnterMaintenance", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "validatorExitMaintenance", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "validator", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "validatorFelony", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "validatorJailed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "validator", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "validatorMisdemeanor", + "type": "event" + }, + { + "anonymous": false, + "inputs": [], + "name": "validatorSetUpdated", + "type": "event" + }, + { + "inputs": [], + "name": "BIND_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "BURN_ADDRESS", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "BURN_RATIO_SCALE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CODE_OK", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CROSS_CHAIN_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "DUSTY_INCOMING", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "EPOCH", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERROR_FAIL_CHECK_VALIDATORS", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERROR_FAIL_DECODE", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERROR_LEN_OF_VAL_MISMATCH", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERROR_RELAYFEE_TOO_LARGE", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERROR_UNKNOWN_PACKAGE_TYPE", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "EXPIRE_TIME_SECOND_GAP", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INCENTIVIZE_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INIT_BURN_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INIT_FINALITY_REWARD_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INIT_MAINTAIN_SLASH_SCALE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INIT_MAX_NUM_OF_MAINTAINING", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INIT_NUM_OF_CABINETS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INIT_VALIDATORSET_BYTES", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "JAIL_MESSAGE_TYPE", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LIGHT_CLIENT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_NUM_OF_VALIDATORS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PRECISION", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "RELAYERHUB_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "STAKING_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SYSTEM_REWARD_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_MANAGER_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_IN_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_OUT_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VALIDATORS_UPDATE_MESSAGE_TYPE", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VALIDATOR_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "alreadyInit", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "bscChainID", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "burnRatio", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "burnRatioInitialized", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "currentValidatorSet", + "outputs": [ + { + "internalType": "address", + "name": "consensusAddress", + "type": "address" + }, + { + "internalType": "address payable", + "name": "feeAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "BBCFeeAddress", + "type": "address" + }, + { + "internalType": "uint64", + "name": "votingPower", + "type": "uint64" + }, + { + "internalType": "bool", + "name": "jailed", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "incoming", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "currentValidatorSetMap", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "expireTimeSecondGap", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "finalityRewardRatio", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "maintainSlashScale", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "maxNumOfCandidates", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "maxNumOfMaintaining", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "maxNumOfWorkingCandidates", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "numOfCabinets", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "numOfJailed", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "numOfMaintaining", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "previousHeight", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalInComing", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "validatorExtraSet", + "outputs": [ + { + "internalType": "uint256", + "name": "enterMaintenanceHeight", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "isMaintaining", + "type": "bool" + }, + { + "internalType": "bytes", + "name": "voteAddress", + "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" + }, + { + "inputs": [], + "name": "init", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "handleSynPackage", + "outputs": [ + { + "internalType": "bytes", + "name": "responsePayload", + "type": "bytes" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "handleAckPackage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "handleFailAckPackage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "valAddr", + "type": "address" + } + ], + "name": "deposit", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "getLivingValidators", + "outputs": [ + { + "internalType": "address[]", + "name": "", + "type": "address[]" + }, + { + "internalType": "bytes[]", + "name": "", + "type": "bytes[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getMiningValidators", + "outputs": [ + { + "internalType": "address[]", + "name": "", + "type": "address[]" + }, + { + "internalType": "bytes[]", + "name": "", + "type": "bytes[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getValidators", + "outputs": [ + { + "internalType": "address[]", + "name": "", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "isWorkingValidator", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "getIncoming", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "isCurrentValidator", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "valAddrs", + "type": "address[]" + }, + { + "internalType": "uint256[]", + "name": "weights", + "type": "uint256[]" + } + ], + "name": "distributeFinalityReward", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "misdemeanor", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "felony", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_validator", + "type": "address" + } + ], + "name": "getCurrentValidatorIndex", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "canEnterMaintenance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "enterMaintenance", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "exitMaintenance", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "updateParam", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } ] \ No newline at end of file diff --git a/abi/govhub.abi b/abi/govhub.abi index 981fd424..fb3a9020 100644 --- a/abi/govhub.abi +++ b/abi/govhub.abi @@ -1,458 +1,406 @@ [ - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "bytes", - "name": "message", - "type": "bytes" - } - ], - "name": "failReasonWithBytes", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "string", - "name": "message", - "type": "string" - } - ], - "name": "failReasonWithStr", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "value", - "type": "bytes" - } - ], - "name": "paramChange", - "type": "event" - }, - { - "constant": true, - "inputs": [], - "name": "BIND_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CODE_OK", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CROSS_CHAIN_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "ERROR_FAIL_DECODE", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "ERROR_TARGET_CONTRACT_FAIL", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "ERROR_TARGET_NOT_CONTRACT", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "GOV_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "GOV_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "INCENTIVIZE_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "LIGHT_CLIENT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "PARAM_UPDATE_MESSAGE_TYPE", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "RELAYERHUB_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SLASH_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SLASH_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "STAKING_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SYSTEM_REWARD_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TOKEN_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TOKEN_MANAGER_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TRANSFER_IN_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TRANSFER_OUT_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "VALIDATOR_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "alreadyInit", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "bscChainID", - "outputs": [ - { - "internalType": "uint16", - "name": "", - "type": "uint16" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - } - ], - "name": "handleSynPackage", - "outputs": [ - { - "internalType": "bytes", - "name": "responsePayload", - "type": "bytes" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "", - "type": "bytes" - } - ], - "name": "handleAckPackage", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "", - "type": "bytes" - } - ], - "name": "handleFailAckPackage", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - } + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "bytes", + "name": "message", + "type": "bytes" + } + ], + "name": "failReasonWithBytes", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "message", + "type": "string" + } + ], + "name": "failReasonWithStr", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "paramChange", + "type": "event" + }, + { + "inputs": [], + "name": "BIND_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CODE_OK", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CROSS_CHAIN_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERROR_FAIL_DECODE", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERROR_TARGET_CONTRACT_FAIL", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERROR_TARGET_NOT_CONTRACT", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INCENTIVIZE_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LIGHT_CLIENT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PARAM_UPDATE_MESSAGE_TYPE", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "RELAYERHUB_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "STAKING_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SYSTEM_REWARD_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_MANAGER_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_IN_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_OUT_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VALIDATOR_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "alreadyInit", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "bscChainID", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "handleSynPackage", + "outputs": [ + { + "internalType": "bytes", + "name": "responsePayload", + "type": "bytes" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "name": "handleAckPackage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "name": "handleFailAckPackage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } ] \ No newline at end of file diff --git a/abi/relayerhub.abi b/abi/relayerhub.abi index 719c4cc6..a4851bc2 100644 --- a/abi/relayerhub.abi +++ b/abi/relayerhub.abi @@ -1,475 +1,417 @@ [ - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "value", - "type": "bytes" - } - ], - "name": "paramChange", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "_relayer", - "type": "address" - } - ], - "name": "relayerRegister", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "_relayer", - "type": "address" - } - ], - "name": "relayerUnRegister", - "type": "event" - }, - { - "constant": true, - "inputs": [], - "name": "BIND_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CODE_OK", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CROSS_CHAIN_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "ERROR_FAIL_DECODE", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "GOV_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "GOV_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "INCENTIVIZE_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "INIT_DUES", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "INIT_REQUIRED_DEPOSIT", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "LIGHT_CLIENT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "RELAYERHUB_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SLASH_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SLASH_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "STAKING_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SYSTEM_REWARD_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TOKEN_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TOKEN_MANAGER_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TRANSFER_IN_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TRANSFER_OUT_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "VALIDATOR_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "alreadyInit", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "bscChainID", - "outputs": [ - { - "internalType": "uint16", - "name": "", - "type": "uint16" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "dues", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "requiredDeposit", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [], - "name": "init", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [], - "name": "register", - "outputs": [], - "payable": true, - "stateMutability": "payable", - "type": "function" - }, - { - "constant": false, - "inputs": [], - "name": "unregister", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "internalType": "bytes", - "name": "value", - "type": "bytes" - } - ], - "name": "updateParam", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "sender", - "type": "address" - } - ], - "name": "isRelayer", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - } + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "paramChange", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_relayer", + "type": "address" + } + ], + "name": "relayerRegister", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_relayer", + "type": "address" + } + ], + "name": "relayerUnRegister", + "type": "event" + }, + { + "inputs": [], + "name": "BIND_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CODE_OK", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CROSS_CHAIN_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERROR_FAIL_DECODE", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INCENTIVIZE_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INIT_DUES", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INIT_REQUIRED_DEPOSIT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LIGHT_CLIENT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "RELAYERHUB_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "STAKING_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SYSTEM_REWARD_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_MANAGER_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_IN_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_OUT_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VALIDATOR_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "alreadyInit", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "bscChainID", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "dues", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "requiredDeposit", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "init", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "register", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "unregister", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "updateParam", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "isRelayer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + } ] \ No newline at end of file diff --git a/abi/relayerincentivize.abi b/abi/relayerincentivize.abi index b389ff6b..c452d088 100644 --- a/abi/relayerincentivize.abi +++ b/abi/relayerincentivize.abi @@ -1,807 +1,729 @@ [ - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "sequence", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "roundRewardForHeaderRelayer", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "roundRewardForTransferRelayer", - "type": "uint256" - } - ], - "name": "distributeCollectedReward", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "value", - "type": "bytes" - } - ], - "name": "paramChange", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "relayer", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "rewardToRelayer", - "type": "event" - }, - { - "payable": true, - "stateMutability": "payable", - "type": "fallback" - }, - { - "constant": true, - "inputs": [], - "name": "BIND_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CALLER_COMPENSATION_DENOMINATOR", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CALLER_COMPENSATION_MOLECULE", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CODE_OK", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CROSS_CHAIN_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "ERROR_FAIL_DECODE", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "GOV_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "GOV_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "HEADER_RELAYER_REWARD_RATE_DENOMINATOR", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "HEADER_RELAYER_REWARD_RATE_MOLECULE", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "INCENTIVIZE_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "LIGHT_CLIENT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "MAXIMUM_WEIGHT", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "RELAYERHUB_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "ROUND_SIZE", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SLASH_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SLASH_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "STAKING_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SYSTEM_REWARD_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TOKEN_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TOKEN_MANAGER_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TRANSFER_IN_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TRANSFER_OUT_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "VALIDATOR_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "alreadyInit", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "bscChainID", - "outputs": [ - { - "internalType": "uint16", - "name": "", - "type": "uint16" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "callerCompensationDenominator", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "callerCompensationMolecule", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "collectedRewardForHeaderRelayer", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "collectedRewardForTransferRelayer", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "countInRound", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "headerRelayerAddressRecord", - "outputs": [ - { - "internalType": "address payable", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "headerRelayerRewardRateDenominator", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "headerRelayerRewardRateMolecule", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "headerRelayersSubmitCount", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "packageRelayerAddressRecord", - "outputs": [ - { - "internalType": "address payable", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "packageRelayersSubmitCount", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "relayerRewardVault", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "roundSequence", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [], - "name": "init", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address payable", - "name": "headerRelayerAddr", - "type": "address" - }, - { - "internalType": "address payable", - "name": "packageRelayer", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "fromSystemReward", - "type": "bool" - } - ], - "name": "addReward", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "relayerAddr", - "type": "address" - } - ], - "name": "claimRelayerReward", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint256", - "name": "count", - "type": "uint256" - } - ], - "name": "calculateTransferRelayerWeight", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "pure", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint256", - "name": "count", - "type": "uint256" - } - ], - "name": "calculateHeaderRelayerWeight", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "pure", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "internalType": "bytes", - "name": "value", - "type": "bytes" - } - ], - "name": "updateParam", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - } + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "sequence", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "roundRewardForHeaderRelayer", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "roundRewardForTransferRelayer", + "type": "uint256" + } + ], + "name": "distributeCollectedReward", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "paramChange", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "relayer", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "rewardToRelayer", + "type": "event" + }, + { + "inputs": [], + "name": "BIND_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CALLER_COMPENSATION_DENOMINATOR", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CALLER_COMPENSATION_MOLECULE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CODE_OK", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CROSS_CHAIN_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERROR_FAIL_DECODE", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "HEADER_RELAYER_REWARD_RATE_DENOMINATOR", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "HEADER_RELAYER_REWARD_RATE_MOLECULE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INCENTIVIZE_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LIGHT_CLIENT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAXIMUM_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "RELAYERHUB_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ROUND_SIZE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "STAKING_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SYSTEM_REWARD_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_MANAGER_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_IN_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_OUT_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VALIDATOR_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "alreadyInit", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "bscChainID", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "callerCompensationDenominator", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "callerCompensationMolecule", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "collectedRewardForHeaderRelayer", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "collectedRewardForTransferRelayer", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "countInRound", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "dynamicExtraIncentiveAmount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "headerRelayerAddressRecord", + "outputs": [ + { + "internalType": "address payable", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "headerRelayerRewardRateDenominator", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "headerRelayerRewardRateMolecule", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "headerRelayersSubmitCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "packageRelayerAddressRecord", + "outputs": [ + { + "internalType": "address payable", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "packageRelayersSubmitCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "relayerRewardVault", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "roundSequence", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" + }, + { + "inputs": [], + "name": "init", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address payable", + "name": "headerRelayerAddr", + "type": "address" + }, + { + "internalType": "address payable", + "name": "packageRelayer", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "fromSystemReward", + "type": "bool" + } + ], + "name": "addReward", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "relayerAddr", + "type": "address" + } + ], + "name": "claimRelayerReward", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "count", + "type": "uint256" + } + ], + "name": "calculateTransferRelayerWeight", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "count", + "type": "uint256" + } + ], + "name": "calculateHeaderRelayerWeight", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "updateParam", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } ] \ No newline at end of file diff --git a/abi/slashindicator.abi b/abi/slashindicator.abi index 60eb3d90..01450fad 100644 --- a/abi/slashindicator.abi +++ b/abi/slashindicator.abi @@ -1,674 +1,741 @@ [ - { - "anonymous": false, - "inputs": [], - "name": "crashResponse", - "type": "event" - }, - { - "anonymous": false, - "inputs": [], - "name": "indicatorCleaned", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint32", - "name": "code", - "type": "uint32" - } - ], - "name": "knownResponse", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "value", - "type": "bytes" - } - ], - "name": "paramChange", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint32", - "name": "code", - "type": "uint32" - } - ], - "name": "unKnownResponse", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "validator", - "type": "address" - } - ], - "name": "validatorSlashed", - "type": "event" - }, - { - "constant": true, - "inputs": [], - "name": "BIND_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "BSC_RELAYER_REWARD", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CODE_OK", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CROSS_CHAIN_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "DECREASE_RATE", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "ERROR_FAIL_DECODE", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "FELONY_THRESHOLD", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "GOV_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "GOV_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "INCENTIVIZE_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "LIGHT_CLIENT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "MISDEMEANOR_THRESHOLD", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "RELAYERHUB_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SLASH_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SLASH_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "STAKING_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SYSTEM_REWARD_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TOKEN_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TOKEN_MANAGER_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TRANSFER_IN_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TRANSFER_OUT_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "VALIDATOR_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "alreadyInit", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "bscChainID", - "outputs": [ - { - "internalType": "uint16", - "name": "", - "type": "uint16" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "felonyThreshold", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "indicators", - "outputs": [ - { - "internalType": "uint256", - "name": "height", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "count", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "exist", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "misdemeanorThreshold", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "previousHeight", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "validators", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [], - "name": "init", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "", - "type": "bytes" - } - ], - "name": "handleSynPackage", - "outputs": [ - { - "internalType": "bytes", - "name": "", - "type": "bytes" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - } - ], - "name": "handleAckPackage", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "", - "type": "bytes" - } - ], - "name": "handleFailAckPackage", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "validator", - "type": "address" - } - ], - "name": "slash", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [], - "name": "clean", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "internalType": "bytes", - "name": "value", - "type": "bytes" - } - ], - "name": "updateParam", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "validator", - "type": "address" - } - ], - "name": "getSlashIndicator", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - } + { + "anonymous": false, + "inputs": [], + "name": "crashResponse", + "type": "event" + }, + { + "anonymous": false, + "inputs": [], + "name": "indicatorCleaned", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint32", + "name": "code", + "type": "uint32" + } + ], + "name": "knownResponse", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "paramChange", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint32", + "name": "code", + "type": "uint32" + } + ], + "name": "unKnownResponse", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "validatorSlashed", + "type": "event" + }, + { + "inputs": [], + "name": "BIND_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "BSC_RELAYER_REWARD", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CODE_OK", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CROSS_CHAIN_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "DECREASE_RATE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERROR_FAIL_DECODE", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "FELONY_THRESHOLD", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INCENTIVIZE_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INIT_FINALITY_SLASH_REWARD_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LIGHT_CLIENT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MISDEMEANOR_THRESHOLD", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "RELAYERHUB_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "STAKING_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SYSTEM_REWARD_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_MANAGER_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_IN_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_OUT_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VALIDATOR_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "alreadyInit", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "bscChainID", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "felonyThreshold", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "finalitySlashRewardRatio", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "indicators", + "outputs": [ + { + "internalType": "uint256", + "name": "height", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "count", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "exist", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "misdemeanorThreshold", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "previousHeight", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "validators", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "init", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "name": "handleSynPackage", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "handleAckPackage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "name": "handleFailAckPackage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "slash", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "clean", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "components": [ + { + "internalType": "uint256", + "name": "srcNum", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "srcHash", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "tarNum", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "tarHash", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "sig", + "type": "bytes" + } + ], + "internalType": "struct SlashIndicator.VoteData", + "name": "voteA", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "srcNum", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "srcHash", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "tarNum", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "tarHash", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "sig", + "type": "bytes" + } + ], + "internalType": "struct SlashIndicator.VoteData", + "name": "voteB", + "type": "tuple" + }, + { + "internalType": "address", + "name": "valAddr", + "type": "address" + } + ], + "internalType": "struct SlashIndicator.FinalityEvidence", + "name": "_evidence", + "type": "tuple" + } + ], + "name": "submitFinalityViolationEvidence", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "sendFelonyPackage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "updateParam", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "getSlashIndicator", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getSlashThresholds", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + } ] \ No newline at end of file diff --git a/abi/systemreward.abi b/abi/systemreward.abi index aca3233f..621ecc47 100644 --- a/abi/systemreward.abi +++ b/abi/systemreward.abi @@ -1,428 +1,429 @@ [ - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "receiveDeposit", - "type": "event" - }, - { - "anonymous": false, - "inputs": [], - "name": "rewardEmpty", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "rewardTo", - "type": "event" - }, - { - "payable": true, - "stateMutability": "payable", - "type": "fallback" - }, - { - "constant": true, - "inputs": [], - "name": "BIND_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CODE_OK", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CROSS_CHAIN_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "ERROR_FAIL_DECODE", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "GOV_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "GOV_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "INCENTIVIZE_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "LIGHT_CLIENT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "MAX_REWARDS", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "RELAYERHUB_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SLASH_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SLASH_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "STAKING_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SYSTEM_REWARD_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TOKEN_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TOKEN_MANAGER_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TRANSFER_IN_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TRANSFER_OUT_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "VALIDATOR_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "alreadyInit", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "bscChainID", - "outputs": [ - { - "internalType": "uint16", - "name": "", - "type": "uint16" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "numOperator", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address payable", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "claimRewards", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "addr", - "type": "address" - } - ], - "name": "isOperator", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - } + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "paramChange", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "receiveDeposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [], + "name": "rewardEmpty", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "rewardTo", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "operator", + "type": "address" + } + ], + "name": "updateOperator", + "type": "event" + }, + { + "inputs": [], + "name": "BIND_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CODE_OK", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CROSS_CHAIN_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERROR_FAIL_DECODE", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INCENTIVIZE_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LIGHT_CLIENT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_REWARDS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "RELAYERHUB_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "STAKING_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SYSTEM_REWARD_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_MANAGER_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_IN_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_OUT_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VALIDATOR_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "alreadyInit", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "bscChainID", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "numOperator", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" + }, + { + "inputs": [ + { + "internalType": "address payable", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "claimRewards", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "addr", + "type": "address" + } + ], + "name": "isOperator", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "updateParam", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } ] \ No newline at end of file diff --git a/abi/tendermintlightclient.abi b/abi/tendermintlightclient.abi index 8ed2dc61..93dc47fc 100644 --- a/abi/tendermintlightclient.abi +++ b/abi/tendermintlightclient.abi @@ -1,657 +1,586 @@ [ - { - "inputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint64", - "name": "initHeight", - "type": "uint64" - }, - { - "indexed": false, - "internalType": "bytes32", - "name": "appHash", - "type": "bytes32" - } - ], - "name": "initConsensusState", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "value", - "type": "bytes" - } - ], - "name": "paramChange", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint64", - "name": "height", - "type": "uint64" - }, - { - "indexed": false, - "internalType": "uint64", - "name": "preValidatorSetChangeHeight", - "type": "uint64" - }, - { - "indexed": false, - "internalType": "bytes32", - "name": "appHash", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "bool", - "name": "validatorChanged", - "type": "bool" - } - ], - "name": "syncConsensusState", - "type": "event" - }, - { - "constant": true, - "inputs": [], - "name": "BIND_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CODE_OK", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CROSS_CHAIN_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "ERROR_FAIL_DECODE", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "GOV_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "GOV_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "INCENTIVIZE_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "INIT_CONSENSUS_STATE_BYTES", - "outputs": [ - { - "internalType": "bytes", - "name": "", - "type": "bytes" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "INIT_REWARD_FOR_VALIDATOR_SER_CHANGE", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "LIGHT_CLIENT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "RELAYERHUB_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SLASH_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SLASH_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "STAKING_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SYSTEM_REWARD_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TOKEN_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TOKEN_MANAGER_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TRANSFER_IN_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TRANSFER_OUT_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "VALIDATOR_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "alreadyInit", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "bscChainID", - "outputs": [ - { - "internalType": "uint16", - "name": "", - "type": "uint16" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "chainID", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "initialHeight", - "outputs": [ - { - "internalType": "uint64", - "name": "", - "type": "uint64" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "latestHeight", - "outputs": [ - { - "internalType": "uint64", - "name": "", - "type": "uint64" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint64", - "name": "", - "type": "uint64" - } - ], - "name": "lightClientConsensusStates", - "outputs": [ - { - "internalType": "uint64", - "name": "preValidatorSetChangeHeight", - "type": "uint64" - }, - { - "internalType": "bytes32", - "name": "appHash", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "curValidatorSetHash", - "type": "bytes32" - }, - { - "internalType": "bytes", - "name": "nextValidatorSet", - "type": "bytes" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "rewardForValidatorSetChange", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint64", - "name": "", - "type": "uint64" - } - ], - "name": "submitters", - "outputs": [ - { - "internalType": "address payable", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [], - "name": "init", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "bytes", - "name": "header", - "type": "bytes" - }, - { - "internalType": "uint64", - "name": "height", - "type": "uint64" - } - ], - "name": "syncTendermintHeader", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint64", - "name": "height", - "type": "uint64" - } - ], - "name": "isHeaderSynced", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint64", - "name": "height", - "type": "uint64" - } - ], - "name": "getAppHash", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint64", - "name": "height", - "type": "uint64" - } - ], - "name": "getSubmitter", - "outputs": [ - { - "internalType": "address payable", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "getChainID", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "internalType": "bytes", - "name": "value", - "type": "bytes" - } - ], - "name": "updateParam", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - } + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint64", + "name": "initHeight", + "type": "uint64" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "appHash", + "type": "bytes32" + } + ], + "name": "initConsensusState", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "paramChange", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint64", + "name": "height", + "type": "uint64" + }, + { + "indexed": false, + "internalType": "uint64", + "name": "preValidatorSetChangeHeight", + "type": "uint64" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "appHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "bool", + "name": "validatorChanged", + "type": "bool" + } + ], + "name": "syncConsensusState", + "type": "event" + }, + { + "inputs": [], + "name": "BIND_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CODE_OK", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CROSS_CHAIN_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERROR_FAIL_DECODE", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INCENTIVIZE_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INIT_CONSENSUS_STATE_BYTES", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INIT_REWARD_FOR_VALIDATOR_SER_CHANGE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LIGHT_CLIENT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "RELAYERHUB_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "STAKING_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SYSTEM_REWARD_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_MANAGER_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_IN_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_OUT_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VALIDATOR_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "alreadyInit", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "bscChainID", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "chainID", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "initialHeight", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "latestHeight", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "name": "lightClientConsensusStates", + "outputs": [ + { + "internalType": "uint64", + "name": "preValidatorSetChangeHeight", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "appHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "curValidatorSetHash", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "nextValidatorSet", + "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "rewardForValidatorSetChange", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "name": "submitters", + "outputs": [ + { + "internalType": "address payable", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "init", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "header", + "type": "bytes" + }, + { + "internalType": "uint64", + "name": "height", + "type": "uint64" + } + ], + "name": "syncTendermintHeader", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint64", + "name": "height", + "type": "uint64" + } + ], + "name": "isHeaderSynced", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint64", + "name": "height", + "type": "uint64" + } + ], + "name": "getAppHash", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint64", + "name": "height", + "type": "uint64" + } + ], + "name": "getSubmitter", + "outputs": [ + { + "internalType": "address payable", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getChainID", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "updateParam", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } ] \ No newline at end of file diff --git a/abi/tokenmanager.abi b/abi/tokenmanager.abi index 1d03235b..8a0e31d1 100644 --- a/abi/tokenmanager.abi +++ b/abi/tokenmanager.abi @@ -1,1202 +1,1055 @@ [ - { - "inputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "contractAddr", - "type": "address" - }, - { - "indexed": false, - "internalType": "string", - "name": "bep2Symbol", - "type": "string" - }, - { - "indexed": false, - "internalType": "uint32", - "name": "failedReason", - "type": "uint32" - } - ], - "name": "bindFailure", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "contractAddr", - "type": "address" - }, - { - "indexed": false, - "internalType": "string", - "name": "bep2Symbol", - "type": "string" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "totalSupply", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "peggyAmount", - "type": "uint256" - } - ], - "name": "bindSuccess", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "bep20Addr", - "type": "address" - }, - { - "indexed": false, - "internalType": "string", - "name": "reason", - "type": "string" - } - ], - "name": "mirrorFailure", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "bep20Addr", - "type": "address" - }, - { - "indexed": false, - "internalType": "bytes32", - "name": "bep2Symbol", - "type": "bytes32" - } - ], - "name": "mirrorSuccess", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "value", - "type": "bytes" - } - ], - "name": "paramChange", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "bep20Addr", - "type": "address" - }, - { - "indexed": false, - "internalType": "string", - "name": "reason", - "type": "string" - } - ], - "name": "syncFailure", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "bep20Addr", - "type": "address" - } - ], - "name": "syncSuccess", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - } - ], - "name": "unexpectedPackage", - "type": "event" - }, - { - "constant": true, - "inputs": [], - "name": "BEP2_TOKEN_DECIMALS", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "BIND_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "BIND_PACKAGE", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "BIND_STATUS_ALREADY_BOUND_TOKEN", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "BIND_STATUS_DECIMALS_MISMATCH", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "BIND_STATUS_REJECTED", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "BIND_STATUS_SUCCESS", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "BIND_STATUS_SYMBOL_MISMATCH", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "BIND_STATUS_TIMEOUT", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "BIND_STATUS_TOO_MUCH_TOKENHUB_BALANCE", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "BIND_STATUS_TOTAL_SUPPLY_MISMATCH", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CODE_OK", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CROSS_CHAIN_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "ERROR_FAIL_DECODE", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "GOV_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "GOV_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "INCENTIVIZE_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "LIGHT_CLIENT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "MAXIMUM_BEP20_SYMBOL_LEN", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "MAX_BEP2_TOTAL_SUPPLY", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "MAX_GAS_FOR_TRANSFER_BNB", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "MINIMUM_BEP20_SYMBOL_LEN", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "MIRROR_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "MIRROR_STATUS_ALREADY_BOUND", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "MIRROR_STATUS_DUPLICATED_BEP2_SYMBOL", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "MIRROR_STATUS_SUCCESS", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "MIRROR_STATUS_TIMEOUT", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "RELAYERHUB_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SLASH_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SLASH_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "STAKING_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SYNC_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SYNC_STATUS_NOT_BOUND_MIRROR", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SYNC_STATUS_SUCCESS", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SYNC_STATUS_TIMEOUT", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "SYSTEM_REWARD_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TEN_DECIMALS", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TOKEN_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TOKEN_MANAGER_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TRANSFER_IN_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "TRANSFER_OUT_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "UNBIND_PACKAGE", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "VALIDATOR_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "alreadyInit", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "contractAddr", - "type": "address" - }, - { - "internalType": "string", - "name": "bep2Symbol", - "type": "string" - } - ], - "name": "approveBind", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": true, - "stateMutability": "payable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "name": "bindPackageRecord", - "outputs": [ - { - "internalType": "uint8", - "name": "packageType", - "type": "uint8" - }, - { - "internalType": "bytes32", - "name": "bep2TokenSymbol", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "contractAddr", - "type": "address" - }, - { - "internalType": "uint256", - "name": "totalSupply", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "peggyAmount", - "type": "uint256" - }, - { - "internalType": "uint8", - "name": "bep20Decimals", - "type": "uint8" - }, - { - "internalType": "uint64", - "name": "expireTime", - "type": "uint64" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "boundByMirror", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "bscChainID", - "outputs": [ - { - "internalType": "uint16", - "name": "", - "type": "uint16" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "string", - "name": "bep2Symbol", - "type": "string" - } - ], - "name": "expireBind", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": true, - "stateMutability": "payable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - } - ], - "name": "handleAckPackage", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - } - ], - "name": "handleFailAckPackage", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - } - ], - "name": "handleSynPackage", - "outputs": [ - { - "internalType": "bytes", - "name": "", - "type": "bytes" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "bep20Addr", - "type": "address" - }, - { - "internalType": "uint64", - "name": "expireTime", - "type": "uint64" - } - ], - "name": "mirror", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": true, - "stateMutability": "payable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "mirrorFee", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "mirrorPendingRecord", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "string", - "name": "symbol", - "type": "string" - } - ], - "name": "queryRequiredLockAmountForBind", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "contractAddr", - "type": "address" - }, - { - "internalType": "string", - "name": "bep2Symbol", - "type": "string" - } - ], - "name": "rejectBind", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": true, - "stateMutability": "payable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "bep20Addr", - "type": "address" - }, - { - "internalType": "uint64", - "name": "expireTime", - "type": "uint64" - } - ], - "name": "sync", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": true, - "stateMutability": "payable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "syncFee", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "internalType": "bytes", - "name": "value", - "type": "bytes" - } - ], - "name": "updateParam", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - } + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "contractAddr", + "type": "address" + }, + { + "indexed": false, + "internalType": "string", + "name": "bep2Symbol", + "type": "string" + }, + { + "indexed": false, + "internalType": "uint32", + "name": "failedReason", + "type": "uint32" + } + ], + "name": "bindFailure", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "contractAddr", + "type": "address" + }, + { + "indexed": false, + "internalType": "string", + "name": "bep2Symbol", + "type": "string" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "totalSupply", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "peggyAmount", + "type": "uint256" + } + ], + "name": "bindSuccess", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "bep20Addr", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "errCode", + "type": "uint8" + } + ], + "name": "mirrorFailure", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "bep20Addr", + "type": "address" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "bep2Symbol", + "type": "bytes32" + } + ], + "name": "mirrorSuccess", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "paramChange", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "bep20Addr", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "errCode", + "type": "uint8" + } + ], + "name": "syncFailure", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "bep20Addr", + "type": "address" + } + ], + "name": "syncSuccess", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "unexpectedPackage", + "type": "event" + }, + { + "inputs": [], + "name": "BEP2_TOKEN_DECIMALS", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "BIND_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "BIND_PACKAGE", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "BIND_STATUS_ALREADY_BOUND_TOKEN", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "BIND_STATUS_DECIMALS_MISMATCH", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "BIND_STATUS_REJECTED", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "BIND_STATUS_SYMBOL_MISMATCH", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "BIND_STATUS_TIMEOUT", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "BIND_STATUS_TOO_MUCH_TOKENHUB_BALANCE", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "BIND_STATUS_TOTAL_SUPPLY_MISMATCH", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CODE_OK", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CROSS_CHAIN_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERROR_FAIL_DECODE", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INCENTIVIZE_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LIGHT_CLIENT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LOG_MAX_UINT256", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAXIMUM_BEP20_SYMBOL_LEN", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_BEP2_TOTAL_SUPPLY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_GAS_FOR_TRANSFER_BNB", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MINIMUM_BEP20_SYMBOL_LEN", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MIRROR_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MIRROR_STATUS_ALREADY_BOUND", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MIRROR_STATUS_DUPLICATED_BEP2_SYMBOL", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MIRROR_STATUS_TIMEOUT", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "RELAYERHUB_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "STAKING_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SYNC_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SYNC_STATUS_NOT_BOUND_MIRROR", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SYNC_STATUS_TIMEOUT", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SYSTEM_REWARD_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TEN_DECIMALS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_MANAGER_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_IN_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_OUT_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "UNBIND_PACKAGE", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VALIDATOR_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "alreadyInit", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "name": "bindPackageRecord", + "outputs": [ + { + "internalType": "uint8", + "name": "packageType", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "bep2TokenSymbol", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "contractAddr", + "type": "address" + }, + { + "internalType": "uint256", + "name": "totalSupply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "peggyAmount", + "type": "uint256" + }, + { + "internalType": "uint8", + "name": "bep20Decimals", + "type": "uint8" + }, + { + "internalType": "uint64", + "name": "expireTime", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "boundByMirror", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "bscChainID", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "mirrorFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "mirrorPendingRecord", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "syncFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "handleSynPackage", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "handleAckPackage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "handleFailAckPackage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "contractAddr", + "type": "address" + }, + { + "internalType": "string", + "name": "bep2Symbol", + "type": "string" + } + ], + "name": "approveBind", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "contractAddr", + "type": "address" + }, + { + "internalType": "string", + "name": "bep2Symbol", + "type": "string" + } + ], + "name": "rejectBind", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "bep2Symbol", + "type": "string" + } + ], + "name": "expireBind", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "bep20Addr", + "type": "address" + }, + { + "internalType": "uint64", + "name": "expireTime", + "type": "uint64" + } + ], + "name": "mirror", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "bep20Addr", + "type": "address" + }, + { + "internalType": "uint64", + "name": "expireTime", + "type": "uint64" + } + ], + "name": "sync", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "updateParam", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "symbol", + "type": "string" + } + ], + "name": "queryRequiredLockAmountForBind", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + } ] \ No newline at end of file diff --git a/generate-validator.js b/generate-validator.js index b23556fb..338d3605 100644 --- a/generate-validator.js +++ b/generate-validator.js @@ -1,35 +1,38 @@ const fs = require("fs"); -const readline = require('readline'); +const readline = require("readline"); const nunjucks = require("nunjucks"); - +const BLSKeys = require("./BLSkeystore.json"); async function processValidatorConf() { - const fileStream = fs.createReadStream(__dirname + '/validators.conf'); + const fileStream = fs.createReadStream(__dirname + "/validators.conf"); + const publicKey = BLSKeys.public_key; const rl = readline.createInterface({ input: fileStream, - crlfDelay: Infinity + crlfDelay: Infinity, }); let validators = []; for await (const line of rl) { // Each line in input.txt will be successively available here as `line`. - let vs = line.split(",") + let vs = line.split(","); validators.push({ consensusAddr: vs[0], feeAddr: vs[1], bscFeeAddr: vs[2], votingPower: vs[3], - }) + bLSPublicKey: "0x" + publicKey.pop() + }); } return validators } -processValidatorConf().then(function (validators) { +processValidatorConf().then(function (validators, bLSPublicKeys) { const data = { - validators: validators + validators: validators, + bLSPublicKeys: bLSPublicKeys, }; - const templateString = fs.readFileSync(__dirname + '/validators.template').toString(); + const templateString = fs.readFileSync(__dirname + "/validators.template").toString(); const resultString = nunjucks.renderString(templateString, data); - fs.writeFileSync(__dirname + '/validators.js', resultString); + fs.writeFileSync(__dirname + "/validators.js", resultString); console.log("BSCValidatorSet file updated."); -}) +}); diff --git a/validators.js b/validators.js index 355e0a99..9573a57d 100644 --- a/validators.js +++ b/validators.js @@ -10,44 +10,50 @@ const validators = [ votingPower: 0x0000000000000064 } ]; +const bLSPublicKeys = [ + "0x85e6972fc98cd3c81d64d40e325acfed44365b97a7567a27939c14dbc7512ddcf54cb1284eb637cfa308ae4e00cb5588", +]; // =============== Do not edit below ==== -function generateExtradata(validators) { - let extraVanity =Buffer.alloc(32); - let validatorsBytes = extraDataSerialize(validators); - let extraSeal =Buffer.alloc(65); - return Buffer.concat([extraVanity,validatorsBytes,extraSeal]); +function generateExtradata(validators, bLSPublicKeys) { + let extraVanity = Buffer.alloc(32); + let validatorsBytes = extraDataSerialize(validators, bLSPublicKeys); + let extraSeal = Buffer.alloc(65); + return Buffer.concat([extraVanity, validatorsBytes, extraSeal]); } -function extraDataSerialize(validators) { +function extraDataSerialize(validators, bLSPublicKeys) { let n = validators.length; let arr = []; - for(let i = 0;i Date: Mon, 25 Apr 2022 15:44:23 +0800 Subject: [PATCH 03/15] Revert code format changes --- contracts/RelayerIncentivize.sol | 78 ++++++++++++------------ contracts/RelayerIncentivize.template | 78 ++++++++++++------------ contracts/System.sol | 2 +- contracts/SystemReward.sol | 9 +-- contracts/SystemReward.template | 13 ++-- contracts/TendermintLightClient.sol | 52 ++++++++-------- contracts/TendermintLightClient.template | 52 ++++++++-------- contracts/interface/IBSCValidatorSet.sol | 2 +- generate-validator.js | 12 ++-- truffle-config.js | 4 +- validators.js | 6 +- validators.template | 12 ++-- 12 files changed, 161 insertions(+), 159 deletions(-) diff --git a/contracts/RelayerIncentivize.sol b/contracts/RelayerIncentivize.sol index a39a67e9..5bad9ef9 100644 --- a/contracts/RelayerIncentivize.sol +++ b/contracts/RelayerIncentivize.sol @@ -31,11 +31,11 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { mapping(address => uint256) public packageRelayersSubmitCount; address payable[] public packageRelayerAddressRecord; - uint256 public collectedRewardForHeaderRelayer = 0; - uint256 public collectedRewardForTransferRelayer = 0; + uint256 public collectedRewardForHeaderRelayer=0; + uint256 public collectedRewardForTransferRelayer=0; - uint256 public roundSequence = 0; - uint256 public countInRound = 0; + uint256 public roundSequence=0; + uint256 public countInRound=0; mapping(address => uint256) public relayerRewardVault; @@ -47,14 +47,14 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { function init() onlyNotInit external { require(!alreadyInit, "already initialized"); - headerRelayerRewardRateMolecule = HEADER_RELAYER_REWARD_RATE_MOLECULE; - headerRelayerRewardRateDenominator = HEADER_RELAYER_REWARD_RATE_DENOMINATOR; - callerCompensationMolecule = CALLER_COMPENSATION_MOLECULE; - callerCompensationDenominator = CALLER_COMPENSATION_DENOMINATOR; + headerRelayerRewardRateMolecule=HEADER_RELAYER_REWARD_RATE_MOLECULE; + headerRelayerRewardRateDenominator=HEADER_RELAYER_REWARD_RATE_DENOMINATOR; + callerCompensationMolecule=CALLER_COMPENSATION_MOLECULE; + callerCompensationDenominator=CALLER_COMPENSATION_DENOMINATOR; alreadyInit = true; } - receive() external payable {} + receive() external payable{} function addReward(address payable headerRelayerAddr, address payable packageRelayer, uint256 amount, bool fromSystemReward) onlyInit onlyCrossChainContract external override returns (bool) { uint256 actualAmount; @@ -63,7 +63,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { } else { actualAmount = ISystemReward(TOKEN_HUB_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), amount); if (dynamicExtraIncentiveAmount > 0) { - actualAmount = actualAmount.add(ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), dynamicExtraIncentiveAmount)); + actualAmount = actualAmount.add(ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), dynamicExtraIncentiveAmount)); } } @@ -73,17 +73,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 (packageRelayersSubmitCount[packageRelayer] == 0) { + if (packageRelayersSubmitCount[packageRelayer]==0) { packageRelayerAddressRecord.push(packageRelayer); } ++packageRelayersSubmitCount[packageRelayer]; - if (countInRound >= ROUND_SIZE) { + if (countInRound>=ROUND_SIZE) { emit distributeCollectedReward(roundSequence, collectedRewardForHeaderRelayer, collectedRewardForTransferRelayer); uint256 callerHeaderReward = distributeHeaderRelayerReward(); @@ -98,17 +98,17 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { } function claimRelayerReward(address relayerAddr) external { - uint256 reward = relayerRewardVault[relayerAddr]; - require(reward > 0, "no relayer reward"); - relayerRewardVault[relayerAddr] = 0; - address payable recipient = address(uint160(relayerAddr)); - if (!recipient.send(reward)) { - address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); - systemPayable.transfer(reward); - emit rewardToRelayer(SYSTEM_REWARD_ADDR, reward); - return; - } - emit rewardToRelayer(relayerAddr, reward); + uint256 reward = relayerRewardVault[relayerAddr]; + require(reward > 0, "no relayer reward"); + relayerRewardVault[relayerAddr] = 0; + address payable recipient = address(uint160(relayerAddr)); + if (!recipient.send(reward)) { + address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); + systemPayable.transfer(reward); + emit rewardToRelayer(SYSTEM_REWARD_ADDR, reward); + return; + } + emit rewardToRelayer(relayerAddr, reward); } function calculateRewardForHeaderRelayer(uint256 reward) internal view returns (uint256) { @@ -118,7 +118,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { function distributeHeaderRelayerReward() internal returns (uint256) { uint256 totalReward = collectedRewardForHeaderRelayer; - uint256 totalWeight = 0; + uint256 totalWeight=0; address payable[] memory relayers = headerRelayerAddressRecord; uint256[] memory relayerWeight = new uint256[](relayers.length); for (uint256 index = 0; index < relayers.length; ++index) { @@ -149,7 +149,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { function distributePackageRelayerReward() internal returns (uint256) { uint256 totalReward = collectedRewardForTransferRelayer; - uint256 totalWeight = 0; + uint256 totalWeight=0; address payable[] memory relayers = packageRelayerAddressRecord; uint256[] memory relayerWeight = new uint256[](relayers.length); for (uint256 index = 0; index < relayers.length; ++index) { @@ -177,19 +177,19 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { return callerReward; } - function calculateTransferRelayerWeight(uint256 count) public pure returns (uint256) { + function calculateTransferRelayerWeight(uint256 count) public pure returns(uint256) { if (count <= MAXIMUM_WEIGHT) { return count; - } else if (MAXIMUM_WEIGHT < count && count <= 2 * MAXIMUM_WEIGHT) { + } 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)) { - return 3 * MAXIMUM_WEIGHT - count; + } else if (2*MAXIMUM_WEIGHT < count && count <= (2*MAXIMUM_WEIGHT + 3*MAXIMUM_WEIGHT/4)) { + return 3*MAXIMUM_WEIGHT - count; } else { - return count / 4; + return count/4; } } - function calculateHeaderRelayerWeight(uint256 count) public pure returns (uint256) { + function calculateHeaderRelayerWeight(uint256 count) public pure returns(uint256) { if (count <= MAXIMUM_WEIGHT) { return count; } else { @@ -197,32 +197,32 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { } } - function updateParam(string calldata key, bytes calldata value) override external onlyGov { + function updateParam(string calldata key, bytes calldata value) override external onlyGov{ require(alreadyInit, "contract has not been initialized"); - if (Memory.compareStrings(key, "headerRelayerRewardRateMolecule")) { + if (Memory.compareStrings(key,"headerRelayerRewardRateMolecule")) { require(value.length == 32, "length of headerRelayerRewardRateMolecule mismatch"); uint256 newHeaderRelayerRewardRateMolecule = BytesToTypes.bytesToUint256(32, value); require(newHeaderRelayerRewardRateMolecule <= headerRelayerRewardRateDenominator, "new headerRelayerRewardRateMolecule shouldn't be greater than headerRelayerRewardRateDenominator"); headerRelayerRewardRateMolecule = newHeaderRelayerRewardRateMolecule; - } else if (Memory.compareStrings(key, "headerRelayerRewardRateDenominator")) { + } else if (Memory.compareStrings(key,"headerRelayerRewardRateDenominator")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newHeaderRelayerRewardRateDenominator = BytesToTypes.bytesToUint256(32, value); require(newHeaderRelayerRewardRateDenominator != 0 && newHeaderRelayerRewardRateDenominator >= headerRelayerRewardRateMolecule, "the new headerRelayerRewardRateDenominator must not be zero and no less than headerRelayerRewardRateMolecule"); headerRelayerRewardRateDenominator = newHeaderRelayerRewardRateDenominator; - } else if (Memory.compareStrings(key, "callerCompensationMolecule")) { + } else if (Memory.compareStrings(key,"callerCompensationMolecule")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newCallerCompensationMolecule = BytesToTypes.bytesToUint256(32, value); require(newCallerCompensationMolecule <= callerCompensationDenominator, "new callerCompensationMolecule shouldn't be greater than callerCompensationDenominator"); callerCompensationMolecule = newCallerCompensationMolecule; - } else if (Memory.compareStrings(key, "callerCompensationDenominator")) { + } else if (Memory.compareStrings(key,"callerCompensationDenominator")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newCallerCompensationDenominator = BytesToTypes.bytesToUint256(32, value); require(newCallerCompensationDenominator != 0 && newCallerCompensationDenominator >= callerCompensationMolecule, "the newCallerCompensationDenominator must not be zero and no less than callerCompensationMolecule"); callerCompensationDenominator = newCallerCompensationDenominator; - } else if (Memory.compareStrings(key, "dynamicExtraIncentiveAmount")) { + } else if (Memory.compareStrings(key,"dynamicExtraIncentiveAmount")) { require(value.length == 32, "length of dynamicExtraIncentiveAmount mismatch"); uint256 newDynamicExtraIncentiveAmount = BytesToTypes.bytesToUint256(32, value); - require(newDynamicExtraIncentiveAmount >= 0, "the newDynamicExtraIncentiveAmount must be no less than zero"); + require(newDynamicExtraIncentiveAmount >= 0 , "the newDynamicExtraIncentiveAmount must be no less than zero"); dynamicExtraIncentiveAmount = newDynamicExtraIncentiveAmount; } else { require(false, "unknown param"); diff --git a/contracts/RelayerIncentivize.template b/contracts/RelayerIncentivize.template index eee982c3..e52c3740 100644 --- a/contracts/RelayerIncentivize.template +++ b/contracts/RelayerIncentivize.template @@ -31,11 +31,11 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { mapping(address => uint256) public packageRelayersSubmitCount; address payable[] public packageRelayerAddressRecord; - uint256 public collectedRewardForHeaderRelayer = 0; - uint256 public collectedRewardForTransferRelayer = 0; + uint256 public collectedRewardForHeaderRelayer=0; + uint256 public collectedRewardForTransferRelayer=0; - uint256 public roundSequence = 0; - uint256 public countInRound = 0; + uint256 public roundSequence=0; + uint256 public countInRound=0; mapping(address => uint256) public relayerRewardVault; @@ -47,14 +47,14 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { function init() onlyNotInit external { require(!alreadyInit, "already initialized"); - headerRelayerRewardRateMolecule = HEADER_RELAYER_REWARD_RATE_MOLECULE; - headerRelayerRewardRateDenominator = HEADER_RELAYER_REWARD_RATE_DENOMINATOR; - callerCompensationMolecule = CALLER_COMPENSATION_MOLECULE; - callerCompensationDenominator = CALLER_COMPENSATION_DENOMINATOR; + headerRelayerRewardRateMolecule=HEADER_RELAYER_REWARD_RATE_MOLECULE; + headerRelayerRewardRateDenominator=HEADER_RELAYER_REWARD_RATE_DENOMINATOR; + callerCompensationMolecule=CALLER_COMPENSATION_MOLECULE; + callerCompensationDenominator=CALLER_COMPENSATION_DENOMINATOR; alreadyInit = true; } - receive() external payable {} + receive() external payable{} function addReward(address payable headerRelayerAddr, address payable packageRelayer, uint256 amount, bool fromSystemReward) onlyInit onlyCrossChainContract external override returns (bool) { uint256 actualAmount; @@ -63,7 +63,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { } else { actualAmount = ISystemReward(TOKEN_HUB_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), amount); if (dynamicExtraIncentiveAmount > 0) { - actualAmount = actualAmount.add(ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), dynamicExtraIncentiveAmount)); + actualAmount = actualAmount.add(ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), dynamicExtraIncentiveAmount)); } } @@ -73,17 +73,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 (packageRelayersSubmitCount[packageRelayer] == 0) { + if (packageRelayersSubmitCount[packageRelayer]==0) { packageRelayerAddressRecord.push(packageRelayer); } ++packageRelayersSubmitCount[packageRelayer]; - if (countInRound >= ROUND_SIZE) { + if (countInRound>=ROUND_SIZE) { emit distributeCollectedReward(roundSequence, collectedRewardForHeaderRelayer, collectedRewardForTransferRelayer); uint256 callerHeaderReward = distributeHeaderRelayerReward(); @@ -98,17 +98,17 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { } function claimRelayerReward(address relayerAddr) external { - uint256 reward = relayerRewardVault[relayerAddr]; - require(reward > 0, "no relayer reward"); - relayerRewardVault[relayerAddr] = 0; - address payable recipient = address(uint160(relayerAddr)); - if (!recipient.send(reward)) { - address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); - systemPayable.transfer(reward); - emit rewardToRelayer(SYSTEM_REWARD_ADDR, reward); - return; - } - emit rewardToRelayer(relayerAddr, reward); + uint256 reward = relayerRewardVault[relayerAddr]; + require(reward > 0, "no relayer reward"); + relayerRewardVault[relayerAddr] = 0; + address payable recipient = address(uint160(relayerAddr)); + if (!recipient.send(reward)) { + address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); + systemPayable.transfer(reward); + emit rewardToRelayer(SYSTEM_REWARD_ADDR, reward); + return; + } + emit rewardToRelayer(relayerAddr, reward); } function calculateRewardForHeaderRelayer(uint256 reward) internal view returns (uint256) { @@ -118,7 +118,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { function distributeHeaderRelayerReward() internal returns (uint256) { uint256 totalReward = collectedRewardForHeaderRelayer; - uint256 totalWeight = 0; + uint256 totalWeight=0; address payable[] memory relayers = headerRelayerAddressRecord; uint256[] memory relayerWeight = new uint256[](relayers.length); for (uint256 index = 0; index < relayers.length; ++index) { @@ -149,7 +149,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { function distributePackageRelayerReward() internal returns (uint256) { uint256 totalReward = collectedRewardForTransferRelayer; - uint256 totalWeight = 0; + uint256 totalWeight=0; address payable[] memory relayers = packageRelayerAddressRecord; uint256[] memory relayerWeight = new uint256[](relayers.length); for (uint256 index = 0; index < relayers.length; ++index) { @@ -177,19 +177,19 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { return callerReward; } - function calculateTransferRelayerWeight(uint256 count) public pure returns (uint256) { + function calculateTransferRelayerWeight(uint256 count) public pure returns(uint256) { if (count <= MAXIMUM_WEIGHT) { return count; - } else if (MAXIMUM_WEIGHT < count && count <= 2 * MAXIMUM_WEIGHT) { + } 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)) { - return 3 * MAXIMUM_WEIGHT - count; + } else if (2*MAXIMUM_WEIGHT < count && count <= (2*MAXIMUM_WEIGHT + 3*MAXIMUM_WEIGHT/4)) { + return 3*MAXIMUM_WEIGHT - count; } else { - return count / 4; + return count/4; } } - function calculateHeaderRelayerWeight(uint256 count) public pure returns (uint256) { + function calculateHeaderRelayerWeight(uint256 count) public pure returns(uint256) { if (count <= MAXIMUM_WEIGHT) { return count; } else { @@ -197,32 +197,32 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber { } } - function updateParam(string calldata key, bytes calldata value) override external onlyGov { + function updateParam(string calldata key, bytes calldata value) override external onlyGov{ require(alreadyInit, "contract has not been initialized"); - if (Memory.compareStrings(key, "headerRelayerRewardRateMolecule")) { + if (Memory.compareStrings(key,"headerRelayerRewardRateMolecule")) { require(value.length == 32, "length of headerRelayerRewardRateMolecule mismatch"); uint256 newHeaderRelayerRewardRateMolecule = BytesToTypes.bytesToUint256(32, value); require(newHeaderRelayerRewardRateMolecule <= headerRelayerRewardRateDenominator, "new headerRelayerRewardRateMolecule shouldn't be greater than headerRelayerRewardRateDenominator"); headerRelayerRewardRateMolecule = newHeaderRelayerRewardRateMolecule; - } else if (Memory.compareStrings(key, "headerRelayerRewardRateDenominator")) { + } else if (Memory.compareStrings(key,"headerRelayerRewardRateDenominator")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newHeaderRelayerRewardRateDenominator = BytesToTypes.bytesToUint256(32, value); require(newHeaderRelayerRewardRateDenominator != 0 && newHeaderRelayerRewardRateDenominator >= headerRelayerRewardRateMolecule, "the new headerRelayerRewardRateDenominator must not be zero and no less than headerRelayerRewardRateMolecule"); headerRelayerRewardRateDenominator = newHeaderRelayerRewardRateDenominator; - } else if (Memory.compareStrings(key, "callerCompensationMolecule")) { + } else if (Memory.compareStrings(key,"callerCompensationMolecule")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newCallerCompensationMolecule = BytesToTypes.bytesToUint256(32, value); require(newCallerCompensationMolecule <= callerCompensationDenominator, "new callerCompensationMolecule shouldn't be greater than callerCompensationDenominator"); callerCompensationMolecule = newCallerCompensationMolecule; - } else if (Memory.compareStrings(key, "callerCompensationDenominator")) { + } else if (Memory.compareStrings(key,"callerCompensationDenominator")) { require(value.length == 32, "length of rewardForValidatorSetChange mismatch"); uint256 newCallerCompensationDenominator = BytesToTypes.bytesToUint256(32, value); require(newCallerCompensationDenominator != 0 && newCallerCompensationDenominator >= callerCompensationMolecule, "the newCallerCompensationDenominator must not be zero and no less than callerCompensationMolecule"); callerCompensationDenominator = newCallerCompensationDenominator; - } else if (Memory.compareStrings(key, "dynamicExtraIncentiveAmount")) { + } else if (Memory.compareStrings(key,"dynamicExtraIncentiveAmount")) { require(value.length == 32, "length of dynamicExtraIncentiveAmount mismatch"); uint256 newDynamicExtraIncentiveAmount = BytesToTypes.bytesToUint256(32, value); - require(newDynamicExtraIncentiveAmount >= 0, "the newDynamicExtraIncentiveAmount must be no less than zero"); + require(newDynamicExtraIncentiveAmount >= 0 , "the newDynamicExtraIncentiveAmount must be no less than zero"); dynamicExtraIncentiveAmount = newDynamicExtraIncentiveAmount; } else { require(false, "unknown param"); diff --git a/contracts/System.sol b/contracts/System.sol index 67677172..b86d845c 100644 --- a/contracts/System.sol +++ b/contracts/System.sol @@ -25,7 +25,7 @@ contract System { address public constant SYSTEM_REWARD_ADDR = 0x0000000000000000000000000000000000001002; address public constant LIGHT_CLIENT_ADDR = 0x0000000000000000000000000000000000001003; address public constant TOKEN_HUB_ADDR = 0x0000000000000000000000000000000000001004; - address public constant INCENTIVIZE_ADDR = 0x0000000000000000000000000000000000001005; + address public constant INCENTIVIZE_ADDR=0x0000000000000000000000000000000000001005; address public constant RELAYERHUB_CONTRACT_ADDR = 0x0000000000000000000000000000000000001006; address public constant GOV_HUB_ADDR = 0x0000000000000000000000000000000000001007; address public constant TOKEN_MANAGER_ADDR = 0x0000000000000000000000000000000000001008; diff --git a/contracts/SystemReward.sol b/contracts/SystemReward.sol index ed0c8df7..5e65d9c7 100644 --- a/contracts/SystemReward.sol +++ b/contracts/SystemReward.sol @@ -29,12 +29,13 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { event paramChange(string key, bytes value); - receive() external payable { - if (msg.value > 0) { + receive() external payable{ + if (msg.value>0) { emit receiveDeposit(msg.sender, msg.value); } } + function claimRewards(address payable to, uint256 amount) external override(ISystemReward) doInit returns (uint256) { if (!operators[msg.sender]) { return 0; @@ -44,7 +45,7 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { if (actualAmount > MAX_REWARDS) { actualAmount = MAX_REWARDS; } - if (actualAmount > 0) { + if (actualAmount>0) { to.transfer(actualAmount); emit rewardTo(to, actualAmount); } else { @@ -72,4 +73,4 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { } emit paramChange(key, value); } -} +} \ No newline at end of file diff --git a/contracts/SystemReward.template b/contracts/SystemReward.template index ca00f956..38727983 100644 --- a/contracts/SystemReward.template +++ b/contracts/SystemReward.template @@ -24,7 +24,7 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { {% if mock %} event newOperator(address indexed operator); event deleteOperator(address indexed operator); -{% endif %} + {% endif %} event rewardTo(address indexed to, uint256 amount); event rewardEmpty(); event receiveDeposit(address indexed from, uint256 amount); @@ -32,12 +32,13 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { event paramChange(string key, bytes value); - receive() external payable { - if (msg.value > 0) { + receive() external payable{ + if (msg.value>0) { emit receiveDeposit(msg.sender, msg.value); } } -{% if mock %} + + {% if mock %} modifier onlyOperatorExist(address _operator) { require(operators[_operator], "the operator do not exist"); _; @@ -69,7 +70,7 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { if (actualAmount > MAX_REWARDS) { actualAmount = MAX_REWARDS; } - if (actualAmount > 0) { + if (actualAmount>0) { to.transfer(actualAmount); emit rewardTo(to, actualAmount); } else { @@ -97,4 +98,4 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { } emit paramChange(key, value); } -} +} \ No newline at end of file diff --git a/contracts/TendermintLightClient.sol b/contracts/TendermintLightClient.sol index 1df32a20..8421a780 100644 --- a/contracts/TendermintLightClient.sol +++ b/contracts/TendermintLightClient.sol @@ -7,13 +7,13 @@ import "./interface/ISystemReward.sol"; import "./interface/IParamSubscriber.sol"; import "./System.sol"; -contract TendermintLightClient is ILightClient, System, IParamSubscriber { +contract TendermintLightClient is ILightClient, System, IParamSubscriber{ struct ConsensusState { - uint64 preValidatorSetChangeHeight; + uint64 preValidatorSetChangeHeight; bytes32 appHash; bytes32 curValidatorSetHash; - bytes nextValidatorSet; + bytes nextValidatorSet; } mapping(uint64 => ConsensusState) public lightClientConsensusStates; @@ -23,7 +23,7 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber { bytes32 public chainID; bytes constant public INIT_CONSENSUS_STATE_BYTES = hex"42696e616e63652d436861696e2d4e696c650000000000000000000000000000000000000000000229eca254b3859bffefaf85f4c95da9fbd26527766b784272789c30ec56b380b6eb96442aaab207bc59978ba3dd477690f5c5872334fc39e627723daa97e441e88ba4515150ec3182bc82593df36f8abb25a619187fcfab7e552b94e64ed2deed000000e8d4a51000"; - uint256 constant public INIT_REWARD_FOR_VALIDATOR_SER_CHANGE = 1e16; + uint256 constant public INIT_REWARD_FOR_VALIDATOR_SER_CHANGE = 1e16; uint256 public rewardForValidatorSetChange; event initConsensusState(uint64 initHeight, bytes32 appHash); @@ -75,17 +75,17 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber { //32 + 32 + 8 + 32 + 32 + cs.nextValidatorSet.length; uint256 length = 136 + cs.nextValidatorSet.length; - bytes memory input = new bytes(length + header.length); + bytes memory input = new bytes(length+header.length); uint256 ptr = Memory.dataPtr(input); require(encodeConsensusState(cs, preValidatorSetChangeHeight, ptr, length), "failed to serialize consensus state"); // write header to input uint256 src; - ptr = ptr + length; + ptr = ptr+length; (src, length) = Memory.fromBytes(header); Memory.copy(src, ptr, length); - length = input.length + 32; + length = input.length+32; // Maximum validator quantity is 99 bytes32[128] memory result; /* solium-disable-next-line */ @@ -103,11 +103,11 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber { length := mload(add(result, 0)) } bool validatorChanged = false; - if ((length & (0x01 << 248)) != 0x00) { + if ((length&(0x01<<248))!=0x00) { validatorChanged = true; ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(msg.sender, rewardForValidatorSetChange); } - length = length & 0xffffffffffffffff; + length = length&0xffffffffffffffff; /* solium-disable-next-line */ assembly { @@ -145,7 +145,7 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber { function getChainID() external view returns (string memory) { bytes memory chainIDBytes = new bytes(32); assembly { - mstore(add(chainIDBytes, 32), sload(chainID_slot)) + mstore(add(chainIDBytes,32), sload(chainID_slot)) } uint8 chainIDLength = 0; @@ -175,36 +175,36 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber { uint256 length; (src, length) = Memory.fromBytes(cs.nextValidatorSet); Memory.copy(src, outputPtr, length); - outputPtr = outputPtr - 32; + outputPtr = outputPtr-32; bytes32 hash = cs.curValidatorSetHash; /* solium-disable-next-line */ assembly { mstore(outputPtr, hash) } - outputPtr = outputPtr - 32; + outputPtr = outputPtr-32; hash = cs.appHash; /* solium-disable-next-line */ assembly { mstore(outputPtr, hash) } - outputPtr = outputPtr - 32; + outputPtr = outputPtr-32; /* solium-disable-next-line */ assembly { mstore(outputPtr, height) } - outputPtr = outputPtr - 8; + outputPtr = outputPtr-8; /* solium-disable-next-line */ assembly { mstore(outputPtr, sload(chainID_slot)) } - outputPtr = outputPtr - 32; + outputPtr = outputPtr-32; // size doesn't contain length - size = size - 32; + size = size-32; /* solium-disable-next-line */ assembly { mstore(outputPtr, size) @@ -216,22 +216,22 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber { // | chainID | height | appHash | curValidatorSetHash | [{validator pubkey, voting power}] | // | 32 bytes | 8 bytes | 32 bytes | 32 bytes | [{32 bytes, 8 bytes}] | /* solium-disable-next-line */ - function decodeConsensusState(uint256 ptr, uint256 size, bool leaveOutValidatorSet) internal pure returns (ConsensusState memory, uint64) { - ptr = ptr + 8; + function decodeConsensusState(uint256 ptr, uint256 size, bool leaveOutValidatorSet) internal pure returns(ConsensusState memory, uint64) { + ptr = ptr+8; uint64 height; /* solium-disable-next-line */ assembly { height := mload(ptr) } - ptr = ptr + 32; + ptr = ptr+32; bytes32 appHash; /* solium-disable-next-line */ assembly { appHash := mload(ptr) } - ptr = ptr + 32; + ptr = ptr+32; bytes32 curValidatorSetHash; /* solium-disable-next-line */ assembly { @@ -245,17 +245,17 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber { if (!leaveOutValidatorSet) { uint256 dest; uint256 length; - cs.nextValidatorSet = new bytes(size - 104); - (dest, length) = Memory.fromBytes(cs.nextValidatorSet); + cs.nextValidatorSet = new bytes(size-104); + (dest,length) = Memory.fromBytes(cs.nextValidatorSet); - Memory.copy(ptr + 32, dest, length); + Memory.copy(ptr+32, dest, length); } return (cs, height); } - function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov { - if (Memory.compareStrings(key, "rewardForValidatorSetChange")) { + function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov{ + 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"); @@ -265,4 +265,4 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber { } emit paramChange(key, value); } -} +} \ No newline at end of file diff --git a/contracts/TendermintLightClient.template b/contracts/TendermintLightClient.template index 7145266d..51ceb63f 100644 --- a/contracts/TendermintLightClient.template +++ b/contracts/TendermintLightClient.template @@ -7,13 +7,13 @@ import "./interface/ISystemReward.sol"; import "./interface/IParamSubscriber.sol"; import "./System.sol"; -contract TendermintLightClient is ILightClient, System, IParamSubscriber { +contract TendermintLightClient is ILightClient, System, IParamSubscriber{ struct ConsensusState { - uint64 preValidatorSetChangeHeight; + uint64 preValidatorSetChangeHeight; bytes32 appHash; bytes32 curValidatorSetHash; - bytes nextValidatorSet; + bytes nextValidatorSet; } mapping(uint64 => ConsensusState) public lightClientConsensusStates; @@ -23,7 +23,7 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber { bytes32 public chainID; bytes constant public INIT_CONSENSUS_STATE_BYTES = hex"{{initConsensusStateBytes}}"; - uint256 constant public INIT_REWARD_FOR_VALIDATOR_SER_CHANGE = {{rewardForValidatorSetChange}}; + uint256 constant public INIT_REWARD_FOR_VALIDATOR_SER_CHANGE = {{rewardForValidatorSetChange}}; uint256 public rewardForValidatorSetChange; event initConsensusState(uint64 initHeight, bytes32 appHash); @@ -75,17 +75,17 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber { //32 + 32 + 8 + 32 + 32 + cs.nextValidatorSet.length; uint256 length = 136 + cs.nextValidatorSet.length; - bytes memory input = new bytes(length + header.length); + bytes memory input = new bytes(length+header.length); uint256 ptr = Memory.dataPtr(input); require(encodeConsensusState(cs, preValidatorSetChangeHeight, ptr, length), "failed to serialize consensus state"); // write header to input uint256 src; - ptr = ptr + length; + ptr = ptr+length; (src, length) = Memory.fromBytes(header); Memory.copy(src, ptr, length); - length = input.length + 32; + length = input.length+32; // Maximum validator quantity is 99 bytes32[128] memory result; /* solium-disable-next-line */ @@ -103,11 +103,11 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber { length := mload(add(result, 0)) } bool validatorChanged = false; - if ((length & (0x01 << 248)) != 0x00) { + if ((length&(0x01<<248))!=0x00) { validatorChanged = true; ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(msg.sender, rewardForValidatorSetChange); } - length = length & 0xffffffffffffffff; + length = length&0xffffffffffffffff; /* solium-disable-next-line */ assembly { @@ -145,7 +145,7 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber { function getChainID() external view returns (string memory) { bytes memory chainIDBytes = new bytes(32); assembly { - mstore(add(chainIDBytes, 32), sload(chainID_slot)) + mstore(add(chainIDBytes,32), sload(chainID_slot)) } uint8 chainIDLength = 0; @@ -175,36 +175,36 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber { uint256 length; (src, length) = Memory.fromBytes(cs.nextValidatorSet); Memory.copy(src, outputPtr, length); - outputPtr = outputPtr - 32; + outputPtr = outputPtr-32; bytes32 hash = cs.curValidatorSetHash; /* solium-disable-next-line */ assembly { mstore(outputPtr, hash) } - outputPtr = outputPtr - 32; + outputPtr = outputPtr-32; hash = cs.appHash; /* solium-disable-next-line */ assembly { mstore(outputPtr, hash) } - outputPtr = outputPtr - 32; + outputPtr = outputPtr-32; /* solium-disable-next-line */ assembly { mstore(outputPtr, height) } - outputPtr = outputPtr - 8; + outputPtr = outputPtr-8; /* solium-disable-next-line */ assembly { mstore(outputPtr, sload(chainID_slot)) } - outputPtr = outputPtr - 32; + outputPtr = outputPtr-32; // size doesn't contain length - size = size - 32; + size = size-32; /* solium-disable-next-line */ assembly { mstore(outputPtr, size) @@ -216,22 +216,22 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber { // | chainID | height | appHash | curValidatorSetHash | [{validator pubkey, voting power}] | // | 32 bytes | 8 bytes | 32 bytes | 32 bytes | [{32 bytes, 8 bytes}] | /* solium-disable-next-line */ - function decodeConsensusState(uint256 ptr, uint256 size, bool leaveOutValidatorSet) internal pure returns (ConsensusState memory, uint64) { - ptr = ptr + 8; + function decodeConsensusState(uint256 ptr, uint256 size, bool leaveOutValidatorSet) internal pure returns(ConsensusState memory, uint64) { + ptr = ptr+8; uint64 height; /* solium-disable-next-line */ assembly { height := mload(ptr) } - ptr = ptr + 32; + ptr = ptr+32; bytes32 appHash; /* solium-disable-next-line */ assembly { appHash := mload(ptr) } - ptr = ptr + 32; + ptr = ptr+32; bytes32 curValidatorSetHash; /* solium-disable-next-line */ assembly { @@ -245,17 +245,17 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber { if (!leaveOutValidatorSet) { uint256 dest; uint256 length; - cs.nextValidatorSet = new bytes(size - 104); - (dest, length) = Memory.fromBytes(cs.nextValidatorSet); + cs.nextValidatorSet = new bytes(size-104); + (dest,length) = Memory.fromBytes(cs.nextValidatorSet); - Memory.copy(ptr + 32, dest, length); + Memory.copy(ptr+32, dest, length); } return (cs, height); } - function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov { - if (Memory.compareStrings(key, "rewardForValidatorSetChange")) { + function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov{ + 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"); @@ -265,4 +265,4 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber { } emit paramChange(key, value); } -} +} \ No newline at end of file diff --git a/contracts/interface/IBSCValidatorSet.sol b/contracts/interface/IBSCValidatorSet.sol index 51f3e9fe..3a6f2407 100644 --- a/contracts/interface/IBSCValidatorSet.sol +++ b/contracts/interface/IBSCValidatorSet.sol @@ -3,7 +3,7 @@ pragma experimental ABIEncoderV2; interface IBSCValidatorSet { function misdemeanor(address validator) external; - function felony(address validator) external; + function felony(address validator)external; function isCurrentValidator(address validator) external view returns (bool); function getLivingValidators() external view returns(address[] memory, bytes[] memory); function getMiningValidators() external view returns(address[] memory, bytes[] memory); diff --git a/generate-validator.js b/generate-validator.js index 338d3605..7246b684 100644 --- a/generate-validator.js +++ b/generate-validator.js @@ -1,5 +1,5 @@ const fs = require("fs"); -const readline = require("readline"); +const readline = require('readline'); const nunjucks = require("nunjucks"); const BLSKeys = require("./BLSkeystore.json"); @@ -9,12 +9,12 @@ async function processValidatorConf() { const rl = readline.createInterface({ input: fileStream, - crlfDelay: Infinity, + crlfDelay: Infinity }); let validators = []; for await (const line of rl) { // Each line in input.txt will be successively available here as `line`. - let vs = line.split(","); + let vs = line.split(",") validators.push({ consensusAddr: vs[0], feeAddr: vs[1], @@ -31,8 +31,8 @@ processValidatorConf().then(function (validators, bLSPublicKeys) { validators: validators, bLSPublicKeys: bLSPublicKeys, }; - const templateString = fs.readFileSync(__dirname + "/validators.template").toString(); + const templateString = fs.readFileSync(__dirname + '/validators.template').toString(); const resultString = nunjucks.renderString(templateString, data); - fs.writeFileSync(__dirname + "/validators.js", resultString); + fs.writeFileSync(__dirname + '/validators.js', resultString); console.log("BSCValidatorSet file updated."); -}); +}) diff --git a/truffle-config.js b/truffle-config.js index e2cf168c..8c5be080 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -45,8 +45,8 @@ module.exports = { development: { host: "127.0.0.1", // Localhost (default: none) port: 8545, // Standard Ethereum port (default: none) - network_id: "*" // Any network (default: none) - } + network_id: "*", // Any network (default: none) + }, // Another network with more advanced options... // advanced: { diff --git a/validators.js b/validators.js index 9573a57d..2e8e6cdc 100644 --- a/validators.js +++ b/validators.js @@ -25,7 +25,7 @@ function generateExtradata(validators, bLSPublicKeys) { function extraDataSerialize(validators, bLSPublicKeys) { let n = validators.length; let arr = []; - for (let i = 0; i < n; i++) { + for(let i = 0;i Date: Thu, 28 Apr 2022 23:25:23 +0800 Subject: [PATCH 04/15] Resolve conflict --- validators.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/validators.js b/validators.js index 2e8e6cdc..cfe30890 100644 --- a/validators.js +++ b/validators.js @@ -16,10 +16,10 @@ const bLSPublicKeys = [ // =============== Do not edit below ==== function generateExtradata(validators, bLSPublicKeys) { - let extraVanity = Buffer.alloc(32); + let extraVanity =Buffer.alloc(32); let validatorsBytes = extraDataSerialize(validators, bLSPublicKeys); - let extraSeal = Buffer.alloc(65); - return Buffer.concat([extraVanity, validatorsBytes, extraSeal]); + let extraSeal =Buffer.alloc(65); + return Buffer.concat([extraVanity,validatorsBytes,extraSeal]); } function extraDataSerialize(validators, bLSPublicKeys) { From 0fb244a0188be93aa37fa8698134436a5e4a0adc Mon Sep 17 00:00:00 2001 From: Loverush Date: Thu, 19 May 2022 16:43:36 +0800 Subject: [PATCH 05/15] Update contracts' abi --- abi/bscvalidatorset.abi | 13 +++++++++++++ abi/slashindicator.abi | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/abi/bscvalidatorset.abi b/abi/bscvalidatorset.abi index e1be421e..1558f9ec 100644 --- a/abi/bscvalidatorset.abi +++ b/abi/bscvalidatorset.abi @@ -1275,6 +1275,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "getWorkingValidatorCount", + "outputs": [ + { + "internalType": "uint256", + "name": "workingValidatorCount", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { diff --git a/abi/slashindicator.abi b/abi/slashindicator.abi index 01450fad..9c2f4e6a 100644 --- a/abi/slashindicator.abi +++ b/abi/slashindicator.abi @@ -650,9 +650,9 @@ "type": "tuple" }, { - "internalType": "address", - "name": "valAddr", - "type": "address" + "internalType": "bytes", + "name": "voteAddr", + "type": "bytes" } ], "internalType": "struct SlashIndicator.FinalityEvidence", From ee3fbaed46519941b63a656e063d0755517a5648 Mon Sep 17 00:00:00 2001 From: Loverush Date: Thu, 19 May 2022 21:22:26 +0800 Subject: [PATCH 06/15] Update finality reward related events --- abi/bscvalidatorset.abi | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/abi/bscvalidatorset.abi b/abi/bscvalidatorset.abi index 1558f9ec..e4696e46 100644 --- a/abi/bscvalidatorset.abi +++ b/abi/bscvalidatorset.abi @@ -69,6 +69,25 @@ "name": "deprecatedDeposit", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "validator", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "deprecatedFinalityRewardDeposit", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -133,6 +152,25 @@ "name": "feeBurned", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "validator", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "finalityRewardDeposit", + "type": "event" + }, { "anonymous": false, "inputs": [ From a545e34e46369d9d89f83f6660544780c96ba51f Mon Sep 17 00:00:00 2001 From: Loverush Date: Wed, 27 Jul 2022 17:14:11 +0800 Subject: [PATCH 07/15] Fix some audit comments --- contracts/SystemReward.sol | 2 +- contracts/SystemReward.template | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/SystemReward.sol b/contracts/SystemReward.sol index 5e65d9c7..fa8fd6fe 100644 --- a/contracts/SystemReward.sol +++ b/contracts/SystemReward.sol @@ -45,7 +45,7 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { if (actualAmount > MAX_REWARDS) { actualAmount = MAX_REWARDS; } - if (actualAmount>0) { + if (actualAmount != 0) { to.transfer(actualAmount); emit rewardTo(to, actualAmount); } else { diff --git a/contracts/SystemReward.template b/contracts/SystemReward.template index 38727983..46f786b1 100644 --- a/contracts/SystemReward.template +++ b/contracts/SystemReward.template @@ -70,7 +70,7 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { if (actualAmount > MAX_REWARDS) { actualAmount = MAX_REWARDS; } - if (actualAmount>0) { + if (actualAmount != 0) { to.transfer(actualAmount); emit rewardTo(to, actualAmount); } else { From 45f9ee94deed3299541565700e5ce61cbe23103f Mon Sep 17 00:00:00 2001 From: Roshan Date: Mon, 16 Jan 2023 08:24:25 +0800 Subject: [PATCH 08/15] resolve conflict and adapt to new precompile bls verify contract --- abi/bscvalidatorset.abi | 414 +++--- abi/crosschain.abi | 1635 +++++++++++---------- abi/govhub.abi | 52 +- abi/relayerhub.abi | 80 +- abi/relayerincentivize.abi | 218 +-- abi/slashindicator.abi | 200 +-- abi/staking.abi | 276 ++-- abi/systemreward.abi | 60 +- abi/tokenhub.abi | 2110 +++++++++++++-------------- abi/tokenmanager.abi | 194 +-- contracts/BSCValidatorSet.sol | 399 +++-- contracts/BSCValidatorSet.template | 450 +++--- contracts/SlashIndicator.sol | 113 +- contracts/SlashIndicator.template | 136 +- contracts/System.sol | 2 +- contracts/SystemReward.sol | 16 +- contracts/SystemReward.template | 4 +- contracts/TendermintLightClient.sol | 2 +- genesis-template.json | 2 + genesis.json | 4 +- lib/Deployer.sol | 37 + lib/interface/IBSCValidatorSet.sol | 14 +- lib/interface/ISlashIndicator.sol | 17 + lib/interface/ISystemReward.sol | 3 + test/Slash.js | 580 ++++++++ test/SlashIndicator.t.sol | 301 +++- test/Staking.t.sol | 4 +- test/SystemReward.t.sol | 16 +- test/TokenHub.t.sol | 56 +- test/ValidatorSet.t.sol | 127 +- test/slash.ts | 784 ++++++++++ 31 files changed, 5351 insertions(+), 2955 deletions(-) create mode 100644 test/Slash.js create mode 100644 test/slash.ts diff --git a/abi/bscvalidatorset.abi b/abi/bscvalidatorset.abi index e4696e46..207effaf 100644 --- a/abi/bscvalidatorset.abi +++ b/abi/bscvalidatorset.abi @@ -402,6 +402,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "CROSS_STAKE_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "DUSTY_INCOMING", @@ -727,6 +740,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "STAKING_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "SYSTEM_REWARD_ADDR", @@ -870,6 +896,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "canEnterMaintenance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -934,47 +979,53 @@ "type": "function" }, { - "inputs": [], - "name": "expireTimeSecondGap", - "outputs": [ + "inputs": [ { - "internalType": "uint256", - "name": "", - "type": "uint256" + "internalType": "address", + "name": "valAddr", + "type": "address" } ], - "stateMutability": "view", + "name": "deposit", + "outputs": [], + "stateMutability": "payable", "type": "function" }, { - "inputs": [], - "name": "finalityRewardRatio", - "outputs": [ + "inputs": [ { - "internalType": "uint256", - "name": "", - "type": "uint256" + "internalType": "address[]", + "name": "valAddrs", + "type": "address[]" + }, + { + "internalType": "uint256[]", + "name": "weights", + "type": "uint256[]" } ], - "stateMutability": "view", + "name": "distributeFinalityReward", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], - "name": "maintainSlashScale", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", + "name": "enterMaintenance", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], - "name": "maxNumOfCandidates", + "name": "exitMaintenance", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "expireTimeSecondGap", "outputs": [ { "internalType": "uint256", @@ -986,21 +1037,21 @@ "type": "function" }, { - "inputs": [], - "name": "maxNumOfMaintaining", - "outputs": [ + "inputs": [ { - "internalType": "uint256", - "name": "", - "type": "uint256" + "internalType": "address", + "name": "validator", + "type": "address" } ], - "stateMutability": "view", + "name": "felony", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], - "name": "maxNumOfWorkingCandidates", + "name": "finalityRewardRatio", "outputs": [ { "internalType": "uint256", @@ -1012,8 +1063,14 @@ "type": "function" }, { - "inputs": [], - "name": "numOfCabinets", + "inputs": [ + { + "internalType": "address", + "name": "_validator", + "type": "address" + } + ], + "name": "getCurrentValidatorIndex", "outputs": [ { "internalType": "uint256", @@ -1025,8 +1082,14 @@ "type": "function" }, { - "inputs": [], - "name": "numOfJailed", + "inputs": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "getIncoming", "outputs": [ { "internalType": "uint256", @@ -1039,12 +1102,17 @@ }, { "inputs": [], - "name": "numOfMaintaining", + "name": "getLivingValidators", "outputs": [ { - "internalType": "uint256", + "internalType": "address[]", "name": "", - "type": "uint256" + "type": "address[]" + }, + { + "internalType": "bytes[]", + "name": "", + "type": "bytes[]" } ], "stateMutability": "view", @@ -1052,12 +1120,17 @@ }, { "inputs": [], - "name": "previousHeight", + "name": "getMiningValidators", "outputs": [ { - "internalType": "uint256", + "internalType": "address[]", "name": "", - "type": "uint256" + "type": "address[]" + }, + { + "internalType": "bytes[]", + "name": "", + "type": "bytes[]" } ], "stateMutability": "view", @@ -1065,62 +1138,35 @@ }, { "inputs": [], - "name": "totalInComing", + "name": "getValidators", "outputs": [ { - "internalType": "uint256", + "internalType": "address[]", "name": "", - "type": "uint256" + "type": "address[]" } ], "stateMutability": "view", "type": "function" }, { - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "validatorExtraSet", + "inputs": [], + "name": "getWorkingValidatorCount", "outputs": [ { "internalType": "uint256", - "name": "enterMaintenanceHeight", + "name": "workingValidatorCount", "type": "uint256" - }, - { - "internalType": "bool", - "name": "isMaintaining", - "type": "bool" - }, - { - "internalType": "bytes", - "name": "voteAddress", - "type": "bytes" } ], "stateMutability": "view", "type": "function" }, - { - "stateMutability": "payable", - "type": "receive" - }, - { - "inputs": [], - "name": "init", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [ { "internalType": "uint8", - "name": "", + "name": "channelId", "type": "uint8" }, { @@ -1129,14 +1175,8 @@ "type": "bytes" } ], - "name": "handleSynPackage", - "outputs": [ - { - "internalType": "bytes", - "name": "responsePayload", - "type": "bytes" - } - ], + "name": "handleAckPackage", + "outputs": [], "stateMutability": "nonpayable", "type": "function" }, @@ -1153,7 +1193,7 @@ "type": "bytes" } ], - "name": "handleAckPackage", + "name": "handleFailAckPackage", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -1162,7 +1202,7 @@ "inputs": [ { "internalType": "uint8", - "name": "channelId", + "name": "", "type": "uint8" }, { @@ -1171,68 +1211,38 @@ "type": "bytes" } ], - "name": "handleFailAckPackage", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ + "name": "handleSynPackage", + "outputs": [ { - "internalType": "address", - "name": "valAddr", - "type": "address" + "internalType": "bytes", + "name": "responsePayload", + "type": "bytes" } ], - "name": "deposit", - "outputs": [], - "stateMutability": "payable", + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], - "name": "getLivingValidators", - "outputs": [ - { - "internalType": "address[]", - "name": "", - "type": "address[]" - }, - { - "internalType": "bytes[]", - "name": "", - "type": "bytes[]" - } - ], - "stateMutability": "view", + "name": "init", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { - "inputs": [], - "name": "getMiningValidators", - "outputs": [ - { - "internalType": "address[]", - "name": "", - "type": "address[]" - }, + "inputs": [ { - "internalType": "bytes[]", - "name": "", - "type": "bytes[]" + "internalType": "address", + "name": "validator", + "type": "address" } ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getValidators", + "name": "isCurrentValidator", "outputs": [ { - "internalType": "address[]", + "internalType": "bool", "name": "", - "type": "address[]" + "type": "bool" } ], "stateMutability": "view", @@ -1258,14 +1268,8 @@ "type": "function" }, { - "inputs": [ - { - "internalType": "address", - "name": "validator", - "type": "address" - } - ], - "name": "getIncoming", + "inputs": [], + "name": "maintainSlashScale", "outputs": [ { "internalType": "uint256", @@ -1277,49 +1281,38 @@ "type": "function" }, { - "inputs": [ - { - "internalType": "address", - "name": "validator", - "type": "address" - } - ], - "name": "isCurrentValidator", + "inputs": [], + "name": "maxNumOfCandidates", "outputs": [ { - "internalType": "bool", + "internalType": "uint256", "name": "", - "type": "bool" + "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { - "inputs": [ - { - "internalType": "address[]", - "name": "valAddrs", - "type": "address[]" - }, + "inputs": [], + "name": "maxNumOfMaintaining", + "outputs": [ { - "internalType": "uint256[]", - "name": "weights", - "type": "uint256[]" + "internalType": "uint256", + "name": "", + "type": "uint256" } ], - "name": "distributeFinalityReward", - "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { "inputs": [], - "name": "getWorkingValidatorCount", + "name": "maxNumOfWorkingCandidates", "outputs": [ { "internalType": "uint256", - "name": "workingValidatorCount", + "name": "", "type": "uint256" } ], @@ -1340,27 +1333,21 @@ "type": "function" }, { - "inputs": [ + "inputs": [], + "name": "numOfCabinets", + "outputs": [ { - "internalType": "address", - "name": "validator", - "type": "address" + "internalType": "uint256", + "name": "", + "type": "uint256" } ], - "name": "felony", - "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { - "inputs": [ - { - "internalType": "address", - "name": "_validator", - "type": "address" - } - ], - "name": "getCurrentValidatorIndex", + "inputs": [], + "name": "numOfJailed", "outputs": [ { "internalType": "uint256", @@ -1372,19 +1359,26 @@ "type": "function" }, { - "inputs": [ + "inputs": [], + "name": "numOfMaintaining", + "outputs": [ { "internalType": "uint256", - "name": "index", + "name": "", "type": "uint256" } ], - "name": "canEnterMaintenance", + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "previousHeight", "outputs": [ { - "internalType": "bool", + "internalType": "uint256", "name": "", - "type": "bool" + "type": "uint256" } ], "stateMutability": "view", @@ -1392,16 +1386,15 @@ }, { "inputs": [], - "name": "enterMaintenance", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "exitMaintenance", - "outputs": [], - "stateMutability": "nonpayable", + "name": "totalInComing", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", "type": "function" }, { @@ -1421,5 +1414,38 @@ "outputs": [], "stateMutability": "nonpayable", "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "validatorExtraSet", + "outputs": [ + { + "internalType": "uint256", + "name": "enterMaintenanceHeight", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "isMaintaining", + "type": "bool" + }, + { + "internalType": "bytes", + "name": "voteAddress", + "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" } ] \ No newline at end of file diff --git a/abi/crosschain.abi b/abi/crosschain.abi index e84fcd2d..f8291385 100644 --- a/abi/crosschain.abi +++ b/abi/crosschain.abi @@ -1,810 +1,829 @@ [ - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - }, - { - "indexed": true, - "internalType": "address", - "name": "contractAddr", - "type": "address" - } - ], - "name": "addChannel", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint16", - "name": "chainId", - "type": "uint16" - }, - { - "indexed": true, - "internalType": "uint64", - "name": "oracleSequence", - "type": "uint64" - }, - { - "indexed": true, - "internalType": "uint64", - "name": "packageSequence", - "type": "uint64" - }, - { - "indexed": true, - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "payload", - "type": "bytes" - } - ], - "name": "crossChainPackage", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - }, - { - "indexed": false, - "internalType": "bool", - "name": "isEnable", - "type": "bool" - } - ], - "name": "enableOrDisableChannel", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "value", - "type": "bytes" - } - ], - "name": "paramChange", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint8", - "name": "packageType", - "type": "uint8" - }, - { - "indexed": true, - "internalType": "uint64", - "name": "packageSequence", - "type": "uint64" - }, - { - "indexed": true, - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - } - ], - "name": "receivedPackage", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "contractAddr", - "type": "address" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "lowLevelData", - "type": "bytes" - } - ], - "name": "unexpectedFailureAssertionInPackageHandler", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "contractAddr", - "type": "address" - }, - { - "indexed": false, - "internalType": "string", - "name": "reason", - "type": "string" - } - ], - "name": "unexpectedRevertInPackageHandler", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint64", - "name": "packageSequence", - "type": "uint64" - }, - { - "indexed": true, - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "payload", - "type": "bytes" - } - ], - "name": "unsupportedPackage", - "type": "event" - }, - { - "inputs": [], - "name": "ACK_PACKAGE", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "BIND_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "CODE_OK", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "CROSS_CHAIN_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "CROSS_CHAIN_KEY_PREFIX", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "CROSS_STAKE_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "ERROR_FAIL_DECODE", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "FAIL_ACK_PACKAGE", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "GOV_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "GOV_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "INCENTIVIZE_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "INIT_BATCH_SIZE", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "LIGHT_CLIENT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "RELAYERHUB_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "SLASH_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "SLASH_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "STAKING_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "STAKING_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "STORE_NAME", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "SYN_PACKAGE", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "SYSTEM_REWARD_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TOKEN_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TOKEN_MANAGER_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TRANSFER_IN_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TRANSFER_OUT_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "VALIDATOR_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "alreadyInit", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "batchSizeForOracle", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "bscChainID", - "outputs": [ - { - "internalType": "uint16", - "name": "", - "type": "uint16" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "name": "channelHandlerContractMap", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "name": "channelReceiveSequenceMap", - "outputs": [ - { - "internalType": "uint64", - "name": "", - "type": "uint64" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "name": "channelSendSequenceMap", - "outputs": [ - { - "internalType": "uint64", - "name": "", - "type": "uint64" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "name": "isRelayRewardFromSystemReward", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "oracleSequence", - "outputs": [ - { - "internalType": "int64", - "name": "", - "type": "int64" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "previousTxHeight", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "name": "registeredContractChannelMap", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "txCounter", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "init", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "packageType", - "type": "uint8" - }, - { - "internalType": "uint256", - "name": "relayFee", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - } - ], - "name": "encodePayload", - "outputs": [ - { - "internalType": "bytes", - "name": "", - "type": "bytes" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes", - "name": "payload", - "type": "bytes" - }, - { - "internalType": "bytes", - "name": "proof", - "type": "bytes" - }, - { - "internalType": "uint64", - "name": "height", - "type": "uint64" - }, - { - "internalType": "uint64", - "name": "packageSequence", - "type": "uint64" - }, - { - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - } - ], - "name": "handlePackage", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - }, - { - "internalType": "uint256", - "name": "relayFee", - "type": "uint256" - } - ], - "name": "sendSynPackage", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "internalType": "bytes", - "name": "value", - "type": "bytes" - } - ], - "name": "updateParam", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - } + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + }, + { + "indexed": true, + "internalType": "address", + "name": "contractAddr", + "type": "address" + } + ], + "name": "addChannel", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint16", + "name": "chainId", + "type": "uint16" + }, + { + "indexed": true, + "internalType": "uint64", + "name": "oracleSequence", + "type": "uint64" + }, + { + "indexed": true, + "internalType": "uint64", + "name": "packageSequence", + "type": "uint64" + }, + { + "indexed": true, + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "payload", + "type": "bytes" + } + ], + "name": "crossChainPackage", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "bool", + "name": "isEnable", + "type": "bool" + } + ], + "name": "enableOrDisableChannel", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "paramChange", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "packageType", + "type": "uint8" + }, + { + "indexed": true, + "internalType": "uint64", + "name": "packageSequence", + "type": "uint64" + }, + { + "indexed": true, + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + } + ], + "name": "receivedPackage", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "contractAddr", + "type": "address" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "lowLevelData", + "type": "bytes" + } + ], + "name": "unexpectedFailureAssertionInPackageHandler", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "contractAddr", + "type": "address" + }, + { + "indexed": false, + "internalType": "string", + "name": "reason", + "type": "string" + } + ], + "name": "unexpectedRevertInPackageHandler", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint64", + "name": "packageSequence", + "type": "uint64" + }, + { + "indexed": true, + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "payload", + "type": "bytes" + } + ], + "name": "unsupportedPackage", + "type": "event" + }, + { + "inputs": [], + "name": "ACK_PACKAGE", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "BIND_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CODE_OK", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CROSS_CHAIN_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CROSS_CHAIN_KEY_PREFIX", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CROSS_STAKE_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERROR_FAIL_DECODE", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "FAIL_ACK_PACKAGE", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INCENTIVIZE_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INIT_BATCH_SIZE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LIGHT_CLIENT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "RELAYERHUB_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "STAKING_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "STAKING_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "STORE_NAME", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SYN_PACKAGE", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SYSTEM_REWARD_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_MANAGER_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_IN_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_OUT_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VALIDATOR_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "alreadyInit", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "batchSizeForOracle", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "bscChainID", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "name": "channelHandlerContractMap", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "name": "channelReceiveSequenceMap", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "name": "channelSendSequenceMap", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "name": "channelSyncedHeaderMap", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "packageType", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "relayFee", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "encodePayload", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "payload", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "proof", + "type": "bytes" + }, + { + "internalType": "uint64", + "name": "height", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "packageSequence", + "type": "uint64" + }, + { + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + } + ], + "name": "handlePackage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "init", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "name": "isRelayRewardFromSystemReward", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "oracleSequence", + "outputs": [ + { + "internalType": "int64", + "name": "", + "type": "int64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "previousTxHeight", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "name": "registeredContractChannelMap", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + }, + { + "internalType": "uint256", + "name": "relayFee", + "type": "uint256" + } + ], + "name": "sendSynPackage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "txCounter", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "updateParam", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } ] \ No newline at end of file diff --git a/abi/govhub.abi b/abi/govhub.abi index fb3a9020..cbd6ff0a 100644 --- a/abi/govhub.abi +++ b/abi/govhub.abi @@ -83,6 +83,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "CROSS_STAKE_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "ERROR_FAIL_DECODE", @@ -239,6 +252,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "STAKING_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "SYSTEM_REWARD_ADDR", @@ -352,18 +378,12 @@ }, { "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - } - ], - "name": "handleSynPackage", - "outputs": [ - { - "internalType": "bytes", - "name": "responsePayload", + "name": "", "type": "bytes" } ], + "name": "handleAckPackage", + "outputs": [], "stateMutability": "nonpayable", "type": "function" }, @@ -380,7 +400,7 @@ "type": "bytes" } ], - "name": "handleAckPackage", + "name": "handleFailAckPackage", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -394,12 +414,18 @@ }, { "internalType": "bytes", - "name": "", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "handleSynPackage", + "outputs": [ + { + "internalType": "bytes", + "name": "responsePayload", "type": "bytes" } ], - "name": "handleFailAckPackage", - "outputs": [], "stateMutability": "nonpayable", "type": "function" } diff --git a/abi/relayerhub.abi b/abi/relayerhub.abi index a4851bc2..b712a5c7 100644 --- a/abi/relayerhub.abi +++ b/abi/relayerhub.abi @@ -83,6 +83,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "CROSS_STAKE_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "ERROR_FAIL_DECODE", @@ -226,6 +239,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "STAKING_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "SYSTEM_REWARD_ADDR", @@ -345,12 +371,25 @@ }, { "inputs": [], - "name": "requiredDeposit", + "name": "init", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "isRelayer", "outputs": [ { - "internalType": "uint256", + "internalType": "bool", "name": "", - "type": "uint256" + "type": "bool" } ], "stateMutability": "view", @@ -358,16 +397,22 @@ }, { "inputs": [], - "name": "init", + "name": "register", "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "payable", "type": "function" }, { "inputs": [], - "name": "register", - "outputs": [], - "stateMutability": "payable", + "name": "requiredDeposit", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", "type": "function" }, { @@ -394,24 +439,5 @@ "outputs": [], "stateMutability": "nonpayable", "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "sender", - "type": "address" - } - ], - "name": "isRelayer", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" } ] \ No newline at end of file diff --git a/abi/relayerincentivize.abi b/abi/relayerincentivize.abi index c452d088..4cc97425 100644 --- a/abi/relayerincentivize.abi +++ b/abi/relayerincentivize.abi @@ -127,6 +127,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "CROSS_STAKE_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "ERROR_FAIL_DECODE", @@ -296,6 +309,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "STAKING_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "SYSTEM_REWARD_ADDR", @@ -374,6 +400,40 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address payable", + "name": "headerRelayerAddr", + "type": "address" + }, + { + "internalType": "address payable", + "name": "packageRelayer", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "fromSystemReward", + "type": "bool" + } + ], + "name": "addReward", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [], "name": "alreadyInit", @@ -400,6 +460,44 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "count", + "type": "uint256" + } + ], + "name": "calculateHeaderRelayerWeight", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "count", + "type": "uint256" + } + ], + "name": "calculateTransferRelayerWeight", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + }, { "inputs": [], "name": "callerCompensationDenominator", @@ -426,6 +524,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "relayerAddr", + "type": "address" + } + ], + "name": "claimRelayerReward", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [], "name": "collectedRewardForHeaderRelayer", @@ -542,6 +653,13 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "init", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -612,102 +730,6 @@ "stateMutability": "view", "type": "function" }, - { - "stateMutability": "payable", - "type": "receive" - }, - { - "inputs": [], - "name": "init", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address payable", - "name": "headerRelayerAddr", - "type": "address" - }, - { - "internalType": "address payable", - "name": "packageRelayer", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "fromSystemReward", - "type": "bool" - } - ], - "name": "addReward", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "relayerAddr", - "type": "address" - } - ], - "name": "claimRelayerReward", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "count", - "type": "uint256" - } - ], - "name": "calculateTransferRelayerWeight", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "count", - "type": "uint256" - } - ], - "name": "calculateHeaderRelayerWeight", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "pure", - "type": "function" - }, { "inputs": [ { @@ -725,5 +747,9 @@ "outputs": [], "stateMutability": "nonpayable", "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" } ] \ No newline at end of file diff --git a/abi/slashindicator.abi b/abi/slashindicator.abi index 9c2f4e6a..99a044f5 100644 --- a/abi/slashindicator.abi +++ b/abi/slashindicator.abi @@ -121,6 +121,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "CROSS_STAKE_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "DECREASE_RATE", @@ -290,6 +303,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "STAKING_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "SYSTEM_REWARD_ADDR", @@ -394,6 +420,13 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "clean", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [], "name": "felonyThreshold", @@ -424,26 +457,21 @@ "inputs": [ { "internalType": "address", - "name": "", + "name": "validator", "type": "address" } ], - "name": "indicators", + "name": "getSlashIndicator", "outputs": [ { "internalType": "uint256", - "name": "height", + "name": "", "type": "uint256" }, { "internalType": "uint256", - "name": "count", + "name": "", "type": "uint256" - }, - { - "internalType": "bool", - "name": "exist", - "type": "bool" } ], "stateMutability": "view", @@ -451,8 +479,13 @@ }, { "inputs": [], - "name": "misdemeanorThreshold", + "name": "getSlashThresholds", "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, { "internalType": "uint256", "name": "", @@ -463,40 +496,37 @@ "type": "function" }, { - "inputs": [], - "name": "previousHeight", - "outputs": [ + "inputs": [ { - "internalType": "uint256", + "internalType": "uint8", "name": "", - "type": "uint256" + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" } ], - "stateMutability": "view", + "name": "handleAckPackage", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { - "internalType": "uint256", + "internalType": "uint8", "name": "", - "type": "uint256" - } - ], - "name": "validators", - "outputs": [ + "type": "uint8" + }, { - "internalType": "address", + "internalType": "bytes", "name": "", - "type": "address" + "type": "bytes" } ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "init", + "name": "handleFailAckPackage", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -528,37 +558,63 @@ { "inputs": [ { - "internalType": "uint8", + "internalType": "address", "name": "", - "type": "uint8" + "type": "address" + } + ], + "name": "indicators", + "outputs": [ + { + "internalType": "uint256", + "name": "height", + "type": "uint256" }, { - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" + "internalType": "uint256", + "name": "count", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "exist", + "type": "bool" } ], - "name": "handleAckPackage", + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "init", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { - "inputs": [ + "inputs": [], + "name": "misdemeanorThreshold", + "outputs": [ { - "internalType": "uint8", + "internalType": "uint256", "name": "", - "type": "uint8" - }, + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "previousHeight", + "outputs": [ { - "internalType": "bytes", + "internalType": "uint256", "name": "", - "type": "bytes" + "type": "uint256" } ], - "name": "handleFailAckPackage", - "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { @@ -569,14 +625,20 @@ "type": "address" } ], - "name": "slash", + "name": "sendFelonyPackage", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { - "inputs": [], - "name": "clean", + "inputs": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "slash", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -665,19 +727,6 @@ "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [ - { - "internalType": "address", - "name": "validator", - "type": "address" - } - ], - "name": "sendFelonyPackage", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [ { @@ -698,41 +747,18 @@ }, { "inputs": [ - { - "internalType": "address", - "name": "validator", - "type": "address" - } - ], - "name": "getSlashIndicator", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, { "internalType": "uint256", "name": "", "type": "uint256" } ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getSlashThresholds", + "name": "validators", "outputs": [ { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "internalType": "uint256", + "internalType": "address", "name": "", - "type": "uint256" + "type": "address" } ], "stateMutability": "view", diff --git a/abi/staking.abi b/abi/staking.abi index 551f0511..495bd05b 100644 --- a/abi/staking.abi +++ b/abi/staking.abi @@ -658,6 +658,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "INIT_TRANSFER_GAS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "LIGHT_CLIENT_ADDR", @@ -881,177 +894,168 @@ }, { "inputs": [], - "name": "minDelegation", + "name": "claimReward", "outputs": [ { "internalType": "uint256", - "name": "", + "name": "amount", "type": "uint256" } ], - "stateMutability": "view", + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], - "name": "relayerFee", + "name": "claimUndelegated", "outputs": [ { "internalType": "uint256", - "name": "", + "name": "amount", "type": "uint256" } ], - "stateMutability": "view", + "stateMutability": "nonpayable", "type": "function" }, - { - "stateMutability": "payable", - "type": "receive" - }, { "inputs": [ { - "internalType": "uint8", - "name": "", - "type": "uint8" + "internalType": "address", + "name": "validator", + "type": "address" }, { - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - } - ], - "name": "handleSynPackage", - "outputs": [ - { - "internalType": "bytes", - "name": "", - "type": "bytes" + "internalType": "uint256", + "name": "amount", + "type": "uint256" } ], - "stateMutability": "nonpayable", + "name": "delegate", + "outputs": [], + "stateMutability": "payable", "type": "function" }, { "inputs": [ { - "internalType": "uint8", - "name": "", - "type": "uint8" + "internalType": "address", + "name": "delegator", + "type": "address" }, { - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" + "internalType": "address", + "name": "validator", + "type": "address" } ], - "name": "handleAckPackage", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ + "name": "getDelegated", + "outputs": [ { - "internalType": "uint8", + "internalType": "uint256", "name": "", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" + "type": "uint256" } ], - "name": "handleFailAckPackage", - "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", - "name": "validator", + "name": "delegator", "type": "address" - }, + } + ], + "name": "getDistributedReward", + "outputs": [ { "internalType": "uint256", - "name": "amount", + "name": "", "type": "uint256" } ], - "name": "delegate", - "outputs": [], - "stateMutability": "payable", + "stateMutability": "view", "type": "function" }, { - "inputs": [ - { - "internalType": "address", - "name": "validator", - "type": "address" - }, + "inputs": [], + "name": "getMinDelegation", + "outputs": [ { "internalType": "uint256", - "name": "amount", + "name": "", "type": "uint256" } ], - "name": "undelegate", - "outputs": [], - "stateMutability": "payable", + "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", - "name": "validatorSrc", + "name": "delegator", "type": "address" }, { "internalType": "address", - "name": "validatorDst", + "name": "valSrc", "type": "address" }, + { + "internalType": "address", + "name": "valDst", + "type": "address" + } + ], + "name": "getPendingRedelegateTime", + "outputs": [ { "internalType": "uint256", - "name": "amount", + "name": "", "type": "uint256" } ], - "name": "redelegate", - "outputs": [], - "stateMutability": "payable", + "stateMutability": "view", "type": "function" }, { - "inputs": [], - "name": "claimReward", + "inputs": [ + { + "internalType": "address", + "name": "delegator", + "type": "address" + }, + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "getPendingUndelegateTime", "outputs": [ { "internalType": "uint256", - "name": "amount", + "name": "", "type": "uint256" } ], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { "inputs": [], - "name": "claimUndelegated", + "name": "getRelayerFee", "outputs": [ { "internalType": "uint256", - "name": "amount", + "name": "", "type": "uint256" } ], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { @@ -1060,19 +1064,14 @@ "internalType": "address", "name": "delegator", "type": "address" - }, - { - "internalType": "address", - "name": "validator", - "type": "address" } ], - "name": "getDelegated", + "name": "getRequestInFly", "outputs": [ { - "internalType": "uint256", + "internalType": "uint256[3]", "name": "", - "type": "uint256" + "type": "uint256[3]" } ], "stateMutability": "view", @@ -1105,7 +1104,7 @@ "type": "address" } ], - "name": "getDistributedReward", + "name": "getUndelegated", "outputs": [ { "internalType": "uint256", @@ -1119,41 +1118,66 @@ { "inputs": [ { - "internalType": "address", - "name": "delegator", - "type": "address" - }, - { - "internalType": "address", - "name": "valSrc", - "type": "address" + "internalType": "uint8", + "name": "", + "type": "uint8" }, { - "internalType": "address", - "name": "valDst", - "type": "address" + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" } ], - "name": "getPendingRedelegateTime", - "outputs": [ + "name": "handleAckPackage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ { - "internalType": "uint256", + "internalType": "uint8", "name": "", - "type": "uint256" + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" } ], - "stateMutability": "view", + "name": "handleFailAckPackage", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { - "internalType": "address", - "name": "delegator", - "type": "address" + "internalType": "uint8", + "name": "", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" } ], - "name": "getUndelegated", + "name": "handleSynPackage", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "minDelegation", "outputs": [ { "internalType": "uint256", @@ -1168,29 +1192,28 @@ "inputs": [ { "internalType": "address", - "name": "delegator", + "name": "validatorSrc", "type": "address" }, { "internalType": "address", - "name": "validator", + "name": "validatorDst", "type": "address" - } - ], - "name": "getPendingUndelegateTime", - "outputs": [ + }, { "internalType": "uint256", - "name": "", + "name": "amount", "type": "uint256" } ], - "stateMutability": "view", + "name": "redelegate", + "outputs": [], + "stateMutability": "payable", "type": "function" }, { "inputs": [], - "name": "getRelayerFee", + "name": "relayerFee", "outputs": [ { "internalType": "uint256", @@ -1203,7 +1226,7 @@ }, { "inputs": [], - "name": "getMinDelegation", + "name": "transferGas", "outputs": [ { "internalType": "uint256", @@ -1218,19 +1241,18 @@ "inputs": [ { "internalType": "address", - "name": "delegator", + "name": "validator", "type": "address" - } - ], - "name": "getRequestInFly", - "outputs": [ + }, { - "internalType": "uint256[3]", - "name": "", - "type": "uint256[3]" + "internalType": "uint256", + "name": "amount", + "type": "uint256" } ], - "stateMutability": "view", + "name": "undelegate", + "outputs": [], + "stateMutability": "payable", "type": "function" }, { @@ -1250,5 +1272,9 @@ "outputs": [], "stateMutability": "nonpayable", "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" } ] \ No newline at end of file diff --git a/abi/systemreward.abi b/abi/systemreward.abi index 621ecc47..43865ac3 100644 --- a/abi/systemreward.abi +++ b/abi/systemreward.abi @@ -114,6 +114,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "CROSS_STAKE_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "ERROR_FAIL_DECODE", @@ -244,6 +257,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "STAKING_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "SYSTEM_REWARD_ADDR", @@ -348,23 +374,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [], - "name": "numOperator", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "stateMutability": "payable", - "type": "receive" - }, { "inputs": [ { @@ -408,6 +417,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "numOperator", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -425,5 +447,9 @@ "outputs": [], "stateMutability": "nonpayable", "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" } ] \ No newline at end of file diff --git a/abi/tokenhub.abi b/abi/tokenhub.abi index 1faeb599..f4f8e88e 100644 --- a/abi/tokenhub.abi +++ b/abi/tokenhub.abi @@ -1,1057 +1,1057 @@ [ - { - "inputs": [], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "value", - "type": "bytes" - } - ], - "name": "paramChange", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "receiveDeposit", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "bep20Addr", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "refundAddr", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint32", - "name": "status", - "type": "uint32" - } - ], - "name": "refundFailure", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "bep20Addr", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "refundAddr", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint32", - "name": "status", - "type": "uint32" - } - ], - "name": "refundSuccess", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "rewardTo", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "bep20Addr", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "refundAddr", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "transferInSuccess", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "bep20Addr", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "senderAddr", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "relayFee", - "type": "uint256" - } - ], - "name": "transferOutSuccess", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - } - ], - "name": "unexpectedPackage", - "type": "event" - }, - { - "inputs": [], - "name": "BEP2_TOKEN_DECIMALS", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "BEP2_TOKEN_SYMBOL_FOR_BNB", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "BIND_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "CODE_OK", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "CROSS_CHAIN_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "CROSS_STAKE_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "ERROR_FAIL_DECODE", - "outputs": [ - { - "internalType": "uint32", - "name": "", - "type": "uint32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "GOV_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "GOV_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "INCENTIVIZE_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "INIT_MINIMUM_RELAY_FEE", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "LIGHT_CLIENT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MAXIMUM_BEP20_SYMBOL_LEN", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MAX_BEP2_TOTAL_SUPPLY", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MAX_GAS_FOR_CALLING_BEP20", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MAX_GAS_FOR_TRANSFER_BNB", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MINIMUM_BEP20_SYMBOL_LEN", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "RELAYERHUB_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "REWARD_UPPER_LIMIT", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "SLASH_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "SLASH_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "STAKING_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "STAKING_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "SYSTEM_REWARD_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TEN_DECIMALS", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TOKEN_HUB_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TOKEN_MANAGER_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TRANSFER_IN_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TRANSFER_IN_FAILURE_INSUFFICIENT_BALANCE", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TRANSFER_IN_FAILURE_NON_PAYABLE_RECIPIENT", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TRANSFER_IN_FAILURE_TIMEOUT", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TRANSFER_IN_FAILURE_UNBOUND_TOKEN", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TRANSFER_IN_FAILURE_UNKNOWN", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TRANSFER_IN_SUCCESS", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TRANSFER_OUT_CHANNELID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "VALIDATOR_CONTRACT_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "alreadyInit", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "bep20ContractDecimals", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "bscChainID", - "outputs": [ - { - "internalType": "uint16", - "name": "", - "type": "uint16" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "relayFee", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "stateMutability": "payable", - "type": "receive" - }, - { - "inputs": [], - "name": "init", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address payable", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "claimRewards", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "getMiniRelayFee", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - } - ], - "name": "handleSynPackage", - "outputs": [ - { - "internalType": "bytes", - "name": "", - "type": "bytes" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - } - ], - "name": "handleAckPackage", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "channelId", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "msgBytes", - "type": "bytes" - } - ], - "name": "handleFailAckPackage", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "contractAddr", - "type": "address" - }, - { - "internalType": "address", - "name": "recipient", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "uint64", - "name": "expireTime", - "type": "uint64" - } - ], - "name": "transferOut", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address[]", - "name": "recipientAddrs", - "type": "address[]" - }, - { - "internalType": "uint256[]", - "name": "amounts", - "type": "uint256[]" - }, - { - "internalType": "address[]", - "name": "refundAddrs", - "type": "address[]" - }, - { - "internalType": "uint64", - "name": "expireTime", - "type": "uint64" - } - ], - "name": "batchTransferOutBNB", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "internalType": "bytes", - "name": "value", - "type": "bytes" - } - ], - "name": "updateParam", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "bep2Symbol", - "type": "bytes32" - } - ], - "name": "getContractAddrByBEP2Symbol", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "contractAddr", - "type": "address" - } - ], - "name": "getBep2SymbolByContractAddr", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "bep2Symbol", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "contractAddr", - "type": "address" - }, - { - "internalType": "uint256", - "name": "decimals", - "type": "uint256" - } - ], - "name": "bindToken", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "bep2Symbol", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "contractAddr", - "type": "address" - } - ], - "name": "unbindToken", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "string", - "name": "bep2Symbol", - "type": "string" - } - ], - "name": "getBoundContract", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "contractAddr", - "type": "address" - } - ], - "name": "getBoundBep2Symbol", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "withdrawStakingBNB", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - } + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "paramChange", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "receiveDeposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "bep20Addr", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "refundAddr", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint32", + "name": "status", + "type": "uint32" + } + ], + "name": "refundFailure", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "bep20Addr", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "refundAddr", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint32", + "name": "status", + "type": "uint32" + } + ], + "name": "refundSuccess", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "rewardTo", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "bep20Addr", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "refundAddr", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transferInSuccess", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "bep20Addr", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "senderAddr", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "relayFee", + "type": "uint256" + } + ], + "name": "transferOutSuccess", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "unexpectedPackage", + "type": "event" + }, + { + "inputs": [], + "name": "BEP2_TOKEN_DECIMALS", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "BEP2_TOKEN_SYMBOL_FOR_BNB", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "BIND_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CODE_OK", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CROSS_CHAIN_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "CROSS_STAKE_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERROR_FAIL_DECODE", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "GOV_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INCENTIVIZE_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INIT_MINIMUM_RELAY_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LIGHT_CLIENT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAXIMUM_BEP20_SYMBOL_LEN", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_BEP2_TOTAL_SUPPLY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_GAS_FOR_CALLING_BEP20", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_GAS_FOR_TRANSFER_BNB", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MINIMUM_BEP20_SYMBOL_LEN", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "RELAYERHUB_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "REWARD_UPPER_LIMIT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SLASH_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "STAKING_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "STAKING_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "SYSTEM_REWARD_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TEN_DECIMALS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_HUB_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TOKEN_MANAGER_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_IN_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_IN_FAILURE_INSUFFICIENT_BALANCE", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_IN_FAILURE_NON_PAYABLE_RECIPIENT", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_IN_FAILURE_TIMEOUT", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_IN_FAILURE_UNBOUND_TOKEN", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_IN_FAILURE_UNKNOWN", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_IN_SUCCESS", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_OUT_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VALIDATOR_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "alreadyInit", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "recipientAddrs", + "type": "address[]" + }, + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + }, + { + "internalType": "address[]", + "name": "refundAddrs", + "type": "address[]" + }, + { + "internalType": "uint64", + "name": "expireTime", + "type": "uint64" + } + ], + "name": "batchTransferOutBNB", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "bep20ContractDecimals", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "bep2Symbol", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "contractAddr", + "type": "address" + }, + { + "internalType": "uint256", + "name": "decimals", + "type": "uint256" + } + ], + "name": "bindToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "bscChainID", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address payable", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "claimRewards", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "contractAddr", + "type": "address" + } + ], + "name": "getBep2SymbolByContractAddr", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "contractAddr", + "type": "address" + } + ], + "name": "getBoundBep2Symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "bep2Symbol", + "type": "string" + } + ], + "name": "getBoundContract", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "bep2Symbol", + "type": "bytes32" + } + ], + "name": "getContractAddrByBEP2Symbol", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getMiniRelayFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "handleAckPackage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "handleFailAckPackage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "handleSynPackage", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "init", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "relayFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "contractAddr", + "type": "address" + }, + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint64", + "name": "expireTime", + "type": "uint64" + } + ], + "name": "transferOut", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "bep2Symbol", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "contractAddr", + "type": "address" + } + ], + "name": "unbindToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "updateParam", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "withdrawStakingBNB", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" + } ] \ No newline at end of file diff --git a/abi/tokenmanager.abi b/abi/tokenmanager.abi index 8a0e31d1..11d7ea2a 100644 --- a/abi/tokenmanager.abi +++ b/abi/tokenmanager.abi @@ -324,6 +324,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "CROSS_STAKE_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "ERROR_FAIL_DECODE", @@ -558,6 +571,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "STAKING_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "SYNC_CHANNELID", @@ -714,6 +740,30 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "contractAddr", + "type": "address" + }, + { + "internalType": "string", + "name": "bep2Symbol", + "type": "string" + } + ], + "name": "approveBind", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "payable", + "type": "function" + }, { "inputs": [ { @@ -795,28 +845,15 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [], - "name": "mirrorFee", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [ { - "internalType": "address", - "name": "", - "type": "address" + "internalType": "string", + "name": "bep2Symbol", + "type": "string" } ], - "name": "mirrorPendingRecord", + "name": "expireBind", "outputs": [ { "internalType": "bool", @@ -824,20 +861,7 @@ "type": "bool" } ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "syncFee", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", + "stateMutability": "payable", "type": "function" }, { @@ -853,14 +877,8 @@ "type": "bytes" } ], - "name": "handleSynPackage", - "outputs": [ - { - "internalType": "bytes", - "name": "", - "type": "bytes" - } - ], + "name": "handleAckPackage", + "outputs": [], "stateMutability": "nonpayable", "type": "function" }, @@ -877,7 +895,7 @@ "type": "bytes" } ], - "name": "handleAckPackage", + "name": "handleFailAckPackage", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -895,8 +913,14 @@ "type": "bytes" } ], - "name": "handleFailAckPackage", - "outputs": [], + "name": "handleSynPackage", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], "stateMutability": "nonpayable", "type": "function" }, @@ -904,16 +928,16 @@ "inputs": [ { "internalType": "address", - "name": "contractAddr", + "name": "bep20Addr", "type": "address" }, { - "internalType": "string", - "name": "bep2Symbol", - "type": "string" + "internalType": "uint64", + "name": "expireTime", + "type": "uint64" } ], - "name": "approveBind", + "name": "mirror", "outputs": [ { "internalType": "bool", @@ -924,20 +948,28 @@ "stateMutability": "payable", "type": "function" }, + { + "inputs": [], + "name": "mirrorFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { "internalType": "address", - "name": "contractAddr", + "name": "", "type": "address" - }, - { - "internalType": "string", - "name": "bep2Symbol", - "type": "string" } ], - "name": "rejectBind", + "name": "mirrorPendingRecord", "outputs": [ { "internalType": "bool", @@ -945,42 +977,42 @@ "type": "bool" } ], - "stateMutability": "payable", + "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "string", - "name": "bep2Symbol", + "name": "symbol", "type": "string" } ], - "name": "expireBind", + "name": "queryRequiredLockAmountForBind", "outputs": [ { - "internalType": "bool", + "internalType": "uint256", "name": "", - "type": "bool" + "type": "uint256" } ], - "stateMutability": "payable", + "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", - "name": "bep20Addr", + "name": "contractAddr", "type": "address" }, { - "internalType": "uint64", - "name": "expireTime", - "type": "uint64" + "internalType": "string", + "name": "bep2Symbol", + "type": "string" } ], - "name": "mirror", + "name": "rejectBind", "outputs": [ { "internalType": "bool", @@ -1015,6 +1047,19 @@ "stateMutability": "payable", "type": "function" }, + { + "inputs": [], + "name": "syncFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -1032,24 +1077,5 @@ "outputs": [], "stateMutability": "nonpayable", "type": "function" - }, - { - "inputs": [ - { - "internalType": "string", - "name": "symbol", - "type": "string" - } - ], - "name": "queryRequiredLockAmountForBind", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" } ] \ No newline at end of file diff --git a/contracts/BSCValidatorSet.sol b/contracts/BSCValidatorSet.sol index f2f7fbb4..b0012752 100644 --- a/contracts/BSCValidatorSet.sol +++ b/contracts/BSCValidatorSet.sol @@ -1,4 +1,5 @@ pragma solidity 0.6.4; +pragma experimental ABIEncoderV2; import "./System.sol"; import "./lib/BytesToTypes.sol"; @@ -74,7 +75,13 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica uint256 public maxNumOfCandidates; uint256 public maxNumOfWorkingCandidates; - struct Validator{ + // BEP-126 Fast Finality + uint256 public constant INIT_FINALITY_REWARD_RATIO = 10; + + uint256 public finalityRewardRatio; + uint256 public previousHeight; + + struct Validator { address consensusAddress; address payable feeAddress; address BBCFeeAddress; @@ -90,14 +97,18 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica uint256 enterMaintenanceHeight; // the height from where the validator enters Maintenance bool isMaintaining; + // BEP-126 Fast Finality + bytes voteAddress; + // reserve for future use - uint256[20] slots; + uint256[19] slots; } /*********************** cross chain package **************************/ struct IbcValidatorSetPackage { uint8 packageType; Validator[] validatorSet; + bytes[] voteAddrs; } /*********************** modifiers **************************/ @@ -111,7 +122,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica ValidatorExtra memory validatorExtra; // init validatorExtraSet uint256 validatorsNum = currentValidatorSet.length; - for (uint i; i < validatorsNum; ++i) { + for (uint i; i previousHeight, "can not do this twice in one block"); + _; + previousHeight = block.number; + } + /*********************** events **************************/ event validatorSetUpdated(); event validatorJailed(address indexed validator); @@ -139,12 +156,14 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica event feeBurned(uint256 amount); event validatorEnterMaintenance(address indexed validator); event validatorExitMaintenance(address indexed validator); + event finalityRewardDeposit(address indexed validator, uint256 amount); + event deprecatedFinalityRewardDeposit(address indexed validator, uint256 amount); /*********************** init **************************/ function init() external onlyNotInit{ (IbcValidatorSetPackage memory validatorSetPkg, bool valid)= decodeValidatorSetSynPackage(INIT_VALIDATORSET_BYTES); require(valid, "failed to parse init validatorSet"); - for (uint i;i MAX_NUM_OF_VALIDATORS) { + emit failReasonWithStr("the number of validators exceed the limit"); return ERROR_FAIL_CHECK_VALIDATORS; } + for (uint i; i= DUSTY_INCOMING) { - ++crossSize; - } else if (currentValidatorSet[i].incoming > 0) { - ++directSize; - } - } - - //cross transfer - address[] memory crossAddrs = new address[](crossSize); - uint256[] memory crossAmounts = new uint256[](crossSize); - uint256[] memory crossIndexes = new uint256[](crossSize); - address[] memory crossRefundAddrs = new address[](crossSize); - uint256 crossTotal; - // direct transfer - address payable[] memory directAddrs = new address payable[](directSize); - uint256[] memory directAmounts = new uint256[](directSize); - crossSize = 0; - directSize = 0; - uint256 relayFee = ITokenHub(TOKEN_HUB_ADDR).getMiniRelayFee(); - if (relayFee > DUSTY_INCOMING) { - emit failReasonWithStr("fee is larger than DUSTY_INCOMING"); - return ERROR_RELAYFEE_TOO_LARGE; - } - for (uint i; i < validatorsNum; ++i) { - if (currentValidatorSet[i].incoming >= DUSTY_INCOMING) { - crossAddrs[crossSize] = currentValidatorSet[i].BBCFeeAddress; - uint256 value = currentValidatorSet[i].incoming - currentValidatorSet[i].incoming % PRECISION; - crossAmounts[crossSize] = value.sub(relayFee); - crossRefundAddrs[crossSize] = currentValidatorSet[i].BBCFeeAddress; - crossIndexes[crossSize] = i; - crossTotal = crossTotal.add(value); - ++crossSize; - } else if (currentValidatorSet[i].incoming > 0) { - directAddrs[directSize] = currentValidatorSet[i].feeAddress; - directAmounts[directSize] = currentValidatorSet[i].incoming; - ++directSize; - } - } - - //step 2: do cross chain transfer - bool failCross = false; - 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 { - emit batchTransferFailed(crossTotal, "batch transfer return false"); + (Validator[] memory validatorSetTemp, bytes[] memory voteAddrsTemp) = _forceMaintainingValidatorsExit(validatorSet, voteAddrs); + + { + //step 1: do calculate distribution, do not make it as an internal function for saving gas. + uint crossSize; + uint directSize; + uint validatorsNum = currentValidatorSet.length; + for (uint i; i= DUSTY_INCOMING) { + --crossSize; + } else if (currentValidatorSet[i].incoming > 0) { + --directSize; } - }catch Error(string memory reason) { - failCross = true; - emit batchTransferFailed(crossTotal, reason); - }catch (bytes memory lowLevelData) { - failCross = true; - emit batchTransferLowerFailed(crossTotal, lowLevelData); } - } - if (failCross) { - for (uint i; i< crossIndexes.length;++i) { - uint idx = crossIndexes[i]; - bool success = currentValidatorSet[idx].feeAddress.send(currentValidatorSet[idx].incoming); - if (success) { - emit directTransfer(currentValidatorSet[idx].feeAddress, currentValidatorSet[idx].incoming); - } else { - emit directTransferFail(currentValidatorSet[idx].feeAddress, currentValidatorSet[idx].incoming); + //cross transfer + address[] memory crossAddrs = new address[](crossSize); + uint256[] memory crossAmounts = new uint256[](crossSize); + uint256[] memory crossIndexes = new uint256[](crossSize); + address[] memory crossRefundAddrs = new address[](crossSize); + uint256 crossTotal; + // direct transfer + address payable[] memory directAddrs = new address payable[](directSize); + uint256[] memory directAmounts = new uint256[](directSize); + crossSize = 0; + directSize = 0; + uint256 relayFee = ITokenHub(TOKEN_HUB_ADDR).getMiniRelayFee(); + if (relayFee > DUSTY_INCOMING) { + emit failReasonWithStr("fee is larger than DUSTY_INCOMING"); + return ERROR_RELAYFEE_TOO_LARGE; + } + for (uint i; i= DUSTY_INCOMING) { + crossAddrs[crossSize] = currentValidatorSet[i].BBCFeeAddress; + uint256 value = currentValidatorSet[i].incoming - currentValidatorSet[i].incoming % PRECISION; + crossAmounts[crossSize] = value.sub(relayFee); + crossRefundAddrs[crossSize] = currentValidatorSet[i].BBCFeeAddress; + crossIndexes[crossSize] = i; + crossTotal = crossTotal.add(value); + --crossSize; + } else if (currentValidatorSet[i].incoming > 0) { + directAddrs[directSize] = currentValidatorSet[i].feeAddress; + directAmounts[directSize] = currentValidatorSet[i].incoming; + --directSize; } } - } - // step 3: direct transfer - if (directAddrs.length>0) { - for (uint i;i 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 { + emit batchTransferFailed(crossTotal, "batch transfer return false"); + } + }catch Error(string memory reason) { + failCross = true; + emit batchTransferFailed(crossTotal, reason); + }catch (bytes memory lowLevelData) { + failCross = true; + emit batchTransferLowerFailed(crossTotal, lowLevelData); + } + } + + if (failCross) { + for (uint i; i0) { + for (uint i; i0) { - doUpdateState(validatorSetTemp); + doUpdateState(validatorSetTemp, voteAddrsTemp); } // step 6: clean slash contract @@ -372,13 +402,16 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica * @dev With each epoch, there will be a partial rotation between cabinets and candidates. Rotation is determined by this function * */ - function shuffle(address[] memory validators, uint256 epochNumber, uint startIdx, uint offset, uint limit, uint modNumber) internal pure { + function shuffle(address[] memory validators, bytes[] memory voteAddrs, uint256 epochNumber, uint startIdx, uint offset, uint limit, uint modNumber) internal pure { for (uint i; i 0) { uint256 epochNumber = block.number / EPOCH; - shuffle(validators, epochNumber, _numOfCabinets-_maxNumOfWorkingCandidates, 0, _maxNumOfWorkingCandidates, _numOfCabinets); - shuffle(validators, epochNumber, _numOfCabinets-_maxNumOfWorkingCandidates, _numOfCabinets-_maxNumOfWorkingCandidates, - _maxNumOfWorkingCandidates, validators.length-_numOfCabinets+_maxNumOfWorkingCandidates); + shuffle(validators, voteAddrs, epochNumber, _numOfCabinets-_maxNumOfWorkingCandidates, 0, _maxNumOfWorkingCandidates, _numOfCabinets); + shuffle(validators, voteAddrs, epochNumber, _numOfCabinets-_maxNumOfWorkingCandidates, _numOfCabinets-_maxNumOfWorkingCandidates, + _maxNumOfWorkingCandidates, validators.length - _numOfCabinets+_maxNumOfWorkingCandidates); } address[] memory miningValidators = new address[](_numOfCabinets); + bytes[] memory miningVoteAddrs = new bytes[](_numOfCabinets); for (uint i; i<_numOfCabinets; ++i) { miningValidators[i] = validators[i]; + miningVoteAddrs[i] = voteAddrs[i]; } - return miningValidators; + return (miningValidators, miningVoteAddrs); } /** @@ -470,6 +540,51 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica return isWorkingValidator(index); } + function distributeFinalityReward(address[] calldata valAddrs, uint256[] calldata weights) external onlyCoinbase oncePerBlock onlyInit { + if (finalityRewardRatio == 0) { + finalityRewardRatio = INIT_FINALITY_REWARD_RATIO; + } + + uint256 totalValue; + totalValue = (address(SYSTEM_REWARD_ADDR).balance * finalityRewardRatio) / 100; + totalValue = ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(payable(address(this)), totalValue); + if (totalValue == 0) { + return; + } + + uint256 totalWeight; + for (uint256 i; i 0) { + Validator storage validator = currentValidatorSet[index - 1]; + if (validator.jailed) { + emit deprecatedFinalityRewardDeposit(valAddr, value); + } else { + totalInComing = totalInComing.add(value); + validator.incoming = validator.incoming.add(value); + emit finalityRewardDeposit(valAddr, value); + } + } else { + // get incoming from deprecated validator; + emit deprecatedFinalityRewardDeposit(valAddr, value); + } + } + + } + function getWorkingValidatorCount() public view returns(uint256 workingValidatorCount) { workingValidatorCount = getValidators().length; uint256 _numOfCabinets = numOfCabinets > 0 ? numOfCabinets : INIT_NUM_OF_CABINETS; @@ -584,12 +699,12 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica if (_numOfCabinets == 0) { _numOfCabinets = INIT_NUM_OF_CABINETS; } - require(newMaxNumOfMaintaining < _numOfCabinets, "the maxNumOfMaintaining must be less than numOfCaninates"); + require(newMaxNumOfMaintaining < _numOfCabinets, "the maxNumOfMaintaining must be less than numOfCabinets"); maxNumOfMaintaining = newMaxNumOfMaintaining; } else if (Memory.compareStrings(key, "maintainSlashScale")) { require(value.length == 32, "length of maintainSlashScale mismatch"); uint256 newMaintainSlashScale = BytesToTypes.bytesToUint256(32, value); - require(newMaintainSlashScale > 0 && newMaintainSlashScale < 10, "the maintainSlashScale must be greater than 0 and less than 10"); + require(newMaintainSlashScale > 0, "the maintainSlashScale must be greater than 0"); maintainSlashScale = newMaintainSlashScale; } else if (Memory.compareStrings(key, "maxNumOfWorkingCandidates")) { require(value.length == 32, "length of maxNumOfWorkingCandidates mismatch"); @@ -609,6 +724,11 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica require(newNumOfCabinets > 0, "the numOfCabinets must be greater than 0"); require(newNumOfCabinets <= MAX_NUM_OF_VALIDATORS, "the numOfCabinets must be less than MAX_NUM_OF_VALIDATORS"); numOfCabinets = newNumOfCabinets; + } else if (Memory.compareStrings(key, "finalityRewardRatio")) { + require(value.length == 32, "length of finalityRewardRatio mismatch"); + uint256 newFinalityRewardRatio = BytesToTypes.bytesToUint256(32, value); + require(newFinalityRewardRatio >= 1 && newFinalityRewardRatio < 100, "the finalityRewardRatio is out of range"); + finalityRewardRatio = newFinalityRewardRatio; } else { require(false, "unknown param"); } @@ -616,29 +736,14 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } /*********************** Internal Functions **************************/ - - function checkValidatorSet(Validator[] memory validatorSet) private pure returns(bool, string memory) { - if (validatorSet.length > MAX_NUM_OF_VALIDATORS){ - return (false, "the number of validators exceed the limit"); - } - for (uint i; i < validatorSet.length; ++i) { - for (uint j = 0; jm) { - for (uint i = m; i < n; ++i) { + for (uint i=m; in) { ValidatorExtra memory validatorExtra; - for (uint i = n; i < m; ++i) { + for (uint i = n; i previousHeight, "can not do this twice in one block"); + _; + previousHeight = block.number; + } + /*********************** events **************************/ event validatorSetUpdated(); event validatorJailed(address indexed validator); @@ -139,6 +156,8 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica event feeBurned(uint256 amount); event validatorEnterMaintenance(address indexed validator); event validatorExitMaintenance(address indexed validator); + event finalityRewardDeposit(address indexed validator, uint256 amount); + event deprecatedFinalityRewardDeposit(address indexed validator, uint256 amount); /*********************** init **************************/ function init() external onlyNotInit{ @@ -152,6 +171,8 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica alreadyInit = true; } + receive() external payable {} + /*********************** Cross Chain App Implement **************************/ function handleSynPackage(uint8, bytes calldata msgBytes) onlyInit onlyCrossChainContract initValidatorExtraSet external override returns(bytes memory responsePayload) { (IbcValidatorSetPackage memory validatorSetPackage, bool ok) = decodeValidatorSetSynPackage(msgBytes); @@ -160,7 +181,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } uint32 resCode; if (validatorSetPackage.packageType == VALIDATORS_UPDATE_MESSAGE_TYPE) { - resCode = updateValidatorSet(validatorSetPackage.validatorSet); + resCode = updateValidatorSet(validatorSetPackage.validatorSet, validatorSetPackage.voteAddrs); } else if (validatorSetPackage.packageType == JAIL_MESSAGE_TYPE) { if (validatorSetPackage.validatorSet.length != 1) { emit failReasonWithStr("length of jail validators must be one"); @@ -189,12 +210,6 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } /*********************** External Functions **************************/ - - /** - * @dev Collect all fee of transactions from the current block and deposit it to the contract - * - * @param valAddr The validator address who produced the current block - */ function deposit(address valAddr) external payable onlyCoinbase onlyInit noEmptyDeposit{ uint256 value = msg.value; uint256 index = currentValidatorSetMap[valAddr]; @@ -242,110 +257,119 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica emit validatorEmptyJailed(v.consensusAddress); return CODE_OK; } - ++numOfJailed; + numOfJailed ++; currentValidatorSet[index-1].jailed = true; emit validatorJailed(v.consensusAddress); return CODE_OK; } - function updateValidatorSet(Validator[] memory validatorSet) internal returns (uint32) { + function updateValidatorSet(Validator[] memory validatorSet, bytes[] memory voteAddrs) internal returns (uint32) { { // do verify. - (bool valid, string memory errMsg) = checkValidatorSet(validatorSet); - if (!valid) { - emit failReasonWithStr(errMsg); + if (validatorSet.length > MAX_NUM_OF_VALIDATORS) { + emit failReasonWithStr("the number of validators exceed the limit"); return ERROR_FAIL_CHECK_VALIDATORS; } + for (uint i; i < validatorSet.length; ++i) { + for (uint j; j < i; ++j) { + if (validatorSet[i].consensusAddress == validatorSet[j].consensusAddress) { + emit failReasonWithStr("duplicate consensus address of validatorSet"); + return ERROR_FAIL_CHECK_VALIDATORS; + } + } + } } // step 0: force all maintaining validators to exit `Temporary Maintenance` // - 1. validators exit maintenance // - 2. clear all maintainInfo // - 3. get unjailed validators from validatorSet - Validator[] memory validatorSetTemp = _forceMaintainingValidatorsExit(validatorSet); - - //step 1: do calculate distribution, do not make it as an internal function for saving gas. - uint crossSize; - uint directSize; - uint validatorsNum = currentValidatorSet.length; - for (uint i; i < validatorsNum; ++i) { - if (currentValidatorSet[i].incoming >= DUSTY_INCOMING) { - ++crossSize; - } else if (currentValidatorSet[i].incoming > 0) { - ++directSize; - } - } - - //cross transfer - address[] memory crossAddrs = new address[](crossSize); - uint256[] memory crossAmounts = new uint256[](crossSize); - uint256[] memory crossIndexes = new uint256[](crossSize); - address[] memory crossRefundAddrs = new address[](crossSize); - uint256 crossTotal; - // direct transfer - address payable[] memory directAddrs = new address payable[](directSize); - uint256[] memory directAmounts = new uint256[](directSize); - crossSize = 0; - directSize = 0; - uint256 relayFee = ITokenHub(TOKEN_HUB_ADDR).getMiniRelayFee(); - if (relayFee > DUSTY_INCOMING) { - emit failReasonWithStr("fee is larger than DUSTY_INCOMING"); - return ERROR_RELAYFEE_TOO_LARGE; - } - for (uint i; i < validatorsNum; ++i) { - if (currentValidatorSet[i].incoming >= DUSTY_INCOMING) { - crossAddrs[crossSize] = currentValidatorSet[i].BBCFeeAddress; - uint256 value = currentValidatorSet[i].incoming - currentValidatorSet[i].incoming % PRECISION; - crossAmounts[crossSize] = value.sub(relayFee); - crossRefundAddrs[crossSize] = currentValidatorSet[i].BBCFeeAddress; - crossIndexes[crossSize] = i; - crossTotal = crossTotal.add(value); - ++crossSize; - } else if (currentValidatorSet[i].incoming > 0) { - directAddrs[directSize] = currentValidatorSet[i].feeAddress; - directAmounts[directSize] = currentValidatorSet[i].incoming; - ++directSize; - } - } - - //step 2: do cross chain transfer - bool failCross = false; - 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 { - emit batchTransferFailed(crossTotal, "batch transfer return false"); + (Validator[] memory validatorSetTemp, bytes[] memory voteAddrsTemp) = _forceMaintainingValidatorsExit(validatorSet, voteAddrs); + + { + //step 1: do calculate distribution, do not make it as an internal function for saving gas. + uint crossSize; + uint directSize; + uint validatorsNum = currentValidatorSet.length; + for (uint i; i < validatorsNum; ++i) { + if (currentValidatorSet[i].incoming >= DUSTY_INCOMING) { + crossSize ++; + } else if (currentValidatorSet[i].incoming > 0) { + directSize ++; } - }catch Error(string memory reason) { - failCross = true; - emit batchTransferFailed(crossTotal, reason); - }catch (bytes memory lowLevelData) { - failCross = true; - emit batchTransferLowerFailed(crossTotal, lowLevelData); } - } - if (failCross) { - for (uint i; i< crossIndexes.length;++i) { - uint idx = crossIndexes[i]; - bool success = currentValidatorSet[idx].feeAddress.send(currentValidatorSet[idx].incoming); - if (success) { - emit directTransfer(currentValidatorSet[idx].feeAddress, currentValidatorSet[idx].incoming); - } else { - emit directTransferFail(currentValidatorSet[idx].feeAddress, currentValidatorSet[idx].incoming); + //cross transfer + address[] memory crossAddrs = new address[](crossSize); + uint256[] memory crossAmounts = new uint256[](crossSize); + uint256[] memory crossIndexes = new uint256[](crossSize); + address[] memory crossRefundAddrs = new address[](crossSize); + uint256 crossTotal; + // direct transfer + address payable[] memory directAddrs = new address payable[](directSize); + uint256[] memory directAmounts = new uint256[](directSize); + crossSize = 0; + directSize = 0; + uint256 relayFee = ITokenHub(TOKEN_HUB_ADDR).getMiniRelayFee(); + if (relayFee > DUSTY_INCOMING) { + emit failReasonWithStr("fee is larger than DUSTY_INCOMING"); + return ERROR_RELAYFEE_TOO_LARGE; + } + for (uint i; i < validatorsNum; ++i) { + if (currentValidatorSet[i].incoming >= DUSTY_INCOMING) { + crossAddrs[crossSize] = currentValidatorSet[i].BBCFeeAddress; + uint256 value = currentValidatorSet[i].incoming - currentValidatorSet[i].incoming % PRECISION; + crossAmounts[crossSize] = value.sub(relayFee); + crossRefundAddrs[crossSize] = currentValidatorSet[i].BBCFeeAddress; + crossIndexes[crossSize] = i; + crossTotal = crossTotal.add(value); + crossSize ++; + } else if (currentValidatorSet[i].incoming > 0) { + directAddrs[directSize] = currentValidatorSet[i].feeAddress; + directAmounts[directSize] = currentValidatorSet[i].incoming; + directSize ++; } } - } - // step 3: direct transfer - if (directAddrs.length>0) { - for (uint i;i 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 { + emit batchTransferFailed(crossTotal, "batch transfer return false"); + } + }catch Error(string memory reason) { + failCross = true; + emit batchTransferFailed(crossTotal, reason); + }catch (bytes memory lowLevelData) { + failCross = true; + emit batchTransferLowerFailed(crossTotal, lowLevelData); + } + } + + if (failCross) { + for (uint i; i< crossIndexes.length;++i) { + uint idx = crossIndexes[i]; + bool success = currentValidatorSet[idx].feeAddress.send(currentValidatorSet[idx].incoming); + if (success) { + emit directTransfer(currentValidatorSet[idx].feeAddress, currentValidatorSet[idx].incoming); + } else { + emit directTransferFail(currentValidatorSet[idx].feeAddress, currentValidatorSet[idx].incoming); + } + } + } + + // step 3: direct transfer + if (directAddrs.length>0) { + for (uint i;i0) { - doUpdateState(validatorSetTemp); + doUpdateState(validatorSetTemp, voteAddrsTemp); } // step 6: clean slash contract @@ -368,26 +392,51 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica return CODE_OK; } - /** - * @dev With each epoch, there will be a partial rotation between cabinets and candidates. Rotation is determined by this function - * - */ - function shuffle(address[] memory validators, uint256 epochNumber, uint startIdx, uint offset, uint limit, uint modNumber) internal pure { + function shuffle(address[] memory validators, bytes[] memory voteAddrs, uint256 epochNumber, uint startIdx, uint offset, uint limit, uint modNumber) internal pure { for (uint i; i 0) { uint256 epochNumber = block.number / EPOCH; - shuffle(validators, epochNumber, _numOfCabinets-_maxNumOfWorkingCandidates, 0, _maxNumOfWorkingCandidates, _numOfCabinets); - shuffle(validators, epochNumber, _numOfCabinets-_maxNumOfWorkingCandidates, _numOfCabinets-_maxNumOfWorkingCandidates, - _maxNumOfWorkingCandidates, validators.length-_numOfCabinets+_maxNumOfWorkingCandidates); + shuffle(validators, voteAddrs, epochNumber, _numOfCabinets-_maxNumOfWorkingCandidates, 0, _maxNumOfWorkingCandidates, _numOfCabinets); + shuffle(validators, voteAddrs, epochNumber, _numOfCabinets-_maxNumOfWorkingCandidates, _numOfCabinets-_maxNumOfWorkingCandidates, + _maxNumOfWorkingCandidates, validators.length - _numOfCabinets+_maxNumOfWorkingCandidates); } address[] memory miningValidators = new address[](_numOfCabinets); + bytes[] memory miningVoteAddrs = new bytes[](_numOfCabinets); for (uint i; i<_numOfCabinets; ++i) { miningValidators[i] = validators[i]; + miningVoteAddrs[i] = voteAddrs[i]; } - return miningValidators; + return (miningValidators, miningVoteAddrs); } - /** - * @dev Get all validators, including all of the cabinets and all of the candidates - * - */ function getValidators() public view returns(address[] memory) { uint n = currentValidatorSet.length; uint valid = 0; for (uint i; i 0) { + Validator storage validator = currentValidatorSet[index - 1]; + if (validator.jailed) { + emit deprecatedFinalityRewardDeposit(valAddr, value); + } else { + totalInComing = totalInComing.add(value); + validator.incoming = validator.incoming.add(value); + emit finalityRewardDeposit(valAddr, value); + } + } else { + // get incoming from deprecated validator; + emit deprecatedFinalityRewardDeposit(valAddr, value); + } + } + + } + function getWorkingValidatorCount() public view returns(uint256 workingValidatorCount) { workingValidatorCount = getValidators().length; uint256 _numOfCabinets = numOfCabinets > 0 ? numOfCabinets : INIT_NUM_OF_CABINETS; @@ -498,7 +592,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica bool isMaintaining = validatorExtraSet[index].isMaintaining; if (_felony(validator, index) && isMaintaining) { - --numOfMaintaining; + numOfMaintaining--; } } @@ -532,11 +626,6 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica return true; } - - /** - * @dev Enter maintenance for current validators. refer to https://github.com/bnb-chain/BEPs/blob/master/BEP127.md - * - */ function enterMaintenance() external initValidatorExtraSet { // check maintain config if (maxNumOfMaintaining == 0) { @@ -551,10 +640,6 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica _enterMaintenance(msg.sender, index); } - /** - * @dev Exit maintenance for current validators. refer to https://github.com/bnb-chain/BEPs/blob/master/BEP127.md - * - */ function exitMaintenance() external { uint256 index = getCurrentValidatorIndex(msg.sender); @@ -584,12 +669,12 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica if (_numOfCabinets == 0) { _numOfCabinets = INIT_NUM_OF_CABINETS; } - require(newMaxNumOfMaintaining < _numOfCabinets, "the maxNumOfMaintaining must be less than numOfCaninates"); + require(newMaxNumOfMaintaining < _numOfCabinets, "the maxNumOfMaintaining must be less than numOfCabinets"); maxNumOfMaintaining = newMaxNumOfMaintaining; } else if (Memory.compareStrings(key, "maintainSlashScale")) { require(value.length == 32, "length of maintainSlashScale mismatch"); uint256 newMaintainSlashScale = BytesToTypes.bytesToUint256(32, value); - require(newMaintainSlashScale > 0 && newMaintainSlashScale < 10, "the maintainSlashScale must be greater than 0 and less than 10"); + require(newMaintainSlashScale > 0, "the maintainSlashScale must be greater than 0"); maintainSlashScale = newMaintainSlashScale; } else if (Memory.compareStrings(key, "maxNumOfWorkingCandidates")) { require(value.length == 32, "length of maxNumOfWorkingCandidates mismatch"); @@ -609,6 +694,11 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica require(newNumOfCabinets > 0, "the numOfCabinets must be greater than 0"); require(newNumOfCabinets <= MAX_NUM_OF_VALIDATORS, "the numOfCabinets must be less than MAX_NUM_OF_VALIDATORS"); numOfCabinets = newNumOfCabinets; + } else if (Memory.compareStrings(key, "finalityRewardRatio")) { + require(value.length == 32, "length of finalityRewardRatio mismatch"); + uint256 newFinalityRewardRatio = BytesToTypes.bytesToUint256(32, value); + require(newFinalityRewardRatio >= 1 && newFinalityRewardRatio < 100, "the finalityRewardRatio is out of range"); + finalityRewardRatio = newFinalityRewardRatio; } else { require(false, "unknown param"); } @@ -616,37 +706,13 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } /*********************** Internal Functions **************************/ - - function checkValidatorSet(Validator[] memory validatorSet) private pure returns(bool, string memory) { - if (validatorSet.length > MAX_NUM_OF_VALIDATORS){ - return (false, "the number of validators exceed the limit"); - } - for (uint i; i < validatorSet.length; ++i) { - for (uint j = 0; jm) { @@ -657,18 +723,18 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } uint k = n < m ? n:m; for (uint i; i < k; ++i) { - if (!isSameValidator(validatorSet[i], currentValidatorSet[i])) { - currentValidatorSetMap[validatorSet[i].consensusAddress] = i+1; - currentValidatorSet[i] = validatorSet[i]; - } else { - currentValidatorSet[i].incoming = 0; - } + currentValidatorSetMap[validatorSet[i].consensusAddress] = i+1; + currentValidatorSet[i] = validatorSet[i]; + validatorExtraSet[i].voteAddress = voteAddrs[i]; + validatorExtraSet[i].isMaintaining = false; + validatorExtraSet[i].enterMaintenanceHeight = 0; } if (m>n) { - ValidatorExtra memory validatorExtra; - for (uint i = n; i < m; ++i) { + ValidatorExtra memory _validatorExtra; + for (uint i = n; i < m; i++) { + _validatorExtra.voteAddress = voteAddrs[i]; currentValidatorSet.push(validatorSet[i]); - validatorExtraSet.push(validatorExtra); + validatorExtraSet.push(_validatorExtra); currentValidatorSetMap[validatorSet[i].consensusAddress] = i+1; } } @@ -683,8 +749,20 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } } - 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; + function getVoteAddresses(address[] memory validators) internal view returns(bytes[] memory) { + uint n = currentValidatorSet.length; + uint length = validators.length; + bytes[] memory voteAddrs = new bytes[](length); + + // check if validatorExtraSet has been initialized + if (validatorExtraSet.length != n) { + return voteAddrs; + } + + for (uint i; i previousHeight, "can not slash twice in one block"); _; @@ -115,7 +140,6 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication emit validatorSlashed(validator); } - // To prevent validator misbehaving and leaving, do not clean slash record to zero, but decrease by felonyThreshold/DECREASE_RATE . // Clean is an effective implement to reorganize "validators" and "indicators". function clean() external override(ISlashIndicator) onlyValidatorContract onlyInit{ @@ -124,10 +148,10 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication } uint i = 0; uint j = validators.length-1; - for (;i <= j;) { + for (; i<=j;) { bool findLeft = false; bool findRight = false; - for(;i felonyThreshold/DECREASE_RATE){ leftIndicator.count = leftIndicator.count - felonyThreshold/DECREASE_RATE; @@ -137,7 +161,7 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication break; } } - for(;i<=j;--j){ + for(; i<=j ; --j){ Indicator memory rightIndicator = indicators[validators[j]]; if(rightIndicator.count > felonyThreshold/DECREASE_RATE){ rightIndicator.count = rightIndicator.count - felonyThreshold/DECREASE_RATE; @@ -170,6 +194,43 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication emit indicatorCleaned(); } + function submitFinalityViolationEvidence(FinalityEvidence memory _evidence) public onlyInit onlyRelayer { + if (finalitySlashRewardRatio == 0) { + finalitySlashRewardRatio = INIT_FINALITY_SLASH_REWARD_RATIO; + } + + // Basic check + require(_evidence.voteA.srcNum+256 > block.number && + _evidence.voteB.srcNum+256 > block.number, "too old block involved"); + require(!(_evidence.voteA.srcHash == _evidence.voteB.srcHash && + _evidence.voteA.tarHash == _evidence.voteB.tarHash), "two identical votes"); + require(_evidence.voteA.srcNum < _evidence.voteA.tarNum && + _evidence.voteB.srcNum < _evidence.voteB.tarNum, "srcNum bigger than tarNum"); + + // Vote rules check + require((_evidence.voteA.srcNum<_evidence.voteB.srcNum && _evidence.voteB.tarNum<_evidence.voteA.tarNum) || + (_evidence.voteB.srcNum<_evidence.voteA.srcNum && _evidence.voteA.tarNum<_evidence.voteB.tarNum) || + _evidence.voteA.tarNum == _evidence.voteB.tarNum, "no violation of vote rules"); + + // BLS verification + (address[] memory vals, bytes[] memory voteAddrs) = IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).getLivingValidators(); + address valAddr; + bytes memory voteAddr = _evidence.voteAddr; + for (uint i; i < voteAddrs.length; ++i) { + if (BytesLib.equal(voteAddrs[i], voteAddr)) { + valAddr = vals[i]; + break; + } + } + require(valAddr != address(0), "validator not exist"); + + uint256 amount = (address(SYSTEM_REWARD_ADDR).balance * finalitySlashRewardRatio) / 100; + ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(msg.sender, amount); + IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).felony(valAddr); + ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeSlashPackage(valAddr), 0); + emit validatorSlashed(valAddr); + } + /** * @dev Send a felony cross-chain package to jail a validator * @@ -179,6 +240,45 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeSlashPackage(validator), 0); } + function verifyBLSSignature(VoteData memory vote, bytes memory voteAddr) internal view returns(bool) { + bytes[] memory elements = new bytes[](4); + bytes memory _bytes = new bytes(32); + elements[0] = vote.srcNum.encodeUint(); + TypesToBytes.bytes32ToBytes(32, vote.srcHash, _bytes); + elements[1] = _bytes.encodeBytes(); + elements[2] = vote.tarNum.encodeUint(); + TypesToBytes.bytes32ToBytes(32, vote.tarHash, _bytes); + elements[3] = _bytes.encodeBytes(); + + TypesToBytes.bytes32ToBytes(32, keccak256(elements.encodeList()), _bytes); + + // assemble input data + bytes memory input = new bytes(176); + bytesConcat(input, _bytes, 0, 32); + bytesConcat(input, vote.sig, 32, 96); + bytesConcat(input, voteAddr, 128, 48); + + // call the precompiled contract to verify the BLS signature + // the precompiled contract's address is 0x66 + bytes memory output = new bytes(1); + assembly { + let len := mload(input) + if iszero(staticcall(not(0), 0x66, add(input, 0x20), len, add(output, 0x20), 0x01)) { + revert(0, 0) + } + } + if (BytesLib.toUint8(output, 0) != uint8(1)) { + return false; + } + return true; + } + + function bytesConcat(bytes memory data, bytes memory _bytes, uint256 index, uint256 len) internal pure { + for (uint i; i misdemeanorThreshold, "the felonyThreshold out of range"); felonyThreshold = newFelonyThreshold; + } else if (Memory.compareStrings(key, "finalitySlashRewardRatio")) { + require(value.length == 32, "length of finalitySlashRewardRatio mismatch"); + uint256 newFinalitySlashRewardRatio = BytesToTypes.bytesToUint256(32, value); + require(newFinalitySlashRewardRatio >= 10 && newFinalitySlashRewardRatio < 100, "the finality slash reward ratio out of range"); + finalitySlashRewardRatio = newFinalitySlashRewardRatio; } else { require(false, "unknown param"); } diff --git a/contracts/SlashIndicator.template b/contracts/SlashIndicator.template index 647e937c..15448fdb 100644 --- a/contracts/SlashIndicator.template +++ b/contracts/SlashIndicator.template @@ -1,12 +1,17 @@ pragma solidity 0.6.4; +pragma experimental ABIEncoderV2; + import "./System.sol"; import "./lib/BytesToTypes.sol"; +import "./lib/TypesToBytes.sol"; +import "./lib/BytesLib.sol"; import "./lib/Memory.sol"; import "./interface/ISlashIndicator.sol"; import "./interface/IApplication.sol"; import "./interface/IBSCValidatorSet.sol"; import "./interface/IParamSubscriber.sol"; import "./interface/ICrossChain.sol"; +import "./interface/ISystemReward.sol"; import "./lib/CmnPkg.sol"; import "./lib/RLPEncode.sol"; @@ -28,6 +33,11 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication uint256 public misdemeanorThreshold; uint256 public felonyThreshold; + // BEP-126 Fast Finality + uint256 public constant INIT_FINALITY_SLASH_REWARD_RATIO = 20; + + uint256 public finalitySlashRewardRatio; + event validatorSlashed(address indexed validator); event indicatorCleaned(); event paramChange(string key, bytes value); @@ -36,14 +46,27 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication event unKnownResponse(uint32 code); event crashResponse(); - event failedFelony(address indexed validator, uint256 slashCount, bytes failReason); - struct Indicator { uint256 height; uint256 count; bool exist; } + // Proof that a validator misbehaved in fast finality + struct VoteData { + uint256 srcNum; + bytes32 srcHash; + uint256 tarNum; + bytes32 tarHash; + bytes sig; + } + + struct FinalityEvidence { + VoteData voteA; + VoteData voteB; + bytes voteAddr; + } + modifier oncePerBlock() { require(block.number > previousHeight, "can not slash twice in one block"); _; @@ -89,18 +112,13 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication } /*********************** External func ********************************/ - /** - * @dev Slash the validator who should have produced the current block - * - * @param validator The validator who should have produced the current block - */ function slash(address validator) external onlyCoinbase onlyInit oncePerBlock onlyZeroGasPrice{ if (!IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).isCurrentValidator(validator)) { return; } Indicator memory indicator = indicators[validator]; if (indicator.exist) { - ++indicator.count; + indicator.count++; } else { indicator.exist = true; indicator.count = 1; @@ -110,9 +128,7 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication if (indicator.count % felonyThreshold == 0) { indicator.count = 0; IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).felony(validator); - try ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeSlashPackage(validator), 0) {} catch (bytes memory reason) { - emit failedFelony(validator, indicator.count, reason); - } + ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeSlashPackage(validator), 0); } else if (indicator.count % misdemeanorThreshold == 0) { IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).misdemeanor(validator); } @@ -120,7 +136,6 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication emit validatorSlashed(validator); } - // To prevent validator misbehaving and leaving, do not clean slash record to zero, but decrease by felonyThreshold/DECREASE_RATE . // Clean is an effective implement to reorganize "validators" and "indicators". function clean() external override(ISlashIndicator) onlyValidatorContract onlyInit{ @@ -132,7 +147,7 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication for (;i <= j;) { bool findLeft = false; bool findRight = false; - for(;i felonyThreshold/DECREASE_RATE){ leftIndicator.count = leftIndicator.count - felonyThreshold/DECREASE_RATE; @@ -142,7 +157,7 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication break; } } - for(;i<=j;--j){ + for(;i<=j;j--){ Indicator memory rightIndicator = indicators[validators[j]]; if(rightIndicator.count > felonyThreshold/DECREASE_RATE){ rightIndicator.count = rightIndicator.count - felonyThreshold/DECREASE_RATE; @@ -169,21 +184,95 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication break; } // move to next - ++i; - --j; + i++; + j--; } emit indicatorCleaned(); } - /** - * @dev Send a felony cross-chain package to jail a validator - * - * @param validator Who will be jailed - */ + function submitFinalityViolationEvidence(FinalityEvidence memory _evidence) public onlyInit onlyRelayer { + if (finalitySlashRewardRatio == 0) { + finalitySlashRewardRatio = INIT_FINALITY_SLASH_REWARD_RATIO; + } + + // Basic check + require(_evidence.voteA.srcNum+256 > block.number && + _evidence.voteB.srcNum+256 > block.number, "too old block involved"); + require(!(_evidence.voteA.srcHash == _evidence.voteB.srcHash && + _evidence.voteA.tarHash == _evidence.voteB.tarHash), "two identical votes"); + require(_evidence.voteA.srcNum < _evidence.voteA.tarNum && + _evidence.voteB.srcNum < _evidence.voteB.tarNum, "srcNum bigger than tarNum"); + + // Vote rules check + require((_evidence.voteA.srcNum<_evidence.voteB.srcNum && _evidence.voteB.tarNum<_evidence.voteA.tarNum) || + (_evidence.voteB.srcNum<_evidence.voteA.srcNum && _evidence.voteA.tarNum<_evidence.voteB.tarNum) || + _evidence.voteA.tarNum == _evidence.voteB.tarNum, "no violation of vote rules"); + + // BLS verification + (address[] memory vals, bytes[] memory voteAddrs) = IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).getLivingValidators(); + address valAddr; + bytes memory voteAddr = _evidence.voteAddr; + for (uint i; i < voteAddrs.length; ++i) { + if (BytesLib.equal(voteAddrs[i], voteAddr)) { + valAddr = vals[i]; + break; + } + } + require(valAddr != address(0), "validator not exist"); +{% if mock %}{% else %} + require(verifyBLSSignature(_evidence.voteA, _evidence.voteAddr) && + verifyBLSSignature(_evidence.voteB, _evidence.voteAddr), "verify signature failed"); +{% endif %} + uint256 amount = (address(SYSTEM_REWARD_ADDR).balance * finalitySlashRewardRatio) / 100; + ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(msg.sender, amount); + IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).felony(valAddr); + ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeSlashPackage(valAddr), 0); + emit validatorSlashed(valAddr); + } + function sendFelonyPackage(address validator) external override(ISlashIndicator) onlyValidatorContract onlyInit { ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeSlashPackage(validator), 0); } + function verifyBLSSignature(VoteData memory vote, bytes memory voteAddr) internal view returns(bool) { + bytes[] memory elements = new bytes[](4); + bytes memory _bytes = new bytes(32); + elements[0] = vote.srcNum.encodeUint(); + TypesToBytes.bytes32ToBytes(32, vote.srcHash, _bytes); + elements[1] = _bytes.encodeBytes(); + elements[2] = tarNum.encodeUint(); + TypesToBytes.bytes32ToBytes(32, vote.tarHash, _bytes); + elements[3] = _bytes.encodeBytes(); + + TypesToBytes.bytes32ToBytes(32, keccak256(elements.encodeList()), _bytes); + + // assemble input data + bytes memory input = new bytes(176); + bytesConcat(input, _bytes, 0, 32); + bytesConcat(input, vote.sig, 32, 96); + bytesConcat(input, voteAddr, 128, 48); + + // call the precompiled contract to verify the BLS signature + // the precompiled contract's address is 0x66 + bytes memory output = new bytes(1); + assembly { + let len := mload(input) + if iszero(staticcall(not(0), 0x66, add(input, 0x20), len, add(output, 0x20), 0x01)) { + revert(0, 0) + } + } + if (BytesLib.toUint8(output, 0) != uint8(1)) { + return false; + } + return true; + } + + function bytesConcat(bytes memory data, bytes memory _bytes, uint256 index, uint256 len) internal pure { + for (uint i; i misdemeanorThreshold, "the felonyThreshold out of range"); felonyThreshold = newFelonyThreshold; + } else if (Memory.compareStrings(key, "finalitySlashRewardRatio")) { + require(value.length == 32, "length of finalitySlashRewardRatio mismatch"); + uint256 newFinalitySlashRewardRatio = BytesToTypes.bytesToUint256(32, value); + require(newFinalitySlashRewardRatio >= 10 && newFinalitySlashRewardRatio < 100, "the finality slash reward ratio out of range"); + finalitySlashRewardRatio = newFinalitySlashRewardRatio; } else { require(false, "unknown param"); } diff --git a/contracts/System.sol b/contracts/System.sol index b86d845c..3a3b85ca 100644 --- a/contracts/System.sol +++ b/contracts/System.sol @@ -18,7 +18,7 @@ contract System { uint8 constant public GOV_CHANNELID = 0x09; uint8 constant public SLASH_CHANNELID = 0x0b; uint8 constant public CROSS_STAKE_CHANNELID = 0x10; - uint16 constant public bscChainID = 0x0060; + uint16 constant public bscChainID = 0x0038; address public constant VALIDATOR_CONTRACT_ADDR = 0x0000000000000000000000000000000000001000; address public constant SLASH_CONTRACT_ADDR = 0x0000000000000000000000000000000000001001; diff --git a/contracts/SystemReward.sol b/contracts/SystemReward.sol index fa8fd6fe..34c1f406 100644 --- a/contracts/SystemReward.sol +++ b/contracts/SystemReward.sol @@ -11,7 +11,6 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { uint public numOperator; mapping(address => bool) operators; - modifier doInit() { if (!alreadyInit) { operators[LIGHT_CLIENT_ADDR] = true; @@ -22,25 +21,24 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { _; } + modifier onlyOperator() { + require(operators[msg.sender],"only operator is allowed to call the method"); + _; + } + event rewardTo(address indexed to, uint256 amount); event rewardEmpty(); event receiveDeposit(address indexed from, uint256 amount); event updateOperator(address indexed operator); event paramChange(string key, bytes value); - receive() external payable{ if (msg.value>0) { emit receiveDeposit(msg.sender, msg.value); } } - - function claimRewards(address payable to, uint256 amount) external override(ISystemReward) doInit returns (uint256) { - if (!operators[msg.sender]) { - return 0; - } - + 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) { actualAmount = MAX_REWARDS; @@ -73,4 +71,4 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { } emit paramChange(key, value); } -} \ No newline at end of file +} diff --git a/contracts/SystemReward.template b/contracts/SystemReward.template index 46f786b1..2af14176 100644 --- a/contracts/SystemReward.template +++ b/contracts/SystemReward.template @@ -11,7 +11,6 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { uint public numOperator; mapping(address => bool) operators; - modifier doInit() { if (!alreadyInit) { operators[LIGHT_CLIENT_ADDR] = true; @@ -31,7 +30,6 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { event updateOperator(address indexed operator); event paramChange(string key, bytes value); - receive() external payable{ if (msg.value>0) { emit receiveDeposit(msg.sender, msg.value); @@ -98,4 +96,4 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { } emit paramChange(key, value); } -} \ No newline at end of file +} diff --git a/contracts/TendermintLightClient.sol b/contracts/TendermintLightClient.sol index 8421a780..b11ba35b 100644 --- a/contracts/TendermintLightClient.sol +++ b/contracts/TendermintLightClient.sol @@ -22,7 +22,7 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ uint64 public latestHeight; bytes32 public chainID; - bytes constant public INIT_CONSENSUS_STATE_BYTES = hex"42696e616e63652d436861696e2d4e696c650000000000000000000000000000000000000000000229eca254b3859bffefaf85f4c95da9fbd26527766b784272789c30ec56b380b6eb96442aaab207bc59978ba3dd477690f5c5872334fc39e627723daa97e441e88ba4515150ec3182bc82593df36f8abb25a619187fcfab7e552b94e64ed2deed000000e8d4a51000"; + bytes constant public INIT_CONSENSUS_STATE_BYTES = hex"42696e616e63652d436861696e2d5469677269730000000000000000000000000000000006915167cedaf7bbf7df47d932fdda630527ee648562cf3e52c5e5f46156a3a971a4ceb443c53a50d8653ef8cf1e5716da68120fb51b636dc6d111ec3277b098ecd42d49d3769d8a1f78b4c17a965f7a30d4181fabbd1f969f46d3c8e83b5ad4845421d8000000e8d4a510002ba4e81542f437b7ae1f8a35ddb233c789a8dc22734377d9b6d63af1ca403b61000000e8d4a51000df8da8c5abfdb38595391308bb71e5a1e0aabdc1d0cf38315d50d6be939b2606000000e8d4a51000b6619edca4143484800281d698b70c935e9152ad57b31d85c05f2f79f64b39f3000000e8d4a510009446d14ad86c8d2d74780b0847110001a1c2e252eedfea4753ebbbfce3a22f52000000e8d4a510000353c639f80cc8015944436dab1032245d44f912edc31ef668ff9f4a45cd0599000000e8d4a51000e81d3797e0544c3a718e1f05f0fb782212e248e784c1a851be87e77ae0db230e000000e8d4a510005e3fcda30bd19d45c4b73688da35e7da1fce7c6859b2c1f20ed5202d24144e3e000000e8d4a51000b06a59a2d75bf5d014fce7c999b5e71e7a960870f725847d4ba3235baeaa08ef000000e8d4a510000c910e2fe650e4e01406b3310b489fb60a84bc3ff5c5bee3a56d5898b6a8af32000000e8d4a5100071f2d7b8ec1c8b99a653429b0118cd201f794f409d0fea4d65b1b662f2b00063000000e8d4a51000"; uint256 constant public INIT_REWARD_FOR_VALIDATOR_SER_CHANGE = 1e16; uint256 public rewardForValidatorSetChange; diff --git a/genesis-template.json b/genesis-template.json index a421cd51..8636d298 100644 --- a/genesis-template.json +++ b/genesis-template.json @@ -18,6 +18,8 @@ "eulerBlock": 2, "gibbsBlock": 3, "moranBlock": 4, + "bonehBlock": 5, + "lynnBlock": 6, "parlia": { "period": 3, "epoch": 200 diff --git a/genesis.json b/genesis.json index 8785c315..8520d550 100644 --- a/genesis.json +++ b/genesis.json @@ -18,6 +18,8 @@ "eulerBlock": 2, "gibbsBlock": 3, "moranBlock": 4, + "bonehBlock": 5, + "lynnBlock": 6, "parlia": { "period": 3, "epoch": 200 @@ -25,7 +27,7 @@ }, "nonce": "0x0", "timestamp": "0x5e9da7ce", - "extraData": "0x00000000000000000000000000000000000000000000000000000000000000009fb29aac15b9a4b7f17c3385939b007540f4d7910000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "extraData": "0x00000000000000000000000000000000000000000000000000000000000000009fb29aac15b9a4b7f17c3385939b007540f4d79185e6972fc98cd3c81d64d40e325acfed44365b97a7567a27939c14dbc7512ddcf54cb1284eb637cfa308ae4e00cb55880000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "gasLimit": "0x2625a00", "difficulty": "0x1", "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", diff --git a/lib/Deployer.sol b/lib/Deployer.sol index 67d23cb4..b9af68d3 100644 --- a/lib/Deployer.sol +++ b/lib/Deployer.sol @@ -121,4 +121,41 @@ contract Deployer is Test { govHub.handleSynPackage(GOV_CHANNELID, elements.encodeList()); vm.stopPrank(); } + + function encodeOldValidatorSetUpdatePack(uint8 code, address[] memory valSet) internal pure returns (bytes memory) { + bytes[] memory elements = new bytes[](2); + elements[0] = code.encodeUint(); + + bytes[] memory vals = new bytes[](valSet.length); + for (uint256 i; i < valSet.length; ++i) { + bytes[] memory tmp = new bytes[](4); + tmp[0] = valSet[i].encodeAddress(); + tmp[1] = valSet[i].encodeAddress(); + tmp[2] = valSet[i].encodeAddress(); + tmp[3] = uint8(0x64).encodeUint(); + vals[i] = tmp.encodeList(); + } + + elements[1] = vals.encodeList(); + return elements.encodeList(); + } + + function encodeNewValidatorSetUpdatePack(uint8 code, address[] memory valSet, bytes[] memory voteAddrs) internal pure returns (bytes memory) { + bytes[] memory elements = new bytes[](2); + elements[0] = code.encodeUint(); + + bytes[] memory vals = new bytes[](valSet.length); + for (uint256 i; i < valSet.length; ++i) { + bytes[] memory tmp = new bytes[](5); + tmp[0] = valSet[i].encodeAddress(); + tmp[1] = valSet[i].encodeAddress(); + tmp[2] = valSet[i].encodeAddress(); + tmp[3] = uint8(0x64).encodeUint(); + tmp[4] = voteAddrs[i].encodeBytes(); + vals[i] = tmp.encodeList(); + } + + elements[1] = vals.encodeList(); + return elements.encodeList(); + } } diff --git a/lib/interface/IBSCValidatorSet.sol b/lib/interface/IBSCValidatorSet.sol index d5364b94..350dba8a 100644 --- a/lib/interface/IBSCValidatorSet.sol +++ b/lib/interface/IBSCValidatorSet.sol @@ -5,10 +5,12 @@ interface BSCValidatorSet { event batchTransferFailed(uint256 indexed amount, string reason); event batchTransferLowerFailed(uint256 indexed amount, bytes reason); event deprecatedDeposit(address indexed validator, uint256 amount); + event deprecatedFinalityRewardDeposit(address indexed validator, uint256 amount); event directTransfer(address indexed validator, uint256 amount); event directTransferFail(address indexed validator, uint256 amount); event failReasonWithStr(string message); event feeBurned(uint256 amount); + event finalityRewardDeposit(address indexed validator, uint256 amount); event paramChange(string key, bytes value); event systemTransfer(uint256 amount); event unexpectedPackage(uint8 channelId, bytes msgBytes); @@ -39,6 +41,7 @@ interface BSCValidatorSet { function GOV_HUB_ADDR() external view returns (address); function INCENTIVIZE_ADDR() external view returns (address); function INIT_BURN_RATIO() external view returns (uint256); + function INIT_FINALITY_REWARD_RATIO() external view returns (uint256); function INIT_MAINTAIN_SLASH_SCALE() external view returns (uint256); function INIT_MAX_NUM_OF_MAINTAINING() external view returns (uint256); function INIT_NUM_OF_CABINETS() external view returns (uint256); @@ -77,13 +80,16 @@ interface BSCValidatorSet { ); function currentValidatorSetMap(address) external view returns (uint256); function deposit(address valAddr) external payable; + function distributeFinalityReward(address[] memory valAddrs, uint256[] memory weights) external; function enterMaintenance() external; function exitMaintenance() external; function expireTimeSecondGap() external view returns (uint256); function felony(address validator) external; + function finalityRewardRatio() external view returns (uint256); function getCurrentValidatorIndex(address _validator) external view returns (uint256); function getIncoming(address validator) external view returns (uint256); - function getMiningValidators() external view returns (address[] memory); + function getLivingValidators() external view returns (address[] memory, bytes[] memory); + function getMiningValidators() external view returns (address[] memory, bytes[] memory); function getValidators() external view returns (address[] memory); function getWorkingValidatorCount() external view returns (uint256 workingValidatorCount); function handleAckPackage(uint8 channelId, bytes memory msgBytes) external; @@ -100,7 +106,11 @@ interface BSCValidatorSet { function numOfCabinets() external view returns (uint256); function numOfJailed() external view returns (uint256); function numOfMaintaining() external view returns (uint256); + function previousHeight() external view returns (uint256); function totalInComing() external view returns (uint256); function updateParam(string memory key, bytes memory value) external; - function validatorExtraSet(uint256) external view returns (uint256 enterMaintenanceHeight, bool isMaintaining); + function validatorExtraSet(uint256) + external + view + returns (uint256 enterMaintenanceHeight, bool isMaintaining, bytes memory voteAddress); } diff --git a/lib/interface/ISlashIndicator.sol b/lib/interface/ISlashIndicator.sol index e9d53129..1c0edb1f 100644 --- a/lib/interface/ISlashIndicator.sol +++ b/lib/interface/ISlashIndicator.sol @@ -8,6 +8,20 @@ interface SlashIndicator { event unKnownResponse(uint32 code); event validatorSlashed(address indexed validator); + struct FinalityEvidence { + VoteData voteA; + VoteData voteB; + bytes voteAddr; + } + + struct VoteData { + uint256 srcNum; + bytes32 srcHash; + uint256 tarNum; + bytes32 tarHash; + bytes sig; + } + function BIND_CHANNELID() external view returns (uint8); function BSC_RELAYER_REWARD() external view returns (uint256); function CODE_OK() external view returns (uint32); @@ -19,6 +33,7 @@ interface SlashIndicator { function GOV_CHANNELID() external view returns (uint8); function GOV_HUB_ADDR() external view returns (address); function INCENTIVIZE_ADDR() external view returns (address); + function INIT_FINALITY_SLASH_REWARD_RATIO() external view returns (uint256); function LIGHT_CLIENT_ADDR() external view returns (address); function MISDEMEANOR_THRESHOLD() external view returns (uint256); function RELAYERHUB_CONTRACT_ADDR() external view returns (address); @@ -36,6 +51,7 @@ interface SlashIndicator { function bscChainID() external view returns (uint16); function clean() external; function felonyThreshold() external view returns (uint256); + function finalitySlashRewardRatio() external view returns (uint256); function getSlashIndicator(address validator) external view returns (uint256, uint256); function getSlashThresholds() external view returns (uint256, uint256); function handleAckPackage(uint8, bytes memory msgBytes) external; @@ -47,6 +63,7 @@ interface SlashIndicator { function previousHeight() external view returns (uint256); function sendFelonyPackage(address validator) external; function slash(address validator) external; + function submitFinalityViolationEvidence(FinalityEvidence memory _evidence) external; function updateParam(string memory key, bytes memory value) external; function validators(uint256) external view returns (address); } diff --git a/lib/interface/ISystemReward.sol b/lib/interface/ISystemReward.sol index deabd0ed..b9884fa4 100644 --- a/lib/interface/ISystemReward.sol +++ b/lib/interface/ISystemReward.sol @@ -1,9 +1,11 @@ pragma solidity ^0.8.10; interface SystemReward { + event paramChange(string key, bytes value); event receiveDeposit(address indexed from, uint256 amount); event rewardEmpty(); event rewardTo(address indexed to, uint256 amount); + event updateOperator(address indexed operator); function BIND_CHANNELID() external view returns (uint8); function CODE_OK() external view returns (uint32); @@ -31,4 +33,5 @@ interface SystemReward { function claimRewards(address to, uint256 amount) external returns (uint256); function isOperator(address addr) external view returns (bool); function numOperator() external view returns (uint256); + function updateParam(string memory key, bytes memory value) external; } diff --git a/test/Slash.js b/test/Slash.js new file mode 100644 index 00000000..1d233a06 --- /dev/null +++ b/test/Slash.js @@ -0,0 +1,580 @@ +const SlashIndicator = artifacts.require("SlashIndicator"); +const BSCValidatorSet = artifacts.require("BSCValidatorSet"); +const Web3 = require('web3'); +const crypto = require('crypto'); +const RLP = require('rlp'); +const SystemReward = artifacts.require("SystemReward"); +const truffleAssert = require('truffle-assertions'); +const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')); +const STAKE_CHANNEL_ID = 0x08; + +contract('SlashIndicator', (accounts) => { + it('slash success', async () => { + const slashInstance = await SlashIndicator.deployed(); + const validatorInstance = await BSCValidatorSet.deployed(); + + const accountOne = accounts[0]; + + let validatorAccounts = (await validatorInstance.getMiningValidators.call())["0"]; + let validatorAccount = validatorAccounts[0]; + + for (let i =1; i<10; i++){ + await slashInstance.slash(validatorAccount, { from: accountOne }); + let res= (await slashInstance.getSlashIndicator.call(validatorAccount)); + let count =res[1].toNumber(); + assert.equal(count, i, "slash num is not correct"); + } + }); + + it('slash from no system account', async () => { + const slashInstance = await SlashIndicator.deployed(); + const validatorInstance = await BSCValidatorSet.deployed(); + + const nonSystemAccount = accounts[1]; + let validatorAccounts = (await validatorInstance.getMiningValidators.call())["0"]; + let validatorAccount = validatorAccounts[0]; + // first slash + try{ + await slashInstance.slash(validatorAccount, { from: nonSystemAccount }); + assert.fail(); + }catch (error) { + assert.ok(error.toString().includes("the message sender must be the block producer"), "slash from no system account should not be ok"); + } + }); +}); + +contract('SlashIndicator: isOperator works', (accounts) => { + it('isOperator works', async () => { + const slashInstance = await SlashIndicator.deployed(); + const validatorInstance = await BSCValidatorSet.deployed(); + + const accountOne = accounts[0]; + let validatorAccounts = (await validatorInstance.getMiningValidators.call())["0"]; + let validatorAccount = validatorAccounts[0]; + + // slash afterward + for (let i =1; i<10; i++){ + await slashInstance.slash(validatorAccount, { from: accountOne }); + let res= (await slashInstance.getSlashIndicator.call(validatorAccount)); + let count =res[1].toNumber(); + assert.equal(count, i, "slash num is not correct for validator"); + } + }); +}); + +contract('SlashIndicator: catch emit event', (accounts) => { + it('catch emit event', async () => { + const slashInstance = await SlashIndicator.deployed(); + const validatorInstance = await BSCValidatorSet.deployed(); + + const accountOne = accounts[0]; + let validatorAccounts = (await validatorInstance.getMiningValidators.call())["0"]; + let validatorAccount = validatorAccounts[0]; + for (let i =1; i<50; i++){ + let tx = await slashInstance.slash(validatorAccount, { from: accountOne }); + truffleAssert.eventEmitted(tx, "validatorSlashed",(ev) => { + return ev.validator === validatorAccount; + }); + } + }); +}); + +contract('SlashIndicator', (accounts) => { + it('trigger misdemeanor', async () => { + const slashInstance = await SlashIndicator.deployed(); + const validatorSetInstance = await BSCValidatorSet.deployed(); + const systemRewardInstance = await SystemReward.deployed(); + + const systemAccount = accounts[0]; + let validator = accounts[0]; + let secondValidator = accounts[1]; + let thirdValidator = accounts[2]; + + await validatorSetInstance.deposit(validator, {from: systemAccount, value: 1e18 }); + await systemRewardInstance.addOperator(validatorSetInstance.address, {from: systemAccount}); + + let amount = await validatorSetInstance.getIncoming.call(validator); + assert.equal(amount.toString(),web3.utils.toBN(1e18).toString()) + + for (let i =1; i<=50; i++){ + await slashInstance.slash(validator, { from: systemAccount }); + } + + amount = await validatorSetInstance.getIncoming.call(validator); + assert.equal(amount.toNumber(),0); + + let packageBytes = validatorUpdateRlpEncode([validator,secondValidator,thirdValidator], + [validator,secondValidator,thirdValidator],[validator,secondValidator,thirdValidator]); + await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: accounts[8]}); + + await validatorSetInstance.deposit(validator, {from: systemAccount, value: 2e18 }); + amount = await validatorSetInstance.getIncoming.call(validator); + assert.equal(amount.toString(),web3.utils.toBN(2e18).toString()) + for (let i =1; i<=4; i++){ + await slashInstance.slash(validator, { from: systemAccount }); + } + let res= (await slashInstance.getSlashIndicator.call(validator)); + assert.equal(res[1].toNumber(),50); + amount = await validatorSetInstance.getIncoming.call(validator); + assert.equal(amount.toNumber(),0); + amount = await validatorSetInstance.getIncoming.call(secondValidator); + assert.equal(amount.toString(),web3.utils.toBN(1e18).toString()) + amount = await validatorSetInstance.getIncoming.call(thirdValidator); + assert.equal(amount.toString(),web3.utils.toBN(1e18).toString()) + + + await validatorSetInstance.deposit(secondValidator, {from: systemAccount, value: 1e18 }); + amount = await validatorSetInstance.getIncoming.call(secondValidator); + assert.equal(amount.toString(),web3.utils.toBN(2e18).toString()) + for (let i =1; i<=50; i++){ + await slashInstance.slash(secondValidator, { from: systemAccount }); + } + res= (await slashInstance.getSlashIndicator.call(secondValidator)); + assert.equal(res[1].toNumber(),50); + amount = await validatorSetInstance.getIncoming.call(validator); + assert.equal(amount.toString(),web3.utils.toBN(1e18).toString()) + amount = await validatorSetInstance.getIncoming.call(secondValidator); + assert.equal(amount.toNumber(),0); + amount = await validatorSetInstance.getIncoming.call(thirdValidator); + assert.equal(amount.toString(),web3.utils.toBN(2e18).toString()) + + for (let i =1; i<=50; i++){ + await slashInstance.slash(thirdValidator, { from: systemAccount }); + } + res= (await slashInstance.getSlashIndicator.call(thirdValidator)); + assert.equal(res[1].toNumber(),50); + amount = await validatorSetInstance.getIncoming.call(validator); + assert.equal(amount.toString(),web3.utils.toBN(2e18).toString()) + amount = await validatorSetInstance.getIncoming.call(secondValidator); + assert.equal(amount.toString(),web3.utils.toBN(1e18).toString()) + amount = await validatorSetInstance.getIncoming.call(thirdValidator); + assert.equal(amount.toNumber(),0); + + }); +}); + +contract('felony SlashIndicator', (accounts) => { + it('trigger felony ', async () => { + const slashInstance = await SlashIndicator.deployed(); + const validatorSetInstance = await BSCValidatorSet.deployed(); + + const systemAccount = accounts[0]; + let validator = accounts[0]; + let secondValidator = accounts[1]; + let thirdValidator = accounts[2]; + + let packageBytes = validatorUpdateRlpEncode([validator,secondValidator,thirdValidator], + [validator,secondValidator,thirdValidator],[validator,secondValidator,thirdValidator]); + await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: accounts[8]}); + + await validatorSetInstance.deposit(validator, {from: systemAccount, value: 2e18 }); + amount = await validatorSetInstance.getIncoming.call(validator); + assert.equal(amount.toString(),web3.utils.toBN(2e18).toString(), "case1: incoming of account1 is wrong") + for (let i =1; i<=150; i++){ + await slashInstance.slash(validator, { from: systemAccount }); + } + + let res= (await slashInstance.getSlashIndicator.call(validator)); + assert.equal(res[1].toNumber(),0, "case1: slash indicator of account1 is wrong"); + amount = await validatorSetInstance.getIncoming.call(validator); + assert.equal(amount.toNumber(),0, "case1: incoming of account1 is wrong"); + amount = await validatorSetInstance.getIncoming.call(secondValidator); + assert.equal(amount.toString(),web3.utils.toBN(1e18).toString(), "case1: incoming of account2 is wrong"); + amount = await validatorSetInstance.getIncoming.call(thirdValidator); + assert.equal(amount.toString(),web3.utils.toBN(1e18).toString(), "case1: incoming of account3 is wrong"); + let consensusAddress = await validatorSetInstance.getValidators.call(); + assert.equal(consensusAddress.length,2, "case1: length of validators should be 2"); + assert.equal(consensusAddress[0],secondValidator, "case1: index 0 of validators should be account2"); + assert.equal(consensusAddress[1],thirdValidator, "case1: index 1 of validators should be account3"); + + packageBytes = validatorUpdateRlpEncode([validator,secondValidator,thirdValidator], + [validator,secondValidator,thirdValidator],[validator,secondValidator,thirdValidator]); + await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: accounts[8]}); + + await validatorSetInstance.deposit(secondValidator, {from: systemAccount, value: 2e18 }); + amount = await validatorSetInstance.getIncoming.call(secondValidator); + assert.equal(amount.toString(),web3.utils.toBN(2e18).toString(), "case2: incoming of account2 is wrong") + for (let i =1; i<=150; i++){ + await slashInstance.slash(secondValidator, { from: systemAccount }); + } + + res= (await slashInstance.getSlashIndicator.call(secondValidator)); + assert.equal(res[1].toNumber(),0, "case2: slash indicator of account2 is wrong"); + amount = await validatorSetInstance.getIncoming.call(secondValidator); + assert.equal(amount.toNumber(),0, "case2: incoming of account2 is wrong"); + amount = await validatorSetInstance.getIncoming.call(validator); + assert.equal(amount.toString(),web3.utils.toBN(1e18).toString(), "case2: incoming of account1 is wrong"); + amount = await validatorSetInstance.getIncoming.call(thirdValidator); + assert.equal(amount.toString(),web3.utils.toBN(1e18).toString(), "case2: incoming of account3 is wrong"); + consensusAddress = await validatorSetInstance.getValidators.call(); + assert.equal(consensusAddress.length,2, "case2: length of validators should be 2"); + assert.equal(consensusAddress[0],validator, "case2: index 0 of validators should be account1"); + assert.equal(consensusAddress[1],thirdValidator, "case2: index 1 of validators should be account3"); + + packageBytes = validatorUpdateRlpEncode([validator,secondValidator,thirdValidator], + [validator,secondValidator,thirdValidator],[validator,secondValidator,thirdValidator]); + await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: accounts[8]}); + + await validatorSetInstance.deposit(thirdValidator, {from: systemAccount, value: 2e18 }); + amount = await validatorSetInstance.getIncoming.call(thirdValidator); + assert.equal(amount.toString(),web3.utils.toBN(2e18).toString(), "case3: incoming of account3 is wrong") + for (let i =1; i<=150; i++){ + await slashInstance.slash(thirdValidator, { from: systemAccount }); + } + + res= (await slashInstance.getSlashIndicator.call(thirdValidator)); + assert.equal(res[1].toNumber(),0, "case3: slash indicator of account3 is wrong"); + amount = await validatorSetInstance.getIncoming.call(thirdValidator); + assert.equal(amount.toNumber(),0, "case3: incoming of account3 is wrong"); + amount = await validatorSetInstance.getIncoming.call(validator); + assert.equal(amount.toString(),web3.utils.toBN(1e18).toString(), "case3: incoming of account1 is wrong"); + amount = await validatorSetInstance.getIncoming.call(secondValidator); + assert.equal(amount.toString(),web3.utils.toBN(1e18).toString(), "case3: incoming of account2 is wrong"); + consensusAddress = await validatorSetInstance.getValidators.call(); + assert.equal(consensusAddress.length,2, "case3: length of validators should be 2"); + assert.equal(consensusAddress[0],validator, "case3: index 0 of validators should be account1"); + assert.equal(consensusAddress[1],secondValidator, "case3: index 0 of validators should be account2"); + + }); +}); + +contract('Clean SlashIndicator', (accounts) => { + it('test slash clean', async () => { + const slashInstance = await SlashIndicator.deployed(); + const validatorSetInstance = await BSCValidatorSet.deployed(); + let newValidator = web3.eth.accounts.create(); + let relayerAccount = accounts[8]; + const accountOne = accounts[0]; + + // case 1: all clean. + let validators = []; + for(let i =0;i <20; i++){ + validators.push(web3.eth.accounts.create().address); + } + // Do init + let packageBytes = validatorUpdateRlpEncode(validators, + validators,validators); + await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: relayerAccount}); + + for(let i =0;i <20;i++){ + await slashInstance.slash(validators[i], { from: accountOne }); + } + + // do clean + await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: relayerAccount}); + + let res= (await slashInstance.getSlashValidators.call()); + assert.equal(res.length, 0); + + for(let i =0;i <20;i++){ + let res = await slashInstance.getSlashIndicator.call(validators[i]); + let count =res[1].toNumber(); + let height = res[0].toNumber(); + assert.equal(count, 0); + assert.equal(height, 0); + } + + // case 2: all stay. + for(let i =0;i <20;i++){ + for(let j=0;j<5;j++){ + await slashInstance.slash(validators[i], { from: accountOne }); + } + } + // do clean + await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: relayerAccount}); + res= (await slashInstance.getSlashValidators.call()); + assert.equal(res.length, 20); + for(let i =0;i <20;i++){ + let res = await slashInstance.getSlashIndicator.call(validators[i]); + let count =res[1].toNumber(); + assert.equal(count, 1); + } + + // case 3: partial stay. + for(let i =0;i <10;i++){ + for(let j=0;j<5;j++){ + await slashInstance.slash(validators[2*i], { from: accountOne }); + } + await slashInstance.slash(validators[2*i+1], { from: accountOne }); + } + // doclean + await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: relayerAccount}); + res= (await slashInstance.getSlashValidators.call()); + assert.equal(res.length, 10); + for(let i =0;i <20;i++){ + let res = await slashInstance.getSlashIndicator.call(validators[i]); + let count =res[1].toNumber(); + if(i%2==0){ + assert.equal(count, 2); + }else{ + assert.equal(count, 0); + } + } + + // case 4: partial stay. + for(let i =0;i <10;i++){ + for(let j=0;j<5;j++){ + await slashInstance.slash(validators[2*i+1], { from: accountOne }); + } + await slashInstance.slash(validators[2*i], { from: accountOne }); + } + // doclean + await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: relayerAccount}); + res= (await slashInstance.getSlashValidators.call()); + assert.equal(res.length, 10); + for(let i =0;i <20;i++){ + let res = await slashInstance.getSlashIndicator.call(validators[i]); + let count =res[1].toNumber(); + if(i%2==0){ + assert.equal(count, 0); + }else{ + assert.equal(count, 1); + } + } + + }); +}); + +contract("finality slash SlashIndicator", (accounts) => { + it("valid finality evidence: same target block", async () => { + const slashInstance = await SlashIndicator.deployed(); + const systemRewardInstance = await SystemReward.deployed(); + const validatorSetInstance = await BSCValidatorSet.deployed(); + let relayerAccount = accounts[8]; + + await systemRewardInstance.send(web3.utils.toBN(1e18), { from: accounts[1] }); + await systemRewardInstance.addOperator(slashInstance.address); + + // add vote address + let packageBytes = newValidatorUpdateRlpEncode( + [accounts[0]], + [accounts[0]], + [accounts[0]], + [Buffer.from("voteAddr")] + ); + await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID, packageBytes, { + from: relayerAccount, + }); + + let currentNumber = await web3.eth.getBlockNumber(); + let srcNumA = currentNumber - 20; + let tarNumA = currentNumber - 10; + let srcNumB = currentNumber - 15; + let tarNumB = tarNumA; + let srcHashA = await web3.eth.getBlock(srcNumA).then((x) => { + return x.hash; + }); + let tarHashA = await web3.eth.getBlock(tarNumA).then((x) => { + return x.hash; + }); + let srcHashB = await web3.eth.getBlock(srcNumB).then((x) => { + return x.hash; + }); + let tarHashB = tarHashA; + + let voteDataA = { + srcNum: srcNumA, + tarNum: tarNumA, + srcHash: srcHashA, + tarHash: tarHashA, + sig: Buffer.from("sigA") + } + let voteDataB = { + srcNum: srcNumB, + tarNum: tarNumB, + srcHash: srcHashB, + tarHash: tarHashB, + sig: Buffer.from("sigB") + } + let evidence = { + voteA: voteDataA, + voteB: voteDataB, + voteAddr: Buffer.from("voteAddr"), + }; + + let tx = await slashInstance.submitFinalityViolationEvidence(evidence, { + from: relayerAccount, + }); + truffleAssert.eventEmitted(tx, "validatorSlashed", (ev) => { + return ev.validator === accounts[0]; + }); + }); + + it("valid finality evidence: vote within span", async () => { + const slashInstance = await SlashIndicator.deployed(); + let relayerAccount = accounts[8]; + + let currentNumber = await web3.eth.getBlockNumber(); + let srcNumA = currentNumber - 20; + let tarNumA = currentNumber - 10; + let srcNumB = currentNumber - 18; + let tarNumB = currentNumber - 15; + let srcHashA = await web3.eth.getBlock(srcNumA).then((x) => { + return x.hash; + }); + let tarHashA = await web3.eth.getBlock(tarNumA).then((x) => { + return x.hash; + }); + let srcHashB = await web3.eth.getBlock(srcNumA).then((x) => { + return x.hash; + }); + let tarHashB = await web3.eth.getBlock(tarNumB).then((x) => { + return x.hash; + }); + + let voteDataA = { + srcNum: srcNumA, + tarNum: tarNumA, + srcHash: srcHashA, + tarHash: tarHashA, + sig: Buffer.from("sigA") + } + let voteDataB = { + srcNum: srcNumB, + tarNum: tarNumB, + srcHash: srcHashB, + tarHash: tarHashB, + sig: Buffer.from("sigB") + } + let evidence = { + voteA: voteDataA, + voteB: voteDataB, + voteAddr: Buffer.from("voteAddr"), + }; + + let tx = await slashInstance.submitFinalityViolationEvidence(evidence, { + from: relayerAccount, + }); + truffleAssert.eventEmitted(tx, "validatorSlashed", (ev) => { + return ev.validator === accounts[0]; + }); + }); + + it("invalid finality evidence", async () => { + const slashInstance = await SlashIndicator.deployed(); + let relayerAccount = accounts[8]; + + let currentNumber = await web3.eth.getBlockNumber(); + let srcNumA = currentNumber - 20; + let tarNumA = currentNumber - 10; + let srcNumB = currentNumber - 18; + let tarNumB = currentNumber - 12; + let srcHashA = await web3.eth.getBlock(srcNumA).then((x) => { + return x.hash; + }); + let tarHashA = await web3.eth.getBlock(tarNumA).then((x) => { + return x.hash; + }); + let srcHashB = await web3.eth.getBlock(srcNumA).then((x) => { + return x.hash; + }); + let tarHashB = await web3.eth.getBlock(tarNumB).then((x) => { + return x.hash; + }); + + let voteDataA = { + srcNum: srcNumA, + tarNum: tarNumA, + srcHash: srcHashA, + tarHash: tarHashA, + sig: Buffer.from("sigA") + } + let voteDataB = { + srcNum: srcNumB, + tarNum: tarNumB, + srcHash: srcHashB, + tarHash: tarHashB, + sig: Buffer.from("sigB") + } + let evidence = { + voteA: voteDataA, + voteB: voteDataB, + voteAddr: Buffer.from("voteAddr"), + }; + + evidence.voteA.srcNum = currentNumber - 257; + try { + await slashInstance.submitFinalityViolationEvidence(evidence, { from: relayerAccount }); + assert.fail(); + } catch (error) { + assert.ok( + error.toString().includes("too old block involved") + ); + } + + evidence.voteA.srcNum = currentNumber - 20; + evidence.voteB = voteDataA; + try { + await slashInstance.submitFinalityViolationEvidence(evidence, { from: relayerAccount }); + assert.fail(); + } catch (error) { + assert.ok( + error.toString().includes("two identical votes") + ); + } + + evidence.voteB = voteDataB; + evidence.voteA.tarNum = evidence.voteA.srcNum - 1; + try { + await slashInstance.submitFinalityViolationEvidence(evidence, { from: relayerAccount }); + assert.fail(); + } catch (error) { + assert.ok( + error.toString().includes("srcNum bigger than tarNum") + ); + } + + evidence.voteA.tarNum = currentNumber - 10; + evidence.voteB.tarNum = currentNumber - 8; + try { + await slashInstance.submitFinalityViolationEvidence(evidence, { from: relayerAccount }); + assert.fail(); + } catch (error) { + assert.ok(error.toString().includes("no violation of vote rules")); + } + + evidence.voteB.tarNum = currentNumber - 12; + evidence.voteAddr = Buffer.from("wrongVoteAddr"); + try { + await slashInstance.submitFinalityViolationEvidence(evidence, { from: relayerAccount }); + assert.fail(); + } catch (error) { + assert.ok(error.toString().includes("validator not exist")); + } + }); +}); + +function validatorUpdateRlpEncode(consensusAddrList,feeAddrList, bscFeeAddrList) { + let pkg = []; + pkg.push(0x00); + let n = consensusAddrList.length; + let vals = []; + for(let i = 0;i bool) cabinets; function setUp() public { + bytes memory rewardCode = vm.getDeployedCode("SystemReward.sol"); + vm.etch(address(systemReward), rewardCode); + bytes memory slashCode = vm.getDeployedCode("SlashIndicator.sol"); + vm.etch(address(slash), slashCode); + bytes memory validatorCode = vm.getDeployedCode("BSCValidatorSet.sol"); + vm.etch(address(validator), validatorCode); + + // add operator + bytes memory key = "updateOperator"; + bytes memory valueBytes = abi.encodePacked(address(validator)); + vm.expectEmit(false, false, false, true, address(systemReward)); + emit paramChange(string(key), valueBytes); + updateParamByGovHub(key, valueBytes, address(systemReward)); + assertTrue(systemReward.isOperator(address(validator))); + burnRatio = validator.INIT_BURN_RATIO(); burnRatioScale = validator.BURN_RATIO_SCALE(); validators = validator.getValidators(); @@ -120,27 +137,33 @@ contract ValidatorSetTest is Deployer { newValidators[i] = addrSet[addrIdx++]; } vm.startPrank(address(crossChain)); - validator.handleSynPackage(STAKING_CHANNELID, _encodeValidatorSetUpdatePack(0x00, newValidators)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, newValidators)); vm.stopPrank(); address[] memory vals = validator.getValidators(); - address[] memory miningVals = validator.getMiningValidators(); + (address[] memory miningVals,) = validator.getMiningValidators(); + uint256 count; uint256 _numOfCabinets; + uint256 _maxNumOfWorkingCandidates = maxNumOfWorkingCandidates; if (numOfCabinets == 0) { _numOfCabinets = validator.INIT_NUM_OF_CABINETS(); } else { _numOfCabinets = numOfCabinets; } + if ((vals.length - _numOfCabinets) < _maxNumOfWorkingCandidates) { + _maxNumOfWorkingCandidates = vals.length - _numOfCabinets; + } + for (uint256 i; i < _numOfCabinets; ++i) { cabinets[vals[i]] = true; } - for (uint256 i; i < miningVals.length; ++i) { + for (uint256 i; i < _numOfCabinets; ++i) { if (!cabinets[miningVals[i]]) { ++count; } } - assertGe(maxNumOfWorkingCandidates, count); + assertGe(_maxNumOfWorkingCandidates, count); assertGe(count, 0); } @@ -150,7 +173,7 @@ contract ValidatorSetTest is Deployer { // To reset the incoming vm.startPrank(address(crossChain)); - validator.handleSynPackage(STAKING_CHANNELID, _encodeValidatorSetUpdatePack(0x00, newValidator)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, newValidator)); vm.stopPrank(); address val = newValidator[0]; @@ -180,7 +203,7 @@ contract ValidatorSetTest is Deployer { vm.expectEmit(false, false, false, false, address(validator)); emit validatorSetUpdated(); vm.startPrank(address(crossChain)); - validator.handleSynPackage(STAKING_CHANNELID, _encodeValidatorSetUpdatePack(0x00, newValidator)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, newValidator)); vm.stopPrank(); } @@ -192,7 +215,7 @@ contract ValidatorSetTest is Deployer { // To reset the incoming vm.startPrank(address(crossChain)); - validator.handleSynPackage(STAKING_CHANNELID, _encodeValidatorSetUpdatePack(0x00, newValidators)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, newValidators)); vm.stopPrank(); vm.startPrank(coinbase); @@ -205,7 +228,7 @@ contract ValidatorSetTest is Deployer { newValidators[i] = addrSet[addrIdx++]; } vm.startPrank(address(crossChain)); - validator.handleSynPackage(STAKING_CHANNELID, _encodeValidatorSetUpdatePack(0x00, newValidators)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, newValidators)); vm.stopPrank(); } @@ -219,7 +242,7 @@ contract ValidatorSetTest is Deployer { vm.startPrank(address(crossChain)); vm.expectEmit(false, false, false, true, address(validator)); emit failReasonWithStr("the number of validators exceed the limit"); - validator.handleSynPackage(STAKING_CHANNELID, _encodeValidatorSetUpdatePack(0x00, newValidators)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, newValidators)); vm.stopPrank(); } @@ -230,7 +253,7 @@ contract ValidatorSetTest is Deployer { for (uint256 i; i < 5; ++i) { newValidators[i] = addrSet[addrIdx++]; } - bytes memory pack = _encodeValidatorSetUpdatePack(0x00, newValidators); + bytes memory pack = encodeOldValidatorSetUpdatePack(0x00, newValidators); vm.startPrank(address(crossChain)); validator.handleSynPackage(STAKING_CHANNELID, pack); vm.stopPrank(); @@ -282,7 +305,7 @@ contract ValidatorSetTest is Deployer { vm.startPrank(address(crossChain)); for (uint256 k; k < 5; ++k) { - validator.handleSynPackage(STAKING_CHANNELID, _encodeValidatorSetUpdatePack(0x00, newValSet[k])); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, newValSet[k])); address[] memory valSet = validator.getValidators(); for (uint256 l; l < 5 + k; ++l) { assertEq(valSet[l], newValSet[k][l], "consensusAddr not equal"); @@ -309,13 +332,13 @@ contract ValidatorSetTest is Deployer { newValSet[2][3] = addrSet[addrIdx++]; vm.startPrank(address(crossChain)); - validator.handleSynPackage(STAKING_CHANNELID, _encodeValidatorSetUpdatePack(0x00, newValSet[2])); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, newValSet[2])); for (uint256 i; i < 2; ++i) { vm.expectEmit(false, false, false, true, address(validator)); emit failReasonWithStr("duplicate consensus address of validatorSet"); - validator.handleSynPackage(STAKING_CHANNELID, _encodeValidatorSetUpdatePack(0x00, newValSet[i])); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, newValSet[i])); } - validator.handleSynPackage(STAKING_CHANNELID, _encodeValidatorSetUpdatePack(0x00, newValSet[3])); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, newValSet[3])); vm.stopPrank(); uint256 height = block.number; @@ -336,11 +359,11 @@ contract ValidatorSetTest is Deployer { address[] memory newValidators = new address[](5); address deprecated = addrSet[addrIdx++]; uint256 balance = deprecated.balance; - newValidators[0] = address(validator); + newValidators[0] = address(slash); for (uint256 i = 1; i < 5; ++i) { newValidators[i] = addrSet[addrIdx++]; } - bytes memory pack = _encodeValidatorSetUpdatePack(0x00, newValidators); + bytes memory pack = encodeOldValidatorSetUpdatePack(0x00, newValidators); vm.startPrank(address(crossChain)); validator.handleSynPackage(STAKING_CHANNELID, pack); vm.stopPrank(); @@ -385,7 +408,7 @@ contract ValidatorSetTest is Deployer { address[] memory newValidators = new address[](5); address deprecated = addrSet[addrIdx++]; uint256 balance = deprecated.balance; - newValidators[0] = address(validator); + newValidators[0] = address(slash); for (uint256 i = 1; i < 5; ++i) { newValidators[i] = addrSet[addrIdx++]; } @@ -396,7 +419,7 @@ contract ValidatorSetTest is Deployer { (bool success,) = address(tokenHub).call(abi.encodeWithSignature("setPanicBatchTransferOut(bool)", true)); require(success); - bytes memory pack = _encodeValidatorSetUpdatePack(0x00, newValidators); + bytes memory pack = encodeOldValidatorSetUpdatePack(0x00, newValidators); vm.startPrank(address(crossChain)); validator.handleSynPackage(STAKING_CHANNELID, pack); vm.stopPrank(); @@ -450,7 +473,7 @@ contract ValidatorSetTest is Deployer { } vm.startPrank(address(crossChain)); - validator.handleSynPackage(STAKING_CHANNELID, _encodeValidatorSetUpdatePack(0x00, newValidators)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, newValidators)); address[] memory remainVals = validator.getValidators(); assertEq(remainVals.length, 3); @@ -460,11 +483,11 @@ contract ValidatorSetTest is Deployer { vm.expectEmit(false, false, false, true, address(validator)); emit failReasonWithStr("length of jail validators must be one"); - validator.handleSynPackage(STAKING_CHANNELID, _encodeValidatorSetUpdatePack(0x01, newValidators)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x01, newValidators)); address[] memory jailVal = new address[](1); jailVal[0] = newValidators[0]; - validator.handleSynPackage(STAKING_CHANNELID, _encodeValidatorSetUpdatePack(0x01, jailVal)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x01, jailVal)); remainVals = validator.getValidators(); assertEq(remainVals.length, 2); @@ -473,34 +496,64 @@ contract ValidatorSetTest is Deployer { } jailVal[0] = newValidators[1]; - validator.handleSynPackage(STAKING_CHANNELID, _encodeValidatorSetUpdatePack(0x01, jailVal)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x01, jailVal)); remainVals = validator.getValidators(); assertEq(remainVals.length, 1); assertEq(remainVals[0], newValidators[2]); jailVal[0] = newValidators[2]; - validator.handleSynPackage(STAKING_CHANNELID, _encodeValidatorSetUpdatePack(0x01, jailVal)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x01, jailVal)); remainVals = validator.getValidators(); assertEq(remainVals.length, 1); assertEq(remainVals[0], newValidators[2]); vm.stopPrank(); } - function _encodeValidatorSetUpdatePack(uint8 code, address[] memory valSet) internal pure returns (bytes memory) { - bytes[] memory elements = new bytes[](2); - elements[0] = code.encodeUint(); - - bytes[] memory vals = new bytes[](valSet.length); - for (uint256 i; i < valSet.length; ++i) { - bytes[] memory tmp = new bytes[](4); - tmp[0] = valSet[i].encodeAddress(); - tmp[1] = valSet[i].encodeAddress(); - tmp[2] = valSet[i].encodeAddress(); - tmp[3] = uint8(0x64).encodeUint(); - vals[i] = tmp.encodeList(); + function testDecodeNewCrossChainPack() public { + address[] memory newValidators = new address[](41); + bytes[] memory newVoteAddrs = new bytes[](41); + for (uint256 i; i < newValidators.length; ++i) { + newValidators[i] = addrSet[addrIdx++]; + newVoteAddrs[i] = abi.encodePacked(newValidators[i]); + } + vm.startPrank(address(crossChain)); + validator.handleSynPackage(STAKING_CHANNELID, encodeNewValidatorSetUpdatePack(0x00, newValidators, newVoteAddrs)); + vm.stopPrank(); + + (address[] memory vals, bytes[] memory voteAddrs) = validator.getLivingValidators(); + for (uint256 i; i < newValidators.length; ++i) { + assertEq(voteAddrs[i], abi.encodePacked(vals[i])); } + } - elements[1] = vals.encodeList(); - return elements.encodeList(); + function testDistributeFinalityReward() public { + address[] memory addrs = new address[](20); + uint256[] memory weights = new uint256[](20); + address[] memory vals = validator.getValidators(); + for (uint256 i; i < 10; ++i) { + addrs[i] = vals[i]; + weights[i] = 1; + } + + for (uint256 i = 10; i < 20; ++i) { + vals[i] = addrSet[addrIdx++]; + weights[i] = 1; + } + + vm.deal(address(systemReward), 1 ether); + vm.expectRevert(bytes("the message sender must be the block producer")); + validator.distributeFinalityReward(addrs, weights); + + vm.expectEmit(true, false, false, true, address(validator)); + emit finalityRewardDeposit(addrs[0], 5e15); + vm.expectEmit(true, false, false, true, address(validator)); + emit finalityRewardDeposit(addrs[9], 5e15); + vm.expectEmit(true, false, false, true, address(validator)); + emit deprecatedFinalityRewardDeposit(addrs[10], 5e15); + vm.expectEmit(true, false, false, true, address(validator)); + emit deprecatedFinalityRewardDeposit(addrs[19], 5e15); + vm.startPrank(address(coinbase)); + validator.distributeFinalityReward(addrs, weights); + vm.stopPrank(); } } diff --git a/test/slash.ts b/test/slash.ts new file mode 100644 index 00000000..00dc0207 --- /dev/null +++ b/test/slash.ts @@ -0,0 +1,784 @@ +import {BigNumber, Contract} from 'ethers'; +import {ethers} from 'hardhat'; +import {expect} from 'chai'; +import { + buildSyncPackagePrefix, + deployContract, + mineBlocks, + serializeGovPack, + setSlashIndicator, + validatorUpdateRlpEncode, + waitTx, +} from './helper'; +import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers'; +import web3 from 'web3'; +import { + BSCValidatorSet, + CrossChain, + GovHub, + RelayerHub, + RelayerIncentivize, + SlashIndicator, + SystemReward, + TendermintLightClient, +} from '../../typechain-types'; + +const log = console.log; +const STAKE_CHANNEL_ID = 0x08; +const GOV_CHANNEL_ID = 0x09; +const proof = Buffer.from(web3.utils.hexToBytes('0x00')); +const merkleHeight = 100; + +const deployContractAndInit = async ( + deployer: SignerWithAddress, + factoryPath: string, + needInit?: boolean +): Promise => { + const instance = await deployContract(deployer, factoryPath); + if (needInit) { + await (await instance.init()).wait(1); + } + return instance; +}; + +describe('BSCValidatorSet', () => { + const unit = ethers.constants.WeiPerEther; + let instances: any[]; + + let relayerIncentivize: RelayerIncentivize; + let tendermintLightClient: TendermintLightClient; + let validatorSet: BSCValidatorSet; + let systemReward: SystemReward; + let slashIndicator: SlashIndicator; + let crosschain: CrossChain; + let relayerHub: RelayerHub; + let govHub: GovHub; + + let operator: SignerWithAddress; + let validators: string[]; + let relayerAccount: string; + let signers: SignerWithAddress[]; + + let maxNumOfMaintaining: number; + let maintainSlashScale: number; + before('before', async () => { + signers = await ethers.getSigners(); + log(signers.length); + operator = signers[0]; + relayerAccount = signers[1].address; + validators = signers.slice(0, 100).map((signer) => signer.address); + + const contractPaths = [ + { + name: 'RelayerIncentivize', // 0 + needInit: true, + needUpdate: true, + }, + { + name: 'TendermintLightClient', // 1 + needInit: true, + needUpdate: true, + }, + { + name: 'CrossChain', // 2 + needInit: false, + needUpdate: true, + }, + { + name: 'SystemReward', // 3 + needInit: false, + needUpdate: false, + }, + { + name: 'MockLightClient', // 4 + needInit: false, + needUpdate: false, + }, + { + name: 'TokenHub', // 5 + needInit: true, + needUpdate: true, + }, + { + name: 'TokenManager', // 6 + needInit: false, + needUpdate: true, + }, + { + name: 'RelayerHub', // 7 + needInit: true, + needUpdate: true, + }, + { + name: 'SlashIndicator', // 8 + needInit: true, + needUpdate: true, + }, + { + name: 'GovHub', // 9 + needInit: false, + needUpdate: true, + }, + { + name: 'BSCValidatorSet', // 10 + needInit: true, + needUpdate: true, + }, + ]; + instances = []; + for (let i = 0; i < contractPaths.length; i++) { + const pathObj = contractPaths[i]; + instances.push(await deployContractAndInit(operator, pathObj.name, pathObj.needInit)); + } + + for (let i = 0; i < contractPaths.length; i++) { + const pathObj = contractPaths[i]; + const instance = instances[i]; + + if (!pathObj.needUpdate) { + continue; + } + + let crosschainAddress = instances[2].address; + if (pathObj.name === 'BSCValidatorSet' || pathObj.name === 'GovHub') { + crosschainAddress = operator.address; + } + + await waitTx( + instance.updateContractAddr( + instances[10].address, + instances[8].address, + instances[3].address, + instances[4].address, + instances[5].address, + instances[0].address, + instances[7].address, + instances[9].address, + instances[6].address, + crosschainAddress + ) + ); + } + + relayerIncentivize = instances[0]; + tendermintLightClient = instances[1]; + + systemReward = instances[3] as SystemReward; + slashIndicator = instances[8] as SlashIndicator; + await waitTx(systemReward.addOperator(operator.address)); + await waitTx(systemReward.addOperator(tendermintLightClient.address)); + await waitTx(systemReward.addOperator(relayerIncentivize.address)); + + validatorSet = instances[10] as BSCValidatorSet; + relayerHub = instances[7] as RelayerHub; + + crosschain = instances[2] as CrossChain; + await waitTx(crosschain.init()); + + govHub = instances[9] as GovHub; + }); + + beforeEach('beforeEach', async () => {}); + + it('query code size', async () => { + const code = await ethers.provider.getCode(validatorSet.address) + const codeSize = (code.length - 2) / 2 + log(`BSCValidatorSet Mock Template code size: ${codeSize}, UpperLimit: 24567` ) + }); + + it('update validators', async () => { + // do update validators + let packageBytes = validatorUpdateRlpEncode( + validators.slice(1, 22), + validators.slice(1, 22), + validators.slice(1, 22) + ); + + await waitTx(validatorSet.connect(operator).handleSynPackage(STAKE_CHANNEL_ID, packageBytes)); + }); + + it('query all view func', async () => { + expect(await validatorSet.getValidators()).to.deep.eq(validators.slice(1, 22)); + for (let i = 1; i < 50; i++) { + const currentValidatorSetIndex = i - 1 + if (i >= 1 && i < 22) { + expect(await validatorSet.isWorkingValidator(currentValidatorSetIndex)).to.deep.eq(true); + expect(await validatorSet.isCurrentValidator(validators[i])).to.deep.eq(true); + expect(await validatorSet.canEnterMaintenance(validators[i])).to.deep.eq(false); + } else { + expect(await validatorSet.isWorkingValidator(currentValidatorSetIndex)).to.be.eq(false); + expect(await validatorSet.isCurrentValidator(validators[i])).to.deep.eq(false); + expect(await validatorSet.canEnterMaintenance(validators[i])).to.deep.eq(false); + } + expect(await validatorSet.getIncoming(validators[i])).to.deep.eq(0); + } + + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([]); + expect(await validatorSet.numOfMaintaining()).to.be.eq(0); + + }); + + it('common case 1-1 update params', async () => { + await waitTx(relayerHub.connect(operator).register({ value: unit.mul(100) })); + await waitTx( + govHub.updateContractAddr( + instances[10].address, + instances[8].address, + instances[3].address, + instances[4].address, + instances[5].address, + instances[0].address, + instances[7].address, + instances[9].address, + instances[6].address, + instances[2].address + ) + ); + + // set maxNumOfMaintaining to 5 + let govChannelSeq = await crosschain.channelReceiveSequenceMap(GOV_CHANNEL_ID); + maxNumOfMaintaining = 5; + let govValue = '0x0000000000000000000000000000000000000000000000000000000000000005'; // 5; + let govPackageBytes = serializeGovPack('maxNumOfMaintaining', govValue, validatorSet.address); + await crosschain + .connect(operator) + .handlePackage( + Buffer.concat([buildSyncPackagePrefix(2e16), govPackageBytes]), + proof, + merkleHeight, + govChannelSeq, + GOV_CHANNEL_ID + ); + expect(await validatorSet.maxNumOfMaintaining()).to.be.eq(BigNumber.from(govValue)); + + // set maintainSlashScale to 2 + govChannelSeq = await crosschain.channelReceiveSequenceMap(GOV_CHANNEL_ID); + maintainSlashScale = 2; + govValue = '0x0000000000000000000000000000000000000000000000000000000000000002'; // 2; + govPackageBytes = serializeGovPack('maintainSlashScale', govValue, validatorSet.address); + await crosschain + .connect(operator) + .handlePackage( + Buffer.concat([buildSyncPackagePrefix(2e16), govPackageBytes]), + proof, + merkleHeight, + govChannelSeq, + GOV_CHANNEL_ID + ); + expect(await validatorSet.maintainSlashScale()).to.be.eq(BigNumber.from(govValue)); + expect(await validatorSet.numOfMaintaining()).to.be.eq(0); + }); + + it('common case 1-2: validator-1 enterMaintenance', async () => { + await waitTx(validatorSet.connect(signers[1]).enterMaintenance()); + const maintainingValidators = await validatorSet.getMaintainingValidators() + expect(maintainingValidators).to.deep.eq([validators[1]]); + }); + + it('common case 1-3: validator-2 enterMaintenance', async () => { + await waitTx(validatorSet.connect(signers[2]).enterMaintenance()); + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ + validators[1], + validators[2], + ]); + expect(await validatorSet.numOfMaintaining()).to.be.eq(2); + }); + + it('common case 1-4: validator-3 misdemeanor, enterMaintenance', async () => { + await setSlashIndicator(operator.address, validatorSet, instances); + + await validatorSet.connect(operator).misdemeanor(validators[3]); + + const index = await validatorSet.getCurrentValidatorIndex(validators[3]); + const validatorExtra = await validatorSet.validatorExtraSet(index); + + expect(validatorExtra.isMaintaining).to.be.eq(true); + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ + validators[1], + validators[2], + validators[3], + ]); + expect(await validatorSet.numOfMaintaining()).to.be.eq(3); + }); + + it('common case 1-5: validator-2 exitMaintenance', async () => { + await setSlashIndicator(slashIndicator.address, validatorSet, instances); + + await waitTx(validatorSet.connect(signers[2]).exitMaintenance()); + const index = await validatorSet.getCurrentValidatorIndex(validators[2]); + const validatorExtra = await validatorSet.validatorExtraSet(index); + + expect(validatorExtra.isMaintaining).to.be.eq(false); + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ + validators[1], + validators[3], + ]); + expect(await validatorSet.numOfMaintaining()).to.be.eq(2); + }); + + it('common case 1-6: validator-4 misdemeanor, enterMaintenance', async () => { + await setSlashIndicator(operator.address, validatorSet, instances); + + await validatorSet.connect(operator).misdemeanor(validators[4]); + const index = await validatorSet.getCurrentValidatorIndex(validators[4]); + const validatorExtra = await validatorSet.validatorExtraSet(index); + + + expect(validatorExtra.isMaintaining).to.be.eq(true); + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ + validators[1], + validators[3], + validators[4], + ]); + expect(await validatorSet.numOfMaintaining()).to.be.eq(3); + }); + + it('common case 1-7: validator-5 misdemeanor, enterMaintenance', async () => { + await validatorSet.connect(operator).misdemeanor(validators[5]); + const index = await validatorSet.getCurrentValidatorIndex(validators[5]); + const validatorExtra = await validatorSet.validatorExtraSet(index); + + expect(validatorExtra.isMaintaining).to.be.eq(true); + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ + validators[1], + validators[3], + validators[4], + validators[5], + ]); + expect(await validatorSet.numOfMaintaining()).to.be.eq(4); + + }); + + it('common case 1-8: validator-6 enterMaintenance', async () => { + await setSlashIndicator(slashIndicator.address, validatorSet, instances); + + await waitTx(validatorSet.connect(signers[6]).enterMaintenance()); + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ + validators[1], + validators[3], + validators[4], + validators[5], + validators[6], + ]); + expect(await validatorSet.numOfMaintaining()).to.be.eq(5); + + }); + + it('common case 1-9: validator-7 enterMaintenance failed!', async () => { + expect(validatorSet.connect(signers[7]).enterMaintenance()).to.be.revertedWith( + 'can not enter Temporary Maintenance' + ); + expect(await validatorSet.numOfMaintaining()).to.be.eq(5); + }); + + it('common case 1-10: validator-7 misdemeanor, enterMaintenance failed!', async () => { + await setSlashIndicator(operator.address, validatorSet, instances); + + await validatorSet.connect(operator).misdemeanor(validators[7]); + const index = await validatorSet.getCurrentValidatorIndex(validators[7]); + const validatorExtra = await validatorSet.validatorExtraSet(index); + + expect(validatorExtra.isMaintaining).to.be.eq(false); + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ + validators[1], + validators[3], + validators[4], + validators[5], + validators[6], + ]); + expect(await validatorSet.numOfMaintaining()).to.be.eq(5); + }); + + it('common case 1-11: validator-1 exitMaintenance', async () => { + await setSlashIndicator(slashIndicator.address, validatorSet, instances); + + await waitTx(validatorSet.connect(signers[1]).exitMaintenance()); + const index = await validatorSet.getCurrentValidatorIndex(validators[1]); + const validatorExtra = await validatorSet.validatorExtraSet(index); + + expect(validatorExtra.isMaintaining).to.be.eq(false); + expect(validatorExtra.enterMaintenanceHeight.toNumber() > 0).to.be.eq(true); + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ + validators[3], + validators[4], + validators[5], + validators[6], + ]); + expect(await validatorSet.numOfMaintaining()).to.be.eq(4); + }); + + it('common case 1-12: validator-1 misdemeanor, enterMaintenance failed!', async () => { + await setSlashIndicator(operator.address, validatorSet, instances); + + await validatorSet.connect(operator).misdemeanor(validators[1]); + const index = await validatorSet.getCurrentValidatorIndex(validators[1]); + const validatorExtra = await validatorSet.validatorExtraSet(index); + + expect(validatorExtra.isMaintaining).to.be.eq(false); + expect(validatorExtra.enterMaintenanceHeight.toNumber() > 0).to.be.eq(true); + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ + validators[3], + validators[4], + validators[5], + validators[6], + ]); + expect(await validatorSet.numOfMaintaining()).to.be.eq(4); + }); + + it('common case 1-13: validator-8 enterMaintenance', async () => { + await mineBlocks(21 * 100 * maintainSlashScale); + + await setSlashIndicator(slashIndicator.address, validatorSet, instances); + + await waitTx(validatorSet.connect(signers[8]).enterMaintenance()); + + const index = await validatorSet.getCurrentValidatorIndex(validators[8]); + const validatorExtra = await validatorSet.validatorExtraSet(index); + + expect(validatorExtra.isMaintaining).to.be.eq(true); + expect(validatorExtra.enterMaintenanceHeight.toNumber() > 0).to.be.eq(true); + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ + validators[3], + validators[4], + validators[5], + validators[6], + validators[8], + ]); + expect(await validatorSet.numOfMaintaining()).to.be.eq(5); + }); + + it('common case 1-14: validator-9 enterMaintenance failed!', async () => { + expect(validatorSet.connect(signers[9]).enterMaintenance()).to.be.revertedWith( + 'can not enter Temporary Maintenance' + ); + }); + + it('common case 1-15: validator-1 felony', async () => { + let index = await validatorSet.currentValidatorSetMap(validators[1]); + expect(index.toNumber() > 0).to.be.eq(true); + + await setSlashIndicator(operator.address, validatorSet, instances); + await validatorSet.connect(operator).felony(validators[1]); + + index = await validatorSet.currentValidatorSetMap(validators[1]); + expect(index.toNumber() === 0).to.be.eq(true); + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ + validators[3], + validators[4], + validators[5], + validators[6], + validators[8], + ]); + expect(await validatorSet.numOfMaintaining()).to.be.eq(5); + }); + + it('common case 1-16: validator-2 enterMaintenance failed!', async () => { + expect(validatorSet.connect(signers[2]).enterMaintenance()).to.be.revertedWith( + 'can not enter Temporary Maintenance' + ); + }); + + it('common case 1-17: validator-4 exitMaintenance', async () => { + await setSlashIndicator(slashIndicator.address, validatorSet, instances); + + await waitTx(validatorSet.connect(signers[4]).exitMaintenance()); + const index = await validatorSet.getCurrentValidatorIndex(validators[4]); + const validatorExtra = await validatorSet.validatorExtraSet(index); + + expect(validatorExtra.isMaintaining).to.be.eq(false); + expect(validatorExtra.enterMaintenanceHeight.toNumber() > 0).to.be.eq(true); + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ + validators[3], + validators[5], + validators[6], + validators[8], + ]); + expect(await validatorSet.numOfMaintaining()).to.be.eq(4); + }); + + it('common case 1-18: validator-2 enterMaintenance failed!', async () => { + expect(validatorSet.connect(signers[2]).enterMaintenance()).to.be.revertedWith( + 'can not enter Temporary Maintenance' + ); + }); + + it('common case 1-19: validator-2 misdemeanor, enterMaintenance failed!', async () => { + await setSlashIndicator(operator.address, validatorSet, instances); + await validatorSet.connect(operator).misdemeanor(validators[2]); + const index = await validatorSet.getCurrentValidatorIndex(validators[2]); + const validatorExtra = await validatorSet.validatorExtraSet(index); + + expect(validatorExtra.isMaintaining).to.be.eq(false); + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ + validators[3], + validators[5], + validators[6], + validators[8], + ]); + expect(await validatorSet.numOfMaintaining()).to.be.eq(4); + }); + + it('common case 1-20: validator-10 enterMaintenance', async () => { + await setSlashIndicator(slashIndicator.address, validatorSet, instances); + + await waitTx(validatorSet.connect(signers[10]).enterMaintenance()); + + const index = await validatorSet.getCurrentValidatorIndex(validators[10]); + const validatorExtra = await validatorSet.validatorExtraSet(index); + + expect(validatorExtra.isMaintaining).to.be.eq(true); + expect(validatorExtra.enterMaintenanceHeight.toNumber() > 0).to.be.eq(true); + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ + validators[3], + validators[5], + validators[6], + validators[8], + validators[10], + ]); + expect(await validatorSet.numOfMaintaining()).to.be.eq(5); + }); + + it('common case 1-21: validator-3 exitMaintenance', async () => { + await setSlashIndicator(slashIndicator.address, validatorSet, instances); + + await waitTx(validatorSet.connect(signers[3]).exitMaintenance()); + const index = await validatorSet.getCurrentValidatorIndex(validators[3]); + const validatorExtra = await validatorSet.validatorExtraSet(index); + + expect(validatorExtra.isMaintaining).to.be.eq(false); + expect(validatorExtra.enterMaintenanceHeight.toNumber() > 0).to.be.eq(true); + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ + validators[5], + validators[6], + validators[8], + validators[10], + ]); + expect(await validatorSet.numOfMaintaining()).to.be.eq(4); + }); + + it('common case 1-22: validator-4 exitMaintenance', async () => { + await setSlashIndicator(slashIndicator.address, validatorSet, instances); + expect(validatorSet.connect(signers[4]).exitMaintenance()).to.revertedWith( + 'not in maintenance' + ); + }); + + it('common case 1-23: validator-4 enterMaintenance failed!', async () => { + expect(validatorSet.connect(signers[4]).enterMaintenance()).to.be.revertedWith( + 'can not enter Temporary Maintenance' + ); + }); + + it('common case 1-24: 24 hours ended, clear all maintainInfo', async () => { + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ + validators[5], + validators[6], + validators[8], + validators[10], + ]); + expect(await validatorSet.numOfMaintaining()).to.be.eq(4); + + await waitTx( + validatorSet.updateContractAddr( + instances[10].address, + instances[8].address, + instances[3].address, + instances[4].address, + instances[5].address, + instances[0].address, + instances[7].address, + instances[9].address, + instances[6].address, + operator.address + ) + ); + + await mineBlocks(21 * 50 * maintainSlashScale); + + // do update validators + let packageBytes = validatorUpdateRlpEncode( + validators.slice(2, 23), + validators.slice(2, 23), + validators.slice(2, 23) + ); + await waitTx(validatorSet.connect(operator).handleSynPackage(STAKE_CHANNEL_ID, packageBytes)); + + // validator-5,6 felony, validator-8 misdemeanor + const expectedValidators = validators + .slice(2, 23) + .filter((item) => item !== validators[5] && item !== validators[6]); + expect(await validatorSet.getValidators()).to.deep.eq(expectedValidators); + expect(await validatorSet.numOfMaintaining()).to.be.eq(0); + + for (let i = 2; i < 23; i++) { + if (i === 5 || i === 6) { + // because of felony, validator-5,6 are not the current validators + expect(validatorSet.getCurrentValidatorIndex(validators[i])).to.be.revertedWith( + 'only current validators' + ); + continue; + } + const index = await validatorSet.getCurrentValidatorIndex(validators[i]); + const validatorExtra = await validatorSet.validatorExtraSet(index); + + expect(validatorExtra.isMaintaining).to.be.eq(false); + expect(validatorExtra.enterMaintenanceHeight.toNumber() === 0).to.be.eq(true); + } + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([]); + }); + + + it('common case 1-25: query all view func', async () => { + expect(await validatorSet.maxNumOfMaintaining()).to.be.eq(maxNumOfMaintaining) + expect(await validatorSet.maintainSlashScale()).to.be.eq(maintainSlashScale) + expect(await validatorSet.numOfMaintaining()).to.be.eq(0); + + for (let i = 2; i < 50; i++) { + if (i >= 2 && i < 23 && i !== 5 && i !== 6) { + expect(await validatorSet.isCurrentValidator(validators[i])).to.deep.eq(true); + } else { + expect(await validatorSet.isCurrentValidator(validators[i])).to.deep.eq(false); + } + expect(await validatorSet.getIncoming(validators[i])).to.deep.eq(0); + } + + expect(await validatorSet.getMaintainingValidators()).to.deep.eq([]); + }); + + + it('common case 2-1 update params', async () => { + await waitTx( + govHub.updateContractAddr( + instances[10].address, + instances[8].address, + instances[3].address, + instances[4].address, + instances[5].address, + instances[0].address, + instances[7].address, + instances[9].address, + instances[6].address, + instances[2].address + ) + ); + + // set maxNumOfMaintaining to 5 + let govChannelSeq = await crosschain.channelReceiveSequenceMap(GOV_CHANNEL_ID); + maxNumOfMaintaining = 18; + let govValue = '0x0000000000000000000000000000000000000000000000000000000000000012'; // 18 + let govPackageBytes = serializeGovPack('maxNumOfMaintaining', govValue, validatorSet.address); + await crosschain + .connect(operator) + .handlePackage( + Buffer.concat([buildSyncPackagePrefix(2e16), govPackageBytes]), + proof, + merkleHeight, + govChannelSeq, + GOV_CHANNEL_ID + ); + expect(await validatorSet.maxNumOfMaintaining()).to.be.eq(BigNumber.from(govValue)); + + // set maintainSlashScale to 2 + govChannelSeq = await crosschain.channelReceiveSequenceMap(GOV_CHANNEL_ID); + maintainSlashScale = 1; + govValue = '0x0000000000000000000000000000000000000000000000000000000000000001'; // 1 + govPackageBytes = serializeGovPack('maintainSlashScale', govValue, validatorSet.address); + await crosschain + .connect(operator) + .handlePackage( + Buffer.concat([buildSyncPackagePrefix(2e16), govPackageBytes]), + proof, + merkleHeight, + govChannelSeq, + GOV_CHANNEL_ID + ); + expect(await validatorSet.maintainSlashScale()).to.be.eq(BigNumber.from(govValue)); + expect(await validatorSet.numOfMaintaining()).to.be.eq(0); + }); + + + it('common case 2-2: validator 7 ~ 10 enterMaintenance', async () => { + await setSlashIndicator(slashIndicator.address, validatorSet, instances); + + for (let i = 7; i < 10; i++) { + await waitTx(validatorSet.connect(signers[i]).enterMaintenance()); + } + + const expectedMaintainingValidators = [] + + for (let i = 7; i < 10; i++) { + const index = await validatorSet.getCurrentValidatorIndex(validators[i]); + const validatorExtra = await validatorSet.validatorExtraSet(index); + expect(validatorExtra.isMaintaining).to.be.eq(true); + expect(validatorExtra.enterMaintenanceHeight.toNumber() > 0).to.be.eq(true); + expectedMaintainingValidators.push(validators[i]); + } + + + expect(await validatorSet.getMaintainingValidators()).to.deep.eq(expectedMaintainingValidators); + expect(await validatorSet.numOfMaintaining()).to.be.eq(3); + + const felonyThreshold = (await slashIndicator.felonyThreshold()).toNumber(); + await mineBlocks( 4 * felonyThreshold * maintainSlashScale / 2); + }); + + + it('common case 2-3: validator 10 ~ 21 enterMaintenance', async () => { + await setSlashIndicator(slashIndicator.address, validatorSet, instances); + + for (let i = 10; i < 22; i++) { + await waitTx(validatorSet.connect(signers[i]).enterMaintenance()); + } + + const expectedMaintainingValidators = [] + for (let i = 7; i < 10; i++) { + expectedMaintainingValidators.push(validators[i]); + } + + for (let i = 10; i < 22; i++) { + const index = await validatorSet.getCurrentValidatorIndex(validators[i]); + const validatorExtra = await validatorSet.validatorExtraSet(index); + expect(validatorExtra.isMaintaining).to.be.eq(true); + expect(validatorExtra.enterMaintenanceHeight.toNumber() > 0).to.be.eq(true); + expectedMaintainingValidators.push(validators[i]); + } + + expect(await validatorSet.getMaintainingValidators()).to.deep.eq(expectedMaintainingValidators); + expect(await validatorSet.numOfMaintaining()).to.be.eq(15); + + const felonyThreshold = (await slashIndicator.felonyThreshold()).toNumber(); + await mineBlocks( 4 * felonyThreshold * maintainSlashScale / 2 + 1); + }); + + it('common case 2-4: update validator set', async () => { + await waitTx( + validatorSet.updateContractAddr( + instances[10].address, + instances[8].address, + instances[3].address, + instances[4].address, + instances[5].address, + instances[0].address, + instances[7].address, + instances[9].address, + instances[6].address, + operator.address + ) + ); + + // do update validators + let packageBytes = validatorUpdateRlpEncode( + validators.slice(5, 26), + validators.slice(5, 26), + validators.slice(5, 26), + ); + await waitTx(validatorSet.connect(operator).handleSynPackage(STAKE_CHANNEL_ID, packageBytes)); + + // validator 7 ~ 9 will be felony, their slashCount = 4 * felonyThreshold * maintainSlashScale / workingValidatorCount(4) + const expectedValidators: string[] = [validators[5], validators[6]].concat(validators.slice(10, 26)); + + expect(await validatorSet.getValidators()).to.deep.eq(expectedValidators); + expect(await validatorSet.numOfMaintaining()).to.be.eq(0); + }); + +}); From fec8e9dfa00be1c68d660c74a58323c3615af11b Mon Sep 17 00:00:00 2001 From: Roshan Date: Mon, 16 Jan 2023 20:04:49 +0800 Subject: [PATCH 09/15] fix: recover deleted verifyBLSSignature function call --- contracts/SlashIndicator.sol | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contracts/SlashIndicator.sol b/contracts/SlashIndicator.sol index 3c524e75..ba689cf6 100644 --- a/contracts/SlashIndicator.sol +++ b/contracts/SlashIndicator.sol @@ -224,6 +224,9 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication } require(valAddr != address(0), "validator not exist"); + require(verifyBLSSignature(_evidence.voteA, _evidence.voteAddr) && + verifyBLSSignature(_evidence.voteB, _evidence.voteAddr), "verify signature failed"); + uint256 amount = (address(SYSTEM_REWARD_ADDR).balance * finalitySlashRewardRatio) / 100; ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(msg.sender, amount); IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).felony(valAddr); From 92093b1c10da1b6ca30274586974c152244015be Mon Sep 17 00:00:00 2001 From: Roshan Date: Mon, 16 Jan 2023 20:11:27 +0800 Subject: [PATCH 10/15] fix: revert modification for local unit test --- contracts/BSCValidatorSet.sol | 24 ++++++++++++------------ contracts/SlashIndicator.template | 2 +- contracts/System.sol | 2 +- contracts/TendermintLightClient.sol | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/contracts/BSCValidatorSet.sol b/contracts/BSCValidatorSet.sol index b0012752..c5011d3a 100644 --- a/contracts/BSCValidatorSet.sol +++ b/contracts/BSCValidatorSet.sol @@ -423,7 +423,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica function getLivingValidators() external view override returns (address[] memory, bytes[] memory) { uint n = currentValidatorSet.length; uint living = 0; - for (uint i = 0; in) { - ValidatorExtra memory validatorExtra; - for (uint i = n; i Date: Mon, 16 Jan 2023 20:42:32 +0800 Subject: [PATCH 11/15] fix: errors with template --- contracts/BSCValidatorSet.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/BSCValidatorSet.template b/contracts/BSCValidatorSet.template index bf970421..ab2dca2f 100644 --- a/contracts/BSCValidatorSet.template +++ b/contracts/BSCValidatorSet.template @@ -532,7 +532,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } uint256 totalWeight; - for (uint256 i = 0; i < weights.length; i++) { + for (uint256 i; i < weights.length; ++i) { totalWeight += weights[i]; } if (totalWeight == 0) { From 26385f1f911431935ad72f6ccbb2f7b537a051e7 Mon Sep 17 00:00:00 2001 From: Roshan Date: Fri, 24 Mar 2023 15:44:32 +0800 Subject: [PATCH 12/15] fix rebase errors --- contracts/BSCValidatorSet.sol | 44 +- contracts/BSCValidatorSet.template | 151 +++--- contracts/SlashIndicator.sol | 10 +- contracts/SlashIndicator.template | 36 +- contracts/SystemReward.sol | 20 +- contracts/SystemReward.template | 57 +-- lib/RLPDecode.sol | 8 +- lib/RLPEncode.sol | 6 +- lib/interface/ISystemReward.sol | 3 +- test/Slash.js | 580 --------------------- test/SystemReward.t.sol | 8 +- test/ValidatorSet.t.sol | 2 +- test/slash.ts | 784 ----------------------------- 13 files changed, 200 insertions(+), 1509 deletions(-) delete mode 100644 test/Slash.js delete mode 100644 test/slash.ts diff --git a/contracts/BSCValidatorSet.sol b/contracts/BSCValidatorSet.sol index c5011d3a..3b4373ed 100644 --- a/contracts/BSCValidatorSet.sol +++ b/contracts/BSCValidatorSet.sol @@ -55,7 +55,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica uint256 public constant BURN_RATIO_SCALE = 10000; address public constant BURN_ADDRESS = 0x000000000000000000000000000000000000dEaD; - uint256 public constant INIT_BURN_RATIO = 0; + uint256 public constant INIT_BURN_RATIO = 1000; uint256 public burnRatio; bool public burnRatioInitialized; @@ -299,9 +299,9 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica uint validatorsNum = currentValidatorSet.length; for (uint i; i= DUSTY_INCOMING) { - --crossSize; + ++crossSize; } else if (currentValidatorSet[i].incoming > 0) { - --directSize; + ++directSize; } } @@ -329,11 +329,11 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica crossRefundAddrs[crossSize] = currentValidatorSet[i].BBCFeeAddress; crossIndexes[crossSize] = i; crossTotal = crossTotal.add(value); - --crossSize; + ++crossSize; } else if (currentValidatorSet[i].incoming > 0) { directAddrs[directSize] = currentValidatorSet[i].feeAddress; directAmounts[directSize] = currentValidatorSet[i].incoming; - --directSize; + ++directSize; } } @@ -422,8 +422,8 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica */ function getLivingValidators() external view override returns (address[] memory, bytes[] memory) { uint n = currentValidatorSet.length; - uint living = 0; - for (uint i=0; i 0, "the maintainSlashScale must be greater than 0"); + require(newMaintainSlashScale > 0 && newMaintainSlashScale < 10, "the maintainSlashScale must be greater than 0 and less than 10"); maintainSlashScale = newMaintainSlashScale; } else if (Memory.compareStrings(key, "maxNumOfWorkingCandidates")) { require(value.length == 32, "length of maxNumOfWorkingCandidates mismatch"); @@ -739,7 +739,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica for (uint i; in) { - ValidatorExtra memory _validatorExtra; - for (uint i = n; i < m; i++) { - _validatorExtra.voteAddress = voteAddrs[i]; + ValidatorExtra memory validatorExtra; + for (uint i=n; i < m; ++i) { + validatorExtra.voteAddress = voteAddrs[i]; currentValidatorSet.push(validatorSet[i]); - validatorExtraSet.push(_validatorExtra); + validatorExtraSet.push(validatorExtra); currentValidatorSetMap[validatorSet[i].consensusAddress] = i+1; } } @@ -1012,7 +1012,6 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica success = true; } else if (idx == 4) { voteAddr = iter.next().toBytes(); - success = true; } else { break; } @@ -1021,5 +1020,4 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica return (validator, voteAddr, success); } - } diff --git a/contracts/BSCValidatorSet.template b/contracts/BSCValidatorSet.template index ab2dca2f..1ae539f7 100644 --- a/contracts/BSCValidatorSet.template +++ b/contracts/BSCValidatorSet.template @@ -122,7 +122,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica ValidatorExtra memory validatorExtra; // init validatorExtraSet uint256 validatorsNum = currentValidatorSet.length; - for (uint i; i < validatorsNum; ++i) { + for (uint i; i= DUSTY_INCOMING) { - crossSize ++; + ++crossSize; } else if (currentValidatorSet[i].incoming > 0) { - directSize ++; + ++directSize; } } @@ -315,7 +321,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica emit failReasonWithStr("fee is larger than DUSTY_INCOMING"); return ERROR_RELAYFEE_TOO_LARGE; } - for (uint i; i < validatorsNum; ++i) { + for (uint i; i= DUSTY_INCOMING) { crossAddrs[crossSize] = currentValidatorSet[i].BBCFeeAddress; uint256 value = currentValidatorSet[i].incoming - currentValidatorSet[i].incoming % PRECISION; @@ -323,11 +329,11 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica crossRefundAddrs[crossSize] = currentValidatorSet[i].BBCFeeAddress; crossIndexes[crossSize] = i; crossTotal = crossTotal.add(value); - crossSize ++; + ++crossSize; } else if (currentValidatorSet[i].incoming > 0) { directAddrs[directSize] = currentValidatorSet[i].feeAddress; directAmounts[directSize] = currentValidatorSet[i].incoming; - directSize ++; + ++directSize; } } @@ -350,7 +356,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } if (failCross) { - for (uint i; i< crossIndexes.length;++i) { + for (uint i; i0) { - for (uint i;i 0, "the maintainSlashScale must be greater than 0"); + require(newMaintainSlashScale > 0 && newMaintainSlashScale < 10, "the maintainSlashScale must be greater than 0 and less than 10"); maintainSlashScale = newMaintainSlashScale; } else if (Memory.compareStrings(key, "maxNumOfWorkingCandidates")) { require(value.length == 32, "length of maxNumOfWorkingCandidates mismatch"); @@ -710,24 +736,37 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica uint n = currentValidatorSet.length; uint m = validatorSet.length; - for (uint i; i < n; ++i) { + for (uint i; im) { - for (uint i = m; i < n; ++i) { + for (uint i=m; in) { ValidatorExtra memory _validatorExtra; @@ -743,12 +782,16 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica // should not happen, still protect numOfMaintaining = 0; n = currentValidatorSet.length; - for (uint i; i < n; ++i) { + for (uint i; i felonyThreshold/DECREASE_RATE){ leftIndicator.count = leftIndicator.count - felonyThreshold/DECREASE_RATE; @@ -161,7 +161,7 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication break; } } - for(; i<=j ; --j){ + for( ; i<=j; --j){ Indicator memory rightIndicator = indicators[validators[j]]; if(rightIndicator.count > felonyThreshold/DECREASE_RATE){ rightIndicator.count = rightIndicator.count - felonyThreshold/DECREASE_RATE; diff --git a/contracts/SlashIndicator.template b/contracts/SlashIndicator.template index 3f1f5613..a3ecf96f 100644 --- a/contracts/SlashIndicator.template +++ b/contracts/SlashIndicator.template @@ -46,6 +46,8 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication event unKnownResponse(uint32 code); event crashResponse(); + event failedFelony(address indexed validator, uint256 slashCount, bytes failReason); + struct Indicator { uint256 height; uint256 count; @@ -112,13 +114,18 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication } /*********************** External func ********************************/ + /** + * @dev Slash the validator who should have produced the current block + * + * @param validator The validator who should have produced the current block + */ function slash(address validator) external onlyCoinbase onlyInit oncePerBlock onlyZeroGasPrice{ if (!IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).isCurrentValidator(validator)) { return; } Indicator memory indicator = indicators[validator]; if (indicator.exist) { - indicator.count++; + ++indicator.count; } else { indicator.exist = true; indicator.count = 1; @@ -128,7 +135,9 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication if (indicator.count % felonyThreshold == 0) { indicator.count = 0; IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).felony(validator); - ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeSlashPackage(validator), 0); + try ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeSlashPackage(validator), 0) {} catch (bytes memory reason) { + emit failedFelony(validator, indicator.count, reason); + } } else if (indicator.count % misdemeanorThreshold == 0) { IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).misdemeanor(validator); } @@ -139,15 +148,15 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication // To prevent validator misbehaving and leaving, do not clean slash record to zero, but decrease by felonyThreshold/DECREASE_RATE . // Clean is an effective implement to reorganize "validators" and "indicators". function clean() external override(ISlashIndicator) onlyValidatorContract onlyInit{ - if(validators.length == 0){ + if (validators.length == 0) { return; } - uint i = 0; + uint i; uint j = validators.length-1; - for (;i <= j;) { + for ( ; i<=j; ) { bool findLeft = false; bool findRight = false; - for(;i felonyThreshold/DECREASE_RATE){ leftIndicator.count = leftIndicator.count - felonyThreshold/DECREASE_RATE; @@ -157,7 +166,7 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication break; } } - for(;i<=j;j--){ + for( ; i<=j; --j){ Indicator memory rightIndicator = indicators[validators[j]]; if(rightIndicator.count > felonyThreshold/DECREASE_RATE){ rightIndicator.count = rightIndicator.count - felonyThreshold/DECREASE_RATE; @@ -184,8 +193,8 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication break; } // move to next - i++; - j--; + ++i; + --j; } emit indicatorCleaned(); } @@ -219,10 +228,10 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication } } require(valAddr != address(0), "validator not exist"); -{% if mock %}{% else %} + require(verifyBLSSignature(_evidence.voteA, _evidence.voteAddr) && verifyBLSSignature(_evidence.voteB, _evidence.voteAddr), "verify signature failed"); -{% endif %} + uint256 amount = (address(SYSTEM_REWARD_ADDR).balance * finalitySlashRewardRatio) / 100; ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(msg.sender, amount); IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).felony(valAddr); @@ -230,6 +239,11 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication emit validatorSlashed(valAddr); } + /** + * @dev Send a felony cross-chain package to jail a validator + * + * @param validator Who will be jailed + */ function sendFelonyPackage(address validator) external override(ISlashIndicator) onlyValidatorContract onlyInit { ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeSlashPackage(validator), 0); } diff --git a/contracts/SystemReward.sol b/contracts/SystemReward.sol index 34c1f406..7669d23f 100644 --- a/contracts/SystemReward.sol +++ b/contracts/SystemReward.sol @@ -29,7 +29,8 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { event rewardTo(address indexed to, uint256 amount); event rewardEmpty(); event receiveDeposit(address indexed from, uint256 amount); - event updateOperator(address indexed operator); + event addOperator(address indexed operator); + event deleteOperator(address indexed operator); event paramChange(string key, bytes value); receive() external payable{ @@ -38,7 +39,7 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { } } - function claimRewards(address payable to, uint256 amount) external override(ISystemReward) doInit onlyOperator returns(uint256) { + 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) { actualAmount = MAX_REWARDS; @@ -57,15 +58,24 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { } function updateParam(string calldata key, bytes calldata value) onlyGov external override { - if (Memory.compareStrings(key, "updateOperator")) { + if (Memory.compareStrings(key, "addOperator")) { bytes memory valueLocal = value; - require(valueLocal.length == 20, "length of value for updateOperator should be 20"); + require(valueLocal.length == 20, "length of value for addOperator should be 20"); address operatorAddr; assembly { operatorAddr := mload(add(valueLocal, 20)) } operators[operatorAddr] = true; - emit updateOperator(operatorAddr); + emit addOperator(operatorAddr); + } else if (Memory.compareStrings(key, "deleteOperator")) { + bytes memory valueLocal = value; + require(valueLocal.length == 20, "length of value for deleteOperator should be 20"); + address operatorAddr; + assembly { + operatorAddr := mload(add(valueLocal, 20)) + } + delete operators[operatorAddr]; + emit deleteOperator(operatorAddr); } else { require(false, "unknown param"); } diff --git a/contracts/SystemReward.template b/contracts/SystemReward.template index 2af14176..7669d23f 100644 --- a/contracts/SystemReward.template +++ b/contracts/SystemReward.template @@ -20,14 +20,17 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { } _; } -{% if mock %} - event newOperator(address indexed operator); - event deleteOperator(address indexed operator); - {% endif %} + + modifier onlyOperator() { + require(operators[msg.sender],"only operator is allowed to call the method"); + _; + } + event rewardTo(address indexed to, uint256 amount); event rewardEmpty(); event receiveDeposit(address indexed from, uint256 amount); - event updateOperator(address indexed operator); + event addOperator(address indexed operator); + event deleteOperator(address indexed operator); event paramChange(string key, bytes value); receive() external payable{ @@ -36,34 +39,7 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { } } - {% if mock %} - modifier onlyOperatorExist(address _operator) { - require(operators[_operator], "the operator do not exist"); - _; - } - - modifier onlyOperatorNotExist(address _operator) { - require(!operators[_operator],"the operator already exist"); - _; - } - - function addOperator(address operator) external doInit onlyOperatorNotExist(operator) { - operators[operator] = true; - ++numOperator; - emit newOperator(operator); - } - - function removeOperator(address operator) external doInit onlyOperatorExist(operator) { - delete operators[operator]; - --numOperator; - emit deleteOperator(operator); - } -{% endif %} - function claimRewards(address payable to, uint256 amount) external override(ISystemReward) doInit returns (uint256) { - if (!operators[msg.sender]) { - return 0; - } - + 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) { actualAmount = MAX_REWARDS; @@ -82,15 +58,24 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { } function updateParam(string calldata key, bytes calldata value) onlyGov external override { - if (Memory.compareStrings(key, "updateOperator")) { + if (Memory.compareStrings(key, "addOperator")) { bytes memory valueLocal = value; - require(valueLocal.length == 20, "length of value for updateOperator should be 20"); + require(valueLocal.length == 20, "length of value for addOperator should be 20"); address operatorAddr; assembly { operatorAddr := mload(add(valueLocal, 20)) } operators[operatorAddr] = true; - emit updateOperator(operatorAddr); + emit addOperator(operatorAddr); + } else if (Memory.compareStrings(key, "deleteOperator")) { + bytes memory valueLocal = value; + require(valueLocal.length == 20, "length of value for deleteOperator should be 20"); + address operatorAddr; + assembly { + operatorAddr := mload(add(valueLocal, 20)) + } + delete operators[operatorAddr]; + emit deleteOperator(operatorAddr); } else { require(false, "unknown param"); } diff --git a/lib/RLPDecode.sol b/lib/RLPDecode.sol index 69bcad8c..9ee71ffa 100644 --- a/lib/RLPDecode.sol +++ b/lib/RLPDecode.sol @@ -109,7 +109,11 @@ library RLPDecode { result := byte(0, mload(memPtr)) } - return result == 0 ? false : true; + if (result == 0 || result == STRING_SHORT_START) { + return false; + } else { + return true; + } } function toAddress(RLPItem memory item) internal pure returns (address) { @@ -272,4 +276,4 @@ library RLPDecode { mstore(dest, or(destpart, srcpart)) } } -} \ No newline at end of file +} diff --git a/lib/RLPEncode.sol b/lib/RLPEncode.sol index cc286dbc..423ef0b8 100644 --- a/lib/RLPEncode.sol +++ b/lib/RLPEncode.sol @@ -58,9 +58,7 @@ library RLPEncode { */ function encodeBool(bool self) internal pure returns (bytes memory) { bytes memory rs = new bytes(1); - if (self) { - rs[0] = bytes1(uint8(1)); - } + rs[0] = (self ? bytes1(0x01) : bytes1(0x80)); return rs; } @@ -213,4 +211,4 @@ library RLPEncode { } return rs; } -} \ No newline at end of file +} diff --git a/lib/interface/ISystemReward.sol b/lib/interface/ISystemReward.sol index b9884fa4..48f98080 100644 --- a/lib/interface/ISystemReward.sol +++ b/lib/interface/ISystemReward.sol @@ -5,7 +5,8 @@ interface SystemReward { event receiveDeposit(address indexed from, uint256 amount); event rewardEmpty(); event rewardTo(address indexed to, uint256 amount); - event updateOperator(address indexed operator); + event addOperator(address indexed operator); + event deleteOperator(address indexed operator); function BIND_CHANNELID() external view returns (uint8); function CODE_OK() external view returns (uint32); diff --git a/test/Slash.js b/test/Slash.js deleted file mode 100644 index 1d233a06..00000000 --- a/test/Slash.js +++ /dev/null @@ -1,580 +0,0 @@ -const SlashIndicator = artifacts.require("SlashIndicator"); -const BSCValidatorSet = artifacts.require("BSCValidatorSet"); -const Web3 = require('web3'); -const crypto = require('crypto'); -const RLP = require('rlp'); -const SystemReward = artifacts.require("SystemReward"); -const truffleAssert = require('truffle-assertions'); -const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')); -const STAKE_CHANNEL_ID = 0x08; - -contract('SlashIndicator', (accounts) => { - it('slash success', async () => { - const slashInstance = await SlashIndicator.deployed(); - const validatorInstance = await BSCValidatorSet.deployed(); - - const accountOne = accounts[0]; - - let validatorAccounts = (await validatorInstance.getMiningValidators.call())["0"]; - let validatorAccount = validatorAccounts[0]; - - for (let i =1; i<10; i++){ - await slashInstance.slash(validatorAccount, { from: accountOne }); - let res= (await slashInstance.getSlashIndicator.call(validatorAccount)); - let count =res[1].toNumber(); - assert.equal(count, i, "slash num is not correct"); - } - }); - - it('slash from no system account', async () => { - const slashInstance = await SlashIndicator.deployed(); - const validatorInstance = await BSCValidatorSet.deployed(); - - const nonSystemAccount = accounts[1]; - let validatorAccounts = (await validatorInstance.getMiningValidators.call())["0"]; - let validatorAccount = validatorAccounts[0]; - // first slash - try{ - await slashInstance.slash(validatorAccount, { from: nonSystemAccount }); - assert.fail(); - }catch (error) { - assert.ok(error.toString().includes("the message sender must be the block producer"), "slash from no system account should not be ok"); - } - }); -}); - -contract('SlashIndicator: isOperator works', (accounts) => { - it('isOperator works', async () => { - const slashInstance = await SlashIndicator.deployed(); - const validatorInstance = await BSCValidatorSet.deployed(); - - const accountOne = accounts[0]; - let validatorAccounts = (await validatorInstance.getMiningValidators.call())["0"]; - let validatorAccount = validatorAccounts[0]; - - // slash afterward - for (let i =1; i<10; i++){ - await slashInstance.slash(validatorAccount, { from: accountOne }); - let res= (await slashInstance.getSlashIndicator.call(validatorAccount)); - let count =res[1].toNumber(); - assert.equal(count, i, "slash num is not correct for validator"); - } - }); -}); - -contract('SlashIndicator: catch emit event', (accounts) => { - it('catch emit event', async () => { - const slashInstance = await SlashIndicator.deployed(); - const validatorInstance = await BSCValidatorSet.deployed(); - - const accountOne = accounts[0]; - let validatorAccounts = (await validatorInstance.getMiningValidators.call())["0"]; - let validatorAccount = validatorAccounts[0]; - for (let i =1; i<50; i++){ - let tx = await slashInstance.slash(validatorAccount, { from: accountOne }); - truffleAssert.eventEmitted(tx, "validatorSlashed",(ev) => { - return ev.validator === validatorAccount; - }); - } - }); -}); - -contract('SlashIndicator', (accounts) => { - it('trigger misdemeanor', async () => { - const slashInstance = await SlashIndicator.deployed(); - const validatorSetInstance = await BSCValidatorSet.deployed(); - const systemRewardInstance = await SystemReward.deployed(); - - const systemAccount = accounts[0]; - let validator = accounts[0]; - let secondValidator = accounts[1]; - let thirdValidator = accounts[2]; - - await validatorSetInstance.deposit(validator, {from: systemAccount, value: 1e18 }); - await systemRewardInstance.addOperator(validatorSetInstance.address, {from: systemAccount}); - - let amount = await validatorSetInstance.getIncoming.call(validator); - assert.equal(amount.toString(),web3.utils.toBN(1e18).toString()) - - for (let i =1; i<=50; i++){ - await slashInstance.slash(validator, { from: systemAccount }); - } - - amount = await validatorSetInstance.getIncoming.call(validator); - assert.equal(amount.toNumber(),0); - - let packageBytes = validatorUpdateRlpEncode([validator,secondValidator,thirdValidator], - [validator,secondValidator,thirdValidator],[validator,secondValidator,thirdValidator]); - await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: accounts[8]}); - - await validatorSetInstance.deposit(validator, {from: systemAccount, value: 2e18 }); - amount = await validatorSetInstance.getIncoming.call(validator); - assert.equal(amount.toString(),web3.utils.toBN(2e18).toString()) - for (let i =1; i<=4; i++){ - await slashInstance.slash(validator, { from: systemAccount }); - } - let res= (await slashInstance.getSlashIndicator.call(validator)); - assert.equal(res[1].toNumber(),50); - amount = await validatorSetInstance.getIncoming.call(validator); - assert.equal(amount.toNumber(),0); - amount = await validatorSetInstance.getIncoming.call(secondValidator); - assert.equal(amount.toString(),web3.utils.toBN(1e18).toString()) - amount = await validatorSetInstance.getIncoming.call(thirdValidator); - assert.equal(amount.toString(),web3.utils.toBN(1e18).toString()) - - - await validatorSetInstance.deposit(secondValidator, {from: systemAccount, value: 1e18 }); - amount = await validatorSetInstance.getIncoming.call(secondValidator); - assert.equal(amount.toString(),web3.utils.toBN(2e18).toString()) - for (let i =1; i<=50; i++){ - await slashInstance.slash(secondValidator, { from: systemAccount }); - } - res= (await slashInstance.getSlashIndicator.call(secondValidator)); - assert.equal(res[1].toNumber(),50); - amount = await validatorSetInstance.getIncoming.call(validator); - assert.equal(amount.toString(),web3.utils.toBN(1e18).toString()) - amount = await validatorSetInstance.getIncoming.call(secondValidator); - assert.equal(amount.toNumber(),0); - amount = await validatorSetInstance.getIncoming.call(thirdValidator); - assert.equal(amount.toString(),web3.utils.toBN(2e18).toString()) - - for (let i =1; i<=50; i++){ - await slashInstance.slash(thirdValidator, { from: systemAccount }); - } - res= (await slashInstance.getSlashIndicator.call(thirdValidator)); - assert.equal(res[1].toNumber(),50); - amount = await validatorSetInstance.getIncoming.call(validator); - assert.equal(amount.toString(),web3.utils.toBN(2e18).toString()) - amount = await validatorSetInstance.getIncoming.call(secondValidator); - assert.equal(amount.toString(),web3.utils.toBN(1e18).toString()) - amount = await validatorSetInstance.getIncoming.call(thirdValidator); - assert.equal(amount.toNumber(),0); - - }); -}); - -contract('felony SlashIndicator', (accounts) => { - it('trigger felony ', async () => { - const slashInstance = await SlashIndicator.deployed(); - const validatorSetInstance = await BSCValidatorSet.deployed(); - - const systemAccount = accounts[0]; - let validator = accounts[0]; - let secondValidator = accounts[1]; - let thirdValidator = accounts[2]; - - let packageBytes = validatorUpdateRlpEncode([validator,secondValidator,thirdValidator], - [validator,secondValidator,thirdValidator],[validator,secondValidator,thirdValidator]); - await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: accounts[8]}); - - await validatorSetInstance.deposit(validator, {from: systemAccount, value: 2e18 }); - amount = await validatorSetInstance.getIncoming.call(validator); - assert.equal(amount.toString(),web3.utils.toBN(2e18).toString(), "case1: incoming of account1 is wrong") - for (let i =1; i<=150; i++){ - await slashInstance.slash(validator, { from: systemAccount }); - } - - let res= (await slashInstance.getSlashIndicator.call(validator)); - assert.equal(res[1].toNumber(),0, "case1: slash indicator of account1 is wrong"); - amount = await validatorSetInstance.getIncoming.call(validator); - assert.equal(amount.toNumber(),0, "case1: incoming of account1 is wrong"); - amount = await validatorSetInstance.getIncoming.call(secondValidator); - assert.equal(amount.toString(),web3.utils.toBN(1e18).toString(), "case1: incoming of account2 is wrong"); - amount = await validatorSetInstance.getIncoming.call(thirdValidator); - assert.equal(amount.toString(),web3.utils.toBN(1e18).toString(), "case1: incoming of account3 is wrong"); - let consensusAddress = await validatorSetInstance.getValidators.call(); - assert.equal(consensusAddress.length,2, "case1: length of validators should be 2"); - assert.equal(consensusAddress[0],secondValidator, "case1: index 0 of validators should be account2"); - assert.equal(consensusAddress[1],thirdValidator, "case1: index 1 of validators should be account3"); - - packageBytes = validatorUpdateRlpEncode([validator,secondValidator,thirdValidator], - [validator,secondValidator,thirdValidator],[validator,secondValidator,thirdValidator]); - await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: accounts[8]}); - - await validatorSetInstance.deposit(secondValidator, {from: systemAccount, value: 2e18 }); - amount = await validatorSetInstance.getIncoming.call(secondValidator); - assert.equal(amount.toString(),web3.utils.toBN(2e18).toString(), "case2: incoming of account2 is wrong") - for (let i =1; i<=150; i++){ - await slashInstance.slash(secondValidator, { from: systemAccount }); - } - - res= (await slashInstance.getSlashIndicator.call(secondValidator)); - assert.equal(res[1].toNumber(),0, "case2: slash indicator of account2 is wrong"); - amount = await validatorSetInstance.getIncoming.call(secondValidator); - assert.equal(amount.toNumber(),0, "case2: incoming of account2 is wrong"); - amount = await validatorSetInstance.getIncoming.call(validator); - assert.equal(amount.toString(),web3.utils.toBN(1e18).toString(), "case2: incoming of account1 is wrong"); - amount = await validatorSetInstance.getIncoming.call(thirdValidator); - assert.equal(amount.toString(),web3.utils.toBN(1e18).toString(), "case2: incoming of account3 is wrong"); - consensusAddress = await validatorSetInstance.getValidators.call(); - assert.equal(consensusAddress.length,2, "case2: length of validators should be 2"); - assert.equal(consensusAddress[0],validator, "case2: index 0 of validators should be account1"); - assert.equal(consensusAddress[1],thirdValidator, "case2: index 1 of validators should be account3"); - - packageBytes = validatorUpdateRlpEncode([validator,secondValidator,thirdValidator], - [validator,secondValidator,thirdValidator],[validator,secondValidator,thirdValidator]); - await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: accounts[8]}); - - await validatorSetInstance.deposit(thirdValidator, {from: systemAccount, value: 2e18 }); - amount = await validatorSetInstance.getIncoming.call(thirdValidator); - assert.equal(amount.toString(),web3.utils.toBN(2e18).toString(), "case3: incoming of account3 is wrong") - for (let i =1; i<=150; i++){ - await slashInstance.slash(thirdValidator, { from: systemAccount }); - } - - res= (await slashInstance.getSlashIndicator.call(thirdValidator)); - assert.equal(res[1].toNumber(),0, "case3: slash indicator of account3 is wrong"); - amount = await validatorSetInstance.getIncoming.call(thirdValidator); - assert.equal(amount.toNumber(),0, "case3: incoming of account3 is wrong"); - amount = await validatorSetInstance.getIncoming.call(validator); - assert.equal(amount.toString(),web3.utils.toBN(1e18).toString(), "case3: incoming of account1 is wrong"); - amount = await validatorSetInstance.getIncoming.call(secondValidator); - assert.equal(amount.toString(),web3.utils.toBN(1e18).toString(), "case3: incoming of account2 is wrong"); - consensusAddress = await validatorSetInstance.getValidators.call(); - assert.equal(consensusAddress.length,2, "case3: length of validators should be 2"); - assert.equal(consensusAddress[0],validator, "case3: index 0 of validators should be account1"); - assert.equal(consensusAddress[1],secondValidator, "case3: index 0 of validators should be account2"); - - }); -}); - -contract('Clean SlashIndicator', (accounts) => { - it('test slash clean', async () => { - const slashInstance = await SlashIndicator.deployed(); - const validatorSetInstance = await BSCValidatorSet.deployed(); - let newValidator = web3.eth.accounts.create(); - let relayerAccount = accounts[8]; - const accountOne = accounts[0]; - - // case 1: all clean. - let validators = []; - for(let i =0;i <20; i++){ - validators.push(web3.eth.accounts.create().address); - } - // Do init - let packageBytes = validatorUpdateRlpEncode(validators, - validators,validators); - await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: relayerAccount}); - - for(let i =0;i <20;i++){ - await slashInstance.slash(validators[i], { from: accountOne }); - } - - // do clean - await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: relayerAccount}); - - let res= (await slashInstance.getSlashValidators.call()); - assert.equal(res.length, 0); - - for(let i =0;i <20;i++){ - let res = await slashInstance.getSlashIndicator.call(validators[i]); - let count =res[1].toNumber(); - let height = res[0].toNumber(); - assert.equal(count, 0); - assert.equal(height, 0); - } - - // case 2: all stay. - for(let i =0;i <20;i++){ - for(let j=0;j<5;j++){ - await slashInstance.slash(validators[i], { from: accountOne }); - } - } - // do clean - await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: relayerAccount}); - res= (await slashInstance.getSlashValidators.call()); - assert.equal(res.length, 20); - for(let i =0;i <20;i++){ - let res = await slashInstance.getSlashIndicator.call(validators[i]); - let count =res[1].toNumber(); - assert.equal(count, 1); - } - - // case 3: partial stay. - for(let i =0;i <10;i++){ - for(let j=0;j<5;j++){ - await slashInstance.slash(validators[2*i], { from: accountOne }); - } - await slashInstance.slash(validators[2*i+1], { from: accountOne }); - } - // doclean - await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: relayerAccount}); - res= (await slashInstance.getSlashValidators.call()); - assert.equal(res.length, 10); - for(let i =0;i <20;i++){ - let res = await slashInstance.getSlashIndicator.call(validators[i]); - let count =res[1].toNumber(); - if(i%2==0){ - assert.equal(count, 2); - }else{ - assert.equal(count, 0); - } - } - - // case 4: partial stay. - for(let i =0;i <10;i++){ - for(let j=0;j<5;j++){ - await slashInstance.slash(validators[2*i+1], { from: accountOne }); - } - await slashInstance.slash(validators[2*i], { from: accountOne }); - } - // doclean - await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID,packageBytes,{from: relayerAccount}); - res= (await slashInstance.getSlashValidators.call()); - assert.equal(res.length, 10); - for(let i =0;i <20;i++){ - let res = await slashInstance.getSlashIndicator.call(validators[i]); - let count =res[1].toNumber(); - if(i%2==0){ - assert.equal(count, 0); - }else{ - assert.equal(count, 1); - } - } - - }); -}); - -contract("finality slash SlashIndicator", (accounts) => { - it("valid finality evidence: same target block", async () => { - const slashInstance = await SlashIndicator.deployed(); - const systemRewardInstance = await SystemReward.deployed(); - const validatorSetInstance = await BSCValidatorSet.deployed(); - let relayerAccount = accounts[8]; - - await systemRewardInstance.send(web3.utils.toBN(1e18), { from: accounts[1] }); - await systemRewardInstance.addOperator(slashInstance.address); - - // add vote address - let packageBytes = newValidatorUpdateRlpEncode( - [accounts[0]], - [accounts[0]], - [accounts[0]], - [Buffer.from("voteAddr")] - ); - await validatorSetInstance.handleSynPackage(STAKE_CHANNEL_ID, packageBytes, { - from: relayerAccount, - }); - - let currentNumber = await web3.eth.getBlockNumber(); - let srcNumA = currentNumber - 20; - let tarNumA = currentNumber - 10; - let srcNumB = currentNumber - 15; - let tarNumB = tarNumA; - let srcHashA = await web3.eth.getBlock(srcNumA).then((x) => { - return x.hash; - }); - let tarHashA = await web3.eth.getBlock(tarNumA).then((x) => { - return x.hash; - }); - let srcHashB = await web3.eth.getBlock(srcNumB).then((x) => { - return x.hash; - }); - let tarHashB = tarHashA; - - let voteDataA = { - srcNum: srcNumA, - tarNum: tarNumA, - srcHash: srcHashA, - tarHash: tarHashA, - sig: Buffer.from("sigA") - } - let voteDataB = { - srcNum: srcNumB, - tarNum: tarNumB, - srcHash: srcHashB, - tarHash: tarHashB, - sig: Buffer.from("sigB") - } - let evidence = { - voteA: voteDataA, - voteB: voteDataB, - voteAddr: Buffer.from("voteAddr"), - }; - - let tx = await slashInstance.submitFinalityViolationEvidence(evidence, { - from: relayerAccount, - }); - truffleAssert.eventEmitted(tx, "validatorSlashed", (ev) => { - return ev.validator === accounts[0]; - }); - }); - - it("valid finality evidence: vote within span", async () => { - const slashInstance = await SlashIndicator.deployed(); - let relayerAccount = accounts[8]; - - let currentNumber = await web3.eth.getBlockNumber(); - let srcNumA = currentNumber - 20; - let tarNumA = currentNumber - 10; - let srcNumB = currentNumber - 18; - let tarNumB = currentNumber - 15; - let srcHashA = await web3.eth.getBlock(srcNumA).then((x) => { - return x.hash; - }); - let tarHashA = await web3.eth.getBlock(tarNumA).then((x) => { - return x.hash; - }); - let srcHashB = await web3.eth.getBlock(srcNumA).then((x) => { - return x.hash; - }); - let tarHashB = await web3.eth.getBlock(tarNumB).then((x) => { - return x.hash; - }); - - let voteDataA = { - srcNum: srcNumA, - tarNum: tarNumA, - srcHash: srcHashA, - tarHash: tarHashA, - sig: Buffer.from("sigA") - } - let voteDataB = { - srcNum: srcNumB, - tarNum: tarNumB, - srcHash: srcHashB, - tarHash: tarHashB, - sig: Buffer.from("sigB") - } - let evidence = { - voteA: voteDataA, - voteB: voteDataB, - voteAddr: Buffer.from("voteAddr"), - }; - - let tx = await slashInstance.submitFinalityViolationEvidence(evidence, { - from: relayerAccount, - }); - truffleAssert.eventEmitted(tx, "validatorSlashed", (ev) => { - return ev.validator === accounts[0]; - }); - }); - - it("invalid finality evidence", async () => { - const slashInstance = await SlashIndicator.deployed(); - let relayerAccount = accounts[8]; - - let currentNumber = await web3.eth.getBlockNumber(); - let srcNumA = currentNumber - 20; - let tarNumA = currentNumber - 10; - let srcNumB = currentNumber - 18; - let tarNumB = currentNumber - 12; - let srcHashA = await web3.eth.getBlock(srcNumA).then((x) => { - return x.hash; - }); - let tarHashA = await web3.eth.getBlock(tarNumA).then((x) => { - return x.hash; - }); - let srcHashB = await web3.eth.getBlock(srcNumA).then((x) => { - return x.hash; - }); - let tarHashB = await web3.eth.getBlock(tarNumB).then((x) => { - return x.hash; - }); - - let voteDataA = { - srcNum: srcNumA, - tarNum: tarNumA, - srcHash: srcHashA, - tarHash: tarHashA, - sig: Buffer.from("sigA") - } - let voteDataB = { - srcNum: srcNumB, - tarNum: tarNumB, - srcHash: srcHashB, - tarHash: tarHashB, - sig: Buffer.from("sigB") - } - let evidence = { - voteA: voteDataA, - voteB: voteDataB, - voteAddr: Buffer.from("voteAddr"), - }; - - evidence.voteA.srcNum = currentNumber - 257; - try { - await slashInstance.submitFinalityViolationEvidence(evidence, { from: relayerAccount }); - assert.fail(); - } catch (error) { - assert.ok( - error.toString().includes("too old block involved") - ); - } - - evidence.voteA.srcNum = currentNumber - 20; - evidence.voteB = voteDataA; - try { - await slashInstance.submitFinalityViolationEvidence(evidence, { from: relayerAccount }); - assert.fail(); - } catch (error) { - assert.ok( - error.toString().includes("two identical votes") - ); - } - - evidence.voteB = voteDataB; - evidence.voteA.tarNum = evidence.voteA.srcNum - 1; - try { - await slashInstance.submitFinalityViolationEvidence(evidence, { from: relayerAccount }); - assert.fail(); - } catch (error) { - assert.ok( - error.toString().includes("srcNum bigger than tarNum") - ); - } - - evidence.voteA.tarNum = currentNumber - 10; - evidence.voteB.tarNum = currentNumber - 8; - try { - await slashInstance.submitFinalityViolationEvidence(evidence, { from: relayerAccount }); - assert.fail(); - } catch (error) { - assert.ok(error.toString().includes("no violation of vote rules")); - } - - evidence.voteB.tarNum = currentNumber - 12; - evidence.voteAddr = Buffer.from("wrongVoteAddr"); - try { - await slashInstance.submitFinalityViolationEvidence(evidence, { from: relayerAccount }); - assert.fail(); - } catch (error) { - assert.ok(error.toString().includes("validator not exist")); - } - }); -}); - -function validatorUpdateRlpEncode(consensusAddrList,feeAddrList, bscFeeAddrList) { - let pkg = []; - pkg.push(0x00); - let n = consensusAddrList.length; - let vals = []; - for(let i = 0;i => { - const instance = await deployContract(deployer, factoryPath); - if (needInit) { - await (await instance.init()).wait(1); - } - return instance; -}; - -describe('BSCValidatorSet', () => { - const unit = ethers.constants.WeiPerEther; - let instances: any[]; - - let relayerIncentivize: RelayerIncentivize; - let tendermintLightClient: TendermintLightClient; - let validatorSet: BSCValidatorSet; - let systemReward: SystemReward; - let slashIndicator: SlashIndicator; - let crosschain: CrossChain; - let relayerHub: RelayerHub; - let govHub: GovHub; - - let operator: SignerWithAddress; - let validators: string[]; - let relayerAccount: string; - let signers: SignerWithAddress[]; - - let maxNumOfMaintaining: number; - let maintainSlashScale: number; - before('before', async () => { - signers = await ethers.getSigners(); - log(signers.length); - operator = signers[0]; - relayerAccount = signers[1].address; - validators = signers.slice(0, 100).map((signer) => signer.address); - - const contractPaths = [ - { - name: 'RelayerIncentivize', // 0 - needInit: true, - needUpdate: true, - }, - { - name: 'TendermintLightClient', // 1 - needInit: true, - needUpdate: true, - }, - { - name: 'CrossChain', // 2 - needInit: false, - needUpdate: true, - }, - { - name: 'SystemReward', // 3 - needInit: false, - needUpdate: false, - }, - { - name: 'MockLightClient', // 4 - needInit: false, - needUpdate: false, - }, - { - name: 'TokenHub', // 5 - needInit: true, - needUpdate: true, - }, - { - name: 'TokenManager', // 6 - needInit: false, - needUpdate: true, - }, - { - name: 'RelayerHub', // 7 - needInit: true, - needUpdate: true, - }, - { - name: 'SlashIndicator', // 8 - needInit: true, - needUpdate: true, - }, - { - name: 'GovHub', // 9 - needInit: false, - needUpdate: true, - }, - { - name: 'BSCValidatorSet', // 10 - needInit: true, - needUpdate: true, - }, - ]; - instances = []; - for (let i = 0; i < contractPaths.length; i++) { - const pathObj = contractPaths[i]; - instances.push(await deployContractAndInit(operator, pathObj.name, pathObj.needInit)); - } - - for (let i = 0; i < contractPaths.length; i++) { - const pathObj = contractPaths[i]; - const instance = instances[i]; - - if (!pathObj.needUpdate) { - continue; - } - - let crosschainAddress = instances[2].address; - if (pathObj.name === 'BSCValidatorSet' || pathObj.name === 'GovHub') { - crosschainAddress = operator.address; - } - - await waitTx( - instance.updateContractAddr( - instances[10].address, - instances[8].address, - instances[3].address, - instances[4].address, - instances[5].address, - instances[0].address, - instances[7].address, - instances[9].address, - instances[6].address, - crosschainAddress - ) - ); - } - - relayerIncentivize = instances[0]; - tendermintLightClient = instances[1]; - - systemReward = instances[3] as SystemReward; - slashIndicator = instances[8] as SlashIndicator; - await waitTx(systemReward.addOperator(operator.address)); - await waitTx(systemReward.addOperator(tendermintLightClient.address)); - await waitTx(systemReward.addOperator(relayerIncentivize.address)); - - validatorSet = instances[10] as BSCValidatorSet; - relayerHub = instances[7] as RelayerHub; - - crosschain = instances[2] as CrossChain; - await waitTx(crosschain.init()); - - govHub = instances[9] as GovHub; - }); - - beforeEach('beforeEach', async () => {}); - - it('query code size', async () => { - const code = await ethers.provider.getCode(validatorSet.address) - const codeSize = (code.length - 2) / 2 - log(`BSCValidatorSet Mock Template code size: ${codeSize}, UpperLimit: 24567` ) - }); - - it('update validators', async () => { - // do update validators - let packageBytes = validatorUpdateRlpEncode( - validators.slice(1, 22), - validators.slice(1, 22), - validators.slice(1, 22) - ); - - await waitTx(validatorSet.connect(operator).handleSynPackage(STAKE_CHANNEL_ID, packageBytes)); - }); - - it('query all view func', async () => { - expect(await validatorSet.getValidators()).to.deep.eq(validators.slice(1, 22)); - for (let i = 1; i < 50; i++) { - const currentValidatorSetIndex = i - 1 - if (i >= 1 && i < 22) { - expect(await validatorSet.isWorkingValidator(currentValidatorSetIndex)).to.deep.eq(true); - expect(await validatorSet.isCurrentValidator(validators[i])).to.deep.eq(true); - expect(await validatorSet.canEnterMaintenance(validators[i])).to.deep.eq(false); - } else { - expect(await validatorSet.isWorkingValidator(currentValidatorSetIndex)).to.be.eq(false); - expect(await validatorSet.isCurrentValidator(validators[i])).to.deep.eq(false); - expect(await validatorSet.canEnterMaintenance(validators[i])).to.deep.eq(false); - } - expect(await validatorSet.getIncoming(validators[i])).to.deep.eq(0); - } - - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([]); - expect(await validatorSet.numOfMaintaining()).to.be.eq(0); - - }); - - it('common case 1-1 update params', async () => { - await waitTx(relayerHub.connect(operator).register({ value: unit.mul(100) })); - await waitTx( - govHub.updateContractAddr( - instances[10].address, - instances[8].address, - instances[3].address, - instances[4].address, - instances[5].address, - instances[0].address, - instances[7].address, - instances[9].address, - instances[6].address, - instances[2].address - ) - ); - - // set maxNumOfMaintaining to 5 - let govChannelSeq = await crosschain.channelReceiveSequenceMap(GOV_CHANNEL_ID); - maxNumOfMaintaining = 5; - let govValue = '0x0000000000000000000000000000000000000000000000000000000000000005'; // 5; - let govPackageBytes = serializeGovPack('maxNumOfMaintaining', govValue, validatorSet.address); - await crosschain - .connect(operator) - .handlePackage( - Buffer.concat([buildSyncPackagePrefix(2e16), govPackageBytes]), - proof, - merkleHeight, - govChannelSeq, - GOV_CHANNEL_ID - ); - expect(await validatorSet.maxNumOfMaintaining()).to.be.eq(BigNumber.from(govValue)); - - // set maintainSlashScale to 2 - govChannelSeq = await crosschain.channelReceiveSequenceMap(GOV_CHANNEL_ID); - maintainSlashScale = 2; - govValue = '0x0000000000000000000000000000000000000000000000000000000000000002'; // 2; - govPackageBytes = serializeGovPack('maintainSlashScale', govValue, validatorSet.address); - await crosschain - .connect(operator) - .handlePackage( - Buffer.concat([buildSyncPackagePrefix(2e16), govPackageBytes]), - proof, - merkleHeight, - govChannelSeq, - GOV_CHANNEL_ID - ); - expect(await validatorSet.maintainSlashScale()).to.be.eq(BigNumber.from(govValue)); - expect(await validatorSet.numOfMaintaining()).to.be.eq(0); - }); - - it('common case 1-2: validator-1 enterMaintenance', async () => { - await waitTx(validatorSet.connect(signers[1]).enterMaintenance()); - const maintainingValidators = await validatorSet.getMaintainingValidators() - expect(maintainingValidators).to.deep.eq([validators[1]]); - }); - - it('common case 1-3: validator-2 enterMaintenance', async () => { - await waitTx(validatorSet.connect(signers[2]).enterMaintenance()); - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ - validators[1], - validators[2], - ]); - expect(await validatorSet.numOfMaintaining()).to.be.eq(2); - }); - - it('common case 1-4: validator-3 misdemeanor, enterMaintenance', async () => { - await setSlashIndicator(operator.address, validatorSet, instances); - - await validatorSet.connect(operator).misdemeanor(validators[3]); - - const index = await validatorSet.getCurrentValidatorIndex(validators[3]); - const validatorExtra = await validatorSet.validatorExtraSet(index); - - expect(validatorExtra.isMaintaining).to.be.eq(true); - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ - validators[1], - validators[2], - validators[3], - ]); - expect(await validatorSet.numOfMaintaining()).to.be.eq(3); - }); - - it('common case 1-5: validator-2 exitMaintenance', async () => { - await setSlashIndicator(slashIndicator.address, validatorSet, instances); - - await waitTx(validatorSet.connect(signers[2]).exitMaintenance()); - const index = await validatorSet.getCurrentValidatorIndex(validators[2]); - const validatorExtra = await validatorSet.validatorExtraSet(index); - - expect(validatorExtra.isMaintaining).to.be.eq(false); - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ - validators[1], - validators[3], - ]); - expect(await validatorSet.numOfMaintaining()).to.be.eq(2); - }); - - it('common case 1-6: validator-4 misdemeanor, enterMaintenance', async () => { - await setSlashIndicator(operator.address, validatorSet, instances); - - await validatorSet.connect(operator).misdemeanor(validators[4]); - const index = await validatorSet.getCurrentValidatorIndex(validators[4]); - const validatorExtra = await validatorSet.validatorExtraSet(index); - - - expect(validatorExtra.isMaintaining).to.be.eq(true); - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ - validators[1], - validators[3], - validators[4], - ]); - expect(await validatorSet.numOfMaintaining()).to.be.eq(3); - }); - - it('common case 1-7: validator-5 misdemeanor, enterMaintenance', async () => { - await validatorSet.connect(operator).misdemeanor(validators[5]); - const index = await validatorSet.getCurrentValidatorIndex(validators[5]); - const validatorExtra = await validatorSet.validatorExtraSet(index); - - expect(validatorExtra.isMaintaining).to.be.eq(true); - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ - validators[1], - validators[3], - validators[4], - validators[5], - ]); - expect(await validatorSet.numOfMaintaining()).to.be.eq(4); - - }); - - it('common case 1-8: validator-6 enterMaintenance', async () => { - await setSlashIndicator(slashIndicator.address, validatorSet, instances); - - await waitTx(validatorSet.connect(signers[6]).enterMaintenance()); - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ - validators[1], - validators[3], - validators[4], - validators[5], - validators[6], - ]); - expect(await validatorSet.numOfMaintaining()).to.be.eq(5); - - }); - - it('common case 1-9: validator-7 enterMaintenance failed!', async () => { - expect(validatorSet.connect(signers[7]).enterMaintenance()).to.be.revertedWith( - 'can not enter Temporary Maintenance' - ); - expect(await validatorSet.numOfMaintaining()).to.be.eq(5); - }); - - it('common case 1-10: validator-7 misdemeanor, enterMaintenance failed!', async () => { - await setSlashIndicator(operator.address, validatorSet, instances); - - await validatorSet.connect(operator).misdemeanor(validators[7]); - const index = await validatorSet.getCurrentValidatorIndex(validators[7]); - const validatorExtra = await validatorSet.validatorExtraSet(index); - - expect(validatorExtra.isMaintaining).to.be.eq(false); - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ - validators[1], - validators[3], - validators[4], - validators[5], - validators[6], - ]); - expect(await validatorSet.numOfMaintaining()).to.be.eq(5); - }); - - it('common case 1-11: validator-1 exitMaintenance', async () => { - await setSlashIndicator(slashIndicator.address, validatorSet, instances); - - await waitTx(validatorSet.connect(signers[1]).exitMaintenance()); - const index = await validatorSet.getCurrentValidatorIndex(validators[1]); - const validatorExtra = await validatorSet.validatorExtraSet(index); - - expect(validatorExtra.isMaintaining).to.be.eq(false); - expect(validatorExtra.enterMaintenanceHeight.toNumber() > 0).to.be.eq(true); - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ - validators[3], - validators[4], - validators[5], - validators[6], - ]); - expect(await validatorSet.numOfMaintaining()).to.be.eq(4); - }); - - it('common case 1-12: validator-1 misdemeanor, enterMaintenance failed!', async () => { - await setSlashIndicator(operator.address, validatorSet, instances); - - await validatorSet.connect(operator).misdemeanor(validators[1]); - const index = await validatorSet.getCurrentValidatorIndex(validators[1]); - const validatorExtra = await validatorSet.validatorExtraSet(index); - - expect(validatorExtra.isMaintaining).to.be.eq(false); - expect(validatorExtra.enterMaintenanceHeight.toNumber() > 0).to.be.eq(true); - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ - validators[3], - validators[4], - validators[5], - validators[6], - ]); - expect(await validatorSet.numOfMaintaining()).to.be.eq(4); - }); - - it('common case 1-13: validator-8 enterMaintenance', async () => { - await mineBlocks(21 * 100 * maintainSlashScale); - - await setSlashIndicator(slashIndicator.address, validatorSet, instances); - - await waitTx(validatorSet.connect(signers[8]).enterMaintenance()); - - const index = await validatorSet.getCurrentValidatorIndex(validators[8]); - const validatorExtra = await validatorSet.validatorExtraSet(index); - - expect(validatorExtra.isMaintaining).to.be.eq(true); - expect(validatorExtra.enterMaintenanceHeight.toNumber() > 0).to.be.eq(true); - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ - validators[3], - validators[4], - validators[5], - validators[6], - validators[8], - ]); - expect(await validatorSet.numOfMaintaining()).to.be.eq(5); - }); - - it('common case 1-14: validator-9 enterMaintenance failed!', async () => { - expect(validatorSet.connect(signers[9]).enterMaintenance()).to.be.revertedWith( - 'can not enter Temporary Maintenance' - ); - }); - - it('common case 1-15: validator-1 felony', async () => { - let index = await validatorSet.currentValidatorSetMap(validators[1]); - expect(index.toNumber() > 0).to.be.eq(true); - - await setSlashIndicator(operator.address, validatorSet, instances); - await validatorSet.connect(operator).felony(validators[1]); - - index = await validatorSet.currentValidatorSetMap(validators[1]); - expect(index.toNumber() === 0).to.be.eq(true); - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ - validators[3], - validators[4], - validators[5], - validators[6], - validators[8], - ]); - expect(await validatorSet.numOfMaintaining()).to.be.eq(5); - }); - - it('common case 1-16: validator-2 enterMaintenance failed!', async () => { - expect(validatorSet.connect(signers[2]).enterMaintenance()).to.be.revertedWith( - 'can not enter Temporary Maintenance' - ); - }); - - it('common case 1-17: validator-4 exitMaintenance', async () => { - await setSlashIndicator(slashIndicator.address, validatorSet, instances); - - await waitTx(validatorSet.connect(signers[4]).exitMaintenance()); - const index = await validatorSet.getCurrentValidatorIndex(validators[4]); - const validatorExtra = await validatorSet.validatorExtraSet(index); - - expect(validatorExtra.isMaintaining).to.be.eq(false); - expect(validatorExtra.enterMaintenanceHeight.toNumber() > 0).to.be.eq(true); - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ - validators[3], - validators[5], - validators[6], - validators[8], - ]); - expect(await validatorSet.numOfMaintaining()).to.be.eq(4); - }); - - it('common case 1-18: validator-2 enterMaintenance failed!', async () => { - expect(validatorSet.connect(signers[2]).enterMaintenance()).to.be.revertedWith( - 'can not enter Temporary Maintenance' - ); - }); - - it('common case 1-19: validator-2 misdemeanor, enterMaintenance failed!', async () => { - await setSlashIndicator(operator.address, validatorSet, instances); - await validatorSet.connect(operator).misdemeanor(validators[2]); - const index = await validatorSet.getCurrentValidatorIndex(validators[2]); - const validatorExtra = await validatorSet.validatorExtraSet(index); - - expect(validatorExtra.isMaintaining).to.be.eq(false); - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ - validators[3], - validators[5], - validators[6], - validators[8], - ]); - expect(await validatorSet.numOfMaintaining()).to.be.eq(4); - }); - - it('common case 1-20: validator-10 enterMaintenance', async () => { - await setSlashIndicator(slashIndicator.address, validatorSet, instances); - - await waitTx(validatorSet.connect(signers[10]).enterMaintenance()); - - const index = await validatorSet.getCurrentValidatorIndex(validators[10]); - const validatorExtra = await validatorSet.validatorExtraSet(index); - - expect(validatorExtra.isMaintaining).to.be.eq(true); - expect(validatorExtra.enterMaintenanceHeight.toNumber() > 0).to.be.eq(true); - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ - validators[3], - validators[5], - validators[6], - validators[8], - validators[10], - ]); - expect(await validatorSet.numOfMaintaining()).to.be.eq(5); - }); - - it('common case 1-21: validator-3 exitMaintenance', async () => { - await setSlashIndicator(slashIndicator.address, validatorSet, instances); - - await waitTx(validatorSet.connect(signers[3]).exitMaintenance()); - const index = await validatorSet.getCurrentValidatorIndex(validators[3]); - const validatorExtra = await validatorSet.validatorExtraSet(index); - - expect(validatorExtra.isMaintaining).to.be.eq(false); - expect(validatorExtra.enterMaintenanceHeight.toNumber() > 0).to.be.eq(true); - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ - validators[5], - validators[6], - validators[8], - validators[10], - ]); - expect(await validatorSet.numOfMaintaining()).to.be.eq(4); - }); - - it('common case 1-22: validator-4 exitMaintenance', async () => { - await setSlashIndicator(slashIndicator.address, validatorSet, instances); - expect(validatorSet.connect(signers[4]).exitMaintenance()).to.revertedWith( - 'not in maintenance' - ); - }); - - it('common case 1-23: validator-4 enterMaintenance failed!', async () => { - expect(validatorSet.connect(signers[4]).enterMaintenance()).to.be.revertedWith( - 'can not enter Temporary Maintenance' - ); - }); - - it('common case 1-24: 24 hours ended, clear all maintainInfo', async () => { - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([ - validators[5], - validators[6], - validators[8], - validators[10], - ]); - expect(await validatorSet.numOfMaintaining()).to.be.eq(4); - - await waitTx( - validatorSet.updateContractAddr( - instances[10].address, - instances[8].address, - instances[3].address, - instances[4].address, - instances[5].address, - instances[0].address, - instances[7].address, - instances[9].address, - instances[6].address, - operator.address - ) - ); - - await mineBlocks(21 * 50 * maintainSlashScale); - - // do update validators - let packageBytes = validatorUpdateRlpEncode( - validators.slice(2, 23), - validators.slice(2, 23), - validators.slice(2, 23) - ); - await waitTx(validatorSet.connect(operator).handleSynPackage(STAKE_CHANNEL_ID, packageBytes)); - - // validator-5,6 felony, validator-8 misdemeanor - const expectedValidators = validators - .slice(2, 23) - .filter((item) => item !== validators[5] && item !== validators[6]); - expect(await validatorSet.getValidators()).to.deep.eq(expectedValidators); - expect(await validatorSet.numOfMaintaining()).to.be.eq(0); - - for (let i = 2; i < 23; i++) { - if (i === 5 || i === 6) { - // because of felony, validator-5,6 are not the current validators - expect(validatorSet.getCurrentValidatorIndex(validators[i])).to.be.revertedWith( - 'only current validators' - ); - continue; - } - const index = await validatorSet.getCurrentValidatorIndex(validators[i]); - const validatorExtra = await validatorSet.validatorExtraSet(index); - - expect(validatorExtra.isMaintaining).to.be.eq(false); - expect(validatorExtra.enterMaintenanceHeight.toNumber() === 0).to.be.eq(true); - } - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([]); - }); - - - it('common case 1-25: query all view func', async () => { - expect(await validatorSet.maxNumOfMaintaining()).to.be.eq(maxNumOfMaintaining) - expect(await validatorSet.maintainSlashScale()).to.be.eq(maintainSlashScale) - expect(await validatorSet.numOfMaintaining()).to.be.eq(0); - - for (let i = 2; i < 50; i++) { - if (i >= 2 && i < 23 && i !== 5 && i !== 6) { - expect(await validatorSet.isCurrentValidator(validators[i])).to.deep.eq(true); - } else { - expect(await validatorSet.isCurrentValidator(validators[i])).to.deep.eq(false); - } - expect(await validatorSet.getIncoming(validators[i])).to.deep.eq(0); - } - - expect(await validatorSet.getMaintainingValidators()).to.deep.eq([]); - }); - - - it('common case 2-1 update params', async () => { - await waitTx( - govHub.updateContractAddr( - instances[10].address, - instances[8].address, - instances[3].address, - instances[4].address, - instances[5].address, - instances[0].address, - instances[7].address, - instances[9].address, - instances[6].address, - instances[2].address - ) - ); - - // set maxNumOfMaintaining to 5 - let govChannelSeq = await crosschain.channelReceiveSequenceMap(GOV_CHANNEL_ID); - maxNumOfMaintaining = 18; - let govValue = '0x0000000000000000000000000000000000000000000000000000000000000012'; // 18 - let govPackageBytes = serializeGovPack('maxNumOfMaintaining', govValue, validatorSet.address); - await crosschain - .connect(operator) - .handlePackage( - Buffer.concat([buildSyncPackagePrefix(2e16), govPackageBytes]), - proof, - merkleHeight, - govChannelSeq, - GOV_CHANNEL_ID - ); - expect(await validatorSet.maxNumOfMaintaining()).to.be.eq(BigNumber.from(govValue)); - - // set maintainSlashScale to 2 - govChannelSeq = await crosschain.channelReceiveSequenceMap(GOV_CHANNEL_ID); - maintainSlashScale = 1; - govValue = '0x0000000000000000000000000000000000000000000000000000000000000001'; // 1 - govPackageBytes = serializeGovPack('maintainSlashScale', govValue, validatorSet.address); - await crosschain - .connect(operator) - .handlePackage( - Buffer.concat([buildSyncPackagePrefix(2e16), govPackageBytes]), - proof, - merkleHeight, - govChannelSeq, - GOV_CHANNEL_ID - ); - expect(await validatorSet.maintainSlashScale()).to.be.eq(BigNumber.from(govValue)); - expect(await validatorSet.numOfMaintaining()).to.be.eq(0); - }); - - - it('common case 2-2: validator 7 ~ 10 enterMaintenance', async () => { - await setSlashIndicator(slashIndicator.address, validatorSet, instances); - - for (let i = 7; i < 10; i++) { - await waitTx(validatorSet.connect(signers[i]).enterMaintenance()); - } - - const expectedMaintainingValidators = [] - - for (let i = 7; i < 10; i++) { - const index = await validatorSet.getCurrentValidatorIndex(validators[i]); - const validatorExtra = await validatorSet.validatorExtraSet(index); - expect(validatorExtra.isMaintaining).to.be.eq(true); - expect(validatorExtra.enterMaintenanceHeight.toNumber() > 0).to.be.eq(true); - expectedMaintainingValidators.push(validators[i]); - } - - - expect(await validatorSet.getMaintainingValidators()).to.deep.eq(expectedMaintainingValidators); - expect(await validatorSet.numOfMaintaining()).to.be.eq(3); - - const felonyThreshold = (await slashIndicator.felonyThreshold()).toNumber(); - await mineBlocks( 4 * felonyThreshold * maintainSlashScale / 2); - }); - - - it('common case 2-3: validator 10 ~ 21 enterMaintenance', async () => { - await setSlashIndicator(slashIndicator.address, validatorSet, instances); - - for (let i = 10; i < 22; i++) { - await waitTx(validatorSet.connect(signers[i]).enterMaintenance()); - } - - const expectedMaintainingValidators = [] - for (let i = 7; i < 10; i++) { - expectedMaintainingValidators.push(validators[i]); - } - - for (let i = 10; i < 22; i++) { - const index = await validatorSet.getCurrentValidatorIndex(validators[i]); - const validatorExtra = await validatorSet.validatorExtraSet(index); - expect(validatorExtra.isMaintaining).to.be.eq(true); - expect(validatorExtra.enterMaintenanceHeight.toNumber() > 0).to.be.eq(true); - expectedMaintainingValidators.push(validators[i]); - } - - expect(await validatorSet.getMaintainingValidators()).to.deep.eq(expectedMaintainingValidators); - expect(await validatorSet.numOfMaintaining()).to.be.eq(15); - - const felonyThreshold = (await slashIndicator.felonyThreshold()).toNumber(); - await mineBlocks( 4 * felonyThreshold * maintainSlashScale / 2 + 1); - }); - - it('common case 2-4: update validator set', async () => { - await waitTx( - validatorSet.updateContractAddr( - instances[10].address, - instances[8].address, - instances[3].address, - instances[4].address, - instances[5].address, - instances[0].address, - instances[7].address, - instances[9].address, - instances[6].address, - operator.address - ) - ); - - // do update validators - let packageBytes = validatorUpdateRlpEncode( - validators.slice(5, 26), - validators.slice(5, 26), - validators.slice(5, 26), - ); - await waitTx(validatorSet.connect(operator).handleSynPackage(STAKE_CHANNEL_ID, packageBytes)); - - // validator 7 ~ 9 will be felony, their slashCount = 4 * felonyThreshold * maintainSlashScale / workingValidatorCount(4) - const expectedValidators: string[] = [validators[5], validators[6]].concat(validators.slice(10, 26)); - - expect(await validatorSet.getValidators()).to.deep.eq(expectedValidators); - expect(await validatorSet.numOfMaintaining()).to.be.eq(0); - }); - -}); From f8bab13f56955e979bfb754425dab1e62e52f151 Mon Sep 17 00:00:00 2001 From: Roshan Date: Fri, 24 Mar 2023 15:46:34 +0800 Subject: [PATCH 13/15] update contract abi --- abi/crosschain.abi | 337 +++++++++++++++++++++++++++++++++++++++++ abi/slashindicator.abi | 25 +++ abi/systemreward.abi | 39 +++-- abi/tokenhub.abi | 248 +++++++++++++++++++++++++++++- 4 files changed, 633 insertions(+), 16 deletions(-) diff --git a/abi/crosschain.abi b/abi/crosschain.abi index f8291385..d8f6c78a 100644 --- a/abi/crosschain.abi +++ b/abi/crosschain.abi @@ -1,4 +1,92 @@ [ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "proposalTypeHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "proposer", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "quorum", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "expiredAt", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "contentHash", + "type": "bytes32" + } + ], + "name": "ProposalSubmitted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "executor", + "type": "address" + } + ], + "name": "Reopened", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "challenger", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint64", + "name": "packageSequence", + "type": "uint64" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "channelId", + "type": "uint8" + } + ], + "name": "SuccessChallenge", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "executor", + "type": "address" + } + ], + "name": "Suspended", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -207,6 +295,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "CANCEL_TRANSFER_PROPOSAL", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "CODE_OK", @@ -259,6 +360,32 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "EMERGENCY_PROPOSAL_EXPIRE_PERIOD", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "EMPTY_CONTENT_HASH", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "ERROR_FAIL_DECODE", @@ -337,6 +464,45 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "INIT_CANCEL_TRANSFER_QUORUM", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INIT_REOPEN_QUORUM", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INIT_SUSPEND_QUORUM", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "LIGHT_CLIENT_ADDR", @@ -363,6 +529,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "REOPEN_PROPOSAL", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "SLASH_CHANNELID", @@ -428,6 +607,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "SUSPEND_PROPOSAL", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "SYN_PACKAGE", @@ -558,6 +750,76 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenAddr", + "type": "address" + }, + { + "internalType": "address", + "name": "attacker", + "type": "address" + } + ], + "name": "cancelTransfer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint64[4]", + "name": "params", + "type": "uint64[4]" + }, + { + "internalType": "bytes", + "name": "payload0", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "payload1", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "proof0", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "proof1", + "type": "bytes" + } + ], + "name": "challenge", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "name": "challenged", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -634,6 +896,35 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "name": "emergencyProposals", + "outputs": [ + { + "internalType": "uint16", + "name": "quorum", + "type": "uint16" + }, + { + "internalType": "uint128", + "name": "expiredAt", + "type": "uint128" + }, + { + "internalType": "bytes32", + "name": "contentHash", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -722,6 +1013,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "isSuspended", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "oracleSequence", @@ -748,6 +1052,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "name": "quorumMap", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -772,6 +1095,13 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "reopen", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -795,6 +1125,13 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "suspend", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [], "name": "txCounter", diff --git a/abi/slashindicator.abi b/abi/slashindicator.abi index 99a044f5..83152d12 100644 --- a/abi/slashindicator.abi +++ b/abi/slashindicator.abi @@ -5,6 +5,31 @@ "name": "crashResponse", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "validator", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "slashCount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "failReason", + "type": "bytes" + } + ], + "name": "failedFelony", + "type": "event" + }, { "anonymous": false, "inputs": [], diff --git a/abi/systemreward.abi b/abi/systemreward.abi index 43865ac3..352cd95f 100644 --- a/abi/systemreward.abi +++ b/abi/systemreward.abi @@ -1,4 +1,30 @@ [ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "operator", + "type": "address" + } + ], + "name": "addOperator", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "operator", + "type": "address" + } + ], + "name": "deleteOperator", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -62,19 +88,6 @@ "name": "rewardTo", "type": "event" }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "operator", - "type": "address" - } - ], - "name": "updateOperator", - "type": "event" - }, { "inputs": [], "name": "BIND_CHANNELID", diff --git a/abi/tokenhub.abi b/abi/tokenhub.abi index f4f8e88e..f8ede968 100644 --- a/abi/tokenhub.abi +++ b/abi/tokenhub.abi @@ -1,8 +1,109 @@ [ { - "inputs": [], - "stateMutability": "nonpayable", - "type": "constructor" + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "tokenAddr", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "attacker", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "CancelTransfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "tokenAddr", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "largeTransferLimit", + "type": "uint256" + } + ], + "name": "LargeTransferLimitSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "tokenAddr", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "unlockAt", + "type": "uint256" + } + ], + "name": "LargeTransferLocked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "tokenAddr", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "WithdrawUnlockedToken", + "type": "event" }, { "anonymous": false, @@ -328,6 +429,32 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "INIT_BNB_LARGE_TRANSFER_LIMIT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INIT_LOCK_PERIOD", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "INIT_MINIMUM_RELAY_FEE", @@ -768,6 +895,24 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "attacker", + "type": "address" + } + ], + "name": "cancelTransferIn", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -948,6 +1093,67 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "largeTransferLimitMap", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "lockInfoMap", + "outputs": [ + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "unlockAt", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "lockPeriod", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "relayFee", @@ -961,6 +1167,24 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "bep20Token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "largeTransferLimit", + "type": "uint256" + } + ], + "name": "setLargeTransferLimit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -1050,6 +1274,24 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "recipient", + "type": "address" + } + ], + "name": "withdrawUnlockedToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "stateMutability": "payable", "type": "receive" From dec35012883cd4b8328952d47a58fc99ec90a324 Mon Sep 17 00:00:00 2001 From: Roshan Date: Thu, 6 Apr 2023 16:03:19 +0800 Subject: [PATCH 14/15] update finality reward distribution logic --- contracts/BSCValidatorSet.sol | 16 ++++++++++++++-- contracts/BSCValidatorSet.template | 24 ++++++++++++++---------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/contracts/BSCValidatorSet.sol b/contracts/BSCValidatorSet.sol index 3b4373ed..ccf780b8 100644 --- a/contracts/BSCValidatorSet.sol +++ b/contracts/BSCValidatorSet.sol @@ -76,10 +76,12 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica uint256 public maxNumOfWorkingCandidates; // BEP-126 Fast Finality - uint256 public constant INIT_FINALITY_REWARD_RATIO = 10; + uint256 public constant INIT_FINALITY_REWARD_RATIO = 50; + uint256 public constant MAX_SYSTEM_REWARD_BALANCE = 100 ether; uint256 public finalityRewardRatio; uint256 public previousHeight; + uint256 public previousBalanceOfSystemReward; struct Validator { address consensusAddress; @@ -537,13 +539,23 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } function distributeFinalityReward(address[] calldata valAddrs, uint256[] calldata weights) external onlyCoinbase oncePerBlock onlyInit { + // first time to call this function if (finalityRewardRatio == 0) { finalityRewardRatio = INIT_FINALITY_REWARD_RATIO; + previousBalanceOfSystemReward = address(SYSTEM_REWARD_ADDR).balance; + return; } uint256 totalValue; - totalValue = (address(SYSTEM_REWARD_ADDR).balance * finalityRewardRatio) / 100; + uint256 balanceOfSystemReward = address(SYSTEM_REWARD_ADDR).balance; + if (balanceOfSystemReward > MAX_SYSTEM_REWARD_BALANCE) { + totalValue = balanceOfSystemReward/100; + } else if (balanceOfSystemReward > previousBalanceOfSystemReward) { + totalValue = (balanceOfSystemReward - previousBalanceOfSystemReward)*finalityRewardRatio/100; + } + totalValue = ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(payable(address(this)), totalValue); + previousBalanceOfSystemReward = address(SYSTEM_REWARD_ADDR).balance; if (totalValue == 0) { return; } diff --git a/contracts/BSCValidatorSet.template b/contracts/BSCValidatorSet.template index 1ae539f7..398eaab1 100644 --- a/contracts/BSCValidatorSet.template +++ b/contracts/BSCValidatorSet.template @@ -76,10 +76,12 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica uint256 public maxNumOfWorkingCandidates; // BEP-126 Fast Finality - uint256 public constant INIT_FINALITY_REWARD_RATIO = 10; + uint256 public constant INIT_FINALITY_REWARD_RATIO = 50; + uint256 public constant MAX_SYSTEM_REWARD_BALANCE = 100 ether; uint256 public finalityRewardRatio; uint256 public previousHeight; + uint256 public previousBalanceOfSystemReward; struct Validator { address consensusAddress; @@ -537,22 +539,24 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } function distributeFinalityReward(address[] calldata valAddrs, uint256[] calldata weights) external onlyCoinbase oncePerBlock onlyInit { + // first time to call this function if (finalityRewardRatio == 0) { finalityRewardRatio = INIT_FINALITY_REWARD_RATIO; + previousBalanceOfSystemReward = address(SYSTEM_REWARD_ADDR).balance; + return; } uint256 totalValue; - totalValue = (address(SYSTEM_REWARD_ADDR).balance * finalityRewardRatio) / 100; - totalValue = ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(payable(address(this)), totalValue); - if (totalValue == 0) { - return; + uint256 balanceOfSystemReward = address(SYSTEM_REWARD_ADDR).balance; + if (balanceOfSystemReward > MAX_SYSTEM_REWARD_BALANCE) { + totalValue = balanceOfSystemReward/100; + } else if (balanceOfSystemReward > previousBalanceOfSystemReward) { + totalValue = (balanceOfSystemReward - previousBalanceOfSystemReward)*finalityRewardRatio/100; } - uint256 totalWeight; - for (uint256 i; i Date: Thu, 6 Apr 2023 16:43:59 +0800 Subject: [PATCH 15/15] update reward calculation using SafeMath lib --- contracts/BSCValidatorSet.sol | 12 +++++++----- contracts/BSCValidatorSet.template | 12 +++++++----- test/ValidatorSet.t.sol | 17 +++++++++++------ 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/contracts/BSCValidatorSet.sol b/contracts/BSCValidatorSet.sol index ccf780b8..c0ef234a 100644 --- a/contracts/BSCValidatorSet.sol +++ b/contracts/BSCValidatorSet.sol @@ -548,10 +548,12 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica uint256 totalValue; uint256 balanceOfSystemReward = address(SYSTEM_REWARD_ADDR).balance; - if (balanceOfSystemReward > MAX_SYSTEM_REWARD_BALANCE) { - totalValue = balanceOfSystemReward/100; - } else if (balanceOfSystemReward > previousBalanceOfSystemReward) { - totalValue = (balanceOfSystemReward - previousBalanceOfSystemReward)*finalityRewardRatio/100; + if (balanceOfSystemReward.sub(MAX_SYSTEM_REWARD_BALANCE) > 0) { + totalValue = balanceOfSystemReward.div(100); + } else if (balanceOfSystemReward.sub(previousBalanceOfSystemReward) > 0) { + totalValue = (balanceOfSystemReward.sub(previousBalanceOfSystemReward).mul(finalityRewardRatio).div(100)); + } else { + return; } totalValue = ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(payable(address(this)), totalValue); @@ -735,7 +737,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } else if (Memory.compareStrings(key, "finalityRewardRatio")) { require(value.length == 32, "length of finalityRewardRatio mismatch"); uint256 newFinalityRewardRatio = BytesToTypes.bytesToUint256(32, value); - require(newFinalityRewardRatio >= 1 && newFinalityRewardRatio < 100, "the finalityRewardRatio is out of range"); + require(newFinalityRewardRatio >= 1 && newFinalityRewardRatio <= 100, "the finalityRewardRatio is out of range"); finalityRewardRatio = newFinalityRewardRatio; } else { require(false, "unknown param"); diff --git a/contracts/BSCValidatorSet.template b/contracts/BSCValidatorSet.template index 398eaab1..2cf17430 100644 --- a/contracts/BSCValidatorSet.template +++ b/contracts/BSCValidatorSet.template @@ -548,10 +548,12 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica uint256 totalValue; uint256 balanceOfSystemReward = address(SYSTEM_REWARD_ADDR).balance; - if (balanceOfSystemReward > MAX_SYSTEM_REWARD_BALANCE) { - totalValue = balanceOfSystemReward/100; - } else if (balanceOfSystemReward > previousBalanceOfSystemReward) { - totalValue = (balanceOfSystemReward - previousBalanceOfSystemReward)*finalityRewardRatio/100; + if (balanceOfSystemReward.sub(MAX_SYSTEM_REWARD_BALANCE) > 0) { + totalValue = balanceOfSystemReward.div(100); + } else if (balanceOfSystemReward.sub(previousBalanceOfSystemReward) > 0) { + totalValue = (balanceOfSystemReward.sub(previousBalanceOfSystemReward).mul(finalityRewardRatio).div(100)); + } else { + return; } totalValue = ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(payable(address(this)), totalValue); @@ -727,7 +729,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } else if (Memory.compareStrings(key, "finalityRewardRatio")) { require(value.length == 32, "length of finalityRewardRatio mismatch"); uint256 newFinalityRewardRatio = BytesToTypes.bytesToUint256(32, value); - require(newFinalityRewardRatio >= 1 && newFinalityRewardRatio < 100, "the finalityRewardRatio is out of range"); + require(newFinalityRewardRatio >= 1 && newFinalityRewardRatio <= 100, "the finalityRewardRatio is out of range"); finalityRewardRatio = newFinalityRewardRatio; } else { require(false, "unknown param"); diff --git a/test/ValidatorSet.t.sol b/test/ValidatorSet.t.sol index f2173762..5f840b76 100644 --- a/test/ValidatorSet.t.sol +++ b/test/ValidatorSet.t.sol @@ -540,19 +540,24 @@ contract ValidatorSetTest is Deployer { weights[i] = 1; } - vm.deal(address(systemReward), 1 ether); + vm.deal(address(systemReward), 99 ether); vm.expectRevert(bytes("the message sender must be the block producer")); validator.distributeFinalityReward(addrs, weights); + // first time distribution will init the config and return + vm.startPrank(address(coinbase)); + validator.distributeFinalityReward(addrs, weights); + vm.deal(address(systemReward), 100 ether); + vm.roll(block.number + 1); + vm.expectEmit(true, false, false, true, address(validator)); - emit finalityRewardDeposit(addrs[0], 5e15); + emit finalityRewardDeposit(addrs[0], 25e15); vm.expectEmit(true, false, false, true, address(validator)); - emit finalityRewardDeposit(addrs[9], 5e15); + emit finalityRewardDeposit(addrs[9], 25e15); vm.expectEmit(true, false, false, true, address(validator)); - emit deprecatedFinalityRewardDeposit(addrs[10], 5e15); + emit deprecatedFinalityRewardDeposit(addrs[10], 25e15); vm.expectEmit(true, false, false, true, address(validator)); - emit deprecatedFinalityRewardDeposit(addrs[19], 5e15); - vm.startPrank(address(coinbase)); + emit deprecatedFinalityRewardDeposit(addrs[19], 25e15); validator.distributeFinalityReward(addrs, weights); vm.stopPrank(); }