From 2d1031ba7bfe5978a235ad28318d920847a1ffe7 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Fri, 24 Apr 2020 09:26:16 +0200 Subject: [PATCH] accounts/keystore: added test case for zeroKey --- accounts/keystore/keystore.go | 1 + accounts/keystore/keystore_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/accounts/keystore/keystore.go b/accounts/keystore/keystore.go index f791ad0b3e..5fe29c7c05 100644 --- a/accounts/keystore/keystore.go +++ b/accounts/keystore/keystore.go @@ -495,5 +495,6 @@ func (ks *KeyStore) ImportPreSaleKey(keyJSON []byte, passphrase string) (account // zeroKey zeroes a private key in memory. func zeroKey(k *ecdsa.PrivateKey) { + k.PublicKey = ecdsa.PublicKey{} k.D.SetUint64(uint64(0)) } diff --git a/accounts/keystore/keystore_test.go b/accounts/keystore/keystore_test.go index 29c251d7c1..9ade8ac46d 100644 --- a/accounts/keystore/keystore_test.go +++ b/accounts/keystore/keystore_test.go @@ -18,6 +18,7 @@ package keystore import ( "io/ioutil" + "math/big" "math/rand" "os" "runtime" @@ -218,6 +219,17 @@ func TestSignRace(t *testing.T) { t.Errorf("Account did not lock within the timeout") } +func TestZeroKey(t *testing.T) { + key, err := crypto.GenerateKey() + if err != nil { + t.Fatalf("failed to generate key: %v", key) + } + zeroKey(key) + if key.D.Cmp(big.NewInt(0)) != 0 { + t.Fatalf("failed to zero out key: %v", key) + } +} + // Tests that the wallet notifier loop starts and stops correctly based on the // addition and removal of wallet event subscriptions. func TestWalletNotifierLifecycle(t *testing.T) {