diff --git a/pkg/compiler/syscall_test.go b/pkg/compiler/syscall_test.go index 086ef7621..479261744 100644 --- a/pkg/compiler/syscall_test.go +++ b/pkg/compiler/syscall_test.go @@ -71,6 +71,7 @@ func TestSyscallExecution(t *testing.T) { "runtime.BurnGas": {interopnames.SystemRuntimeBurnGas, []string{"1"}, true}, "runtime.CheckWitness": {interopnames.SystemRuntimeCheckWitness, []string{b}, false}, "runtime.GasLeft": {interopnames.SystemRuntimeGasLeft, nil, false}, + "runtime.GetAddressVersion": {interopnames.SystemRuntimeGetAddressVersion, nil, false}, "runtime.GetCallingScriptHash": {interopnames.SystemRuntimeGetCallingScriptHash, nil, false}, "runtime.GetEntryScriptHash": {interopnames.SystemRuntimeGetEntryScriptHash, nil, false}, "runtime.GetExecutingScriptHash": {interopnames.SystemRuntimeGetExecutingScriptHash, nil, false}, diff --git a/pkg/core/interop/interopnames/names.go b/pkg/core/interop/interopnames/names.go index adbd82f4e..bdb3b93d1 100644 --- a/pkg/core/interop/interopnames/names.go +++ b/pkg/core/interop/interopnames/names.go @@ -16,6 +16,7 @@ const ( SystemRuntimeBurnGas = "System.Runtime.BurnGas" SystemRuntimeCheckWitness = "System.Runtime.CheckWitness" SystemRuntimeGasLeft = "System.Runtime.GasLeft" + SystemRuntimeGetAddressVersion = "System.Runtime.GetAddressVersion" SystemRuntimeGetCallingScriptHash = "System.Runtime.GetCallingScriptHash" SystemRuntimeGetEntryScriptHash = "System.Runtime.GetEntryScriptHash" SystemRuntimeGetExecutingScriptHash = "System.Runtime.GetExecutingScriptHash" @@ -51,6 +52,7 @@ var names = []string{ SystemRuntimeBurnGas, SystemRuntimeCheckWitness, SystemRuntimeGasLeft, + SystemRuntimeGetAddressVersion, SystemRuntimeGetCallingScriptHash, SystemRuntimeGetEntryScriptHash, SystemRuntimeGetExecutingScriptHash, diff --git a/pkg/core/interop/runtime/util.go b/pkg/core/interop/runtime/util.go index efc844b35..057d5c0da 100644 --- a/pkg/core/interop/runtime/util.go +++ b/pkg/core/interop/runtime/util.go @@ -7,6 +7,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/interop" "github.com/nspcc-dev/neo-go/pkg/core/state" + "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/util" "github.com/nspcc-dev/neo-go/pkg/vm" @@ -72,6 +73,12 @@ func GetInvocationCounter(ic *interop.Context) error { return nil } +// GetAddressVersion returns the address version of the current protocol. +func GetAddressVersion(ic *interop.Context) error { + ic.VM.Estack().PushItem(stackitem.NewBigInteger(big.NewInt(int64(address.NEO3Prefix)))) + return nil +} + // GetNetwork returns chain network number. func GetNetwork(ic *interop.Context) error { m := ic.Chain.GetConfig().Magic diff --git a/pkg/core/interop_system_neotest_test.go b/pkg/core/interop_system_neotest_test.go index f2ac39226..7ad7de42f 100644 --- a/pkg/core/interop_system_neotest_test.go +++ b/pkg/core/interop_system_neotest_test.go @@ -13,6 +13,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "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/io" "github.com/nspcc-dev/neo-go/pkg/neotest" "github.com/nspcc-dev/neo-go/pkg/neotest/chain" @@ -207,6 +208,16 @@ func TestSystemRuntimeGetNetwork(t *testing.T) { e.InvokeScriptCheckHALT(t, w.Bytes(), []neotest.Signer{acc}, stackitem.NewBigInteger(big.NewInt(int64(bc.GetConfig().Magic)))) } +func TestSystemRuntimeGetAddressVersion(t *testing.T) { + bc, acc := chain.NewSingle(t) + e := neotest.NewExecutor(t, bc, acc, acc) + w := io.NewBufBinWriter() + + emit.Syscall(w.BinWriter, interopnames.SystemRuntimeGetAddressVersion) + require.NoError(t, w.Err) + e.InvokeScriptCheckHALT(t, w.Bytes(), []neotest.Signer{acc}, stackitem.NewBigInteger(big.NewInt(int64(address.NEO3Prefix)))) +} + func TestSystemRuntimeBurnGas(t *testing.T) { bc, acc := chain.NewSingle(t) e := neotest.NewExecutor(t, bc, acc, acc) diff --git a/pkg/core/interops.go b/pkg/core/interops.go index 030b9a8d3..04a0dae8c 100644 --- a/pkg/core/interops.go +++ b/pkg/core/interops.go @@ -46,6 +46,7 @@ var systemInterops = []interop.Function{ {Name: interopnames.SystemRuntimeCheckWitness, Func: runtime.CheckWitness, Price: 1 << 10, RequiredFlags: callflag.NoneFlag, ParamCount: 1}, {Name: interopnames.SystemRuntimeGasLeft, Func: runtime.GasLeft, Price: 1 << 4}, + {Name: interopnames.SystemRuntimeGetAddressVersion, Func: runtime.GetAddressVersion, Price: 1 << 3}, {Name: interopnames.SystemRuntimeGetCallingScriptHash, Func: runtime.GetCallingScriptHash, Price: 1 << 4}, {Name: interopnames.SystemRuntimeGetEntryScriptHash, Func: runtime.GetEntryScriptHash, Price: 1 << 4}, {Name: interopnames.SystemRuntimeGetExecutingScriptHash, Func: runtime.GetExecutingScriptHash, Price: 1 << 4}, diff --git a/pkg/interop/runtime/runtime.go b/pkg/interop/runtime/runtime.go index f82a1ed4d..9bfd769a2 100644 --- a/pkg/interop/runtime/runtime.go +++ b/pkg/interop/runtime/runtime.go @@ -46,6 +46,14 @@ func Notify(name string, args ...interface{}) { neogointernal.Syscall2NoReturn("System.Runtime.Notify", name, args) } +// GetAddressVersion returns the address version of the current protocol. The +// address version represents the byte used to prepend to Neo addresses when +// encoding them. The default value for Neo3 is 53 (0x35). This function uses +// `System.Runtime.GetAddressVersion` syscall. +func GetAddressVersion() int { + return neogointernal.Syscall0("System.Runtime.GetAddressVersion").(int) +} + // GetNetwork returns network magic number. This function uses // `System.Runtime.GetNetwork` syscall. func GetNetwork() int {