From a4f8435a2f1d059f3ab047d1c9c624636776922a Mon Sep 17 00:00:00 2001 From: adu Date: Fri, 5 Jul 2024 15:29:20 +0800 Subject: [PATCH] slither: use cached array length --- src/core/Bootstrap.sol | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/Bootstrap.sol b/src/core/Bootstrap.sol index 581a86bb..5df18c86 100644 --- a/src/core/Bootstrap.sol +++ b/src/core/Bootstrap.sol @@ -228,7 +228,8 @@ contract Bootstrap is */ function consensusPublicKeyInUse(bytes32 newKey) public view returns (bool) { require(newKey != bytes32(0), "Consensus public key cannot be zero"); - for (uint256 i = 0; i < registeredOperators.length; i++) { + uint256 arrayLength = registeredOperators.length; + for (uint256 i = 0; i < arrayLength; i++) { address ethAddress = registeredOperators[i]; string memory exoAddress = ethToExocoreAddress[ethAddress]; if (operators[exoAddress].consensusPublicKey == newKey) { @@ -274,7 +275,8 @@ contract Bootstrap is * safely used for a new operator. */ function nameInUse(string memory newName) public view returns (bool) { - for (uint256 i = 0; i < registeredOperators.length; i++) { + uint256 arrayLength = registeredOperators.length; + for (uint256 i = 0; i < arrayLength; i++) { address ethAddress = registeredOperators[i]; string memory exoAddress = ethToExocoreAddress[ethAddress]; if (keccak256(abi.encodePacked(operators[exoAddress].name)) == keccak256(abi.encodePacked(newName))) {