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 (
|
2020-04-08 10:35:39 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
2020-11-09 14:26:23 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/binary"
|
2020-07-27 08:06:06 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/callback"
|
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-04-08 11:08:43 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/enumerator"
|
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-06-11 14:17:15 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/json"
|
2020-04-13 12:56:41 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/runtime"
|
2020-03-19 15:52:37 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
2020-06-10 14:21:26 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
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()
|
|
|
|
ic.Functions = [][]interop.Function{systemInterops, neoInterops}
|
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-11-09 14:26:23 +00:00
|
|
|
{Name: interopnames.SystemBinaryAtoi, Func: binary.Atoi, Price: 100000, ParamCount: 2},
|
2020-08-23 14:19:56 +00:00
|
|
|
{Name: interopnames.SystemBinaryBase58Decode, Func: runtimeDecodeBase58, Price: 100000, ParamCount: 1},
|
|
|
|
{Name: interopnames.SystemBinaryBase58Encode, Func: runtimeEncodeBase58, Price: 100000, ParamCount: 1},
|
|
|
|
{Name: interopnames.SystemBinaryBase64Decode, Func: runtimeDecodeBase64, Price: 100000, ParamCount: 1},
|
|
|
|
{Name: interopnames.SystemBinaryBase64Encode, Func: runtimeEncodeBase64, Price: 100000, ParamCount: 1},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemBinaryDeserialize, Func: runtimeDeserialize, Price: 500000, ParamCount: 1},
|
2020-11-09 14:26:23 +00:00
|
|
|
{Name: interopnames.SystemBinaryItoa, Func: binary.Itoa, Price: 100000, ParamCount: 2},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemBinarySerialize, Func: runtimeSerialize, Price: 100000, ParamCount: 1},
|
|
|
|
{Name: interopnames.SystemBlockchainGetBlock, Func: bcGetBlock, Price: 2500000,
|
2020-07-28 10:17:38 +00:00
|
|
|
RequiredFlags: smartcontract.AllowStates, ParamCount: 1},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemBlockchainGetContract, Func: bcGetContract, Price: 1000000,
|
2020-07-28 10:17:38 +00:00
|
|
|
RequiredFlags: smartcontract.AllowStates, ParamCount: 1},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemBlockchainGetHeight, Func: bcGetHeight, Price: 400,
|
2020-07-28 10:17:38 +00:00
|
|
|
RequiredFlags: smartcontract.AllowStates},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemBlockchainGetTransaction, Func: bcGetTransaction, Price: 1000000,
|
2020-07-28 10:17:38 +00:00
|
|
|
RequiredFlags: smartcontract.AllowStates, ParamCount: 1},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemBlockchainGetTransactionFromBlock, Func: bcGetTransactionFromBlock, Price: 1000000,
|
2020-07-28 10:17:38 +00:00
|
|
|
RequiredFlags: smartcontract.AllowStates, ParamCount: 2},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemBlockchainGetTransactionHeight, Func: bcGetTransactionHeight, Price: 1000000,
|
2020-07-28 10:17:38 +00:00
|
|
|
RequiredFlags: smartcontract.AllowStates, ParamCount: 1},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemCallbackCreate, Func: callback.Create, Price: 400, ParamCount: 3, DisallowCallback: true},
|
|
|
|
{Name: interopnames.SystemCallbackCreateFromMethod, Func: callback.CreateFromMethod, Price: 1000000, ParamCount: 2, DisallowCallback: true},
|
|
|
|
{Name: interopnames.SystemCallbackCreateFromSyscall, Func: callback.CreateFromSyscall, Price: 400, ParamCount: 1, DisallowCallback: true},
|
|
|
|
{Name: interopnames.SystemCallbackInvoke, Func: callback.Invoke, Price: 1000000, ParamCount: 2, DisallowCallback: true},
|
2020-09-21 14:00:33 +00:00
|
|
|
{Name: interopnames.SystemContractCall, Func: contract.Call, Price: 1000000,
|
2020-07-28 14:15:23 +00:00
|
|
|
RequiredFlags: smartcontract.AllowCall, ParamCount: 3, DisallowCallback: true},
|
2020-09-21 14:00:33 +00:00
|
|
|
{Name: interopnames.SystemContractCallEx, Func: contract.CallEx, Price: 1000000,
|
2020-07-28 14:15:23 +00:00
|
|
|
RequiredFlags: smartcontract.AllowCall, ParamCount: 4, DisallowCallback: true},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemContractCreate, Func: contractCreate, Price: 0,
|
2020-07-28 14:15:23 +00:00
|
|
|
RequiredFlags: smartcontract.AllowModifyStates, ParamCount: 2, DisallowCallback: true},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemContractCreateStandardAccount, Func: contractCreateStandardAccount, Price: 10000, ParamCount: 1, DisallowCallback: true},
|
|
|
|
{Name: interopnames.SystemContractDestroy, Func: contractDestroy, Price: 1000000, RequiredFlags: smartcontract.AllowModifyStates, DisallowCallback: true},
|
2020-08-23 12:41:55 +00:00
|
|
|
{Name: interopnames.SystemContractIsStandard, Func: contractIsStandard, Price: 30000, RequiredFlags: smartcontract.AllowStates, ParamCount: 1},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemContractGetCallFlags, Func: contractGetCallFlags, Price: 30000, DisallowCallback: true},
|
|
|
|
{Name: interopnames.SystemContractUpdate, Func: contractUpdate, Price: 0,
|
2020-07-28 14:15:23 +00:00
|
|
|
RequiredFlags: smartcontract.AllowModifyStates, ParamCount: 2, DisallowCallback: true},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemEnumeratorConcat, Func: enumerator.Concat, Price: 400, ParamCount: 2, DisallowCallback: true},
|
|
|
|
{Name: interopnames.SystemEnumeratorCreate, Func: enumerator.Create, Price: 400, ParamCount: 1, DisallowCallback: true},
|
|
|
|
{Name: interopnames.SystemEnumeratorNext, Func: enumerator.Next, Price: 1000000, ParamCount: 1, DisallowCallback: true},
|
|
|
|
{Name: interopnames.SystemEnumeratorValue, Func: enumerator.Value, Price: 400, ParamCount: 1, DisallowCallback: true},
|
|
|
|
{Name: interopnames.SystemIteratorConcat, Func: iterator.Concat, Price: 400, ParamCount: 2, DisallowCallback: true},
|
|
|
|
{Name: interopnames.SystemIteratorCreate, Func: iterator.Create, Price: 400, ParamCount: 1, DisallowCallback: true},
|
|
|
|
{Name: interopnames.SystemIteratorKey, Func: iterator.Key, Price: 400, ParamCount: 1, DisallowCallback: true},
|
|
|
|
{Name: interopnames.SystemIteratorKeys, Func: iterator.Keys, Price: 400, ParamCount: 1, DisallowCallback: true},
|
|
|
|
{Name: interopnames.SystemIteratorValues, Func: iterator.Values, Price: 400, ParamCount: 1, DisallowCallback: true},
|
|
|
|
{Name: interopnames.SystemJSONDeserialize, Func: json.Deserialize, Price: 500000, ParamCount: 1},
|
|
|
|
{Name: interopnames.SystemJSONSerialize, Func: json.Serialize, Price: 100000, ParamCount: 1},
|
|
|
|
{Name: interopnames.SystemRuntimeCheckWitness, Func: runtime.CheckWitness, Price: 30000,
|
2020-08-24 10:18:02 +00:00
|
|
|
RequiredFlags: smartcontract.NoneFlag, ParamCount: 1},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemRuntimeGasLeft, Func: runtime.GasLeft, Price: 400},
|
|
|
|
{Name: interopnames.SystemRuntimeGetCallingScriptHash, Func: engineGetCallingScriptHash, Price: 400},
|
|
|
|
{Name: interopnames.SystemRuntimeGetEntryScriptHash, Func: engineGetEntryScriptHash, Price: 400},
|
|
|
|
{Name: interopnames.SystemRuntimeGetExecutingScriptHash, Func: engineGetExecutingScriptHash, Price: 400},
|
|
|
|
{Name: interopnames.SystemRuntimeGetInvocationCounter, Func: runtime.GetInvocationCounter, Price: 400},
|
|
|
|
{Name: interopnames.SystemRuntimeGetNotifications, Func: runtime.GetNotifications, Price: 10000, ParamCount: 1},
|
|
|
|
{Name: interopnames.SystemRuntimeGetScriptContainer, Func: engineGetScriptContainer, Price: 250},
|
|
|
|
{Name: interopnames.SystemRuntimeGetTime, Func: runtimeGetTime, Price: 250, RequiredFlags: smartcontract.AllowStates},
|
|
|
|
{Name: interopnames.SystemRuntimeGetTrigger, Func: runtimeGetTrigger, Price: 250},
|
|
|
|
{Name: interopnames.SystemRuntimeLog, Func: runtimeLog, Price: 1000000, RequiredFlags: smartcontract.AllowNotify,
|
2020-07-28 14:15:23 +00:00
|
|
|
ParamCount: 1, DisallowCallback: true},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemRuntimeNotify, Func: runtimeNotify, Price: 1000000, RequiredFlags: smartcontract.AllowNotify,
|
2020-07-28 14:15:23 +00:00
|
|
|
ParamCount: 2, DisallowCallback: true},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemRuntimePlatform, Func: runtimePlatform, Price: 250},
|
|
|
|
{Name: interopnames.SystemStorageDelete, Func: storageDelete, Price: StoragePrice,
|
2020-07-28 14:15:23 +00:00
|
|
|
RequiredFlags: smartcontract.AllowModifyStates, ParamCount: 2, DisallowCallback: true},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemStorageFind, Func: storageFind, Price: 1000000, RequiredFlags: smartcontract.AllowStates,
|
2020-07-28 14:15:23 +00:00
|
|
|
ParamCount: 2, DisallowCallback: true},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemStorageGet, Func: storageGet, Price: 1000000, RequiredFlags: smartcontract.AllowStates,
|
2020-07-28 14:15:23 +00:00
|
|
|
ParamCount: 2, DisallowCallback: true},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemStorageGetContext, Func: storageGetContext, Price: 400,
|
2020-07-28 14:15:23 +00:00
|
|
|
RequiredFlags: smartcontract.AllowStates, DisallowCallback: true},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemStorageGetReadOnlyContext, Func: storageGetReadOnlyContext, Price: 400,
|
2020-07-28 14:15:23 +00:00
|
|
|
RequiredFlags: smartcontract.AllowStates, DisallowCallback: true},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemStoragePut, Func: storagePut, Price: 0, RequiredFlags: smartcontract.AllowModifyStates,
|
2020-07-28 14:15:23 +00:00
|
|
|
ParamCount: 3, DisallowCallback: true}, // These don't have static price in C# code.
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemStoragePutEx, Func: storagePutEx, Price: 0, RequiredFlags: smartcontract.AllowModifyStates,
|
2020-07-28 14:15:23 +00:00
|
|
|
ParamCount: 4, DisallowCallback: true},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.SystemStorageAsReadOnly, Func: storageContextAsReadOnly, Price: 400,
|
2020-07-28 14:15:23 +00:00
|
|
|
RequiredFlags: smartcontract.AllowStates, ParamCount: 1, DisallowCallback: true},
|
2019-12-18 16:49:56 +00:00
|
|
|
}
|
2019-10-11 14:00:11 +00:00
|
|
|
|
2020-04-08 10:35:39 +00:00
|
|
|
var neoInterops = []interop.Function{
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.NeoCryptoVerifyWithECDsaSecp256r1, Func: crypto.ECDSASecp256r1Verify,
|
2020-07-28 10:17:38 +00:00
|
|
|
Price: crypto.ECDSAVerifyPrice, ParamCount: 3},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.NeoCryptoVerifyWithECDsaSecp256k1, Func: crypto.ECDSASecp256k1Verify,
|
2020-07-28 10:17:38 +00:00
|
|
|
Price: crypto.ECDSAVerifyPrice, ParamCount: 3},
|
2020-08-14 10:50:52 +00:00
|
|
|
{Name: interopnames.NeoCryptoCheckMultisigWithECDsaSecp256r1, Func: crypto.ECDSASecp256r1CheckMultisig, Price: 0, ParamCount: 3},
|
|
|
|
{Name: interopnames.NeoCryptoCheckMultisigWithECDsaSecp256k1, Func: crypto.ECDSASecp256k1CheckMultisig, Price: 0, ParamCount: 3},
|
|
|
|
{Name: interopnames.NeoCryptoSHA256, Func: crypto.Sha256, Price: 1000000, ParamCount: 1},
|
|
|
|
{Name: interopnames.NeoCryptoRIPEMD160, Func: crypto.RipeMD160, Price: 1000000, ParamCount: 1},
|
|
|
|
{Name: interopnames.NeoNativeCall, Func: native.Call, Price: 0, ParamCount: 1, DisallowCallback: true},
|
|
|
|
{Name: interopnames.NeoNativeDeploy, Func: native.Deploy, Price: 0, RequiredFlags: smartcontract.AllowModifyStates, DisallowCallback: true},
|
2019-12-18 16:49:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// initIDinInteropsSlice initializes IDs from names in one given
|
2020-04-08 10:35:39 +00:00
|
|
|
// Function slice and then sorts it.
|
|
|
|
func initIDinInteropsSlice(iops []interop.Function) {
|
2019-12-18 16:49:56 +00:00
|
|
|
for i := range iops {
|
2020-08-13 07:41:33 +00:00
|
|
|
iops[i].ID = interopnames.ToID([]byte(iops[i].Name))
|
2019-10-11 14:00:11 +00:00
|
|
|
}
|
2020-07-28 13:38:00 +00:00
|
|
|
interop.Sort(iops)
|
2019-12-18 16:49:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// init initializes IDs in the global interop slices.
|
|
|
|
func init() {
|
|
|
|
initIDinInteropsSlice(systemInterops)
|
|
|
|
initIDinInteropsSlice(neoInterops)
|
2019-10-11 14:00:11 +00:00
|
|
|
}
|