diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-10-19 14:35:20 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:50 +0800 |
commit | 7febfae8bba63f6b7e1326b22437dee38989c400 (patch) | |
tree | fc9610537d2f3be3776a1e1c3b5fc4849a8587e4 | |
parent | 17fb63161b6672c0e8101e5fde709b1b7ab2df23 (diff) | |
download | dexon-7febfae8bba63f6b7e1326b22437dee38989c400.tar.gz dexon-7febfae8bba63f6b7e1326b22437dee38989c400.tar.zst dexon-7febfae8bba63f6b7e1326b22437dee38989c400.zip |
dex: fix public key parsing due to changes in consensus core
-rw-r--r-- | core/vm/governance.go | 5 | ||||
-rw-r--r-- | dex/governance.go | 20 | ||||
-rw-r--r-- | test/genesis.json | 20 | ||||
-rw-r--r-- | test/keygen.go | 2 | ||||
-rw-r--r-- | test/test0.nodekey | 2 | ||||
-rw-r--r-- | test/test1.nodekey | 2 | ||||
-rw-r--r-- | test/test2.nodekey | 2 | ||||
-rw-r--r-- | test/test3.nodekey | 2 |
8 files changed, 29 insertions, 26 deletions
diff --git a/core/vm/governance.go b/core/vm/governance.go index a720e31f5..2e07ba3eb 100644 --- a/core/vm/governance.go +++ b/core/vm/governance.go @@ -1316,7 +1316,10 @@ func (g *GovernanceContract) inDKGSet(nodeID coreTypes.NodeID) bool { ns := coreTypes.NewNodeSet() for _, x := range g.state.Nodes() { - mpk := ecdsa.NewPublicKeyFromByteSlice(x.PublicKey) + mpk, err := ecdsa.NewPublicKeyFromByteSlice(x.PublicKey) + if err != nil { + panic(err) + } ns.Add(coreTypes.NewNodeID(mpk)) } diff --git a/dex/governance.go b/dex/governance.go index 9235ffce1..4ec69c2d6 100644 --- a/dex/governance.go +++ b/dex/governance.go @@ -3,6 +3,7 @@ package dex import ( "context" "crypto/ecdsa" + "encoding/hex" "encoding/json" "math/big" "time" @@ -18,7 +19,6 @@ import ( "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/log" - "github.com/dexon-foundation/dexon/p2p/discover" "github.com/dexon-foundation/dexon/params" "github.com/dexon-foundation/dexon/rlp" "github.com/dexon-foundation/dexon/rpc" @@ -164,7 +164,11 @@ func (d *DexconGovernance) NodeSet(round uint64) []coreCrypto.PublicKey { var pks []coreCrypto.PublicKey for _, n := range s.Nodes() { - pks = append(pks, coreEcdsa.NewPublicKeyFromByteSlice(n.PublicKey)) + pk, err := coreEcdsa.NewPublicKeyFromByteSlice(n.PublicKey) + if err != nil { + panic(err) + } + pks = append(pks, pk) } return pks } @@ -306,11 +310,7 @@ func (d *DexconGovernance) NotarySet( r := make(map[string]struct{}, len(notarySet)) for id := range notarySet { if key, exists := d.nodeSetCache.GetPublicKey(id); exists { - uncompressedKey, err := crypto.DecompressPubkey(key.Bytes()) - if err != nil { - log.Error("decompress key fail", "err", err) - } - r[discover.PubkeyID(uncompressedKey).String()] = struct{}{} + r[hex.EncodeToString(key.Bytes()[1:])] = struct{}{} } } return r, nil @@ -325,11 +325,7 @@ func (d *DexconGovernance) DKGSet(round uint64) (map[string]struct{}, error) { r := make(map[string]struct{}, len(dkgSet)) for id := range dkgSet { if key, exists := d.nodeSetCache.GetPublicKey(id); exists { - uncompressedKey, err := crypto.DecompressPubkey(key.Bytes()) - if err != nil { - log.Error("decompress key fail", "err", err) - } - r[discover.PubkeyID(uncompressedKey).String()] = struct{}{} + r[hex.EncodeToString(key.Bytes()[1:])] = struct{}{} } } return r, nil diff --git a/test/genesis.json b/test/genesis.json index ba5965988..0a47ec209 100644 --- a/test/genesis.json +++ b/test/genesis.json @@ -35,25 +35,29 @@ "staked": "0", "code": "0x5765692d4e696e6720536f6e696320426f6a6965" }, - "0x7C3c31B19395A5e2627F921Cc2802560B71f1caB": { + "0xBF8C48A620bacc46907f9B89732D25E47A2D7Cf7": { + "balance": "100000000000000000000000", + "staked": "0" + }, + "0x361e4958bd8b4d035C68C473193E77FdAb6aEa9D": { "balance": "1000000000000000000000", "staked": "500000000000000000000", - "publicKey": "0x025477069c1fe7cc2825cdb55d161eb6608c8bb125a55bc746d4cf745e60b08bb1" + "publicKey": "0x040c2f07cf22966ebaa19dd87de11d04f9a606e83e75a5295574760a5a4dd82807e7d9f28f86cd389871dd931a477cac64e233a6f098d5b257871d8163dc1bddcf" }, - "0x9b507545785F22982F5C25f9e7a8f881423A6348": { + "0xbC71C0F2aeCa46fa0001e765965029b16a06049E": { "balance": "1000000000000000000000", "staked": "500000000000000000000", - "publicKey": "0x02d723ec266a229e0f8cc4a907776ce09152ef73c55a55c0fb289c182efea1ed74" + "publicKey": "0x04a12a015f27d98e5305498d23aeacde281e48aad918ae87d7f61784ab43828953db99bf1f44426294cbc21e32cf3a99122f2ce8a35ba718a7c814eec7bae9a3ea" }, - "0xCC275C8712Cb4c5d02f1c9E0EE7810e474e6350B": { + "0xB6a2e270b54F19B4002d6535a71CFDd1CA1f5fC1": { "balance": "1000000000000000000000", "staked": "500000000000000000000", - "publicKey": "0x03a6ab84d92f9f9684e2f6ddeff736f428a88ca5aca2873ea60557aedcf452db90" + "publicKey": "0x0463f78d398f6b042952062a26f3551a4e294a11084b1006c8d6376437b72488d8f3af6b849931c03624ad2d581900e9ad5f3cfeeed040c799e5308cd8012853fb" }, - "0x6177f5C9Dd006A7026A14139CdDDB013025098Bf": { + "0xb6bBBE39033131e428d5a3545856a596cacB7810": { "balance": "1000000000000000000000", "staked": "500000000000000000000", - "publicKey": "0x03cac6efc54d32b52b13b8ba01c902c125dbdd0657707277e1320868ef2a1599e6" + "publicKey": "0x04a1118c8f1c2e293de528e5b45ac5e65167af4cb4d10887924a9f839287d060da26414e971cab75013e560dfec7897b1983eaa631ae2f16ea4062525310edd8ea" } } } diff --git a/test/keygen.go b/test/keygen.go index b2c789723..986342368 100644 --- a/test/keygen.go +++ b/test/keygen.go @@ -14,7 +14,7 @@ func main() { panic(err) } address := crypto.PubkeyToAddress(privKey.PublicKey).String() - pk := hex.EncodeToString(crypto.CompressPubkey(&privKey.PublicKey)) + pk := hex.EncodeToString(crypto.FromECDSAPub(&privKey.PublicKey)) fmt.Printf(` "%s": { diff --git a/test/test0.nodekey b/test/test0.nodekey index 51c29073b..5ecbc48a6 100644 --- a/test/test0.nodekey +++ b/test/test0.nodekey @@ -1 +1 @@ -fb5efc249ba2db0edb80b0ccd08b32a4b98ff7c7684318137a5bb205f08a8f9f
\ No newline at end of file +3cf5bdee098cc34536a7b0e80d85e07a380efca76fc12136299b9e5ba24193c8
\ No newline at end of file diff --git a/test/test1.nodekey b/test/test1.nodekey index aecdc8a5f..c16f73286 100644 --- a/test/test1.nodekey +++ b/test/test1.nodekey @@ -1 +1 @@ -1d547b9b710c6d11e68805a1250a5b9ec6345051d56115b3b9af16419214f32a
\ No newline at end of file +96c9f1435d53577db18d45411326311529a0e8affb19218e27f65769a482c0fb
\ No newline at end of file diff --git a/test/test2.nodekey b/test/test2.nodekey index 74740daac..402577df2 100644 --- a/test/test2.nodekey +++ b/test/test2.nodekey @@ -1 +1 @@ -d5f3d1638dc20c9475edbf98da723aba49f666847f7ae3e09b60d1b73ff249a0
\ No newline at end of file +b25e955e30dd87cbaec83287beea6ec9c4c72498bc66905590756bf48da5d1fc
\ No newline at end of file diff --git a/test/test3.nodekey b/test/test3.nodekey index ea5bb63e2..b706958d6 100644 --- a/test/test3.nodekey +++ b/test/test3.nodekey @@ -1 +1 @@ -bfd1d410f07fd28820bb75856aaa7975b7844222bab7c159ffe28b3dfb2417ad
\ No newline at end of file +35577f65312f4a5e0b5391f5385043a6bc7b51fa4851a579e845b5fea33efded
\ No newline at end of file |