Skip to content

Commit

Permalink
fix: validate cons key non-empty
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMustermann2 committed Aug 5, 2024
1 parent 3eb235a commit 233acbb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/Bootstrap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ contract Bootstrap is
if (bytes(validators[validatorAddress].name).length > 0) {
revert Errors.BootstrapValidatorAlreadyRegistered();
}
// check that the consensus key is not empty.
if (consensusPublicKey == bytes32(0)) {
revert Errors.ZeroValue();
}
// check that the consensus key is unique.
if (consensusPublicKeyInUse[consensusPublicKey]) {
revert Errors.BootstrapConsensusPubkeyAlreadyUsed(consensusPublicKey);
Expand Down Expand Up @@ -261,6 +265,11 @@ contract Bootstrap is
if (bytes(ethToExocoreAddress[msg.sender]).length == 0) {
revert Errors.BootstrapValidatorNotExist();
}
// check that the consensus key is not empty.
if (newKey == bytes32(0)) {
revert Errors.ZeroValue();
}
// check that the consensus key is unique.
if (consensusPublicKeyInUse[newKey]) {
revert Errors.BootstrapConsensusPubkeyAlreadyUsed(newKey);
}
Expand Down
20 changes: 20 additions & 0 deletions test/foundry/unit/Bootstrap.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,17 @@ contract BootstrapTest is Test {
bootstrap.registerValidator(exo, name, commission, pubKey);
}

function test03_RegisterValidator_ZeroConsensusKey() public {
IValidatorRegistry.Commission memory commission = IValidatorRegistry.Commission(0, 1e18, 1e18);
// Register validator
string memory exo = "exo13hasr43vvq8v44xpzh0l6yuym4kca98f87j7ac";
string memory name = "validator1";
bytes32 pubKey = bytes32(0);
vm.startPrank(addrs[0]);
vm.expectRevert(Errors.ZeroValue.selector);
bootstrap.registerValidator(exo, name, commission, pubKey);
}

function test04_DepositThenDelegate() public {
// since deposit and delegate are already tested, we will just do a simple success
// check here to ensure the reentrancy modifier works.
Expand Down Expand Up @@ -493,6 +504,15 @@ contract BootstrapTest is Test {
vm.stopPrank();
}

function test05_ReplaceKey_ZeroConsensusKey() public {
test03_RegisterValidator();
vm.startPrank(addrs[0]);
bytes32 newKey = bytes32(0);
vm.expectRevert(Errors.ZeroValue.selector);
bootstrap.replaceKey(newKey);
vm.stopPrank();
}

function test06_UpdateRate() public {
IValidatorRegistry.Commission memory commission = IValidatorRegistry.Commission(0, 1e18, 1e18);
// Register one validator
Expand Down

0 comments on commit 233acbb

Please sign in to comment.