Skip to content

Commit

Permalink
fix: added DAO Operator fuzz testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohsen-T committed Jan 16, 2024
1 parent 3ce40c3 commit 437439a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
9 changes: 7 additions & 2 deletions contracts/modules/DAO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import "./SSVDAO.sol";
contract DAO is SSVDAO {
uint64 private constant MINIMAL_LIQUIDATION_THRESHOLD = 100_800;

function echidna_test(uint256 amount) public returns (bool) {
return SSVStorageProtocol.load().networkFee == amount;
constructor() {
StorageProtocol storage sp = SSVStorageProtocol.load();
sp.networkFee = 100000000 / 10;
}

function helper_updateNetworkFee(uint256 amount) public returns (bool) {
this.updateNetworkFee(amount);
}
}
8 changes: 3 additions & 5 deletions contracts/modules/Operators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ contract Operators is SSVOperators {
}

function helper_createOperator(bytes calldata publicKey, uint256 fee) public {
require(publicKey.length != 0 && publicKey[0] != 0, "invalid publicKey: cannot be empty");

uint256 maxValue = 2 ** 64 * DEDUCTED_DIGITS;

uint256 minN = (MINIMAL_OPERATOR_FEE + DEDUCTED_DIGITS - 1) / DEDUCTED_DIGITS;
uint256 maxN = maxValue / DEDUCTED_DIGITS;
uint256 maxN = SSVStorageProtocol.load().operatorMaxFee;

require(fee > minN && fee < maxN, "fee value exceeded");
fee = fee * DEDUCTED_DIGITS;
Expand All @@ -44,13 +46,11 @@ contract Operators is SSVOperators {
}
}

/*
function helper_setOperatorWhitelist(uint64 operatorId, address whitelisted) public {
operatorId = operatorId % uint64(opIds.length);

this.setOperatorWhitelist(operatorId, whitelisted);
}
*/

function helper_declareOperatorFee(uint64 operatorId) public {
operatorId = operatorId % uint64(opIds.length);
Expand Down Expand Up @@ -81,7 +81,6 @@ contract Operators is SSVOperators {
/***********
* Assertions
***********/
/*
function check_removedOperatorNotWhitelisted(uint64 operatorId) public {
operatorId = operatorId % uint64(opIds.length);

Expand All @@ -90,7 +89,6 @@ contract Operators is SSVOperators {
if ((operator.snapshot.block == 0) && operator.whitelisted)
emit AssertionFailed(operatorId, operator.whitelisted);
}
*/

function check_removedOperatorNoFeeDeclared(uint64 operatorId) public {
operatorId = 1 + (operatorId % (uint64(opIds.length) - 1));
Expand Down
2 changes: 1 addition & 1 deletion crytic-export/combined_solc.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion echidna.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
testMode: assertion
# testLimit: 50000
# multi-abi: true
# corpusDir: "corpus"
cryticArgs: ['--solc-remaps', '@openzeppelin=node_modules/@openzeppelin']
# contractAddr: '0xContractAddress'
Expand Down
4 changes: 2 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ const config: HardhatUserConfig = {
ssvToken: process.env.SSVTOKEN_ADDRESS, // if empty, deploy SSV mock token
} as SSVNetworkConfig,
hardhat: {
forking: process.env.GOERLI_ETH_NODE_URL
forking: process.env.HOLESKY_ETH_NODE_URL
? {
url: process.env.GOERLI_ETH_NODE_URL,
url: process.env.HOLESKY_ETH_NODE_URL,
// blockNumber can be specified here if needed
}
: undefined,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"slither": "slither contracts --solc-remaps @openzeppelin=node_modules/@openzeppelin",
"size-contracts": "npx hardhat size-contracts",
"install-echidna": "brew install echidna",
"run-echidna": "echidna --config echidna.yaml"
"echidna": "echidna --config echidna.yaml --contract"
},
"devDependencies": {
"@crytic/echidna": "^0.0.6",
Expand Down

0 comments on commit 437439a

Please sign in to comment.