From 540ac23ca82facc028433275aa4cd88dad103be4 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 19 Jun 2020 12:21:37 +0300 Subject: [PATCH 1/4] core: calculate prices of `Neo.Crypt.*` opcodes correctly --- pkg/core/interop/crypto/ecdsa.go | 7 +++++++ pkg/core/interops.go | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/core/interop/crypto/ecdsa.go b/pkg/core/interop/crypto/ecdsa.go index d80d67578..cdcee4c23 100644 --- a/pkg/core/interop/crypto/ecdsa.go +++ b/pkg/core/interop/crypto/ecdsa.go @@ -8,10 +8,14 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto" "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/util" "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) +// ECDSAVerifyPrice is a gas price of a single verification. +const ECDSAVerifyPrice = 1000000 + // ECDSAVerify checks ECDSA signature. func ECDSAVerify(ic *interop.Context, v *vm.VM) error { msg := getMessage(ic, v.Estack().Pop().Item()) @@ -35,6 +39,9 @@ func ECDSACheckMultisig(ic *interop.Context, v *vm.VM) error { if err != nil { return fmt.Errorf("wrong parameters: %s", err.Error()) } + if !v.AddGas(util.Fixed8(ECDSAVerifyPrice * len(pkeys))) { + return errors.New("gas limit exceeded") + } sigs, err := v.Estack().PopSigElements() if err != nil { return fmt.Errorf("wrong parameters: %s", err.Error()) diff --git a/pkg/core/interops.go b/pkg/core/interops.go index 7f8629061..37b007248 100644 --- a/pkg/core/interops.go +++ b/pkg/core/interops.go @@ -138,9 +138,9 @@ var systemInterops = []interop.Function{ } var neoInterops = []interop.Function{ - {Name: "Neo.Crypto.ECDsaVerify", Func: crypto.ECDSAVerify, Price: 1}, - {Name: "Neo.Crypto.ECDsaCheckMultiSig", Func: crypto.ECDSACheckMultisig, Price: 1}, - {Name: "Neo.Crypto.SHA256", Func: crypto.Sha256, Price: 1}, + {Name: "Neo.Crypto.ECDsaVerify", Func: crypto.ECDSAVerify, Price: crypto.ECDSAVerifyPrice}, + {Name: "Neo.Crypto.ECDsaCheckMultiSig", Func: crypto.ECDSACheckMultisig, Price: 0}, + {Name: "Neo.Crypto.SHA256", Func: crypto.Sha256, Price: 1000000}, {Name: "Neo.Native.Deploy", Func: native.Deploy, Price: 1, AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowModifyStates}, } From 4b31c183160ff840456e2bc3b617441d12b827b5 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 19 Jun 2020 12:22:18 +0300 Subject: [PATCH 2/4] core: fix `Neo.Native.Deploy` price --- pkg/core/interops.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/core/interops.go b/pkg/core/interops.go index 37b007248..35bb5e5ae 100644 --- a/pkg/core/interops.go +++ b/pkg/core/interops.go @@ -141,7 +141,7 @@ var neoInterops = []interop.Function{ {Name: "Neo.Crypto.ECDsaVerify", Func: crypto.ECDSAVerify, Price: crypto.ECDSAVerifyPrice}, {Name: "Neo.Crypto.ECDsaCheckMultiSig", Func: crypto.ECDSACheckMultisig, Price: 0}, {Name: "Neo.Crypto.SHA256", Func: crypto.Sha256, Price: 1000000}, - {Name: "Neo.Native.Deploy", Func: native.Deploy, Price: 1, + {Name: "Neo.Native.Deploy", Func: native.Deploy, Price: 0, AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowModifyStates}, } From 47f53e612e65667fcc7bc985ff0d7b1e10848914 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 19 Jun 2020 12:33:33 +0300 Subject: [PATCH 3/4] vm: fix Log and Notify default interop prices --- pkg/vm/interop.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/vm/interop.go b/pkg/vm/interop.go index f0dd90f35..2cc188bc6 100644 --- a/pkg/vm/interop.go +++ b/pkg/vm/interop.go @@ -40,9 +40,9 @@ var defaultVMInterops = []interopIDFuncPrice{ {emit.InteropNameToID([]byte("System.Binary.Serialize")), InteropFuncPrice{Func: RuntimeSerialize, Price: 100000}}, {emit.InteropNameToID([]byte("System.Runtime.Log")), - InteropFuncPrice{Func: runtimeLog, Price: 1}}, + InteropFuncPrice{Func: runtimeLog, Price: 1000000, RequiredFlags: smartcontract.AllowNotify}}, {emit.InteropNameToID([]byte("System.Runtime.Notify")), - InteropFuncPrice{Func: runtimeNotify, Price: 1}}, + InteropFuncPrice{Func: runtimeNotify, Price: 1000000, RequiredFlags: smartcontract.AllowNotify}}, {emit.InteropNameToID([]byte("System.Enumerator.Create")), InteropFuncPrice{Func: EnumeratorCreate, Price: 400}}, {emit.InteropNameToID([]byte("System.Enumerator.Next")), From a584c5a6a4269970a4d77a44edbd2db4bae95ab4 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 19 Jun 2020 12:45:51 +0300 Subject: [PATCH 4/4] native: fix NEP5 contract method prices Closes #1073. --- pkg/core/native/native_nep5.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/core/native/native_nep5.go b/pkg/core/native/native_nep5.go index f12160de5..63bdf7321 100644 --- a/pkg/core/native/native_nep5.go +++ b/pkg/core/native/native_nep5.go @@ -50,24 +50,24 @@ func newNEP5Native(name string) *nep5TokenNative { n := &nep5TokenNative{ContractMD: *interop.NewContractMD(name)} desc := newDescriptor("name", smartcontract.StringType) - md := newMethodAndPrice(n.Name, 1, smartcontract.NoneFlag) + md := newMethodAndPrice(n.Name, 0, smartcontract.NoneFlag) n.AddMethod(md, desc, true) desc = newDescriptor("symbol", smartcontract.StringType) - md = newMethodAndPrice(n.Symbol, 1, smartcontract.NoneFlag) + md = newMethodAndPrice(n.Symbol, 0, smartcontract.NoneFlag) n.AddMethod(md, desc, true) desc = newDescriptor("decimals", smartcontract.IntegerType) - md = newMethodAndPrice(n.Decimals, 1, smartcontract.NoneFlag) + md = newMethodAndPrice(n.Decimals, 0, smartcontract.NoneFlag) n.AddMethod(md, desc, true) desc = newDescriptor("totalSupply", smartcontract.IntegerType) - md = newMethodAndPrice(n.TotalSupply, 1, smartcontract.AllowStates) + md = newMethodAndPrice(n.TotalSupply, 1000000, smartcontract.AllowStates) n.AddMethod(md, desc, true) desc = newDescriptor("balanceOf", smartcontract.IntegerType, manifest.NewParameter("account", smartcontract.Hash160Type)) - md = newMethodAndPrice(n.balanceOf, 1, smartcontract.AllowStates) + md = newMethodAndPrice(n.balanceOf, 1000000, smartcontract.AllowStates) n.AddMethod(md, desc, true) desc = newDescriptor("transfer", smartcontract.BoolType, @@ -75,7 +75,7 @@ func newNEP5Native(name string) *nep5TokenNative { manifest.NewParameter("to", smartcontract.Hash160Type), manifest.NewParameter("amount", smartcontract.IntegerType), ) - md = newMethodAndPrice(n.Transfer, 1, smartcontract.AllowModifyStates) + md = newMethodAndPrice(n.Transfer, 8000000, smartcontract.AllowModifyStates) n.AddMethod(md, desc, false) desc = newDescriptor("onPersist", smartcontract.BoolType)