From 232f1f465caebe6c12058364d9868f726e3a8f4c Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Wed, 17 Jan 2024 18:57:17 +0200 Subject: [PATCH 01/15] Fix rotation history --- contracts/NodeRotation.sol | 3 ++- contracts/Schains.sol | 11 +++++++++-- contracts/SkaleDKG.sol | 15 +++++++++------ package.json | 2 +- test/SkaleDKG.ts | 32 ++++++++++++++++++++------------ yarn.lock | 8 ++++---- 6 files changed, 45 insertions(+), 26 deletions(-) diff --git a/contracts/NodeRotation.sol b/contracts/NodeRotation.sol index 517bbc55..acd21fbf 100644 --- a/contracts/NodeRotation.sol +++ b/contracts/NodeRotation.sol @@ -198,7 +198,7 @@ contract NodeRotation is Permissions, INodeRotation { ) public override - allowTwo("SkaleDKG", "SkaleManager") + allowThree("SkaleDKG", "SkaleManager", "Schains") returns (uint256 newNode) { ISchainsInternal schainsInternal = ISchainsInternal(contractManager.getContract("SchainsInternal")); @@ -297,6 +297,7 @@ contract NodeRotation is Permissions, INodeRotation { } leavingHistory[nodeIndex].push(LeavingHistory({schainHash: schainHash, finishedRotation: finishTimestamp})); require(_rotations[schainHash].newNodeIndexes.add(newNodeIndex), "New node was already added"); + _rotations[schainHash].nodeIndex = nodeIndex; _rotations[schainHash].newNodeIndex = newNodeIndex; _rotations[schainHash].rotationCounter++; _rotations[schainHash].previousNodes[newNodeIndex] = nodeIndex; diff --git a/contracts/Schains.sol b/contracts/Schains.sol index edc173c2..c31e1198 100644 --- a/contracts/Schains.sol +++ b/contracts/Schains.sol @@ -35,6 +35,7 @@ import { IWallets } from "@skalenetwork/skale-manager-interfaces/IWallets.sol"; import { Permissions } from "./Permissions.sol"; import { ConstantsHolder } from "./ConstantsHolder.sol"; import { G2Operations } from "./utils/fieldOperations/G2Operations.sol"; +import { SkaleDKG } from "./SkaleDKG.sol"; /** @@ -195,12 +196,18 @@ contract Schains is Permissions, ISchains { function restartSchainCreation(string calldata name) external override allow("SkaleManager") { INodeRotation nodeRotation = INodeRotation(contractManager.getContract("NodeRotation")); bytes32 schainHash = keccak256(abi.encodePacked(name)); - ISkaleDKG skaleDKG = ISkaleDKG(contractManager.getContract("SkaleDKG")); + SkaleDKG skaleDKG = SkaleDKG(contractManager.getContract("SkaleDKG")); require(!skaleDKG.isLastDKGSuccessful(schainHash), "DKG success"); ISchainsInternal schainsInternal = ISchainsInternal( contractManager.getContract("SchainsInternal")); require(schainsInternal.isAnyFreeNode(schainHash), "No free Nodes for new group formation"); - uint256 newNodeIndex = nodeRotation.selectNodeToGroup(schainHash); + uint256 newNodeIndex = nodeRotation.rotateNode( + skaleDKG.pendingToBeReplaced(schainHash), + schainHash, + false, + true + ); + skaleDKG.resetPendingToBeReplaced(schainHash); skaleDKG.openChannel(schainHash); emit NodeAdded(schainHash, newNodeIndex); } diff --git a/contracts/SkaleDKG.sol b/contracts/SkaleDKG.sol index 64487423..3475f027 100644 --- a/contracts/SkaleDKG.sol +++ b/contracts/SkaleDKG.sol @@ -71,6 +71,8 @@ contract SkaleDKG is Permissions, ISkaleDKG { mapping(bytes32 => uint256) private _badNodes; + mapping(bytes32 => uint256) public pendingToBeReplaced; + modifier correctGroup(bytes32 schainHash) { require(channels[schainHash].active, "Group is not created"); _; @@ -320,6 +322,10 @@ contract SkaleDKG is Permissions, ISkaleDKG { _badNodes[schainHash] = nodeIndex; } + function resetPendingToBeReplaced(bytes32 schainHash) external override allow("Schains") { + delete pendingToBeReplaced[schainHash]; + } + function finalizeSlashing(bytes32 schainHash, uint256 badNode) external override allow("SkaleDKG") { INodeRotation nodeRotation = INodeRotation(contractManager.getContract("NodeRotation")); ISchainsInternal schainsInternal = ISchainsInternal( @@ -328,24 +334,21 @@ contract SkaleDKG is Permissions, ISkaleDKG { emit BadGuy(badNode); emit FailedDKG(schainHash); - schainsInternal.makeSchainNodesInvisible(schainHash); if (schainsInternal.isAnyFreeNode(schainHash)) { + schainsInternal.makeSchainNodesInvisible(schainHash); uint256 newNode = nodeRotation.rotateNode( badNode, schainHash, false, true ); + schainsInternal.makeSchainNodesVisible(schainHash); emit NewGuy(newNode); } else { + pendingToBeReplaced[schainHash] = badNode; _openChannel(schainHash); - schainsInternal.removeNodeFromSchain( - badNode, - schainHash - ); channels[schainHash].active = false; } - schainsInternal.makeSchainNodesVisible(schainHash); IPunisher(contractManager.getPunisher()).slash( INodes(contractManager.getContract("Nodes")).getValidatorId(badNode), ISlashingTable(contractManager.getContract("SlashingTable")).getPenalty("FailedDKG") diff --git a/package.json b/package.json index 10a465c2..8626c18c 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@openzeppelin/contracts": "^4.9.3", "@openzeppelin/contracts-upgradeable": "^4.9.3", "@openzeppelin/hardhat-upgrades": "^1.14.0", - "@skalenetwork/skale-manager-interfaces": "2.1.0-develop.0", + "@skalenetwork/skale-manager-interfaces": "2.2.0-dkg-fix.0", "@skalenetwork/upgrade-tools": "^2.0.1", "@typechain/hardhat": "^7.0.0", "dotenv": "^16.3.1", diff --git a/test/SkaleDKG.ts b/test/SkaleDKG.ts index 6924264c..d186d0e4 100644 --- a/test/SkaleDKG.ts +++ b/test/SkaleDKG.ts @@ -1409,7 +1409,7 @@ describe("SkaleDKG", () => { badEncryptedSecretKeyContributions[indexes[0]] ) ); - + const response = await skaleDKG.connect(validators[0].nodeAddress).response( stringKeccak256(schainName), 0, @@ -1498,7 +1498,7 @@ describe("SkaleDKG", () => { ), "Broadcast 1" ); - + await reimbursed( await skaleDKG.connect(validators[1].nodeAddress).broadcast( stringKeccak256(schainName), @@ -1509,7 +1509,7 @@ describe("SkaleDKG", () => { ), "Broadcast 2" ); - + const complaintBadData = await skaleDKG.connect(validators[1].nodeAddress).complaintBadData( stringKeccak256(schainName), 1, @@ -1533,7 +1533,7 @@ describe("SkaleDKG", () => { ), "Pre response" ); - + const responseTx = await skaleDKG.connect(validators[0].nodeAddress).response( stringKeccak256(schainName), 0, @@ -1928,7 +1928,7 @@ describe("SkaleDKG", () => { ), "Alright" ); - + alrightPoss = await skaleDKG.connect(validators[index].nodeAddress).isAlrightPossible( stringKeccak256("New16NodeSchain"), i @@ -2381,7 +2381,7 @@ describe("SkaleDKG", () => { accusedNode ) ); - + const complaint = await skaleDKG.connect(validators[0].nodeAddress).complaint( stringKeccak256("New16NodeSchain"), 8, @@ -2454,8 +2454,8 @@ describe("SkaleDKG", () => { rotation.rotationCounter ); } - const accusedNode = "15"; - const complaintNode = "7"; + const accusedNode = 15; + const complaintNode = 7; await skipTime(1800); await reimbursed( await skaleDKG.connect(validators[0].nodeAddress).complaint( @@ -2465,7 +2465,8 @@ describe("SkaleDKG", () => { ) ); const space = await nodes.spaceOfNodes(accusedNode); - space.freeSpace.should.be.equal(128); + // The node is still a part of schain because can't be replaced + space.freeSpace.should.be.equal(0); const complaint = await skaleDKG.connect(validators[0].nodeAddress).complaint( stringKeccak256("New16NodeSchain"), @@ -2486,11 +2487,18 @@ describe("SkaleDKG", () => { domainName: "some.domain.name" } ); + const createdNode = 16; await schains.restartSchainCreation("New16NodeSchain"); + rotation = await nodeRotation.getRotation(stringKeccak256("New16NodeSchain")); + + expect(rotation.rotationCounter).to.be.equal(1); + expect(rotation.nodeIndex).to.be.equal(accusedNode); + expect(rotation.newNodeIndex).to.be.equal(createdNode); + for (let i = 0; i < 17; i++) { - if (i.toString() === accusedNode) { + if (i === accusedNode) { continue; } let index = 0; @@ -2507,7 +2515,7 @@ describe("SkaleDKG", () => { } let comPubKey; for (let i = 0; i < 17; i++) { - if (i.toString() === accusedNode) { + if (i === accusedNode) { continue; } comPubKey = await keyStorage.getCommonPublicKey(stringKeccak256("New16NodeSchain")); @@ -2605,7 +2613,7 @@ describe("SkaleDKG", () => { accusedNode ) ); - + const complaint = await skaleDKG.connect(validators[0].nodeAddress).complaint( stringKeccak256("New16NodeSchain"), 8, diff --git a/yarn.lock b/yarn.lock index cc10bbc9..4680075b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1752,10 +1752,10 @@ dependencies: "@sinonjs/commons" "^1.7.0" -"@skalenetwork/skale-manager-interfaces@2.1.0-develop.0": - version "2.1.0-develop.0" - resolved "https://registry.yarnpkg.com/@skalenetwork/skale-manager-interfaces/-/skale-manager-interfaces-2.1.0-develop.0.tgz#b762606fa45ef4c0daa481a644272dd35c77fefc" - integrity sha512-0RC+4yGSOSqRoYhGYza3UWwkaPyp09Xf2d+bzWrNeK0BgBXvDvRQ7KINHZLFtjfOGJ/sVy2WI22oPro2dVLw+g== +"@skalenetwork/skale-manager-interfaces@2.2.0-dkg-fix.0": + version "2.2.0-dkg-fix.0" + resolved "https://registry.yarnpkg.com/@skalenetwork/skale-manager-interfaces/-/skale-manager-interfaces-2.2.0-dkg-fix.0.tgz#79f0037253e17b5886599345c3f6be6eb7655b75" + integrity sha512-DQFTMAvQ4nvoNyq3TYQsGmZEpzkcTYfAvw3bgZZSTVA/5vGmCSLcqsdgUPqebpNPbQYsJ+YrrLppBilY93buyg== "@skalenetwork/upgrade-tools@^2.0.1": version "2.0.1" From 9b938551844b4bee7327da36ff34b052e576773a Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Thu, 18 Jan 2024 17:45:44 +0200 Subject: [PATCH 02/15] Update reimbursement constant --- contracts/ConstantsHolder.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/ConstantsHolder.sol b/contracts/ConstantsHolder.sol index f65f316f..1522716f 100644 --- a/contracts/ConstantsHolder.sol +++ b/contracts/ConstantsHolder.sol @@ -82,7 +82,7 @@ contract ConstantsHolder is Permissions, IConstantsHolder { uint256 public constant BROADCAST_DELTA = 177490; uint256 public constant COMPLAINT_BAD_DATA_DELTA = 80995; uint256 public constant PRE_RESPONSE_DELTA = 100061; - uint256 public constant COMPLAINT_DELTA = 106611; + uint256 public constant COMPLAINT_DELTA = 161464; uint256 public constant RESPONSE_DELTA = 48132; // MSR - Minimum staking requirement From ae5f6ecd2096f8f454a55a8ba25fc4d7e8ac46a0 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Thu, 18 Jan 2024 20:16:12 +0200 Subject: [PATCH 03/15] Fix isAnyFreeNode function --- contracts/BountyV2.sol | 2 +- contracts/ConstantsHolder.sol | 4 +-- contracts/ContractManager.sol | 5 ++++ contracts/NodeRotation.sol | 2 +- contracts/Nodes.sol | 32 +++++++++++++++++---- contracts/Permissions.sol | 44 +++++++++++++++++++++-------- contracts/Schains.sol | 8 +++--- contracts/SchainsInternal.sol | 53 +++++++++++++---------------------- contracts/SkaleDKG.sol | 4 +-- contracts/SkaleToken.sol | 2 +- contracts/Wallets.sol | 2 +- package.json | 2 +- test/SchainsInternal.ts | 7 ----- yarn.lock | 8 +++--- 14 files changed, 100 insertions(+), 75 deletions(-) diff --git a/contracts/BountyV2.sol b/contracts/BountyV2.sol index 1bcd1611..2bc6804d 100644 --- a/contracts/BountyV2.sol +++ b/contracts/BountyV2.sol @@ -83,7 +83,7 @@ contract BountyV2 is Permissions, IBountyV2 { function calculateBounty(uint256 nodeIndex) external override - allow("SkaleManager") + onlySkaleManager() returns (uint256 bounty) { ConstantsHolder constantsHolder = ConstantsHolder(contractManager.getContract("ConstantsHolder")); diff --git a/contracts/ConstantsHolder.sol b/contracts/ConstantsHolder.sol index 1522716f..4cc226b4 100644 --- a/contracts/ConstantsHolder.sol +++ b/contracts/ConstantsHolder.sol @@ -82,8 +82,8 @@ contract ConstantsHolder is Permissions, IConstantsHolder { uint256 public constant BROADCAST_DELTA = 177490; uint256 public constant COMPLAINT_BAD_DATA_DELTA = 80995; uint256 public constant PRE_RESPONSE_DELTA = 100061; - uint256 public constant COMPLAINT_DELTA = 161464; - uint256 public constant RESPONSE_DELTA = 48132; + uint256 public constant COMPLAINT_DELTA = 189562; + uint256 public constant RESPONSE_DELTA = 40312; // MSR - Minimum staking requirement uint256 public msr; diff --git a/contracts/ContractManager.sol b/contracts/ContractManager.sol index 2faa006b..4aba3577 100644 --- a/contracts/ContractManager.sol +++ b/contracts/ContractManager.sol @@ -41,6 +41,7 @@ contract ContractManager is InitializableWithGap, OwnableUpgradeable, IContractM string public constant CONSTANTS_HOLDER = "ConstantsHolder"; string public constant DELEGATION_PERIOD_MANAGER = "DelegationPeriodManager"; string public constant PUNISHER = "Punisher"; + string public constant SKALE_MANAGER = "SkaleManager"; string public constant SKALE_TOKEN = "SkaleToken"; string public constant TIME_HELPERS = "TimeHelpers"; string public constant TOKEN_STATE = "TokenState"; @@ -123,6 +124,10 @@ contract ContractManager is InitializableWithGap, OwnableUpgradeable, IContractM return getContract(PUNISHER); } + function getSkaleManager() external view override returns (address skaleManager) { + return getContract(SKALE_MANAGER); + } + function getContract(string memory name) public view override returns (address contractAddress) { contractAddress = contracts[keccak256(abi.encodePacked(name))]; if (contractAddress == address(0)) { diff --git a/contracts/NodeRotation.sol b/contracts/NodeRotation.sol index acd21fbf..55e24c34 100644 --- a/contracts/NodeRotation.sol +++ b/contracts/NodeRotation.sol @@ -97,7 +97,7 @@ contract NodeRotation is Permissions, INodeRotation { ) external override - allow("SkaleManager") + onlySkaleManager() returns (bool contains, bool successful) { ISchainsInternal schainsInternal = ISchainsInternal(contractManager.getContract("SchainsInternal")); diff --git a/contracts/Nodes.sol b/contracts/Nodes.sol index 65e7160b..7e3f53c9 100644 --- a/contracts/Nodes.sol +++ b/contracts/Nodes.sol @@ -177,7 +177,7 @@ contract Nodes is Permissions, INodes { external override checkNodeExists(nodeIndex) - allow("SkaleManager") + onlySkaleManager() { nodes[nodeIndex].lastRewardDate = block.timestamp; } @@ -189,7 +189,7 @@ contract Nodes is Permissions, INodes { external override checkNodeExists(nodeIndex) - allow("SkaleManager") + onlySkaleManager() { nodes[nodeIndex].finishTime = time; } @@ -210,7 +210,7 @@ contract Nodes is Permissions, INodes { function createNode(address from, NodeCreationParams calldata params) external override - allow("SkaleManager") + onlySkaleManager() nonZeroIP(params.ip) { // checks that Node has correct data @@ -292,7 +292,7 @@ contract Nodes is Permissions, INodes { external override checkNodeExists(nodeIndex) - allow("SkaleManager") + onlySkaleManager() returns (bool successful) { require(isNodeLeaving(nodeIndex), "Node is not Leaving"); @@ -314,7 +314,7 @@ contract Nodes is Permissions, INodes { external override checkNodeExists(nodeIndex) - allow("SkaleManager") + onlySkaleManager() { IValidatorService validatorService = IValidatorService(contractManager.getValidatorService()); require(validatorService.validatorExists(validatorId), "Validator ID does not exist"); @@ -348,7 +348,7 @@ contract Nodes is Permissions, INodes { * - Validator must be included on trusted list if trusted list is enabled. * - Validator must have sufficient stake to operate an additional node. */ - function checkPossibilityCreatingNode(address nodeAddress) external override allow("SkaleManager") { + function checkPossibilityCreatingNode(address nodeAddress) external override onlySkaleManager() { IValidatorService validatorService = IValidatorService(contractManager.getValidatorService()); uint256 validatorId = validatorService.getValidatorIdByNodeAddress(nodeAddress); require(validatorService.isAuthorizedValidator(validatorId), "Validator is not authorized to create a node"); @@ -732,6 +732,26 @@ contract Nodes is Permissions, INodes { return nodeExtras[nodeIndex].lastChangeIpTime; } + function isNodeVisible(uint256 nodeIndex) + external + view + override + checkNodeExists(nodeIndex) + returns (bool visible) + { + return !_invisible[nodeIndex]; + } + + function getFreeSpace(uint256 nodeIndex) + external + view + override + checkNodeExists(nodeIndex) + returns (uint8 freeSpace) + { + return spaceOfNodes[nodeIndex].freeSpace; + } + /** * @dev Returns the Validator ID for a given node. */ diff --git a/contracts/Permissions.sol b/contracts/Permissions.sol index b6fd25bd..988d08e2 100644 --- a/contracts/Permissions.sol +++ b/contracts/Permissions.sol @@ -37,6 +37,11 @@ contract Permissions is AccessControlUpgradeableLegacy, IPermissions { IContractManager public contractManager; + error MessageSenderIsInvalid(address sender); + error MessageSenderIsNotOwner(address sender); + error MessageSenderIsNotAdmin(address sender); + error MessageSenderIsNotSkaleManager(address sender); + /** * @dev Modifier to make a function callable only when caller is the Owner. * @@ -45,7 +50,9 @@ contract Permissions is AccessControlUpgradeableLegacy, IPermissions { * - The caller must be the owner. */ modifier onlyOwner() { - require(_isOwner(), "Caller is not the owner"); + if(!_isOwner()) { + revert MessageSenderIsNotOwner(msg.sender); + } _; } @@ -57,7 +64,9 @@ contract Permissions is AccessControlUpgradeableLegacy, IPermissions { * - The caller must be an admin. */ modifier onlyAdmin() { - require(_isAdmin(msg.sender), "Caller is not an admin"); + if(!_isAdmin(msg.sender)) { + revert MessageSenderIsNotAdmin(msg.sender); + } _; } @@ -70,9 +79,10 @@ contract Permissions is AccessControlUpgradeableLegacy, IPermissions { * - The caller must be the owner or `contractName`. */ modifier allow(string memory contractName) { - require( - contractManager.getContract(contractName) == msg.sender || _isOwner(), - "Message sender is invalid"); + if(!(contractManager.getContract(contractName) == msg.sender || _isOwner())) + { + revert MessageSenderIsInvalid(msg.sender); + } _; } @@ -85,11 +95,13 @@ contract Permissions is AccessControlUpgradeableLegacy, IPermissions { * - The caller must be the owner, `contractName1`, or `contractName2`. */ modifier allowTwo(string memory contractName1, string memory contractName2) { - require( + if(!( contractManager.getContract(contractName1) == msg.sender || contractManager.getContract(contractName2) == msg.sender || - _isOwner(), - "Message sender is invalid"); + _isOwner())) + { + revert MessageSenderIsInvalid(msg.sender); + } _; } @@ -103,12 +115,22 @@ contract Permissions is AccessControlUpgradeableLegacy, IPermissions { * `contractName3`. */ modifier allowThree(string memory contractName1, string memory contractName2, string memory contractName3) { - require( + if(!( contractManager.getContract(contractName1) == msg.sender || contractManager.getContract(contractName2) == msg.sender || contractManager.getContract(contractName3) == msg.sender || - _isOwner(), - "Message sender is invalid"); + _isOwner())) + { + revert MessageSenderIsInvalid(msg.sender); + } + _; + } + + modifier onlySkaleManager() { + if(!(contractManager.getSkaleManager() == msg.sender || _isOwner())) + { + revert MessageSenderIsNotSkaleManager(msg.sender); + } _; } diff --git a/contracts/Schains.sol b/contracts/Schains.sol index c31e1198..7004bea2 100644 --- a/contracts/Schains.sol +++ b/contracts/Schains.sol @@ -83,7 +83,7 @@ contract Schains is Permissions, ISchains { * - There is sufficient deposit to create type of schain. * - If from is a smart contract originator must be specified */ - function addSchain(address from, uint256 deposit, bytes calldata data) external override allow("SkaleManager") { + function addSchain(address from, uint256 deposit, bytes calldata data) external override onlySkaleManager() { SchainParameters memory schainParameters = abi.decode(data, (SchainParameters)); ConstantsHolder constantsHolder = ConstantsHolder(contractManager.getConstantsHolder()); uint256 schainCreationTimeStamp = constantsHolder.schainCreationTimeStamp(); @@ -156,7 +156,7 @@ contract Schains is Permissions, ISchains { * * - Executed by schain owner. */ - function deleteSchain(address from, string calldata name) external override allow("SkaleManager") { + function deleteSchain(address from, string calldata name) external override onlySkaleManager() { ISchainsInternal schainsInternal = ISchainsInternal(contractManager.getContract("SchainsInternal")); bytes32 schainHash = keccak256(abi.encodePacked(name)); require( @@ -177,7 +177,7 @@ contract Schains is Permissions, ISchains { * * - Schain exists. */ - function deleteSchainByRoot(string calldata name) external override allow("SkaleManager") { + function deleteSchainByRoot(string calldata name) external override onlySkaleManager() { _deleteSchain(name, ISchainsInternal(contractManager.getContract("SchainsInternal"))); } @@ -193,7 +193,7 @@ contract Schains is Permissions, ISchains { * - DKG failure got stuck because there were no free nodes to rotate in. * - A free node must be released in the network. */ - function restartSchainCreation(string calldata name) external override allow("SkaleManager") { + function restartSchainCreation(string calldata name) external override onlySkaleManager() { INodeRotation nodeRotation = INodeRotation(contractManager.getContract("NodeRotation")); bytes32 schainHash = keccak256(abi.encodePacked(name)); SkaleDKG skaleDKG = SkaleDKG(contractManager.getContract("SkaleDKG")); diff --git a/contracts/SchainsInternal.sol b/contracts/SchainsInternal.sol index 32e5c1ac..24cf72cf 100644 --- a/contracts/SchainsInternal.sol +++ b/contracts/SchainsInternal.sol @@ -24,13 +24,14 @@ pragma solidity 0.8.17; import { EnumerableSetUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol"; -import { ISkaleDKG } from "@skalenetwork/skale-manager-interfaces/ISkaleDKG.sol"; import { INodes } from "@skalenetwork/skale-manager-interfaces/INodes.sol"; +import { ISkaleDKG } from "@skalenetwork/skale-manager-interfaces/ISkaleDKG.sol"; -import { IPruningSchainsInternal } from "./interfaces/IPruningSchainInternal.sol"; -import { Permissions } from "./Permissions.sol"; import { ConstantsHolder } from "./ConstantsHolder.sol"; +import { IPruningSchainsInternal } from "./interfaces/IPruningSchainInternal.sol"; import { IRandom, Random } from "./utils/Random.sol"; +import { Nodes } from "./Nodes.sol"; +import { Permissions } from "./Permissions.sol"; /** @@ -182,29 +183,6 @@ contract SchainsInternal is Permissions, IPruningSchainsInternal { return _generateGroup(schainHash, numberOfNodes); } - /** - * @dev Allows Schains contract to change the Schain lifetime through - * an additional SKL token deposit. - * - * Requirements: - * - * - Message sender is Schains smart contract - * - Schain must exist - */ - function changeLifetime( - bytes32 schainHash, - uint256 lifetime, - uint256 deposit - ) - external - override - allow("Schains") - schainExists(schainHash) - { - schains[schainHash].deposit = schains[schainHash].deposit + deposit; - schains[schainHash].lifetime = schains[schainHash].lifetime + lifetime; - } - /** * @dev Allows Schains contract to remove an schain from the network. * Generally schains are not removed from the system; instead they are @@ -281,7 +259,7 @@ contract SchainsInternal is Permissions, IPruningSchainsInternal { removeSchainForNode(nodeIndex, placeOfSchainOnNode[schainHash][nodeIndex] - 1); delete placeOfSchainOnNode[schainHash][nodeIndex]; - INodes nodes = INodes(contractManager.getContract("Nodes")); + Nodes nodes = Nodes(contractManager.getContract("Nodes")); require(_removeAddressFromSchain(schainHash, nodes.getNodeAddress(nodeIndex)), "Incorrect node address"); nodes.addSpaceToNode(nodeIndex, schains[schainHash].partOfNode); } @@ -403,7 +381,7 @@ contract SchainsInternal is Permissions, IPruningSchainsInternal { numberOfSchainTypes = newNumberOfSchainTypes; } - function removeNodeFromAllExceptionSchains(uint256 nodeIndex) external override allow("SkaleManager") { + function removeNodeFromAllExceptionSchains(uint256 nodeIndex) external override onlySkaleManager() { uint256 len = _nodeToLockedSchains[nodeIndex].length; for (uint256 i = len; i > 0; i--) { removeNodeFromExceptions(_nodeToLockedSchains[nodeIndex][i - 1], nodeIndex); @@ -437,7 +415,7 @@ contract SchainsInternal is Permissions, IPruningSchainsInternal { allowTwo("NodeRotation", "SkaleDKG") schainExists(schainHash) { - INodes nodes = INodes(contractManager.getContract("Nodes")); + Nodes nodes = Nodes(contractManager.getContract("Nodes")); for (uint256 i = 0; i < _schainToExceptionNodes[schainHash].length; i++) { nodes.makeNodeInvisible(_schainToExceptionNodes[schainHash][i]); } @@ -755,9 +733,18 @@ contract SchainsInternal is Permissions, IPruningSchainsInternal { * - Schain must exist */ function isAnyFreeNode(bytes32 schainHash) external view override schainExists(schainHash) returns (bool free) { - INodes nodes = INodes(contractManager.getContract("Nodes")); + // TODO: + // Move this function to Nodes? + Nodes nodes = Nodes(contractManager.getContract("Nodes")); uint8 space = schains[schainHash].partOfNode; - return nodes.countNodesWithFreeSpace(space) > 0; + uint256 numberOfCandidates = nodes.countNodesWithFreeSpace(space); + for (uint256 i = 0; i < _schainToExceptionNodes[schainHash].length; i++) { + uint256 nodeIndex = _schainToExceptionNodes[schainHash][i]; + if (space <= nodes.getFreeSpace(nodeIndex) && nodes.isNodeVisible(nodeIndex)) { + --numberOfCandidates; + } + } + return numberOfCandidates > 0; } /** @@ -979,7 +966,7 @@ contract SchainsInternal is Permissions, IPruningSchainsInternal { * @dev Generates schain group using a pseudo-random generator. */ function _generateGroup(bytes32 schainHash, uint256 numberOfNodes) private returns (uint256[] memory nodesInGroup) { - INodes nodes = INodes(contractManager.getContract("Nodes")); + Nodes nodes = Nodes(contractManager.getContract("Nodes")); uint8 space = schains[schainHash].partOfNode; nodesInGroup = new uint256[](numberOfNodes); @@ -1007,7 +994,7 @@ contract SchainsInternal is Permissions, IPruningSchainsInternal { } function _makeSchainNodesVisible(bytes32 schainHash) private { - INodes nodes = INodes(contractManager.getContract("Nodes")); + Nodes nodes = Nodes(contractManager.getContract("Nodes")); for (uint256 i = 0; i < _schainToExceptionNodes[schainHash].length; i++) { nodes.makeNodeVisible(_schainToExceptionNodes[schainHash][i]); } diff --git a/contracts/SkaleDKG.sol b/contracts/SkaleDKG.sol index 3475f027..a1b6ea24 100644 --- a/contracts/SkaleDKG.sol +++ b/contracts/SkaleDKG.sol @@ -335,14 +335,12 @@ contract SkaleDKG is Permissions, ISkaleDKG { emit FailedDKG(schainHash); if (schainsInternal.isAnyFreeNode(schainHash)) { - schainsInternal.makeSchainNodesInvisible(schainHash); uint256 newNode = nodeRotation.rotateNode( badNode, schainHash, false, true ); - schainsInternal.makeSchainNodesVisible(schainHash); emit NewGuy(newNode); } else { pendingToBeReplaced[schainHash] = badNode; @@ -598,7 +596,7 @@ contract SkaleDKG is Permissions, ISkaleDKG { ); } else if (context.dkgFunction == DkgFunction.Response){ wallets.refundGasBySchain( - schainHash, payable(msg.sender), gasTotal - gasleft() - context.delta, context.isDebt + schainHash, payable(msg.sender), gasTotal - gasleft() + context.delta, context.isDebt ); } else { wallets.refundGasBySchain( diff --git a/contracts/SkaleToken.sol b/contracts/SkaleToken.sol index 5e25bb66..7ddb6994 100644 --- a/contracts/SkaleToken.sol +++ b/contracts/SkaleToken.sol @@ -74,7 +74,7 @@ contract SkaleToken is ERC777, Permissions, ReentrancyGuard, IDelegatableToken, ) external override - allow("SkaleManager") + onlySkaleManager() //onlyAuthorized returns (bool successful) { diff --git a/contracts/Wallets.sol b/contracts/Wallets.sol index 38dec0fa..05e16c93 100644 --- a/contracts/Wallets.sol +++ b/contracts/Wallets.sol @@ -127,7 +127,7 @@ contract Wallets is Permissions, IWallets { ) external override - allow("SkaleManager") + onlySkaleManager() { require(spender != address(0), "Spender must be specified"); require(validatorId != 0, "ValidatorId could not be zero"); diff --git a/package.json b/package.json index 8626c18c..bc1d9ab5 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@openzeppelin/contracts": "^4.9.3", "@openzeppelin/contracts-upgradeable": "^4.9.3", "@openzeppelin/hardhat-upgrades": "^1.14.0", - "@skalenetwork/skale-manager-interfaces": "2.2.0-dkg-fix.0", + "@skalenetwork/skale-manager-interfaces": "^2.2.0-dkg-fix.3", "@skalenetwork/upgrade-tools": "^2.0.1", "@typechain/hardhat": "^7.0.0", "dotenv": "^16.3.1", diff --git a/test/SchainsInternal.ts b/test/SchainsInternal.ts index ba8b20c7..12e85dbf 100644 --- a/test/SchainsInternal.ts +++ b/test/SchainsInternal.ts @@ -143,13 +143,6 @@ describe("SchainsInternal", () => { totalResources.should.be.equal(64); }); - it("should change schain lifetime", async () => { - await schainsInternal.changeLifetime(schainNameHash, 7, 8); - const schain = await schainsInternal.schains(schainNameHash); - schain.lifetime.should.be.equal(12); - schain.deposit.should.be.equal(13); - }); - describe("on registered schain", () => { const nodeIndex = 0; const numberOfNewSchains = 5 diff --git a/yarn.lock b/yarn.lock index 4680075b..08c6ce4a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1752,10 +1752,10 @@ dependencies: "@sinonjs/commons" "^1.7.0" -"@skalenetwork/skale-manager-interfaces@2.2.0-dkg-fix.0": - version "2.2.0-dkg-fix.0" - resolved "https://registry.yarnpkg.com/@skalenetwork/skale-manager-interfaces/-/skale-manager-interfaces-2.2.0-dkg-fix.0.tgz#79f0037253e17b5886599345c3f6be6eb7655b75" - integrity sha512-DQFTMAvQ4nvoNyq3TYQsGmZEpzkcTYfAvw3bgZZSTVA/5vGmCSLcqsdgUPqebpNPbQYsJ+YrrLppBilY93buyg== +"@skalenetwork/skale-manager-interfaces@^2.2.0-dkg-fix.3": + version "2.2.0-dkg-fix.3" + resolved "https://registry.yarnpkg.com/@skalenetwork/skale-manager-interfaces/-/skale-manager-interfaces-2.2.0-dkg-fix.3.tgz#3e5d7b0b96716e8cce7052d6b819ef73786211aa" + integrity sha512-pbhe/iOeM1naHQABbD4NpWYXUVg9MFUwwuMqmgIsby0lK8cgbgXZ5egKaoHNSqSo0Jj2hsi8LxOlaL6xjejiRg== "@skalenetwork/upgrade-tools@^2.0.1": version "2.0.1" From 1f1b51231673a3f3c25aeb6537ba57c218f5383e Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Fri, 19 Jan 2024 18:30:09 +0200 Subject: [PATCH 04/15] Fix NodesFunctionality tests --- dictionaries/libraries.txt | 1 + hardhat.config.ts | 2 +- package.json | 4 ++- test/NodesFunctionality.ts | 12 ++++++--- yarn.lock | 51 ++++++++++++++++++++++---------------- 5 files changed, 43 insertions(+), 27 deletions(-) diff --git a/dictionaries/libraries.txt b/dictionaries/libraries.txt index 840b6da0..f4d45d39 100644 --- a/dictionaries/libraries.txt +++ b/dictionaries/libraries.txt @@ -21,6 +21,7 @@ mulmod muln nbconvert nbformat +nomicfoundation nomiclabs pygments pyplot diff --git a/hardhat.config.ts b/hardhat.config.ts index 5a24e312..00043614 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -1,6 +1,6 @@ import { task, HardhatUserConfig } from "hardhat/config"; +import "@nomicfoundation/hardhat-chai-matchers"; import "@nomiclabs/hardhat-etherscan"; -import "@nomiclabs/hardhat-waffle"; import "@openzeppelin/hardhat-upgrades"; import '@typechain/hardhat' import "solidity-coverage"; diff --git a/package.json b/package.json index bc1d9ab5..78d0b1be 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "@openzeppelin/contracts": "^4.9.3", "@openzeppelin/contracts-upgradeable": "^4.9.3", "@openzeppelin/hardhat-upgrades": "^1.14.0", + "@openzeppelin/upgrades-core": "^1.27.0", "@skalenetwork/skale-manager-interfaces": "^2.2.0-dkg-fix.3", "@skalenetwork/upgrade-tools": "^2.0.1", "@typechain/hardhat": "^7.0.0", @@ -53,8 +54,8 @@ "hardhat": "2.11.0 - 2.16.1" }, "devDependencies": { + "@nomicfoundation/hardhat-chai-matchers": "<2.0.0", "@nomiclabs/hardhat-etherscan": "^3.1.0", - "@nomiclabs/hardhat-waffle": "^2.0.2", "@typechain/ethers-v5": "^11.1.1", "@types/chai": "^4.3.6", "@types/chai-almost": "^1.0.1", @@ -64,6 +65,7 @@ "@types/mocha": "^9.1.1", "@types/node": "^20.8.7", "@types/sinon-chai": "^3.2.9", + "@types/underscore": "^1.11.15", "@typescript-eslint/eslint-plugin": "^5.62.0", "@typescript-eslint/parser": "^5.62.0", "bignumber.js": "^9.1.2", diff --git a/test/NodesFunctionality.ts b/test/NodesFunctionality.ts index 3b434318..63719d5f 100644 --- a/test/NodesFunctionality.ts +++ b/test/NodesFunctionality.ts @@ -180,7 +180,9 @@ describe("NodesFunctionality", () => { }); it("should change IP", async () => { - await nodes.connect(holder).changeIP(0, "0x7f000001", "0x00000000").should.be.eventually.rejectedWith("Caller is not an admin"); + await expect(nodes.connect(holder).changeIP(0, "0x7f000001", "0x00000000")) + .to.be.revertedWithCustomError(nodes, "MessageSenderIsNotAdmin") + .withArgs(holder.address); await nodes.connect(owner).changeIP(0, "0x7f000001", "0x00000000").should.be.eventually.rejectedWith("IP address is zero or is not available"); await nodes.connect(owner).changeIP(0, "0x00000000", "0x00000000").should.be.eventually.rejectedWith("IP address is zero or is not available"); await nodes.connect(owner).changeIP(0, "0x7f000002", "0x7f000001").should.be.eventually.rejectedWith("IP address is not the same"); @@ -302,12 +304,16 @@ describe("NodesFunctionality", () => { }); it("should change IP", async () => { - await nodes.connect(holder).changeIP(0, "0x7f000001", "0x00000000").should.be.eventually.rejectedWith("Caller is not an admin"); + await expect(nodes.connect(holder).changeIP(0, "0x7f000001", "0x00000000")) + .to.be.revertedWithCustomError(nodes, "MessageSenderIsNotAdmin") + .withArgs(holder.address); await nodes.connect(owner).changeIP(0, "0x7f000001", "0x00000000").should.be.eventually.rejectedWith("IP address is zero or is not available"); await nodes.connect(owner).changeIP(0, "0x00000000", "0x00000000").should.be.eventually.rejectedWith("IP address is zero or is not available"); await nodes.connect(owner).changeIP(0, "0x7f000002", "0x00000000").should.be.eventually.rejectedWith("IP address is zero or is not available"); await nodes.connect(owner).changeIP(0, "0x7f000003", "0x7f000002").should.be.eventually.rejectedWith("IP address is not the same"); - await nodes.connect(holder).changeIP(1, "0x7f000002", "0x00000000").should.be.eventually.rejectedWith("Caller is not an admin"); + await expect(nodes.connect(holder).changeIP(1, "0x7f000002", "0x00000000")) + .to.be.revertedWithCustomError(nodes, "MessageSenderIsNotAdmin") + .withArgs(holder.address); await nodes.connect(owner).changeIP(1, "0x7f000002", "0x00000000").should.be.eventually.rejectedWith("IP address is zero or is not available"); await nodes.connect(owner).changeIP(1, "0x00000000", "0x00000000").should.be.eventually.rejectedWith("IP address is zero or is not available"); await nodes.connect(owner).changeIP(1, "0x7f000001", "0x00000000").should.be.eventually.rejectedWith("IP address is zero or is not available"); diff --git a/yarn.lock b/yarn.lock index 08c6ce4a..31f5f07c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1287,6 +1287,17 @@ mcl-wasm "^0.7.1" rustbn.js "~0.2.0" +"@nomicfoundation/hardhat-chai-matchers@<2.0.0": + version "1.0.6" + resolved "https://registry.yarnpkg.com/@nomicfoundation/hardhat-chai-matchers/-/hardhat-chai-matchers-1.0.6.tgz#72a2e312e1504ee5dd73fe302932736432ba96bc" + integrity sha512-f5ZMNmabZeZegEfuxn/0kW+mm7+yV7VNDxLpMOMGXWFJ2l/Ct3QShujzDRF9cOkK9Ui/hbDeOWGZqyQALDXVCQ== + dependencies: + "@ethersproject/abi" "^5.1.2" + "@types/chai-as-promised" "^7.1.3" + chai-as-promised "^7.1.1" + deep-eql "^4.0.1" + ordinal "^1.0.3" + "@nomicfoundation/solidity-analyzer-darwin-arm64@0.1.1": version "0.1.1" resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-darwin-arm64/-/solidity-analyzer-darwin-arm64-0.1.1.tgz#4c858096b1c17fe58a474fe81b46815f93645c15" @@ -1374,14 +1385,6 @@ table "^6.8.0" undici "^5.14.0" -"@nomiclabs/hardhat-waffle@^2.0.2": - version "2.0.2" - resolved "https://registry.yarnpkg.com/@nomiclabs/hardhat-waffle/-/hardhat-waffle-2.0.2.tgz#6030aa6fd9ea05327bf79d1107356af906d8b1e4" - integrity sha512-dnhry6Bj15O8L3pBksTuXfr4RAUIf+BxRxWJXiu+ioSawcQaOcNF4gfMxn6ik0auk3zrsAJLA6m9vqe87d4xvg== - dependencies: - "@types/sinon-chai" "^3.2.3" - "@types/web3" "1.0.19" - "@oclif/command@^1.8.0": version "1.8.16" resolved "https://registry.yarnpkg.com/@oclif/command/-/command-1.8.16.tgz#bea46f81b2061b47e1cda318a0b923e62ca4cc0c" @@ -1854,6 +1857,13 @@ dependencies: "@types/chai" "*" +"@types/chai-as-promised@^7.1.3": + version "7.1.8" + resolved "https://registry.yarnpkg.com/@types/chai-as-promised/-/chai-as-promised-7.1.8.tgz#f2b3d82d53c59626b5d6bbc087667ccb4b677fe9" + integrity sha512-ThlRVIJhr69FLlh6IctTXFkmhtP3NpMZ2QGq69StYLyKZFp/HOp1VdKZj7RvfNWYYcJ1xlbLGLLWj1UvP5u/Gw== + dependencies: + "@types/chai" "*" + "@types/chai-as-promised@^7.1.6": version "7.1.6" resolved "https://registry.yarnpkg.com/@types/chai-as-promised/-/chai-as-promised-7.1.6.tgz#3b08cbe1e7206567a480dc6538bade374b19e4e1" @@ -1979,7 +1989,7 @@ resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.1.tgz#0480eeb7221eb9bc398ad7432c9d7e14b1a5a367" integrity sha512-cJRQXpObxfNKkFAZbJl2yjWtJCqELQIdShsogr1d2MilP8dKD9TE/nEKHkJgUNHdGKCQaf9HbIynuV2csLGVLg== -"@types/sinon-chai@^3.2.3", "@types/sinon-chai@^3.2.9": +"@types/sinon-chai@^3.2.9": version "3.2.9" resolved "https://registry.yarnpkg.com/@types/sinon-chai/-/sinon-chai-3.2.9.tgz#71feb938574bbadcb176c68e5ff1a6014c5e69d4" integrity sha512-/19t63pFYU0ikrdbXKBWj9PCdnKyTd0Qkz0X91Ta081cYsq90OxYdcWwK/dwEoDa6dtXgj2HJfmzgq+QZTHdmQ== @@ -1994,18 +2004,10 @@ dependencies: "@sinonjs/fake-timers" "^7.1.0" -"@types/underscore@*": - version "1.11.4" - resolved "https://registry.yarnpkg.com/@types/underscore/-/underscore-1.11.4.tgz#62e393f8bc4bd8a06154d110c7d042a93751def3" - integrity sha512-uO4CD2ELOjw8tasUrAhvnn2W4A0ZECOvMjCivJr4gA9pGgjv+qxKWY9GLTMVEK8ej85BxQOocUyE7hImmSQYcg== - -"@types/web3@1.0.19": - version "1.0.19" - resolved "https://registry.yarnpkg.com/@types/web3/-/web3-1.0.19.tgz#46b85d91d398ded9ab7c85a5dd57cb33ac558924" - integrity sha512-fhZ9DyvDYDwHZUp5/STa9XW2re0E8GxoioYJ4pEUZ13YHpApSagixj7IAdoYH5uAK+UalGq6Ml8LYzmgRA/q+A== - dependencies: - "@types/bn.js" "*" - "@types/underscore" "*" +"@types/underscore@^1.11.15": + version "1.11.15" + resolved "https://registry.yarnpkg.com/@types/underscore/-/underscore-1.11.15.tgz#29c776daecf6f1935da9adda17509686bf979947" + integrity sha512-HP38xE+GuWGlbSRq9WrZkousaQ7dragtZCruBVMi0oX1migFZavZ3OROKHSkNp/9ouq82zrWtZpg18jFnVN96g== "@typescript-eslint/eslint-plugin@^5.62.0": version "5.62.0" @@ -4325,7 +4327,7 @@ deep-eql@^2.0.2: dependencies: type-detect "^3.0.0" -deep-eql@^4.1.2: +deep-eql@^4.0.1, deep-eql@^4.1.2: version "4.1.3" resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-4.1.3.tgz#7c7775513092f7df98d8df9996dd085eb668cc6d" integrity sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw== @@ -8577,6 +8579,11 @@ optionator@^0.9.3: prelude-ls "^1.2.1" type-check "^0.4.0" +ordinal@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/ordinal/-/ordinal-1.0.3.tgz#1a3c7726a61728112f50944ad7c35c06ae3a0d4d" + integrity sha512-cMddMgb2QElm8G7vdaa02jhUNbTSrhsgAGUz1OokD83uJTwSUn+nKoNoKVVaRa08yF6sgfO7Maou1+bgLd9rdQ== + os-homedir@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3" From ef1e0c34fc48d210b13c8a4db99052dd68ec8477 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Fri, 19 Jan 2024 18:33:37 +0200 Subject: [PATCH 05/15] Remove reference to @openzeppelin/upgrades-core --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 78d0b1be..fa07952c 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "@openzeppelin/contracts": "^4.9.3", "@openzeppelin/contracts-upgradeable": "^4.9.3", "@openzeppelin/hardhat-upgrades": "^1.14.0", - "@openzeppelin/upgrades-core": "^1.27.0", "@skalenetwork/skale-manager-interfaces": "^2.2.0-dkg-fix.3", "@skalenetwork/upgrade-tools": "^2.0.1", "@typechain/hardhat": "^7.0.0", From d7829ce077c2b3fba6868f678d12fb133014a82f Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Fri, 19 Jan 2024 19:10:47 +0200 Subject: [PATCH 06/15] Fix SkaleManager tests --- test/SkaleManager.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/SkaleManager.ts b/test/SkaleManager.ts index 9ce22719..5fca828f 100644 --- a/test/SkaleManager.ts +++ b/test/SkaleManager.ts @@ -1,4 +1,5 @@ import * as chai from "chai"; +import { expect } from "chai"; import chaiAsPromised from "chai-as-promised"; import { ConstantsHolder, ContractManager, @@ -121,14 +122,15 @@ describe("SkaleManager", () => { }); it("should fail to process token fallback if sent not from SkaleToken", async () => { - await skaleManager.connect(validator).tokensReceived( + await expect(skaleManager.connect(validator).tokensReceived( hacker.address, validator.address, developer.address, 5, "0x11", "0x11" - ).should.be.eventually.rejectedWith("Message sender is invalid"); + )).to.be.revertedWithCustomError(skaleManager, "MessageSenderIsInvalid") + .withArgs(validator.address); }); it("should transfer ownership", async () => { @@ -141,8 +143,9 @@ describe("SkaleManager", () => { }); it("should allow only owner to set a version", async () => { - await skaleManager.connect(hacker).setVersion("bad") - .should.be.eventually.rejectedWith("Caller is not the owner"); + await expect(skaleManager.connect(hacker).setVersion("bad")) + .to.be.revertedWithCustomError(skaleManager, "MessageSenderIsNotOwner") + .withArgs(hacker.address); await skaleManager.setVersion("good"); (await skaleManager.version()).should.be.equal("good"); From 88cb28cbe40df8ebc648995a10fe4c7791c9c1ba Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Fri, 19 Jan 2024 19:44:39 +0200 Subject: [PATCH 07/15] Update COMPLAINT_DELTA --- contracts/ConstantsHolder.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/ConstantsHolder.sol b/contracts/ConstantsHolder.sol index 4cc226b4..6c896a6a 100644 --- a/contracts/ConstantsHolder.sol +++ b/contracts/ConstantsHolder.sol @@ -82,7 +82,7 @@ contract ConstantsHolder is Permissions, IConstantsHolder { uint256 public constant BROADCAST_DELTA = 177490; uint256 public constant COMPLAINT_BAD_DATA_DELTA = 80995; uint256 public constant PRE_RESPONSE_DELTA = 100061; - uint256 public constant COMPLAINT_DELTA = 189562; + uint256 public constant COMPLAINT_DELTA = 203048; uint256 public constant RESPONSE_DELTA = 40312; // MSR - Minimum staking requirement From 43d5ccf1c568b1670fe108474939074dda80773a Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Tue, 23 Jan 2024 16:34:57 +0200 Subject: [PATCH 08/15] Update response gas constant --- contracts/ConstantsHolder.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/ConstantsHolder.sol b/contracts/ConstantsHolder.sol index 6c896a6a..bc9d3337 100644 --- a/contracts/ConstantsHolder.sol +++ b/contracts/ConstantsHolder.sol @@ -81,9 +81,9 @@ contract ConstantsHolder is Permissions, IConstantsHolder { uint256 public constant ALRIGHT_DELTA = 134161; uint256 public constant BROADCAST_DELTA = 177490; uint256 public constant COMPLAINT_BAD_DATA_DELTA = 80995; - uint256 public constant PRE_RESPONSE_DELTA = 100061; + uint256 public constant PRE_RESPONSE_DELTA = 114511; uint256 public constant COMPLAINT_DELTA = 203048; - uint256 public constant RESPONSE_DELTA = 40312; + uint256 public constant RESPONSE_DELTA = 54762; // MSR - Minimum staking requirement uint256 public msr; From 801238fd0f11b1bfdace5eb9d6d0a095e05e0c5f Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Wed, 24 Jan 2024 16:54:13 +0200 Subject: [PATCH 09/15] Revert changes in Permissions --- contracts/BountyV2.sol | 2 +- contracts/NodeRotation.sol | 2 +- contracts/Nodes.sol | 12 +++++----- contracts/Permissions.sol | 44 +++++++++-------------------------- contracts/Schains.sol | 8 +++---- contracts/SchainsInternal.sol | 2 +- contracts/SkaleToken.sol | 2 +- contracts/Wallets.sol | 2 +- 8 files changed, 26 insertions(+), 48 deletions(-) diff --git a/contracts/BountyV2.sol b/contracts/BountyV2.sol index 2bc6804d..1bcd1611 100644 --- a/contracts/BountyV2.sol +++ b/contracts/BountyV2.sol @@ -83,7 +83,7 @@ contract BountyV2 is Permissions, IBountyV2 { function calculateBounty(uint256 nodeIndex) external override - onlySkaleManager() + allow("SkaleManager") returns (uint256 bounty) { ConstantsHolder constantsHolder = ConstantsHolder(contractManager.getContract("ConstantsHolder")); diff --git a/contracts/NodeRotation.sol b/contracts/NodeRotation.sol index 55e24c34..acd21fbf 100644 --- a/contracts/NodeRotation.sol +++ b/contracts/NodeRotation.sol @@ -97,7 +97,7 @@ contract NodeRotation is Permissions, INodeRotation { ) external override - onlySkaleManager() + allow("SkaleManager") returns (bool contains, bool successful) { ISchainsInternal schainsInternal = ISchainsInternal(contractManager.getContract("SchainsInternal")); diff --git a/contracts/Nodes.sol b/contracts/Nodes.sol index 7e3f53c9..7b899c7b 100644 --- a/contracts/Nodes.sol +++ b/contracts/Nodes.sol @@ -177,7 +177,7 @@ contract Nodes is Permissions, INodes { external override checkNodeExists(nodeIndex) - onlySkaleManager() + allow("SkaleManager") { nodes[nodeIndex].lastRewardDate = block.timestamp; } @@ -189,7 +189,7 @@ contract Nodes is Permissions, INodes { external override checkNodeExists(nodeIndex) - onlySkaleManager() + allow("SkaleManager") { nodes[nodeIndex].finishTime = time; } @@ -210,7 +210,7 @@ contract Nodes is Permissions, INodes { function createNode(address from, NodeCreationParams calldata params) external override - onlySkaleManager() + allow("SkaleManager") nonZeroIP(params.ip) { // checks that Node has correct data @@ -292,7 +292,7 @@ contract Nodes is Permissions, INodes { external override checkNodeExists(nodeIndex) - onlySkaleManager() + allow("SkaleManager") returns (bool successful) { require(isNodeLeaving(nodeIndex), "Node is not Leaving"); @@ -314,7 +314,7 @@ contract Nodes is Permissions, INodes { external override checkNodeExists(nodeIndex) - onlySkaleManager() + allow("SkaleManager") { IValidatorService validatorService = IValidatorService(contractManager.getValidatorService()); require(validatorService.validatorExists(validatorId), "Validator ID does not exist"); @@ -348,7 +348,7 @@ contract Nodes is Permissions, INodes { * - Validator must be included on trusted list if trusted list is enabled. * - Validator must have sufficient stake to operate an additional node. */ - function checkPossibilityCreatingNode(address nodeAddress) external override onlySkaleManager() { + function checkPossibilityCreatingNode(address nodeAddress) external override allow("SkaleManager") { IValidatorService validatorService = IValidatorService(contractManager.getValidatorService()); uint256 validatorId = validatorService.getValidatorIdByNodeAddress(nodeAddress); require(validatorService.isAuthorizedValidator(validatorId), "Validator is not authorized to create a node"); diff --git a/contracts/Permissions.sol b/contracts/Permissions.sol index 988d08e2..b6fd25bd 100644 --- a/contracts/Permissions.sol +++ b/contracts/Permissions.sol @@ -37,11 +37,6 @@ contract Permissions is AccessControlUpgradeableLegacy, IPermissions { IContractManager public contractManager; - error MessageSenderIsInvalid(address sender); - error MessageSenderIsNotOwner(address sender); - error MessageSenderIsNotAdmin(address sender); - error MessageSenderIsNotSkaleManager(address sender); - /** * @dev Modifier to make a function callable only when caller is the Owner. * @@ -50,9 +45,7 @@ contract Permissions is AccessControlUpgradeableLegacy, IPermissions { * - The caller must be the owner. */ modifier onlyOwner() { - if(!_isOwner()) { - revert MessageSenderIsNotOwner(msg.sender); - } + require(_isOwner(), "Caller is not the owner"); _; } @@ -64,9 +57,7 @@ contract Permissions is AccessControlUpgradeableLegacy, IPermissions { * - The caller must be an admin. */ modifier onlyAdmin() { - if(!_isAdmin(msg.sender)) { - revert MessageSenderIsNotAdmin(msg.sender); - } + require(_isAdmin(msg.sender), "Caller is not an admin"); _; } @@ -79,10 +70,9 @@ contract Permissions is AccessControlUpgradeableLegacy, IPermissions { * - The caller must be the owner or `contractName`. */ modifier allow(string memory contractName) { - if(!(contractManager.getContract(contractName) == msg.sender || _isOwner())) - { - revert MessageSenderIsInvalid(msg.sender); - } + require( + contractManager.getContract(contractName) == msg.sender || _isOwner(), + "Message sender is invalid"); _; } @@ -95,13 +85,11 @@ contract Permissions is AccessControlUpgradeableLegacy, IPermissions { * - The caller must be the owner, `contractName1`, or `contractName2`. */ modifier allowTwo(string memory contractName1, string memory contractName2) { - if(!( + require( contractManager.getContract(contractName1) == msg.sender || contractManager.getContract(contractName2) == msg.sender || - _isOwner())) - { - revert MessageSenderIsInvalid(msg.sender); - } + _isOwner(), + "Message sender is invalid"); _; } @@ -115,22 +103,12 @@ contract Permissions is AccessControlUpgradeableLegacy, IPermissions { * `contractName3`. */ modifier allowThree(string memory contractName1, string memory contractName2, string memory contractName3) { - if(!( + require( contractManager.getContract(contractName1) == msg.sender || contractManager.getContract(contractName2) == msg.sender || contractManager.getContract(contractName3) == msg.sender || - _isOwner())) - { - revert MessageSenderIsInvalid(msg.sender); - } - _; - } - - modifier onlySkaleManager() { - if(!(contractManager.getSkaleManager() == msg.sender || _isOwner())) - { - revert MessageSenderIsNotSkaleManager(msg.sender); - } + _isOwner(), + "Message sender is invalid"); _; } diff --git a/contracts/Schains.sol b/contracts/Schains.sol index 7004bea2..c31e1198 100644 --- a/contracts/Schains.sol +++ b/contracts/Schains.sol @@ -83,7 +83,7 @@ contract Schains is Permissions, ISchains { * - There is sufficient deposit to create type of schain. * - If from is a smart contract originator must be specified */ - function addSchain(address from, uint256 deposit, bytes calldata data) external override onlySkaleManager() { + function addSchain(address from, uint256 deposit, bytes calldata data) external override allow("SkaleManager") { SchainParameters memory schainParameters = abi.decode(data, (SchainParameters)); ConstantsHolder constantsHolder = ConstantsHolder(contractManager.getConstantsHolder()); uint256 schainCreationTimeStamp = constantsHolder.schainCreationTimeStamp(); @@ -156,7 +156,7 @@ contract Schains is Permissions, ISchains { * * - Executed by schain owner. */ - function deleteSchain(address from, string calldata name) external override onlySkaleManager() { + function deleteSchain(address from, string calldata name) external override allow("SkaleManager") { ISchainsInternal schainsInternal = ISchainsInternal(contractManager.getContract("SchainsInternal")); bytes32 schainHash = keccak256(abi.encodePacked(name)); require( @@ -177,7 +177,7 @@ contract Schains is Permissions, ISchains { * * - Schain exists. */ - function deleteSchainByRoot(string calldata name) external override onlySkaleManager() { + function deleteSchainByRoot(string calldata name) external override allow("SkaleManager") { _deleteSchain(name, ISchainsInternal(contractManager.getContract("SchainsInternal"))); } @@ -193,7 +193,7 @@ contract Schains is Permissions, ISchains { * - DKG failure got stuck because there were no free nodes to rotate in. * - A free node must be released in the network. */ - function restartSchainCreation(string calldata name) external override onlySkaleManager() { + function restartSchainCreation(string calldata name) external override allow("SkaleManager") { INodeRotation nodeRotation = INodeRotation(contractManager.getContract("NodeRotation")); bytes32 schainHash = keccak256(abi.encodePacked(name)); SkaleDKG skaleDKG = SkaleDKG(contractManager.getContract("SkaleDKG")); diff --git a/contracts/SchainsInternal.sol b/contracts/SchainsInternal.sol index 24cf72cf..ff707822 100644 --- a/contracts/SchainsInternal.sol +++ b/contracts/SchainsInternal.sol @@ -381,7 +381,7 @@ contract SchainsInternal is Permissions, IPruningSchainsInternal { numberOfSchainTypes = newNumberOfSchainTypes; } - function removeNodeFromAllExceptionSchains(uint256 nodeIndex) external override onlySkaleManager() { + function removeNodeFromAllExceptionSchains(uint256 nodeIndex) external override allow("SkaleManager") { uint256 len = _nodeToLockedSchains[nodeIndex].length; for (uint256 i = len; i > 0; i--) { removeNodeFromExceptions(_nodeToLockedSchains[nodeIndex][i - 1], nodeIndex); diff --git a/contracts/SkaleToken.sol b/contracts/SkaleToken.sol index 7ddb6994..5e25bb66 100644 --- a/contracts/SkaleToken.sol +++ b/contracts/SkaleToken.sol @@ -74,7 +74,7 @@ contract SkaleToken is ERC777, Permissions, ReentrancyGuard, IDelegatableToken, ) external override - onlySkaleManager() + allow("SkaleManager") //onlyAuthorized returns (bool successful) { diff --git a/contracts/Wallets.sol b/contracts/Wallets.sol index 05e16c93..38dec0fa 100644 --- a/contracts/Wallets.sol +++ b/contracts/Wallets.sol @@ -127,7 +127,7 @@ contract Wallets is Permissions, IWallets { ) external override - onlySkaleManager() + allow("SkaleManager") { require(spender != address(0), "Spender must be specified"); require(validatorId != 0, "ValidatorId could not be zero"); From a924ae425a997aa1151bd0e3eb27c4a10f0625ce Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Wed, 24 Jan 2024 17:05:06 +0200 Subject: [PATCH 10/15] Revert changes in ContractManager --- contracts/ContractManager.sol | 5 ----- package.json | 2 +- yarn.lock | 8 ++++---- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/contracts/ContractManager.sol b/contracts/ContractManager.sol index 4aba3577..2faa006b 100644 --- a/contracts/ContractManager.sol +++ b/contracts/ContractManager.sol @@ -41,7 +41,6 @@ contract ContractManager is InitializableWithGap, OwnableUpgradeable, IContractM string public constant CONSTANTS_HOLDER = "ConstantsHolder"; string public constant DELEGATION_PERIOD_MANAGER = "DelegationPeriodManager"; string public constant PUNISHER = "Punisher"; - string public constant SKALE_MANAGER = "SkaleManager"; string public constant SKALE_TOKEN = "SkaleToken"; string public constant TIME_HELPERS = "TimeHelpers"; string public constant TOKEN_STATE = "TokenState"; @@ -124,10 +123,6 @@ contract ContractManager is InitializableWithGap, OwnableUpgradeable, IContractM return getContract(PUNISHER); } - function getSkaleManager() external view override returns (address skaleManager) { - return getContract(SKALE_MANAGER); - } - function getContract(string memory name) public view override returns (address contractAddress) { contractAddress = contracts[keccak256(abi.encodePacked(name))]; if (contractAddress == address(0)) { diff --git a/package.json b/package.json index fa07952c..b9322f64 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@openzeppelin/contracts": "^4.9.3", "@openzeppelin/contracts-upgradeable": "^4.9.3", "@openzeppelin/hardhat-upgrades": "^1.14.0", - "@skalenetwork/skale-manager-interfaces": "^2.2.0-dkg-fix.3", + "@skalenetwork/skale-manager-interfaces": "^2.2.0-dkg-fix.4", "@skalenetwork/upgrade-tools": "^2.0.1", "@typechain/hardhat": "^7.0.0", "dotenv": "^16.3.1", diff --git a/yarn.lock b/yarn.lock index 31f5f07c..627a0f10 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1755,10 +1755,10 @@ dependencies: "@sinonjs/commons" "^1.7.0" -"@skalenetwork/skale-manager-interfaces@^2.2.0-dkg-fix.3": - version "2.2.0-dkg-fix.3" - resolved "https://registry.yarnpkg.com/@skalenetwork/skale-manager-interfaces/-/skale-manager-interfaces-2.2.0-dkg-fix.3.tgz#3e5d7b0b96716e8cce7052d6b819ef73786211aa" - integrity sha512-pbhe/iOeM1naHQABbD4NpWYXUVg9MFUwwuMqmgIsby0lK8cgbgXZ5egKaoHNSqSo0Jj2hsi8LxOlaL6xjejiRg== +"@skalenetwork/skale-manager-interfaces@^2.2.0-dkg-fix.4": + version "2.2.0-dkg-fix.4" + resolved "https://registry.yarnpkg.com/@skalenetwork/skale-manager-interfaces/-/skale-manager-interfaces-2.2.0-dkg-fix.4.tgz#a434daaa39cbbb1164667de7cd77d09910f732c0" + integrity sha512-Fzawk/nkQzZFL/DnBmzitEacvvzd+e/XCbqdQbHdsC3+/u+/nqLrpvhW6mlCitAAag8kDWnpasRrHPmvnSu4ig== "@skalenetwork/upgrade-tools@^2.0.1": version "2.0.1" From cbcb91572e8c75a9288b3f1d7ffc641115a9dee5 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Thu, 25 Jan 2024 17:54:03 +0200 Subject: [PATCH 11/15] Update tests --- test/NodesFunctionality.ts | 12 +++--------- test/SkaleManager.ts | 11 ++++------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/test/NodesFunctionality.ts b/test/NodesFunctionality.ts index 63719d5f..3b434318 100644 --- a/test/NodesFunctionality.ts +++ b/test/NodesFunctionality.ts @@ -180,9 +180,7 @@ describe("NodesFunctionality", () => { }); it("should change IP", async () => { - await expect(nodes.connect(holder).changeIP(0, "0x7f000001", "0x00000000")) - .to.be.revertedWithCustomError(nodes, "MessageSenderIsNotAdmin") - .withArgs(holder.address); + await nodes.connect(holder).changeIP(0, "0x7f000001", "0x00000000").should.be.eventually.rejectedWith("Caller is not an admin"); await nodes.connect(owner).changeIP(0, "0x7f000001", "0x00000000").should.be.eventually.rejectedWith("IP address is zero or is not available"); await nodes.connect(owner).changeIP(0, "0x00000000", "0x00000000").should.be.eventually.rejectedWith("IP address is zero or is not available"); await nodes.connect(owner).changeIP(0, "0x7f000002", "0x7f000001").should.be.eventually.rejectedWith("IP address is not the same"); @@ -304,16 +302,12 @@ describe("NodesFunctionality", () => { }); it("should change IP", async () => { - await expect(nodes.connect(holder).changeIP(0, "0x7f000001", "0x00000000")) - .to.be.revertedWithCustomError(nodes, "MessageSenderIsNotAdmin") - .withArgs(holder.address); + await nodes.connect(holder).changeIP(0, "0x7f000001", "0x00000000").should.be.eventually.rejectedWith("Caller is not an admin"); await nodes.connect(owner).changeIP(0, "0x7f000001", "0x00000000").should.be.eventually.rejectedWith("IP address is zero or is not available"); await nodes.connect(owner).changeIP(0, "0x00000000", "0x00000000").should.be.eventually.rejectedWith("IP address is zero or is not available"); await nodes.connect(owner).changeIP(0, "0x7f000002", "0x00000000").should.be.eventually.rejectedWith("IP address is zero or is not available"); await nodes.connect(owner).changeIP(0, "0x7f000003", "0x7f000002").should.be.eventually.rejectedWith("IP address is not the same"); - await expect(nodes.connect(holder).changeIP(1, "0x7f000002", "0x00000000")) - .to.be.revertedWithCustomError(nodes, "MessageSenderIsNotAdmin") - .withArgs(holder.address); + await nodes.connect(holder).changeIP(1, "0x7f000002", "0x00000000").should.be.eventually.rejectedWith("Caller is not an admin"); await nodes.connect(owner).changeIP(1, "0x7f000002", "0x00000000").should.be.eventually.rejectedWith("IP address is zero or is not available"); await nodes.connect(owner).changeIP(1, "0x00000000", "0x00000000").should.be.eventually.rejectedWith("IP address is zero or is not available"); await nodes.connect(owner).changeIP(1, "0x7f000001", "0x00000000").should.be.eventually.rejectedWith("IP address is zero or is not available"); diff --git a/test/SkaleManager.ts b/test/SkaleManager.ts index 5fca828f..9ce22719 100644 --- a/test/SkaleManager.ts +++ b/test/SkaleManager.ts @@ -1,5 +1,4 @@ import * as chai from "chai"; -import { expect } from "chai"; import chaiAsPromised from "chai-as-promised"; import { ConstantsHolder, ContractManager, @@ -122,15 +121,14 @@ describe("SkaleManager", () => { }); it("should fail to process token fallback if sent not from SkaleToken", async () => { - await expect(skaleManager.connect(validator).tokensReceived( + await skaleManager.connect(validator).tokensReceived( hacker.address, validator.address, developer.address, 5, "0x11", "0x11" - )).to.be.revertedWithCustomError(skaleManager, "MessageSenderIsInvalid") - .withArgs(validator.address); + ).should.be.eventually.rejectedWith("Message sender is invalid"); }); it("should transfer ownership", async () => { @@ -143,9 +141,8 @@ describe("SkaleManager", () => { }); it("should allow only owner to set a version", async () => { - await expect(skaleManager.connect(hacker).setVersion("bad")) - .to.be.revertedWithCustomError(skaleManager, "MessageSenderIsNotOwner") - .withArgs(hacker.address); + await skaleManager.connect(hacker).setVersion("bad") + .should.be.eventually.rejectedWith("Caller is not the owner"); await skaleManager.setVersion("good"); (await skaleManager.version()).should.be.equal("good"); From 69c30d1e52d48a39c6351d537b609f9054ae0c62 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Thu, 25 Jan 2024 18:20:43 +0200 Subject: [PATCH 12/15] Update the complaint constant --- contracts/ConstantsHolder.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/ConstantsHolder.sol b/contracts/ConstantsHolder.sol index bc9d3337..67ee45e1 100644 --- a/contracts/ConstantsHolder.sol +++ b/contracts/ConstantsHolder.sol @@ -82,7 +82,7 @@ contract ConstantsHolder is Permissions, IConstantsHolder { uint256 public constant BROADCAST_DELTA = 177490; uint256 public constant COMPLAINT_BAD_DATA_DELTA = 80995; uint256 public constant PRE_RESPONSE_DELTA = 114511; - uint256 public constant COMPLAINT_DELTA = 203048; + uint256 public constant COMPLAINT_DELTA = 203288; uint256 public constant RESPONSE_DELTA = 54762; // MSR - Minimum staking requirement From c0bbd6b11ede6d97af5d046c1043c049c8115ba8 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Thu, 25 Jan 2024 18:46:32 +0200 Subject: [PATCH 13/15] Update the response constant --- contracts/ConstantsHolder.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/ConstantsHolder.sol b/contracts/ConstantsHolder.sol index 67ee45e1..c842b0df 100644 --- a/contracts/ConstantsHolder.sol +++ b/contracts/ConstantsHolder.sol @@ -83,7 +83,7 @@ contract ConstantsHolder is Permissions, IConstantsHolder { uint256 public constant COMPLAINT_BAD_DATA_DELTA = 80995; uint256 public constant PRE_RESPONSE_DELTA = 114511; uint256 public constant COMPLAINT_DELTA = 203288; - uint256 public constant RESPONSE_DELTA = 54762; + uint256 public constant RESPONSE_DELTA = 55002; // MSR - Minimum staking requirement uint256 public msr; From e53b1a8e569a59c8896791e7077978e2fe605214 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Mon, 29 Jan 2024 12:33:59 +0200 Subject: [PATCH 14/15] Replace contracts with interfaces --- contracts/Schains.sol | 3 +-- contracts/SchainsInternal.sol | 11 +++++------ contracts/SkaleDKG.sol | 2 +- package.json | 2 +- yarn.lock | 8 ++++---- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/contracts/Schains.sol b/contracts/Schains.sol index c31e1198..04f796b0 100644 --- a/contracts/Schains.sol +++ b/contracts/Schains.sol @@ -35,7 +35,6 @@ import { IWallets } from "@skalenetwork/skale-manager-interfaces/IWallets.sol"; import { Permissions } from "./Permissions.sol"; import { ConstantsHolder } from "./ConstantsHolder.sol"; import { G2Operations } from "./utils/fieldOperations/G2Operations.sol"; -import { SkaleDKG } from "./SkaleDKG.sol"; /** @@ -196,7 +195,7 @@ contract Schains is Permissions, ISchains { function restartSchainCreation(string calldata name) external override allow("SkaleManager") { INodeRotation nodeRotation = INodeRotation(contractManager.getContract("NodeRotation")); bytes32 schainHash = keccak256(abi.encodePacked(name)); - SkaleDKG skaleDKG = SkaleDKG(contractManager.getContract("SkaleDKG")); + ISkaleDKG skaleDKG = ISkaleDKG(contractManager.getContract("SkaleDKG")); require(!skaleDKG.isLastDKGSuccessful(schainHash), "DKG success"); ISchainsInternal schainsInternal = ISchainsInternal( contractManager.getContract("SchainsInternal")); diff --git a/contracts/SchainsInternal.sol b/contracts/SchainsInternal.sol index ff707822..bb34cae0 100644 --- a/contracts/SchainsInternal.sol +++ b/contracts/SchainsInternal.sol @@ -30,7 +30,6 @@ import { ISkaleDKG } from "@skalenetwork/skale-manager-interfaces/ISkaleDKG.sol" import { ConstantsHolder } from "./ConstantsHolder.sol"; import { IPruningSchainsInternal } from "./interfaces/IPruningSchainInternal.sol"; import { IRandom, Random } from "./utils/Random.sol"; -import { Nodes } from "./Nodes.sol"; import { Permissions } from "./Permissions.sol"; @@ -259,7 +258,7 @@ contract SchainsInternal is Permissions, IPruningSchainsInternal { removeSchainForNode(nodeIndex, placeOfSchainOnNode[schainHash][nodeIndex] - 1); delete placeOfSchainOnNode[schainHash][nodeIndex]; - Nodes nodes = Nodes(contractManager.getContract("Nodes")); + INodes nodes = INodes(contractManager.getContract("Nodes")); require(_removeAddressFromSchain(schainHash, nodes.getNodeAddress(nodeIndex)), "Incorrect node address"); nodes.addSpaceToNode(nodeIndex, schains[schainHash].partOfNode); } @@ -415,7 +414,7 @@ contract SchainsInternal is Permissions, IPruningSchainsInternal { allowTwo("NodeRotation", "SkaleDKG") schainExists(schainHash) { - Nodes nodes = Nodes(contractManager.getContract("Nodes")); + INodes nodes = INodes(contractManager.getContract("Nodes")); for (uint256 i = 0; i < _schainToExceptionNodes[schainHash].length; i++) { nodes.makeNodeInvisible(_schainToExceptionNodes[schainHash][i]); } @@ -735,7 +734,7 @@ contract SchainsInternal is Permissions, IPruningSchainsInternal { function isAnyFreeNode(bytes32 schainHash) external view override schainExists(schainHash) returns (bool free) { // TODO: // Move this function to Nodes? - Nodes nodes = Nodes(contractManager.getContract("Nodes")); + INodes nodes = INodes(contractManager.getContract("Nodes")); uint8 space = schains[schainHash].partOfNode; uint256 numberOfCandidates = nodes.countNodesWithFreeSpace(space); for (uint256 i = 0; i < _schainToExceptionNodes[schainHash].length; i++) { @@ -966,7 +965,7 @@ contract SchainsInternal is Permissions, IPruningSchainsInternal { * @dev Generates schain group using a pseudo-random generator. */ function _generateGroup(bytes32 schainHash, uint256 numberOfNodes) private returns (uint256[] memory nodesInGroup) { - Nodes nodes = Nodes(contractManager.getContract("Nodes")); + INodes nodes = INodes(contractManager.getContract("Nodes")); uint8 space = schains[schainHash].partOfNode; nodesInGroup = new uint256[](numberOfNodes); @@ -994,7 +993,7 @@ contract SchainsInternal is Permissions, IPruningSchainsInternal { } function _makeSchainNodesVisible(bytes32 schainHash) private { - Nodes nodes = Nodes(contractManager.getContract("Nodes")); + INodes nodes = INodes(contractManager.getContract("Nodes")); for (uint256 i = 0; i < _schainToExceptionNodes[schainHash].length; i++) { nodes.makeNodeVisible(_schainToExceptionNodes[schainHash][i]); } diff --git a/contracts/SkaleDKG.sol b/contracts/SkaleDKG.sol index a1b6ea24..38f28b1d 100644 --- a/contracts/SkaleDKG.sol +++ b/contracts/SkaleDKG.sol @@ -71,7 +71,7 @@ contract SkaleDKG is Permissions, ISkaleDKG { mapping(bytes32 => uint256) private _badNodes; - mapping(bytes32 => uint256) public pendingToBeReplaced; + mapping(bytes32 => uint256) public override pendingToBeReplaced; modifier correctGroup(bytes32 schainHash) { require(channels[schainHash].active, "Group is not created"); diff --git a/package.json b/package.json index b9322f64..1f16b6c6 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@openzeppelin/contracts": "^4.9.3", "@openzeppelin/contracts-upgradeable": "^4.9.3", "@openzeppelin/hardhat-upgrades": "^1.14.0", - "@skalenetwork/skale-manager-interfaces": "^2.2.0-dkg-fix.4", + "@skalenetwork/skale-manager-interfaces": "^2.2.0-dkg-fix.5", "@skalenetwork/upgrade-tools": "^2.0.1", "@typechain/hardhat": "^7.0.0", "dotenv": "^16.3.1", diff --git a/yarn.lock b/yarn.lock index 627a0f10..625e1925 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1755,10 +1755,10 @@ dependencies: "@sinonjs/commons" "^1.7.0" -"@skalenetwork/skale-manager-interfaces@^2.2.0-dkg-fix.4": - version "2.2.0-dkg-fix.4" - resolved "https://registry.yarnpkg.com/@skalenetwork/skale-manager-interfaces/-/skale-manager-interfaces-2.2.0-dkg-fix.4.tgz#a434daaa39cbbb1164667de7cd77d09910f732c0" - integrity sha512-Fzawk/nkQzZFL/DnBmzitEacvvzd+e/XCbqdQbHdsC3+/u+/nqLrpvhW6mlCitAAag8kDWnpasRrHPmvnSu4ig== +"@skalenetwork/skale-manager-interfaces@^2.2.0-dkg-fix.5": + version "2.2.0-dkg-fix.5" + resolved "https://registry.yarnpkg.com/@skalenetwork/skale-manager-interfaces/-/skale-manager-interfaces-2.2.0-dkg-fix.5.tgz#da4de987914a18b36751c3f5fe450b1cea7c1a7f" + integrity sha512-M/jwyXnfeDpVvoxBWbfOyy8JpMGtIdVPS7QYshHvt9A1Qlyr5xQ+VSgg3j4/Av1bXRUqpxFIH7DMa+l6ODjN2A== "@skalenetwork/upgrade-tools@^2.0.1": version "2.0.1" From 6fa05b6c7075a6f09ebacec518d3bc5b25792000 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Mon, 29 Jan 2024 18:12:05 +0200 Subject: [PATCH 15/15] Update skale-manager-interfaces --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 1f16b6c6..d0b6fab3 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@openzeppelin/contracts": "^4.9.3", "@openzeppelin/contracts-upgradeable": "^4.9.3", "@openzeppelin/hardhat-upgrades": "^1.14.0", - "@skalenetwork/skale-manager-interfaces": "^2.2.0-dkg-fix.5", + "@skalenetwork/skale-manager-interfaces": "3.0.0-develop.0", "@skalenetwork/upgrade-tools": "^2.0.1", "@typechain/hardhat": "^7.0.0", "dotenv": "^16.3.1", diff --git a/yarn.lock b/yarn.lock index 625e1925..5cc04691 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1755,10 +1755,10 @@ dependencies: "@sinonjs/commons" "^1.7.0" -"@skalenetwork/skale-manager-interfaces@^2.2.0-dkg-fix.5": - version "2.2.0-dkg-fix.5" - resolved "https://registry.yarnpkg.com/@skalenetwork/skale-manager-interfaces/-/skale-manager-interfaces-2.2.0-dkg-fix.5.tgz#da4de987914a18b36751c3f5fe450b1cea7c1a7f" - integrity sha512-M/jwyXnfeDpVvoxBWbfOyy8JpMGtIdVPS7QYshHvt9A1Qlyr5xQ+VSgg3j4/Av1bXRUqpxFIH7DMa+l6ODjN2A== +"@skalenetwork/skale-manager-interfaces@3.0.0-develop.0": + version "3.0.0-develop.0" + resolved "https://registry.yarnpkg.com/@skalenetwork/skale-manager-interfaces/-/skale-manager-interfaces-3.0.0-develop.0.tgz#8a1c489cda5c9a44a41b7854c7ce1d7ee4db0126" + integrity sha512-7NXDWtzOKIqmSU0lnG8e9Hb7uK6H3DbuPwic/xMohPhCxJ1NnNMRBNcFpClDtuMlHnmvoHXKrWPJajKd/Ul58g== "@skalenetwork/upgrade-tools@^2.0.1": version "2.0.1"