Skip to content

Commit

Permalink
Add pubkeyAddressToValidatorID mapping (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
thaarok committed Sep 4, 2024
1 parent c950937 commit 915f4e8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion contracts/sfc/SFC.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6.0;

import "./GasPriceConstants.sol";
import "../version/Version.sol";
Expand Down Expand Up @@ -134,8 +134,13 @@ contract SFC is SFCBase, Version {
require(pubkeyHashToValidatorID[keccak256(pubkey)] == 0, "already used");
require(validatorPubkeyChanges[validatorID] == 0 || validatorID == 64 || validatorID <= 12, "allowed only once");

address oldAddress = address(uint160(uint256(keccak256(getValidatorPubkey[validatorID][2:]))));
address newAddress = address(uint160(uint256(keccak256(pubkey[2:]))));

validatorPubkeyChanges[validatorID]++;
pubkeyHashToValidatorID[keccak256(pubkey)] = validatorID;
pubkeyAddressToValidatorID[oldAddress] = 0;
pubkeyAddressToValidatorID[newAddress] = validatorID;
getValidatorPubkey[validatorID] = pubkey;
_syncValidator(validatorID, true);
}
Expand Down
5 changes: 3 additions & 2 deletions contracts/sfc/SFCLib.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6.0;

import "../common/Decimal.sol";
import "./GasPriceConstants.sol";
Expand Down Expand Up @@ -63,7 +63,7 @@ contract SFCLib is SFCBase {
_rawCreateValidator(auth, validatorID, pubkey, OK_STATUS, currentEpoch(), _now(), 0, 0);
}

function _rawCreateValidator(address auth, uint256 validatorID, bytes memory pubkey, uint256 status, uint256 createdEpoch, uint256 createdTime, uint256 deactivatedEpoch, uint256 deactivatedTime) internal {
function _rawCreateValidator(address auth, uint256 validatorID, bytes calldata pubkey, uint256 status, uint256 createdEpoch, uint256 createdTime, uint256 deactivatedEpoch, uint256 deactivatedTime) internal {
require(getValidatorID[auth] == 0, "validator already exists");
getValidatorID[auth] = validatorID;
getValidator[validatorID].status = status;
Expand All @@ -74,6 +74,7 @@ contract SFCLib is SFCBase {
getValidator[validatorID].auth = auth;
getValidatorPubkey[validatorID] = pubkey;
pubkeyHashToValidatorID[keccak256(pubkey)] = validatorID;
pubkeyAddressToValidatorID[address(uint160(uint256(keccak256(pubkey[2:]))))] = validatorID;

emit CreatedValidator(validatorID, auth, createdEpoch, createdTime);
if (deactivatedEpoch != 0) {
Expand Down
2 changes: 2 additions & 0 deletions contracts/sfc/SFCState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,6 @@ contract SFCState is Initializable, Ownable {
mapping(address => address) public getRedirectionRequest;

mapping(address => address) public getRedirection;

mapping(address => uint256) internal pubkeyAddressToValidatorID;
}

0 comments on commit 915f4e8

Please sign in to comment.