From 527eb79a0272a4a762dc758681aecd4a8a3ac394 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Sat, 4 Nov 2023 18:13:08 +0100 Subject: [PATCH] fuzzing: move keystore fuzzer --- .../keystore/keystore_fuzzing_test.go | 17 +++++++-- oss-fuzz.sh | 36 ++++++++---------- tests/fuzzers/keystore/keystore-fuzzer.go | 37 ------------------- 3 files changed, 28 insertions(+), 62 deletions(-) rename tests/fuzzers/keystore/keystore_test.go => accounts/keystore/keystore_fuzzing_test.go (72%) delete mode 100644 tests/fuzzers/keystore/keystore-fuzzer.go diff --git a/tests/fuzzers/keystore/keystore_test.go b/accounts/keystore/keystore_fuzzing_test.go similarity index 72% rename from tests/fuzzers/keystore/keystore_test.go rename to accounts/keystore/keystore_fuzzing_test.go index 167ff6c471..793b46336a 100644 --- a/tests/fuzzers/keystore/keystore_test.go +++ b/accounts/keystore/keystore_fuzzing_test.go @@ -16,10 +16,19 @@ package keystore -import "testing" +import ( + "testing" +) -func Fuzz(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - fuzz(data) +func FuzzPassword(f *testing.F) { + f.Fuzz(func(t *testing.T, password string) { + ks := NewKeyStore(t.TempDir(), LightScryptN, LightScryptP) + a, err := ks.NewAccount(password) + if err != nil { + t.Fatal(err) + } + if err := ks.Unlock(a, password); err != nil { + t.Fatal(err) + } }) } diff --git a/oss-fuzz.sh b/oss-fuzz.sh index b6b74d01b0..121af840c6 100644 --- a/oss-fuzz.sh +++ b/oss-fuzz.sh @@ -81,31 +81,31 @@ function compile_fuzzer() { go install github.com/holiman/gofuzz-shim@latest -#compile_fuzzer accounts/abi FuzzABI fuzzAbi -compile_fuzzer github.com/ethereum/go-ethereum/accounts/abi FuzzABI fuzzAbi +# compile_fuzzer github.com/ethereum/go-ethereum/accounts/abi FuzzABI fuzzAbi +# compile_fuzzer github.com/ethereum/go-ethereum/common/bitutil FuzzEncoder fuzzBitutilEncoder +# compile_fuzzer github.com/ethereum/go-ethereum/common/bitutil FuzzDecoder fuzzBitutilDecoder +# compile_fuzzer github.com/ethereum/go-ethereum/core/vm/runtime FuzzVmRuntime fuzzVmRuntime +# compile_fuzzer github.com/ethereum/go-ethereum/core/vm FuzzPrecompiledContracts fuzzPrecompiledContracts +# compile_fuzzer github.com/ethereum/go-ethereum/core/types FuzzRLP fuzzRlp -#compile_fuzzer common/bitutil FuzzEncoder fuzzBitutilEncoder -compile_fuzzer github.com/ethereum/go-ethereum/common/bitutil FuzzEncoder fuzzBitutilEncoder +compile_fuzzer github.com/ethereum/go-ethereum/crypto/blake2b Fuzz fuzzBlake2b -#compile_fuzzer common/bitutil FuzzDecoder fuzzBitutilDecoder -compile_fuzzer github.com/ethereum/go-ethereum/common/bitutil FuzzDecoder fuzzBitutilDecoder +compile_fuzzer github.com/ethereum/go-ethereum/accounts/keystore FuzzPassword fuzzKeystore -#compile_fuzzer core/vm/runtime FuzzVmRuntime fuzzVmRuntime -compile_fuzzer github.com/ethereum/go-ethereum/core/vm/runtime FuzzVmRuntime fuzzVmRuntime +#compile_fuzzer tests/fuzzers/trie Fuzz fuzzTrie +#compile_fuzzer tests/fuzzers/stacktrie Fuzz fuzzStackTrie + +#compile_fuzzer tests/fuzzers/snap FuzzARange fuzz_account_range +#compile_fuzzer tests/fuzzers/snap FuzzSRange fuzz_storage_range +#compile_fuzzer tests/fuzzers/snap FuzzByteCodes fuzz_byte_codes +#compile_fuzzer tests/fuzzers/snap FuzzTrieNodes fuzz_trie_nodes -#compile_fuzzer core/vm FuzzPrecompiledContracts fuzzPrecompiledContracts -compile_fuzzer github.com/ethereum/go-ethereum/core/vm FuzzPrecompiledContracts fuzzPrecompiledContracts -#compile_fuzzer core/types/ FuzzRLP fuzzRlp -compile_fuzzer github.com/ethereum/go-ethereum/core/types FuzzRLP fuzzRlp #compile_fuzzer tests/fuzzers/bn256 FuzzAdd fuzzBn256Add #compile_fuzzer tests/fuzzers/bn256 FuzzMul fuzzBn256Mul #compile_fuzzer tests/fuzzers/bn256 FuzzPair fuzzBn256Pair -#compile_fuzzer tests/fuzzers/keystore Fuzz fuzzKeystore #compile_fuzzer tests/fuzzers/txfetcher Fuzz fuzzTxfetcher -#compile_fuzzer tests/fuzzers/trie Fuzz fuzzTrie -#compile_fuzzer tests/fuzzers/stacktrie Fuzz fuzzStackTrie #compile_fuzzer tests/fuzzers/difficulty Fuzz fuzzDifficulty #compile_fuzzer tests/fuzzers/les Fuzz fuzzLes #compile_fuzzer tests/fuzzers/secp256k1 Fuzz fuzzSecp256k1 @@ -126,9 +126,3 @@ compile_fuzzer github.com/ethereum/go-ethereum/core/types FuzzRLP fuzzRlp #compile_fuzzer tests/fuzzers/bls12381 FuzzCrossG2Add fuzz_cross_g2_add #compile_fuzzer tests/fuzzers/bls12381 FuzzCrossPairing fuzz_cross_pairing -#compile_fuzzer tests/fuzzers/snap FuzzARange fuzz_account_range -#compile_fuzzer tests/fuzzers/snap FuzzSRange fuzz_storage_range -#compile_fuzzer tests/fuzzers/snap FuzzByteCodes fuzz_byte_codes -#compile_fuzzer tests/fuzzers/snap FuzzTrieNodes fuzz_trie_nodes - -#compile_fuzzer crypto/blake2b Fuzz fuzzBlake2b diff --git a/tests/fuzzers/keystore/keystore-fuzzer.go b/tests/fuzzers/keystore/keystore-fuzzer.go deleted file mode 100644 index 07a85d77b5..0000000000 --- a/tests/fuzzers/keystore/keystore-fuzzer.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2019 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see . - -package keystore - -import ( - "os" - - "github.com/ethereum/go-ethereum/accounts/keystore" -) - -func fuzz(input []byte) int { - ks := keystore.NewKeyStore("/tmp/ks", keystore.LightScryptN, keystore.LightScryptP) - - a, err := ks.NewAccount(string(input)) - if err != nil { - panic(err) - } - if err := ks.Unlock(a, string(input)); err != nil { - panic(err) - } - os.Remove(a.URL.Path) - return 1 -}