From 259cbc33566859c18d71496ceaea384fad5b181d Mon Sep 17 00:00:00 2001 From: Tatiana Nesterenko Date: Thu, 31 Aug 2023 09:55:54 +0100 Subject: [PATCH] vm: add address&swap endianness to opcode dump for hashes If the parameter in the opcode dump is a 20-byte value, the converted values, such as the address and the swapped endianness, have been added. Signed-off-by: Tatiana Nesterenko --- pkg/vm/vm.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 32f8c8210d..b175998a98 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -3,6 +3,7 @@ package vm import ( "crypto/elliptic" "encoding/binary" + "encoding/hex" "encoding/json" "errors" "fmt" @@ -15,6 +16,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" + "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/encoding/bigint" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/smartcontract/nef" @@ -217,7 +219,14 @@ func (v *VM) PrintOps(out io.Writer) { if utf8.Valid(parameter) { desc = fmt.Sprintf("%x (%q)", parameter, parameter) } else { - desc = fmt.Sprintf("%x", parameter) + // Try converting the parameter to an address and swap the endianness + // if the parameter is a 20-byte value. + u, err := util.Uint160DecodeBytesBE(parameter) + if err == nil { + desc = fmt.Sprintf("%x (%q, %q)", parameter, address.Uint160ToString(u), "0x"+hex.EncodeToString(slice.CopyReverse(parameter))) + } else { + desc = fmt.Sprintf("%x", parameter) + } } } }