Skip to content

Commit

Permalink
fuzz: add crypto/hd.DerivePrivateKeyForPath (#9135)
Browse files Browse the repository at this point in the history
Updates #7921.
  • Loading branch information
odeke-em committed Apr 22, 2021
1 parent 38de376 commit 040a2b0
Show file tree
Hide file tree
Showing 114 changed files with 141 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m /4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m /4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m      /4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1/1/0/11/0/1/0/1/0/1/0/0/0/0/0/0/0/0/0/1/0/0/1/0/1/0/1/0/0/0/0/0/1/1/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1/1/0/11/0/1/0/1/0/1/0/0/0/0/0/0/0/0/0/0/1/1/0/0/130/0/0/0/0/1/0/0/0/1/0/0/10/0/0/0/0/1/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I ald*1/7
1 change: 1 addition & 0 deletions fuzz/crypto/hd/DerivePrivateKeyForPath/corpus/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am become Death, the destroyer of worlds!*m/1'/2147483647'/1/0'/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m                                    /9
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m                                  /9
1 change: 1 addition & 0 deletions fuzz/crypto/hd/DerivePrivateKeyForPath/corpus/2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
artwork blanket carpet cricket disorder disorder artwork blanket carpet cricket disorder disorder*1'/2147483647'/1/0'/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m           /6
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* m/4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*  m /4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m /4
1 change: 1 addition & 0 deletions fuzz/crypto/hd/DerivePrivateKeyForPath/corpus/3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
carpet cricket disorder cricket cricket artwork carpet cricket disorder cricket cricket artwork*m/44'/0'/0'/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m                                        /9
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1'/8'/0'/1'/8'/8'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m                           /3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m                  /9
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
8CKrN2cPg/Fvyt0Xlp/DoCzjA0CQQDU
y2ptGsuSmgUtWj3NM9xuwYPm+Z/F84K6+ARYiZ6PYj013sovGKUFfYAqVXVlxtIX
qyUBnu3X9ps8ZfjLZO7BAkEAlT4R5Yl6cGhaJQYZHOde3JEMhNRcVFMO8dJDaFeo
f9Oeos0UUothgiDktdQHxdNEwLjQf7lJJBzV+5OtwswCWA==
-----END RSA TESTING KEY-----* m/4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
der*1'/8/1/0'/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s*1/3/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/0
1 change: 1 addition & 0 deletions fuzz/crypto/hd/DerivePrivateKeyForPath/corpus/4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wolf afraid artwork blanket carpet cricket wolf afraid artwork blanket carpet cricket*m/44'/118'/52'/1/41
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wlardartwor blnkt capetcicket wolf afraid artwork blarket carpet cricket*44'/118'/52'/1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m    /4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m /4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* m /4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m      /4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m/1*
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* m/4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1'/8'/0'/8'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*  m/4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!*1/1/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m          /6
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*  m/4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m /4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c*5/1/4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*5/1////
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1/1/0/1/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1/1/0/0/0/0/0/1/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
der*1/8/11/4/0'/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* m /6
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1'/8'/0'/1'/0'/5'/8'/8'/8'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
der*1'/8/11/4/0'/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m/1***
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1/1/0/1/0/11/0/0/0/0/0/1/1/0/0/0/0/0/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*5/1//
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1/1/0/11/0/1/0/1/0/1/0/0/0/0/0/0/0/0/0/1/0/0/1/0/1/0/1/0/0/0/0/0/1/1/0/1/0/0/0/0/0/1/1/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*  m/4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m/4/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!*1/1/0/0/0/0/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am ecome Death, the destroyer of worlds!*m/1'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* m/4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*  m/4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m /4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m/1*********************************************************************
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s/0/*1/1/0/0/1/1/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m/1**
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*5/1////////////////
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1/1/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m/1****************
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m                  /3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* m/4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* m/4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* m/4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m                                      /9
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m /6
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* m/4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1'/8'/8'/0'/1'/0'/5'/8'/8'/8'/0'/1'/0'/5'/8'/8'/8'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1/1/0/1/0/1/0/0/0/0/0/1/1/0/0/0/5/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m       /4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1/1/0/11/0/1/0/1/0/1/0/0/0/0/0/0/0/0/0/0/1/1/0/0/0/0/0/0/130/0/0/0/1/0/1/0/1/0/0/0/0/0/1/1/0/0/0/0/0/1/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wolf af*1/1/0/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m/1********
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wlardartwor blnkt capetcicket wolf afraid artwork blanket carpet cricket*44'/118'/52'/1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m      /4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m     /4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s�*1/1/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!*1/1/0/0/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*5/1////////
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s*1/1/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* m /4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wlardarafraidket carpet cricket*44'/118'/52/1/4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
de�*1/8/4/0/1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m    /4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* m /4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s*1/1/0/0/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1/81/1375175421/469062971/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m   /4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m                                 /9
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s!*1/1/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1/1/0/1/0/1/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*111/0/11/0/1/0/1/0/1/0/0/0/0/0/0/0/0/0/1/1/0/0/0/0/0/0/1/0/0/0/0/0/1/0/1/0/1/0/0/0/0/1/1/0/0/0/0/0/0/100/0/1/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m /4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* m /6
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
de�*1/8/11/4/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e!*1/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1/1/0/11/0/1/0/1/0/1/0/0/0/0/0/0/0/0/0/0/1/1/0/0/130/0/0/0/0/1/0/4/0/1/0/0/1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*  m/4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m  /4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1/1/0/11/0/1/0/1/0/1/0/0/0/0/0/0/0/0/0/1/1/0/0/0/0/0/0/130/0/0/0/0/1/0/1/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/1/0/0/0/0/0/1/1/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1/1/0/11/0/1/0/1/0/1/0/0/0/0/0/0/0/0/0/1/1/0/0/0/0/0/0/1/0/0/0/0/0/1/0/1/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1/1/0/1/0/0/0/0/0/1/0/1/0/0/0/0/0/1/1/0/0/0/0/01/0/0/0/0/0/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m/1********************************
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m           /4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*1/1/0/1/0/11/0/0/0/0/0/1/1/0/0/0/0/0/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m  /4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s*1/1/0/0/1/1/0/0/0/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*m                               /9
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s*11/4/1/0
Binary file not shown.
27 changes: 27 additions & 0 deletions fuzz/crypto/hd/DerivePrivateKeyForPath/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package derive

import (
"bytes"

"github.com/cosmos/cosmos-sdk/crypto/hd"
bip39 "github.com/cosmos/go-bip39"
)

func mnemonicToSeed(mnemonic string) []byte {
return bip39.NewSeed(mnemonic, "" /* Default passphrase */)
}

