Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chain): update ed25519 addresses in dev/gssmr genesis files #2225

Merged
merged 9 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chain/dev/genesis-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"Grandpa": {
"Authorities": [
[
"5DFNv4Txc4b88qHqQ6GG4D646QcT4fN3jjS2G3r1PyZkfDut",
"5FA9nQDVg267DEd8m1ZypXLBnvN7SFxYwV7ndqSYGiN9TTpu",
1
]
]
Expand Down
2 changes: 1 addition & 1 deletion chain/dev/genesis.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions chain/gssmr/genesis-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,39 +50,39 @@
"Grandpa": {
"Authorities": [
[
"5DFNv4Txc4b88qHqQ6GG4D646QcT4fN3jjS2G3r1PyZkfDut",
"5FA9nQDVg267DEd8m1ZypXLBnvN7SFxYwV7ndqSYGiN9TTpu",
1
],
[
"5FRbF5E5xpBxaCdjuVkCAtoLgvvoL6wJoE7kAVTUdZBwpgi7",
"5GoNkf6WdbxCFnPdAnYYQyCjAKPJgLNxXwPjwTh6DGg6gN3E",
1
],
[
"5DYo8CvjQcBQFdehVhansDiZCPebpgqvNC8PQPi6K9cL9giT",
"5DbKjhNLpqX3zqZdNBc9BGb4fHU1cRBaDhJUskrvkwfraDi6",
1
],
[
"5EtkA16QN4DED9vrxb4LnmytCFBhm6qJ5pw6FkoaiRtsPeuG",
"5ECTwv6cZ5nJQPk6tWfaTrEk8YH2L7X1VT4EL5Tx2ikfFwb7",
1
],
[
"5G64P3LJTK28dDVGNSzSHp4mfZyKqdzxgeZ1cULRoxMdt8m1",
"5Ck2miBfCe1JQ4cY3NDsXyBaD6EcsgiVmEFTWwqNSs25XDEq",
1
],
[
"5D7QrtMByWQpi8EtqkH1sPDBCVZvoH6G1vY5mknQiCC3ZVQM",
"5E2BmpVFzYGd386XRCZ76cDePMB3sfbZp5ZKGUsrG1m6gomN",
1
],
[
"5FdsD3mYg5gzh1Uj4FxyeHqMTpaAVd3gDNmcuKypBzRGGMQH",
"5CGR8FbjxeV31JKaUUuVUgasW79k8xFGdoh8WG5MokEc78qj",
1
],
[
"5DqDws3YxzL8r741gw33jdbohzAESRR9qGCGg6GAZ3Qw5fYX",
"5E9ZP1w5qat63KrWEJLkh7aDr2fPTbu3UhetAjxeyBojKHYH",
1
],
[
"5FYrfAUUzuahCL2swxoPXc846dKrWuD2nwzrKc1oEfWBS6RL",
"5Cjb197EXcHehjxuyKUCF3wJm86owKiuKCzF18DcMhbgMhPX",
1
]
]
Expand Down
2 changes: 1 addition & 1 deletion chain/gssmr/genesis.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions dot/rpc/modules/grandpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,23 @@ func TestGrandpaModule_RoundState(t *testing.T) {
Prevotes: Votes{
CurrentWeight: 0x4,
Missing: []string{
"5G64P3LJTK28dDVGNSzSHp4mfZyKqdzxgeZ1cULRoxMdt8m1",
"5D7QrtMByWQpi8EtqkH1sPDBCVZvoH6G1vY5mknQiCC3ZVQM",
"5FdsD3mYg5gzh1Uj4FxyeHqMTpaAVd3gDNmcuKypBzRGGMQH",
"5DqDws3YxzL8r741gw33jdbohzAESRR9qGCGg6GAZ3Qw5fYX",
"5FYrfAUUzuahCL2swxoPXc846dKrWuD2nwzrKc1oEfWBS6RL",
"5Ck2miBfCe1JQ4cY3NDsXyBaD6EcsgiVmEFTWwqNSs25XDEq",
"5E2BmpVFzYGd386XRCZ76cDePMB3sfbZp5ZKGUsrG1m6gomN",
"5CGR8FbjxeV31JKaUUuVUgasW79k8xFGdoh8WG5MokEc78qj",
"5E9ZP1w5qat63KrWEJLkh7aDr2fPTbu3UhetAjxeyBojKHYH",
"5Cjb197EXcHehjxuyKUCF3wJm86owKiuKCzF18DcMhbgMhPX",
},
},
Precommits: Votes{
CurrentWeight: 0x2,
Missing: []string{
"5DYo8CvjQcBQFdehVhansDiZCPebpgqvNC8PQPi6K9cL9giT",
"5EtkA16QN4DED9vrxb4LnmytCFBhm6qJ5pw6FkoaiRtsPeuG",
"5G64P3LJTK28dDVGNSzSHp4mfZyKqdzxgeZ1cULRoxMdt8m1",
"5D7QrtMByWQpi8EtqkH1sPDBCVZvoH6G1vY5mknQiCC3ZVQM",
"5FdsD3mYg5gzh1Uj4FxyeHqMTpaAVd3gDNmcuKypBzRGGMQH",
"5DqDws3YxzL8r741gw33jdbohzAESRR9qGCGg6GAZ3Qw5fYX",
"5FYrfAUUzuahCL2swxoPXc846dKrWuD2nwzrKc1oEfWBS6RL",
"5DbKjhNLpqX3zqZdNBc9BGb4fHU1cRBaDhJUskrvkwfraDi6",
"5ECTwv6cZ5nJQPk6tWfaTrEk8YH2L7X1VT4EL5Tx2ikfFwb7",
"5Ck2miBfCe1JQ4cY3NDsXyBaD6EcsgiVmEFTWwqNSs25XDEq",
"5E2BmpVFzYGd386XRCZ76cDePMB3sfbZp5ZKGUsrG1m6gomN",
"5CGR8FbjxeV31JKaUUuVUgasW79k8xFGdoh8WG5MokEc78qj",
"5E9ZP1w5qat63KrWEJLkh7aDr2fPTbu3UhetAjxeyBojKHYH",
"5Cjb197EXcHehjxuyKUCF3wJm86owKiuKCzF18DcMhbgMhPX",
},
},
},
Expand Down
8 changes: 5 additions & 3 deletions dot/rpc/modules/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func (sm *StateModule) GetStorage(
return nil
}

// GetStorageHash returns the hash of a storage entry at a block's state.
// GetStorageHash returns the blake2b hash of a storage entry at a block's state.
// If no block hash is provided, the latest value is returned.
func (sm *StateModule) GetStorageHash(
_ *http.Request, req *StateStorageHashRequest, res *StateStorageHashResponse) error {
Expand All @@ -364,10 +364,12 @@ func (sm *StateModule) GetStorageHash(
}
}

if len(item) > 0 {
*res = StateStorageHashResponse(common.BytesToHash(item).String())
hash, err := common.Blake2bHash(item)
if err != nil {
return err
}

*res = StateStorageHashResponse(hash.String())
return nil
}

Expand Down
20 changes: 8 additions & 12 deletions dot/rpc/modules/state_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,17 @@ func TestStateModule_GetStorageHash(t *testing.T) {
randomHash, err := common.HexToHash(RandomHash)
require.NoError(t, err)

hashOfNil := common.NewHash(common.MustHexToBytes("0x0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8")) //nolint:lll
hash1 := common.MustBlake2bHash([]byte("value1"))

testCases := []struct {
params []string
expected []byte
expected common.Hash
errMsg string
}{
{params: []string{""}, expected: nil},
{params: []string{":key1"}, expected: []byte("value1")},
{params: []string{":key1", hash.String()}, expected: []byte("value1")},
{params: []string{""}, expected: hashOfNil},
{params: []string{":key1"}, expected: hash1},
{params: []string{":key1", hash.String()}, expected: hash1},
{params: []string{"0x", randomHash.String()}, errMsg: "Key not found"},
}

Expand Down Expand Up @@ -255,14 +258,7 @@ func TestStateModule_GetStorageHash(t *testing.T) {
}

require.NoError(t, err)
if test.expected == nil {
require.Empty(t, res)
return
}

// Convert human-readable result value to hex.
expectedVal := common.BytesToHash(test.expected)
require.Equal(t, StateStorageHashResponse(expectedVal.String()), res)
require.Equal(t, StateStorageHashResponse(test.expected.String()), res)
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions dot/rpc/modules/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ func TestStateModuleGetStorageHash(t *testing.T) {
Bhash: &hash,
},
},
exp: StateStorageHashResponse("0x0000000000000000000000000000000000000000000000000000000000000015"),
exp: StateStorageHashResponse("0x8c272b95141731e2069ed10ad288146965eb76f0a566885323195f4cd7d58f3b"),
},
{
name: "bHash Nil OK",
Expand All @@ -663,7 +663,7 @@ func TestStateModuleGetStorageHash(t *testing.T) {
Key: "0x3aa96b0149b6ca3688878bdbd19464448624136398e3ce45b9e755d3ab61355a",
},
},
exp: StateStorageHashResponse("0x0000000000000000000000000000000000000000000000000000000000000015"),
exp: StateStorageHashResponse("0x8c272b95141731e2069ed10ad288146965eb76f0a566885323195f4cd7d58f3b"),
},
{
name: "bHash Not Nil Err",
Expand Down
18 changes: 18 additions & 0 deletions lib/crypto/ed25519/ed25519_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,23 @@ func TestVerifySignature(t *testing.T) {
require.NoError(t, err)
})
}
}

