Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: post audit #144

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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];
Comment on lines -490 to +494
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified the workflow into one loop.

// 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
Loading