From 1d9c1e2ef7a0dc83a8d2fac45e826ecd8a068013 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 15 Nov 2022 10:27:44 +0000 Subject: [PATCH 01/90] Add new proposed functions skeleton --- contracts/RelayerHub.sol | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index f4545dbc..3f81133c 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -19,6 +19,8 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ mapping(address =>relayer) relayers; mapping(address =>bool) relayersExistMap; + mapping(address =>bool) relayAdminsExistMap; + mapping(address =>address) adminsAndRelayers; struct relayer{ uint256 deposit; @@ -83,6 +85,12 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ uint256 newDues = BytesToTypes.bytesToUint256(32, value); require(newDues > 0 && newDues < requiredDeposit, "the dues out of range"); dues = newDues; + } else if (Memory.compareStrings(key,"addAdmin")) { + // TODO check and parse value + // addAdminAddress(...) + } else if (Memory.compareStrings(key,"removeAdmin")) { + // TODO check and parse value + // removeAdminAddress(...) } else { require(false, "unknown param"); } @@ -92,4 +100,32 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ function isRelayer(address sender) external override view returns (bool) { return relayersExistMap[sender]; } + + function removeAdminAddress(address) external onlyGov{ + + } + + function removeAdmin() external onlyAdmin { + + } + + function addAdminAddress(address) external onlyGov{ + + } + + function registerAdmin() external payable onlyAdmin { + + } + + function addRelayer(address) external onlyAdmin{ + + } + + function registerAdminAddRelayer(address) external payable onlyAdmin { + + } + + function removeRelayer() external onlyAdmin { + + } } From 9c9423afdc6c6b925a6d1004bd3c3bd66d056bb3 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 15 Nov 2022 12:24:32 +0000 Subject: [PATCH 02/90] admin struct & removeAdminAddress code --- contracts/RelayerHub.sol | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 3f81133c..f01039f7 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -19,6 +19,8 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ mapping(address =>relayer) relayers; mapping(address =>bool) relayersExistMap; + + mapping(address =>admin) admins; mapping(address =>bool) relayAdminsExistMap; mapping(address =>address) adminsAndRelayers; @@ -27,6 +29,11 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ uint256 dues; } + struct admin{ + uint256 deposit; + uint256 dues; + } + modifier notContract() { require(!isContract(msg.sender), "contract is not allowed to be a relayer"); _; @@ -51,6 +58,8 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); + event removeAdminAddress(address _removedAdmin); + function init() external onlyNotInit{ requiredDeposit = INIT_REQUIRED_DEPOSIT; @@ -101,8 +110,23 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ return relayersExistMap[sender]; } - function removeAdminAddress(address) external onlyGov{ + function removeAdminAddress(address adminToBeRemoved) external onlyGov{ + // todo more pre-checks if any + + // check if the admin address already exists + require(relayAdminsExistMap[adminToBeRemoved], "admin doesn't exist"); + + delete(relayAdminsExistMap[adminToBeRemoved]); + delete(adminsAndRelayers[adminToBeRemoved]); + + // todo transfer dues and deposits BNB -> check + admin memory a = admins[adminToBeRemoved]; + adminToBeRemoved.transfer(a.deposit.sub(a.dues)); + address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); + systemPayable.transfer(a.dues); + // emit success event + emit removeAdminAddress(adminToBeRemoved); } function removeAdmin() external onlyAdmin { From 646ba57f7a7d83ac8686b904752b32910cb85562 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 15 Nov 2022 12:41:55 +0000 Subject: [PATCH 03/90] remove, register, add admin + onlyAdmin modifier --- contracts/RelayerHub.sol | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index f01039f7..615891a9 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -54,11 +54,18 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ _; } + modifier onlyAdmin() { + require(admins[msg.sender], "admin does not exist"); + _; + } + event relayerRegister(address _relayer); event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); event removeAdminAddress(address _removedAdmin); + event addAdminAddress(address _addedAdmin); + event registerAdmin(address _registeredAdmin); function init() external onlyNotInit{ @@ -111,7 +118,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ } function removeAdminAddress(address adminToBeRemoved) external onlyGov{ - // todo more pre-checks if any + // fixme more pre-checks if any // check if the admin address already exists require(relayAdminsExistMap[adminToBeRemoved], "admin doesn't exist"); @@ -119,7 +126,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ delete(relayAdminsExistMap[adminToBeRemoved]); delete(adminsAndRelayers[adminToBeRemoved]); - // todo transfer dues and deposits BNB -> check + // fixme transfer dues and deposits BNB -> check admin memory a = admins[adminToBeRemoved]; adminToBeRemoved.transfer(a.deposit.sub(a.dues)); address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); @@ -130,15 +137,37 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ } function removeAdmin() external onlyAdmin { + // here the admin removes himself + // check if the admin address already exists + require(relayAdminsExistMap[msg.sender], "admin doesn't exist"); + + delete(relayAdminsExistMap[msg.sender]); + delete(adminsAndRelayers[msg.sender]); + // fixme transfer dues and deposits BNB -> check + admin memory a = admins[msg.sender]; + msg.sender.transfer(a.deposit.sub(a.dues)); + address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); + systemPayable.transfer(a.dues); + + // emit success event + emit removeAdminAddress(msg.sender); } - function addAdminAddress(address) external onlyGov{ + function addAdminAddress(address adminToBeAdded) external onlyGov{ + require(!relayAdminsExistMap[adminToBeAdded], "admin already exists"); + relayAdminsExistMap[adminToBeAdded] = true; + // admins[adminToBeAdded] = admin(requiredDeposit, dues); todo this will be done when admin registers himself in registerAdmin(?) + + emit addAdminAddress(adminToBeAdded); } function registerAdmin() external payable onlyAdmin { - + require(relayAdminsExistMap[msg.sender], "admin not added by Gov yet"); + require(msg.value == requiredDeposit, "deposit value is not exactly the same"); + admins[msg.sender] = admin(requiredDeposit, dues); + emit registerAdmin(msg.sender); } function addRelayer(address) external onlyAdmin{ From 2747fcb83f3bbfa62b21ba0fc2be977759132c1c Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 15 Nov 2022 13:23:21 +0000 Subject: [PATCH 04/90] add relayer functions --- contracts/RelayerHub.sol | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 615891a9..e0bc8ab8 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -55,6 +55,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ } modifier onlyAdmin() { + require(relayAdminsExistMap[msg.sender], "admin does not exist"); require(admins[msg.sender], "admin does not exist"); _; } @@ -66,6 +67,8 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ event removeAdminAddress(address _removedAdmin); event addAdminAddress(address _addedAdmin); event registerAdmin(address _registeredAdmin); + event addRelayer(address _relayerToBeAdded); + event removeRelayer(address _removedRelayer); function init() external onlyNotInit{ @@ -102,10 +105,10 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ require(newDues > 0 && newDues < requiredDeposit, "the dues out of range"); dues = newDues; } else if (Memory.compareStrings(key,"addAdmin")) { - // TODO check and parse value + // fixme check and parse value // addAdminAddress(...) } else if (Memory.compareStrings(key,"removeAdmin")) { - // TODO check and parse value + // fixme check and parse value // removeAdminAddress(...) } else { require(false, "unknown param"); @@ -164,21 +167,27 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ } function registerAdmin() external payable onlyAdmin { - require(relayAdminsExistMap[msg.sender], "admin not added by Gov yet"); +// require(relayAdminsExistMap[msg.sender], "admin not added by Gov yet"); require(msg.value == requiredDeposit, "deposit value is not exactly the same"); admins[msg.sender] = admin(requiredDeposit, dues); emit registerAdmin(msg.sender); } - function addRelayer(address) external onlyAdmin{ - + function addRelayer(address relayerToBeAdded) external onlyAdmin{ + adminsAndRelayers[msg.sender] = relayerToBeAdded; + emit addRelayer(relayerToBeAdded); } - function registerAdminAddRelayer(address) external payable onlyAdmin { - + function registerAdminAddRelayer(address relayer) external payable onlyAdmin { + registerAdmin(); + addRelayer(relayer); } function removeRelayer() external onlyAdmin { + require(adminsAndRelayers[msg.sender], "relayer doesn't exist for this admin"); + emit removeRelayer(adminsAndRelayers[msg.sender]); + + delete(adminsAndRelayers[msg.sender]); } } From 0065836537df01775a13a63706526129602b087a Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 16 Nov 2022 08:23:19 +0000 Subject: [PATCH 05/90] helper function to avoid repeat of code --- contracts/RelayerHub.sol | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index e0bc8ab8..96417306 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -122,39 +122,29 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ function removeAdminAddress(address adminToBeRemoved) external onlyGov{ // fixme more pre-checks if any - - // check if the admin address already exists - require(relayAdminsExistMap[adminToBeRemoved], "admin doesn't exist"); - - delete(relayAdminsExistMap[adminToBeRemoved]); - delete(adminsAndRelayers[adminToBeRemoved]); - - // fixme transfer dues and deposits BNB -> check - admin memory a = admins[adminToBeRemoved]; - adminToBeRemoved.transfer(a.deposit.sub(a.dues)); - address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); - systemPayable.transfer(a.dues); - - // emit success event - emit removeAdminAddress(adminToBeRemoved); + removeAdminHelper(adminToBeRemoved); } function removeAdmin() external onlyAdmin { // here the admin removes himself + removeAdminHelper(msg.sender); + } + + function removeAdminHelper(address adminAddress) { // check if the admin address already exists - require(relayAdminsExistMap[msg.sender], "admin doesn't exist"); + require(relayAdminsExistMap[adminAddress], "admin doesn't exist"); - delete(relayAdminsExistMap[msg.sender]); - delete(adminsAndRelayers[msg.sender]); + delete(relayAdminsExistMap[adminAddress]); + delete(adminsAndRelayers[adminAddress]); // fixme transfer dues and deposits BNB -> check - admin memory a = admins[msg.sender]; - msg.sender.transfer(a.deposit.sub(a.dues)); + admin memory a = admins[adminAddress]; + adminAddress.transfer(a.deposit.sub(a.dues)); address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); systemPayable.transfer(a.dues); // emit success event - emit removeAdminAddress(msg.sender); + emit removeAdminAddress(adminAddress); } function addAdminAddress(address adminToBeAdded) external onlyGov{ From 981c2256f0777c5bbab74c48c2937332f29d7a6a Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 16 Nov 2022 21:15:38 +0000 Subject: [PATCH 06/90] verifyRelayer and relayerExistsMap --- contracts/RelayerHub.sol | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 96417306..5a46e910 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -23,6 +23,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ mapping(address =>admin) admins; mapping(address =>bool) relayAdminsExistMap; mapping(address =>address) adminsAndRelayers; + mapping(address =>bool) relayerExistsMap; struct relayer{ uint256 deposit; @@ -121,7 +122,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ } function removeAdminAddress(address adminToBeRemoved) external onlyGov{ - // fixme more pre-checks if any removeAdminHelper(adminToBeRemoved); } @@ -137,7 +137,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ delete(relayAdminsExistMap[adminAddress]); delete(adminsAndRelayers[adminAddress]); - // fixme transfer dues and deposits BNB -> check admin memory a = admins[adminAddress]; adminAddress.transfer(a.deposit.sub(a.dues)); address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); @@ -151,7 +150,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ require(!relayAdminsExistMap[adminToBeAdded], "admin already exists"); relayAdminsExistMap[adminToBeAdded] = true; - // admins[adminToBeAdded] = admin(requiredDeposit, dues); todo this will be done when admin registers himself in registerAdmin(?) emit addAdminAddress(adminToBeAdded); } @@ -165,6 +163,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ function addRelayer(address relayerToBeAdded) external onlyAdmin{ adminsAndRelayers[msg.sender] = relayerToBeAdded; + relayerExistsMap[relayerToBeAdded] = true; emit addRelayer(relayerToBeAdded); } @@ -179,5 +178,16 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ emit removeRelayer(adminsAndRelayers[msg.sender]); delete(adminsAndRelayers[msg.sender]); + + relayer memory r = adminsAndRelayers[msg.sender]; + + delete(relayerExistsMap[r]); + } + + function verifyRelayer(address relayerAddress) external returns (bool){ + if (relayerExistsMap[relayerAddress]) { + return true; + } + return false; } } From d31bc5da88d44f46695f9dffacea091570d767e1 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 16 Nov 2022 21:21:04 +0000 Subject: [PATCH 07/90] updateParam changes --- contracts/RelayerHub.sol | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 5a46e910..0fb521bd 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -106,11 +106,17 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ require(newDues > 0 && newDues < requiredDeposit, "the dues out of range"); dues = newDues; } else if (Memory.compareStrings(key,"addAdmin")) { - // fixme check and parse value - // addAdminAddress(...) + + require(value.length == 32, "length of admin address mismatch"); // fixme: check if the length is correct + address newAdmin = BytesToTypes.bytesToAddress(32, value); + addAdminAddress(newAdmin); + } else if (Memory.compareStrings(key,"removeAdmin")) { - // fixme check and parse value - // removeAdminAddress(...) + + require(value.length == 32, "length of admin address mismatch"); + address admin = BytesToTypes.bytesToAddress(32, value); + removeAdminAddress(admin); + } else { require(false, "unknown param"); } From 7513b3ff4d92f7d0f294e2388e47c490329928bc Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 16 Nov 2022 21:44:00 +0000 Subject: [PATCH 08/90] Remove unwanted code and variables --- contracts/RelayerHub.sol | 47 ---------------------------------------- 1 file changed, 47 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 0fb521bd..01972753 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -17,44 +17,16 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ uint256 public requiredDeposit; uint256 public dues; - mapping(address =>relayer) relayers; - mapping(address =>bool) relayersExistMap; - mapping(address =>admin) admins; mapping(address =>bool) relayAdminsExistMap; mapping(address =>address) adminsAndRelayers; mapping(address =>bool) relayerExistsMap; - struct relayer{ - uint256 deposit; - uint256 dues; - } - struct admin{ uint256 deposit; uint256 dues; } - modifier notContract() { - require(!isContract(msg.sender), "contract is not allowed to be a relayer"); - _; - } - - modifier noProxy() { - require(msg.sender == tx.origin, "no proxy is allowed"); - _; - } - - modifier noExist() { - require(!relayersExistMap[msg.sender], "relayer already exist"); - _; - } - - modifier exist() { - require(relayersExistMap[msg.sender], "relayer do not exist"); - _; - } - modifier onlyAdmin() { require(relayAdminsExistMap[msg.sender], "admin does not exist"); require(admins[msg.sender], "admin does not exist"); @@ -77,21 +49,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ dues = INIT_DUES; alreadyInit = true; } - - function register() external payable noExist onlyInit notContract noProxy{ - revert("register suspended"); - } - - - function unregister() external exist onlyInit{ - relayer memory r = relayers[msg.sender]; - msg.sender.transfer(r.deposit.sub(r.dues)); - address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); - systemPayable.transfer(r.dues); - delete relayersExistMap[msg.sender]; - delete relayers[msg.sender]; - emit relayerUnRegister(msg.sender); - } /*********************** Param update ********************************/ function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov{ @@ -123,10 +80,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ emit paramChange(key, value); } - function isRelayer(address sender) external override view returns (bool) { - return relayersExistMap[sender]; - } - function removeAdminAddress(address adminToBeRemoved) external onlyGov{ removeAdminHelper(adminToBeRemoved); } From 38224e572dc1735d7894fcd6087768ed3a092e1d Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 16 Nov 2022 21:51:28 +0000 Subject: [PATCH 09/90] Remove old code --- contracts/RelayerHub.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 01972753..4fbb1e07 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -114,7 +114,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ } function registerAdmin() external payable onlyAdmin { -// require(relayAdminsExistMap[msg.sender], "admin not added by Gov yet"); require(msg.value == requiredDeposit, "deposit value is not exactly the same"); admins[msg.sender] = admin(requiredDeposit, dues); emit registerAdmin(msg.sender); From 5a5bb13f091e0946c9d3dafb1110cfd7a9d7d126 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Thu, 17 Nov 2022 12:53:35 +0000 Subject: [PATCH 10/90] Formatting + efficient return for verify function --- contracts/RelayerHub.sol | 238 +++++++++++++++++++-------------------- 1 file changed, 118 insertions(+), 120 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 4fbb1e07..c9531abb 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -8,144 +8,142 @@ import "./System.sol"; import "./lib/SafeMath.sol"; -contract RelayerHub is IRelayerHub, System, IParamSubscriber{ - using SafeMath for uint256; - - uint256 public constant INIT_REQUIRED_DEPOSIT = 1e20; - uint256 public constant INIT_DUES = 1e17; - - uint256 public requiredDeposit; - uint256 public dues; - - mapping(address =>admin) admins; - mapping(address =>bool) relayAdminsExistMap; - mapping(address =>address) adminsAndRelayers; - mapping(address =>bool) relayerExistsMap; - - struct admin{ - uint256 deposit; - uint256 dues; - } - - modifier onlyAdmin() { - require(relayAdminsExistMap[msg.sender], "admin does not exist"); - require(admins[msg.sender], "admin does not exist"); - _; - } - - event relayerRegister(address _relayer); - event relayerUnRegister(address _relayer); - event paramChange(string key, bytes value); - - event removeAdminAddress(address _removedAdmin); - event addAdminAddress(address _addedAdmin); - event registerAdmin(address _registeredAdmin); - event addRelayer(address _relayerToBeAdded); - event removeRelayer(address _removedRelayer); - - - function init() external onlyNotInit{ - requiredDeposit = INIT_REQUIRED_DEPOSIT; - dues = INIT_DUES; - alreadyInit = true; - } - - /*********************** Param update ********************************/ - function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov{ - if (Memory.compareStrings(key,"requiredDeposit")) { - require(value.length == 32, "length of requiredDeposit mismatch"); - uint256 newRequiredDeposit = BytesToTypes.bytesToUint256(32, value); - require(newRequiredDeposit > 1 && newRequiredDeposit <= 1e21 && newRequiredDeposit > dues, "the requiredDeposit out of range"); - requiredDeposit = newRequiredDeposit; - } else if (Memory.compareStrings(key,"dues")) { - require(value.length == 32, "length of dues mismatch"); - uint256 newDues = BytesToTypes.bytesToUint256(32, value); - require(newDues > 0 && newDues < requiredDeposit, "the dues out of range"); - dues = newDues; - } else if (Memory.compareStrings(key,"addAdmin")) { - - require(value.length == 32, "length of admin address mismatch"); // fixme: check if the length is correct - address newAdmin = BytesToTypes.bytesToAddress(32, value); - addAdminAddress(newAdmin); - - } else if (Memory.compareStrings(key,"removeAdmin")) { - - require(value.length == 32, "length of admin address mismatch"); - address admin = BytesToTypes.bytesToAddress(32, value); - removeAdminAddress(admin); - - } else { - require(false, "unknown param"); +contract RelayerHub is IRelayerHub, System, IParamSubscriber { + using SafeMath for uint256; + + uint256 public constant INIT_REQUIRED_DEPOSIT = 1e20; + uint256 public constant INIT_DUES = 1e17; + + uint256 public requiredDeposit; + uint256 public dues; + + mapping(address => admin) admins; + mapping(address => bool) relayAdminsExistMap; + mapping(address => address) adminsAndRelayers; + mapping(address => bool) relayerExistsMap; + + struct admin { + uint256 deposit; + uint256 dues; } - emit paramChange(key, value); - } - function removeAdminAddress(address adminToBeRemoved) external onlyGov{ - removeAdminHelper(adminToBeRemoved); - } + modifier onlyAdmin() { + require(relayAdminsExistMap[msg.sender], "admin does not exist"); + require(admins[msg.sender], "admin does not exist"); + _; + } - function removeAdmin() external onlyAdmin { - // here the admin removes himself - removeAdminHelper(msg.sender); - } + event relayerRegister(address _relayer); + event relayerUnRegister(address _relayer); + event paramChange(string key, bytes value); - function removeAdminHelper(address adminAddress) { - // check if the admin address already exists - require(relayAdminsExistMap[adminAddress], "admin doesn't exist"); + event removeAdminAddress(address _removedAdmin); + event addAdminAddress(address _addedAdmin); + event registerAdmin(address _registeredAdmin); + event addRelayer(address _relayerToBeAdded); + event removeRelayer(address _removedRelayer); - delete(relayAdminsExistMap[adminAddress]); - delete(adminsAndRelayers[adminAddress]); - admin memory a = admins[adminAddress]; - adminAddress.transfer(a.deposit.sub(a.dues)); - address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); - systemPayable.transfer(a.dues); + function init() external onlyNotInit { + requiredDeposit = INIT_REQUIRED_DEPOSIT; + dues = INIT_DUES; + alreadyInit = true; + } - // emit success event - emit removeAdminAddress(adminAddress); - } + /*********************** Param update ********************************/ + function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov { + if (Memory.compareStrings(key, "requiredDeposit")) { + require(value.length == 32, "length of requiredDeposit mismatch"); + uint256 newRequiredDeposit = BytesToTypes.bytesToUint256(32, value); + require(newRequiredDeposit > 1 && newRequiredDeposit <= 1e21 && newRequiredDeposit > dues, "the requiredDeposit out of range"); + requiredDeposit = newRequiredDeposit; + } else if (Memory.compareStrings(key, "dues")) { + require(value.length == 32, "length of dues mismatch"); + uint256 newDues = BytesToTypes.bytesToUint256(32, value); + require(newDues > 0 && newDues < requiredDeposit, "the dues out of range"); + dues = newDues; + } else if (Memory.compareStrings(key, "addAdmin")) { + + require(value.length == 32, "length of admin address mismatch"); + // fixme: check if the length is correct + address newAdmin = BytesToTypes.bytesToAddress(32, value); + addAdminAddress(newAdmin); + + } else if (Memory.compareStrings(key, "removeAdmin")) { + + require(value.length == 32, "length of admin address mismatch"); + address admin = BytesToTypes.bytesToAddress(32, value); + removeAdminAddress(admin); + + } else { + require(false, "unknown param"); + } + emit paramChange(key, value); + } - function addAdminAddress(address adminToBeAdded) external onlyGov{ - require(!relayAdminsExistMap[adminToBeAdded], "admin already exists"); + function removeAdminAddress(address adminToBeRemoved) external onlyGov { + removeAdminHelper(adminToBeRemoved); + } - relayAdminsExistMap[adminToBeAdded] = true; + function removeAdmin() external onlyAdmin { + // here the admin removes himself + removeAdminHelper(msg.sender); + } - emit addAdminAddress(adminToBeAdded); - } + function removeAdminHelper(address adminAddress) { + // check if the admin address already exists + require(relayAdminsExistMap[adminAddress], "admin doesn't exist"); - function registerAdmin() external payable onlyAdmin { - require(msg.value == requiredDeposit, "deposit value is not exactly the same"); - admins[msg.sender] = admin(requiredDeposit, dues); - emit registerAdmin(msg.sender); - } + delete (relayAdminsExistMap[adminAddress]); + delete (adminsAndRelayers[adminAddress]); - function addRelayer(address relayerToBeAdded) external onlyAdmin{ - adminsAndRelayers[msg.sender] = relayerToBeAdded; - relayerExistsMap[relayerToBeAdded] = true; - emit addRelayer(relayerToBeAdded); - } + admin memory a = admins[adminAddress]; + adminAddress.transfer(a.deposit.sub(a.dues)); + address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); + systemPayable.transfer(a.dues); - function registerAdminAddRelayer(address relayer) external payable onlyAdmin { - registerAdmin(); - addRelayer(relayer); - } + // emit success event + emit removeAdminAddress(adminAddress); + } - function removeRelayer() external onlyAdmin { - require(adminsAndRelayers[msg.sender], "relayer doesn't exist for this admin"); + function addAdminAddress(address adminToBeAdded) external onlyGov { + require(!relayAdminsExistMap[adminToBeAdded], "admin already exists"); - emit removeRelayer(adminsAndRelayers[msg.sender]); + relayAdminsExistMap[adminToBeAdded] = true; - delete(adminsAndRelayers[msg.sender]); + emit addAdminAddress(adminToBeAdded); + } - relayer memory r = adminsAndRelayers[msg.sender]; + function registerAdmin() external payable onlyAdmin { + require(msg.value == requiredDeposit, "deposit value is not exactly the same"); + admins[msg.sender] = admin(requiredDeposit, dues); + emit registerAdmin(msg.sender); + } + + function addRelayer(address relayerToBeAdded) external onlyAdmin { + adminsAndRelayers[msg.sender] = relayerToBeAdded; + relayerExistsMap[relayerToBeAdded] = true; + emit addRelayer(relayerToBeAdded); + } + + function registerAdminAddRelayer(address relayer) external payable onlyAdmin { + registerAdmin(); + addRelayer(relayer); + } - delete(relayerExistsMap[r]); - } + function removeRelayer() external onlyAdmin { + require(adminsAndRelayers[msg.sender], "relayer doesn't exist for this admin"); + + emit removeRelayer(adminsAndRelayers[msg.sender]); + + delete (adminsAndRelayers[msg.sender]); + + relayer memory r = adminsAndRelayers[msg.sender]; + + delete (relayerExistsMap[r]); + } - function verifyRelayer(address relayerAddress) external returns (bool){ - if (relayerExistsMap[relayerAddress]) { - return true; + function verifyRelayer(address relayerAddress) external returns (bool){ + return relayerExistsMap[relayerAddress]; } - return false; - } } From a40d34c86a7a7a448fadcf8bc354facba7078094 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Thu, 17 Nov 2022 13:11:13 +0000 Subject: [PATCH 11/90] decouple registered and nonregistered admins, remove relayer before deleting, correct address size, --- contracts/RelayerHub.sol | 42 +++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index c9531abb..733b47ca 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -27,9 +27,14 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { uint256 dues; } - modifier onlyAdmin() { + modifier onlyNonRegisteredAdmin() { require(relayAdminsExistMap[msg.sender], "admin does not exist"); - require(admins[msg.sender], "admin does not exist"); + _; + } + + modifier onlyRegisteredAdmin() { + require(relayAdminsExistMap[msg.sender], "admin does not exist"); + require(admins[msg.sender], "admin not registered"); _; } @@ -64,15 +69,14 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { dues = newDues; } else if (Memory.compareStrings(key, "addAdmin")) { - require(value.length == 32, "length of admin address mismatch"); - // fixme: check if the length is correct - address newAdmin = BytesToTypes.bytesToAddress(32, value); + require(value.length == 20, "length of admin address mismatch"); + address newAdmin = BytesToTypes.bytesToAddress(20, value); addAdminAddress(newAdmin); } else if (Memory.compareStrings(key, "removeAdmin")) { - require(value.length == 32, "length of admin address mismatch"); - address admin = BytesToTypes.bytesToAddress(32, value); + require(value.length == 20, "length of admin address mismatch"); + address admin = BytesToTypes.bytesToAddress(20, value); removeAdminAddress(admin); } else { @@ -85,7 +89,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { removeAdminHelper(adminToBeRemoved); } - function removeAdmin() external onlyAdmin { + function removeAdmin() external onlyRegisteredAdmin { // here the admin removes himself removeAdminHelper(msg.sender); } @@ -94,6 +98,8 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // check if the admin address already exists require(relayAdminsExistMap[adminAddress], "admin doesn't exist"); + relayer memory relayerAddress = adminsAndRelayers[adminAddress]; + delete (relayAdminsExistMap[adminAddress]); delete (adminsAndRelayers[adminAddress]); @@ -102,8 +108,13 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); systemPayable.transfer(a.dues); + delete (admins[adminAddress]); + // emit success event emit removeAdminAddress(adminAddress); + if (relayerAddress != address(0)) { + emit removeRelayer(relayerAddress); + } } function addAdminAddress(address adminToBeAdded) external onlyGov { @@ -114,33 +125,32 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit addAdminAddress(adminToBeAdded); } - function registerAdmin() external payable onlyAdmin { + function registerAdmin() external payable onlyNonRegisteredAdmin { require(msg.value == requiredDeposit, "deposit value is not exactly the same"); admins[msg.sender] = admin(requiredDeposit, dues); emit registerAdmin(msg.sender); } - function addRelayer(address relayerToBeAdded) external onlyAdmin { + function addRelayer(address relayerToBeAdded) external onlyRegisteredAdmin { adminsAndRelayers[msg.sender] = relayerToBeAdded; relayerExistsMap[relayerToBeAdded] = true; emit addRelayer(relayerToBeAdded); } - function registerAdminAddRelayer(address relayer) external payable onlyAdmin { + function registerAdminAddRelayer(address relayer) external payable onlyNonRegisteredAdmin { registerAdmin(); addRelayer(relayer); } - function removeRelayer() external onlyAdmin { + function removeRelayer() external onlyRegisteredAdmin { require(adminsAndRelayers[msg.sender], "relayer doesn't exist for this admin"); - emit removeRelayer(adminsAndRelayers[msg.sender]); - - delete (adminsAndRelayers[msg.sender]); - relayer memory r = adminsAndRelayers[msg.sender]; delete (relayerExistsMap[r]); + delete (adminsAndRelayers[msg.sender]); + + emit removeRelayer(r); } function verifyRelayer(address relayerAddress) external returns (bool){ From 744819c173127016231eb340cc3e6d4ed436bd83 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Thu, 17 Nov 2022 13:16:34 +0000 Subject: [PATCH 12/90] add old modifier checks before adding relayer --- contracts/RelayerHub.sol | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 733b47ca..6173664c 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -38,6 +38,21 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { _; } + modifier notContract() { + require(!isContract(msg.sender), "contract is not allowed to be a relayer"); + _; + } + + modifier noProxy() { + require(msg.sender == tx.origin, "no proxy is allowed"); + _; + } + + modifier noExist() { + require(!relayerExistsMap[msg.sender], "relayer already exists"); + _; + } + event relayerRegister(address _relayer); event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); @@ -131,7 +146,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit registerAdmin(msg.sender); } - function addRelayer(address relayerToBeAdded) external onlyRegisteredAdmin { + function addRelayer(address relayerToBeAdded) external onlyRegisteredAdmin noExist notContract noProxy { adminsAndRelayers[msg.sender] = relayerToBeAdded; relayerExistsMap[relayerToBeAdded] = true; emit addRelayer(relayerToBeAdded); From 0994f270dda34f8a07c40a0a147a8683976b1c59 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Fri, 18 Nov 2022 08:20:49 +0000 Subject: [PATCH 13/90] seed with current whitelists.todo: add relayers --- contracts/RelayerHub.sol | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 6173664c..0a1abf4f 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -13,6 +13,8 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { uint256 public constant INIT_REQUIRED_DEPOSIT = 1e20; uint256 public constant INIT_DUES = 1e17; + address public constant WHITELIST_1 = 0xb005741528b86F5952469d80A8614591E3c5B632; + address public constant WHITELIST_2 = 0x446AA6E0DC65690403dF3F127750da1322941F3e; uint256 public requiredDeposit; uint256 public dues; @@ -68,6 +70,19 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { requiredDeposit = INIT_REQUIRED_DEPOSIT; dues = INIT_DUES; alreadyInit = true; + + // todo initialise the currently existing admins and their relayer keys + + admins[WHITELIST_1] = admin(requiredDeposit, dues); + admins[WHITELIST_2] = admin(requiredDeposit, dues); + + relayAdminsExistMap[WHITELIST_1] = true; + relayAdminsExistMap[WHITELIST_2] = true; + + adminsAndRelayers[WHITELIST_1] = WHITELIST_1; // fixme current relayer + adminsAndRelayers[WHITELIST_2] = WHITELIST_2; // fixme current relayer + + // fixme initialise relayerExistsMap } /*********************** Param update ********************************/ From 1f1135c05892557d1a8f313bf2a48109d9a82efe Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 21 Nov 2022 09:26:39 +0000 Subject: [PATCH 14/90] Refactor: replace admin with manager --- contracts/RelayerHub.sol | 114 +++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 0a1abf4f..c72bfe49 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -19,24 +19,24 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { uint256 public requiredDeposit; uint256 public dues; - mapping(address => admin) admins; - mapping(address => bool) relayAdminsExistMap; - mapping(address => address) adminsAndRelayers; + mapping(address => manager) managers; + mapping(address => bool) relayManagersExistMap; + mapping(address => address) managersAndRelayers; mapping(address => bool) relayerExistsMap; - struct admin { + struct manager { uint256 deposit; uint256 dues; } - modifier onlyNonRegisteredAdmin() { - require(relayAdminsExistMap[msg.sender], "admin does not exist"); + modifier onlyNonRegisteredManager() { + require(relayManagersExistMap[msg.sender], "manager does not exist"); _; } - modifier onlyRegisteredAdmin() { - require(relayAdminsExistMap[msg.sender], "admin does not exist"); - require(admins[msg.sender], "admin not registered"); + modifier onlyRegisteredManager() { + require(relayManagersExistMap[msg.sender], "manager does not exist"); + require(managers[msg.sender], "manager not registered"); _; } @@ -59,9 +59,9 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); - event removeAdminAddress(address _removedAdmin); - event addAdminAddress(address _addedAdmin); - event registerAdmin(address _registeredAdmin); + event removeManagerAddress(address _removedManager); + event addManagerAddress(address _addedManager); + event registerManager(address _registeredManager); event addRelayer(address _relayerToBeAdded); event removeRelayer(address _removedRelayer); @@ -71,16 +71,16 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { dues = INIT_DUES; alreadyInit = true; - // todo initialise the currently existing admins and their relayer keys + // todo initialise the currently existing Managers and their relayer keys - admins[WHITELIST_1] = admin(requiredDeposit, dues); - admins[WHITELIST_2] = admin(requiredDeposit, dues); + managers[WHITELIST_1] = manager(requiredDeposit, dues); + managers[WHITELIST_2] = manager(requiredDeposit, dues); - relayAdminsExistMap[WHITELIST_1] = true; - relayAdminsExistMap[WHITELIST_2] = true; + relayManagersExistMap[WHITELIST_1] = true; + relayManagersExistMap[WHITELIST_2] = true; - adminsAndRelayers[WHITELIST_1] = WHITELIST_1; // fixme current relayer - adminsAndRelayers[WHITELIST_2] = WHITELIST_2; // fixme current relayer + managersAndRelayers[WHITELIST_1] = WHITELIST_1; // fixme current relayer + managersAndRelayers[WHITELIST_2] = WHITELIST_2; // fixme current relayer // fixme initialise relayerExistsMap } @@ -97,17 +97,17 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { uint256 newDues = BytesToTypes.bytesToUint256(32, value); require(newDues > 0 && newDues < requiredDeposit, "the dues out of range"); dues = newDues; - } else if (Memory.compareStrings(key, "addAdmin")) { + } else if (Memory.compareStrings(key, "addManager")) { - require(value.length == 20, "length of admin address mismatch"); - address newAdmin = BytesToTypes.bytesToAddress(20, value); - addAdminAddress(newAdmin); + require(value.length == 20, "length of manager address mismatch"); + address newManager = BytesToTypes.bytesToAddress(20, value); + addManagerAddress(newManager); - } else if (Memory.compareStrings(key, "removeAdmin")) { + } else if (Memory.compareStrings(key, "removeManager")) { - require(value.length == 20, "length of admin address mismatch"); - address admin = BytesToTypes.bytesToAddress(20, value); - removeAdminAddress(admin); + require(value.length == 20, "length of manager address mismatch"); + address manager = BytesToTypes.bytesToAddress(20, value); + removeManagerAddress(manager); } else { require(false, "unknown param"); @@ -115,70 +115,70 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit paramChange(key, value); } - function removeAdminAddress(address adminToBeRemoved) external onlyGov { - removeAdminHelper(adminToBeRemoved); + function removeManagerAddress(address managerToBeRemoved) external onlyGov { + removeManagerHelper(managerToBeRemoved); } - function removeAdmin() external onlyRegisteredAdmin { - // here the admin removes himself - removeAdminHelper(msg.sender); + function removeManager() external onlyRegisteredManager { + // here the manager removes himself + removeManagerHelper(msg.sender); } - function removeAdminHelper(address adminAddress) { - // check if the admin address already exists - require(relayAdminsExistMap[adminAddress], "admin doesn't exist"); + function removeManagerHelper(address managerAddress) { + // check if the manager address already exists + require(relayManagersExistMap[managerAddress], "manager doesn't exist"); - relayer memory relayerAddress = adminsAndRelayers[adminAddress]; + relayer memory relayerAddress = managersAndRelayers[managerAddress]; - delete (relayAdminsExistMap[adminAddress]); - delete (adminsAndRelayers[adminAddress]); + delete (relayManagersExistMap[managerAddress]); + delete (managersAndRelayers[managerAddress]); - admin memory a = admins[adminAddress]; - adminAddress.transfer(a.deposit.sub(a.dues)); + manager memory a = managers[managerAddress]; + managerAddress.transfer(a.deposit.sub(a.dues)); address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); systemPayable.transfer(a.dues); - delete (admins[adminAddress]); + delete (managers[managerAddress]); // emit success event - emit removeAdminAddress(adminAddress); + emit removeManagerAddress(managerAddress); if (relayerAddress != address(0)) { emit removeRelayer(relayerAddress); } } - function addAdminAddress(address adminToBeAdded) external onlyGov { - require(!relayAdminsExistMap[adminToBeAdded], "admin already exists"); + function addManagerAddress(address managerToBeAdded) external onlyGov { + require(!relayManagersExistMap[managerToBeAdded], "manager already exists"); - relayAdminsExistMap[adminToBeAdded] = true; + relayManagersExistMap[managerToBeAdded] = true; - emit addAdminAddress(adminToBeAdded); + emit addManagerAddress(managerToBeAdded); } - function registerAdmin() external payable onlyNonRegisteredAdmin { + function registerManager() external payable onlyNonRegisteredManager { require(msg.value == requiredDeposit, "deposit value is not exactly the same"); - admins[msg.sender] = admin(requiredDeposit, dues); - emit registerAdmin(msg.sender); + managers[msg.sender] = manager(requiredDeposit, dues); + emit registerManager(msg.sender); } - function addRelayer(address relayerToBeAdded) external onlyRegisteredAdmin noExist notContract noProxy { - adminsAndRelayers[msg.sender] = relayerToBeAdded; + function addRelayer(address relayerToBeAdded) external onlyRegisteredManager noExist notContract noProxy { + managersAndRelayers[msg.sender] = relayerToBeAdded; relayerExistsMap[relayerToBeAdded] = true; emit addRelayer(relayerToBeAdded); } - function registerAdminAddRelayer(address relayer) external payable onlyNonRegisteredAdmin { - registerAdmin(); + function registerManagerAddRelayer(address relayer) external payable onlyNonRegisteredManager { + registerManager(); addRelayer(relayer); } - function removeRelayer() external onlyRegisteredAdmin { - require(adminsAndRelayers[msg.sender], "relayer doesn't exist for this admin"); + function removeRelayer() external onlyRegisteredManager { + require(managersAndRelayers[msg.sender], "relayer doesn't exist for this manager"); - relayer memory r = adminsAndRelayers[msg.sender]; + relayer memory r = managersAndRelayers[msg.sender]; delete (relayerExistsMap[r]); - delete (adminsAndRelayers[msg.sender]); + delete (managersAndRelayers[msg.sender]); emit removeRelayer(r); } From 3efc715902b47f0f9ff97060a9a906fbf22200cb Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 21 Nov 2022 11:54:53 +0000 Subject: [PATCH 15/90] contract and exist checks inside function --- contracts/RelayerHub.sol | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index c72bfe49..e9faedac 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -40,21 +40,11 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { _; } - modifier notContract() { - require(!isContract(msg.sender), "contract is not allowed to be a relayer"); - _; - } - modifier noProxy() { require(msg.sender == tx.origin, "no proxy is allowed"); _; } - modifier noExist() { - require(!relayerExistsMap[msg.sender], "relayer already exists"); - _; - } - event relayerRegister(address _relayer); event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); @@ -161,7 +151,10 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit registerManager(msg.sender); } - function addRelayer(address relayerToBeAdded) external onlyRegisteredManager noExist notContract noProxy { + function addRelayer(address relayerToBeAdded) external onlyRegisteredManager noProxy { + require(!relayerExistsMap[relayerToBeAdded], "relayer already exists"); + require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); + managersAndRelayers[msg.sender] = relayerToBeAdded; relayerExistsMap[relayerToBeAdded] = true; emit addRelayer(relayerToBeAdded); From e8088195389fce054dc7fdd978dfacd0722efe4e Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 22 Nov 2022 14:28:48 +0000 Subject: [PATCH 16/90] remove onlyWhitelabelRelayer for the most part. --- contracts/CrossChain.sol | 2 +- contracts/CrossChain.template | 2 +- contracts/System.sol | 9 +-------- contracts/TendermintLightClient.sol | 2 +- contracts/TendermintLightClient.template | 2 +- 5 files changed, 5 insertions(+), 12 deletions(-) diff --git a/contracts/CrossChain.sol b/contracts/CrossChain.sol index b3b18d4e..7185f7b5 100644 --- a/contracts/CrossChain.sol +++ b/contracts/CrossChain.sol @@ -200,7 +200,7 @@ contract CrossChain is System, ICrossChain, IParamSubscriber{ return (true, packageType, relayFee, msgBytes); } - function handlePackage(bytes calldata payload, bytes calldata proof, uint64 height, uint64 packageSequence, uint8 channelId) onlyInit onlyRelayer onlyWhitelabelRelayer + function handlePackage(bytes calldata payload, bytes calldata proof, uint64 height, uint64 packageSequence, uint8 channelId) onlyInit onlyRelayer sequenceInOrder(packageSequence, channelId) blockSynced(height) channelSupported(channelId) headerInOrder(height, channelId) external { bytes memory payloadLocal = payload; // fix error: stack too deep, try removing local variables bytes memory proofLocal = proof; // fix error: stack too deep, try removing local variables diff --git a/contracts/CrossChain.template b/contracts/CrossChain.template index 614b8830..ccb31403 100644 --- a/contracts/CrossChain.template +++ b/contracts/CrossChain.template @@ -201,7 +201,7 @@ contract CrossChain is System, ICrossChain, IParamSubscriber{ return (true, packageType, relayFee, msgBytes); } - function handlePackage(bytes calldata payload, bytes calldata proof, uint64 height, uint64 packageSequence, uint8 channelId) onlyInit onlyRelayer onlyWhitelabelRelayer + function handlePackage(bytes calldata payload, bytes calldata proof, uint64 height, uint64 packageSequence, uint8 channelId) onlyInit onlyRelayer sequenceInOrder(packageSequence, channelId) blockSynced(height) channelSupported(channelId) headerInOrder(height, channelId) external { bytes memory payloadLocal = payload; // fix error: stack too deep, try removing local variables bytes memory proofLocal = proof; // fix error: stack too deep, try removing local variables diff --git a/contracts/System.sol b/contracts/System.sol index 1db84db4..9b0aeea2 100644 --- a/contracts/System.sol +++ b/contracts/System.sol @@ -79,17 +79,10 @@ contract System { } modifier onlyRelayer() { - require(IRelayerHub(RELAYERHUB_CONTRACT_ADDR).isRelayer(msg.sender), "the msg sender is not a relayer"); + require(IRelayerHub(RELAYERHUB_CONTRACT_ADDR).verifyRelayer(msg.sender), "the msg sender is not a relayer"); _; } - - modifier onlyWhitelabelRelayer() { - require(msg.sender == 0xb005741528b86F5952469d80A8614591E3c5B632 || msg.sender == 0x446AA6E0DC65690403dF3F127750da1322941F3e, "the msg sender is not a whitelabel relayer"); - _; - } - - modifier onlyTokenManager() { require(msg.sender == TOKEN_MANAGER_ADDR, "the msg sender must be tokenManager"); _; diff --git a/contracts/TendermintLightClient.sol b/contracts/TendermintLightClient.sol index d8db849c..418dbe32 100644 --- a/contracts/TendermintLightClient.sol +++ b/contracts/TendermintLightClient.sol @@ -57,7 +57,7 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ emit initConsensusState(initialHeight, cs.appHash); } - function syncTendermintHeader(bytes calldata header, uint64 height) external onlyRelayer onlyWhitelabelRelayer returns (bool) { + function syncTendermintHeader(bytes calldata header, uint64 height) external onlyRelayer returns (bool) { require(submitters[height] == address(0x0), "can't sync duplicated header"); require(height > initialHeight, "can't sync header before initialHeight"); diff --git a/contracts/TendermintLightClient.template b/contracts/TendermintLightClient.template index efdba652..13511ed7 100644 --- a/contracts/TendermintLightClient.template +++ b/contracts/TendermintLightClient.template @@ -57,7 +57,7 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{ emit initConsensusState(initialHeight, cs.appHash); } - function syncTendermintHeader(bytes calldata header, uint64 height) external onlyRelayer onlyWhitelabelRelayer returns (bool) { + function syncTendermintHeader(bytes calldata header, uint64 height) external onlyRelayer returns (bool) { require(submitters[height] == address(0x0), "can't sync duplicated header"); require(height > initialHeight, "can't sync header before initialHeight"); From 0fc3985687ba392e534a75e7592966f90082da78 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 23 Nov 2022 09:04:12 +0000 Subject: [PATCH 17/90] Remove register unregister from template file --- contracts/RelayerHub.template | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/contracts/RelayerHub.template b/contracts/RelayerHub.template index 7950ff9a..629fcf33 100644 --- a/contracts/RelayerHub.template +++ b/contracts/RelayerHub.template @@ -55,28 +55,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{ dues = INIT_DUES; alreadyInit = true; } - {% if mock %} - function register() external payable noExist onlyInit notContract noProxy{ - require(msg.value == requiredDeposit, "deposit value is not exactly the same"); - relayers[msg.sender] = relayer(requiredDeposit, dues); - relayersExistMap[msg.sender] = true; - emit relayerRegister(msg.sender); - } - {% else %} - function register() external payable noExist onlyInit notContract noProxy{ - revert("register suspended"); - } - {% endif %} - - function unregister() external exist onlyInit{ - relayer memory r = relayers[msg.sender]; - msg.sender.transfer(r.deposit.sub(r.dues)); - address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); - systemPayable.transfer(r.dues); - delete relayersExistMap[msg.sender]; - delete relayers[msg.sender]; - emit relayerUnRegister(msg.sender); - } /*********************** Param update ********************************/ function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov{ From ef4e08694a906e0b44fba5604952c7ad1445d420 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 23 Nov 2022 12:29:29 +0000 Subject: [PATCH 18/90] isRelayer, not verifyRelayer --- contracts/RelayerHub.sol | 2 +- contracts/System.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index e9faedac..ab344cc9 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -176,7 +176,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit removeRelayer(r); } - function verifyRelayer(address relayerAddress) external returns (bool){ + function isRelayer(address relayerAddress) external view returns (bool){ return relayerExistsMap[relayerAddress]; } } diff --git a/contracts/System.sol b/contracts/System.sol index 9b0aeea2..56d49b69 100644 --- a/contracts/System.sol +++ b/contracts/System.sol @@ -79,7 +79,7 @@ contract System { } modifier onlyRelayer() { - require(IRelayerHub(RELAYERHUB_CONTRACT_ADDR).verifyRelayer(msg.sender), "the msg sender is not a relayer"); + require(IRelayerHub(RELAYERHUB_CONTRACT_ADDR).isRelayer(msg.sender), "the msg sender is not a relayer"); _; } From 9304110285a08b87ad65826ef5f2f723cf5aaaad Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 23 Nov 2022 12:31:31 +0000 Subject: [PATCH 19/90] isContract check for manager --- contracts/RelayerHub.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index ab344cc9..ac1ab14a 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -139,6 +139,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { function addManagerAddress(address managerToBeAdded) external onlyGov { require(!relayManagersExistMap[managerToBeAdded], "manager already exists"); + require(!isContract(managerToBeAdded), "contract is not allowed to be a manager"); relayManagersExistMap[managerToBeAdded] = true; From 7f5751ef64401f508cc763dfd808115a50bdae69 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 23 Nov 2022 12:59:20 +0000 Subject: [PATCH 20/90] override in isRelayer --- contracts/RelayerHub.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index ac1ab14a..fa2a2d61 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -177,7 +177,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit removeRelayer(r); } - function isRelayer(address relayerAddress) external view returns (bool){ + function isRelayer(address relayerAddress) external override view returns (bool){ return relayerExistsMap[relayerAddress]; } } From 5b757c72c89b5a4e96e16e5dab96e203fc620aa2 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Thu, 24 Nov 2022 14:32:11 +0000 Subject: [PATCH 21/90] refactor naming --- contracts/RelayerHub.sol | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index fa2a2d61..8229bb3c 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -49,8 +49,8 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); - event removeManagerAddress(address _removedManager); - event addManagerAddress(address _addedManager); + event removeManagerByGov(address _removedManager); + event addManagerByGov(address _addedManager); event registerManager(address _registeredManager); event addRelayer(address _relayerToBeAdded); event removeRelayer(address _removedRelayer); @@ -91,13 +91,13 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { require(value.length == 20, "length of manager address mismatch"); address newManager = BytesToTypes.bytesToAddress(20, value); - addManagerAddress(newManager); + addManagerByGov(newManager); } else if (Memory.compareStrings(key, "removeManager")) { require(value.length == 20, "length of manager address mismatch"); address manager = BytesToTypes.bytesToAddress(20, value); - removeManagerAddress(manager); + removeManagerByGov(manager); } else { require(false, "unknown param"); @@ -105,7 +105,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit paramChange(key, value); } - function removeManagerAddress(address managerToBeRemoved) external onlyGov { + function removeManagerByGov(address managerToBeRemoved) external onlyGov { removeManagerHelper(managerToBeRemoved); } @@ -131,19 +131,19 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { delete (managers[managerAddress]); // emit success event - emit removeManagerAddress(managerAddress); + emit removeManagerByGov(managerAddress); if (relayerAddress != address(0)) { emit removeRelayer(relayerAddress); } } - function addManagerAddress(address managerToBeAdded) external onlyGov { + function addManagerByGov(address managerToBeAdded) external onlyGov { require(!relayManagersExistMap[managerToBeAdded], "manager already exists"); require(!isContract(managerToBeAdded), "contract is not allowed to be a manager"); relayManagersExistMap[managerToBeAdded] = true; - emit addManagerAddress(managerToBeAdded); + emit addManagerByGov(managerToBeAdded); } function registerManager() external payable onlyNonRegisteredManager { From ea38c55ce07e914fec6393d46f5a3ba8d79d888d Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Thu, 24 Nov 2022 17:55:21 +0000 Subject: [PATCH 22/90] addRelayer -> editRelayer --- contracts/RelayerHub.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 8229bb3c..badb034f 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -52,7 +52,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { event removeManagerByGov(address _removedManager); event addManagerByGov(address _addedManager); event registerManager(address _registeredManager); - event addRelayer(address _relayerToBeAdded); + event editRelayer(address _relayerToBeAdded); event removeRelayer(address _removedRelayer); @@ -152,18 +152,18 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit registerManager(msg.sender); } - function addRelayer(address relayerToBeAdded) external onlyRegisteredManager noProxy { + function editRelayer(address relayerToBeAdded) external onlyRegisteredManager noProxy { require(!relayerExistsMap[relayerToBeAdded], "relayer already exists"); require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); managersAndRelayers[msg.sender] = relayerToBeAdded; relayerExistsMap[relayerToBeAdded] = true; - emit addRelayer(relayerToBeAdded); + emit editRelayer(relayerToBeAdded); } function registerManagerAddRelayer(address relayer) external payable onlyNonRegisteredManager { registerManager(); - addRelayer(relayer); + editRelayer(relayer); } function removeRelayer() external onlyRegisteredManager { From 9a6385c31b8bbcfe8db2cc919c50ab1b644a5ea0 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Fri, 25 Nov 2022 07:42:53 +0000 Subject: [PATCH 23/90] remove most compilation errors apart from transfer --- contracts/RelayerHub.sol | 55 +++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index badb034f..f5ce71c9 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -20,6 +20,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { uint256 public dues; mapping(address => manager) managers; + mapping(address => bool) managersRegistered; mapping(address => bool) relayManagersExistMap; mapping(address => address) managersAndRelayers; mapping(address => bool) relayerExistsMap; @@ -36,7 +37,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { modifier onlyRegisteredManager() { require(relayManagersExistMap[msg.sender], "manager does not exist"); - require(managers[msg.sender], "manager not registered"); + require(managersRegistered[msg.sender], "manager not registered"); _; } @@ -49,11 +50,11 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); - event removeManagerByGov(address _removedManager); - event addManagerByGov(address _addedManager); - event registerManager(address _registeredManager); - event editRelayer(address _relayerToBeAdded); - event removeRelayer(address _removedRelayer); + event removeManagerByGovEvent(address _removedManager); + event addManagerByGovEvent(address _addedManager); + event registerManagerEvent(address _registeredManager); + event editRelayerEvent(address _relayerToBeAdded); + event removeRelayerEvent(address _removedRelayer); function init() external onlyNotInit { @@ -66,6 +67,9 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { managers[WHITELIST_1] = manager(requiredDeposit, dues); managers[WHITELIST_2] = manager(requiredDeposit, dues); + managersRegistered[WHITELIST_1] = true; + managersRegistered[WHITELIST_2] = true; + relayManagersExistMap[WHITELIST_1] = true; relayManagersExistMap[WHITELIST_2] = true; @@ -96,8 +100,8 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } else if (Memory.compareStrings(key, "removeManager")) { require(value.length == 20, "length of manager address mismatch"); - address manager = BytesToTypes.bytesToAddress(20, value); - removeManagerByGov(manager); + address managerAddress = BytesToTypes.bytesToAddress(20, value); + removeManagerByGov(managerAddress); } else { require(false, "unknown param"); @@ -105,7 +109,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit paramChange(key, value); } - function removeManagerByGov(address managerToBeRemoved) external onlyGov { + function removeManagerByGov(address managerToBeRemoved) internal { removeManagerHelper(managerToBeRemoved); } @@ -114,11 +118,11 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { removeManagerHelper(msg.sender); } - function removeManagerHelper(address managerAddress) { + function removeManagerHelper(address managerAddress) internal { // check if the manager address already exists require(relayManagersExistMap[managerAddress], "manager doesn't exist"); - relayer memory relayerAddress = managersAndRelayers[managerAddress]; + address relayerAddress = managersAndRelayers[managerAddress]; delete (relayManagersExistMap[managerAddress]); delete (managersAndRelayers[managerAddress]); @@ -129,27 +133,38 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { systemPayable.transfer(a.dues); delete (managers[managerAddress]); + delete (managersRegistered[managerAddress]); // emit success event emit removeManagerByGov(managerAddress); if (relayerAddress != address(0)) { - emit removeRelayer(relayerAddress); + emit removeRelayerEvent(relayerAddress); } } - function addManagerByGov(address managerToBeAdded) external onlyGov { + function addManagerByGov(address managerToBeAdded) internal { require(!relayManagersExistMap[managerToBeAdded], "manager already exists"); require(!isContract(managerToBeAdded), "contract is not allowed to be a manager"); relayManagersExistMap[managerToBeAdded] = true; - emit addManagerByGov(managerToBeAdded); + emit addManagerByGovEvent(managerToBeAdded); } - function registerManager() external payable onlyNonRegisteredManager { + function registerManager() internal payable onlyNonRegisteredManager { require(msg.value == requiredDeposit, "deposit value is not exactly the same"); managers[msg.sender] = manager(requiredDeposit, dues); - emit registerManager(msg.sender); + managersRegistered[msg.sender] = true; + emit registerManagerEvent(msg.sender); + } + + function addRelayer(address relayerToBeAdded) internal onlyRegisteredManager noProxy { + require(!relayerExistsMap[relayerToBeAdded], "relayer already exists"); + require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); + + managersAndRelayers[msg.sender] = relayerToBeAdded; + relayerExistsMap[relayerToBeAdded] = true; + emit editRelayerEvent(relayerToBeAdded); } function editRelayer(address relayerToBeAdded) external onlyRegisteredManager noProxy { @@ -158,23 +173,23 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { managersAndRelayers[msg.sender] = relayerToBeAdded; relayerExistsMap[relayerToBeAdded] = true; - emit editRelayer(relayerToBeAdded); + emit editRelayerEvent(relayerToBeAdded); } function registerManagerAddRelayer(address relayer) external payable onlyNonRegisteredManager { registerManager(); - editRelayer(relayer); + addRelayer(relayer); } function removeRelayer() external onlyRegisteredManager { require(managersAndRelayers[msg.sender], "relayer doesn't exist for this manager"); - relayer memory r = managersAndRelayers[msg.sender]; + address r = managersAndRelayers[msg.sender]; delete (relayerExistsMap[r]); delete (managersAndRelayers[msg.sender]); - emit removeRelayer(r); + emit removeRelayerEvent(r); } function isRelayer(address relayerAddress) external override view returns (bool){ From ba4c474b3748915818eee3322e060947e4ef12be Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Fri, 25 Nov 2022 08:10:56 +0000 Subject: [PATCH 24/90] compilation error fix: payable+map --- contracts/RelayerHub.sol | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index f5ce71c9..820cd986 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -100,7 +100,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } else if (Memory.compareStrings(key, "removeManager")) { require(value.length == 20, "length of manager address mismatch"); - address managerAddress = BytesToTypes.bytesToAddress(20, value); + address payable managerAddress = payable(BytesToTypes.bytesToAddress(20, value)); removeManagerByGov(managerAddress); } else { @@ -109,7 +109,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit paramChange(key, value); } - function removeManagerByGov(address managerToBeRemoved) internal { + function removeManagerByGov(address payable managerToBeRemoved) internal { removeManagerHelper(managerToBeRemoved); } @@ -118,7 +118,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { removeManagerHelper(msg.sender); } - function removeManagerHelper(address managerAddress) internal { + function removeManagerHelper(address payable managerAddress) internal { // check if the manager address already exists require(relayManagersExistMap[managerAddress], "manager doesn't exist"); @@ -136,7 +136,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { delete (managersRegistered[managerAddress]); // emit success event - emit removeManagerByGov(managerAddress); + emit removeManagerByGovEvent(managerAddress); if (relayerAddress != address(0)) { emit removeRelayerEvent(relayerAddress); } @@ -151,7 +151,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit addManagerByGovEvent(managerToBeAdded); } - function registerManager() internal payable onlyNonRegisteredManager { + function registerManager() internal onlyNonRegisteredManager { require(msg.value == requiredDeposit, "deposit value is not exactly the same"); managers[msg.sender] = manager(requiredDeposit, dues); managersRegistered[msg.sender] = true; @@ -182,7 +182,9 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } function removeRelayer() external onlyRegisteredManager { - require(managersAndRelayers[msg.sender], "relayer doesn't exist for this manager"); + if (managersAndRelayers[msg.sender] == address(0)) { + require(false, "relayer doesn't exist for this manager"); + } address r = managersAndRelayers[msg.sender]; From c3cdc8d9781fb47fe3f82a037a2e278a1e3fbce5 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Fri, 25 Nov 2022 13:22:22 +0000 Subject: [PATCH 25/90] extra payables --- contracts/RelayerHub.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 820cd986..58714e70 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -115,7 +115,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { function removeManager() external onlyRegisteredManager { // here the manager removes himself - removeManagerHelper(msg.sender); + removeManagerHelper(payable(msg.sender)); } function removeManagerHelper(address payable managerAddress) internal { @@ -129,7 +129,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { manager memory a = managers[managerAddress]; managerAddress.transfer(a.deposit.sub(a.dues)); - address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); + address payable systemPayable = payable(address(uint160(SYSTEM_REWARD_ADDR))); systemPayable.transfer(a.dues); delete (managers[managerAddress]); From 5d67e91360a43156f5a8b50a55709e2225f8857d Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Fri, 9 Dec 2022 14:42:09 +0100 Subject: [PATCH 26/90] modify templates --- contracts/RelayerHub.sol | 31 ++-- contracts/RelayerHub.template | 265 +++++++++++++++++++++++++--------- contracts/System.template | 22 --- 3 files changed, 210 insertions(+), 108 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 58714e70..03f32ae6 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -58,25 +58,17 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { function init() external onlyNotInit { - requiredDeposit = INIT_REQUIRED_DEPOSIT; - dues = INIT_DUES; alreadyInit = true; + addInitRelayer(WHITELIST_1); + addInitRelayer(WHITELIST_1); + } - // todo initialise the currently existing Managers and their relayer keys - - managers[WHITELIST_1] = manager(requiredDeposit, dues); - managers[WHITELIST_2] = manager(requiredDeposit, dues); - - managersRegistered[WHITELIST_1] = true; - managersRegistered[WHITELIST_2] = true; - - relayManagersExistMap[WHITELIST_1] = true; - relayManagersExistMap[WHITELIST_2] = true; - - managersAndRelayers[WHITELIST_1] = WHITELIST_1; // fixme current relayer - managersAndRelayers[WHITELIST_2] = WHITELIST_2; // fixme current relayer - - // fixme initialise relayerExistsMap + function addInitRelayer(address addr) internal { + managers[addr] = manager(INIT_REQUIRED_DEPOSIT, INIT_DUES); + managersRegistered[addr] = true; + relayManagersExistMap[addr] = true; + managersAndRelayers[addr] = addr; // fixme current relayer + relayerExistsMap[addr] = true; } /*********************** Param update ********************************/ @@ -197,4 +189,9 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { function isRelayer(address relayerAddress) external override view returns (bool){ return relayerExistsMap[relayerAddress]; } + + // TODO remove just for testing + function isManager(address relayerAddress) external view returns (bool){ + return managersRegistered[relayerAddress]; + } } diff --git a/contracts/RelayerHub.template b/contracts/RelayerHub.template index 629fcf33..bf2380c5 100644 --- a/contracts/RelayerHub.template +++ b/contracts/RelayerHub.template @@ -8,73 +8,200 @@ import "./System.sol"; import "./lib/SafeMath.sol"; -contract RelayerHub is IRelayerHub, System, IParamSubscriber{ - using SafeMath for uint256; - - uint256 public constant INIT_REQUIRED_DEPOSIT = 1e20; - uint256 public constant INIT_DUES = 1e17; - - uint256 public requiredDeposit; - uint256 public dues; - - mapping(address =>relayer) relayers; - mapping(address =>bool) relayersExistMap; - - struct relayer{ - uint256 deposit; - uint256 dues; - } - - modifier notContract() { - require(!isContract(msg.sender), "contract is not allowed to be a relayer"); - _; - } - - modifier noProxy() { - require(msg.sender == tx.origin, "no proxy is allowed"); - _; - } - - modifier noExist() { - require(!relayersExistMap[msg.sender], "relayer already exist"); - _; - } - - modifier exist() { - require(relayersExistMap[msg.sender], "relayer do not exist"); - _; - } - - event relayerRegister(address _relayer); - event relayerUnRegister(address _relayer); - event paramChange(string key, bytes value); - - - function init() external onlyNotInit{ - requiredDeposit = INIT_REQUIRED_DEPOSIT; - dues = INIT_DUES; - alreadyInit = true; - } - - /*********************** Param update ********************************/ - function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov{ - if (Memory.compareStrings(key,"requiredDeposit")) { - require(value.length == 32, "length of requiredDeposit mismatch"); - uint256 newRequiredDeposit = BytesToTypes.bytesToUint256(32, value); - require(newRequiredDeposit > 1 && newRequiredDeposit <= 1e21 && newRequiredDeposit > dues, "the requiredDeposit out of range"); - requiredDeposit = newRequiredDeposit; - } else if (Memory.compareStrings(key,"dues")) { - require(value.length == 32, "length of dues mismatch"); - uint256 newDues = BytesToTypes.bytesToUint256(32, value); - require(newDues > 0 && newDues < requiredDeposit, "the dues out of range"); - dues = newDues; - } else { - require(false, "unknown param"); - } - emit paramChange(key, value); - } - - function isRelayer(address sender) external override view returns (bool) { - return relayersExistMap[sender]; - } +contract RelayerHub is IRelayerHub, System, IParamSubscriber { + using SafeMath for uint256; + + uint256 public constant INIT_REQUIRED_DEPOSIT = 1e20; + uint256 public constant INIT_DUES = 1e17; + {% if network == 'local' %} + address public constant WHITELIST_1 = 0xA904540818AC9c47f2321F97F1069B9d8746c6DB; + address public constant WHITELIST_2 = 0x316b2Fa7C8a2ab7E21110a4B3f58771C01A71344; + {% elif network == 'QA' %} + address public constant WHITELIST_1 = 0x88cb4D8F77742c24d647BEf8049D3f3C56067cDD; + address public constant WHITELIST_2 = 0x42D596440775C90db8d9187b47650986E1063493; + {% elif network == 'testnet' %} + address public constant WHITELIST_1 = 0x9fB29AAc15b9A4B7F17c3385939b007540f4d791; + address public constant WHITELIST_2 = 0x37B8516a0F88E65D677229b402ec6C1e0E333004; + {% else %} + address public constant WHITELIST_1 = 0x04d63aBCd2b9b1baa327f2Dda0f873F197ccd186; + address public constant WHITELIST_2 = 0x446AA6E0DC65690403dF3F127750da1322941F3e; + {% endif %} + uint256 public requiredDeposit; + uint256 public dues; + + mapping(address => manager) managers; + mapping(address => bool) managersRegistered; + mapping(address => bool) relayManagersExistMap; + mapping(address => address) managersAndRelayers; + mapping(address => bool) relayerExistsMap; + + struct manager { + uint256 deposit; + uint256 dues; + } + + modifier onlyNonRegisteredManager() { + require(relayManagersExistMap[msg.sender], "manager does not exist"); + _; + } + + modifier onlyRegisteredManager() { + require(relayManagersExistMap[msg.sender], "manager does not exist"); + require(managersRegistered[msg.sender], "manager not registered"); + _; + } + + modifier noProxy() { + require(msg.sender == tx.origin, "no proxy is allowed"); + _; + } + + event relayerRegister(address _relayer); + event relayerUnRegister(address _relayer); + event paramChange(string key, bytes value); + + event removeManagerByGovEvent(address _removedManager); + event addManagerByGovEvent(address _addedManager); + event registerManagerEvent(address _registeredManager); + event editRelayerEvent(address _relayerToBeAdded); + event removeRelayerEvent(address _removedRelayer); + + + function init() external onlyNotInit { + alreadyInit = true; + addInitRelayer(WHITELIST_1); + addInitRelayer(WHITELIST_1); + } + + function addInitRelayer(address addr) internal { + managers[addr] = manager(INIT_REQUIRED_DEPOSIT, INIT_DUES); + managersRegistered[addr] = true; + relayManagersExistMap[addr] = true; + managersAndRelayers[addr] = addr; // fixme current relayer + relayerExistsMap[addr] = true; + } + + /*********************** Param update ********************************/ + function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov { + if (Memory.compareStrings(key, "requiredDeposit")) { + require(value.length == 32, "length of requiredDeposit mismatch"); + uint256 newRequiredDeposit = BytesToTypes.bytesToUint256(32, value); + require(newRequiredDeposit > 1 && newRequiredDeposit <= 1e21 && newRequiredDeposit > dues, "the requiredDeposit out of range"); + requiredDeposit = newRequiredDeposit; + } else if (Memory.compareStrings(key, "dues")) { + require(value.length == 32, "length of dues mismatch"); + uint256 newDues = BytesToTypes.bytesToUint256(32, value); + require(newDues > 0 && newDues < requiredDeposit, "the dues out of range"); + dues = newDues; + } else if (Memory.compareStrings(key, "addManager")) { + + require(value.length == 20, "length of manager address mismatch"); + address newManager = BytesToTypes.bytesToAddress(20, value); + addManagerByGov(newManager); + + } else if (Memory.compareStrings(key, "removeManager")) { + + require(value.length == 20, "length of manager address mismatch"); + address payable managerAddress = payable(BytesToTypes.bytesToAddress(20, value)); + removeManagerByGov(managerAddress); + + } else { + require(false, "unknown param"); + } + emit paramChange(key, value); + } + + function removeManagerByGov(address payable managerToBeRemoved) internal { + removeManagerHelper(managerToBeRemoved); + } + + function removeManager() external onlyRegisteredManager { + // here the manager removes himself + removeManagerHelper(payable(msg.sender)); + } + + function removeManagerHelper(address payable managerAddress) internal { + // check if the manager address already exists + require(relayManagersExistMap[managerAddress], "manager doesn't exist"); + + address relayerAddress = managersAndRelayers[managerAddress]; + + delete (relayManagersExistMap[managerAddress]); + delete (managersAndRelayers[managerAddress]); + + manager memory a = managers[managerAddress]; + managerAddress.transfer(a.deposit.sub(a.dues)); + address payable systemPayable = payable(address(uint160(SYSTEM_REWARD_ADDR))); + systemPayable.transfer(a.dues); + + delete (managers[managerAddress]); + delete (managersRegistered[managerAddress]); + + // emit success event + emit removeManagerByGovEvent(managerAddress); + if (relayerAddress != address(0)) { + emit removeRelayerEvent(relayerAddress); + } + } + + function addManagerByGov(address managerToBeAdded) internal { + require(!relayManagersExistMap[managerToBeAdded], "manager already exists"); + require(!isContract(managerToBeAdded), "contract is not allowed to be a manager"); + + relayManagersExistMap[managerToBeAdded] = true; + + emit addManagerByGovEvent(managerToBeAdded); + } + + function registerManager() internal onlyNonRegisteredManager { + require(msg.value == requiredDeposit, "deposit value is not exactly the same"); + managers[msg.sender] = manager(requiredDeposit, dues); + managersRegistered[msg.sender] = true; + emit registerManagerEvent(msg.sender); + } + + function addRelayer(address relayerToBeAdded) internal onlyRegisteredManager noProxy { + require(!relayerExistsMap[relayerToBeAdded], "relayer already exists"); + require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); + + managersAndRelayers[msg.sender] = relayerToBeAdded; + relayerExistsMap[relayerToBeAdded] = true; + emit editRelayerEvent(relayerToBeAdded); + } + + function editRelayer(address relayerToBeAdded) external onlyRegisteredManager noProxy { + require(!relayerExistsMap[relayerToBeAdded], "relayer already exists"); + require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); + + managersAndRelayers[msg.sender] = relayerToBeAdded; + relayerExistsMap[relayerToBeAdded] = true; + emit editRelayerEvent(relayerToBeAdded); + } + + function registerManagerAddRelayer(address relayer) external payable onlyNonRegisteredManager { + registerManager(); + addRelayer(relayer); + } + + function removeRelayer() external onlyRegisteredManager { + if (managersAndRelayers[msg.sender] == address(0)) { + require(false, "relayer doesn't exist for this manager"); + } + + address r = managersAndRelayers[msg.sender]; + + delete (relayerExistsMap[r]); + delete (managersAndRelayers[msg.sender]); + + emit removeRelayerEvent(r); + } + + function isRelayer(address relayerAddress) external override view returns (bool){ + return relayerExistsMap[relayerAddress]; + } + + // TODO remove just for testing + function isManager(address relayerAddress) external view returns (bool){ + return managersRegistered[relayerAddress]; + } } diff --git a/contracts/System.template b/contracts/System.template index 6089c896..7daf4f7d 100644 --- a/contracts/System.template +++ b/contracts/System.template @@ -116,28 +116,6 @@ contract System { _; } - {% if network == 'local' %} - modifier onlyWhitelabelRelayer() { - require(msg.sender == 0xA904540818AC9c47f2321F97F1069B9d8746c6DB || msg.sender == 0x316b2Fa7C8a2ab7E21110a4B3f58771C01A71344, "the msg sender is not a whitelabel relayer"); - _; - } - {% elif network == 'QA' %} - modifier onlyWhitelabelRelayer() { - require(msg.sender == 0x88cb4D8F77742c24d647BEf8049D3f3C56067cDD || msg.sender == 0x42D596440775C90db8d9187b47650986E1063493, "the msg sender is not a whitelabel relayer"); - _; - } - {% elif network == 'testnet' %} - modifier onlyWhitelabelRelayer() { - require(msg.sender == 0x9fB29AAc15b9A4B7F17c3385939b007540f4d791 || msg.sender == 0x37B8516a0F88E65D677229b402ec6C1e0E333004, "the msg sender is not a whitelabel relayer"); - _; - } - {% else %} - modifier onlyWhitelabelRelayer() { - require(msg.sender == 0xb005741528b86F5952469d80A8614591E3c5B632 || msg.sender == 0x446AA6E0DC65690403dF3F127750da1322941F3e, "the msg sender is not a whitelabel relayer"); - _; - } - {% endif %} - modifier onlyTokenManager() { require(msg.sender == TOKEN_MANAGER_ADDR, "the msg sender must be tokenManager"); _; From 5ee2dc0ebf7ec8f80a2d72cf642d7fc4b4290313 Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Tue, 13 Dec 2022 15:27:26 +0100 Subject: [PATCH 27/90] fix bugs in contract --- contracts/RelayerHub.sol | 31 +++++++++++++++---------------- contracts/RelayerHub.template | 31 +++++++++++++++---------------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 03f32ae6..613a0df8 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -53,18 +53,20 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { event removeManagerByGovEvent(address _removedManager); event addManagerByGovEvent(address _addedManager); event registerManagerEvent(address _registeredManager); - event editRelayerEvent(address _relayerToBeAdded); + event addRelayerEvent(address _relayerToBeAdded); event removeRelayerEvent(address _removedRelayer); function init() external onlyNotInit { - alreadyInit = true; - addInitRelayer(WHITELIST_1); + requiredDeposit = INIT_REQUIRED_DEPOSIT; + dues = INIT_DUES; addInitRelayer(WHITELIST_1); + addInitRelayer(WHITELIST_2); + alreadyInit = true; } function addInitRelayer(address addr) internal { - managers[addr] = manager(INIT_REQUIRED_DEPOSIT, INIT_DUES); + managers[addr] = manager(requiredDeposit, dues); managersRegistered[addr] = true; relayManagersExistMap[addr] = true; managersAndRelayers[addr] = addr; // fixme current relayer @@ -150,22 +152,19 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit registerManagerEvent(msg.sender); } - function addRelayer(address relayerToBeAdded) internal onlyRegisteredManager noProxy { - require(!relayerExistsMap[relayerToBeAdded], "relayer already exists"); - require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); - - managersAndRelayers[msg.sender] = relayerToBeAdded; - relayerExistsMap[relayerToBeAdded] = true; - emit editRelayerEvent(relayerToBeAdded); - } - - function editRelayer(address relayerToBeAdded) external onlyRegisteredManager noProxy { + function addRelayer(address relayerToBeAdded) public onlyRegisteredManager noProxy { require(!relayerExistsMap[relayerToBeAdded], "relayer already exists"); require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); + if(managersAndRelayers[msg.sender] != address(0)) { + address r = managersAndRelayers[msg.sender]; + delete (relayerExistsMap[r]); + emit removeRelayerEvent(r); + } + managersAndRelayers[msg.sender] = relayerToBeAdded; relayerExistsMap[relayerToBeAdded] = true; - emit editRelayerEvent(relayerToBeAdded); + emit addRelayerEvent(relayerToBeAdded); } function registerManagerAddRelayer(address relayer) external payable onlyNonRegisteredManager { @@ -192,6 +191,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // TODO remove just for testing function isManager(address relayerAddress) external view returns (bool){ - return managersRegistered[relayerAddress]; + return relayManagersExistMap[relayerAddress]; } } diff --git a/contracts/RelayerHub.template b/contracts/RelayerHub.template index bf2380c5..045dadfa 100644 --- a/contracts/RelayerHub.template +++ b/contracts/RelayerHub.template @@ -63,18 +63,20 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { event removeManagerByGovEvent(address _removedManager); event addManagerByGovEvent(address _addedManager); event registerManagerEvent(address _registeredManager); - event editRelayerEvent(address _relayerToBeAdded); + event addRelayerEvent(address _relayerToBeAdded); event removeRelayerEvent(address _removedRelayer); function init() external onlyNotInit { - alreadyInit = true; - addInitRelayer(WHITELIST_1); + requiredDeposit = INIT_REQUIRED_DEPOSIT; + dues = INIT_DUES; addInitRelayer(WHITELIST_1); + addInitRelayer(WHITELIST_2); + alreadyInit = true; } function addInitRelayer(address addr) internal { - managers[addr] = manager(INIT_REQUIRED_DEPOSIT, INIT_DUES); + managers[addr] = manager(requiredDeposit, dues); managersRegistered[addr] = true; relayManagersExistMap[addr] = true; managersAndRelayers[addr] = addr; // fixme current relayer @@ -160,22 +162,19 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit registerManagerEvent(msg.sender); } - function addRelayer(address relayerToBeAdded) internal onlyRegisteredManager noProxy { - require(!relayerExistsMap[relayerToBeAdded], "relayer already exists"); - require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); - - managersAndRelayers[msg.sender] = relayerToBeAdded; - relayerExistsMap[relayerToBeAdded] = true; - emit editRelayerEvent(relayerToBeAdded); - } - - function editRelayer(address relayerToBeAdded) external onlyRegisteredManager noProxy { + function addRelayer(address relayerToBeAdded) public onlyRegisteredManager noProxy { require(!relayerExistsMap[relayerToBeAdded], "relayer already exists"); require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); + if(managersAndRelayers[msg.sender] != address(0)) { + address r = managersAndRelayers[msg.sender]; + delete (relayerExistsMap[r]); + emit removeRelayerEvent(r); + } + managersAndRelayers[msg.sender] = relayerToBeAdded; relayerExistsMap[relayerToBeAdded] = true; - emit editRelayerEvent(relayerToBeAdded); + emit addRelayerEvent(relayerToBeAdded); } function registerManagerAddRelayer(address relayer) external payable onlyNonRegisteredManager { @@ -202,6 +201,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // TODO remove just for testing function isManager(address relayerAddress) external view returns (bool){ - return managersRegistered[relayerAddress]; + return relayManagersExistMap[relayerAddress]; } } From 5c501c445f40b670b5b3b97b809345ade5159b7b Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 20 Dec 2022 13:04:47 +0000 Subject: [PATCH 28/90] Remove unneeded modifier + properly remove relayer --- contracts/RelayerHub.sol | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 613a0df8..ca244f32 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -107,7 +107,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { removeManagerHelper(managerToBeRemoved); } - function removeManager() external onlyRegisteredManager { + function removeManager() external { // here the manager removes himself removeManagerHelper(payable(msg.sender)); } @@ -132,6 +132,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // emit success event emit removeManagerByGovEvent(managerAddress); if (relayerAddress != address(0)) { + delete (relayerExistsMap[relayerAddress]); emit removeRelayerEvent(relayerAddress); } } @@ -152,7 +153,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit registerManagerEvent(msg.sender); } - function addRelayer(address relayerToBeAdded) public onlyRegisteredManager noProxy { + function updateRelayer(address relayerToBeAdded) public onlyRegisteredManager { require(!relayerExistsMap[relayerToBeAdded], "relayer already exists"); require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); @@ -169,7 +170,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { function registerManagerAddRelayer(address relayer) external payable onlyNonRegisteredManager { registerManager(); - addRelayer(relayer); + updateRelayer(relayer); } function removeRelayer() external onlyRegisteredManager { From ce2ea8fc213672665cfcf3c9e03a3a7c8e4c6c15 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 20 Dec 2022 13:25:27 +0000 Subject: [PATCH 29/90] updateRelayer event and no need for removeRelayer --- contracts/RelayerHub.sol | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index ca244f32..21e43f17 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -55,6 +55,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { event registerManagerEvent(address _registeredManager); event addRelayerEvent(address _relayerToBeAdded); event removeRelayerEvent(address _removedRelayer); + event updateRelayerEvent(address _from, address _to); function init() external onlyNotInit { @@ -153,19 +154,19 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit registerManagerEvent(msg.sender); } + // updateRelayer() can be used to add relayer for the first time, update it in future and remove it + // in case of removal we can simply update it to a non-existing account function updateRelayer(address relayerToBeAdded) public onlyRegisteredManager { require(!relayerExistsMap[relayerToBeAdded], "relayer already exists"); require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); - if(managersAndRelayers[msg.sender] != address(0)) { - address r = managersAndRelayers[msg.sender]; - delete (relayerExistsMap[r]); - emit removeRelayerEvent(r); - } - + address oldRelayer = managersAndRelayers[msg.sender]; + relayerExistsMap[oldRelayer] = false; + managersAndRelayers[msg.sender] = relayerToBeAdded; relayerExistsMap[relayerToBeAdded] = true; - emit addRelayerEvent(relayerToBeAdded); + + emit updateRelayerEvent(oldRelayer, relayerToBeAdded); } function registerManagerAddRelayer(address relayer) external payable onlyNonRegisteredManager { @@ -173,19 +174,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { updateRelayer(relayer); } - function removeRelayer() external onlyRegisteredManager { - if (managersAndRelayers[msg.sender] == address(0)) { - require(false, "relayer doesn't exist for this manager"); - } - - address r = managersAndRelayers[msg.sender]; - - delete (relayerExistsMap[r]); - delete (managersAndRelayers[msg.sender]); - - emit removeRelayerEvent(r); - } - function isRelayer(address relayerAddress) external override view returns (bool){ return relayerExistsMap[relayerAddress]; } From 6dfa1690db3275431c080108c54e7571013fb988 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 20 Dec 2022 13:38:28 +0000 Subject: [PATCH 30/90] For smooth transition and let old relayers exit --- contracts/RelayerHub.sol | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 21e43f17..8117881c 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -19,6 +19,9 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { uint256 public requiredDeposit; uint256 public dues; + mapping(address => relayer) relayers; // old map holding the relayers which are to be allowed safe exit + mapping(address => bool) relayersExistMap; + mapping(address => manager) managers; mapping(address => bool) managersRegistered; mapping(address => bool) relayManagersExistMap; @@ -30,6 +33,11 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { uint256 dues; } + modifier onlyPreviousRegisteredRelayer() { + require(relayersExistMap[msg.sender], "relayer do not exist"); + _; + } + modifier onlyNonRegisteredManager() { require(relayManagersExistMap[msg.sender], "manager does not exist"); _; @@ -46,6 +54,14 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { _; } + modifier onlyAllowedParty() { + require(msg.sender == 0xb005741528b86F5952469d80A8614591E3c5B632 || msg.sender == 0x446AA6E0DC65690403dF3F127750da1322941F3e, "the msg sender is not allowed to call update to ensure smooth transition"); + // todo change the above address to appropriate ones + _; + } + + event relayerUnRegister(address _relayer); + event relayerRegister(address _relayer); event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); @@ -57,13 +73,25 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { event removeRelayerEvent(address _removedRelayer); event updateRelayerEvent(address _from, address _to); + function exitOldRelayers() external onlyPreviousRegisteredRelayer { + relayer memory r = relayers[msg.sender]; + msg.sender.transfer(r.deposit.sub(r.dues)); + address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); + systemPayable.transfer(r.dues); + delete relayersExistMap[msg.sender]; + delete relayers[msg.sender]; + emit relayerUnRegister(msg.sender); + } function init() external onlyNotInit { requiredDeposit = INIT_REQUIRED_DEPOSIT; dues = INIT_DUES; + alreadyInit = true; + } + + function update() external onlyAllowedParty { addInitRelayer(WHITELIST_1); addInitRelayer(WHITELIST_2); - alreadyInit = true; } function addInitRelayer(address addr) internal { From 21fd9d690962e22b2d3f7a9e3feadfeae7eabf05 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 21 Dec 2022 08:21:00 +0000 Subject: [PATCH 31/90] Only use updateRelayerEvent + Refacoring functions --- contracts/RelayerHub.sol | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 8117881c..4202931b 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -34,7 +34,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } modifier onlyPreviousRegisteredRelayer() { - require(relayersExistMap[msg.sender], "relayer do not exist"); + require(relayersExistMap[msg.sender], "relayer does not exist"); _; } @@ -56,7 +56,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { modifier onlyAllowedParty() { require(msg.sender == 0xb005741528b86F5952469d80A8614591E3c5B632 || msg.sender == 0x446AA6E0DC65690403dF3F127750da1322941F3e, "the msg sender is not allowed to call update to ensure smooth transition"); - // todo change the above address to appropriate ones + // todo change the above address to appropriate ones which can call update() _; } @@ -69,8 +69,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { event removeManagerByGovEvent(address _removedManager); event addManagerByGovEvent(address _addedManager); event registerManagerEvent(address _registeredManager); - event addRelayerEvent(address _relayerToBeAdded); - event removeRelayerEvent(address _removedRelayer); event updateRelayerEvent(address _from, address _to); function exitOldRelayers() external onlyPreviousRegisteredRelayer { @@ -133,15 +131,15 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } function removeManagerByGov(address payable managerToBeRemoved) internal { - removeManagerHelper(managerToBeRemoved); + removeManager(managerToBeRemoved); } - function removeManager() external { + function removeManagerByHimself() external { // here the manager removes himself - removeManagerHelper(payable(msg.sender)); + removeManager(payable(msg.sender)); } - function removeManagerHelper(address payable managerAddress) internal { + function removeManager(address payable managerAddress) internal { // check if the manager address already exists require(relayManagersExistMap[managerAddress], "manager doesn't exist"); @@ -162,7 +160,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit removeManagerByGovEvent(managerAddress); if (relayerAddress != address(0)) { delete (relayerExistsMap[relayerAddress]); - emit removeRelayerEvent(relayerAddress); + emit updateRelayerEvent(relayerAddress, address(0)); } } From b570b674a00a16b6582a5672de5f8f38dae25cee Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 21 Dec 2022 08:38:59 +0000 Subject: [PATCH 32/90] Better naming of some maps --- contracts/RelayerHub.sol | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 4202931b..7ddea7cc 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -25,8 +25,8 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { mapping(address => manager) managers; mapping(address => bool) managersRegistered; mapping(address => bool) relayManagersExistMap; - mapping(address => address) managersAndRelayers; - mapping(address => bool) relayerExistsMap; + mapping(address => address) managerToRelayer; + mapping(address => bool) currentRelayers; struct manager { uint256 deposit; @@ -96,8 +96,8 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { managers[addr] = manager(requiredDeposit, dues); managersRegistered[addr] = true; relayManagersExistMap[addr] = true; - managersAndRelayers[addr] = addr; // fixme current relayer - relayerExistsMap[addr] = true; + managerToRelayer[addr] = addr; // fixme current relayer + currentRelayers[addr] = true; } /*********************** Param update ********************************/ @@ -143,10 +143,10 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // check if the manager address already exists require(relayManagersExistMap[managerAddress], "manager doesn't exist"); - address relayerAddress = managersAndRelayers[managerAddress]; + address relayerAddress = managerToRelayer[managerAddress]; delete (relayManagersExistMap[managerAddress]); - delete (managersAndRelayers[managerAddress]); + delete (managerToRelayer[managerAddress]); manager memory a = managers[managerAddress]; managerAddress.transfer(a.deposit.sub(a.dues)); @@ -159,7 +159,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // emit success event emit removeManagerByGovEvent(managerAddress); if (relayerAddress != address(0)) { - delete (relayerExistsMap[relayerAddress]); + delete (currentRelayers[relayerAddress]); emit updateRelayerEvent(relayerAddress, address(0)); } } @@ -183,14 +183,14 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // updateRelayer() can be used to add relayer for the first time, update it in future and remove it // in case of removal we can simply update it to a non-existing account function updateRelayer(address relayerToBeAdded) public onlyRegisteredManager { - require(!relayerExistsMap[relayerToBeAdded], "relayer already exists"); + require(!currentRelayers[relayerToBeAdded], "relayer already exists"); require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); - address oldRelayer = managersAndRelayers[msg.sender]; - relayerExistsMap[oldRelayer] = false; + address oldRelayer = managerToRelayer[msg.sender]; + currentRelayers[oldRelayer] = false; - managersAndRelayers[msg.sender] = relayerToBeAdded; - relayerExistsMap[relayerToBeAdded] = true; + managerToRelayer[msg.sender] = relayerToBeAdded; + currentRelayers[relayerToBeAdded] = true; emit updateRelayerEvent(oldRelayer, relayerToBeAdded); } @@ -201,7 +201,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } function isRelayer(address relayerAddress) external override view returns (bool){ - return relayerExistsMap[relayerAddress]; + return currentRelayers[relayerAddress]; } // TODO remove just for testing From dacd6ec2cce74229756daf309798b35a42751eed Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 21 Dec 2022 09:46:23 +0000 Subject: [PATCH 33/90] update only once --- contracts/RelayerHub.sol | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 7ddea7cc..f2c67e09 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -11,6 +11,8 @@ import "./lib/SafeMath.sol"; contract RelayerHub is IRelayerHub, System, IParamSubscriber { using SafeMath for uint256; + bool public alreadyUpdate; + uint256 public constant INIT_REQUIRED_DEPOSIT = 1e20; uint256 public constant INIT_DUES = 1e17; address public constant WHITELIST_1 = 0xb005741528b86F5952469d80A8614591E3c5B632; @@ -88,8 +90,10 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } function update() external onlyAllowedParty { + require(!alreadyUpdate, "the contract already updated"); addInitRelayer(WHITELIST_1); addInitRelayer(WHITELIST_2); + alreadyUpdate = true; } function addInitRelayer(address addr) internal { From 744320e2afcbc8da56d5097ab1e1b175d62f777c Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 21 Dec 2022 13:26:49 +0000 Subject: [PATCH 34/90] Remove repeated event --- contracts/RelayerHub.sol | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index f2c67e09..433ee414 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -62,8 +62,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { _; } - event relayerUnRegister(address _relayer); - event relayerRegister(address _relayer); event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); @@ -152,10 +150,10 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { delete (relayManagersExistMap[managerAddress]); delete (managerToRelayer[managerAddress]); - manager memory a = managers[managerAddress]; - managerAddress.transfer(a.deposit.sub(a.dues)); + manager memory m = managers[managerAddress]; + managerAddress.transfer(m.deposit.sub(m.dues)); address payable systemPayable = payable(address(uint160(SYSTEM_REWARD_ADDR))); - systemPayable.transfer(a.dues); + systemPayable.transfer(m.dues); delete (managers[managerAddress]); delete (managersRegistered[managerAddress]); @@ -177,7 +175,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit addManagerByGovEvent(managerToBeAdded); } - function registerManager() internal onlyNonRegisteredManager { + function registerManager() internal { require(msg.value == requiredDeposit, "deposit value is not exactly the same"); managers[msg.sender] = manager(requiredDeposit, dues); managersRegistered[msg.sender] = true; From 2820ea46ab935a98e382b28e21f34b5b51c69d0c Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Fri, 23 Dec 2022 14:05:28 +0000 Subject: [PATCH 35/90] Remove onlyAllowedParty + correct var order --- contracts/RelayerHub.sol | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 433ee414..ea34071b 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -11,8 +11,6 @@ import "./lib/SafeMath.sol"; contract RelayerHub is IRelayerHub, System, IParamSubscriber { using SafeMath for uint256; - bool public alreadyUpdate; - uint256 public constant INIT_REQUIRED_DEPOSIT = 1e20; uint256 public constant INIT_DUES = 1e17; address public constant WHITELIST_1 = 0xb005741528b86F5952469d80A8614591E3c5B632; @@ -24,12 +22,19 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { mapping(address => relayer) relayers; // old map holding the relayers which are to be allowed safe exit mapping(address => bool) relayersExistMap; + struct relayer{ + uint256 deposit; + uint256 dues; + } + mapping(address => manager) managers; mapping(address => bool) managersRegistered; mapping(address => bool) relayManagersExistMap; mapping(address => address) managerToRelayer; mapping(address => bool) currentRelayers; + bool public alreadyUpdate; + struct manager { uint256 deposit; uint256 dues; @@ -56,12 +61,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { _; } - modifier onlyAllowedParty() { - require(msg.sender == 0xb005741528b86F5952469d80A8614591E3c5B632 || msg.sender == 0x446AA6E0DC65690403dF3F127750da1322941F3e, "the msg sender is not allowed to call update to ensure smooth transition"); - // todo change the above address to appropriate ones which can call update() - _; - } - event relayerRegister(address _relayer); event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); @@ -87,7 +86,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { alreadyInit = true; } - function update() external onlyAllowedParty { + function update() external { require(!alreadyUpdate, "the contract already updated"); addInitRelayer(WHITELIST_1); addInitRelayer(WHITELIST_2); From 627bb00ad435e2a9d9b45502f8aae754226f69d6 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 2 Jan 2023 10:41:20 +0000 Subject: [PATCH 36/90] remove deposit + bring back old withdraw --- contracts/RelayerHub.sol | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index ea34071b..eef9fdb2 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -16,13 +16,13 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { address public constant WHITELIST_1 = 0xb005741528b86F5952469d80A8614591E3c5B632; address public constant WHITELIST_2 = 0x446AA6E0DC65690403dF3F127750da1322941F3e; - uint256 public requiredDeposit; + uint256 public requiredDeposit; // have to keep it to not break the storage layout uint256 public dues; mapping(address => relayer) relayers; // old map holding the relayers which are to be allowed safe exit mapping(address => bool) relayersExistMap; - struct relayer{ + struct relayer { uint256 deposit; uint256 dues; } @@ -36,15 +36,9 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { bool public alreadyUpdate; struct manager { - uint256 deposit; uint256 dues; } - modifier onlyPreviousRegisteredRelayer() { - require(relayersExistMap[msg.sender], "relayer does not exist"); - _; - } - modifier onlyNonRegisteredManager() { require(relayManagersExistMap[msg.sender], "manager does not exist"); _; @@ -61,6 +55,11 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { _; } + modifier exist() { + require(relayersExistMap[msg.sender], "relayer do not exist"); + _; + } + event relayerRegister(address _relayer); event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); @@ -70,7 +69,13 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { event registerManagerEvent(address _registeredManager); event updateRelayerEvent(address _from, address _to); - function exitOldRelayers() external onlyPreviousRegisteredRelayer { + function init() external onlyNotInit { + requiredDeposit = INIT_REQUIRED_DEPOSIT; + dues = INIT_DUES; + alreadyInit = true; + } + + function unregister() external exist onlyInit { relayer memory r = relayers[msg.sender]; msg.sender.transfer(r.deposit.sub(r.dues)); address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); @@ -80,12 +85,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit relayerUnRegister(msg.sender); } - function init() external onlyNotInit { - requiredDeposit = INIT_REQUIRED_DEPOSIT; - dues = INIT_DUES; - alreadyInit = true; - } - function update() external { require(!alreadyUpdate, "the contract already updated"); addInitRelayer(WHITELIST_1); @@ -94,7 +93,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } function addInitRelayer(address addr) internal { - managers[addr] = manager(requiredDeposit, dues); + managers[addr] = manager(dues); managersRegistered[addr] = true; relayManagersExistMap[addr] = true; managerToRelayer[addr] = addr; // fixme current relayer @@ -150,7 +149,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { delete (managerToRelayer[managerAddress]); manager memory m = managers[managerAddress]; - managerAddress.transfer(m.deposit.sub(m.dues)); address payable systemPayable = payable(address(uint160(SYSTEM_REWARD_ADDR))); systemPayable.transfer(m.dues); @@ -175,8 +173,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } function registerManager() internal { - require(msg.value == requiredDeposit, "deposit value is not exactly the same"); - managers[msg.sender] = manager(requiredDeposit, dues); + managers[msg.sender] = manager(dues); managersRegistered[msg.sender] = true; emit registerManagerEvent(msg.sender); } @@ -196,9 +193,9 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit updateRelayerEvent(oldRelayer, relayerToBeAdded); } - function registerManagerAddRelayer(address relayer) external payable onlyNonRegisteredManager { + function registerManagerAddRelayer(address r) external payable onlyNonRegisteredManager { registerManager(); - updateRelayer(relayer); + updateRelayer(r); } function isRelayer(address relayerAddress) external override view returns (bool){ From 14f9aada3bdabfa5e95a28fa5f1096617e064cbb Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Thu, 5 Jan 2023 06:10:01 +0000 Subject: [PATCH 37/90] test for adding new param which doesn't work --- lib/interface/IRelayerHub.sol | 1 + test/RelayerHub.t.sol | 115 ++++++++++++++++++++-------------- 2 files changed, 70 insertions(+), 46 deletions(-) diff --git a/lib/interface/IRelayerHub.sol b/lib/interface/IRelayerHub.sol index 105a5d80..314fdf6c 100644 --- a/lib/interface/IRelayerHub.sol +++ b/lib/interface/IRelayerHub.sol @@ -36,4 +36,5 @@ interface RelayerHub { function requiredDeposit() external view returns (uint256); function unregister() external; function updateParam(string memory key, bytes memory value) external; + function registerManagerAddRelayer(address r) external payable; } diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index ce8c9a7e..f4b297de 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -3,50 +3,73 @@ pragma solidity ^0.8.10; import "../lib/Deployer.sol"; contract RelayerHubTest is Deployer { - event relayerRegister(address _relayer); - event relayerUnRegister(address _relayer); - event paramChange(string key, bytes value); - - uint256 public requiredDeposit; - uint256 public dues; - - function setUp() public { - requiredDeposit = relayerHub.requiredDeposit(); - dues = relayerHub.dues(); - } - - // new relayer register is suspended - function testRegister() public { - address newRelayer = addrSet[addrIdx++]; - vm.prank(newRelayer, newRelayer); - vm.expectRevert(bytes("register suspended")); - relayerHub.register{value: 100 ether}(); - } - - // function testCannotRegister() public { - // address newRelayer = addrSet[addrIdx++]; - // vm.startPrank(newRelayer, newRelayer); - // relayerHub.register{value: 100 ether}(); - // - // // re-register - // vm.expectRevert(bytes("relayer already exist")); - // relayerHub.register{value: 100 ether}(); - // - // relayerHub.unregister(); - // // re-unregister - // vm.expectRevert(bytes("relayer do not exist")); - // relayerHub.unregister(); - // - // vm.stopPrank(); - // newRelayer = addrSet[addrIdx++]; - // vm.startPrank(newRelayer, newRelayer); - // - // // send 200 ether - // vm.expectRevert(bytes("deposit value is not exactly the same")); - // relayerHub.register{value: 200 ether}(); - // - // // send 10 ether - // vm.expectRevert(bytes("deposit value is not exactly the same")); - // relayerHub.register{value: 10 ether}(); - // } + event relayerRegister(address _relayer); + event relayerUnRegister(address _relayer); + event paramChange(string key, bytes value); + + uint256 public requiredDeposit; + uint256 public dues; + + function setUp() public { + requiredDeposit = relayerHub.requiredDeposit(); + dues = relayerHub.dues(); + } + + // new relayer register is suspended + function testRegister() public { + address newRelayer = addrSet[addrIdx++]; + vm.prank(newRelayer, newRelayer); + vm.expectRevert(bytes("register suspended")); + relayerHub.register{value : 100 ether}(); + } + + function testAddManager() public { + address manager = payable(addrSet[addrIdx++]); + address newRelayer = payable(addrSet[addrIdx++]); + + // testing if we can update "dues" param which is currently there on mainnet. + // this works fine in forge test + bytes memory keyDues = "dues"; + uint256 valueDues = 23; + bytes memory testValueBytes = abi.encode(valueDues); + updateParamByGovHub(keyDues, testValueBytes, address(relayerHub)); + + // testing if we can update "addManager" param which is currently NOT there on mainnet but exists locally. + // this gives error of "unknown param" in "forge test -vvvv --match-test testAddManager" + bytes memory key = "addManager"; + bytes memory valueBytes = abi.encode(manager); + updateParamByGovHub(key, valueBytes, address(relayerHub)); + + // check if manager is there + vm.prank(manager, manager); + relayerHub.registerManagerAddRelayer(newRelayer); + + } + + // function testCannotRegister() public { + // address newRelayer = addrSet[addrIdx++]; + // vm.startPrank(newRelayer, newRelayer); + // relayerHub.register{value: 100 ether}(); + // + // // re-register + // vm.expectRevert(bytes("relayer already exist")); + // relayerHub.register{value: 100 ether}(); + // + // relayerHub.unregister(); + // // re-unregister + // vm.expectRevert(bytes("relayer do not exist")); + // relayerHub.unregister(); + // + // vm.stopPrank(); + // newRelayer = addrSet[addrIdx++]; + // vm.startPrank(newRelayer, newRelayer); + // + // // send 200 ether + // vm.expectRevert(bytes("deposit value is not exactly the same")); + // relayerHub.register{value: 200 ether}(); + // + // // send 10 ether + // vm.expectRevert(bytes("deposit value is not exactly the same")); + // relayerHub.register{value: 10 ether}(); + // } } From 0ad173aad6096d6e5350c64b726642e99a34b234 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Thu, 5 Jan 2023 11:46:01 +0000 Subject: [PATCH 38/90] correct the test --- test/RelayerHub.t.sol | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index f4b297de..6316a9e4 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -24,26 +24,28 @@ contract RelayerHubTest is Deployer { } function testAddManager() public { - address manager = payable(addrSet[addrIdx++]); - address newRelayer = payable(addrSet[addrIdx++]); + RelayerHub newRelayerHub; - // testing if we can update "dues" param which is currently there on mainnet. - // this works fine in forge test - bytes memory keyDues = "dues"; - uint256 valueDues = 23; - bytes memory testValueBytes = abi.encode(valueDues); - updateParamByGovHub(keyDues, testValueBytes, address(relayerHub)); + bytes memory relayerCode = vm.getDeployedCode("RelayerHub.sol"); + vm.etch(RELAYERHUB_CONTRACT_ADDR, relayerCode); + newRelayerHub = RelayerHub(RELAYERHUB_CONTRACT_ADDR); - // testing if we can update "addManager" param which is currently NOT there on mainnet but exists locally. - // this gives error of "unknown param" in "forge test -vvvv --match-test testAddManager" bytes memory key = "addManager"; - bytes memory valueBytes = abi.encode(manager); - updateParamByGovHub(key, valueBytes, address(relayerHub)); + address manager = payable(addrSet[addrIdx++]); + address newRelayer = payable(addrSet[addrIdx++]); + bytes memory valueBytes = abi.encodePacked(bytes20(uint160(manager))); + require(valueBytes.length == 20, "length of manager address mismatch in tests"); + + updateParamByGovHub(key, valueBytes, address(newRelayerHub)); - // check if manager is there + // check if manager is there and can add a relayer vm.prank(manager, manager); - relayerHub.registerManagerAddRelayer(newRelayer); + newRelayerHub.registerManagerAddRelayer(newRelayer); + // do illegal call + vm.prank(newRelayer, newRelayer); + vm.expectRevert(bytes("manager does not exist")); + newRelayerHub.registerManagerAddRelayer(manager); } // function testCannotRegister() public { From af5b457d35e13568343b811562c7103e24844f65 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 9 Jan 2023 11:32:47 +0000 Subject: [PATCH 39/90] testunregister --- contracts/RelayerHub.sol | 2 +- test/RelayerHub.t.sol | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index eef9fdb2..b324dd0b 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -96,7 +96,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { managers[addr] = manager(dues); managersRegistered[addr] = true; relayManagersExistMap[addr] = true; - managerToRelayer[addr] = addr; // fixme current relayer + managerToRelayer[addr] = addr; // for the current whitelisted relayers we are keeping manager and relayer address the same currentRelayers[addr] = true; } diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index 6316a9e4..2c58088a 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -48,6 +48,37 @@ contract RelayerHubTest is Deployer { newRelayerHub.registerManagerAddRelayer(manager); } + // todo test data + + + // this checks if the previously existing unregister() function can support safe exit for existing relayers after hardfork + function testunregister() public { + RelayerHub newRelayerHub = helperGetNewRelayerHub(); + + address existingRelayer1 = 0xb005741528b86F5952469d80A8614591E3c5B632; + vm.prank(existingRelayer1, existingRelayer1); + newRelayerHub.unregister(); + + address existingRelayer2 = 0x446AA6E0DC65690403dF3F127750da1322941F3e; + vm.prank(existingRelayer2, existingRelayer2); + newRelayerHub.unregister(); + + address nonExistingRelayer = 0x9fB29AAc15b9A4B7F17c3385939b007540f4d791; + vm.prank(nonExistingRelayer, nonExistingRelayer); + vm.expectRevert(bytes("relayer do not exist")); + newRelayerHub.unregister(); + } + + function helperGetNewRelayerHub() internal returns (RelayerHub) { + RelayerHub newRelayerHub; + + bytes memory relayerCode = vm.getDeployedCode("RelayerHub.sol"); + vm.etch(RELAYERHUB_CONTRACT_ADDR, relayerCode); + newRelayerHub = RelayerHub(RELAYERHUB_CONTRACT_ADDR); + + return newRelayerHub; + } + // function testCannotRegister() public { // address newRelayer = addrSet[addrIdx++]; // vm.startPrank(newRelayer, newRelayer); From f0b45900c9ae2812638cf9f6caafe6c6ef360aa6 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 9 Jan 2023 14:11:13 +0000 Subject: [PATCH 40/90] Check emit event --- test/RelayerHub.t.sol | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index 2c58088a..7207068f 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -6,6 +6,7 @@ contract RelayerHubTest is Deployer { event relayerRegister(address _relayer); event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); + event updateRelayerEvent(address _from, address _to); uint256 public requiredDeposit; uint256 public dues; @@ -24,11 +25,7 @@ contract RelayerHubTest is Deployer { } function testAddManager() public { - RelayerHub newRelayerHub; - - bytes memory relayerCode = vm.getDeployedCode("RelayerHub.sol"); - vm.etch(RELAYERHUB_CONTRACT_ADDR, relayerCode); - newRelayerHub = RelayerHub(RELAYERHUB_CONTRACT_ADDR); + RelayerHub newRelayerHub = helperGetNewRelayerHub(); bytes memory key = "addManager"; address manager = payable(addrSet[addrIdx++]); @@ -40,6 +37,8 @@ contract RelayerHubTest is Deployer { // check if manager is there and can add a relayer vm.prank(manager, manager); + vm.expectEmit(true, true, false, true); + emit updateRelayerEvent(payable(address(0)), newRelayer); newRelayerHub.registerManagerAddRelayer(newRelayer); // do illegal call From 96d1b633c0d4c7796eec45c53cdd5d79e3e3fbd6 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 9 Jan 2023 17:17:51 +0000 Subject: [PATCH 41/90] remove manager and ismanger, isrelayer test --- lib/interface/IRelayerHub.sol | 1 + test/RelayerHub.t.sol | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/interface/IRelayerHub.sol b/lib/interface/IRelayerHub.sol index 314fdf6c..68b3fb5a 100644 --- a/lib/interface/IRelayerHub.sol +++ b/lib/interface/IRelayerHub.sol @@ -37,4 +37,5 @@ interface RelayerHub { function unregister() external; function updateParam(string memory key, bytes memory value) external; function registerManagerAddRelayer(address r) external payable; + function isManager(address relayerAddress) external view returns (bool); } diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index 7207068f..55674f9d 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -7,6 +7,7 @@ contract RelayerHubTest is Deployer { event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); event updateRelayerEvent(address _from, address _to); + event removeManagerByGovEvent(address _manager); uint256 public requiredDeposit; uint256 public dues; @@ -27,13 +28,13 @@ contract RelayerHubTest is Deployer { function testAddManager() public { RelayerHub newRelayerHub = helperGetNewRelayerHub(); - bytes memory key = "addManager"; + bytes memory keyAddManager = "addManager"; address manager = payable(addrSet[addrIdx++]); address newRelayer = payable(addrSet[addrIdx++]); - bytes memory valueBytes = abi.encodePacked(bytes20(uint160(manager))); - require(valueBytes.length == 20, "length of manager address mismatch in tests"); + bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); + require(valueManagerBytes.length == 20, "length of manager address mismatch in tests"); - updateParamByGovHub(key, valueBytes, address(newRelayerHub)); + updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); // check if manager is there and can add a relayer vm.prank(manager, manager); @@ -45,6 +46,22 @@ contract RelayerHubTest is Deployer { vm.prank(newRelayer, newRelayer); vm.expectRevert(bytes("manager does not exist")); newRelayerHub.registerManagerAddRelayer(manager); + + bool isRelayerTrue = newRelayerHub.isRelayer(newRelayer); + assertTrue(isRelayerTrue); + + bool isManagerTrue = newRelayerHub.isManager(manager); + assertTrue(isManagerTrue); + + // remove manager test i.e. for removeManager() + bytes memory keyRemoveManager = "removeManager"; + vm.expectEmit(true, true, false, true); + emit removeManagerByGovEvent(manager); + updateParamByGovHub(keyRemoveManager, valueManagerBytes, address(newRelayerHub)); + +// bool isRelayerFalse = newRelayerHub.isRelayer(manager); +// assertFalse(isRelayerFalse); + } // todo test data From 7c5f2a0c38f5f8ab092af181f45a840e2f87fea3 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 10 Jan 2023 07:23:53 +0000 Subject: [PATCH 42/90] removeManagerByHimself test + comments --- contracts/RelayerHub.sol | 1 + lib/interface/IRelayerHub.sol | 1 + test/RelayerHub.t.sol | 21 ++++++++++++++++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index b324dd0b..2e015a37 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -85,6 +85,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit relayerUnRegister(msg.sender); } + // todo this is probably no longer needed, so remove this function update() external { require(!alreadyUpdate, "the contract already updated"); addInitRelayer(WHITELIST_1); diff --git a/lib/interface/IRelayerHub.sol b/lib/interface/IRelayerHub.sol index 68b3fb5a..b46a4928 100644 --- a/lib/interface/IRelayerHub.sol +++ b/lib/interface/IRelayerHub.sol @@ -38,4 +38,5 @@ interface RelayerHub { function updateParam(string memory key, bytes memory value) external; function registerManagerAddRelayer(address r) external payable; function isManager(address relayerAddress) external view returns (bool); + function removeManagerByHimself() external; } diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index 55674f9d..c0ba94f0 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -47,9 +47,11 @@ contract RelayerHubTest is Deployer { vm.expectRevert(bytes("manager does not exist")); newRelayerHub.registerManagerAddRelayer(manager); + // check if relayer is added bool isRelayerTrue = newRelayerHub.isRelayer(newRelayer); assertTrue(isRelayerTrue); + // check if manager is added bool isManagerTrue = newRelayerHub.isManager(manager); assertTrue(isManagerTrue); @@ -59,15 +61,22 @@ contract RelayerHubTest is Deployer { emit removeManagerByGovEvent(manager); updateParamByGovHub(keyRemoveManager, valueManagerBytes, address(newRelayerHub)); -// bool isRelayerFalse = newRelayerHub.isRelayer(manager); -// assertFalse(isRelayerFalse); + // check if relayer got removed + bool isRelayerFalse = newRelayerHub.isRelayer(newRelayer); + assertFalse(isRelayerFalse); - } - - // todo test data + // check if manager got removed + bool isManagerFalse = newRelayerHub.isManager(manager); + assertFalse(isManagerFalse); + // check if the manager can remove himself + updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); + vm.prank(manager, manager); + newRelayerHub.removeManagerByHimself(); + } // this checks if the previously existing unregister() function can support safe exit for existing relayers after hardfork + // this indirectly tests whether update() was called or not function testunregister() public { RelayerHub newRelayerHub = helperGetNewRelayerHub(); @@ -85,6 +94,8 @@ contract RelayerHubTest is Deployer { newRelayerHub.unregister(); } + // helperGetNewRelayerHub() deploys the new RelayerHub into the existing mainnet data so that we can test + // data compatibility function helperGetNewRelayerHub() internal returns (RelayerHub) { RelayerHub newRelayerHub; From 466688db87877076c43849109db894519952e56c Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 10 Jan 2023 08:42:20 +0000 Subject: [PATCH 43/90] testCurrentRelayerTransition() and update() --- lib/interface/IRelayerHub.sol | 1 + test/RelayerHub.t.sol | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/interface/IRelayerHub.sol b/lib/interface/IRelayerHub.sol index b46a4928..0baeef58 100644 --- a/lib/interface/IRelayerHub.sol +++ b/lib/interface/IRelayerHub.sol @@ -39,4 +39,5 @@ interface RelayerHub { function registerManagerAddRelayer(address r) external payable; function isManager(address relayerAddress) external view returns (bool); function removeManagerByHimself() external; + function update() external; } diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index c0ba94f0..b20dab7d 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -76,7 +76,6 @@ contract RelayerHubTest is Deployer { } // this checks if the previously existing unregister() function can support safe exit for existing relayers after hardfork - // this indirectly tests whether update() was called or not function testunregister() public { RelayerHub newRelayerHub = helperGetNewRelayerHub(); @@ -94,6 +93,33 @@ contract RelayerHubTest is Deployer { newRelayerHub.unregister(); } + function testCurrentRelayerTransition() public { + RelayerHub newRelayerHub = helperGetNewRelayerHub(); + + // an existing manager/relayer won't be shown to be valid since update() isn't called + // note that for pre-hardfork, the relayer and manager are the same for simplicity + address existingRelayer1 = 0xb005741528b86F5952469d80A8614591E3c5B632; + bool isManagerFalse = newRelayerHub.isManager(existingRelayer1); + assertFalse(isManagerFalse); + bool isRelayerFalse = newRelayerHub.isRelayer(existingRelayer1); + assertFalse(isRelayerFalse); + + + // now we call update() and the existing relayer/manager should be shown to be valid + newRelayerHub.update(); + bool isManagerTrue = newRelayerHub.isManager(existingRelayer1); + assertTrue(isManagerTrue); + bool isRelayerTrue = newRelayerHub.isRelayer(existingRelayer1); + assertTrue(isRelayerTrue); + + // for completeness, now we test that a non-existing address isn't a relayer or manager + address nonExistingRelayer = 0x9fB29AAc15b9A4B7F17c3385939b007540f4d791; + bool isManagerFalse2 = newRelayerHub.isManager(nonExistingRelayer); + assertFalse(isManagerFalse2); + bool isRelayerFalse2 = newRelayerHub.isRelayer(nonExistingRelayer); + assertFalse(isRelayerFalse2); + } + // helperGetNewRelayerHub() deploys the new RelayerHub into the existing mainnet data so that we can test // data compatibility function helperGetNewRelayerHub() internal returns (RelayerHub) { From d0b9e2ad1dc6c4b2f776895b04976ef67263c6b9 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 10 Jan 2023 12:38:35 +0000 Subject: [PATCH 44/90] Remove manager struct --- contracts/RelayerHub.sol | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 2e015a37..27b1200e 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -27,7 +27,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { uint256 dues; } - mapping(address => manager) managers; + mapping(address => uint256) managerDeus; mapping(address => bool) managersRegistered; mapping(address => bool) relayManagersExistMap; mapping(address => address) managerToRelayer; @@ -35,10 +35,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { bool public alreadyUpdate; - struct manager { - uint256 dues; - } - modifier onlyNonRegisteredManager() { require(relayManagersExistMap[msg.sender], "manager does not exist"); _; @@ -94,7 +90,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } function addInitRelayer(address addr) internal { - managers[addr] = manager(dues); + managerDeus[addr] = dues; managersRegistered[addr] = true; relayManagersExistMap[addr] = true; managerToRelayer[addr] = addr; // for the current whitelisted relayers we are keeping manager and relayer address the same @@ -149,11 +145,11 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { delete (relayManagersExistMap[managerAddress]); delete (managerToRelayer[managerAddress]); - manager memory m = managers[managerAddress]; + uint256 mDues = managerDeus[managerAddress]; address payable systemPayable = payable(address(uint160(SYSTEM_REWARD_ADDR))); - systemPayable.transfer(m.dues); + systemPayable.transfer(mDues); - delete (managers[managerAddress]); + delete (managerDeus[managerAddress]); delete (managersRegistered[managerAddress]); // emit success event @@ -174,7 +170,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } function registerManager() internal { - managers[msg.sender] = manager(dues); + managerDeus[msg.sender] = dues; managersRegistered[msg.sender] = true; emit registerManagerEvent(msg.sender); } From 58f82eb262cc49e4ed655215eb6812f3e8b57636 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 11 Jan 2023 13:55:03 +0000 Subject: [PATCH 45/90] Refactor + remove unwanted functions --- contracts/RelayerHub.sol | 37 +++++++++++++------------------------ test/RelayerHub.t.sol | 4 ++-- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 27b1200e..f1f8093c 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -27,7 +27,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { uint256 dues; } - mapping(address => uint256) managerDeus; + mapping(address => uint256) managerDues; mapping(address => bool) managersRegistered; mapping(address => bool) relayManagersExistMap; mapping(address => address) managerToRelayer; @@ -46,11 +46,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { _; } - modifier noProxy() { - require(msg.sender == tx.origin, "no proxy is allowed"); - _; - } - modifier exist() { require(relayersExistMap[msg.sender], "relayer do not exist"); _; @@ -60,7 +55,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); - event removeManagerByGovEvent(address _removedManager); + event removeManagerEvent(address _removedManager); event addManagerByGovEvent(address _addedManager); event registerManagerEvent(address _registeredManager); event updateRelayerEvent(address _from, address _to); @@ -90,7 +85,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } function addInitRelayer(address addr) internal { - managerDeus[addr] = dues; + managerDues[addr] = dues; managersRegistered[addr] = true; relayManagersExistMap[addr] = true; managerToRelayer[addr] = addr; // for the current whitelisted relayers we are keeping manager and relayer address the same @@ -119,7 +114,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { require(value.length == 20, "length of manager address mismatch"); address payable managerAddress = payable(BytesToTypes.bytesToAddress(20, value)); - removeManagerByGov(managerAddress); + removeManager(managerAddress); } else { require(false, "unknown param"); @@ -127,10 +122,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit paramChange(key, value); } - function removeManagerByGov(address payable managerToBeRemoved) internal { - removeManager(managerToBeRemoved); - } - function removeManagerByHimself() external { // here the manager removes himself removeManager(payable(msg.sender)); @@ -145,15 +136,15 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { delete (relayManagersExistMap[managerAddress]); delete (managerToRelayer[managerAddress]); - uint256 mDues = managerDeus[managerAddress]; + uint256 mDues = managerDues[managerAddress]; address payable systemPayable = payable(address(uint160(SYSTEM_REWARD_ADDR))); systemPayable.transfer(mDues); - delete (managerDeus[managerAddress]); + delete (managerDues[managerAddress]); delete (managersRegistered[managerAddress]); // emit success event - emit removeManagerByGovEvent(managerAddress); + emit removeManagerEvent(managerAddress); if (relayerAddress != address(0)) { delete (currentRelayers[relayerAddress]); emit updateRelayerEvent(relayerAddress, address(0)); @@ -169,12 +160,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit addManagerByGovEvent(managerToBeAdded); } - function registerManager() internal { - managerDeus[msg.sender] = dues; - managersRegistered[msg.sender] = true; - emit registerManagerEvent(msg.sender); - } - // updateRelayer() can be used to add relayer for the first time, update it in future and remove it // in case of removal we can simply update it to a non-existing account function updateRelayer(address relayerToBeAdded) public onlyRegisteredManager { @@ -182,7 +167,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); address oldRelayer = managerToRelayer[msg.sender]; - currentRelayers[oldRelayer] = false; + delete currentRelayers[oldRelayer]; managerToRelayer[msg.sender] = relayerToBeAdded; currentRelayers[relayerToBeAdded] = true; @@ -191,7 +176,11 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } function registerManagerAddRelayer(address r) external payable onlyNonRegisteredManager { - registerManager(); + // register manager + managerDues[msg.sender] = dues; + managersRegistered[msg.sender] = true; + emit registerManagerEvent(msg.sender); + updateRelayer(r); } diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index b20dab7d..842e3b10 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -7,7 +7,7 @@ contract RelayerHubTest is Deployer { event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); event updateRelayerEvent(address _from, address _to); - event removeManagerByGovEvent(address _manager); + event removeManagerEvent(address _manager); uint256 public requiredDeposit; uint256 public dues; @@ -58,7 +58,7 @@ contract RelayerHubTest is Deployer { // remove manager test i.e. for removeManager() bytes memory keyRemoveManager = "removeManager"; vm.expectEmit(true, true, false, true); - emit removeManagerByGovEvent(manager); + emit removeManagerEvent(manager); updateParamByGovHub(keyRemoveManager, valueManagerBytes, address(newRelayerHub)); // check if relayer got removed From 673f92992ab73b88cb805d880df26eb302c979bf Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 11 Jan 2023 14:02:53 +0000 Subject: [PATCH 46/90] Remove check that is not needed --- contracts/RelayerHub.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index f1f8093c..a5c3bfc9 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -41,7 +41,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } modifier onlyRegisteredManager() { - require(relayManagersExistMap[msg.sender], "manager does not exist"); require(managersRegistered[msg.sender], "manager not registered"); _; } From 001e9b3482306b24505b7d67ce9e815d09952af4 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 11 Jan 2023 14:08:49 +0000 Subject: [PATCH 47/90] Refactor to less confusing name --- contracts/RelayerHub.sol | 9 ++++----- lib/interface/IRelayerHub.sol | 2 +- test/RelayerHub.t.sol | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index a5c3bfc9..50ededf3 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -33,7 +33,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { mapping(address => address) managerToRelayer; mapping(address => bool) currentRelayers; - bool public alreadyUpdate; + bool public whitelistInitDone; modifier onlyNonRegisteredManager() { require(relayManagersExistMap[msg.sender], "manager does not exist"); @@ -75,12 +75,11 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit relayerUnRegister(msg.sender); } - // todo this is probably no longer needed, so remove this - function update() external { - require(!alreadyUpdate, "the contract already updated"); + function whitelistInit() external { + require(!whitelistInitDone, "the whitelists already updated"); addInitRelayer(WHITELIST_1); addInitRelayer(WHITELIST_2); - alreadyUpdate = true; + whitelistInitDone = true; } function addInitRelayer(address addr) internal { diff --git a/lib/interface/IRelayerHub.sol b/lib/interface/IRelayerHub.sol index 0baeef58..e524d4e9 100644 --- a/lib/interface/IRelayerHub.sol +++ b/lib/interface/IRelayerHub.sol @@ -39,5 +39,5 @@ interface RelayerHub { function registerManagerAddRelayer(address r) external payable; function isManager(address relayerAddress) external view returns (bool); function removeManagerByHimself() external; - function update() external; + function whitelistInit() external; } diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index 842e3b10..3963f77d 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -106,7 +106,7 @@ contract RelayerHubTest is Deployer { // now we call update() and the existing relayer/manager should be shown to be valid - newRelayerHub.update(); + newRelayerHub.whitelistInit(); bool isManagerTrue = newRelayerHub.isManager(existingRelayer1); assertTrue(isManagerTrue); bool isRelayerTrue = newRelayerHub.isRelayer(existingRelayer1); From 286f4cebb905d182ab7fadc75356c3a8d16919b1 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Thu, 12 Jan 2023 08:12:36 +0000 Subject: [PATCH 48/90] Ensure manager isn't already registered --- contracts/RelayerHub.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 50ededf3..dffb73b5 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -37,6 +37,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { modifier onlyNonRegisteredManager() { require(relayManagersExistMap[msg.sender], "manager does not exist"); + require(!managersRegistered[msg.sender], "manager already registered"); _; } From ee7473186856adc6d46ed830a238ef17dab42ef6 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Fri, 13 Jan 2023 14:26:18 +0000 Subject: [PATCH 49/90] bug info --- contracts/RelayerHub.sol | 1 + lib/interface/IRelayerHub.sol | 1 + 2 files changed, 2 insertions(+) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index dffb73b5..f1dcf939 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -162,6 +162,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // updateRelayer() can be used to add relayer for the first time, update it in future and remove it // in case of removal we can simply update it to a non-existing account function updateRelayer(address relayerToBeAdded) public onlyRegisteredManager { + // todo this is a bug which the current test doesn't capture. Write test which captures this and then add separate case for 0 address require(!currentRelayers[relayerToBeAdded], "relayer already exists"); require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); diff --git a/lib/interface/IRelayerHub.sol b/lib/interface/IRelayerHub.sol index e524d4e9..ea8644d3 100644 --- a/lib/interface/IRelayerHub.sol +++ b/lib/interface/IRelayerHub.sol @@ -40,4 +40,5 @@ interface RelayerHub { function isManager(address relayerAddress) external view returns (bool); function removeManagerByHimself() external; function whitelistInit() external; + function updateRelayer(address relayerToBeAdded) public; } From e94195874f74794ced1ebbcf7ea34af4cdcd2a75 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Fri, 13 Jan 2023 16:21:28 +0000 Subject: [PATCH 50/90] Test for relayer address 0 which had a bug --- contracts/RelayerHub.sol | 4 +- lib/interface/IRelayerHub.sol | 19 +++++-- test/RelayerHub.t.sol | 101 +++++++++++++++++++++++++++++++--- 3 files changed, 109 insertions(+), 15 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index f1dcf939..e90e93b1 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -163,7 +163,9 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // in case of removal we can simply update it to a non-existing account function updateRelayer(address relayerToBeAdded) public onlyRegisteredManager { // todo this is a bug which the current test doesn't capture. Write test which captures this and then add separate case for 0 address - require(!currentRelayers[relayerToBeAdded], "relayer already exists"); + if (relayerToBeAdded != address(0)){ + require(!currentRelayers[relayerToBeAdded], "relayer already exists"); + } require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); address oldRelayer = managerToRelayer[msg.sender]; diff --git a/lib/interface/IRelayerHub.sol b/lib/interface/IRelayerHub.sol index ea8644d3..9de78e29 100644 --- a/lib/interface/IRelayerHub.sol +++ b/lib/interface/IRelayerHub.sol @@ -1,9 +1,13 @@ pragma solidity ^0.8.10; interface RelayerHub { + event addManagerByGovEvent(address _addedManager); event paramChange(string key, bytes value); + event registerManagerEvent(address _registeredManager); event relayerRegister(address _relayer); event relayerUnRegister(address _relayer); + event removeManagerEvent(address _removedManager); + event updateRelayerEvent(address _from, address _to); function BIND_CHANNELID() external view returns (uint8); function CODE_OK() external view returns (uint32); @@ -27,18 +31,21 @@ interface RelayerHub { function TRANSFER_IN_CHANNELID() external view returns (uint8); function TRANSFER_OUT_CHANNELID() external view returns (uint8); function VALIDATOR_CONTRACT_ADDR() external view returns (address); + function WHITELIST_1() external view returns (address); + function WHITELIST_2() external view returns (address); function alreadyInit() external view returns (bool); function bscChainID() external view returns (uint16); function dues() external view returns (uint256); function init() external; - function isRelayer(address sender) external view returns (bool); - function register() external payable; + function isManager(address relayerAddress) external view returns (bool); + function isRelayer(address relayerAddress) external view returns (bool); + function registerManagerAddRelayer(address r) external payable; + function removeManagerByHimself() external; function requiredDeposit() external view returns (uint256); function unregister() external; function updateParam(string memory key, bytes memory value) external; - function registerManagerAddRelayer(address r) external payable; - function isManager(address relayerAddress) external view returns (bool); - function removeManagerByHimself() external; + function updateRelayer(address relayerToBeAdded) external; function whitelistInit() external; - function updateRelayer(address relayerToBeAdded) public; + function whitelistInitDone() external view returns (bool); } + diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index 3963f77d..9845709e 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -17,14 +17,6 @@ contract RelayerHubTest is Deployer { dues = relayerHub.dues(); } - // new relayer register is suspended - function testRegister() public { - address newRelayer = addrSet[addrIdx++]; - vm.prank(newRelayer, newRelayer); - vm.expectRevert(bytes("register suspended")); - relayerHub.register{value : 100 ether}(); - } - function testAddManager() public { RelayerHub newRelayerHub = helperGetNewRelayerHub(); @@ -55,6 +47,20 @@ contract RelayerHubTest is Deployer { bool isManagerTrue = newRelayerHub.isManager(manager); assertTrue(isManagerTrue); + // set relayer to something else + address newRelayer2 = payable(addrSet[addrIdx++]); + vm.prank(manager, manager); + vm.expectEmit(true, true, false, true); + emit updateRelayerEvent(newRelayer, newRelayer2); + newRelayerHub.updateRelayer(newRelayer2); + + // set relayer to 0 + vm.prank(manager, manager); + vm.expectEmit(true, true, false, true); + emit updateRelayerEvent(newRelayer2, payable(address(0))); + newRelayerHub.updateRelayer(payable(address(0))); + + // remove manager test i.e. for removeManager() bytes memory keyRemoveManager = "removeManager"; vm.expectEmit(true, true, false, true); @@ -75,6 +81,45 @@ contract RelayerHubTest is Deployer { newRelayerHub.removeManagerByHimself(); } + function testRelayerAddingRemoving() public { + RelayerHub newRelayerHub = helperGetNewRelayerHub(); + + bytes memory keyAddManager = "addManager"; + address manager = payable(addrSet[addrIdx++]); + address newRelayer = payable(addrSet[addrIdx++]); + bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); + require(valueManagerBytes.length == 20, "length of manager address mismatch in tests"); + updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); + + vm.prank(manager, manager); + vm.expectEmit(true, true, false, true); + emit updateRelayerEvent(payable(address(0)), newRelayer); + newRelayerHub.registerManagerAddRelayer(newRelayer); + + // set relayer to 0 + vm.prank(manager, manager); + vm.expectEmit(true, true, false, true); + emit updateRelayerEvent(newRelayer, payable(address(0))); + newRelayerHub.updateRelayer(payable(address(0))); + + // get a new manager, have its relayer registered and then try to remove the relayer for this manager + address manager2 = payable(addrSet[addrIdx++]); + bytes memory valueManagerBytes2 = abi.encodePacked(bytes20(uint160(manager2))); + require(valueManagerBytes2.length == 20, "length of manager2 address mismatch in tests"); + updateParamByGovHub(keyAddManager, valueManagerBytes2, address(newRelayerHub)); + address newRelayer2 = payable(addrSet[addrIdx++]); + vm.prank(manager2, manager2); + vm.expectEmit(true, true, false, true); + emit updateRelayerEvent(payable(address(0)), newRelayer2); + newRelayerHub.registerManagerAddRelayer(newRelayer2); + // set relayer to 0 + vm.prank(manager2, manager2); + vm.expectEmit(true, true, false, true); + emit updateRelayerEvent(newRelayer2, payable(address(0))); + newRelayerHub.updateRelayer(payable(address(0))); + + } + // this checks if the previously existing unregister() function can support safe exit for existing relayers after hardfork function testunregister() public { RelayerHub newRelayerHub = helperGetNewRelayerHub(); @@ -132,6 +177,46 @@ contract RelayerHubTest is Deployer { return newRelayerHub; } + function testRelayerAddingRemoving2() public { + RelayerHub newRelayerHub = helperGetNewRelayerHub(); + + bytes memory keyAddManager = "addManager"; + address manager = payable(addrSet[addrIdx++]); + address newRelayer = payable(addrSet[addrIdx++]); + bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); + require(valueManagerBytes.length == 20, "length of manager address mismatch in tests"); + updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); + + vm.prank(manager, manager); + vm.expectEmit(true, true, false, true); + emit updateRelayerEvent(payable(address(0)), newRelayer); + newRelayerHub.registerManagerAddRelayer(newRelayer); + + address manager2 = payable(addrSet[addrIdx++]); + bytes memory valueManagerBytes2 = abi.encodePacked(bytes20(uint160(manager2))); + require(valueManagerBytes2.length == 20, "length of manager2 address mismatch in tests"); + updateParamByGovHub(keyAddManager, valueManagerBytes2, address(newRelayerHub)); + address newRelayer2 = payable(addrSet[addrIdx++]); + vm.prank(manager2, manager2); + vm.expectEmit(true, true, false, true); + emit updateRelayerEvent(payable(address(0)), newRelayer2); + newRelayerHub.registerManagerAddRelayer(newRelayer2); + + // set relayer to 0 for first manager + vm.prank(manager, manager); + vm.expectEmit(true, true, false, true); + emit updateRelayerEvent(newRelayer, payable(address(0))); + newRelayerHub.updateRelayer(payable(address(0))); + + + // set relayer to 0 for second manager + vm.prank(manager2, manager2); + vm.expectEmit(true, true, false, true); + emit updateRelayerEvent(newRelayer2, payable(address(0))); + newRelayerHub.updateRelayer(payable(address(0))); + + } + // function testCannotRegister() public { // address newRelayer = addrSet[addrIdx++]; // vm.startPrank(newRelayer, newRelayer); From 07efff46b7c95c9b1a1a599f96aaa39a9089acdb Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Fri, 13 Jan 2023 16:22:23 +0000 Subject: [PATCH 51/90] Remove todo which is already done now --- contracts/RelayerHub.sol | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index e90e93b1..85e0ff96 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -162,8 +162,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // updateRelayer() can be used to add relayer for the first time, update it in future and remove it // in case of removal we can simply update it to a non-existing account function updateRelayer(address relayerToBeAdded) public onlyRegisteredManager { - // todo this is a bug which the current test doesn't capture. Write test which captures this and then add separate case for 0 address - if (relayerToBeAdded != address(0)){ + if (relayerToBeAdded != address(0)) { require(!currentRelayers[relayerToBeAdded], "relayer already exists"); } require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); From 1e4ab6840810d5a04d02becae2b66c17959dbaad Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 16 Jan 2023 08:48:34 +0000 Subject: [PATCH 52/90] Combine to one manager struct --- contracts/RelayerHub.sol | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 85e0ff96..90cf52c9 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -27,8 +27,12 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { uint256 dues; } - mapping(address => uint256) managerDues; - mapping(address => bool) managersRegistered; + struct manager { + uint256 dues; + bool registered; + } + + mapping(address => manager) managers; mapping(address => bool) relayManagersExistMap; mapping(address => address) managerToRelayer; mapping(address => bool) currentRelayers; @@ -37,12 +41,12 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { modifier onlyNonRegisteredManager() { require(relayManagersExistMap[msg.sender], "manager does not exist"); - require(!managersRegistered[msg.sender], "manager already registered"); + require(!managers[msg.sender].registered, "manager already registered"); _; } modifier onlyRegisteredManager() { - require(managersRegistered[msg.sender], "manager not registered"); + require(managers[msg.sender].registered, "manager not registered"); _; } @@ -84,8 +88,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } function addInitRelayer(address addr) internal { - managerDues[addr] = dues; - managersRegistered[addr] = true; + managers[addr] = manager(dues, true); relayManagersExistMap[addr] = true; managerToRelayer[addr] = addr; // for the current whitelisted relayers we are keeping manager and relayer address the same currentRelayers[addr] = true; @@ -132,15 +135,16 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { address relayerAddress = managerToRelayer[managerAddress]; + manager memory m = managers[managerAddress]; + delete (relayManagersExistMap[managerAddress]); delete (managerToRelayer[managerAddress]); - uint256 mDues = managerDues[managerAddress]; address payable systemPayable = payable(address(uint160(SYSTEM_REWARD_ADDR))); - systemPayable.transfer(mDues); + systemPayable.transfer(m.dues); + + delete(managers[managerAddress]); - delete (managerDues[managerAddress]); - delete (managersRegistered[managerAddress]); // emit success event emit removeManagerEvent(managerAddress); @@ -178,8 +182,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { function registerManagerAddRelayer(address r) external payable onlyNonRegisteredManager { // register manager - managerDues[msg.sender] = dues; - managersRegistered[msg.sender] = true; + managers[msg.sender] = manager(dues, true); emit registerManagerEvent(msg.sender); updateRelayer(r); From 876f9ef2afb573a006b6bf24e92da7ad6f6d4c23 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 16 Jan 2023 15:02:25 +0000 Subject: [PATCH 53/90] Remove dues --- contracts/RelayerHub.sol | 31 ++++++------------------------- test/RelayerHub.t.sol | 12 ++++++------ 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 90cf52c9..21b5aaf9 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -32,21 +32,16 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { bool registered; } - mapping(address => manager) managers; + // mapping(address => manager) managers; + // address payable[] managerS; mapping(address => bool) relayManagersExistMap; mapping(address => address) managerToRelayer; mapping(address => bool) currentRelayers; bool public whitelistInitDone; - modifier onlyNonRegisteredManager() { + modifier onlyManager(){ require(relayManagersExistMap[msg.sender], "manager does not exist"); - require(!managers[msg.sender].registered, "manager already registered"); - _; - } - - modifier onlyRegisteredManager() { - require(managers[msg.sender].registered, "manager not registered"); _; } @@ -88,7 +83,8 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } function addInitRelayer(address addr) internal { - managers[addr] = manager(dues, true); +// managers[addr] = manager(dues, true); +// managerS.push(addr); relayManagersExistMap[addr] = true; managerToRelayer[addr] = addr; // for the current whitelisted relayers we are keeping manager and relayer address the same currentRelayers[addr] = true; @@ -135,17 +131,9 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { address relayerAddress = managerToRelayer[managerAddress]; - manager memory m = managers[managerAddress]; - delete (relayManagersExistMap[managerAddress]); delete (managerToRelayer[managerAddress]); - address payable systemPayable = payable(address(uint160(SYSTEM_REWARD_ADDR))); - systemPayable.transfer(m.dues); - - delete(managers[managerAddress]); - - // emit success event emit removeManagerEvent(managerAddress); if (relayerAddress != address(0)) { @@ -165,7 +153,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // updateRelayer() can be used to add relayer for the first time, update it in future and remove it // in case of removal we can simply update it to a non-existing account - function updateRelayer(address relayerToBeAdded) public onlyRegisteredManager { + function updateRelayer(address relayerToBeAdded) public onlyManager { if (relayerToBeAdded != address(0)) { require(!currentRelayers[relayerToBeAdded], "relayer already exists"); } @@ -180,13 +168,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit updateRelayerEvent(oldRelayer, relayerToBeAdded); } - function registerManagerAddRelayer(address r) external payable onlyNonRegisteredManager { - // register manager - managers[msg.sender] = manager(dues, true); - emit registerManagerEvent(msg.sender); - - updateRelayer(r); - } function isRelayer(address relayerAddress) external override view returns (bool){ return currentRelayers[relayerAddress]; diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index 9845709e..e476a92b 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -32,12 +32,12 @@ contract RelayerHubTest is Deployer { vm.prank(manager, manager); vm.expectEmit(true, true, false, true); emit updateRelayerEvent(payable(address(0)), newRelayer); - newRelayerHub.registerManagerAddRelayer(newRelayer); + newRelayerHub.updateRelayer(newRelayer); // do illegal call vm.prank(newRelayer, newRelayer); vm.expectRevert(bytes("manager does not exist")); - newRelayerHub.registerManagerAddRelayer(manager); + newRelayerHub.updateRelayer(manager); // check if relayer is added bool isRelayerTrue = newRelayerHub.isRelayer(newRelayer); @@ -94,7 +94,7 @@ contract RelayerHubTest is Deployer { vm.prank(manager, manager); vm.expectEmit(true, true, false, true); emit updateRelayerEvent(payable(address(0)), newRelayer); - newRelayerHub.registerManagerAddRelayer(newRelayer); + newRelayerHub.updateRelayer(newRelayer); // set relayer to 0 vm.prank(manager, manager); @@ -111,7 +111,7 @@ contract RelayerHubTest is Deployer { vm.prank(manager2, manager2); vm.expectEmit(true, true, false, true); emit updateRelayerEvent(payable(address(0)), newRelayer2); - newRelayerHub.registerManagerAddRelayer(newRelayer2); + newRelayerHub.updateRelayer(newRelayer2); // set relayer to 0 vm.prank(manager2, manager2); vm.expectEmit(true, true, false, true); @@ -190,7 +190,7 @@ contract RelayerHubTest is Deployer { vm.prank(manager, manager); vm.expectEmit(true, true, false, true); emit updateRelayerEvent(payable(address(0)), newRelayer); - newRelayerHub.registerManagerAddRelayer(newRelayer); + newRelayerHub.updateRelayer(newRelayer); address manager2 = payable(addrSet[addrIdx++]); bytes memory valueManagerBytes2 = abi.encodePacked(bytes20(uint160(manager2))); @@ -200,7 +200,7 @@ contract RelayerHubTest is Deployer { vm.prank(manager2, manager2); vm.expectEmit(true, true, false, true); emit updateRelayerEvent(payable(address(0)), newRelayer2); - newRelayerHub.registerManagerAddRelayer(newRelayer2); + newRelayerHub.updateRelayer(newRelayer2); // set relayer to 0 for first manager vm.prank(manager, manager); From 3d05cbfed44a30529915eec0edda35c7cf45d3bc Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 16 Jan 2023 15:03:41 +0000 Subject: [PATCH 54/90] remove unwanted code --- contracts/RelayerHub.sol | 9 --------- 1 file changed, 9 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 21b5aaf9..8a772b1e 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -27,13 +27,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { uint256 dues; } - struct manager { - uint256 dues; - bool registered; - } - - // mapping(address => manager) managers; - // address payable[] managerS; mapping(address => bool) relayManagersExistMap; mapping(address => address) managerToRelayer; mapping(address => bool) currentRelayers; @@ -83,8 +76,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } function addInitRelayer(address addr) internal { -// managers[addr] = manager(dues, true); -// managerS.push(addr); relayManagersExistMap[addr] = true; managerToRelayer[addr] = addr; // for the current whitelisted relayers we are keeping manager and relayer address the same currentRelayers[addr] = true; From 6186657a3919fe9806f106eaafcc49dad75a7ebc Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 17 Jan 2023 13:00:52 +0000 Subject: [PATCH 55/90] ensure 0 address is not a relayer --- contracts/RelayerHub.sol | 2 +- test/RelayerHub.t.sol | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 8a772b1e..5b08ed12 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -147,6 +147,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { function updateRelayer(address relayerToBeAdded) public onlyManager { if (relayerToBeAdded != address(0)) { require(!currentRelayers[relayerToBeAdded], "relayer already exists"); + currentRelayers[relayerToBeAdded] = true; } require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); @@ -154,7 +155,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { delete currentRelayers[oldRelayer]; managerToRelayer[msg.sender] = relayerToBeAdded; - currentRelayers[relayerToBeAdded] = true; emit updateRelayerEvent(oldRelayer, relayerToBeAdded); } diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index e476a92b..8d7c484b 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -60,6 +60,8 @@ contract RelayerHubTest is Deployer { emit updateRelayerEvent(newRelayer2, payable(address(0))); newRelayerHub.updateRelayer(payable(address(0))); + // ensure 0 address is not a relayer + assertFalse(newRelayerHub.isRelayer(address(0))); // remove manager test i.e. for removeManager() bytes memory keyRemoveManager = "removeManager"; From 164c20a8c2768564466e7eea5893bf007f2cfa81 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 17 Jan 2023 13:05:14 +0000 Subject: [PATCH 56/90] remove deposit and dues code in updateParam --- contracts/RelayerHub.sol | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 5b08ed12..e14dd50f 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -83,28 +83,14 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { /*********************** Param update ********************************/ function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov { - if (Memory.compareStrings(key, "requiredDeposit")) { - require(value.length == 32, "length of requiredDeposit mismatch"); - uint256 newRequiredDeposit = BytesToTypes.bytesToUint256(32, value); - require(newRequiredDeposit > 1 && newRequiredDeposit <= 1e21 && newRequiredDeposit > dues, "the requiredDeposit out of range"); - requiredDeposit = newRequiredDeposit; - } else if (Memory.compareStrings(key, "dues")) { - require(value.length == 32, "length of dues mismatch"); - uint256 newDues = BytesToTypes.bytesToUint256(32, value); - require(newDues > 0 && newDues < requiredDeposit, "the dues out of range"); - dues = newDues; - } else if (Memory.compareStrings(key, "addManager")) { - + if (Memory.compareStrings(key, "addManager")) { require(value.length == 20, "length of manager address mismatch"); address newManager = BytesToTypes.bytesToAddress(20, value); addManagerByGov(newManager); - } else if (Memory.compareStrings(key, "removeManager")) { - require(value.length == 20, "length of manager address mismatch"); address payable managerAddress = payable(BytesToTypes.bytesToAddress(20, value)); removeManager(managerAddress); - } else { require(false, "unknown param"); } @@ -159,12 +145,10 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit updateRelayerEvent(oldRelayer, relayerToBeAdded); } - function isRelayer(address relayerAddress) external override view returns (bool){ return currentRelayers[relayerAddress]; } - // TODO remove just for testing function isManager(address relayerAddress) external view returns (bool){ return relayManagersExistMap[relayerAddress]; } From d1c4947c1e51b97a2da97e82973278c8d43d6bac Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 17 Jan 2023 13:52:54 +0000 Subject: [PATCH 57/90] template file update + correct whitelist mainnet addr --- contracts/RelayerHub.template | 153 +++++++++++++--------------------- 1 file changed, 57 insertions(+), 96 deletions(-) diff --git a/contracts/RelayerHub.template b/contracts/RelayerHub.template index 045dadfa..020cbfed 100644 --- a/contracts/RelayerHub.template +++ b/contracts/RelayerHub.template @@ -13,6 +13,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { uint256 public constant INIT_REQUIRED_DEPOSIT = 1e20; uint256 public constant INIT_DUES = 1e17; + {% if network == 'local' %} address public constant WHITELIST_1 = 0xA904540818AC9c47f2321F97F1069B9d8746c6DB; address public constant WHITELIST_2 = 0x316b2Fa7C8a2ab7E21110a4B3f58771C01A71344; @@ -23,36 +24,34 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { address public constant WHITELIST_1 = 0x9fB29AAc15b9A4B7F17c3385939b007540f4d791; address public constant WHITELIST_2 = 0x37B8516a0F88E65D677229b402ec6C1e0E333004; {% else %} - address public constant WHITELIST_1 = 0x04d63aBCd2b9b1baa327f2Dda0f873F197ccd186; + address public constant WHITELIST_1 = 0xb005741528b86F5952469d80A8614591E3c5B632; address public constant WHITELIST_2 = 0x446AA6E0DC65690403dF3F127750da1322941F3e; {% endif %} - uint256 public requiredDeposit; + + uint256 public requiredDeposit; // have to keep it to not break the storage layout uint256 public dues; - mapping(address => manager) managers; - mapping(address => bool) managersRegistered; - mapping(address => bool) relayManagersExistMap; - mapping(address => address) managersAndRelayers; - mapping(address => bool) relayerExistsMap; + mapping(address => relayer) relayers; // old map holding the relayers which are to be allowed safe exit + mapping(address => bool) relayersExistMap; - struct manager { + struct relayer { uint256 deposit; uint256 dues; } - modifier onlyNonRegisteredManager() { - require(relayManagersExistMap[msg.sender], "manager does not exist"); - _; - } + mapping(address => bool) relayManagersExistMap; + mapping(address => address) managerToRelayer; + mapping(address => bool) currentRelayers; + + bool public whitelistInitDone; - modifier onlyRegisteredManager() { + modifier onlyManager(){ require(relayManagersExistMap[msg.sender], "manager does not exist"); - require(managersRegistered[msg.sender], "manager not registered"); _; } - modifier noProxy() { - require(msg.sender == tx.origin, "no proxy is allowed"); + modifier exist() { + require(relayersExistMap[msg.sender], "relayer do not exist"); _; } @@ -60,89 +59,75 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); - event removeManagerByGovEvent(address _removedManager); + event removeManagerEvent(address _removedManager); event addManagerByGovEvent(address _addedManager); event registerManagerEvent(address _registeredManager); - event addRelayerEvent(address _relayerToBeAdded); - event removeRelayerEvent(address _removedRelayer); - + event updateRelayerEvent(address _from, address _to); function init() external onlyNotInit { requiredDeposit = INIT_REQUIRED_DEPOSIT; dues = INIT_DUES; + alreadyInit = true; + } + + function unregister() external exist onlyInit { + relayer memory r = relayers[msg.sender]; + msg.sender.transfer(r.deposit.sub(r.dues)); + address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); + systemPayable.transfer(r.dues); + delete relayersExistMap[msg.sender]; + delete relayers[msg.sender]; + emit relayerUnRegister(msg.sender); + } + + function whitelistInit() external { + require(!whitelistInitDone, "the whitelists already updated"); addInitRelayer(WHITELIST_1); addInitRelayer(WHITELIST_2); - alreadyInit = true; + whitelistInitDone = true; } function addInitRelayer(address addr) internal { - managers[addr] = manager(requiredDeposit, dues); - managersRegistered[addr] = true; relayManagersExistMap[addr] = true; - managersAndRelayers[addr] = addr; // fixme current relayer - relayerExistsMap[addr] = true; + managerToRelayer[addr] = addr; // for the current whitelisted relayers we are keeping manager and relayer address the same + currentRelayers[addr] = true; } /*********************** Param update ********************************/ function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov { - if (Memory.compareStrings(key, "requiredDeposit")) { - require(value.length == 32, "length of requiredDeposit mismatch"); - uint256 newRequiredDeposit = BytesToTypes.bytesToUint256(32, value); - require(newRequiredDeposit > 1 && newRequiredDeposit <= 1e21 && newRequiredDeposit > dues, "the requiredDeposit out of range"); - requiredDeposit = newRequiredDeposit; - } else if (Memory.compareStrings(key, "dues")) { - require(value.length == 32, "length of dues mismatch"); - uint256 newDues = BytesToTypes.bytesToUint256(32, value); - require(newDues > 0 && newDues < requiredDeposit, "the dues out of range"); - dues = newDues; - } else if (Memory.compareStrings(key, "addManager")) { - + if (Memory.compareStrings(key, "addManager")) { require(value.length == 20, "length of manager address mismatch"); address newManager = BytesToTypes.bytesToAddress(20, value); addManagerByGov(newManager); - } else if (Memory.compareStrings(key, "removeManager")) { - require(value.length == 20, "length of manager address mismatch"); address payable managerAddress = payable(BytesToTypes.bytesToAddress(20, value)); - removeManagerByGov(managerAddress); - + removeManager(managerAddress); } else { require(false, "unknown param"); } emit paramChange(key, value); } - function removeManagerByGov(address payable managerToBeRemoved) internal { - removeManagerHelper(managerToBeRemoved); - } - - function removeManager() external onlyRegisteredManager { + function removeManagerByHimself() external { // here the manager removes himself - removeManagerHelper(payable(msg.sender)); + removeManager(payable(msg.sender)); } - function removeManagerHelper(address payable managerAddress) internal { + function removeManager(address payable managerAddress) internal { // check if the manager address already exists require(relayManagersExistMap[managerAddress], "manager doesn't exist"); - address relayerAddress = managersAndRelayers[managerAddress]; + address relayerAddress = managerToRelayer[managerAddress]; delete (relayManagersExistMap[managerAddress]); - delete (managersAndRelayers[managerAddress]); - - manager memory a = managers[managerAddress]; - managerAddress.transfer(a.deposit.sub(a.dues)); - address payable systemPayable = payable(address(uint160(SYSTEM_REWARD_ADDR))); - systemPayable.transfer(a.dues); - - delete (managers[managerAddress]); - delete (managersRegistered[managerAddress]); + delete (managerToRelayer[managerAddress]); // emit success event - emit removeManagerByGovEvent(managerAddress); + emit removeManagerEvent(managerAddress); if (relayerAddress != address(0)) { - emit removeRelayerEvent(relayerAddress); + delete (currentRelayers[relayerAddress]); + emit updateRelayerEvent(relayerAddress, address(0)); } } @@ -155,51 +140,27 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { emit addManagerByGovEvent(managerToBeAdded); } - function registerManager() internal onlyNonRegisteredManager { - require(msg.value == requiredDeposit, "deposit value is not exactly the same"); - managers[msg.sender] = manager(requiredDeposit, dues); - managersRegistered[msg.sender] = true; - emit registerManagerEvent(msg.sender); - } - - function addRelayer(address relayerToBeAdded) public onlyRegisteredManager noProxy { - require(!relayerExistsMap[relayerToBeAdded], "relayer already exists"); - require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); - - if(managersAndRelayers[msg.sender] != address(0)) { - address r = managersAndRelayers[msg.sender]; - delete (relayerExistsMap[r]); - emit removeRelayerEvent(r); - } - - managersAndRelayers[msg.sender] = relayerToBeAdded; - relayerExistsMap[relayerToBeAdded] = true; - emit addRelayerEvent(relayerToBeAdded); - } - - function registerManagerAddRelayer(address relayer) external payable onlyNonRegisteredManager { - registerManager(); - addRelayer(relayer); - } - - function removeRelayer() external onlyRegisteredManager { - if (managersAndRelayers[msg.sender] == address(0)) { - require(false, "relayer doesn't exist for this manager"); + // updateRelayer() can be used to add relayer for the first time, update it in future and remove it + // in case of removal we can simply update it to a non-existing account + function updateRelayer(address relayerToBeAdded) public onlyManager { + if (relayerToBeAdded != address(0)) { + require(!currentRelayers[relayerToBeAdded], "relayer already exists"); + currentRelayers[relayerToBeAdded] = true; } + require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); - address r = managersAndRelayers[msg.sender]; + address oldRelayer = managerToRelayer[msg.sender]; + delete currentRelayers[oldRelayer]; - delete (relayerExistsMap[r]); - delete (managersAndRelayers[msg.sender]); + managerToRelayer[msg.sender] = relayerToBeAdded; - emit removeRelayerEvent(r); + emit updateRelayerEvent(oldRelayer, relayerToBeAdded); } function isRelayer(address relayerAddress) external override view returns (bool){ - return relayerExistsMap[relayerAddress]; + return currentRelayers[relayerAddress]; } - // TODO remove just for testing function isManager(address relayerAddress) external view returns (bool){ return relayManagersExistMap[relayerAddress]; } From 1ebc8fd26d6269f182dc8c60c1eef278e4b987e0 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 17 Jan 2023 14:57:02 +0000 Subject: [PATCH 58/90] check contract first --- contracts/RelayerHub.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index e14dd50f..39d976ea 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -131,11 +131,11 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // updateRelayer() can be used to add relayer for the first time, update it in future and remove it // in case of removal we can simply update it to a non-existing account function updateRelayer(address relayerToBeAdded) public onlyManager { + require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); if (relayerToBeAdded != address(0)) { require(!currentRelayers[relayerToBeAdded], "relayer already exists"); currentRelayers[relayerToBeAdded] = true; } - require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); address oldRelayer = managerToRelayer[msg.sender]; delete currentRelayers[oldRelayer]; From 919c2bb4c282fa4dd40958dfeee4ed871e8f0619 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 17 Jan 2023 15:25:30 +0000 Subject: [PATCH 59/90] refactor --- contracts/RelayerHub.sol | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 39d976ea..1382b802 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -132,15 +132,17 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // in case of removal we can simply update it to a non-existing account function updateRelayer(address relayerToBeAdded) public onlyManager { require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); - if (relayerToBeAdded != address(0)) { - require(!currentRelayers[relayerToBeAdded], "relayer already exists"); - currentRelayers[relayerToBeAdded] = true; - } address oldRelayer = managerToRelayer[msg.sender]; delete currentRelayers[oldRelayer]; - managerToRelayer[msg.sender] = relayerToBeAdded; + if (relayerToBeAdded != address(0)) { + require(!currentRelayers[relayerToBeAdded], "relayer already exists"); + currentRelayers[relayerToBeAdded] = true; + managerToRelayer[msg.sender] = relayerToBeAdded; + } else { + delete managerToRelayer[msg.sender]; + } emit updateRelayerEvent(oldRelayer, relayerToBeAdded); } From ae24743e813c9b4124034cb54246f907ddd54d99 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Fri, 20 Jan 2023 11:42:19 +0000 Subject: [PATCH 60/90] Refactor even names and regenerate interface --- contracts/RelayerHub.sol | 15 +++++----- contracts/RelayerHub.template | 53 ++++++++++++++++++----------------- lib/interface/IRelayerHub.sol | 8 ++---- test/RelayerHub.t.sol | 28 +++++++++--------- 4 files changed, 51 insertions(+), 53 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 1382b802..426d1ef3 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -47,10 +47,9 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); - event removeManagerEvent(address _removedManager); - event addManagerByGovEvent(address _addedManager); - event registerManagerEvent(address _registeredManager); - event updateRelayerEvent(address _from, address _to); + event managerRemoved(address _removedManager); + event managerAdded(address _addedManager); + event relayerUpdated(address _from, address _to); function init() external onlyNotInit { requiredDeposit = INIT_REQUIRED_DEPOSIT; @@ -112,10 +111,10 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { delete (managerToRelayer[managerAddress]); // emit success event - emit removeManagerEvent(managerAddress); + emit managerRemoved(managerAddress); if (relayerAddress != address(0)) { delete (currentRelayers[relayerAddress]); - emit updateRelayerEvent(relayerAddress, address(0)); + emit relayerUpdated(relayerAddress, address(0)); } } @@ -125,7 +124,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { relayManagersExistMap[managerToBeAdded] = true; - emit addManagerByGovEvent(managerToBeAdded); + emit managerAdded(managerToBeAdded); } // updateRelayer() can be used to add relayer for the first time, update it in future and remove it @@ -144,7 +143,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { delete managerToRelayer[msg.sender]; } - emit updateRelayerEvent(oldRelayer, relayerToBeAdded); + emit relayerUpdated(oldRelayer, relayerToBeAdded); } function isRelayer(address relayerAddress) external override view returns (bool){ diff --git a/contracts/RelayerHub.template b/contracts/RelayerHub.template index 020cbfed..06b7cafc 100644 --- a/contracts/RelayerHub.template +++ b/contracts/RelayerHub.template @@ -14,19 +14,19 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { uint256 public constant INIT_REQUIRED_DEPOSIT = 1e20; uint256 public constant INIT_DUES = 1e17; - {% if network == 'local' %} - address public constant WHITELIST_1 = 0xA904540818AC9c47f2321F97F1069B9d8746c6DB; - address public constant WHITELIST_2 = 0x316b2Fa7C8a2ab7E21110a4B3f58771C01A71344; - {% elif network == 'QA' %} - address public constant WHITELIST_1 = 0x88cb4D8F77742c24d647BEf8049D3f3C56067cDD; - address public constant WHITELIST_2 = 0x42D596440775C90db8d9187b47650986E1063493; - {% elif network == 'testnet' %} - address public constant WHITELIST_1 = 0x9fB29AAc15b9A4B7F17c3385939b007540f4d791; - address public constant WHITELIST_2 = 0x37B8516a0F88E65D677229b402ec6C1e0E333004; - {% else %} - address public constant WHITELIST_1 = 0xb005741528b86F5952469d80A8614591E3c5B632; - address public constant WHITELIST_2 = 0x446AA6E0DC65690403dF3F127750da1322941F3e; - {% endif %} + {% if network == 'local' %} + address public constant WHITELIST_1 = 0xA904540818AC9c47f2321F97F1069B9d8746c6DB; + address public constant WHITELIST_2 = 0x316b2Fa7C8a2ab7E21110a4B3f58771C01A71344; + {% elif network == 'QA' %} + address public constant WHITELIST_1 = 0x88cb4D8F77742c24d647BEf8049D3f3C56067cDD; + address public constant WHITELIST_2 = 0x42D596440775C90db8d9187b47650986E1063493; + {% elif network == 'testnet' %} + address public constant WHITELIST_1 = 0x9fB29AAc15b9A4B7F17c3385939b007540f4d791; + address public constant WHITELIST_2 = 0x37B8516a0F88E65D677229b402ec6C1e0E333004; + {% else %} + address public constant WHITELIST_1 = 0xb005741528b86F5952469d80A8614591E3c5B632; + address public constant WHITELIST_2 = 0x446AA6E0DC65690403dF3F127750da1322941F3e; + {% endif %} uint256 public requiredDeposit; // have to keep it to not break the storage layout uint256 public dues; @@ -59,10 +59,9 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); - event removeManagerEvent(address _removedManager); - event addManagerByGovEvent(address _addedManager); - event registerManagerEvent(address _registeredManager); - event updateRelayerEvent(address _from, address _to); + event managerRemoved(address _removedManager); + event managerAdded(address _addedManager); + event relayerUpdated(address _from, address _to); function init() external onlyNotInit { requiredDeposit = INIT_REQUIRED_DEPOSIT; @@ -124,10 +123,10 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { delete (managerToRelayer[managerAddress]); // emit success event - emit removeManagerEvent(managerAddress); + emit managerRemoved(managerAddress); if (relayerAddress != address(0)) { delete (currentRelayers[relayerAddress]); - emit updateRelayerEvent(relayerAddress, address(0)); + emit relayerUpdated(relayerAddress, address(0)); } } @@ -137,24 +136,26 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { relayManagersExistMap[managerToBeAdded] = true; - emit addManagerByGovEvent(managerToBeAdded); + emit managerAdded(managerToBeAdded); } // updateRelayer() can be used to add relayer for the first time, update it in future and remove it // in case of removal we can simply update it to a non-existing account function updateRelayer(address relayerToBeAdded) public onlyManager { - if (relayerToBeAdded != address(0)) { - require(!currentRelayers[relayerToBeAdded], "relayer already exists"); - currentRelayers[relayerToBeAdded] = true; - } require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); address oldRelayer = managerToRelayer[msg.sender]; delete currentRelayers[oldRelayer]; - managerToRelayer[msg.sender] = relayerToBeAdded; + if (relayerToBeAdded != address(0)) { + require(!currentRelayers[relayerToBeAdded], "relayer already exists"); + currentRelayers[relayerToBeAdded] = true; + managerToRelayer[msg.sender] = relayerToBeAdded; + } else { + delete managerToRelayer[msg.sender]; + } - emit updateRelayerEvent(oldRelayer, relayerToBeAdded); + emit relayerUpdated(oldRelayer, relayerToBeAdded); } function isRelayer(address relayerAddress) external override view returns (bool){ diff --git a/lib/interface/IRelayerHub.sol b/lib/interface/IRelayerHub.sol index 9de78e29..7ef268cb 100644 --- a/lib/interface/IRelayerHub.sol +++ b/lib/interface/IRelayerHub.sol @@ -1,13 +1,12 @@ pragma solidity ^0.8.10; interface RelayerHub { - event addManagerByGovEvent(address _addedManager); + event managerAdded(address _addedManager); + event managerRemoved(address _removedManager); event paramChange(string key, bytes value); - event registerManagerEvent(address _registeredManager); event relayerRegister(address _relayer); event relayerUnRegister(address _relayer); - event removeManagerEvent(address _removedManager); - event updateRelayerEvent(address _from, address _to); + event relayerUpdated(address _from, address _to); function BIND_CHANNELID() external view returns (uint8); function CODE_OK() external view returns (uint32); @@ -39,7 +38,6 @@ interface RelayerHub { function init() external; function isManager(address relayerAddress) external view returns (bool); function isRelayer(address relayerAddress) external view returns (bool); - function registerManagerAddRelayer(address r) external payable; function removeManagerByHimself() external; function requiredDeposit() external view returns (uint256); function unregister() external; diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index 8d7c484b..b6883b97 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -6,8 +6,8 @@ contract RelayerHubTest is Deployer { event relayerRegister(address _relayer); event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); - event updateRelayerEvent(address _from, address _to); - event removeManagerEvent(address _manager); + event relayerUpdated(address _from, address _to); + event managerRemoved(address _manager); uint256 public requiredDeposit; uint256 public dues; @@ -31,7 +31,7 @@ contract RelayerHubTest is Deployer { // check if manager is there and can add a relayer vm.prank(manager, manager); vm.expectEmit(true, true, false, true); - emit updateRelayerEvent(payable(address(0)), newRelayer); + emit relayerUpdated(payable(address(0)), newRelayer); newRelayerHub.updateRelayer(newRelayer); // do illegal call @@ -51,13 +51,13 @@ contract RelayerHubTest is Deployer { address newRelayer2 = payable(addrSet[addrIdx++]); vm.prank(manager, manager); vm.expectEmit(true, true, false, true); - emit updateRelayerEvent(newRelayer, newRelayer2); + emit relayerUpdated(newRelayer, newRelayer2); newRelayerHub.updateRelayer(newRelayer2); // set relayer to 0 vm.prank(manager, manager); vm.expectEmit(true, true, false, true); - emit updateRelayerEvent(newRelayer2, payable(address(0))); + emit relayerUpdated(newRelayer2, payable(address(0))); newRelayerHub.updateRelayer(payable(address(0))); // ensure 0 address is not a relayer @@ -66,7 +66,7 @@ contract RelayerHubTest is Deployer { // remove manager test i.e. for removeManager() bytes memory keyRemoveManager = "removeManager"; vm.expectEmit(true, true, false, true); - emit removeManagerEvent(manager); + emit managerRemoved(manager); updateParamByGovHub(keyRemoveManager, valueManagerBytes, address(newRelayerHub)); // check if relayer got removed @@ -95,13 +95,13 @@ contract RelayerHubTest is Deployer { vm.prank(manager, manager); vm.expectEmit(true, true, false, true); - emit updateRelayerEvent(payable(address(0)), newRelayer); + emit relayerUpdated(payable(address(0)), newRelayer); newRelayerHub.updateRelayer(newRelayer); // set relayer to 0 vm.prank(manager, manager); vm.expectEmit(true, true, false, true); - emit updateRelayerEvent(newRelayer, payable(address(0))); + emit relayerUpdated(newRelayer, payable(address(0))); newRelayerHub.updateRelayer(payable(address(0))); // get a new manager, have its relayer registered and then try to remove the relayer for this manager @@ -112,12 +112,12 @@ contract RelayerHubTest is Deployer { address newRelayer2 = payable(addrSet[addrIdx++]); vm.prank(manager2, manager2); vm.expectEmit(true, true, false, true); - emit updateRelayerEvent(payable(address(0)), newRelayer2); + emit relayerUpdated(payable(address(0)), newRelayer2); newRelayerHub.updateRelayer(newRelayer2); // set relayer to 0 vm.prank(manager2, manager2); vm.expectEmit(true, true, false, true); - emit updateRelayerEvent(newRelayer2, payable(address(0))); + emit relayerUpdated(newRelayer2, payable(address(0))); newRelayerHub.updateRelayer(payable(address(0))); } @@ -191,7 +191,7 @@ contract RelayerHubTest is Deployer { vm.prank(manager, manager); vm.expectEmit(true, true, false, true); - emit updateRelayerEvent(payable(address(0)), newRelayer); + emit relayerUpdated(payable(address(0)), newRelayer); newRelayerHub.updateRelayer(newRelayer); address manager2 = payable(addrSet[addrIdx++]); @@ -201,20 +201,20 @@ contract RelayerHubTest is Deployer { address newRelayer2 = payable(addrSet[addrIdx++]); vm.prank(manager2, manager2); vm.expectEmit(true, true, false, true); - emit updateRelayerEvent(payable(address(0)), newRelayer2); + emit relayerUpdated(payable(address(0)), newRelayer2); newRelayerHub.updateRelayer(newRelayer2); // set relayer to 0 for first manager vm.prank(manager, manager); vm.expectEmit(true, true, false, true); - emit updateRelayerEvent(newRelayer, payable(address(0))); + emit relayerUpdated(newRelayer, payable(address(0))); newRelayerHub.updateRelayer(payable(address(0))); // set relayer to 0 for second manager vm.prank(manager2, manager2); vm.expectEmit(true, true, false, true); - emit updateRelayerEvent(newRelayer2, payable(address(0))); + emit relayerUpdated(newRelayer2, payable(address(0))); newRelayerHub.updateRelayer(payable(address(0))); } From 805581498153c1a5a4ebf6ea7cd32e88ccd2177a Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 23 Jan 2023 06:22:42 +0000 Subject: [PATCH 61/90] payable manager not required --- contracts/RelayerHub.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 426d1ef3..3c3f88c9 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -88,7 +88,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { addManagerByGov(newManager); } else if (Memory.compareStrings(key, "removeManager")) { require(value.length == 20, "length of manager address mismatch"); - address payable managerAddress = payable(BytesToTypes.bytesToAddress(20, value)); + address managerAddress = BytesToTypes.bytesToAddress(20, value); removeManager(managerAddress); } else { require(false, "unknown param"); @@ -98,10 +98,10 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { function removeManagerByHimself() external { // here the manager removes himself - removeManager(payable(msg.sender)); + removeManager(msg.sender); } - function removeManager(address payable managerAddress) internal { + function removeManager(address managerAddress) internal { // check if the manager address already exists require(relayManagersExistMap[managerAddress], "manager doesn't exist"); From 195eccb280c42781d4df1be32991fc85cd30dd36 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 23 Jan 2023 06:28:21 +0000 Subject: [PATCH 62/90] bug fix of twice adding of same relayer + test --- contracts/RelayerHub.sol | 2 +- test/RelayerHub.t.sol | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 3c3f88c9..c61e45d8 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -133,7 +133,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); address oldRelayer = managerToRelayer[msg.sender]; - delete currentRelayers[oldRelayer]; if (relayerToBeAdded != address(0)) { require(!currentRelayers[relayerToBeAdded], "relayer already exists"); @@ -143,6 +142,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { delete managerToRelayer[msg.sender]; } + delete currentRelayers[oldRelayer]; emit relayerUpdated(oldRelayer, relayerToBeAdded); } diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index b6883b97..e3b18a3c 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -34,6 +34,11 @@ contract RelayerHubTest is Deployer { emit relayerUpdated(payable(address(0)), newRelayer); newRelayerHub.updateRelayer(newRelayer); + // do updateRelayer() with the existing relayer + vm.prank(manager, manager); + vm.expectRevert(bytes("relayer already exists")); + newRelayerHub.updateRelayer(newRelayer); + // do illegal call vm.prank(newRelayer, newRelayer); vm.expectRevert(bytes("manager does not exist")); From 8ad0ad768023c0da404f01a944f283820aa5d01f Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 23 Jan 2023 06:46:29 +0000 Subject: [PATCH 63/90] emit events in initialisation as well --- contracts/RelayerHub.sol | 2 ++ test/RelayerHub.t.sol | 3 +++ 2 files changed, 5 insertions(+) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index c61e45d8..efc4982f 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -78,6 +78,8 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { relayManagersExistMap[addr] = true; managerToRelayer[addr] = addr; // for the current whitelisted relayers we are keeping manager and relayer address the same currentRelayers[addr] = true; + emit managerAdded(addr); + emit relayerUpdated(address(0), addr); } /*********************** Param update ********************************/ diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index e3b18a3c..097b5543 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -8,6 +8,7 @@ contract RelayerHubTest is Deployer { event paramChange(string key, bytes value); event relayerUpdated(address _from, address _to); event managerRemoved(address _manager); + event managerAdded(address _manager); uint256 public requiredDeposit; uint256 public dues; @@ -158,6 +159,8 @@ contract RelayerHubTest is Deployer { // now we call update() and the existing relayer/manager should be shown to be valid + vm.expectEmit(true, true, false, true); + emit relayerUpdated(payable(address(0)), newRelayerHub.WHITELIST_1()); newRelayerHub.whitelistInit(); bool isManagerTrue = newRelayerHub.isManager(existingRelayer1); assertTrue(isManagerTrue); From ba6aac5b80abcf10be53c947717293424156ff3e Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Thu, 26 Jan 2023 11:52:51 +0000 Subject: [PATCH 64/90] update the template file based on recent changes --- contracts/RelayerHub.template | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/contracts/RelayerHub.template b/contracts/RelayerHub.template index 06b7cafc..0e4143ed 100644 --- a/contracts/RelayerHub.template +++ b/contracts/RelayerHub.template @@ -13,7 +13,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { uint256 public constant INIT_REQUIRED_DEPOSIT = 1e20; uint256 public constant INIT_DUES = 1e17; - + {% if network == 'local' %} address public constant WHITELIST_1 = 0xA904540818AC9c47f2321F97F1069B9d8746c6DB; address public constant WHITELIST_2 = 0x316b2Fa7C8a2ab7E21110a4B3f58771C01A71344; @@ -90,6 +90,8 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { relayManagersExistMap[addr] = true; managerToRelayer[addr] = addr; // for the current whitelisted relayers we are keeping manager and relayer address the same currentRelayers[addr] = true; + emit managerAdded(addr); + emit relayerUpdated(address(0), addr); } /*********************** Param update ********************************/ @@ -100,7 +102,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { addManagerByGov(newManager); } else if (Memory.compareStrings(key, "removeManager")) { require(value.length == 20, "length of manager address mismatch"); - address payable managerAddress = payable(BytesToTypes.bytesToAddress(20, value)); + address managerAddress = BytesToTypes.bytesToAddress(20, value); removeManager(managerAddress); } else { require(false, "unknown param"); @@ -110,10 +112,10 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { function removeManagerByHimself() external { // here the manager removes himself - removeManager(payable(msg.sender)); + removeManager(msg.sender); } - function removeManager(address payable managerAddress) internal { + function removeManager(address managerAddress) internal { // check if the manager address already exists require(relayManagersExistMap[managerAddress], "manager doesn't exist"); @@ -145,7 +147,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); address oldRelayer = managerToRelayer[msg.sender]; - delete currentRelayers[oldRelayer]; if (relayerToBeAdded != address(0)) { require(!currentRelayers[relayerToBeAdded], "relayer already exists"); @@ -155,6 +156,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { delete managerToRelayer[msg.sender]; } + delete currentRelayers[oldRelayer]; emit relayerUpdated(oldRelayer, relayerToBeAdded); } From 06927b44c121ffe6a20e982c7c61097eb9c86d42 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Fri, 3 Feb 2023 16:47:45 +0000 Subject: [PATCH 65/90] public to internal + remove unused event --- contracts/RelayerHub.sol | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index efc4982f..bf1a845f 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -16,8 +16,8 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { address public constant WHITELIST_1 = 0xb005741528b86F5952469d80A8614591E3c5B632; address public constant WHITELIST_2 = 0x446AA6E0DC65690403dF3F127750da1322941F3e; - uint256 public requiredDeposit; // have to keep it to not break the storage layout - uint256 public dues; + uint256 internal requiredDeposit; // have to keep it to not break the storage layout + uint256 internal dues; mapping(address => relayer) relayers; // old map holding the relayers which are to be allowed safe exit mapping(address => bool) relayersExistMap; @@ -43,7 +43,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { _; } - event relayerRegister(address _relayer); event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); From 0785d1dbe5ef4cc20f9032f9b205b4e74756465f Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Thu, 9 Feb 2023 12:07:42 +0000 Subject: [PATCH 66/90] Test to ensure a contract can't be a relayer --- test/RelayerHub.t.sol | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index 097b5543..2e1922e3 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -227,6 +227,43 @@ contract RelayerHubTest is Deployer { } + function testContractRelayer() public { + RelayerHub newRelayerHub = helperGetNewRelayerHub(); + + bytes memory keyAddManager = "addManager"; + address manager = payable(addrSet[addrIdx++]); + address newRelayer = payable(addrSet[addrIdx++]); + bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); + require(valueManagerBytes.length == 20, "length of manager address mismatch in tests"); + updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); + +// vm.prank(manager, manager); + + + uint64 nonceManager = vm.getNonce(manager); +// vm.setNonce(manager, nonceManager++); + + address contractAddress = address(bytes20(keccak256(abi.encodePacked(manager, nonceManager)))); + + // add the above address as relayer address which currently doesn't have code + vm.prank(manager, manager); + newRelayerHub.updateRelayer(contractAddress); + + bytes memory bytecode = "0x60606040525b600080fd00a165627a7a7230582012c9bd00152fa1c480f6827f81515bb19c3e63bf7ed9ffbb5fda0265983ac7980029"; + +// vm.prank(manager, manager); +// (bool success, bytes memory returnData) = address(contractAddress).deploy(bytecode); + +// require(success, "Deployment failed"); + vm.etch(contractAddress, bytecode); + + assertEq(bytes32(bytecode), bytes32(address(contractAddress).code)); + + // here because the added relayer hasn't done the second step, therefore it shouldn't be added as a relayer + assertFalse(newRelayerHub.isRelayer(contractAddress)); + + } + // function testCannotRegister() public { // address newRelayer = addrSet[addrIdx++]; // vm.startPrank(newRelayer, newRelayer); From c9298afe73adac40a65f19a267765e79cdf08be0 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Fri, 10 Feb 2023 11:01:09 +0000 Subject: [PATCH 67/90] 2 step relayer registration. todo: test update --- contracts/RelayerHub.sol | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index bf1a845f..c41707d8 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -30,6 +30,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { mapping(address => bool) relayManagersExistMap; mapping(address => address) managerToRelayer; mapping(address => bool) currentRelayers; + mapping(address => bool) provisionalRelayers; bool public whitelistInitDone; @@ -43,12 +44,18 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { _; } + modifier onlyProvisionalRelayer() { + require(provisionalRelayers[msg.sender], "relayer is not a provisional relayer"); + _; + } + event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); event managerRemoved(address _removedManager); event managerAdded(address _addedManager); event relayerUpdated(address _from, address _to); + event relayerAddedProvisionally(address _relayer); function init() external onlyNotInit { requiredDeposit = INIT_REQUIRED_DEPOSIT; @@ -130,21 +137,43 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // updateRelayer() can be used to add relayer for the first time, update it in future and remove it // in case of removal we can simply update it to a non-existing account - function updateRelayer(address relayerToBeAdded) public onlyManager { + function updateRelayer(address relayerToBeAdded) public onlyManager {// todo make it 2 step if relayer isn't address(0) require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); address oldRelayer = managerToRelayer[msg.sender]; if (relayerToBeAdded != address(0)) { require(!currentRelayers[relayerToBeAdded], "relayer already exists"); - currentRelayers[relayerToBeAdded] = true; - managerToRelayer[msg.sender] = relayerToBeAdded; + // currentRelayers[relayerToBeAdded] = true; + + provisionalRelayers[relayerToBeAdded] = true; + // managerToRelayer[msg.sender] = relayerToBeAdded; } else { delete managerToRelayer[msg.sender]; + + delete currentRelayers[oldRelayer]; + emit relayerUpdated(oldRelayer, relayerToBeAdded); } + // delete currentRelayers[oldRelayer]; + // emit relayerUpdated(oldRelayer, relayerToBeAdded); + + emit relayerAddedProvisionally(relayerToBeAdded); + } + + // acceptBeingRelayer needs to be called by the relayer after being added provisionally. + // This 2 step process of relayer updating is required to avoid having a contract as a relayer. + function acceptBeingRelayer(address manager) external onlyProvisionalRelayer { + address oldRelayer = managerToRelayer[manager]; + + currentRelayers[msg.sender] = true; + managerToRelayer[manager] = msg.sender; + + delete (provisionalRelayers[msg.sender]); + delete currentRelayers[oldRelayer]; - emit relayerUpdated(oldRelayer, relayerToBeAdded); + emit relayerUpdated(oldRelayer, msg.sender); + } function isRelayer(address relayerAddress) external override view returns (bool){ From 15380dcb71ff8cce389df4286841cd0bb6df3c98 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 13 Feb 2023 12:46:47 +0000 Subject: [PATCH 68/90] Fix testAddManager --- contracts/RelayerHub.sol | 1 + lib/interface/IRelayerHub.sol | 2 ++ test/RelayerHub.t.sol | 18 +++++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index c41707d8..223e9243 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -153,6 +153,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { delete currentRelayers[oldRelayer]; emit relayerUpdated(oldRelayer, relayerToBeAdded); + return; } // delete currentRelayers[oldRelayer]; diff --git a/lib/interface/IRelayerHub.sol b/lib/interface/IRelayerHub.sol index 7ef268cb..2c5fbe84 100644 --- a/lib/interface/IRelayerHub.sol +++ b/lib/interface/IRelayerHub.sol @@ -7,6 +7,7 @@ interface RelayerHub { event relayerRegister(address _relayer); event relayerUnRegister(address _relayer); event relayerUpdated(address _from, address _to); + event relayerAddedProvisionally(address _relayer); function BIND_CHANNELID() external view returns (uint8); function CODE_OK() external view returns (uint32); @@ -45,5 +46,6 @@ interface RelayerHub { function updateRelayer(address relayerToBeAdded) external; function whitelistInit() external; function whitelistInitDone() external view returns (bool); + function acceptBeingRelayer(address manager) external; } diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index 2e1922e3..7999626c 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -9,6 +9,7 @@ contract RelayerHubTest is Deployer { event relayerUpdated(address _from, address _to); event managerRemoved(address _manager); event managerAdded(address _manager); + event relayerAddedProvisionally(address _relayer); uint256 public requiredDeposit; uint256 public dues; @@ -32,8 +33,13 @@ contract RelayerHubTest is Deployer { // check if manager is there and can add a relayer vm.prank(manager, manager); vm.expectEmit(true, true, false, true); - emit relayerUpdated(payable(address(0)), newRelayer); + emit relayerAddedProvisionally(newRelayer); newRelayerHub.updateRelayer(newRelayer); + assertFalse(newRelayerHub.isRelayer(newRelayer)); + + vm.prank(newRelayer, newRelayer); + emit relayerUpdated(payable(address(0)), newRelayer); + newRelayerHub.acceptBeingRelayer(manager); // do updateRelayer() with the existing relayer vm.prank(manager, manager); @@ -57,8 +63,14 @@ contract RelayerHubTest is Deployer { address newRelayer2 = payable(addrSet[addrIdx++]); vm.prank(manager, manager); vm.expectEmit(true, true, false, true); - emit relayerUpdated(newRelayer, newRelayer2); +// emit relayerUpdated(newRelayer, newRelayer2); + emit relayerAddedProvisionally(newRelayer2); newRelayerHub.updateRelayer(newRelayer2); + assertFalse(newRelayerHub.isRelayer(newRelayer2)); + + vm.prank(newRelayer2, newRelayer2); + emit relayerUpdated(newRelayer, newRelayer2); + newRelayerHub.acceptBeingRelayer(manager); // set relayer to 0 vm.prank(manager, manager); @@ -76,7 +88,7 @@ contract RelayerHubTest is Deployer { updateParamByGovHub(keyRemoveManager, valueManagerBytes, address(newRelayerHub)); // check if relayer got removed - bool isRelayerFalse = newRelayerHub.isRelayer(newRelayer); + bool isRelayerFalse = newRelayerHub.isRelayer(newRelayer2); assertFalse(isRelayerFalse); // check if manager got removed From e4afcdb8dedafdd6a29d1594c4793160c2e0ae8d Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 13 Feb 2023 17:06:38 +0000 Subject: [PATCH 69/90] Fix the rest of the tests --- test/RelayerHub.t.sol | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index 7999626c..40d6e92b 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -38,6 +38,7 @@ contract RelayerHubTest is Deployer { assertFalse(newRelayerHub.isRelayer(newRelayer)); vm.prank(newRelayer, newRelayer); + vm.expectEmit(true, true, false, true); emit relayerUpdated(payable(address(0)), newRelayer); newRelayerHub.acceptBeingRelayer(manager); @@ -113,8 +114,14 @@ contract RelayerHubTest is Deployer { vm.prank(manager, manager); vm.expectEmit(true, true, false, true); - emit relayerUpdated(payable(address(0)), newRelayer); + emit relayerAddedProvisionally(newRelayer); newRelayerHub.updateRelayer(newRelayer); + assertFalse(newRelayerHub.isRelayer(newRelayer)); + + vm.prank(newRelayer, newRelayer); + vm.expectEmit(true, true, false, true); + emit relayerUpdated(payable(address(0)), newRelayer); + newRelayerHub.acceptBeingRelayer(manager); // set relayer to 0 vm.prank(manager, manager); @@ -130,8 +137,15 @@ contract RelayerHubTest is Deployer { address newRelayer2 = payable(addrSet[addrIdx++]); vm.prank(manager2, manager2); vm.expectEmit(true, true, false, true); - emit relayerUpdated(payable(address(0)), newRelayer2); + emit relayerAddedProvisionally(newRelayer2); newRelayerHub.updateRelayer(newRelayer2); + assertFalse(newRelayerHub.isRelayer(newRelayer2)); + + vm.prank(newRelayer2, newRelayer2); + vm.expectEmit(true, true, false, true); + emit relayerUpdated(payable(address(0)), newRelayer2); + newRelayerHub.acceptBeingRelayer(manager2); + // set relayer to 0 vm.prank(manager2, manager2); vm.expectEmit(true, true, false, true); @@ -211,18 +225,29 @@ contract RelayerHubTest is Deployer { vm.prank(manager, manager); vm.expectEmit(true, true, false, true); - emit relayerUpdated(payable(address(0)), newRelayer); + emit relayerAddedProvisionally(newRelayer); newRelayerHub.updateRelayer(newRelayer); + assertFalse(newRelayerHub.isRelayer(newRelayer)); + + vm.prank(newRelayer, newRelayer); + emit relayerUpdated(payable(address(0)), newRelayer); + newRelayerHub.acceptBeingRelayer(manager); address manager2 = payable(addrSet[addrIdx++]); bytes memory valueManagerBytes2 = abi.encodePacked(bytes20(uint160(manager2))); require(valueManagerBytes2.length == 20, "length of manager2 address mismatch in tests"); updateParamByGovHub(keyAddManager, valueManagerBytes2, address(newRelayerHub)); address newRelayer2 = payable(addrSet[addrIdx++]); + vm.prank(manager2, manager2); vm.expectEmit(true, true, false, true); - emit relayerUpdated(payable(address(0)), newRelayer2); + emit relayerAddedProvisionally(newRelayer2); newRelayerHub.updateRelayer(newRelayer2); + assertFalse(newRelayerHub.isRelayer(newRelayer2)); + + vm.prank(newRelayer2, newRelayer2); + emit relayerUpdated(payable(address(0)), newRelayer2); + newRelayerHub.acceptBeingRelayer(manager2); // set relayer to 0 for first manager vm.prank(manager, manager); From 0f4ff88aad9bfb24ebee3672717cd49e85942162 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 13 Feb 2023 17:10:55 +0000 Subject: [PATCH 70/90] Remove unused comments --- contracts/RelayerHub.sol | 9 +-------- test/RelayerHub.t.sol | 10 ---------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 223e9243..d5e896d2 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -137,28 +137,21 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // updateRelayer() can be used to add relayer for the first time, update it in future and remove it // in case of removal we can simply update it to a non-existing account - function updateRelayer(address relayerToBeAdded) public onlyManager {// todo make it 2 step if relayer isn't address(0) + function updateRelayer(address relayerToBeAdded) public onlyManager { require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); address oldRelayer = managerToRelayer[msg.sender]; if (relayerToBeAdded != address(0)) { require(!currentRelayers[relayerToBeAdded], "relayer already exists"); - // currentRelayers[relayerToBeAdded] = true; - provisionalRelayers[relayerToBeAdded] = true; - // managerToRelayer[msg.sender] = relayerToBeAdded; } else { delete managerToRelayer[msg.sender]; - delete currentRelayers[oldRelayer]; emit relayerUpdated(oldRelayer, relayerToBeAdded); return; } - // delete currentRelayers[oldRelayer]; - // emit relayerUpdated(oldRelayer, relayerToBeAdded); - emit relayerAddedProvisionally(relayerToBeAdded); } diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index 40d6e92b..28ec5946 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -64,7 +64,6 @@ contract RelayerHubTest is Deployer { address newRelayer2 = payable(addrSet[addrIdx++]); vm.prank(manager, manager); vm.expectEmit(true, true, false, true); -// emit relayerUpdated(newRelayer, newRelayer2); emit relayerAddedProvisionally(newRelayer2); newRelayerHub.updateRelayer(newRelayer2); assertFalse(newRelayerHub.isRelayer(newRelayer2)); @@ -269,16 +268,11 @@ contract RelayerHubTest is Deployer { bytes memory keyAddManager = "addManager"; address manager = payable(addrSet[addrIdx++]); - address newRelayer = payable(addrSet[addrIdx++]); bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); require(valueManagerBytes.length == 20, "length of manager address mismatch in tests"); updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); -// vm.prank(manager, manager); - - uint64 nonceManager = vm.getNonce(manager); -// vm.setNonce(manager, nonceManager++); address contractAddress = address(bytes20(keccak256(abi.encodePacked(manager, nonceManager)))); @@ -288,10 +282,6 @@ contract RelayerHubTest is Deployer { bytes memory bytecode = "0x60606040525b600080fd00a165627a7a7230582012c9bd00152fa1c480f6827f81515bb19c3e63bf7ed9ffbb5fda0265983ac7980029"; -// vm.prank(manager, manager); -// (bool success, bytes memory returnData) = address(contractAddress).deploy(bytecode); - -// require(success, "Deployment failed"); vm.etch(contractAddress, bytecode); assertEq(bytes32(bytecode), bytes32(address(contractAddress).code)); From e1068898c5c6fc414082cc6805e6fa8c2cd5742a Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 14 Feb 2023 10:19:34 +0000 Subject: [PATCH 71/90] check for code and proxy relayer + test --- contracts/RelayerHub.sol | 8 ++++++++ test/RelayerHub.t.sol | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index d5e896d2..7469d4d8 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -158,6 +158,14 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // acceptBeingRelayer needs to be called by the relayer after being added provisionally. // This 2 step process of relayer updating is required to avoid having a contract as a relayer. function acceptBeingRelayer(address manager) external onlyProvisionalRelayer { + + // ensure code is zero for msg.sender and it is not a proxy + uint size; + address sender = msg.sender; + assembly { size := extcodesize(sender) } + require(size == 0, "provisional relayer is a contract"); + require(tx.origin == msg.sender, "provisional relayer is a proxy"); + address oldRelayer = managerToRelayer[manager]; currentRelayers[msg.sender] = true; diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index 28ec5946..e7253c3b 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -289,6 +289,37 @@ contract RelayerHubTest is Deployer { // here because the added relayer hasn't done the second step, therefore it shouldn't be added as a relayer assertFalse(newRelayerHub.isRelayer(contractAddress)); + // check if a contract relayer fails + vm.prank(contractAddress, contractAddress); + vm.expectRevert(bytes("provisional relayer is a contract")); + newRelayerHub.acceptBeingRelayer(manager); + } + + function testProxyContractRelayer() public { + RelayerHub newRelayerHub = helperGetNewRelayerHub(); + + bytes memory keyAddManager = "addManager"; + address manager = payable(addrSet[addrIdx++]); + bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); + require(valueManagerBytes.length == 20, "length of manager address mismatch in tests"); + updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); + + uint64 nonceManager = vm.getNonce(manager); + + address contractAddress = address(bytes20(keccak256(abi.encodePacked(manager, nonceManager)))); + + // add the above address as relayer address which currently doesn't have code + vm.prank(manager, manager); + newRelayerHub.updateRelayer(contractAddress); + + // here because the added relayer hasn't done the second step, therefore it shouldn't be added as a relayer + assertFalse(newRelayerHub.isRelayer(contractAddress)); + + // check if a proxy relayer fails + vm.prank(contractAddress, manager); + vm.expectRevert(bytes("provisional relayer is a proxy")); + newRelayerHub.acceptBeingRelayer(manager); + } // function testCannotRegister() public { From d2f96430a7974efe49a96efad6295261f8252620 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 15 Feb 2023 13:50:01 +0000 Subject: [PATCH 72/90] edge case where manager gets removed before accept --- contracts/RelayerHub.sol | 9 +++++++++ lib/interface/IRelayerHub.sol | 4 +++- test/RelayerHub.t.sol | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 7469d4d8..aeca8371 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -31,6 +31,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { mapping(address => address) managerToRelayer; mapping(address => bool) currentRelayers; mapping(address => bool) provisionalRelayers; + mapping(address => address) managerToProvisionalRelayer; bool public whitelistInitDone; @@ -118,6 +119,9 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { delete (relayManagersExistMap[managerAddress]); delete (managerToRelayer[managerAddress]); + delete (provisionalRelayers[managerToProvisionalRelayer[managerAddress]]); + delete (managerToProvisionalRelayer[managerAddress]); + // emit success event emit managerRemoved(managerAddress); if (relayerAddress != address(0)) { @@ -145,6 +149,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { if (relayerToBeAdded != address(0)) { require(!currentRelayers[relayerToBeAdded], "relayer already exists"); provisionalRelayers[relayerToBeAdded] = true; + managerToProvisionalRelayer[msg.sender] = relayerToBeAdded; } else { delete managerToRelayer[msg.sender]; delete currentRelayers[oldRelayer]; @@ -182,6 +187,10 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { return currentRelayers[relayerAddress]; } + function isProvisionalRelayer(address relayerAddress) external view returns (bool){ + return provisionalRelayers[relayerAddress]; + } + function isManager(address relayerAddress) external view returns (bool){ return relayManagersExistMap[relayerAddress]; } diff --git a/lib/interface/IRelayerHub.sol b/lib/interface/IRelayerHub.sol index 2c5fbe84..66bb2706 100644 --- a/lib/interface/IRelayerHub.sol +++ b/lib/interface/IRelayerHub.sol @@ -47,5 +47,7 @@ interface RelayerHub { function whitelistInit() external; function whitelistInitDone() external view returns (bool); function acceptBeingRelayer(address manager) external; -} + function isProvisionalRelayer(address relayerAddress) external view returns (bool); + + } diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index e7253c3b..1a032699 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -322,6 +322,41 @@ contract RelayerHubTest is Deployer { } + // testManagerDeleteProvisionalRelayerRegistration checks the following scenario: + // If a relayer is added provisionally and the manager gets deleted by governance BEFORE relayer registers itself + // then it shouldn't be able to register. + function testManagerDeleteProvisionalRelayerRegistration() public { + RelayerHub newRelayerHub = helperGetNewRelayerHub(); + + bytes memory keyAddManager = "addManager"; + address manager = payable(addrSet[addrIdx++]); + bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); + require(valueManagerBytes.length == 20, "length of manager address mismatch in tests"); + updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); + + address newRelayer = payable(addrSet[addrIdx++]); + + // add the above address as relayer address which currently doesn't have code + vm.prank(manager, manager); + newRelayerHub.updateRelayer(newRelayer); + + // here because the added relayer hasn't done the second step, therefore it shouldn't be added as a relayer + assertFalse(newRelayerHub.isRelayer(newRelayer)); + + // now delete manager before the relayer accepts being a relayer + bytes memory keyRemoveManager = "removeManager"; + updateParamByGovHub(keyRemoveManager, valueManagerBytes, address(newRelayerHub)); + + assertFalse(newRelayerHub.isProvisionalRelayer(newRelayer)); + + // now the relayer tries to register itself which should fail as its manager is already removed + vm.prank(newRelayer, newRelayer); + vm.expectRevert(bytes("relayer is not a provisional relayer")); + newRelayerHub.acceptBeingRelayer(manager); + assertFalse(newRelayerHub.isRelayer(newRelayer)); + + } + // function testCannotRegister() public { // address newRelayer = addrSet[addrIdx++]; // vm.startPrank(newRelayer, newRelayer); From 979cd80ab60695616bd545088e64767e1d140845 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Thu, 16 Feb 2023 10:37:39 +0000 Subject: [PATCH 73/90] name change to be consistent --- contracts/RelayerHub.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index aeca8371..b0c8393f 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -19,7 +19,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { uint256 internal requiredDeposit; // have to keep it to not break the storage layout uint256 internal dues; - mapping(address => relayer) relayers; // old map holding the relayers which are to be allowed safe exit + mapping(address => relayer) deprecatedRelayers; // old map holding the relayers which are to be allowed safe exit mapping(address => bool) relayersExistMap; struct relayer { @@ -65,12 +65,12 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } function unregister() external exist onlyInit { - relayer memory r = relayers[msg.sender]; + relayer memory r = deprecatedRelayers[msg.sender]; msg.sender.transfer(r.deposit.sub(r.dues)); address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); systemPayable.transfer(r.dues); delete relayersExistMap[msg.sender]; - delete relayers[msg.sender]; + delete deprecatedRelayers[msg.sender]; emit relayerUnRegister(msg.sender); } From e094a54bc232ff66bfda592adefaa38e9f0a2233 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 20 Feb 2023 12:05:50 +0000 Subject: [PATCH 74/90] delete provisional relayer when relayer is deleted --- contracts/RelayerHub.sol | 9 ++++----- test/RelayerHub.t.sol | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index b0c8393f..a691560c 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -145,6 +145,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); address oldRelayer = managerToRelayer[msg.sender]; + address oldProvisionalRelayer = managerToProvisionalRelayer[msg.sender]; if (relayerToBeAdded != address(0)) { require(!currentRelayers[relayerToBeAdded], "relayer already exists"); @@ -153,6 +154,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } else { delete managerToRelayer[msg.sender]; delete currentRelayers[oldRelayer]; + delete provisionalRelayers[oldProvisionalRelayer]; emit relayerUpdated(oldRelayer, relayerToBeAdded); return; } @@ -164,11 +166,8 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // This 2 step process of relayer updating is required to avoid having a contract as a relayer. function acceptBeingRelayer(address manager) external onlyProvisionalRelayer { - // ensure code is zero for msg.sender and it is not a proxy - uint size; - address sender = msg.sender; - assembly { size := extcodesize(sender) } - require(size == 0, "provisional relayer is a contract"); + // ensure msg.sender is not contract and it is not a proxy + require(!isContract(msg.sender), "provisional relayer is a contract"); require(tx.origin == msg.sender, "provisional relayer is a proxy"); address oldRelayer = managerToRelayer[manager]; diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index 1a032699..9a30cf15 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -357,6 +357,30 @@ contract RelayerHubTest is Deployer { } + function testDeleteProvisionalRelayerWhileRemovingRelayer() public { + // Say a manager is there and adds its relayer provisionally and then decides to set it to address(0) + // In this case the relayer is added as a provisional only and not full relayer + // So the provisional relayer should also be deleted, especially if the relayer is yet to add itself as a full relayer + RelayerHub newRelayerHub = helperGetNewRelayerHub(); + + bytes memory keyAddManager = "addManager"; + address manager = payable(addrSet[addrIdx++]); + bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); + require(valueManagerBytes.length == 20, "length of manager address mismatch in tests"); + updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); + + address newRelayer = payable(addrSet[addrIdx++]); + + vm.prank(manager, manager); + newRelayerHub.updateRelayer(newRelayer); + assertTrue(newRelayerHub.isProvisionalRelayer(newRelayer)); + + // Now remove the relayer and ensure that it is deleted being a provisional relayer as well + vm.prank(manager, manager); + newRelayerHub.updateRelayer(address(0)); + assertFalse(newRelayerHub.isProvisionalRelayer(newRelayer)); + } + // function testCannotRegister() public { // address newRelayer = addrSet[addrIdx++]; // vm.startPrank(newRelayer, newRelayer); From 1ecf7d0919857fe9bc67cf24f1bd3afc6599c1eb Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 20 Feb 2023 12:38:23 +0000 Subject: [PATCH 75/90] Check for correct manager --- contracts/RelayerHub.sol | 1 + test/RelayerHub.t.sol | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index a691560c..64827a9c 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -169,6 +169,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // ensure msg.sender is not contract and it is not a proxy require(!isContract(msg.sender), "provisional relayer is a contract"); require(tx.origin == msg.sender, "provisional relayer is a proxy"); + require(managerToProvisionalRelayer[manager] == msg.sender, "provisional is not set for this manager"); address oldRelayer = managerToRelayer[manager]; diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index 9a30cf15..b8594571 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -381,6 +381,28 @@ contract RelayerHubTest is Deployer { assertFalse(newRelayerHub.isProvisionalRelayer(newRelayer)); } + function testCorrectManagerForAcceptRelayer() public { + RelayerHub newRelayerHub = helperGetNewRelayerHub(); + + bytes memory keyAddManager = "addManager"; + address manager = payable(addrSet[addrIdx++]); + bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); + require(valueManagerBytes.length == 20, "length of manager address mismatch in tests"); + updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); + + address newRelayer = payable(addrSet[addrIdx++]); + + vm.prank(manager, manager); + newRelayerHub.updateRelayer(newRelayer); + assertTrue(newRelayerHub.isProvisionalRelayer(newRelayer)); + + address randomManager = payable(addrSet[addrIdx++]); + vm.prank(newRelayer, newRelayer); + vm.expectRevert("provisional is not set for this manager"); + newRelayerHub.acceptBeingRelayer(randomManager); + + } + // function testCannotRegister() public { // address newRelayer = addrSet[addrIdx++]; // vm.startPrank(newRelayer, newRelayer); From f79183d087312525693aa5e432684efeb163b1d9 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 20 Feb 2023 12:43:19 +0000 Subject: [PATCH 76/90] update comment --- contracts/RelayerHub.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 64827a9c..279747c1 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -140,7 +140,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } // updateRelayer() can be used to add relayer for the first time, update it in future and remove it - // in case of removal we can simply update it to a non-existing account + // in case of removal, we set relayerToBeAdded to be address(0) function updateRelayer(address relayerToBeAdded) public onlyManager { require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); From eb06f3845817c1185da21f3873ffd3f866b24125 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 20 Feb 2023 15:50:03 +0000 Subject: [PATCH 77/90] dlt managerToProvisionalRelayer when dltng relayer --- contracts/RelayerHub.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 279747c1..2146214f 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -155,6 +155,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { delete managerToRelayer[msg.sender]; delete currentRelayers[oldRelayer]; delete provisionalRelayers[oldProvisionalRelayer]; + delete managerToProvisionalRelayer[msg.sender]; emit relayerUpdated(oldRelayer, relayerToBeAdded); return; } From e326cd0106f13d9795a6426105ac97e3c815fd22 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 22 Feb 2023 11:28:06 +0000 Subject: [PATCH 78/90] address pr comments --- contracts/RelayerHub.sol | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 2146214f..b2738004 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -141,17 +141,16 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { // updateRelayer() can be used to add relayer for the first time, update it in future and remove it // in case of removal, we set relayerToBeAdded to be address(0) - function updateRelayer(address relayerToBeAdded) public onlyManager { + function updateRelayer(address relayerToBeAdded) external onlyManager { require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); - address oldRelayer = managerToRelayer[msg.sender]; - address oldProvisionalRelayer = managerToProvisionalRelayer[msg.sender]; - if (relayerToBeAdded != address(0)) { require(!currentRelayers[relayerToBeAdded], "relayer already exists"); provisionalRelayers[relayerToBeAdded] = true; managerToProvisionalRelayer[msg.sender] = relayerToBeAdded; } else { + address oldRelayer = managerToRelayer[msg.sender]; + address oldProvisionalRelayer = managerToProvisionalRelayer[msg.sender]; delete managerToRelayer[msg.sender]; delete currentRelayers[oldRelayer]; delete provisionalRelayers[oldProvisionalRelayer]; @@ -177,8 +176,8 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { currentRelayers[msg.sender] = true; managerToRelayer[manager] = msg.sender; - delete (provisionalRelayers[msg.sender]); - + delete provisionalRelayers[msg.sender]; + delete managerToProvisionalRelayer[manager]; delete currentRelayers[oldRelayer]; emit relayerUpdated(oldRelayer, msg.sender); @@ -192,7 +191,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { return provisionalRelayers[relayerAddress]; } - function isManager(address relayerAddress) external view returns (bool){ - return relayManagersExistMap[relayerAddress]; + function isManager(address managerAddress) external view returns (bool){ + return relayManagersExistMap[managerAddress]; } } From 1099e1b8b78ff6e14d9416b906698ccdfc5fc122 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Mon, 27 Feb 2023 10:25:37 +0000 Subject: [PATCH 79/90] update template --- contracts/RelayerHub.template | 71 +++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/contracts/RelayerHub.template b/contracts/RelayerHub.template index 0e4143ed..e2a8c5bc 100644 --- a/contracts/RelayerHub.template +++ b/contracts/RelayerHub.template @@ -13,7 +13,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { uint256 public constant INIT_REQUIRED_DEPOSIT = 1e20; uint256 public constant INIT_DUES = 1e17; - + {% if network == 'local' %} address public constant WHITELIST_1 = 0xA904540818AC9c47f2321F97F1069B9d8746c6DB; address public constant WHITELIST_2 = 0x316b2Fa7C8a2ab7E21110a4B3f58771C01A71344; @@ -28,10 +28,10 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { address public constant WHITELIST_2 = 0x446AA6E0DC65690403dF3F127750da1322941F3e; {% endif %} - uint256 public requiredDeposit; // have to keep it to not break the storage layout - uint256 public dues; + uint256 internal requiredDeposit; // have to keep it to not break the storage layout + uint256 internal dues; - mapping(address => relayer) relayers; // old map holding the relayers which are to be allowed safe exit + mapping(address => relayer) deprecatedRelayers; // old map holding the relayers which are to be allowed safe exit mapping(address => bool) relayersExistMap; struct relayer { @@ -42,6 +42,8 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { mapping(address => bool) relayManagersExistMap; mapping(address => address) managerToRelayer; mapping(address => bool) currentRelayers; + mapping(address => bool) provisionalRelayers; + mapping(address => address) managerToProvisionalRelayer; bool public whitelistInitDone; @@ -55,13 +57,18 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { _; } - event relayerRegister(address _relayer); + modifier onlyProvisionalRelayer() { + require(provisionalRelayers[msg.sender], "relayer is not a provisional relayer"); + _; + } + event relayerUnRegister(address _relayer); event paramChange(string key, bytes value); event managerRemoved(address _removedManager); event managerAdded(address _addedManager); event relayerUpdated(address _from, address _to); + event relayerAddedProvisionally(address _relayer); function init() external onlyNotInit { requiredDeposit = INIT_REQUIRED_DEPOSIT; @@ -70,12 +77,12 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } function unregister() external exist onlyInit { - relayer memory r = relayers[msg.sender]; + relayer memory r = deprecatedRelayers[msg.sender]; msg.sender.transfer(r.deposit.sub(r.dues)); address payable systemPayable = address(uint160(SYSTEM_REWARD_ADDR)); systemPayable.transfer(r.dues); delete relayersExistMap[msg.sender]; - delete relayers[msg.sender]; + delete deprecatedRelayers[msg.sender]; emit relayerUnRegister(msg.sender); } @@ -124,6 +131,9 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { delete (relayManagersExistMap[managerAddress]); delete (managerToRelayer[managerAddress]); + delete (provisionalRelayers[managerToProvisionalRelayer[managerAddress]]); + delete (managerToProvisionalRelayer[managerAddress]); + // emit success event emit managerRemoved(managerAddress); if (relayerAddress != address(0)) { @@ -142,29 +152,58 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { } // updateRelayer() can be used to add relayer for the first time, update it in future and remove it - // in case of removal we can simply update it to a non-existing account - function updateRelayer(address relayerToBeAdded) public onlyManager { + // in case of removal, we set relayerToBeAdded to be address(0) + function updateRelayer(address relayerToBeAdded) external onlyManager { require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer"); - address oldRelayer = managerToRelayer[msg.sender]; - if (relayerToBeAdded != address(0)) { require(!currentRelayers[relayerToBeAdded], "relayer already exists"); - currentRelayers[relayerToBeAdded] = true; - managerToRelayer[msg.sender] = relayerToBeAdded; + provisionalRelayers[relayerToBeAdded] = true; + managerToProvisionalRelayer[msg.sender] = relayerToBeAdded; } else { + address oldRelayer = managerToRelayer[msg.sender]; + address oldProvisionalRelayer = managerToProvisionalRelayer[msg.sender]; delete managerToRelayer[msg.sender]; + delete currentRelayers[oldRelayer]; + delete provisionalRelayers[oldProvisionalRelayer]; + delete managerToProvisionalRelayer[msg.sender]; + emit relayerUpdated(oldRelayer, relayerToBeAdded); + return; } + emit relayerAddedProvisionally(relayerToBeAdded); + } + + // acceptBeingRelayer needs to be called by the relayer after being added provisionally. + // This 2 step process of relayer updating is required to avoid having a contract as a relayer. + function acceptBeingRelayer(address manager) external onlyProvisionalRelayer { + + // ensure msg.sender is not contract and it is not a proxy + require(!isContract(msg.sender), "provisional relayer is a contract"); + require(tx.origin == msg.sender, "provisional relayer is a proxy"); + require(managerToProvisionalRelayer[manager] == msg.sender, "provisional is not set for this manager"); + + address oldRelayer = managerToRelayer[manager]; + + currentRelayers[msg.sender] = true; + managerToRelayer[manager] = msg.sender; + + delete provisionalRelayers[msg.sender]; + delete managerToProvisionalRelayer[manager]; delete currentRelayers[oldRelayer]; - emit relayerUpdated(oldRelayer, relayerToBeAdded); + emit relayerUpdated(oldRelayer, msg.sender); + } function isRelayer(address relayerAddress) external override view returns (bool){ return currentRelayers[relayerAddress]; } - function isManager(address relayerAddress) external view returns (bool){ - return relayManagersExistMap[relayerAddress]; + function isProvisionalRelayer(address relayerAddress) external view returns (bool){ + return provisionalRelayers[relayerAddress]; + } + + function isManager(address managerAddress) external view returns (bool){ + return relayManagersExistMap[managerAddress]; } } From f01246139c642970c7770f38583df4a4471f7211 Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Wed, 1 Mar 2023 09:55:11 +0100 Subject: [PATCH 80/90] remove check for contracts on relayer manager --- contracts/RelayerHub.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index b2738004..40dea886 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -132,7 +132,6 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { function addManagerByGov(address managerToBeAdded) internal { require(!relayManagersExistMap[managerToBeAdded], "manager already exists"); - require(!isContract(managerToBeAdded), "contract is not allowed to be a manager"); relayManagersExistMap[managerToBeAdded] = true; From ac8698d2ba3070c350460395cc8eaf782f7fb2bf Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Wed, 1 Mar 2023 10:36:38 +0000 Subject: [PATCH 81/90] remove unused onlyWhitelabelRelayer --- contracts/CrossChain.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/CrossChain.sol b/contracts/CrossChain.sol index 6f259cac..777e0758 100644 --- a/contracts/CrossChain.sol +++ b/contracts/CrossChain.sol @@ -276,7 +276,6 @@ contract CrossChain is System, ICrossChain, IParamSubscriber{ function handlePackage(bytes calldata payload, bytes calldata proof, uint64 height, uint64 packageSequence, uint8 channelId) onlyInit onlyRelayer - onlyWhitelabelRelayer sequenceInOrder(packageSequence, channelId) blockSynced(height) channelSupported(channelId) From 0acc05897852b1cc0223736664b335771b4209ab Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Wed, 1 Mar 2023 12:55:45 +0100 Subject: [PATCH 82/90] relayer: update template --- contracts/RelayerHub.sol | 2 +- contracts/RelayerHub.template | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/contracts/RelayerHub.sol b/contracts/RelayerHub.sol index 40dea886..d5b6176e 100644 --- a/contracts/RelayerHub.sol +++ b/contracts/RelayerHub.sol @@ -132,7 +132,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { function addManagerByGov(address managerToBeAdded) internal { require(!relayManagersExistMap[managerToBeAdded], "manager already exists"); - + relayManagersExistMap[managerToBeAdded] = true; emit managerAdded(managerToBeAdded); diff --git a/contracts/RelayerHub.template b/contracts/RelayerHub.template index e2a8c5bc..9fbfcc7f 100644 --- a/contracts/RelayerHub.template +++ b/contracts/RelayerHub.template @@ -144,8 +144,7 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber { function addManagerByGov(address managerToBeAdded) internal { require(!relayManagersExistMap[managerToBeAdded], "manager already exists"); - require(!isContract(managerToBeAdded), "contract is not allowed to be a manager"); - + relayManagersExistMap[managerToBeAdded] = true; emit managerAdded(managerToBeAdded); From df9bd2c146e063e330f46c825a1a2425f405c96c Mon Sep 17 00:00:00 2001 From: Mister-EA Date: Mon, 27 Feb 2023 09:59:50 +0100 Subject: [PATCH 83/90] extract helper function addNewManager in tests --- test/RelayerHub.t.sol | 106 +++++++++--------------------------------- 1 file changed, 22 insertions(+), 84 deletions(-) diff --git a/test/RelayerHub.t.sol b/test/RelayerHub.t.sol index b8594571..b6dddfa9 100644 --- a/test/RelayerHub.t.sol +++ b/test/RelayerHub.t.sol @@ -21,14 +21,8 @@ contract RelayerHubTest is Deployer { function testAddManager() public { RelayerHub newRelayerHub = helperGetNewRelayerHub(); - - bytes memory keyAddManager = "addManager"; - address manager = payable(addrSet[addrIdx++]); + address manager = addNewManager(newRelayerHub); address newRelayer = payable(addrSet[addrIdx++]); - bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); - require(valueManagerBytes.length == 20, "length of manager address mismatch in tests"); - - updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); // check if manager is there and can add a relayer vm.prank(manager, manager); @@ -85,6 +79,7 @@ contract RelayerHubTest is Deployer { bytes memory keyRemoveManager = "removeManager"; vm.expectEmit(true, true, false, true); emit managerRemoved(manager); + bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); updateParamByGovHub(keyRemoveManager, valueManagerBytes, address(newRelayerHub)); // check if relayer got removed @@ -96,6 +91,7 @@ contract RelayerHubTest is Deployer { assertFalse(isManagerFalse); // check if the manager can remove himself + bytes memory keyAddManager = "addManager"; updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); vm.prank(manager, manager); newRelayerHub.removeManagerByHimself(); @@ -103,13 +99,8 @@ contract RelayerHubTest is Deployer { function testRelayerAddingRemoving() public { RelayerHub newRelayerHub = helperGetNewRelayerHub(); - - bytes memory keyAddManager = "addManager"; - address manager = payable(addrSet[addrIdx++]); + address manager = addNewManager(newRelayerHub); address newRelayer = payable(addrSet[addrIdx++]); - bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); - require(valueManagerBytes.length == 20, "length of manager address mismatch in tests"); - updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); vm.prank(manager, manager); vm.expectEmit(true, true, false, true); @@ -129,10 +120,7 @@ contract RelayerHubTest is Deployer { newRelayerHub.updateRelayer(payable(address(0))); // get a new manager, have its relayer registered and then try to remove the relayer for this manager - address manager2 = payable(addrSet[addrIdx++]); - bytes memory valueManagerBytes2 = abi.encodePacked(bytes20(uint160(manager2))); - require(valueManagerBytes2.length == 20, "length of manager2 address mismatch in tests"); - updateParamByGovHub(keyAddManager, valueManagerBytes2, address(newRelayerHub)); + address manager2 = addNewManager(newRelayerHub); address newRelayer2 = payable(addrSet[addrIdx++]); vm.prank(manager2, manager2); vm.expectEmit(true, true, false, true); @@ -212,15 +200,21 @@ contract RelayerHubTest is Deployer { return newRelayerHub; } - function testRelayerAddingRemoving2() public { - RelayerHub newRelayerHub = helperGetNewRelayerHub(); - + // Helper function to add a new manager through RelayerHub + function addNewManager(RelayerHub relayerHub) internal returns (address) { bytes memory keyAddManager = "addManager"; address manager = payable(addrSet[addrIdx++]); - address newRelayer = payable(addrSet[addrIdx++]); bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); require(valueManagerBytes.length == 20, "length of manager address mismatch in tests"); - updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); + updateParamByGovHub(keyAddManager, valueManagerBytes, address(relayerHub)); + return manager; + } + + + function testRelayerAddingRemoving2() public { + RelayerHub newRelayerHub = helperGetNewRelayerHub(); + address manager = addNewManager(newRelayerHub); + address newRelayer = payable(addrSet[addrIdx++]); vm.prank(manager, manager); vm.expectEmit(true, true, false, true); @@ -232,10 +226,7 @@ contract RelayerHubTest is Deployer { emit relayerUpdated(payable(address(0)), newRelayer); newRelayerHub.acceptBeingRelayer(manager); - address manager2 = payable(addrSet[addrIdx++]); - bytes memory valueManagerBytes2 = abi.encodePacked(bytes20(uint160(manager2))); - require(valueManagerBytes2.length == 20, "length of manager2 address mismatch in tests"); - updateParamByGovHub(keyAddManager, valueManagerBytes2, address(newRelayerHub)); + address manager2 = addNewManager(newRelayerHub); address newRelayer2 = payable(addrSet[addrIdx++]); vm.prank(manager2, manager2); @@ -265,12 +256,7 @@ contract RelayerHubTest is Deployer { function testContractRelayer() public { RelayerHub newRelayerHub = helperGetNewRelayerHub(); - - bytes memory keyAddManager = "addManager"; - address manager = payable(addrSet[addrIdx++]); - bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); - require(valueManagerBytes.length == 20, "length of manager address mismatch in tests"); - updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); + address manager = addNewManager(newRelayerHub); uint64 nonceManager = vm.getNonce(manager); @@ -297,12 +283,7 @@ contract RelayerHubTest is Deployer { function testProxyContractRelayer() public { RelayerHub newRelayerHub = helperGetNewRelayerHub(); - - bytes memory keyAddManager = "addManager"; - address manager = payable(addrSet[addrIdx++]); - bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); - require(valueManagerBytes.length == 20, "length of manager address mismatch in tests"); - updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); + address manager = addNewManager(newRelayerHub); uint64 nonceManager = vm.getNonce(manager); @@ -327,13 +308,8 @@ contract RelayerHubTest is Deployer { // then it shouldn't be able to register. function testManagerDeleteProvisionalRelayerRegistration() public { RelayerHub newRelayerHub = helperGetNewRelayerHub(); - - bytes memory keyAddManager = "addManager"; - address manager = payable(addrSet[addrIdx++]); + address manager = addNewManager(newRelayerHub); bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); - require(valueManagerBytes.length == 20, "length of manager address mismatch in tests"); - updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); - address newRelayer = payable(addrSet[addrIdx++]); // add the above address as relayer address which currently doesn't have code @@ -362,13 +338,7 @@ contract RelayerHubTest is Deployer { // In this case the relayer is added as a provisional only and not full relayer // So the provisional relayer should also be deleted, especially if the relayer is yet to add itself as a full relayer RelayerHub newRelayerHub = helperGetNewRelayerHub(); - - bytes memory keyAddManager = "addManager"; - address manager = payable(addrSet[addrIdx++]); - bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); - require(valueManagerBytes.length == 20, "length of manager address mismatch in tests"); - updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); - + address manager = addNewManager(newRelayerHub); address newRelayer = payable(addrSet[addrIdx++]); vm.prank(manager, manager); @@ -383,13 +353,7 @@ contract RelayerHubTest is Deployer { function testCorrectManagerForAcceptRelayer() public { RelayerHub newRelayerHub = helperGetNewRelayerHub(); - - bytes memory keyAddManager = "addManager"; - address manager = payable(addrSet[addrIdx++]); - bytes memory valueManagerBytes = abi.encodePacked(bytes20(uint160(manager))); - require(valueManagerBytes.length == 20, "length of manager address mismatch in tests"); - updateParamByGovHub(keyAddManager, valueManagerBytes, address(newRelayerHub)); - + address manager = addNewManager(newRelayerHub); address newRelayer = payable(addrSet[addrIdx++]); vm.prank(manager, manager); @@ -403,30 +367,4 @@ contract RelayerHubTest is Deployer { } - // function testCannotRegister() public { - // address newRelayer = addrSet[addrIdx++]; - // vm.startPrank(newRelayer, newRelayer); - // relayerHub.register{value: 100 ether}(); - // - // // re-register - // vm.expectRevert(bytes("relayer already exist")); - // relayerHub.register{value: 100 ether}(); - // - // relayerHub.unregister(); - // // re-unregister - // vm.expectRevert(bytes("relayer do not exist")); - // relayerHub.unregister(); - // - // vm.stopPrank(); - // newRelayer = addrSet[addrIdx++]; - // vm.startPrank(newRelayer, newRelayer); - // - // // send 200 ether - // vm.expectRevert(bytes("deposit value is not exactly the same")); - // relayerHub.register{value: 200 ether}(); - // - // // send 10 ether - // vm.expectRevert(bytes("deposit value is not exactly the same")); - // relayerHub.register{value: 10 ether}(); - // } } From b13d05550c3b6a0c40f19f7cf244daed7ac4f0a1 Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Tue, 7 Mar 2023 08:59:51 +0100 Subject: [PATCH 84/90] relayer: fix generation scripts --- generate-relayerhub.js | 1 + generate-system.js | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/generate-relayerhub.js b/generate-relayerhub.js index 7a62f56c..656c77e3 100644 --- a/generate-relayerhub.js +++ b/generate-relayerhub.js @@ -23,6 +23,7 @@ program.parse(process.argv); const data = { mock: program.mock, + network: program.network, }; const templateString = fs.readFileSync(program.template).toString(); diff --git a/generate-system.js b/generate-system.js index a42c90cb..b46759c9 100644 --- a/generate-system.js +++ b/generate-system.js @@ -32,7 +32,6 @@ const data = { fromChainId: program.fromChainId, bscChainId: program.bscChainId, mock: program.mock, - network: program.network, }; const templateString = fs.readFileSync(program.template).toString(); const resultString = nunjucks.renderString(templateString, data); From 0b5f96389e824ff12eb50ef01150ad84dba4a33b Mon Sep 17 00:00:00 2001 From: yutianwu Date: Thu, 16 Mar 2023 15:47:43 +0800 Subject: [PATCH 85/90] fix: fix the bool decode and encode for rlp lib --- contracts/lib/RLPDecode.sol | 6 +++++- contracts/lib/RLPEncode.sol | 4 +--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/contracts/lib/RLPDecode.sol b/contracts/lib/RLPDecode.sol index 6cc810ca..3c694dbc 100644 --- a/contracts/lib/RLPDecode.sol +++ b/contracts/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) { diff --git a/contracts/lib/RLPEncode.sol b/contracts/lib/RLPEncode.sol index 84fd99f2..e8153114 100644 --- a/contracts/lib/RLPEncode.sol +++ b/contracts/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; } From a74f32085031434b25dad169f1286bf4255bc15c Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 7 Apr 2023 17:02:08 +0800 Subject: [PATCH 86/90] [r4r]Introduce Casper FFG based Fast finality onto BSC (#255) * [WIP]Fast Finality: reward distribution and slash parts (#8) * 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 * Minor error fixed * Fix review comments and update scripts * Fix init issue * Fix external view issue and update test * Fix review comments * Update for new fast finality rules and related issues * Revert code format changes * Resolve conflict * Update contracts' abi * Update finality reward related events * Fix some audit comments * resolve conflict and adapt to new precompile bls verify contract * fix: recover deleted verifyBLSSignature function call * fix: revert modification for local unit test * fix: errors with template * fix rebase errors * update contract abi * update finality reward distribution logic * update reward calculation using SafeMath lib --------- Co-authored-by: Roshan <48975233+loverush@users.noreply.github.com> --- BLSkeystore.json | 45 + abi/bscvalidatorset.abi | 2463 +++++++++++++--------- abi/crosschain.abi | 1972 ++++++++++------- abi/govhub.abi | 886 ++++---- abi/relayerhub.abi | 914 ++++---- abi/relayerincentivize.abi | 1558 +++++++------- abi/slashindicator.abi | 1462 +++++++------ abi/staking.abi | 276 +-- abi/systemreward.abi | 892 ++++---- abi/tendermintlightclient.abi | 1239 +++++------ abi/tokenhub.abi | 2352 ++++++++++++--------- abi/tokenmanager.abi | 2279 ++++++++++---------- contracts/BSCValidatorSet.sol | 411 ++-- contracts/BSCValidatorSet.template | 415 ++-- contracts/SlashIndicator.sol | 120 +- contracts/SlashIndicator.template | 120 +- contracts/SystemReward.sol | 45 +- contracts/SystemReward.template | 70 +- contracts/interface/IBSCValidatorSet.sol | 3 + generate-validator.js | 13 +- genesis-template.json | 2 + genesis.json | 4 +- lib/Deployer.sol | 37 + lib/RLPDecode.sol | 8 +- lib/RLPEncode.sol | 6 +- lib/interface/IBSCValidatorSet.sol | 14 +- lib/interface/ISlashIndicator.sol | 17 + lib/interface/ISystemReward.sol | 4 + test/SlashIndicator.t.sol | 301 ++- test/Staking.t.sol | 4 +- test/SystemReward.t.sol | 22 +- test/TokenHub.t.sol | 56 +- test/ValidatorSet.t.sol | 132 +- validators.js | 18 +- validators.template | 20 +- 35 files changed, 10043 insertions(+), 8137 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..207effaf 100644 --- a/abi/bscvalidatorset.abi +++ b/abi/bscvalidatorset.abi @@ -1,1016 +1,1451 @@ [ - { - "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", + "name": "validator", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "deprecatedFinalityRewardDeposit", + "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": true, + "internalType": "address", + "name": "validator", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "finalityRewardDeposit", + "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": "CROSS_STAKE_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "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": "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": "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": "index", + "type": "uint256" + } + ], + "name": "canEnterMaintenance", + "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": [ + { + "internalType": "address", + "name": "valAddr", + "type": "address" + } + ], + "name": "deposit", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "valAddrs", + "type": "address[]" + }, + { + "internalType": "uint256[]", + "name": "weights", + "type": "uint256[]" + } + ], + "name": "distributeFinalityReward", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "enterMaintenance", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "exitMaintenance", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "expireTimeSecondGap", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "felony", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "finalityRewardRatio", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_validator", + "type": "address" + } + ], + "name": "getCurrentValidatorIndex", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "getIncoming", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "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": [], + "name": "getWorkingValidatorCount", + "outputs": [ + { + "internalType": "uint256", + "name": "workingValidatorCount", + "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": "", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "handleSynPackage", + "outputs": [ + { + "internalType": "bytes", + "name": "responsePayload", + "type": "bytes" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "init", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "isCurrentValidator", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "isWorkingValidator", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "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": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "misdemeanor", + "outputs": [], + "stateMutability": "nonpayable", + "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": "string", + "name": "key", + "type": "string" + }, + { + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "updateParam", + "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..d8f6c78a 100644 --- a/abi/crosschain.abi +++ b/abi/crosschain.abi @@ -1,810 +1,1166 @@ [ - { - "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": "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": [ + { + "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": "CANCEL_TRANSFER_PROPOSAL", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "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": "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", + "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": "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", + "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": "REOPEN_PROPOSAL", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "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": "SUSPEND_PROPOSAL", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "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": "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": [ + { + "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": "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": [ + { + "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": "isSuspended", + "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": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "name": "quorumMap", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "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": "reopen", + "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": [], + "name": "suspend", + "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 981fd424..cbd6ff0a 100644 --- a/abi/govhub.abi +++ b/abi/govhub.abi @@ -1,458 +1,432 @@ [ - { - "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": "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": "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": "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": "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": "", + "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": "uint8", + "name": "", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "msgBytes", + "type": "bytes" + } + ], + "name": "handleSynPackage", + "outputs": [ + { + "internalType": "bytes", + "name": "responsePayload", + "type": "bytes" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } ] \ No newline at end of file diff --git a/abi/relayerhub.abi b/abi/relayerhub.abi index 719c4cc6..b712a5c7 100644 --- a/abi/relayerhub.abi +++ b/abi/relayerhub.abi @@ -1,475 +1,443 @@ [ - { - "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": "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_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": "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": "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": "init", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "isRelayer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "register", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "requiredDeposit", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "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" + } ] \ No newline at end of file diff --git a/abi/relayerincentivize.abi b/abi/relayerincentivize.abi index b389ff6b..4cc97425 100644 --- a/abi/relayerincentivize.abi +++ b/abi/relayerincentivize.abi @@ -1,807 +1,755 @@ [ - { - "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": "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": "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": "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": "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": [ + { + "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", + "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": "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", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "callerCompensationMolecule", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "relayerAddr", + "type": "address" + } + ], + "name": "claimRelayerReward", + "outputs": [], + "stateMutability": "nonpayable", + "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": [], + "name": "init", + "outputs": [], + "stateMutability": "nonpayable", + "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" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "key", + "type": "string" + }, + { + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "updateParam", + "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 60eb3d90..83152d12 100644 --- a/abi/slashindicator.abi +++ b/abi/slashindicator.abi @@ -1,674 +1,792 @@ [ - { - "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": [ + { + "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": [], + "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": "CROSS_STAKE_CHANNELID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "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": "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": "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": "clean", + "outputs": [], + "stateMutability": "nonpayable", + "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": "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" + }, + { + "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": "uint8", + "name": "", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "name": "handleSynPackage", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "nonpayable", + "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": "init", + "outputs": [], + "stateMutability": "nonpayable", + "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": "address", + "name": "validator", + "type": "address" + } + ], + "name": "sendFelonyPackage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "slash", + "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": "bytes", + "name": "voteAddr", + "type": "bytes" + } + ], + "internalType": "struct SlashIndicator.FinalityEvidence", + "name": "_evidence", + "type": "tuple" + } + ], + "name": "submitFinalityViolationEvidence", + "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": "", + "type": "uint256" + } + ], + "name": "validators", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + } ] \ No newline at end of file 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 aca3233f..352cd95f 100644 --- a/abi/systemreward.abi +++ b/abi/systemreward.abi @@ -1,428 +1,468 @@ [ - { - "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": 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": [ + { + "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" + }, + { + "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": "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": "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": "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": "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": [], + "name": "numOperator", + "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" + }, + { + "stateMutability": "payable", + "type": "receive" + } ] \ 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/tokenhub.abi b/abi/tokenhub.abi index 1faeb599..f8ede968 100644 --- a/abi/tokenhub.abi +++ b/abi/tokenhub.abi @@ -1,1057 +1,1299 @@ [ - { - "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" - } + { + "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, + "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_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", + "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", + "name": "tokenAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "attacker", + "type": "address" + } + ], + "name": "cancelTransferIn", + "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": [ + { + "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": [ + { + "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", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "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": [ + { + "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" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "recipient", + "type": "address" + } + ], + "name": "withdrawUnlockedToken", + "outputs": [], + "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 1d03235b..11d7ea2a 100644 --- a/abi/tokenmanager.abi +++ b/abi/tokenmanager.abi @@ -1,1202 +1,1081 @@ [ - { - "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": "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": "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": "STAKING_CONTRACT_ADDR", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "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": "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": "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": [ + { + "internalType": "string", + "name": "bep2Symbol", + "type": "string" + } + ], + "name": "expireBind", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "payable", + "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": [ + { + "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": [], + "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": [ + { + "internalType": "string", + "name": "symbol", + "type": "string" + } + ], + "name": "queryRequiredLockAmountForBind", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "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": "address", + "name": "bep20Addr", + "type": "address" + }, + { + "internalType": "uint64", + "name": "expireTime", + "type": "uint64" + } + ], + "name": "sync", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "syncFee", + "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/contracts/BSCValidatorSet.sol b/contracts/BSCValidatorSet.sol index f2f7fbb4..c0ef234a 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"; @@ -54,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; @@ -74,7 +75,15 @@ 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 = 50; + uint256 public constant MAX_SYSTEM_REWARD_BALANCE = 100 ether; + + uint256 public finalityRewardRatio; + uint256 public previousHeight; + uint256 public previousBalanceOfSystemReward; + + struct Validator { address consensusAddress; address payable feeAddress; address BBCFeeAddress; @@ -90,14 +99,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 +124,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 +158,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 +404,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 +538,63 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica return isWorkingValidator(index); } + 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; + uint256 balanceOfSystemReward = address(SYSTEM_REWARD_ADDR).balance; + 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); + previousBalanceOfSystemReward = address(SYSTEM_REWARD_ADDR).balance; + 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,7 +709,7 @@ 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"); @@ -609,6 +734,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 +746,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 < m; ++i) { + validatorExtra.voteAddress = voteAddrs[i]; currentValidatorSet.push(validatorSet[i]); validatorExtraSet.push(validatorExtra); currentValidatorSetMap[validatorSet[i].consensusAddress] = i+1; @@ -677,7 +796,7 @@ 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 previousHeight, "can not do this twice in one block"); + _; + previousHeight = block.number; + } + /*********************** events **************************/ event validatorSetUpdated(); event validatorJailed(address indexed validator); @@ -139,12 +158,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 +404,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 +538,55 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica return isWorkingValidator(index); } + 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; + uint256 balanceOfSystemReward = address(SYSTEM_REWARD_ADDR).balance; + 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); + previousBalanceOfSystemReward = address(SYSTEM_REWARD_ADDR).balance; + if (totalValue == 0) { + return; + } + + uint256 value; + address valAddr; + uint256 index; + + 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,7 +701,7 @@ 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"); @@ -609,6 +726,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 +738,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) { + 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; } } @@ -677,7 +788,7 @@ 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 previousHeight, "can not slash twice in one block"); _; @@ -115,19 +140,18 @@ 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{ - 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; @@ -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,46 @@ 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"); + + 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); + 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 +243,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..a3ecf96f 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); @@ -44,6 +54,21 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication 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"); _; @@ -120,19 +145,18 @@ 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{ - 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; @@ -142,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; @@ -175,6 +199,46 @@ 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"); + + 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); + 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 * @@ -184,6 +248,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/SystemReward.sol b/contracts/SystemReward.sol index ffaa2a60..7669d23f 100644 --- a/contracts/SystemReward.sol +++ b/contracts/SystemReward.sol @@ -1,14 +1,16 @@ 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; mapping(address => bool) operators; - modifier doInit() { if (!alreadyInit) { operators[LIGHT_CLIENT_ADDR] = true; @@ -19,16 +21,17 @@ 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 addOperator(address indexed operator); + event deleteOperator(address indexed operator); + event paramChange(string key, bytes value); receive() external payable{ if (msg.value>0) { @@ -36,13 +39,12 @@ contract SystemReward is System, 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; } - if (actualAmount>0) { + if (actualAmount != 0) { to.transfer(actualAmount); emit rewardTo(to, actualAmount); } else { @@ -54,4 +56,29 @@ 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, "addOperator")) { + bytes memory valueLocal = value; + require(valueLocal.length == 20, "length of value for addOperator should be 20"); + address operatorAddr; + assembly { + operatorAddr := mload(add(valueLocal, 20)) + } + operators[operatorAddr] = true; + 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"); + } + emit paramChange(key, value); + } +} diff --git a/contracts/SystemReward.template b/contracts/SystemReward.template index b5dec8a1..7669d23f 100644 --- a/contracts/SystemReward.template +++ b/contracts/SystemReward.template @@ -1,14 +1,16 @@ 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; mapping(address => bool) operators; - modifier doInit() { if (!alreadyInit) { operators[LIGHT_CLIENT_ADDR] = true; @@ -19,19 +21,17 @@ contract SystemReward is System, ISystemReward{ _; } - modifier onlyOperator() { require(operators[msg.sender],"only operator is allowed to call the method"); _; } - {% if mock %} - event newOperator(address indexed operator); - event deleteOperator(address indexed operator); - {% endif %} + event rewardTo(address indexed to, uint256 amount); event rewardEmpty(); event receiveDeposit(address indexed from, uint256 amount); - + event addOperator(address indexed operator); + event deleteOperator(address indexed operator); + event paramChange(string key, bytes value); receive() external payable{ if (msg.value>0) { @@ -39,35 +39,12 @@ contract SystemReward is System, 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 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; } - if (actualAmount>0) { + if (actualAmount != 0) { to.transfer(actualAmount); emit rewardTo(to, actualAmount); } else { @@ -79,4 +56,29 @@ 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, "addOperator")) { + bytes memory valueLocal = value; + require(valueLocal.length == 20, "length of value for addOperator should be 20"); + address operatorAddr; + assembly { + operatorAddr := mload(add(valueLocal, 20)) + } + operators[operatorAddr] = true; + 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"); + } + emit paramChange(key, value); + } +} diff --git a/contracts/interface/IBSCValidatorSet.sol b/contracts/interface/IBSCValidatorSet.sol index 513c9289..3a6f2407 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 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 b23556fb..7246b684 100644 --- a/generate-validator.js +++ b/generate-validator.js @@ -1,10 +1,11 @@ const fs = require("fs"); 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, @@ -19,14 +20,16 @@ async function processValidatorConf() { 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 resultString = nunjucks.renderString(templateString, data); 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/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/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..48f98080 100644 --- a/lib/interface/ISystemReward.sol +++ b/lib/interface/ISystemReward.sol @@ -1,9 +1,12 @@ 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 addOperator(address indexed operator); + event deleteOperator(address indexed operator); function BIND_CHANNELID() external view returns (uint8); function CODE_OK() external view returns (uint32); @@ -31,4 +34,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/SlashIndicator.t.sol b/test/SlashIndicator.t.sol index 85ef92e0..56ba9e92 100644 --- a/test/SlashIndicator.t.sol +++ b/test/SlashIndicator.t.sol @@ -3,5 +3,304 @@ pragma solidity ^0.8.10; import "../lib/Deployer.sol"; contract SlashIndicatorTest is Deployer { - function setUp() public {} + event validatorSlashed(address indexed validator); + event indicatorCleaned(); + event paramChange(string key, bytes value); + + address public coinbase; + address[] public validators; + + function setUp() public { + bytes memory slashCode = vm.getDeployedCode("SlashIndicator.sol"); + vm.etch(address(slash), slashCode); + + validators = validator.getValidators(); + + coinbase = block.coinbase; + vm.deal(coinbase, 100 ether); + } + + function testGov() public { + bytes memory key = "misdemeanorThreshold"; + bytes memory value = bytes(hex"0000000000000000000000000000000000000000000000000000000000000064"); // 100 + updateParamByGovHub(key, value, address(slash)); + assertEq(slash.misdemeanorThreshold(), 100); + + key = "felonyThreshold"; + value = bytes(hex"00000000000000000000000000000000000000000000000000000000000000c8"); // 200 + updateParamByGovHub(key, value, address(slash)); + assertEq(slash.felonyThreshold(), 200); + + key = "finalitySlashRewardRatio"; + value = bytes(hex"0000000000000000000000000000000000000000000000000000000000000032"); // 50 + updateParamByGovHub(key, value, address(slash)); + assertEq(slash.finalitySlashRewardRatio(), 50); + } + + function testSlash() public { + address validator = validators[0]; + + vm.expectRevert(bytes("the message sender must be the block producer")); + slash.slash(validator); + + vm.startPrank(coinbase); + (, uint256 origin) = slash.getSlashIndicator(validator); + for (uint256 i = 1; i < 10; ++i) { + vm.expectEmit(true, false, false, true, address(slash)); + emit validatorSlashed(validator); + slash.slash(validator); + vm.roll(block.number + 1); + (, uint256 count) = slash.getSlashIndicator(validator); + assertEq(origin + i, count); + } + vm.stopPrank(); + } + + function testMaintenance() public { + vm.prank(validators[0]); + validator.enterMaintenance(); + + (, uint256 countBefore) = slash.getSlashIndicator(validators[0]); + vm.prank(coinbase); + slash.slash(validators[0]); + (, uint256 countAfter) = slash.getSlashIndicator(validators[0]); + assertEq(countAfter, countBefore); + + vm.prank(validators[0]); + vm.expectRevert(bytes("can not enter Temporary Maintenance")); + validator.enterMaintenance(); + + // exit maintenance + vm.prank(validators[0]); + validator.exitMaintenance(); + vm.roll(block.number + 1); + vm.prank(coinbase); + slash.slash(validators[0]); + (, countAfter) = slash.getSlashIndicator(validators[0]); + assertEq(countAfter, countBefore + 1); + + vm.prank(validators[0]); + vm.expectRevert(bytes("can not enter Temporary Maintenance")); + validator.enterMaintenance(); + } + + function testMisdemeanor() public { + address[] memory vals = new address[](21); + for (uint256 i; i < vals.length; ++i) { + vals[i] = addrSet[addrIdx++]; + } + vm.prank(address(crossChain)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, vals)); + + vm.startPrank(coinbase); + validator.deposit{value: 1 ether}(vals[0]); + assertEq(9e17, validator.getIncoming(vals[0])); + + for (uint256 i; i < 50; ++i) { + vm.roll(block.number + 1); + slash.slash(vals[0]); + } + (, uint256 count) = slash.getSlashIndicator(vals[0]); + assertEq(50, count); + assertEq(0, validator.getIncoming(vals[0])); + + // enter maintenance, cannot be slashed + vm.roll(block.number + 1); + slash.slash(vals[0]); + (, count) = slash.getSlashIndicator(vals[0]); + assertEq(50, count); + vm.stopPrank(); + + address[] memory newVals = new address[](3); + for (uint256 i; i < newVals.length; ++i) { + newVals[i] = vals[i]; + } + vm.prank(address(crossChain)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, newVals)); + + vm.startPrank(coinbase); + validator.deposit{value: 2 ether}(newVals[0]); + assertEq(18e17, validator.getIncoming(newVals[0])); + + for (uint256 i; i < 37; ++i) { + vm.roll(block.number + 1); + slash.slash(newVals[0]); + } + (, count) = slash.getSlashIndicator(newVals[0]); + assertEq(50, count); + assertEq(0, validator.getIncoming(newVals[0])); + assertEq(9e17, validator.getIncoming(newVals[1])); + assertEq(9e17, validator.getIncoming(newVals[2])); + + validator.deposit{value: 1 ether}(newVals[1]); + assertEq(18e17, validator.getIncoming(newVals[1])); + for (uint256 i; i < 50; ++i) { + vm.roll(block.number + 1); + slash.slash(newVals[1]); + } + assertEq(9e17, validator.getIncoming(newVals[0])); + assertEq(0, validator.getIncoming(newVals[1])); + assertEq(18e17, validator.getIncoming(newVals[2])); + + assertEq(18e17, validator.getIncoming(newVals[2])); + for (uint256 i; i < 50; ++i) { + vm.roll(block.number + 1); + slash.slash(newVals[2]); + } + assertEq(18e17, validator.getIncoming(newVals[0])); + assertEq(9e17, validator.getIncoming(newVals[1])); + assertEq(0, validator.getIncoming(newVals[2])); + vm.stopPrank(); + } + + function testFelony() public { + address[] memory vals = new address[](3); + for (uint256 i; i < vals.length; ++i) { + vals[i] = addrSet[addrIdx++]; + } + vm.prank(address(crossChain)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, vals)); + + vm.startPrank(coinbase); + validator.deposit{value: 1 ether}(vals[0]); + assertEq(9e17, validator.getIncoming(vals[0])); + + for (uint256 i; i < 50; ++i) { + vm.roll(block.number + 1); + slash.slash(vals[0]); + } + (, uint256 count) = slash.getSlashIndicator(vals[0]); + assertEq(50, count); + assertEq(0, validator.getIncoming(vals[0])); + vm.stopPrank(); + + vm.prank(vals[0]); + validator.exitMaintenance(); + + vm.startPrank(coinbase); + validator.deposit{value: 1 ether}(vals[0]); + for (uint256 i; i < 100; ++i) { + vm.roll(block.number + 1); + slash.slash(vals[0]); + } + (, count) = slash.getSlashIndicator(vals[0]); + assertEq(0, count); + assertEq(0, validator.getIncoming(vals[0])); + assertEq(9e17, validator.getIncoming(vals[1])); + assertEq(9e17, validator.getIncoming(vals[2])); + + vals = validator.getValidators(); + assertEq(2, vals.length); + vm.stopPrank(); + } + + function testClean() public { + // case 1: all clean. + address[] memory vals = new address[](20); + for (uint256 i; i < vals.length; ++i) { + vals[i] = addrSet[addrIdx++]; + } + vm.prank(address(crossChain)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, vals)); + + vm.startPrank(coinbase); + for (uint256 i; i < vals.length; ++i) { + vm.roll(block.number + 1); + slash.slash(vals[i]); + } + vm.stopPrank(); + + // do clean + vm.prank(address(crossChain)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, vals)); + + uint256 count; + for (uint256 i; i < vals.length; ++i) { + (, count) = slash.getSlashIndicator(vals[i]); + assertEq(0, count); + } + + // case 2: all stay. + // felonyThreshold/DECREASE_RATE = 37 + vm.startPrank(coinbase); + for (uint256 i; i < vals.length; ++i) { + for (uint256 j; j < 38; ++j) { + vm.roll(block.number + 1); + slash.slash(vals[i]); + } + } + vm.stopPrank(); + + // do clean + vm.prank(address(crossChain)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, vals)); + + for (uint256 i; i < vals.length; ++i) { + (, count) = slash.getSlashIndicator(vals[i]); + assertEq(1, count); + } + + // case 3: partial stay. + vm.startPrank(coinbase); + for (uint256 i; i < 10; ++i) { + for (uint256 j; j < 38; ++j) { + vm.roll(block.number + 1); + slash.slash(vals[2 * i]); + } + vm.roll(block.number + 1); + slash.slash(vals[2 * i + 1]); + } + vm.stopPrank(); + + // do clean + vm.prank(address(crossChain)); + validator.handleSynPackage(STAKING_CHANNELID, encodeOldValidatorSetUpdatePack(0x00, vals)); + + for (uint256 i; i < 10; ++i) { + (, count) = slash.getSlashIndicator(vals[i]); + if (i % 2 == 0) { + assertEq(2, count); + } else { + assertEq(0, count); + } + } + } + + // function testFinality() public { + // address[] memory vals = new address[](20); + // bytes[] memory voteAddrs = new bytes[](20); + // for (uint256 i; i < vals.length; ++i) { + // vals[i] = addrSet[addrIdx++]; + // voteAddrs[i] = abi.encodePacked(vals[i]); + // } + // vm.prank(address(crossChain)); + // validator.handleSynPackage(STAKING_CHANNELID, encodeNewValidatorSetUpdatePack(0x00, vals, voteAddrs)); + // + // // case1: valid finality evidence: same target block + // uint256 srcNumA = block.number - 20; + // uint256 tarNumA = block.number - 10; + // uint256 srcNumB = block.number - 15; + // uint256 tarNumB = tarNumA; + // SlashIndicator.VoteData memory voteA; + // voteA.srcNum = srcNumA; + // voteA.srcHash = blockhash(srcNumA); + // voteA.tarNum = tarNumA; + // voteA.tarHash = blockhash(tarNumA); + // voteA.sig = abi.encode("sigA"); + // + // SlashIndicator.VoteData memory voteB; + // voteB.srcNum = srcNumB; + // voteB.srcHash = blockhash(srcNumB); + // voteB.tarNum = tarNumB; + // voteB.tarHash = blockhash(tarNumB); + // voteB.sig = abi.encode("sigB"); + // + // SlashIndicator.FinalityEvidence memory evidence; + // evidence.voteA = voteA; + // evidence.voteB = voteB; + // evidence.voteAddr = voteAddrs[0]; + // + // vm.prank(relayer); + // slash.submitFinalityViolationEvidence(evidence); + // } } diff --git a/test/Staking.t.sol b/test/Staking.t.sol index b270cc02..3a2d1b9e 100644 --- a/test/Staking.t.sol +++ b/test/Staking.t.sol @@ -7,9 +7,7 @@ contract StakingTest is Deployer { event delegateSubmitted(address indexed delegator, address indexed validator, uint256 amount, uint256 oracleRelayerFee); event undelegateSubmitted(address indexed delegator, address indexed validator, uint256 amount, uint256 oracleRelayerFee); - event redelegateSubmitted( - address indexed delegator, address indexed validatorSrc, address indexed validatorDst, uint256 amount, uint256 oracleRelayerFee - ); + event redelegateSubmitted(address indexed delegator, address indexed validatorSrc, address indexed validatorDst, uint256 amount, uint256 oracleRelayerFee); event rewardReceived(address indexed delegator, uint256 amount); event rewardClaimed(address indexed delegator, uint256 amount); event undelegatedReceived(address indexed delegator, address indexed validator, uint256 amount); diff --git a/test/SystemReward.t.sol b/test/SystemReward.t.sol index 3ef0c708..0d97ccf3 100644 --- a/test/SystemReward.t.sol +++ b/test/SystemReward.t.sol @@ -3,10 +3,14 @@ pragma solidity ^0.8.10; import "../lib/Deployer.sol"; contract SystemRewardTest is Deployer { + event paramChange(string key, bytes value); event rewardTo(address indexed to, uint256 amount); event rewardEmpty(); - function setUp() public {} + function setUp() public { + bytes memory rewardCode = vm.getDeployedCode("SystemReward.sol"); + vm.etch(address(systemReward), rewardCode); + } function testReceive(uint256 amount) public { vm.assume(amount < 1e20); @@ -25,7 +29,6 @@ contract SystemRewardTest is Deployer { } function testClaimReward() public { - // vm.assume(amount < 1e20); address newAccount = addrSet[addrIdx++]; payable(address(systemReward)).transfer(1 ether); @@ -43,4 +46,19 @@ contract SystemRewardTest is Deployer { vm.prank(LIGHT_CLIENT_ADDR); systemReward.claimRewards(newAccount, 1 ether); } + + function testGov() public { + bytes memory key = "addOperator"; + 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))); + + key = "deleteOperator"; + vm.expectEmit(false, false, false, true, address(systemReward)); + emit paramChange(string(key), valueBytes); + updateParamByGovHub(key, valueBytes, address(systemReward)); + assertFalse(systemReward.isOperator(address(validator))); + } } diff --git a/test/TokenHub.t.sol b/test/TokenHub.t.sol index 2e4de5c4..36708e4f 100644 --- a/test/TokenHub.t.sol +++ b/test/TokenHub.t.sol @@ -74,8 +74,7 @@ contract TokenHubTest is Deployer { vm.prank(address(crossChain)); tokenManager.handleSynPackage(BIND_CHANNELID, pack); - (, bytes32 symbol, address addr, uint256 totalSupply, uint256 peggyAmount, uint8 decimal,) = - tokenManager.bindPackageRecord(bytes32("ABC-9C7")); + (, bytes32 symbol, address addr, uint256 totalSupply, uint256 peggyAmount, uint8 decimal,) = tokenManager.bindPackageRecord(bytes32("ABC-9C7")); assertEq(symbol, bytes32("ABC-9C7"), "wrong symbol"); assertEq(addr, address(abcToken), "wrong token address"); assertEq(totalSupply, 1e8 * 1e18, "wrong total supply"); @@ -776,9 +775,7 @@ contract TokenHubTest is Deployer { tokenManager.mirror{value: miniRelayerFee + mirrorFee}(address(xyzToken), expireTime); // Mirror fail ack - pack = buildMirrorFailAckPackage( - address(this), address(xyzToken), bytes32("XYZ Token"), uint8(18), bytes32("XYZ"), 1e8 * 1e18, mirrorFee / 1e10, expireTime - ); + pack = buildMirrorFailAckPackage(address(this), address(xyzToken), bytes32("XYZ Token"), uint8(18), bytes32("XYZ"), 1e8 * 1e18, mirrorFee / 1e10, expireTime); vm.prank(address(crossChain)); tokenManager.handleFailAckPackage(MIRROR_CHANNELID, pack); assertEq(address(tokenManager).balance, 0, "wrong balance in tokenManager"); @@ -888,11 +885,7 @@ contract TokenHubTest is Deployer { tokenManager.sync{value: miniRelayerFee + mirrorFee}(address(xyzToken), expireTime); } - function buildBindPackage(uint8 bindType, bytes32 symbol, address addr, uint256 totalSupply, uint256 peggyAmount, uint8 decimal) - internal - view - returns (bytes memory) - { + function buildBindPackage(uint8 bindType, bytes32 symbol, address addr, uint256 totalSupply, uint256 peggyAmount, uint8 decimal) internal view returns (bytes memory) { uint256 timestamp = block.timestamp; uint256 expireTime = timestamp + 3; bytes[] memory elements = new bytes[](7); @@ -906,11 +899,7 @@ contract TokenHubTest is Deployer { return elements.encodeList(); } - function buildTransferInPackage(bytes32 symbol, address tokenAddr, uint256 amount, address recipient, address refundAddr) - internal - view - returns (bytes memory) - { + function buildTransferInPackage(bytes32 symbol, address tokenAddr, uint256 amount, address recipient, address refundAddr) internal view returns (bytes memory) { uint256 timestamp = block.timestamp; uint256 expireTime = timestamp + 3; bytes[] memory elements = new bytes[](6); @@ -923,13 +912,7 @@ contract TokenHubTest is Deployer { return elements.encodeList(); } - function buildBatchTransferOutFailAckPackage( - bytes32 symbol, - address tokenAddr, - uint256[] memory amounts, - address[] memory recipients, - address[] memory refundAddrs - ) internal view returns (bytes memory) { + function buildBatchTransferOutFailAckPackage(bytes32 symbol, address tokenAddr, uint256[] memory amounts, address[] memory recipients, address[] memory refundAddrs) internal view returns (bytes memory) { uint256 length = amounts.length; bytes[] memory amtBytes = new bytes[](length); bytes[] memory recipientBytes = new bytes[](length); @@ -952,11 +935,7 @@ contract TokenHubTest is Deployer { return elements.encodeList(); } - function buildRefundPackage(address tokenAddr, uint256[] memory amounts, address[] memory recipients, uint32 status) - internal - pure - returns (bytes memory) - { + function buildRefundPackage(address tokenAddr, uint256[] memory amounts, address[] memory recipients, uint32 status) internal pure returns (bytes memory) { uint256 length = amounts.length; bytes[] memory amtBytes = new bytes[](length); bytes[] memory recipientBytes = new bytes[](length); @@ -973,11 +952,7 @@ contract TokenHubTest is Deployer { return elements.encodeList(); } - function buildMirrorAckPackage(address sender, address tokenAddr, uint8 decimal, bytes32 symbol, uint256 mirrorFee, uint8 errCode) - internal - pure - returns (bytes memory) - { + function buildMirrorAckPackage(address sender, address tokenAddr, uint8 decimal, bytes32 symbol, uint256 mirrorFee, uint8 errCode) internal pure returns (bytes memory) { bytes[] memory elements = new bytes[](6); elements[0] = sender.encodeAddress(); elements[1] = tokenAddr.encodeAddress(); @@ -988,16 +963,7 @@ contract TokenHubTest is Deployer { return elements.encodeList(); } - function buildMirrorFailAckPackage( - address sender, - address tokenAddr, - bytes32 name, - uint8 decimal, - bytes32 symbol, - uint256 supply, - uint256 mirrorFee, - uint256 expireTime - ) internal pure returns (bytes memory) { + function buildMirrorFailAckPackage(address sender, address tokenAddr, bytes32 name, uint8 decimal, bytes32 symbol, uint256 supply, uint256 mirrorFee, uint256 expireTime) internal pure returns (bytes memory) { bytes[] memory elements = new bytes[](8); elements[0] = sender.encodeAddress(); elements[1] = tokenAddr.encodeAddress(); @@ -1019,11 +985,7 @@ contract TokenHubTest is Deployer { return elements.encodeList(); } - function buildSyncFailAckPackage(address sender, address tokenAddr, bytes32 symbol, uint256 supply, uint256 syncFee, uint256 expireTime) - internal - pure - returns (bytes memory) - { + function buildSyncFailAckPackage(address sender, address tokenAddr, bytes32 symbol, uint256 supply, uint256 syncFee, uint256 expireTime) internal pure returns (bytes memory) { bytes[] memory elements = new bytes[](6); elements[0] = sender.encodeAddress(); elements[1] = tokenAddr.encodeAddress(); diff --git a/test/ValidatorSet.t.sol b/test/ValidatorSet.t.sol index 50b7f275..5f840b76 100644 --- a/test/ValidatorSet.t.sol +++ b/test/ValidatorSet.t.sol @@ -24,6 +24,8 @@ contract ValidatorSetTest is Deployer { 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); uint256 public totalInComing; uint256 public burnRatio; @@ -36,6 +38,21 @@ contract ValidatorSetTest is Deployer { mapping(address => 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 = "addOperator"; + 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,69 @@ 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])); + } + } + + 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; } - elements[1] = vals.encodeList(); - return elements.encodeList(); + 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], 25e15); + vm.expectEmit(true, false, false, true, address(validator)); + emit finalityRewardDeposit(addrs[9], 25e15); + vm.expectEmit(true, false, false, true, address(validator)); + emit deprecatedFinalityRewardDeposit(addrs[10], 25e15); + vm.expectEmit(true, false, false, true, address(validator)); + emit deprecatedFinalityRewardDeposit(addrs[19], 25e15); + validator.distributeFinalityReward(addrs, weights); + vm.stopPrank(); } } diff --git a/validators.js b/validators.js index 355e0a99..cfe30890 100644 --- a/validators.js +++ b/validators.js @@ -10,26 +10,31 @@ const validators = [ votingPower: 0x0000000000000064 } ]; +const bLSPublicKeys = [ + "0x85e6972fc98cd3c81d64d40e325acfed44365b97a7567a27939c14dbc7512ddcf54cb1284eb637cfa308ae4e00cb5588", +]; // =============== Do not edit below ==== -function generateExtradata(validators) { +function generateExtradata(validators, bLSPublicKeys) { let extraVanity =Buffer.alloc(32); - let validatorsBytes = extraDataSerialize(validators); + 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: Wed, 12 Apr 2023 10:10:08 +0200 Subject: [PATCH 87/90] fix missing part in BSCValidatorSet template --- contracts/BSCValidatorSet.template | 8 ++++++++ generate-genesis.js | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/contracts/BSCValidatorSet.template b/contracts/BSCValidatorSet.template index 2cf17430..793570d1 100644 --- a/contracts/BSCValidatorSet.template +++ b/contracts/BSCValidatorSet.template @@ -562,6 +562,14 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica return; } + uint256 totalWeight; + for (uint256 i; i Date: Wed, 12 Apr 2023 16:46:37 +0800 Subject: [PATCH 88/90] fix: error in BSCValidatorSet (#258) --- contracts/BSCValidatorSet.sol | 52 +++++++++++++++++++----------- contracts/BSCValidatorSet.template | 52 +++++++++++++++++++----------- test/ValidatorSet.t.sol | 13 ++++++++ 3 files changed, 79 insertions(+), 38 deletions(-) diff --git a/contracts/BSCValidatorSet.sol b/contracts/BSCValidatorSet.sol index c0ef234a..0d384a65 100644 --- a/contracts/BSCValidatorSet.sol +++ b/contracts/BSCValidatorSet.sol @@ -2,6 +2,7 @@ pragma solidity 0.6.4; pragma experimental ABIEncoderV2; import "./System.sol"; +import "./lib/BytesLib.sol"; import "./lib/BytesToTypes.sol"; import "./lib/Memory.sol"; import "./interface/ILightClient.sol"; @@ -418,10 +419,6 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } } - /** - * @dev Get mining validators that are block producers in the current epoch, including most of the cabinets and a few of the candidates - * - */ function getLivingValidators() external view override returns (address[] memory, bytes[] memory) { uint n = currentValidatorSet.length; uint living; @@ -452,6 +449,9 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica return (consensusAddrs, voteAddrs); } + /** + * @dev Get mining validators that are block producers in the current epoch, including most of the cabinets and a few of the candidates + */ function getMiningValidators() external view override returns(address[] memory, bytes[] memory) { uint256 _maxNumOfWorkingCandidates = maxNumOfWorkingCandidates; uint256 _numOfCabinets = numOfCabinets; @@ -548,10 +548,10 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica uint256 totalValue; uint256 balanceOfSystemReward = address(SYSTEM_REWARD_ADDR).balance; - if (balanceOfSystemReward.sub(MAX_SYSTEM_REWARD_BALANCE) > 0) { + if (balanceOfSystemReward > MAX_SYSTEM_REWARD_BALANCE) { totalValue = balanceOfSystemReward.div(100); - } else if (balanceOfSystemReward.sub(previousBalanceOfSystemReward) > 0) { - totalValue = (balanceOfSystemReward.sub(previousBalanceOfSystemReward).mul(finalityRewardRatio).div(100)); + } else if (balanceOfSystemReward > previousBalanceOfSystemReward) { + totalValue = (balanceOfSystemReward.sub(previousBalanceOfSystemReward)).mul(finalityRewardRatio).div(100); } else { return; } @@ -746,15 +746,16 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } /*********************** Internal Functions **************************/ - function doUpdateState(Validator[] memory validatorSet, bytes[] memory voteAddrs) private { + function doUpdateState(Validator[] memory newValidatorSet, bytes[] memory newVoteAddrs) private { uint n = currentValidatorSet.length; - uint m = validatorSet.length; + uint m = newValidatorSet.length; + // delete stale validators for (uint i; im) { for (uint i=m; in) { - ValidatorExtra memory validatorExtra; + ValidatorExtra memory _validatorExtra; for (uint i=n; i < m; ++i) { - validatorExtra.voteAddress = voteAddrs[i]; - currentValidatorSet.push(validatorSet[i]); - validatorExtraSet.push(validatorExtra); - currentValidatorSetMap[validatorSet[i].consensusAddress] = i+1; + _validatorExtra.voteAddress = newVoteAddrs[i]; + currentValidatorSet.push(newValidatorSet[i]); + validatorExtraSet.push(_validatorExtra); + currentValidatorSetMap[newValidatorSet[i].consensusAddress] = i+1; } } @@ -802,6 +811,11 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } } + /** + * @dev Check if two validators are the same + * + * Vote address is not considered + */ function isSameValidator(Validator memory v1, Validator memory v2) private pure returns(bool) { return v1.consensusAddress == v2.consensusAddress && v1.feeAddress == v2.feeAddress && v1.BBCFeeAddress == v2.BBCFeeAddress && v1.votingPower == v2.votingPower; } diff --git a/contracts/BSCValidatorSet.template b/contracts/BSCValidatorSet.template index 793570d1..fe84878c 100644 --- a/contracts/BSCValidatorSet.template +++ b/contracts/BSCValidatorSet.template @@ -2,6 +2,7 @@ pragma solidity 0.6.4; pragma experimental ABIEncoderV2; import "./System.sol"; +import "./lib/BytesLib.sol"; import "./lib/BytesToTypes.sol"; import "./lib/Memory.sol"; import "./interface/ILightClient.sol"; @@ -418,10 +419,6 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } } - /** - * @dev Get mining validators that are block producers in the current epoch, including most of the cabinets and a few of the candidates - * - */ function getLivingValidators() external view override returns (address[] memory, bytes[] memory) { uint n = currentValidatorSet.length; uint living; @@ -442,7 +439,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } } } else { - for (uint i=0; i 0) { + if (balanceOfSystemReward > MAX_SYSTEM_REWARD_BALANCE) { totalValue = balanceOfSystemReward.div(100); - } else if (balanceOfSystemReward.sub(previousBalanceOfSystemReward) > 0) { - totalValue = (balanceOfSystemReward.sub(previousBalanceOfSystemReward).mul(finalityRewardRatio).div(100)); + } else if (balanceOfSystemReward > previousBalanceOfSystemReward) { + totalValue = (balanceOfSystemReward.sub(previousBalanceOfSystemReward)).mul(finalityRewardRatio).div(100); } else { return; } @@ -746,15 +746,16 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } /*********************** Internal Functions **************************/ - function doUpdateState(Validator[] memory validatorSet, bytes[] memory voteAddrs) private { + function doUpdateState(Validator[] memory newValidatorSet, bytes[] memory newVoteAddrs) private { uint n = currentValidatorSet.length; - uint m = validatorSet.length; + uint m = newValidatorSet.length; + // delete stale validators for (uint i; im) { for (uint i=m; in) { ValidatorExtra memory _validatorExtra; - for (uint i = n; i < m; i++) { - _validatorExtra.voteAddress = voteAddrs[i]; - currentValidatorSet.push(validatorSet[i]); + for (uint i=n; i < m; ++i) { + _validatorExtra.voteAddress = newVoteAddrs[i]; + currentValidatorSet.push(newValidatorSet[i]); validatorExtraSet.push(_validatorExtra); - currentValidatorSetMap[validatorSet[i].consensusAddress] = i+1; + currentValidatorSetMap[newValidatorSet[i].consensusAddress] = i+1; } } @@ -802,6 +811,11 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica } } + /** + * @dev Check if two validators are the same + * + * Vote address is not considered + */ function isSameValidator(Validator memory v1, Validator memory v2) private pure returns(bool) { return v1.consensusAddress == v2.consensusAddress && v1.feeAddress == v2.feeAddress && v1.BBCFeeAddress == v2.BBCFeeAddress && v1.votingPower == v2.votingPower; } diff --git a/test/ValidatorSet.t.sol b/test/ValidatorSet.t.sol index 5f840b76..48a2e0d0 100644 --- a/test/ValidatorSet.t.sol +++ b/test/ValidatorSet.t.sol @@ -524,6 +524,19 @@ contract ValidatorSetTest is Deployer { for (uint256 i; i < newValidators.length; ++i) { assertEq(voteAddrs[i], abi.encodePacked(vals[i])); } + + // edit vote addr for existed validator + for (uint256 i; i < newValidators.length; ++i) { + newVoteAddrs[i] = abi.encodePacked(newValidators[i], "0x1234567890"); + } + vm.startPrank(address(crossChain)); + validator.handleSynPackage(STAKING_CHANNELID, encodeNewValidatorSetUpdatePack(0x00, newValidators, newVoteAddrs)); + vm.stopPrank(); + + (vals, voteAddrs) = validator.getLivingValidators(); + for (uint256 i; i < newValidators.length; ++i) { + assertEq(voteAddrs[i], abi.encodePacked(newValidators[i], "0x1234567890")); + } } function testDistributeFinalityReward() public { From ec1dda95de4025bf07e1638b47ab1777d93a20ba Mon Sep 17 00:00:00 2001 From: NathanBSC <122502194+NathanBSC@users.noreply.github.com> Date: Thu, 20 Apr 2023 10:47:29 +0800 Subject: [PATCH 89/90] fix: slash more bnbs for malicious vote and no matter whether slashed validator is active. (#262) * new slash mechanism * rename failedVoteSlash to failedMaliciousVoteSlash * add comment for a corner case * enable malicious vote slash by gov * change type of enableMaliciousVoteSlash to bool --- contracts/BSCValidatorSet.sol | 2 ++ contracts/BSCValidatorSet.template | 2 ++ contracts/SlashIndicator.sol | 45 +++++++++++++++++++++--------- contracts/SlashIndicator.template | 44 ++++++++++++++++++++--------- 4 files changed, 67 insertions(+), 26 deletions(-) diff --git a/contracts/BSCValidatorSet.sol b/contracts/BSCValidatorSet.sol index 0d384a65..45923b76 100644 --- a/contracts/BSCValidatorSet.sol +++ b/contracts/BSCValidatorSet.sol @@ -551,6 +551,8 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica if (balanceOfSystemReward > MAX_SYSTEM_REWARD_BALANCE) { totalValue = balanceOfSystemReward.div(100); } else if (balanceOfSystemReward > previousBalanceOfSystemReward) { + // when a slash happens, theres will no rewards in some epoches, + // it's tolerated because slash happens rarely totalValue = (balanceOfSystemReward.sub(previousBalanceOfSystemReward)).mul(finalityRewardRatio).div(100); } else { return; diff --git a/contracts/BSCValidatorSet.template b/contracts/BSCValidatorSet.template index fe84878c..cc097d1f 100644 --- a/contracts/BSCValidatorSet.template +++ b/contracts/BSCValidatorSet.template @@ -551,6 +551,8 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica if (balanceOfSystemReward > MAX_SYSTEM_REWARD_BALANCE) { totalValue = balanceOfSystemReward.div(100); } else if (balanceOfSystemReward > previousBalanceOfSystemReward) { + // when a slash happens, theres will no rewards in some epoches, + // it's tolerated because slash happens rarely totalValue = (balanceOfSystemReward.sub(previousBalanceOfSystemReward)).mul(finalityRewardRatio).div(100); } else { return; diff --git a/contracts/SlashIndicator.sol b/contracts/SlashIndicator.sol index 8ee0c80f..68b1f828 100644 --- a/contracts/SlashIndicator.sol +++ b/contracts/SlashIndicator.sol @@ -37,8 +37,10 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication uint256 public constant INIT_FINALITY_SLASH_REWARD_RATIO = 20; uint256 public finalitySlashRewardRatio; + bool public enableMaliciousVoteSlash; event validatorSlashed(address indexed validator); + event maliciousVoteSlashed(bytes32 indexed voteAddrSlice); event indicatorCleaned(); event paramChange(string key, bytes value); @@ -47,6 +49,7 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication event crashResponse(); event failedFelony(address indexed validator, uint256 slashCount, bytes failReason); + event failedMaliciousVoteSlash(bytes32 indexed voteAddrSlice, bytes failReason); struct Indicator { uint256 height; @@ -195,6 +198,7 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication } function submitFinalityViolationEvidence(FinalityEvidence memory _evidence) public onlyInit onlyRelayer { + require(enableMaliciousVoteSlash, "malicious vote slash not enabled"); if (finalitySlashRewardRatio == 0) { finalitySlashRewardRatio = INIT_FINALITY_SLASH_REWARD_RATIO; } @@ -213,27 +217,30 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication _evidence.voteA.tarNum == _evidence.voteB.tarNum, "no violation of vote rules"); // BLS verification + require(verifyBLSSignature(_evidence.voteA, _evidence.voteAddr) && + verifyBLSSignature(_evidence.voteB, _evidence.voteAddr), "verify signature failed"); + + // reward sender and felony validator if validator found (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]; + if (BytesLib.equal(voteAddrs[i], _evidence.voteAddr)) { + uint256 amount = (address(SYSTEM_REWARD_ADDR).balance * finalitySlashRewardRatio) / 100; + ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(msg.sender, amount); + IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).felony( vals[i]); break; } } - 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); - ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeSlashPackage(valAddr), 0); - emit validatorSlashed(valAddr); + // send slash msg to bc + bytes32 voteAddrSlice = BytesLib.toBytes32(_evidence.voteAddr,0); + try ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeVoteSlashPackage(_evidence.voteAddr), 0) { + emit maliciousVoteSlashed(voteAddrSlice); + } catch (bytes memory reason) { + emit failedMaliciousVoteSlash(voteAddrSlice, reason); + } } + /** * @dev Send a felony cross-chain package to jail a validator * @@ -299,6 +306,9 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication uint256 newFinalitySlashRewardRatio = BytesToTypes.bytesToUint256(32, value); require(newFinalitySlashRewardRatio >= 10 && newFinalitySlashRewardRatio < 100, "the finality slash reward ratio out of range"); finalitySlashRewardRatio = newFinalitySlashRewardRatio; + } else if (Memory.compareStrings(key, "enableMaliciousVoteSlash")) { + require(value.length == 32, "length of enableMaliciousVoteSlash mismatch"); + enableMaliciousVoteSlash = BytesToTypes.bytesToBool(32, value); } else { require(false, "unknown param"); } @@ -320,6 +330,15 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication return elements.encodeList(); } + function encodeVoteSlashPackage(bytes memory voteAddr) internal view returns (bytes memory) { + bytes[] memory elements = new bytes[](4); + elements[0] = voteAddr.encodeBytes(); + elements[1] = uint256(block.number).encodeUint(); + elements[2] = uint256(bscChainID).encodeUint(); + elements[3] = uint256(block.timestamp).encodeUint(); + return elements.encodeList(); + } + function getSlashThresholds() override(ISlashIndicator) external view returns (uint256, uint256) { return (misdemeanorThreshold, felonyThreshold); } diff --git a/contracts/SlashIndicator.template b/contracts/SlashIndicator.template index a3ecf96f..9674ba10 100644 --- a/contracts/SlashIndicator.template +++ b/contracts/SlashIndicator.template @@ -37,8 +37,10 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication uint256 public constant INIT_FINALITY_SLASH_REWARD_RATIO = 20; uint256 public finalitySlashRewardRatio; + bool public enableMaliciousVoteSlash; event validatorSlashed(address indexed validator); + event maliciousVoteSlashed(bytes32 indexed voteAddrSlice); event indicatorCleaned(); event paramChange(string key, bytes value); @@ -47,6 +49,7 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication event crashResponse(); event failedFelony(address indexed validator, uint256 slashCount, bytes failReason); + event failedMaliciousVoteSlash(bytes32 indexed voteAddrSlice, bytes failReason); struct Indicator { uint256 height; @@ -200,6 +203,7 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication } function submitFinalityViolationEvidence(FinalityEvidence memory _evidence) public onlyInit onlyRelayer { + require(enableMaliciousVoteSlash, "malicious vote slash not enabled"); if (finalitySlashRewardRatio == 0) { finalitySlashRewardRatio = INIT_FINALITY_SLASH_REWARD_RATIO; } @@ -218,25 +222,27 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication _evidence.voteA.tarNum == _evidence.voteB.tarNum, "no violation of vote rules"); // BLS verification + require(verifyBLSSignature(_evidence.voteA, _evidence.voteAddr) && + verifyBLSSignature(_evidence.voteB, _evidence.voteAddr), "verify signature failed"); + + // reward sender and felony validator if validator found (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]; + if (BytesLib.equal(voteAddrs[i], _evidence.voteAddr)) { + uint256 amount = (address(SYSTEM_REWARD_ADDR).balance * finalitySlashRewardRatio) / 100; + ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(msg.sender, amount); + IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).felony( vals[i]); break; } } - 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); - ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeSlashPackage(valAddr), 0); - emit validatorSlashed(valAddr); + // send slash msg to bc + bytes32 voteAddrSlice = BytesLib.toBytes32(_evidence.voteAddr,0); + try ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeVoteSlashPackage(_evidence.voteAddr), 0) { + emit maliciousVoteSlashed(voteAddrSlice); + } catch (bytes memory reason) { + emit failedMaliciousVoteSlash(voteAddrSlice, reason); + } } /** @@ -304,6 +310,9 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication uint256 newFinalitySlashRewardRatio = BytesToTypes.bytesToUint256(32, value); require(newFinalitySlashRewardRatio >= 10 && newFinalitySlashRewardRatio < 100, "the finality slash reward ratio out of range"); finalitySlashRewardRatio = newFinalitySlashRewardRatio; + } else if (Memory.compareStrings(key, "enableMaliciousVoteSlash")) { + require(value.length == 32, "length of enableMaliciousVoteSlash mismatch"); + enableMaliciousVoteSlash = BytesToTypes.bytesToBool(32, value); } else { require(false, "unknown param"); } @@ -325,6 +334,15 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication return elements.encodeList(); } + function encodeVoteSlashPackage(bytes memory voteAddr) internal view returns (bytes memory) { + bytes[] memory elements = new bytes[](4); + elements[0] = voteAddr.encodeBytes(); + elements[1] = uint256(block.number).encodeUint(); + elements[2] = uint256(bscChainID).encodeUint(); + elements[3] = uint256(block.timestamp).encodeUint(); + return elements.encodeList(); + } + function getSlashThresholds() override(ISlashIndicator) external view returns (uint256, uint256) { return (misdemeanorThreshold, felonyThreshold); } From 304e6ae3a9a4d489abf2ba126be33805111e4284 Mon Sep 17 00:00:00 2001 From: zjubfd <296179868@qq.com> Date: Thu, 20 Apr 2023 14:22:28 +0800 Subject: [PATCH 90/90] fork: enable planckBlock by default (#263) --- genesis-template.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/genesis-template.json b/genesis-template.json index 8636d298..4a8eae40 100644 --- a/genesis-template.json +++ b/genesis-template.json @@ -18,8 +18,9 @@ "eulerBlock": 2, "gibbsBlock": 3, "moranBlock": 4, - "bonehBlock": 5, - "lynnBlock": 6, + "planckBlock": 5, + "bonehBlock": 6, + "lynnBlock": 7, "parlia": { "period": 3, "epoch": 200