From 7d786fac79b430b4ba4a53c6c934d276afc6d1fc Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 10 Jun 2020 19:15:23 +0300 Subject: [PATCH] core: fix key recovery interops return value It's uncompressed coordinate, both X and Y, not just X. Fix #1043. --- pkg/core/interop_neo.go | 2 +- pkg/core/interop_neo_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/core/interop_neo.go b/pkg/core/interop_neo.go index d2c3e2d79..418f943a6 100644 --- a/pkg/core/interop_neo.go +++ b/pkg/core/interop_neo.go @@ -626,7 +626,7 @@ func (ic *interopContext) eccRecover(curve elliptic.Curve, v *vm.VM) error { v.Estack().PushVal([]byte{}) return nil } - v.Estack().PushVal(pKey.Bytes()[1:]) + v.Estack().PushVal(pKey.UncompressedBytes()[1:]) return nil } diff --git a/pkg/core/interop_neo_test.go b/pkg/core/interop_neo_test.go index 86c648b63..d03a864f5 100644 --- a/pkg/core/interop_neo_test.go +++ b/pkg/core/interop_neo_test.go @@ -474,7 +474,7 @@ func TestSecp256k1Recover(t *testing.T) { X: privateKey.PubKey().X, Y: privateKey.PubKey().Y, } - expected := pubKey.Bytes()[1:] + expected := pubKey.UncompressedBytes()[1:] // We don't know which of two recovered keys suites, so let's try both. putOnStackGetResult := func(isEven bool) []byte { @@ -505,7 +505,7 @@ func TestSecp256r1Recover(t *testing.T) { messageHash := hash.Sha256(message).BytesBE() signature := privateKey.Sign(message) require.True(t, privateKey.PublicKey().Verify(signature, messageHash)) - expected := privateKey.PublicKey().Bytes()[1:] + expected := privateKey.PublicKey().UncompressedBytes()[1:] // We don't know which of two recovered keys suites, so let's try both. putOnStackGetResult := func(isEven bool) []byte {