func Fuzz(in []byte) int {
splits := bytes.Split(in, []byte("*"))
if len(splits) == 1 {
return -1
}
mnemonic, path := splits[0], splits[1]
seed := mnemonicToSeed(string(mnemonic))
master, ch := hd.ComputeMastersFromSeed(seed)
_, err := hd.DerivePrivateKeyForPath(master, ch, string(path))
if err == nil {
return 1
}
return -1
}
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ require (
github.com/cosmos/iavl v0.15.3
github.com/cosmos/ledger-cosmos-go v0.11.1
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dvyukov/go-fuzz v0.0.0-20210412031127-69125664ebf2 // indirect
github.com/elazarl/go-bindata-assetfs v1.0.1 // indirect
github.com/enigmampc/btcutil v1.0.3-0.20200723161021-e2fb6adb2a25
github.com/gogo/gateway v1.1.0
github.com/gogo/protobuf v1.3.3
Expand Down Expand Up @@ -46,7 +44,6 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.1
github.com/stephens2424/writerset v1.0.2 // indirect
github.com/stretchr/testify v1.7.0
github.com/tendermint/btcd v0.1.1
github.com/tendermint/cosmos-rosetta-gateway v0.3.0-rc2.0.20210304154332-87d6ca4410df
Expand All @@ -55,7 +52,6 @@ require (
github.com/tendermint/tendermint v0.34.10
github.com/tendermint/tm-db v0.6.4
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/mod v0.4.2 // indirect
golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0 // indirect
google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f
google.golang.org/grpc v1.37.0
Expand Down
Loading

0 comments on commit 040a2b0

Please sign in to comment.