fuzzing: move keystore fuzzer

This commit is contained in:
Martin Holst Swende 2023-11-04 18:13:08 +01:00
parent 5059a5a714
commit 527eb79a02
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
3 changed files with 28 additions and 62 deletions

View file

@ -16,10 +16,19 @@
package keystore package keystore
import "testing" import (
"testing"
)
func Fuzz(f *testing.F) { func FuzzPassword(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, password string) {
fuzz(data) 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)
}
}) })
} }

View file

@ -81,31 +81,31 @@ function compile_fuzzer() {
go install github.com/holiman/gofuzz-shim@latest 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/crypto/blake2b Fuzz fuzzBlake2b
compile_fuzzer github.com/ethereum/go-ethereum/common/bitutil FuzzEncoder fuzzBitutilEncoder
#compile_fuzzer common/bitutil FuzzDecoder fuzzBitutilDecoder compile_fuzzer github.com/ethereum/go-ethereum/accounts/keystore FuzzPassword fuzzKeystore
compile_fuzzer github.com/ethereum/go-ethereum/common/bitutil FuzzDecoder fuzzBitutilDecoder
#compile_fuzzer core/vm/runtime FuzzVmRuntime fuzzVmRuntime #compile_fuzzer tests/fuzzers/trie Fuzz fuzzTrie
compile_fuzzer github.com/ethereum/go-ethereum/core/vm/runtime FuzzVmRuntime fuzzVmRuntime #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 FuzzAdd fuzzBn256Add
#compile_fuzzer tests/fuzzers/bn256 FuzzMul fuzzBn256Mul #compile_fuzzer tests/fuzzers/bn256 FuzzMul fuzzBn256Mul
#compile_fuzzer tests/fuzzers/bn256 FuzzPair fuzzBn256Pair #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/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/difficulty Fuzz fuzzDifficulty
#compile_fuzzer tests/fuzzers/les Fuzz fuzzLes #compile_fuzzer tests/fuzzers/les Fuzz fuzzLes
#compile_fuzzer tests/fuzzers/secp256k1 Fuzz fuzzSecp256k1 #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 FuzzCrossG2Add fuzz_cross_g2_add
#compile_fuzzer tests/fuzzers/bls12381 FuzzCrossPairing fuzz_cross_pairing #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

View file

@ -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 <http://www.gnu.org/licenses/>.
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
}