Merge pull request #1053 from nspcc-dev/fix/interop

Adjust prices for binary/enumerator/iterator syscalls
This commit is contained in:
Roman Khimov 2020-06-16 11:12:21 +03:00 committed by GitHub
commit 349110149f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 46 deletions

View file

@ -25,8 +25,8 @@ var syscalls = map[string]map[string]string{
"Notify": "System.Runtime.Notify",
"Log": "System.Runtime.Log",
"GetTime": "System.Runtime.GetTime",
"Serialize": "System.Runtime.Serialize",
"Deserialize": "System.Runtime.Deserialize",
"Serialize": "System.Binary.Serialize",
"Deserialize": "System.Binary.Deserialize",
},
"blockchain": {
"GetBlock": "System.Blockchain.GetBlock",

View file

@ -68,6 +68,8 @@ func getInteropFromSlice(ic *interop.Context, slice []interop.Function) func(uin
// All lists are sorted, keep 'em this way, please.
var systemInterops = []interop.Function{
{Name: "System.Binary.Deserialize", Func: runtimeDeserialize, Price: 500000},
{Name: "System.Binary.Serialize", Func: runtimeSerialize, Price: 100000},
{Name: "System.Blockchain.GetBlock", Func: bcGetBlock, Price: 250,
AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowStates},
{Name: "System.Blockchain.GetContract", Func: bcGetContract, Price: 100,
@ -90,28 +92,26 @@ var systemInterops = []interop.Function{
AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowModifyStates},
{Name: "System.Contract.Update", Func: contractUpdate, Price: 0,
AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowModifyStates},
{Name: "System.Enumerator.Concat", Func: enumerator.Concat, Price: 1},
{Name: "System.Enumerator.Create", Func: enumerator.Create, Price: 1},
{Name: "System.Enumerator.Next", Func: enumerator.Next, Price: 1},
{Name: "System.Enumerator.Value", Func: enumerator.Value, Price: 1},
{Name: "System.Enumerator.Concat", Func: enumerator.Concat, Price: 400},
{Name: "System.Enumerator.Create", Func: enumerator.Create, Price: 400},
{Name: "System.Enumerator.Next", Func: enumerator.Next, Price: 1000000},
{Name: "System.Enumerator.Value", Func: enumerator.Value, Price: 400},
{Name: "System.ExecutionEngine.GetCallingScriptHash", Func: engineGetCallingScriptHash, Price: 1},
{Name: "System.ExecutionEngine.GetEntryScriptHash", Func: engineGetEntryScriptHash, Price: 1},
{Name: "System.ExecutionEngine.GetExecutingScriptHash", Func: engineGetExecutingScriptHash, Price: 1},
{Name: "System.ExecutionEngine.GetScriptContainer", Func: engineGetScriptContainer, Price: 1},
{Name: "System.Iterator.Concat", Func: iterator.Concat, Price: 1},
{Name: "System.Iterator.Create", Func: iterator.Create, Price: 1},
{Name: "System.Iterator.Key", Func: iterator.Key, Price: 1},
{Name: "System.Iterator.Keys", Func: iterator.Keys, Price: 1},
{Name: "System.Iterator.Values", Func: iterator.Values, Price: 1},
{Name: "System.Iterator.Concat", Func: iterator.Concat, Price: 400},
{Name: "System.Iterator.Create", Func: iterator.Create, Price: 400},
{Name: "System.Iterator.Key", Func: iterator.Key, Price: 400},
{Name: "System.Iterator.Keys", Func: iterator.Keys, Price: 400},
{Name: "System.Iterator.Values", Func: iterator.Values, Price: 400},
{Name: "System.Runtime.CheckWitness", Func: runtime.CheckWitness, Price: 200, RequiredFlags: smartcontract.AllowStates},
{Name: "System.Runtime.Deserialize", Func: runtimeDeserialize, Price: 1},
{Name: "System.Runtime.GetTime", Func: runtimeGetTime, Price: 1,
AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowStates},
{Name: "System.Runtime.GetTrigger", Func: runtimeGetTrigger, Price: 1},
{Name: "System.Runtime.Log", Func: runtimeLog, Price: 1, RequiredFlags: smartcontract.AllowNotify},
{Name: "System.Runtime.Notify", Func: runtimeNotify, Price: 1, RequiredFlags: smartcontract.AllowNotify},
{Name: "System.Runtime.Platform", Func: runtimePlatform, Price: 1},
{Name: "System.Runtime.Serialize", Func: runtimeSerialize, Price: 1},
{Name: "System.Storage.Delete", Func: storageDelete, Price: StoragePrice,
AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowModifyStates},
{Name: "System.Storage.Find", Func: storageFind, Price: 1000000,

View file

@ -0,0 +1,18 @@
/*
Package binary provides binary serialization routines.
*/
package binary
// Serialize serializes any given item into a byte slice. It works for all
// regular VM types (not ones from interop package) and allows to save them in
// storage or pass into Notify and then Deserialize them on the next run or in
// the external event receiver. It uses `System.Binary.Serialize` syscall.
func Serialize(item interface{}) []byte {
return nil
}
// Deserialize unpacks previously serialized value from a byte slice, it's the
// opposite of Serialize. It uses `System.Binary.Deserialize` syscall.
func Deserialize(b []byte) interface{} {
return nil
}

View file

@ -54,17 +54,3 @@ func Application() byte {
func Verification() byte {
return 0x00
}
// Serialize serializes any given item into a byte slice. It works for all
// regular VM types (not ones from interop package) and allows to save them in
// storage or pass into Notify and then Deserialize them on the next run or in
// the external event receiver. It uses `System.Runtime.Serialize` syscall.
func Serialize(item interface{}) []byte {
return nil
}
// Deserialize unpacks previously serialized value from a byte slice, it's the
// opposite of Serialize. It uses `System.Runtime.Deserialize` syscall.
func Deserialize(b []byte) interface{} {
return nil
}

View file

@ -35,32 +35,32 @@ type interopIDFuncPrice struct {
type InteropGetterFunc func(uint32) *InteropFuncPrice
var defaultVMInterops = []interopIDFuncPrice{
{emit.InteropNameToID([]byte("System.Binary.Deserialize")),
InteropFuncPrice{Func: RuntimeDeserialize, Price: 500000}},
{emit.InteropNameToID([]byte("System.Binary.Serialize")),
InteropFuncPrice{Func: RuntimeSerialize, Price: 100000}},
{emit.InteropNameToID([]byte("System.Runtime.Log")),
InteropFuncPrice{Func: runtimeLog, Price: 1}},
{emit.InteropNameToID([]byte("System.Runtime.Notify")),
InteropFuncPrice{Func: runtimeNotify, Price: 1}},
{emit.InteropNameToID([]byte("System.Runtime.Serialize")),
InteropFuncPrice{Func: RuntimeSerialize, Price: 1}},
{emit.InteropNameToID([]byte("System.Runtime.Deserialize")),
InteropFuncPrice{Func: RuntimeDeserialize, Price: 1}},
{emit.InteropNameToID([]byte("System.Enumerator.Create")),
InteropFuncPrice{Func: EnumeratorCreate, Price: 1}},
InteropFuncPrice{Func: EnumeratorCreate, Price: 400}},
{emit.InteropNameToID([]byte("System.Enumerator.Next")),
InteropFuncPrice{Func: EnumeratorNext, Price: 1}},
InteropFuncPrice{Func: EnumeratorNext, Price: 1000000}},
{emit.InteropNameToID([]byte("System.Enumerator.Concat")),
InteropFuncPrice{Func: EnumeratorConcat, Price: 1}},
InteropFuncPrice{Func: EnumeratorConcat, Price: 400}},
{emit.InteropNameToID([]byte("System.Enumerator.Value")),
InteropFuncPrice{Func: EnumeratorValue, Price: 1}},
InteropFuncPrice{Func: EnumeratorValue, Price: 400}},
{emit.InteropNameToID([]byte("System.Iterator.Create")),
InteropFuncPrice{Func: IteratorCreate, Price: 1}},
InteropFuncPrice{Func: IteratorCreate, Price: 400}},
{emit.InteropNameToID([]byte("System.Iterator.Concat")),
InteropFuncPrice{Func: IteratorConcat, Price: 1}},
InteropFuncPrice{Func: IteratorConcat, Price: 400}},
{emit.InteropNameToID([]byte("System.Iterator.Key")),
InteropFuncPrice{Func: IteratorKey, Price: 1}},
InteropFuncPrice{Func: IteratorKey, Price: 400}},
{emit.InteropNameToID([]byte("System.Iterator.Keys")),
InteropFuncPrice{Func: IteratorKeys, Price: 1}},
InteropFuncPrice{Func: IteratorKeys, Price: 400}},
{emit.InteropNameToID([]byte("System.Iterator.Values")),
InteropFuncPrice{Func: IteratorValues, Price: 1}},
InteropFuncPrice{Func: IteratorValues, Price: 400}},
}
func getDefaultVMInterop(id uint32) *InteropFuncPrice {
@ -87,7 +87,7 @@ func runtimeNotify(vm *VM) error {
return nil
}
// RuntimeSerialize handles syscalls System.Runtime.Serialize and System.Runtime.Serialize.
// RuntimeSerialize handles System.Binary.Serialize syscall.
func RuntimeSerialize(vm *VM) error {
item := vm.Estack().Pop()
data, err := stackitem.SerializeItem(item.value)
@ -102,7 +102,7 @@ func RuntimeSerialize(vm *VM) error {
return nil
}
// RuntimeDeserialize handles syscalls System.Runtime.Deserialize and System.Runtime.Deserialize.
// RuntimeDeserialize handles System.Binary.Deserialize syscall.
func RuntimeDeserialize(vm *VM) error {
data := vm.Estack().Pop().Bytes()

View file

@ -656,8 +656,8 @@ func getSyscallProg(name string) (prog []byte) {
}
func getSerializeProg() (prog []byte) {
prog = append(prog, getSyscallProg("System.Runtime.Serialize")...)
prog = append(prog, getSyscallProg("System.Runtime.Deserialize")...)
prog = append(prog, getSyscallProg("System.Binary.Serialize")...)
prog = append(prog, getSyscallProg("System.Binary.Deserialize")...)
prog = append(prog, byte(opcode.RET))
return
@ -762,7 +762,7 @@ func TestSerializeStruct(t *testing.T) {
}
func TestDeserializeUnknown(t *testing.T) {
prog := append(getSyscallProg("System.Runtime.Deserialize"), byte(opcode.RET))
prog := append(getSyscallProg("System.Binary.Deserialize"), byte(opcode.RET))
data, err := stackitem.SerializeItem(stackitem.NewBigInteger(big.NewInt(123)))
require.NoError(t, err)
@ -798,7 +798,7 @@ func TestSerializeMapCompat(t *testing.T) {
emit.Bytes(buf.BinWriter, []byte("key"))
emit.Bytes(buf.BinWriter, []byte("value"))
emit.Opcode(buf.BinWriter, opcode.SETITEM)
emit.Syscall(buf.BinWriter, "System.Runtime.Serialize")
emit.Syscall(buf.BinWriter, "System.Binary.Serialize")
require.NoError(t, buf.Err)
vm := load(buf.Bytes())