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

(Fix) Deny repeatedly adding removed mining key #208

Merged
10 changes: 9 additions & 1 deletion contracts/KeysManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ contract KeysManager is EternalStorage, IKeysManager {
return true;
}

if (hasMiningKeyBeenRemoved(_newKey)) {
return true;
}

if (_currentKey == address(0)) {
return false;
}
Expand Down Expand Up @@ -446,6 +450,9 @@ contract KeysManager is EternalStorage, IKeysManager {
{
if (_key == _oldMiningKey) return false;
if (!isMiningActive(_oldMiningKey)) return false;
if (hasMiningKeyBeenRemoved(_key)) {
return false;
}
if (!IPoaNetworkConsensus(poaNetworkConsensus()).swapValidatorKey(_key, _oldMiningKey)) {
return false;
}
Expand All @@ -461,6 +468,7 @@ contract KeysManager is EternalStorage, IKeysManager {
_setMiningKeyByVoting(votingKey, _key);
_setMiningKeyByPayout(payoutKey, _key);
_getValidatorMetadata().moveMetadata(_oldMiningKey, _key);
_setHasMiningKeyBeenRemoved(_key);
maxaleks marked this conversation as resolved.
Show resolved Hide resolved
emit MiningKeyChanged(_key, "swapped");
return true;
}
Expand Down Expand Up @@ -610,7 +618,7 @@ contract KeysManager is EternalStorage, IKeysManager {
] = _success;
}

function _setHasMiningKeyBeenRemoved(address _key) internal {
function _setHasMiningKeyBeenRemoved(address _key) private {
boolStorage[
keccak256(abi.encode(HAS_MINING_KEY_BEEN_REMOVED, _key))
] = true;
Expand Down
1 change: 0 additions & 1 deletion contracts/VotingToChangeKeys.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ contract VotingToChangeKeys is VotingToChange, EnumKeyTypes {
address _newPayoutKey
) public returns(uint256) {
IKeysManager keysManager = _getKeysManager();
require(!keysManager.hasMiningKeyBeenRemoved(_newMiningKey));
require(keysManager.miningKeyByVoting(_newVotingKey) == address(0));
require(keysManager.miningKeyByPayout(_newPayoutKey) == address(0));
require(_newVotingKey != _newMiningKey);
Expand Down