Skip to content

Commit

Permalink
Merge pull request #144 from valory-xyz/post_audit
Browse files Browse the repository at this point in the history
refactor: post audit
  • Loading branch information
kupermind authored Dec 1, 2023
2 parents 123fe1d + b2d5c46 commit 2ce07e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
8 changes: 7 additions & 1 deletion audits/internal4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -243,6 +246,8 @@ numEvictServices < setServiceIds
setServiceIds.pop();
and move it under for()
```
[x] fixed


#### Notes (unstake scenario)
```solidity
Expand All @@ -265,3 +270,4 @@ numEvictServices < setServiceIds
revert NotEnoughTimeStaked(serviceId, ts, maxAllowedInactivity);
}
```
[x] behaves as expected
13 changes: 2 additions & 11 deletions contracts/staking/ServiceStakingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 2ce07e8

Please sign in to comment.