Merge pull request #1231 from nspcc-dev/fix/printops

vm: pretty-print remaining opcodes
This commit is contained in:
Roman Khimov 2020-08-14 14:43:29 +03:00 committed by GitHub
commit 40bcd4c0bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 400 additions and 199 deletions

View file

@ -12,6 +12,7 @@ import (
"sort"
"strings"
"github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/vm"
@ -1313,7 +1314,7 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
emit.Opcode(c.prog.BinWriter, opcode.THROW)
} else if isString(c.typeInfo.Types[arg].Type) {
ast.Walk(c, arg)
emit.Syscall(c.prog.BinWriter, "System.Runtime.Log")
emit.Syscall(c.prog.BinWriter, interopnames.SystemRuntimeLog)
emit.Opcode(c.prog.BinWriter, opcode.THROW)
} else {
c.prog.Err = errors.New("panic should have string or nil argument")

View file

@ -6,8 +6,8 @@ import (
"math/big"
"testing"
"github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames"
"github.com/nspcc-dev/neo-go/pkg/vm"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/stretchr/testify/require"
)
@ -56,7 +56,7 @@ func getPanicSource(need bool, message string) string {
}
func getLogHandler(logs *[]string) vm.SyscallHandler {
logID := emit.InteropNameToID([]byte("System.Runtime.Log"))
logID := interopnames.ToID([]byte(interopnames.SystemRuntimeLog))
return func(v *vm.VM, id uint32) error {
if id != logID {
return errors.New("syscall not found")

View file

@ -1,5 +1,7 @@
package compiler
import "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames"
// Syscall represents NEO or System syscall API with flag for proper AVM generation
type Syscall struct {
API string
@ -9,80 +11,80 @@ type Syscall struct {
// All lists are sorted, keep 'em this way, please.
var syscalls = map[string]map[string]Syscall{
"binary": {
"Base64Decode": {"System.Binary.Base64Decode", false},
"Base64Encode": {"System.Binary.Base64Encode", false},
"Deserialize": {"System.Binary.Deserialize", false},
"Serialize": {"System.Binary.Serialize", false},
"Base64Decode": {interopnames.SystemBinaryBase64Decode, false},
"Base64Encode": {interopnames.SystemBinaryBase64Encode, false},
"Deserialize": {interopnames.SystemBinaryDeserialize, false},
"Serialize": {interopnames.SystemBinarySerialize, false},
},
"blockchain": {
"GetBlock": {"System.Blockchain.GetBlock", true},
"GetContract": {"System.Blockchain.GetContract", true},
"GetHeight": {"System.Blockchain.GetHeight", false},
"GetTransaction": {"System.Blockchain.GetTransaction", true},
"GetTransactionFromBlock": {"System.Blockchain.GetTransactionFromBlock", false},
"GetTransactionHeight": {"System.Blockchain.GetTransactionHeight", false},
"GetBlock": {interopnames.SystemBlockchainGetBlock, true},
"GetContract": {interopnames.SystemBlockchainGetContract, true},
"GetHeight": {interopnames.SystemBlockchainGetHeight, false},
"GetTransaction": {interopnames.SystemBlockchainGetTransaction, true},
"GetTransactionFromBlock": {interopnames.SystemBlockchainGetTransactionFromBlock, false},
"GetTransactionHeight": {interopnames.SystemBlockchainGetTransactionHeight, false},
},
"contract": {
"Create": {"System.Contract.Create", true},
"CreateStandardAccount": {"System.Contract.CreateStandardAccount", false},
"Destroy": {"System.Contract.Destroy", false},
"IsStandard": {"System.Contract.IsStandard", false},
"GetCallFlags": {"System.Contract.GetCallFlags", false},
"Update": {"System.Contract.Update", false},
"Create": {interopnames.SystemContractCreate, true},
"CreateStandardAccount": {interopnames.SystemContractCreateStandardAccount, false},
"Destroy": {interopnames.SystemContractDestroy, false},
"IsStandard": {interopnames.SystemContractIsStandard, false},
"GetCallFlags": {interopnames.SystemContractGetCallFlags, false},
"Update": {interopnames.SystemContractUpdate, false},
},
"crypto": {
"ECDsaSecp256k1Verify": {"Neo.Crypto.VerifyWithECDsaSecp256k1", false},
"ECDSASecp256k1CheckMultisig": {"Neo.Crypto.CheckMultisigWithECDsaSecp256k1", false},
"ECDsaSecp256r1Verify": {"Neo.Crypto.VerifyWithECDsaSecp256r1", false},
"ECDSASecp256r1CheckMultisig": {"Neo.Crypto.CheckMultisigWithECDsaSecp256r1", false},
"RIPEMD160": {"Neo.Crypto.RIPEMD160", false},
"SHA256": {"Neo.Crypto.SHA256", false},
"ECDsaSecp256k1Verify": {interopnames.NeoCryptoVerifyWithECDsaSecp256k1, false},
"ECDSASecp256k1CheckMultisig": {interopnames.NeoCryptoCheckMultisigWithECDsaSecp256k1, false},
"ECDsaSecp256r1Verify": {interopnames.NeoCryptoVerifyWithECDsaSecp256r1, false},
"ECDSASecp256r1CheckMultisig": {interopnames.NeoCryptoCheckMultisigWithECDsaSecp256r1, false},
"RIPEMD160": {interopnames.NeoCryptoRIPEMD160, false},
"SHA256": {interopnames.NeoCryptoSHA256, false},
},
"enumerator": {
"Concat": {"System.Enumerator.Concat", false},
"Create": {"System.Enumerator.Create", false},
"Next": {"System.Enumerator.Next", false},
"Value": {"System.Enumerator.Value", false},
"Concat": {interopnames.SystemEnumeratorConcat, false},
"Create": {interopnames.SystemEnumeratorCreate, false},
"Next": {interopnames.SystemEnumeratorNext, false},
"Value": {interopnames.SystemEnumeratorValue, false},
},
"engine": {
"AppCall": {"System.Contract.Call", false},
"AppCall": {interopnames.SystemContractCall, false},
},
"iterator": {
"Concat": {"System.Iterator.Concat", false},
"Create": {"System.Iterator.Create", false},
"Key": {"System.Iterator.Key", false},
"Keys": {"System.Iterator.Keys", false},
"Next": {"System.Enumerator.Next", false},
"Value": {"System.Enumerator.Value", false},
"Values": {"System.Iterator.Values", false},
"Concat": {interopnames.SystemIteratorConcat, false},
"Create": {interopnames.SystemIteratorCreate, false},
"Key": {interopnames.SystemIteratorKey, false},
"Keys": {interopnames.SystemIteratorKeys, false},
"Next": {interopnames.SystemEnumeratorNext, false},
"Value": {interopnames.SystemEnumeratorValue, false},
"Values": {interopnames.SystemIteratorValues, false},
},
"json": {
"Deserialize": {"System.Json.Deserialize", false},
"Serialize": {"System.Json.Serialize", false},
"Deserialize": {interopnames.SystemJSONDeserialize, false},
"Serialize": {interopnames.SystemJSONSerialize, false},
},
"runtime": {
"GasLeft": {"System.Runtime.GasLeft", false},
"GetInvocationCounter": {"System.Runtime.GetInvocationCounter", false},
"GetCallingScriptHash": {"System.Runtime.GetCallingScriptHash", false},
"GetEntryScriptHash": {"System.Runtime.GetEntryScriptHash", false},
"GetExecutingScriptHash": {"System.Runtime.GetExecutingScriptHash", false},
"GetNotifications": {"System.Runtime.GetNotifications", false},
"GetScriptContainer": {"System.Runtime.GetScriptContainer", true},
"GetTime": {"System.Runtime.GetTime", false},
"GetTrigger": {"System.Runtime.GetTrigger", false},
"CheckWitness": {"System.Runtime.CheckWitness", false},
"Log": {"System.Runtime.Log", false},
"Notify": {"System.Runtime.Notify", false},
"Platform": {"System.Runtime.Platform", false},
"GasLeft": {interopnames.SystemRuntimeGasLeft, false},
"GetInvocationCounter": {interopnames.SystemRuntimeGetInvocationCounter, false},
"GetCallingScriptHash": {interopnames.SystemRuntimeGetCallingScriptHash, false},
"GetEntryScriptHash": {interopnames.SystemRuntimeGetEntryScriptHash, false},
"GetExecutingScriptHash": {interopnames.SystemRuntimeGetExecutingScriptHash, false},
"GetNotifications": {interopnames.SystemRuntimeGetNotifications, false},
"GetScriptContainer": {interopnames.SystemRuntimeGetScriptContainer, true},
"GetTime": {interopnames.SystemRuntimeGetTime, false},
"GetTrigger": {interopnames.SystemRuntimeGetTrigger, false},
"CheckWitness": {interopnames.SystemRuntimeCheckWitness, false},
"Log": {interopnames.SystemRuntimeLog, false},
"Notify": {interopnames.SystemRuntimeNotify, false},
"Platform": {interopnames.SystemRuntimePlatform, false},
},
"storage": {
"ConvertContextToReadOnly": {"System.Storage.AsReadOnly", false},
"Delete": {"System.Storage.Delete", false},
"Find": {"System.Storage.Find", false},
"Get": {"System.Storage.Get", false},
"GetContext": {"System.Storage.GetContext", false},
"GetReadOnlyContext": {"System.Storage.GetReadOnlyContext", false},
"Put": {"System.Storage.Put", false},
"PutEx": {"System.Storage.PutEx", false},
"ConvertContextToReadOnly": {interopnames.SystemStorageAsReadOnly, false},
"Delete": {interopnames.SystemStorageDelete, false},
"Find": {interopnames.SystemStorageFind, false},
"Get": {interopnames.SystemStorageGet, false},
"GetContext": {interopnames.SystemStorageGetContext, false},
"GetReadOnlyContext": {interopnames.SystemStorageGetReadOnlyContext, false},
"Put": {interopnames.SystemStoragePut, false},
"PutEx": {interopnames.SystemStoragePutEx, false},
},
}

View file

@ -4,9 +4,9 @@ import (
"fmt"
"testing"
"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/vm"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -19,7 +19,7 @@ func TestVerifyGood(t *testing.T) {
src := getVerifyProg(pub, sig, msg)
v, p := vmAndCompileInterop(t, src)
p.interops[emit.InteropNameToID([]byte("Neo.Crypto.VerifyWithECDsaSecp256r1"))] = func(v *vm.VM) error {
p.interops[interopnames.ToID([]byte(interopnames.NeoCryptoVerifyWithECDsaSecp256r1))] = func(v *vm.VM) error {
assert.Equal(t, msg, v.Estack().Pop().Bytes())
assert.Equal(t, pub, v.Estack().Pop().Bytes())
assert.Equal(t, sig, v.Estack().Pop().Bytes())

View file

@ -7,11 +7,11 @@ import (
"testing"
"github.com/nspcc-dev/neo-go/pkg/compiler"
"github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/vm"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -109,10 +109,10 @@ func newStoragePlugin() *storagePlugin {
mem: make(map[string][]byte),
interops: make(map[uint32]func(v *vm.VM) error),
}
s.interops[emit.InteropNameToID([]byte("System.Storage.Get"))] = s.Get
s.interops[emit.InteropNameToID([]byte("System.Storage.Put"))] = s.Put
s.interops[emit.InteropNameToID([]byte("System.Storage.GetContext"))] = s.GetContext
s.interops[emit.InteropNameToID([]byte("System.Runtime.Notify"))] = s.Notify
s.interops[interopnames.ToID([]byte(interopnames.SystemStorageGet))] = s.Get
s.interops[interopnames.ToID([]byte(interopnames.SystemStoragePut))] = s.Put
s.interops[interopnames.ToID([]byte(interopnames.SystemStorageGetContext))] = s.GetContext
s.interops[interopnames.ToID([]byte(interopnames.SystemRuntimeNotify))] = s.Notify
return s
}