Skip to content

Commit

Permalink
2 register validator functions, all tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
mtabasco committed Dec 13, 2023
1 parent c5b63db commit d24c4a2
Show file tree
Hide file tree
Showing 9 changed files with 663 additions and 46 deletions.
248 changes: 248 additions & 0 deletions .openzeppelin/unknown-17000.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
"address": "0x352A18AEe90cdcd825d1E37d9939dCA86C00e281",
"txHash": "0xf36e0e114031e961a1e3452477ed71658cf0f809be94832b4dc4a99a293ef664",
"kind": "uups"
},
{
"address": "0x4fA60408D9c0428b43FCa0E26c2f9aAa510cCeE2",
"txHash": "0x72d9a2c0e2442046a87816203f08b0ad4cb65ef25de40c59c5fe4f83b8834370",
"kind": "uups"
},
{
"address": "0xEa0Fd295Be44Fb909d654dA90198c8E9d766FB74",
"txHash": "0x8cbbb4f8c3fa01e88d0aed6ffcccab3c063d332bf465541a4515fe3070177687",
"kind": "uups"
}
],
"impls": {
Expand Down Expand Up @@ -366,6 +376,244 @@
}
}
}
},
"a2e4bdeb66cec5b0f1a0fc4da857b0ca0211440ce18b5bd191e6a9b185e68499": {
"address": "0xe2a32e5501d4DdF3384b154caed0767f1a1eAdA5",
"txHash": "0x412ecc146a6550790a9140a97df6f3744b4f1e01e3f465717c0665abed59d045",
"layout": {
"solcVersion": "0.8.18",
"storage": [
{
"label": "_initialized",
"offset": 0,
"slot": "0",
"type": "t_uint8",
"contract": "Initializable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:63",
"retypedFrom": "bool"
},
{
"label": "_initializing",
"offset": 1,
"slot": "0",
"type": "t_bool",
"contract": "Initializable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:68"
},
{
"label": "__gap",
"offset": 0,
"slot": "1",
"type": "t_array(t_uint256)50_storage",
"contract": "ERC1967UpgradeUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol:169"
},
{
"label": "__gap",
"offset": 0,
"slot": "51",
"type": "t_array(t_uint256)50_storage",
"contract": "UUPSUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol:111"
},
{
"label": "__gap",
"offset": 0,
"slot": "101",
"type": "t_array(t_uint256)50_storage",
"contract": "ContextUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:36"
},
{
"label": "_owner",
"offset": 0,
"slot": "151",
"type": "t_address",
"contract": "OwnableUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:22"
},
{
"label": "__gap",
"offset": 0,
"slot": "152",
"type": "t_array(t_uint256)49_storage",
"contract": "OwnableUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:94"
},
{
"label": "_pendingOwner",
"offset": 0,
"slot": "201",
"type": "t_address",
"contract": "Ownable2StepUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol:27"
},
{
"label": "__gap",
"offset": 0,
"slot": "202",
"type": "t_array(t_uint256)49_storage",
"contract": "Ownable2StepUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol:70"
}
],
"types": {
"t_address": {
"label": "address",
"numberOfBytes": "20"
},
"t_array(t_uint256)49_storage": {
"label": "uint256[49]",
"numberOfBytes": "1568"
},
"t_array(t_uint256)50_storage": {
"label": "uint256[50]",
"numberOfBytes": "1600"
},
"t_bool": {
"label": "bool",
"numberOfBytes": "1"
},
"t_uint256": {
"label": "uint256",
"numberOfBytes": "32"
},
"t_uint8": {
"label": "uint8",
"numberOfBytes": "1"
}
},
"namespaces": {}
}
},
"8a3382629da06790720d2d37ed76d51b1f949d6c3b17919f08f3b6842b9de108": {
"address": "0x559f1C453E01B91864864C9BBEB353916f4fF2EE",
"txHash": "0x5287d31696b60626b0e02ddb29ae27adc75ab7ad1311f1fe5181eb915e7413a4",
"layout": {
"solcVersion": "0.8.18",
"storage": [
{
"label": "_initialized",
"offset": 0,
"slot": "0",
"type": "t_uint8",
"contract": "Initializable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:63",
"retypedFrom": "bool"
},
{
"label": "_initializing",
"offset": 1,
"slot": "0",
"type": "t_bool",
"contract": "Initializable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:68"
},
{
"label": "__gap",
"offset": 0,
"slot": "1",
"type": "t_array(t_uint256)50_storage",
"contract": "ERC1967UpgradeUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol:169"
},
{
"label": "__gap",
"offset": 0,
"slot": "51",
"type": "t_array(t_uint256)50_storage",
"contract": "UUPSUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol:111"
},
{
"label": "__gap",
"offset": 0,
"slot": "101",
"type": "t_array(t_uint256)50_storage",
"contract": "ContextUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:36"
},
{
"label": "_owner",
"offset": 0,
"slot": "151",
"type": "t_address",
"contract": "OwnableUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:22"
},
{
"label": "__gap",
"offset": 0,
"slot": "152",
"type": "t_array(t_uint256)49_storage",
"contract": "OwnableUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:94"
},
{
"label": "_pendingOwner",
"offset": 0,
"slot": "201",
"type": "t_address",
"contract": "Ownable2StepUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol:27"
},
{
"label": "__gap",
"offset": 0,
"slot": "202",
"type": "t_array(t_uint256)49_storage",
"contract": "Ownable2StepUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol:70"
},
{
"label": "ssvNetwork",
"offset": 0,
"slot": "251",
"type": "t_contract(ISSVViews)4299",
"contract": "SSVNetworkViews",
"src": "contracts/SSVNetworkViews.sol:19"
},
{
"label": "__gap",
"offset": 0,
"slot": "252",
"type": "t_array(t_uint256)50_storage",
"contract": "SSVNetworkViews",
"src": "contracts/SSVNetworkViews.sol:23"
}
],
"types": {
"t_address": {
"label": "address",
"numberOfBytes": "20"
},
"t_array(t_uint256)49_storage": {
"label": "uint256[49]",
"numberOfBytes": "1568"
},
"t_array(t_uint256)50_storage": {
"label": "uint256[50]",
"numberOfBytes": "1600"
},
"t_bool": {
"label": "bool",
"numberOfBytes": "1"
},
"t_contract(ISSVViews)4299": {
"label": "contract ISSVViews",
"numberOfBytes": "20"
},
"t_uint256": {
"label": "uint256",
"numberOfBytes": "32"
},
"t_uint8": {
"label": "uint8",
"numberOfBytes": "1"
}
},
"namespaces": {}
}
}
}
}
12 changes: 11 additions & 1 deletion contracts/SSVNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,19 @@ contract SSVNetwork is
/*******************************/

