Skip to content

Commit eca3b4b

Browse files
Deneb Support (#104)
* real block and sig * add too big index test * add more test for the right derivation path * Fix relative path validation regex in `validateRelativePath` --------- Co-authored-by: moshe-blox <[email protected]>
1 parent 4a62c72 commit eca3b4b

10 files changed

+327
-469
lines changed

core/hd_key_test.go

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,41 @@ func TestDerivableKeyRelativePathDerivation(t *testing.T) {
164164
err: nil,
165165
expectedKey: _bigIntFromSkHex("aaa63a09aa2c0ce6a2a29940df8981eeefac0ea193bf90f2e06edd41356054f2907bc2e1eb5aaa4097361841914cd274"),
166166
},
167+
{
168+
name: "Base account derivation (too big index)",
169+
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
170+
path: "/1000/0", // after basePath
171+
err: nil,
172+
expectedKey: _bigIntFromSkHex("843e5a2e02693309cc14de8ee6b616bffc7a1aa16d670ff906a39bd3792630917b325669b1c9057d4209bf153e7ba7b5"),
173+
},
174+
{
175+
name: "Base account derivation (too big index) in second position",
176+
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
177+
path: "/0/1000", // after basePath
178+
err: nil,
179+
expectedKey: _bigIntFromSkHex("870d7a7eade91784962604e141bc5072a6ba485c873b4934b197afba02cf56625fbbf5e98b278acc17bd040268f8c326"),
180+
},
181+
{
182+
name: "Large Number in First Position",
183+
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
184+
path: "/1000/0/0",
185+
err: nil,
186+
expectedKey: _bigIntFromSkHex("b3befa8735a59a2371dc0db8c82738715bd8fb887ad245a5042396773dd08208e45b1067df61e02e9cfe6dddc5116c9f"),
187+
},
188+
{
189+
name: "Large Number in Second Position",
190+
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
191+
path: "/0/1000/0",
192+
err: nil,
193+
expectedKey: _bigIntFromSkHex("ac65c29d1c94a4fd9a58a625ada6fe8587c85f963f6ff01bf8040108c0acb7f1334e1db9ce389c6da64bca8ab3061cbc"),
194+
},
195+
{
196+
name: "Large Number in Third Position",
197+
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
198+
path: "/0/0/1000",
199+
err: nil,
200+
expectedKey: _bigIntFromSkHex("8ed2b33e1550274715e371cd6134cda81545e36d1b39ede4e3ac6b25728a1575464a985ac01e4b11553f2ef26f1269fb"),
201+
},
167202
{
168203
name: "bad path",
169204
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
@@ -172,9 +207,23 @@ func TestDerivableKeyRelativePathDerivation(t *testing.T) {
172207
expectedKey: nil,
173208
},
174209
{
175-
name: "too large of an index, bad path",
210+
name: "bad path (too long)",
176211
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
177-
path: "/1000/0", // after basePath
212+
path: "0/0/0/0", // after basePath
213+
err: errors.New("invalid relative path. Example: /1/2/3"),
214+
expectedKey: nil,
215+
},
216+
{
217+
name: "bad path (too short)",
218+
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
219+
path: "0", // after basePath
220+
err: errors.New("invalid relative path. Example: /1/2/3"),
221+
expectedKey: nil,
222+
},
223+
{
224+
name: "bad path (too short 2)",
225+
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
226+
path: "/0/9/", // after basePath
178227
err: errors.New("invalid relative path. Example: /1/2/3"),
179228
expectedKey: nil,
180229
},
@@ -185,6 +234,48 @@ func TestDerivableKeyRelativePathDerivation(t *testing.T) {
185234
err: errors.New("invalid relative path. Example: /1/2/3"),
186235
expectedKey: nil,
187236
},
237+
{
238+
name: "Negative Index Handling",
239+
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
240+
path: "/-1/0/0",
241+
err: errors.New("invalid relative path. Example: /1/2/3"),
242+
expectedKey: nil,
243+
},
244+
{
245+
name: "Negative Index Handling",
246+
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
247+
path: "/0/-1/0",
248+
err: errors.New("invalid relative path. Example: /1/2/3"),
249+
expectedKey: nil,
250+
},
251+
{
252+
name: "Negative Index Handling",
253+
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
254+
path: "/0/0/-1",
255+
err: errors.New("invalid relative path. Example: /1/2/3"),
256+
expectedKey: nil,
257+
},
258+
{
259+
name: "Empty String Path",
260+
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
261+
path: "",
262+
err: errors.New("invalid relative path. Example: /1/2/3"),
263+
expectedKey: nil,
264+
},
265+
{
266+
name: "Only Slashes in Path",
267+
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
268+
path: "///",
269+
err: errors.New("invalid relative path. Example: /1/2/3"),
270+
expectedKey: nil,
271+
},
272+
{
273+
name: "Minimum Group Path",
274+
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
275+
path: "/0",
276+
err: errors.New("invalid relative path. Example: /1/2/3"),
277+
expectedKey: nil,
278+
},
188279
}
189280

190281
for _, test := range tests {

core/master_derivable_key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ func (master *MasterDerivableKey) Derive(relativePath string) (*HDKey, error) {
8888
}
8989

9090
func validateRelativePath(relativePath string) bool {
91-
match, _ := regexp.MatchString(`^(\/(\d\d?\d?))+$`, relativePath)
91+
match, _ := regexp.MatchString(`^\/\d+(\/\d+)(\/\d+)?$`, relativePath)
9292
return match
9393
}

go.mod

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,60 @@ module github.com/bloxapp/eth2-key-manager
33
go 1.18
44

55
require (
6-
github.com/attestantio/go-eth2-client v0.15.2
6+
github.com/attestantio/go-eth2-client v0.19.8
77
github.com/btcsuite/btcd/btcec/v2 v2.2.1
8-
github.com/ferranbt/fastssz v0.1.2
8+
github.com/ferranbt/fastssz v0.1.3
99
github.com/google/uuid v1.3.0
1010
github.com/herumi/bls-eth-go-binary v1.28.1
1111
github.com/pkg/errors v0.9.1
12+
github.com/rs/zerolog v1.29.1
1213
github.com/sirupsen/logrus v1.8.1
1314
github.com/spf13/cobra v1.5.0
14-
github.com/stretchr/testify v1.8.0
15+
github.com/stretchr/testify v1.8.4
1516
github.com/tyler-smith/go-bip39 v1.1.0
1617
github.com/wealdtech/go-eth2-types/v2 v2.8.0
1718
github.com/wealdtech/go-eth2-util v1.6.3
18-
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90
19-
golang.org/x/text v0.3.7
19+
golang.org/x/crypto v0.10.0
20+
golang.org/x/text v0.10.0
2021
)
2122

2223
require (
24+
github.com/beorn7/perks v1.0.1 // indirect
25+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
2326
github.com/davecgh/go-spew v1.1.1 // indirect
2427
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
2528
github.com/fatih/color v1.13.0 // indirect
29+
github.com/go-logr/logr v1.2.4 // indirect
30+
github.com/go-logr/stdr v1.2.2 // indirect
2631
github.com/go-playground/validator/v10 v10.10.0 // indirect
2732
github.com/goccy/go-yaml v1.9.5 // indirect
33+
github.com/golang/protobuf v1.5.3 // indirect
34+
github.com/holiman/uint256 v1.2.2 // indirect
35+
github.com/huandu/go-clone v1.6.0 // indirect
2836
github.com/inconshreveable/mousetrap v1.0.0 // indirect
2937
github.com/klauspost/cpuid/v2 v2.2.1 // indirect
3038
github.com/mattn/go-colorable v0.1.13 // indirect
3139
github.com/mattn/go-isatty v0.0.16 // indirect
40+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
3241
github.com/minio/sha256-simd v1.0.0 // indirect
3342
github.com/mitchellh/mapstructure v1.5.0 // indirect
3443
github.com/pmezard/go-difflib v1.0.0 // indirect
44+
github.com/prometheus/client_golang v1.16.0 // indirect
45+
github.com/prometheus/client_model v0.3.0 // indirect
46+
github.com/prometheus/common v0.42.0 // indirect
47+
github.com/prometheus/procfs v0.10.1 // indirect
3548
github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7 // indirect
49+
github.com/r3labs/sse/v2 v2.10.0 // indirect
3650
github.com/spf13/pflag v1.0.5 // indirect
3751
github.com/wealdtech/go-bytesutil v1.1.1 // indirect
38-
golang.org/x/sys v0.2.0 // indirect
52+
go.opentelemetry.io/otel v1.16.0 // indirect
53+
go.opentelemetry.io/otel/metric v1.16.0 // indirect
54+
go.opentelemetry.io/otel/trace v1.16.0 // indirect
55+
golang.org/x/net v0.10.0 // indirect
56+
golang.org/x/sys v0.9.0 // indirect
3957
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
40-
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
58+
google.golang.org/protobuf v1.30.0 // indirect
59+
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
4160
gopkg.in/yaml.v2 v2.4.0 // indirect
4261
gopkg.in/yaml.v3 v3.0.1 // indirect
4362
)

0 commit comments

Comments
 (0)