Skip to content

Commit

Permalink
Deneb Support (#104)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
olegshmuelov and moshe-blox authored Jan 22, 2024
1 parent 4a62c72 commit eca3b4b
Show file tree
Hide file tree
Showing 10 changed files with 327 additions and 469 deletions.
95 changes: 93 additions & 2 deletions core/hd_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,41 @@ func TestDerivableKeyRelativePathDerivation(t *testing.T) {
err: nil,
expectedKey: _bigIntFromSkHex("aaa63a09aa2c0ce6a2a29940df8981eeefac0ea193bf90f2e06edd41356054f2907bc2e1eb5aaa4097361841914cd274"),
},
{
name: "Base account derivation (too big index)",
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
path: "/1000/0", // after basePath
err: nil,
expectedKey: _bigIntFromSkHex("843e5a2e02693309cc14de8ee6b616bffc7a1aa16d670ff906a39bd3792630917b325669b1c9057d4209bf153e7ba7b5"),
},
{
name: "Base account derivation (too big index) in second position",
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
path: "/0/1000", // after basePath
err: nil,
expectedKey: _bigIntFromSkHex("870d7a7eade91784962604e141bc5072a6ba485c873b4934b197afba02cf56625fbbf5e98b278acc17bd040268f8c326"),
},
{
name: "Large Number in First Position",
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
path: "/1000/0/0",
err: nil,
expectedKey: _bigIntFromSkHex("b3befa8735a59a2371dc0db8c82738715bd8fb887ad245a5042396773dd08208e45b1067df61e02e9cfe6dddc5116c9f"),
},
{
name: "Large Number in Second Position",
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
path: "/0/1000/0",
err: nil,
expectedKey: _bigIntFromSkHex("ac65c29d1c94a4fd9a58a625ada6fe8587c85f963f6ff01bf8040108c0acb7f1334e1db9ce389c6da64bca8ab3061cbc"),
},
{
name: "Large Number in Third Position",
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
path: "/0/0/1000",
err: nil,
expectedKey: _bigIntFromSkHex("8ed2b33e1550274715e371cd6134cda81545e36d1b39ede4e3ac6b25728a1575464a985ac01e4b11553f2ef26f1269fb"),
},
{
name: "bad path",
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
Expand All @@ -172,9 +207,23 @@ func TestDerivableKeyRelativePathDerivation(t *testing.T) {
expectedKey: nil,
},
{
name: "too large of an index, bad path",
name: "bad path (too long)",
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
path: "/1000/0", // after basePath
path: "0/0/0/0", // after basePath
err: errors.New("invalid relative path. Example: /1/2/3"),
expectedKey: nil,
},
{
name: "bad path (too short)",
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
path: "0", // after basePath
err: errors.New("invalid relative path. Example: /1/2/3"),
expectedKey: nil,
},
{
name: "bad path (too short 2)",
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
path: "/0/9/", // after basePath
err: errors.New("invalid relative path. Example: /1/2/3"),
expectedKey: nil,
},
Expand All @@ -185,6 +234,48 @@ func TestDerivableKeyRelativePathDerivation(t *testing.T) {
err: errors.New("invalid relative path. Example: /1/2/3"),
expectedKey: nil,
},
{
name: "Negative Index Handling",
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
path: "/-1/0/0",
err: errors.New("invalid relative path. Example: /1/2/3"),
expectedKey: nil,
},
{
name: "Negative Index Handling",
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
path: "/0/-1/0",
err: errors.New("invalid relative path. Example: /1/2/3"),
expectedKey: nil,
},
{
name: "Negative Index Handling",
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
path: "/0/0/-1",
err: errors.New("invalid relative path. Example: /1/2/3"),
expectedKey: nil,
},
{
name: "Empty String Path",
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
path: "",
err: errors.New("invalid relative path. Example: /1/2/3"),
expectedKey: nil,
},
{
name: "Only Slashes in Path",
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
path: "///",
err: errors.New("invalid relative path. Example: /1/2/3"),
expectedKey: nil,
},
{
name: "Minimum Group Path",
seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"),
path: "/0",
err: errors.New("invalid relative path. Example: /1/2/3"),
expectedKey: nil,
},
}

for _, test := range tests {
Expand Down
2 changes: 1 addition & 1 deletion core/master_derivable_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ func (master *MasterDerivableKey) Derive(relativePath string) (*HDKey, error) {
}

func validateRelativePath(relativePath string) bool {
match, _ := regexp.MatchString(`^(\/(\d\d?\d?))+$`, relativePath)
match, _ := regexp.MatchString(`^\/\d+(\/\d+)(\/\d+)?$`, relativePath)
return match
}
33 changes: 26 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,60 @@ module github.com/bloxapp/eth2-key-manager
go 1.18

require (
github.com/attestantio/go-eth2-client v0.15.2
github.com/attestantio/go-eth2-client v0.19.8
github.com/btcsuite/btcd/btcec/v2 v2.2.1
github.com/ferranbt/fastssz v0.1.2
github.com/ferranbt/fastssz v0.1.3
github.com/google/uuid v1.3.0
github.com/herumi/bls-eth-go-binary v1.28.1
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.29.1
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.5.0
github.com/stretchr/testify v1.8.0
github.com/stretchr/testify v1.8.4
github.com/tyler-smith/go-bip39 v1.1.0
github.com/wealdtech/go-eth2-types/v2 v2.8.0
github.com/wealdtech/go-eth2-util v1.6.3
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90
golang.org/x/text v0.3.7
golang.org/x/crypto v0.10.0
golang.org/x/text v0.10.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/validator/v10 v10.10.0 // indirect
github.com/goccy/go-yaml v1.9.5 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/holiman/uint256 v1.2.2 // indirect
github.com/huandu/go-clone v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7 // indirect
github.com/r3labs/sse/v2 v2.10.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/wealdtech/go-bytesutil v1.1.1 // indirect
golang.org/x/sys v0.2.0 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit eca3b4b

Please sign in to comment.