-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #606 from ava-labs/verify-weights-removable
Check weights
- Loading branch information
Showing
8 changed files
with
178 additions
and
62 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
abi-bindings/go/validator-manager/ERC20TokenStakingManager/ERC20TokenStakingManager.go
Large diffs are not rendered by default.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
abi-bindings/go/validator-manager/NativeTokenStakingManager/NativeTokenStakingManager.go
Large diffs are not rendered by default.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
abi-bindings/go/validator-manager/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 |
---|---|---|
|
@@ -77,6 +77,7 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida | |
error InvalidSubnetConversionID( | ||
bytes32 encodedSubnetConversionID, bytes32 expectedSubnetConversionID | ||
); | ||
error InvalidTotalWeight(uint256 weight); | ||
error InvalidValidationID(bytes32 validationID); | ||
error InvalidValidatorStatus(ValidatorStatus status); | ||
error InvalidWarpMessage(); | ||
|
@@ -196,6 +197,12 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida | |
} | ||
$._churnTracker.totalWeight = totalWeight; | ||
|
||
// Rearranged equation for totalWeight < (100 / $._maximumChurnPercentage) | ||
// Total weight must be above this value in order to not trigger churn limits with an added/removed weight of 1. | ||
if (totalWeight * $._maximumChurnPercentage < 100) { | ||
revert InvalidTotalWeight(totalWeight); | ||
} | ||
|
||
// Verify that the sha256 hash of the Subnet conversion data matches with the Warp message's subnetConversionID. | ||
bytes32 subnetConversionID = ValidatorMessages.unpackSubnetConversionMessage( | ||
_getPChainWarpMessage(messageIndex).payload | ||
|
@@ -573,6 +580,12 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida | |
churnTracker.totalWeight += newValidatorWeight; | ||
churnTracker.totalWeight -= oldValidatorWeight; | ||
|
||
// Rearranged equation for totalWeight < (100 / $._maximumChurnPercentage) | ||
// Total weight must be above this value in order to not trigger churn limits with an added/removed weight of 1. | ||
if (churnTracker.totalWeight * $._maximumChurnPercentage < 100) { | ||
revert InvalidTotalWeight(churnTracker.totalWeight); | ||
} | ||
|
||
$._churnTracker = churnTracker; | ||
} | ||
Check notice Code scanning / Slither Block timestamp Low
ValidatorManager._checkAndUpdateChurnTracker(uint64,uint64) uses timestamp for comparisons
Dangerous comparisons: - churnTracker.startTime == 0 || currentTime >= churnTracker.startTime + $._churnPeriodSeconds - $._maximumChurnPercentage * churnTracker.initialWeight < churnTracker.churnAmount * 100 - churnTracker.totalWeight * $._maximumChurnPercentage < 100 |
||
} |
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
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
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 |
---|---|---|
|
@@ -10,7 +10,8 @@ import {PoAValidatorManager} from "../PoAValidatorManager.sol"; | |
import {ICMInitializable} from "@utilities/ICMInitializable.sol"; | ||
import { | ||
ValidatorManagerSettings, | ||
ValidatorRegistrationInput | ||
ValidatorRegistrationInput, | ||
IValidatorManager | ||
} from "../interfaces/IValidatorManager.sol"; | ||
import {OwnableUpgradeable} from | ||
"@openzeppelin/[email protected]/access/OwnableUpgradeable.sol"; | ||
|
@@ -24,16 +25,7 @@ contract PoAValidatorManagerTest is ValidatorManagerTest { | |
function setUp() public override { | ||
ValidatorManagerTest.setUp(); | ||
|
||
app = new PoAValidatorManager(ICMInitializable.Allowed); | ||
app.initialize( | ||
ValidatorManagerSettings({ | ||
subnetID: DEFAULT_SUBNET_ID, | ||
churnPeriodSeconds: DEFAULT_CHURN_PERIOD, | ||
maximumChurnPercentage: DEFAULT_MAXIMUM_CHURN_PERCENTAGE | ||
}), | ||
address(this) | ||
); | ||
validatorManager = app; | ||
_setUp(); | ||
_mockGetBlockchainID(); | ||
_mockInitializeValidatorSet(); | ||
app.initializeValidatorSet(_defaultSubnetConversionData(), 0); | ||
|
@@ -73,6 +65,21 @@ contract PoAValidatorManagerTest is ValidatorManagerTest { | |
return app.initializeEndValidation(validationID); | ||
} | ||
|
||
function _setUp() internal override returns (IValidatorManager) { | ||
app = new PoAValidatorManager(ICMInitializable.Allowed); | ||
app.initialize( | ||
ValidatorManagerSettings({ | ||
subnetID: DEFAULT_SUBNET_ID, | ||
churnPeriodSeconds: DEFAULT_CHURN_PERIOD, | ||
maximumChurnPercentage: DEFAULT_MAXIMUM_CHURN_PERCENTAGE | ||
}), | ||
address(this) | ||
); | ||
validatorManager = app; | ||
|
||
return app; | ||
} | ||
|
||
// solhint-disable-next-line no-empty-blocks | ||
function _beforeSend(uint256 amount, address spender) internal virtual override {} | ||
} |
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