From 02a3770803c4d7b8efde7d20338cd264d7d33b1c Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Fri, 9 Oct 2020 20:46:06 +0300 Subject: [PATCH] Adds a fuzzing test for the validator client CLI Also removes an obsolete way to add validators through the command line --- beacon_chain/conf.nim | 12 ------------ beacon_chain/keystore_management.nim | 8 -------- beacon_chain/spec/datatypes.nim | 2 +- tests/fuzzing/validator_client_cli/corpus/full.txt | 1 + tests/fuzzing/validator_client_cli/corpus/help.txt | 1 + .../fuzzing/validator_client_cli/corpus/medalla.txt | 1 + .../fuzzing/validator_client_cli/corpus/version.txt | 1 + .../fuzz_validator_client_cli.nim | 10 ++++++++++ 8 files changed, 15 insertions(+), 21 deletions(-) create mode 100644 tests/fuzzing/validator_client_cli/corpus/full.txt create mode 100644 tests/fuzzing/validator_client_cli/corpus/help.txt create mode 100644 tests/fuzzing/validator_client_cli/corpus/medalla.txt create mode 100644 tests/fuzzing/validator_client_cli/corpus/version.txt create mode 100644 tests/fuzzing/validator_client_cli/fuzz_validator_client_cli.nim diff --git a/beacon_chain/conf.nim b/beacon_chain/conf.nim index 475997a95..a0ac5021b 100644 --- a/beacon_chain/conf.nim +++ b/beacon_chain/conf.nim @@ -136,12 +136,6 @@ type "Must be one of: any, none, upnp, pmp, extip:" defaultValue: "any" }: string - validators* {. - required - desc: "Path to a validator keystore" - abbr: "v" - name: "validator" }: seq[ValidatorKeyPath] - weakSubjectivityCheckpoint* {. desc: "Weak subjectivity checkpoint in the format block_root:epoch_number" name: "weak-subjectivity-checkpoint" }: Option[Checkpoint] @@ -378,12 +372,6 @@ type desc: "Do not display interative prompts. Quit on missing configuration" name: "non-interactive" }: bool - validators* {. - required - desc: "Attach a validator by supplying a keystore path" - abbr: "v" - name: "validator" }: seq[ValidatorKeyPath] - validatorsDirFlag* {. desc: "A directory containing validator keystores" name: "validators-dir" }: Option[InputDir] diff --git a/beacon_chain/keystore_management.nim b/beacon_chain/keystore_management.nim index 53921edea..a1fc3ef83 100644 --- a/beacon_chain/keystore_management.nim +++ b/beacon_chain/keystore_management.nim @@ -243,14 +243,6 @@ iterator validatorKeysFromDirs*(validatorsDir, secretsDir: string): ValidatorPri quit 1 iterator validatorKeys*(conf: BeaconNodeConf|ValidatorClientConf): ValidatorPrivKey = - for validatorKeyFile in conf.validators: - try: - yield validatorKeyFile.load - except CatchableError as err: - error "Failed to load validator private key", - file = validatorKeyFile.string, err = err.msg - quit 1 - let validatorsDir = conf.validatorsDir try: for kind, file in walkDir(validatorsDir): diff --git a/beacon_chain/spec/datatypes.nim b/beacon_chain/spec/datatypes.nim index 6a28e198c..f628b8cc2 100644 --- a/beacon_chain/spec/datatypes.nim +++ b/beacon_chain/spec/datatypes.nim @@ -460,7 +460,7 @@ type EVRESULT_IGNORE = 2 func shortValidatorKey*(state: BeaconState, validatorIdx: int): string = - ($state.validators[validatorIdx].pubkey)[0..7] + ($state.validators[validatorIdx].pubkey)[0..7] func getDepositMessage*(depositData: DepositData): DepositMessage = result.pubkey = depositData.pubkey diff --git a/tests/fuzzing/validator_client_cli/corpus/full.txt b/tests/fuzzing/validator_client_cli/corpus/full.txt new file mode 100644 index 000000000..e6a508299 --- /dev/null +++ b/tests/fuzzing/validator_client_cli/corpus/full.txt @@ -0,0 +1 @@ +--log-level=TRACE --log-file:"foo/bar.log" --data-dir=/tmp/data --non-interactive --secrets-dir:secrets --graffiti:"some message" --graffiti:0xaa2311aa21 --stop-at-epoch:4 --rpc-port:10000 --rpc-address:127.0.0.1 --retry-delay:10 diff --git a/tests/fuzzing/validator_client_cli/corpus/help.txt b/tests/fuzzing/validator_client_cli/corpus/help.txt new file mode 100644 index 000000000..2255a80a7 --- /dev/null +++ b/tests/fuzzing/validator_client_cli/corpus/help.txt @@ -0,0 +1 @@ +--help diff --git a/tests/fuzzing/validator_client_cli/corpus/medalla.txt b/tests/fuzzing/validator_client_cli/corpus/medalla.txt new file mode 100644 index 000000000..13687148c --- /dev/null +++ b/tests/fuzzing/validator_client_cli/corpus/medalla.txt @@ -0,0 +1 @@ +build/validator_client --log-level=INFO --log-file=build/data/shared_medalla_0/nbc_vc_20201009202103.log --data-dir=build/data/shared_medalla_0 --rpc-port=9190 diff --git a/tests/fuzzing/validator_client_cli/corpus/version.txt b/tests/fuzzing/validator_client_cli/corpus/version.txt new file mode 100644 index 000000000..32776d21b --- /dev/null +++ b/tests/fuzzing/validator_client_cli/corpus/version.txt @@ -0,0 +1 @@ +--version diff --git a/tests/fuzzing/validator_client_cli/fuzz_validator_client_cli.nim b/tests/fuzzing/validator_client_cli/fuzz_validator_client_cli.nim new file mode 100644 index 000000000..24482cbd6 --- /dev/null +++ b/tests/fuzzing/validator_client_cli/fuzz_validator_client_cli.nim @@ -0,0 +1,10 @@ +import + # TODO These imports shouldn't be necessary here + # (this is a variation of the sandwich problem) + stew/shims/net, chronicles, ../../../beacon_chain/spec/network, + + confutils/cli_parsing_fuzzer, + ../../../beacon_chain/conf + +fuzzCliParsing ValidatorClientConf +