Skip to content

Commit

Permalink
fix: updated code for SSVClusters and SSVDao
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohsen-T committed Jan 26, 2024
1 parent a400ab6 commit 4df76be
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
47 changes: 47 additions & 0 deletions contracts/modules/Clusters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,51 @@ import "./SSVClusters.sol";

contract Clusters is SSVClusters {
constructor() {}

bytes[] publicKeys;
bytes32[] hashedClusters;

uint64 private constant MIN_OPERATORS_LENGTH = 4;
uint64 private constant MAX_OPERATORS_LENGTH = 13;
uint64 private constant MODULO_OPERATORS_LENGTH = 3;
uint64 private constant PUBLIC_KEY_LENGTH = 48;

function helper_registerValidator(
bytes calldata publicKey,
uint64[] memory operatorIds,
bytes calldata sharesData,
uint256 amount,
Cluster memory cluster
) public {
require(
operatorIds.length < MIN_OPERATORS_LENGTH ||
operatorIds.length > MAX_OPERATORS_LENGTH ||
operatorIds.length % MODULO_OPERATORS_LENGTH != 1,
"Invalid OperatorIds Length"
);
require(publicKey.length == PUBLIC_KEY_LENGTH, "Invalid PublicKey Length");

bytes32 hashedCluster = keccak256(abi.encodePacked(msg.sender, operatorIds));

try this.registerValidator(publicKey, operatorIds, sharesData, amount, cluster) {
publicKeys.push(publicKey);
hashedClusters.push(hashedCluster);
} catch {
assert(false);
}
}

function check_removeValidator(uint64 publicKeyId, uint64[] calldata operatorIds, Cluster memory cluster) public {
publicKeyId = publicKeyId % uint64(publicKeys.length);

this.removeValidator(publicKeys[publicKeyId], operatorIds, cluster);
}

function check_invariant_validatorPKs() public {
StorageData storage s = SSVStorage.load();

for (uint64 i = 0; i < hashedClusters.length; i++) {
assert(s.clusters[hashedClusters[i]] == bytes32(0));
}
}
}
9 changes: 7 additions & 2 deletions contracts/modules/DAO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ contract DAO is SSVDAO {
sp.networkFee = 100000000 / 10;
}

function helper_updateNetworkFee(uint256 amount) public returns (bool) {
this.updateNetworkFee(amount);
function check_updateNetworkFee(uint256 fee) public {
this.updateNetworkFee(fee);
}

function check_invariant_networkfee() public returns (bool) {
StorageProtocol storage sp = SSVStorageProtocol.load();
assert(sp.networkFee > 0);
}
}
2 changes: 1 addition & 1 deletion crytic-export/combined_solc.json

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions echidna.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
testMode: assertion
testLimit: 2000
testLimit: 5000
corpusDir: 'echidna-corpus'
cryticArgs: ['--solc-remaps', '@openzeppelin=node_modules/@openzeppelin']
format: text
prefix: 'echidna_'
# contractAddr: '0xContractAddress'
# filterBlacklist: false
# filterFunctions: ["Operators.registerOperator(bytes,uint256)", "setOperatorWhitelist(uint64,address)"]

0 comments on commit 4df76be

Please sign in to comment.