-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0ba99e
commit 2faa0af
Showing
4 changed files
with
17 additions
and
32 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
abi-bindings/go/staking/ERC20TokenStakingManager/ERC20TokenStakingManager.go
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
abi-bindings/go/staking/NativeTokenStakingManager/NativeTokenStakingManager.go
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
abi-bindings/go/staking/PoAValidatorManager/PoAValidatorManager.go
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,7 +144,7 @@ abstract contract ValidatorManager is | |
require(input.blsPublicKey.length == 48, "ValidatorManager: invalid blsPublicKey length"); | ||
|
||
// Check that adding this validator would not exceed the maximum churn rate. | ||
_checkAndUpdateChurnTrackerAddition(weight); | ||
_checkAndUpdateChurnTracker(weight, 0); | ||
|
||
(bytes32 validationID, bytes memory registerSubnetValidatorMessage) = ValidatorMessages | ||
.packRegisterSubnetValidatorMessage( | ||
|
@@ -376,12 +376,8 @@ abstract contract ValidatorManager is | |
ValidatorManagerStorage storage $ = _getValidatorManagerStorage(); | ||
uint64 validatorWeight = $._validationPeriods[validationID].weight; | ||
|
||
// Check that removing this delegator would not exceed the maximum churn rate. | ||
if (newWeight >= validatorWeight) { | ||
_checkAndUpdateChurnTrackerAddition(newWeight - validatorWeight); | ||
} else { | ||
_checkAndUpdateChurnTrackerRemoval(validatorWeight - newWeight); | ||
} | ||
// Check that changing the validator weight would not exceed the maximum churn rate. | ||
_checkAndUpdateChurnTracker(newWeight, validatorWeight); | ||
|
||
uint64 nonce = _incrementAndGetNonce(validationID); | ||
|
||
|
@@ -402,41 +398,34 @@ abstract contract ValidatorManager is | |
return (nonce, messageID); | ||
} | ||
Check notice Code scanning / Slither Reentrancy vulnerabilities Low
Reentrancy in ValidatorManager._setValidatorWeight(bytes32,uint64):
External calls: - messageID = WARP_MESSENGER.sendWarpMessage(ValidatorMessages.packSetSubnetValidatorWeightMessage(validationID,nonce,newWeight)) Event emitted after the call(s): - ValidatorWeightUpdate({validationID:validationID,nonce:nonce,validatorWeight:newWeight,setWeightMessageID:messageID}) |
||
|
||
/** | ||
* @dev Helper function to check if the stake amount to be added exceeds churn thresholds. | ||
*/ | ||
function _checkAndUpdateChurnTrackerAddition(uint64 weight) internal { | ||
_checkAndUpdateChurnTracker(weight, true); | ||
} | ||
|
||
/** | ||
* @dev Helper function to check if the stake amount to be removed exceeds churn thresholds. | ||
*/ | ||
function _checkAndUpdateChurnTrackerRemoval(uint64 weight) internal { | ||
_checkAndUpdateChurnTracker(weight, false); | ||
} | ||
|
||
/** | ||
* @dev Helper function to check if the stake weight to be added or removed would exceed the maximum stake churn | ||
* rate for the past churn period. If the churn rate is exceeded, the function will revert. If the churn rate is | ||
* not exceeded, the function will update the churn tracker with the new weight. | ||
*/ | ||
function _checkAndUpdateChurnTracker(uint64 weight, bool addition) private { | ||
function _checkAndUpdateChurnTracker(uint64 newWeight, uint64 oldWeight) private { | ||
ValidatorManagerStorage storage $ = _getValidatorManagerStorage(); | ||
|
||
uint64 weightChange; | ||
if (newWeight > oldWeight) { | ||
weightChange = newWeight - oldWeight; | ||
} else { | ||
weightChange = oldWeight - newWeight; | ||
} | ||
|
||
uint256 currentTime = block.timestamp; | ||
ValidatorChurnPeriod memory churnTracker = $._churnTracker; | ||
|
||
if ( | ||
churnTracker.startedAt == 0 | ||
|| currentTime >= churnTracker.startedAt + $._churnPeriodSeconds | ||
) { | ||
churnTracker.churnAmount = weight; | ||
churnTracker.churnAmount = weightChange; | ||
churnTracker.startedAt = currentTime; | ||
churnTracker.initialWeight = churnTracker.totalWeight; | ||
} else { | ||
// Churn is always additive whether the weight is being added or removed. | ||
churnTracker.churnAmount += weight; | ||
churnTracker.churnAmount += weightChange; | ||
} | ||
|
||
require( | ||
|
@@ -445,11 +434,7 @@ abstract contract ValidatorManager is | |
"ValidatorManager: maximum churn rate exceeded" | ||
); | ||
|
||
if (addition) { | ||
churnTracker.totalWeight += weight; | ||
} else { | ||
churnTracker.totalWeight -= weight; | ||
} | ||
churnTracker.totalWeight += newWeight - oldWeight; | ||
|
||
$._churnTracker = churnTracker; | ||
} | ||
Check notice Code scanning / Slither Block timestamp Low
ValidatorManager._checkAndUpdateChurnTracker(uint64,uint64) uses timestamp for comparisons
Dangerous comparisons: - churnTracker.startedAt == 0 || currentTime >= churnTracker.startedAt + $._churnPeriodSeconds - require(bool,string)($._maximumChurnPercentage * churnTracker.initialWeight >= churnTracker.churnAmount * 100,ValidatorManager: maximum churn rate exceeded) |
||
|