2019-10-11 14:00:11 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
/*
|
|
|
|
Interops are designed to run under VM's execute() panic protection, so it's OK
|
|
|
|
for them to do things like
|
|
|
|
smth := v.Estack().Pop().Bytes()
|
|
|
|
even though technically Pop() can return a nil pointer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import (
|
2021-02-05 08:25:22 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/fee"
|
2020-04-08 10:35:39 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
2020-09-21 14:00:33 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/contract"
|
2020-03-18 09:41:09 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/crypto"
|
2020-08-13 07:41:33 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames"
|
2020-04-08 11:08:43 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/iterator"
|
2020-04-13 12:56:41 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/runtime"
|
2022-06-08 16:31:49 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/storage"
|
2020-03-19 15:52:37 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
2020-12-29 10:45:49 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
2019-10-11 14:00:11 +00:00
|
|
|
)
|
|
|
|
|
2020-04-07 09:54:43 +00:00
|
|
|
// SpawnVM returns a VM with script getter and interop functions set
|
|
|
|
// up for current blockchain.
|
2020-04-08 10:35:39 +00:00
|
|
|
func SpawnVM(ic *interop.Context) *vm.VM {
|
2020-07-28 13:38:00 +00:00
|
|
|
vm := ic.SpawnVM()
|
2021-05-11 14:40:03 +00:00
|
|
|
ic.Functions = systemInterops
|
2020-04-07 09:54:43 +00:00
|
|
|
return vm
|
|
|
|
}
|
|
|
|
|
2019-12-18 16:49:56 +00:00
|
|
|
// All lists are sorted, keep 'em this way, please.
|
2020-04-08 10:35:39 +00:00
|
|
|
var systemInterops = []interop.Function{
|
2020-12-11 12:22:49 +00:00
|
|
|
{Name: interopnames.SystemContractCall, Func: contract.Call, Price: 1 << 15,
|
2021-02-25 15:12:36 +00:00
|
|
|
RequiredFlags: callflag.ReadStates | callflag.AllowCall, ParamCount: 4},
|
2020-12-30 09:26:50 +00:00
|
|
|
{Name: interopnames.SystemContractCallNative, Func: native.Call, Price: 0, ParamCount: 1},
|
2022-06-08 13:02:07 +00:00
|
|
|
{Name: interopnames.SystemContractCreateMultisigAccount, Func: contract.CreateMultisigAccount, Price: 0, ParamCount: 2},
|
|
|
|
{Name: interopnames.SystemContractCreateStandardAccount, Func: contract.CreateStandardAccount, Price: 0, ParamCount: 1},
|
|
|
|
{Name: interopnames.SystemContractGetCallFlags, Func: contract.GetCallFlags, Price: 1 << 10},
|
2021-03-16 19:49:14 +00:00
|
|
|
{Name: interopnames.SystemContractNativeOnPersist, Func: native.OnPersist, Price: 0, RequiredFlags: callflag.States},
|
|
|
|
{Name: interopnames.SystemContractNativePostPersist, Func: native.PostPersist, Price: 0, RequiredFlags: callflag.States},
|
2021-05-11 14:40:03 +00:00
|
|
|
{Name: interopnames.SystemCryptoCheckMultisig, Func: crypto.ECDSASecp256r1CheckMultisig, Price: 0, ParamCount: 2},
|
|
|
|
{Name: interopnames.SystemCryptoCheckSig, Func: crypto.ECDSASecp256r1CheckSig, Price: fee.ECDSAVerifyPrice, ParamCount: 2},
|
2021-01-12 09:30:21 +00:00
|
|
|
{Name: interopnames.SystemIteratorNext, Func: iterator.Next, Price: 1 << 15, ParamCount: 1},
|
|
|
|
{Name: interopnames.SystemIteratorValue, Func: iterator.Value, Price: 1 << 4, ParamCount: 1},
|
2021-04-29 08:33:21 +00:00
|
|
|
{Name: interopnames.SystemRuntimeBurnGas, Func: runtime.BurnGas, Price: 1 << 4, ParamCount: 1},
|
2020-12-11 12:22:49 +00:00
|
|
|
{Name: interopnames.SystemRuntimeCheckWitness, Func: runtime.CheckWitness, Price: 1 << 10,
|
2020-12-29 10:45:49 +00:00
|
|
|
RequiredFlags: callflag.NoneFlag, ParamCount: 1},
|
2023-07-08 10:54:04 +00:00
|
|
|
{Name: interopnames.SystemRuntimeCurrentSigners, Func: runtime.CurrentSigners, Price: 1 << 4,
|
|
|
|
RequiredFlags: callflag.NoneFlag},
|
2020-12-11 12:22:49 +00:00
|
|
|
{Name: interopnames.SystemRuntimeGasLeft, Func: runtime.GasLeft, Price: 1 << 4},
|
2022-04-21 14:53:11 +00:00
|
|
|
{Name: interopnames.SystemRuntimeGetAddressVersion, Func: runtime.GetAddressVersion, Price: 1 << 3},
|
2020-12-11 12:22:49 +00:00
|
|
|
{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},
|
|
|
|
{Name: interopnames.SystemRuntimeGetInvocationCounter, Func: runtime.GetInvocationCounter, Price: 1 << 4},
|
2021-07-06 11:20:25 +00:00
|
|
|
{Name: interopnames.SystemRuntimeGetNetwork, Func: runtime.GetNetwork, Price: 1 << 3},
|
2022-05-24 14:45:23 +00:00
|
|
|
{Name: interopnames.SystemRuntimeGetNotifications, Func: runtime.GetNotifications, Price: 1 << 12, ParamCount: 1},
|
2022-05-26 10:27:24 +00:00
|
|
|
{Name: interopnames.SystemRuntimeGetRandom, Func: runtime.GetRandom, Price: 0},
|
2022-06-08 15:12:41 +00:00
|
|
|
{Name: interopnames.SystemRuntimeGetScriptContainer, Func: runtime.GetScriptContainer, Price: 1 << 3},
|
2020-12-29 10:45:49 +00:00
|
|
|
{Name: interopnames.SystemRuntimeGetTime, Func: runtime.GetTime, Price: 1 << 3, RequiredFlags: callflag.ReadStates},
|
2020-12-11 12:22:49 +00:00
|
|
|
{Name: interopnames.SystemRuntimeGetTrigger, Func: runtime.GetTrigger, Price: 1 << 3},
|
2022-09-29 13:10:47 +00:00
|
|
|
{Name: interopnames.SystemRuntimeLoadScript, Func: runtime.LoadScript, Price: 1 << 15, RequiredFlags: callflag.AllowCall,
|
|
|
|
ParamCount: 3},
|
2020-12-29 10:45:49 +00:00
|
|
|
{Name: interopnames.SystemRuntimeLog, Func: runtime.Log, Price: 1 << 15, RequiredFlags: callflag.AllowNotify,
|
2020-12-30 09:26:50 +00:00
|
|
|
ParamCount: 1},
|
2020-12-29 10:45:49 +00:00
|
|
|
{Name: interopnames.SystemRuntimeNotify, Func: runtime.Notify, Price: 1 << 15, RequiredFlags: callflag.AllowNotify,
|
2020-12-30 09:26:50 +00:00
|
|
|
ParamCount: 2},
|
2020-12-11 12:22:49 +00:00
|
|
|
{Name: interopnames.SystemRuntimePlatform, Func: runtime.Platform, Price: 1 << 3},
|
2022-06-08 16:31:49 +00:00
|
|
|
{Name: interopnames.SystemStorageDelete, Func: storage.Delete, Price: 1 << 15,
|
2020-12-30 09:26:50 +00:00
|
|
|
RequiredFlags: callflag.WriteStates, ParamCount: 2},
|
2022-06-08 16:31:49 +00:00
|
|
|
{Name: interopnames.SystemStorageFind, Func: storage.Find, Price: 1 << 15, RequiredFlags: callflag.ReadStates,
|
2021-03-04 15:12:42 +00:00
|
|
|
ParamCount: 3},
|
2022-06-08 16:31:49 +00:00
|
|
|
{Name: interopnames.SystemStorageGet, Func: storage.Get, Price: 1 << 15, RequiredFlags: callflag.ReadStates,
|
2020-12-30 09:26:50 +00:00
|
|
|
ParamCount: 2},
|
2022-06-08 16:31:49 +00:00
|
|
|
{Name: interopnames.SystemStorageGetContext, Func: storage.GetContext, Price: 1 << 4,
|
2020-12-30 09:26:50 +00:00
|
|
|
RequiredFlags: callflag.ReadStates},
|
2022-06-08 16:31:49 +00:00
|
|
|
{Name: interopnames.SystemStorageGetReadOnlyContext, Func: storage.GetReadOnlyContext, Price: 1 << 4,
|
2020-12-30 09:26:50 +00:00
|
|
|
RequiredFlags: callflag.ReadStates},
|
2022-06-08 16:31:49 +00:00
|
|
|
{Name: interopnames.SystemStoragePut, Func: storage.Put, Price: 1 << 15, RequiredFlags: callflag.WriteStates,
|
2021-03-19 15:41:33 +00:00
|
|
|
ParamCount: 3},
|
2022-06-08 16:31:49 +00:00
|
|
|
{Name: interopnames.SystemStorageAsReadOnly, Func: storage.ContextAsReadOnly, Price: 1 << 4,
|
2020-12-30 09:26:50 +00:00
|
|
|
RequiredFlags: callflag.ReadStates, ParamCount: 1},
|
2019-12-18 16:49:56 +00:00
|
|
|
}
|
2019-10-11 14:00:11 +00:00
|
|
|
|
2019-12-18 16:49:56 +00:00
|
|
|
// init initializes IDs in the global interop slices.
|
|
|
|
func init() {
|
2021-05-11 14:40:03 +00:00
|
|
|
for i := range systemInterops {
|
|
|
|
systemInterops[i].ID = interopnames.ToID([]byte(systemInterops[i].Name))
|
|
|
|
}
|
|
|
|
interop.Sort(systemInterops)
|
2019-10-11 14:00:11 +00:00
|
|
|
}
|