function registerValidator(
bytes calldata publicKey,
uint64[] memory operatorIds,
bytes calldata shares,
uint256 amount,
ISSVNetworkCore.Cluster memory cluster
) external override {
_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_CLUSTERS]);
}

function bulkRegisterValidator(
bytes[] calldata publicKeys,
uint64[] memory operatorIds,
bytes[] calldata shares,
bytes[] calldata sharesData,
uint256 amount,
ISSVNetworkCore.Cluster memory cluster
) external override {
Expand Down
20 changes: 17 additions & 3 deletions contracts/interfaces/ISSVClusters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,29 @@ import "./ISSVNetworkCore.sol";

interface ISSVClusters is ISSVNetworkCore {
/// @notice Registers a new validator on the SSV Network
/// @param publicKeys The public key of the new validator
/// @param publicKey The public key of the new validator
/// @param operatorIds Array of IDs of operators managing this validator
/// @param shares Encrypted shares related to the new validator
/// @param sharesData Encrypted shares related to the new validator
/// @param amount Amount of SSV tokens to be deposited
/// @param cluster Cluster to be used with the new validator
function registerValidator(
bytes calldata publicKey,
uint64[] memory operatorIds,
bytes calldata sharesData,
uint256 amount,
Cluster memory cluster
) external;

/// @notice Registers new validators on the SSV Network
/// @param publicKeys The public key of the new validator
/// @param operatorIds Array of IDs of operators managing this validator
/// @param sharesData Encrypted shares related to the new validator
/// @param amount Amount of SSV tokens to be deposited
/// @param cluster Cluster to be used with the new validator
function bulkRegisterValidator(
bytes[] calldata publicKeys,
uint64[] memory operatorIds,
bytes[] calldata shares,
bytes[] calldata sharesData,
uint256 amount,
Cluster memory cluster
) external;
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ISSVNetworkCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface ISSVNetworkCore {
}

/// @notice Represents a cluster of validators
struct Cluster {
struct Cluster {

Check failure on line 44 in contracts/interfaces/ISSVNetworkCore.sol

View workflow job for this annotation

GitHub Actions / ci

Expected indentation of 4 spaces but found 8
/// @dev The number of validators in the cluster
uint32 validatorCount;
/// @dev The index of network fees related to this cluster
Expand Down
26 changes: 17 additions & 9 deletions contracts/libraries/ValidatorLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,28 @@ import "./SSVStorage.sol";
library ValidatorLib {
uint64 private constant PUBLIC_KEY_LENGTH = 48;

function registerPublicKeys(bytes[] calldata publicKeys, uint64[] memory operatorIds, StorageData storage s) internal {
function registerPublicKeys(
bytes[] calldata publicKeys,
uint64[] memory operatorIds,
StorageData storage s
) internal {
for (uint i; i < publicKeys.length; ++i) {
if (publicKeys[i].length != PUBLIC_KEY_LENGTH) {
revert ISSVNetworkCore.InvalidPublicKeyLength();
}
resgisterPublicKey(publicKeys[i], operatorIds, s);
}
}

bytes32 hashedPk = keccak256(abi.encodePacked(publicKeys[i], msg.sender));
function resgisterPublicKey(bytes memory publicKey, uint64[] memory operatorIds, StorageData storage s) internal {
if (publicKey.length != PUBLIC_KEY_LENGTH) {
revert ISSVNetworkCore.InvalidPublicKeyLength();
}

if (s.validatorPKs[hashedPk] != bytes32(0)) {
revert ISSVNetworkCore.ValidatorAlreadyExists();
}
bytes32 hashedPk = keccak256(abi.encodePacked(publicKey, msg.sender));

s.validatorPKs[hashedPk] = bytes32(uint256(keccak256(abi.encodePacked(operatorIds))) | uint256(0x01)); // set LSB to 1
if (s.validatorPKs[hashedPk] != bytes32(0)) {
revert ISSVNetworkCore.ValidatorAlreadyExists();
}

s.validatorPKs[hashedPk] = bytes32(uint256(keccak256(abi.encodePacked(operatorIds))) | uint256(0x01)); // set LSB to 1
}

function validateState(
Expand Down
Loading

0 comments on commit d24c4a2

Please sign in to comment.