func TestPublicKeyFromPrivate(t *testing.T) {
// subkey inspect //Alice --scheme ed25519
priv := common.MustHexToBytes("0xabf8e5bdbe30c65656c0a3cbd181ff8a56294a69dfedd27982aace4a76909115")
pub := common.MustHexToBytes("0x88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee")

sk, err := NewPrivateKey(append(priv, pub...))
require.NoError(t, err)
pk, err := sk.Public()
require.NoError(t, err)
require.Equal(t, pub, pk.(*PublicKey).Encode())

kp, err := NewKeypairFromSeed(priv)
require.NoError(t, err)
require.Equal(t, pub, kp.public.Encode())

addr := crypto.PublicKeyToAddress(kp.Public())
require.Equal(t, "5FA9nQDVg267DEd8m1ZypXLBnvN7SFxYwV7ndqSYGiN9TTpu", string(addr))
}
8 changes: 6 additions & 2 deletions lib/crypto/keypair.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,20 @@ var ss58Prefix = []byte("SS58PRE")
// also see: https://github.com/paritytech/substrate/blob/master/primitives/core/src/crypto.rs#L275
func PublicKeyToAddress(pub PublicKey) common.Address {
enc := append([]byte{42}, pub.Encode()...)
return publicKeyBytesToAddress(enc)
}

