diff --git a/audits/internal4/README.md b/audits/internal4/README.md index dd3709ea..12a89c93 100644 --- a/audits/internal4/README.md +++ b/audits/internal4/README.md @@ -232,8 +232,11 @@ numEvictServices == 1 numEvictServices > 1 numEvictServices == setServiceIds numEvictServices < setServiceIds +``` +[x] tests are in place -+ is it possible to exclude a special case +```solidity +is it possible to exclude a special case // Deal with the very first element // Get the evicted service index idx = serviceIndexes[0]; @@ -243,6 +246,8 @@ numEvictServices < setServiceIds setServiceIds.pop(); and move it under for() ``` +[x] fixed + #### Notes (unstake scenario) ```solidity @@ -265,3 +270,4 @@ numEvictServices < setServiceIds revert NotEnoughTimeStaked(serviceId, ts, maxAllowedInactivity); } ``` +[x] behaves as expected diff --git a/contracts/staking/ServiceStakingBase.sol b/contracts/staking/ServiceStakingBase.sol index 268877cb..07600c20 100644 --- a/contracts/staking/ServiceStakingBase.sol +++ b/contracts/staking/ServiceStakingBase.sol @@ -487,26 +487,17 @@ abstract contract ServiceStakingBase is ERC721TokenReceiver, IErrorsRegistries { } // Evict services from the global set of staked services - uint256 idx; - for (uint256 i = numEvictServices - 1; i > 0; --i) { + for (uint256 i = numEvictServices; i > 0; --i) { // Decrease the number of services totalNumServices--; // Get the evicted service index - idx = serviceIndexes[i]; + uint256 idx = serviceIndexes[i - 1]; // Assign last service Id to the index that points to the evicted service Id setServiceIds[idx] = setServiceIds[totalNumServices]; // Pop the last element setServiceIds.pop(); } - // Deal with the very first element - // Get the evicted service index - idx = serviceIndexes[0]; - // Assign last service Id to the index that points to the evicted service Id - setServiceIds[idx] = setServiceIds[totalNumServices - 1]; - // Pop the last element - setServiceIds.pop(); - emit ServicesEvicted(epochCounter, serviceIds, owners, multisigs, inactivity); }