Skip to content
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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions contracts/validator-manager/ValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ contract ValidatorManager is Initializable, OwnableUpgradeable, ACP99Manager {
error NodeAlreadyRegistered(bytes nodeID);
error UnexpectedRegistrationStatus(bool validRegistration);
error InvalidPChainOwnerThreshold(uint256 threshold, uint256 addressesLength);
error PChainOwnerAddressesNotSorted();
error InvalidPChainOwnerAddresses();
error ZeroAddress();

// solhint-disable ordering
Expand Down Expand Up @@ -308,11 +308,11 @@ contract ValidatorManager is Initializable, OwnableUpgradeable, ACP99Manager {
if (pChainOwner.addresses.length > 0 && pChainOwner.addresses[0] == address(0)) {
revert ZeroAddress();
}
// Addresses must be sorted in ascending order
// Addresses must be unique and sorted in ascending order
for (uint256 i = 1; i < pChainOwner.addresses.length; i++) {
// Compare current address with the previous one
if (pChainOwner.addresses[i] < pChainOwner.addresses[i - 1]) {
revert PChainOwnerAddressesNotSorted();
if (pChainOwner.addresses[i] <= pChainOwner.addresses[i - 1]) {
revert InvalidPChainOwnerAddresses();
}
}
}
Expand Down
23 changes: 22 additions & 1 deletion contracts/validator-manager/tests/ValidatorManagerTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,28 @@ abstract contract ValidatorManagerTest is Test {

_beforeSend(_weightToValue(DEFAULT_WEIGHT), address(this));
vm.expectRevert(
abi.encodeWithSelector(ValidatorManager.PChainOwnerAddressesNotSorted.selector)
abi.encodeWithSelector(ValidatorManager.InvalidPChainOwnerAddresses.selector)
);
_initiateValidatorRegistration({
nodeID: DEFAULT_NODE_ID,
blsPublicKey: DEFAULT_BLS_PUBLIC_KEY,
remainingBalanceOwner: invalidPChainOwner1,
disableOwner: DEFAULT_P_CHAIN_OWNER,
registrationExpiry: DEFAULT_EXPIRY,
weight: DEFAULT_WEIGHT
});
}

function testInitiateValidatorRegistrationDuplicatePChainOwnerAddress() public {
// Addresses not sorted
address[] memory addresses = new address[](2);
addresses[0] = 0x1234567812345678123456781234567812345678;
addresses[1] = 0x1234567812345678123456781234567812345678;
PChainOwner memory invalidPChainOwner1 = PChainOwner({threshold: 1, addresses: addresses});

_beforeSend(_weightToValue(DEFAULT_WEIGHT), address(this));
vm.expectRevert(
abi.encodeWithSelector(ValidatorManager.InvalidPChainOwnerAddresses.selector)
);
_initiateValidatorRegistration({
nodeID: DEFAULT_NODE_ID,
Expand Down