func publicKeyBytesToAddress(b []byte) common.Address {
hasher, err := blake2b.New(64, nil)
if err != nil {
return ""
}
_, err = hasher.Write(append(ss58Prefix, enc...))
_, err = hasher.Write(append(ss58Prefix, b...))
if err != nil {
return ""
}
checksum := hasher.Sum(nil)
return common.Address(base58.Encode(append(enc, checksum[:2]...)))
return common.Address(base58.Encode(append(b, checksum[:2]...)))
}

// PublicAddressToByteArray returns []byte address for given PublicKey Address
Expand Down
2 changes: 1 addition & 1 deletion lib/grandpa/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var testSignature = [64]byte{1, 2, 3, 4}
var testAuthorityID = [32]byte{5, 6, 7, 8}

func TestCommitMessageEncode(t *testing.T) {
exp := common.MustHexToBytes("0x4d0000000000000000000000000000007db9db5ed9967b80143100189ba69d9e4deab85ac3570e5df25686cabe32964a00000000040a0b0c0d00000000000000000000000000000000000000000000000000000000e7030000040102030400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034602b88f60513f1c805d87ef52896934baf6a662bc37414dbdbf69356b1a691") //nolint:lll
exp := common.MustHexToBytes("0x4d0000000000000000000000000000007db9db5ed9967b80143100189ba69d9e4deab85ac3570e5df25686cabe32964a00000000040a0b0c0d00000000000000000000000000000000000000000000000000000000e7030000040102030400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000088dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee") //nolint:lll
gs, st := newTestService(t)
just := []SignedVote{
{
Expand Down
18 changes: 15 additions & 3 deletions lib/keystore/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// private keys generated using `subkey inspect //Name`
var privateKeys = []string{
var sr25519PrivateKeys = []string{
"0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a",
"0x398f0c28f98885e046333d4a41c19cee4c37368a9832c6502f6cfd182e2aef89",
"0xbc1ede780f784bb6991a585e4f6e61522c14e1cae6ad0895fb57b9a205a8f938",
Expand Down Expand Up @@ -61,7 +61,7 @@ func NewSr25519Keyring() (*Sr25519Keyring, error) {

for i := 0; i < v.NumField()-1; i++ {
who := v.Field(i)
h, err := common.HexToBytes(privateKeys[i])
h, err := common.HexToBytes(sr25519PrivateKeys[i])
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -124,6 +124,18 @@ func (kr *Sr25519Keyring) Ian() crypto.Keypair {
return kr.KeyIan
}

var ed25519PrivateKeys = []string{
"0xabf8e5bdbe30c65656c0a3cbd181ff8a56294a69dfedd27982aace4a76909115",
"0x3b7b60af2abcd57ba401ab398f84f4ca54bd6b2140d2503fbcf3286535fe3ff1",
"0x072c02fa1409dc37e03a4ed01703d4a9e6bba9c228a49a00366e9630a97cba7c",
"0x771f47d3caf8a2ee40b0719e1c1ecbc01d73ada220cf08df12a00453ab703738",
"0xbef5a3cd63dd36ab9792364536140e5a0cce6925969940c431934de056398556",
"0x1441e38eb309b66e9286867a5cd05902b05413eb9723a685d4d77753d73d0a1d",
"0x583b887078cbae4b6ac6fbee324c3d2c16f3a1f8bf18f0d234de3ac33baa4470",
"0xb8f3de627932e28914f3bc4bc3d7d2fc95c1f95c7915343d79df68d8250de180",
"0xfd9f15cac5ffd14ed08914c200b1744ab00bdddf45e86cd13ccf9585ffa0e3ce",
}

// Ed25519Keyring represents a test ed25519 keyring
type Ed25519Keyring struct {
KeyAlice *ed25519.Keypair
Expand All @@ -147,7 +159,7 @@ func NewEd25519Keyring() (*Ed25519Keyring, error) {

for i := 0; i < v.NumField()-1; i++ {
who := v.Field(i)
kp, err := ed25519.NewKeypairFromPrivateKeyString(privateKeys[i])
kp, err := ed25519.NewKeypairFromPrivateKeyString(ed25519PrivateKeys[i])
if err != nil {
return nil, err
}
Expand Down
13 changes: 3 additions & 10 deletions lib/keystore/keyring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import (

func TestNewSr25519Keyring(t *testing.T) {
kr, err := NewSr25519Keyring()
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

v := reflect.ValueOf(kr).Elem()
for i := 0; i < v.NumField()-1; i++ {
Expand Down Expand Up @@ -48,16 +46,11 @@ func TestNewSr25519Keyring(t *testing.T) {

func TestNewEd25519Keyring(t *testing.T) {
kr, err := NewEd25519Keyring()
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

v := reflect.ValueOf(kr).Elem()
for i := 0; i < v.NumField()-1; i++ {
key := v.Field(i).Interface().(*ed25519.Keypair).Private().Hex()
// ed25519 private keys are stored in uncompressed format
if key[:66] != privateKeys[i] {
t.Fatalf("Fail: got %s expected %s", key[:66], privateKeys[i])
}
require.Equal(t, ed25519PrivateKeys[i], key[:66])
}
}
3 changes: 3 additions & 0 deletions lib/runtime/life/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ func TestInstance_GrandpaAuthorities_NodeRuntime(t *testing.T) {

kr, _ := keystore.NewEd25519Keyring()

t.Logf("%x", kr.Alice().Public())
t.Logf("%x", auths[0].Key)

var expected []types.Authority

for _, kp := range kr.Keys {
Expand Down
10 changes: 6 additions & 4 deletions tests/rpc/rpc_05-state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/ChainSafe/gossamer/dot/rpc/modules"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/tests/utils"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -150,10 +151,11 @@ func TestStateRPCAPI(t *testing.T) {
InvalidHashFormat = "invalid hash format"
// `:grandpa_authorities` key
GrandpaAuthorityKey = "0x3a6772616e6470615f617574686f726974696573"
GrandpaAuthorityValue = "0x012434602b88f60513f1c805d87ef52896934baf6a662bc37414dbdbf69356b1a691010000000000000094a297125bf31bc15e2a2f1d7d44d2c2a99ce3ed81fdc3a7acf4a4cc30480fb7010000000000000041a8d68c449e3afc7e4676827a4b11a0c9ec238542327f2e46a8b70a32501bca01000000000000007d1bfc260fee0dcdd73457c15a3895747d1c2fdc4c097060e34f54c99ea1c6c10100000000000000b1f9449c9dea2baa872a96bf655a6e266888ec4ea55051508d8bb725e936cf0c01000000000000002e4cc1538f2fd132e0396282ad5c1d7a54eba14d9ad0eee3768c3ae656577a6001000000000000009dff473ab4f7b55caa005060053a7b315cedb928cf9f99792753ad3a3b6ae8a401000000000000004e30525ea941dc9ccd21302b195a6312024ad627cbe4814c89473ce03c3a20e301000000000000009a2d335e656481978c39fb571ed37c3e04ac2c4c44d450aefb2e71205e2e1d230100000000000000" //nolint:lll
StorageHashGrandpaAuthorityKey = "0x8c39fb571ed37c3e04ac2c4c44d450aefb2e71205e2e1d230100000000000000"
GrandpaAuthorityValue = "0x012488dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee0100000000000000d17c2d7823ebf260fd138f2d7e27d114c0145d968b5ff5006125f2414fadae690100000000000000439660b36c6c03afafca027b910b4fecf99801834c62a5e6006f27d978de234f01000000000000005e639b43e0052c47447dac87d6fd2b6ec50bdd4d0f614e4299c665249bbd09d901000000000000001dfe3e22cc0d45c70779c1095f7489a8ef3cf52d62fbd8c2fa38c9f1723502b50100000000000000568cb4a574c6d178feb39c27dfc8b3f789e5f5423e19c71633c748b9acf086b5010000000000000008ee9f4a5246647ebb938ece750d3d3be5e5f31978460258a1ab850c5d2b698201000000000000005c2c289b817ff4f843447a3346c0f63876acca1b0b93ff65736b4d4f26b8323101000000000000001da77f955bcd0745d2bc7a7e6544a661f4536deabf57fe79737b3e9157e39e420100000000000000" //nolint:lll
StorageSizeGrandpaAuthorityKey = "362"
)
hash := common.MustBlake2bHash(common.MustHexToBytes(GrandpaAuthorityValue))
storageHashGrandpaAuthorityKey := common.BytesToHex(hash[:])

testCases := []*testCase{
{
Expand All @@ -166,7 +168,7 @@ func TestStateRPCAPI(t *testing.T) {
description: "Test valid block hash state_getStorageHash",
method: "state_getStorageHash",
params: fmt.Sprintf(`["%s","%s"]`, GrandpaAuthorityKey, blockHash.String()),
expected: StorageHashGrandpaAuthorityKey,
expected: storageHashGrandpaAuthorityKey,
},
{
description: "Test valid block hash state_getStorageSize",
Expand Down Expand Up @@ -220,7 +222,7 @@ func TestStateRPCAPI(t *testing.T) {
description: "Test optional params hash state_getStorageHash",
method: "state_getStorageHash",
params: fmt.Sprintf(`["%s"]`, GrandpaAuthorityKey),
expected: StorageHashGrandpaAuthorityKey,
expected: storageHashGrandpaAuthorityKey,
},
{
description: "Test optional params hash state_getStorageSize",
Expand Down