Merge pull request #1076 from nspcc-dev/fix/gas

Fix interop gas prices
This commit is contained in:
Roman Khimov 2020-06-19 13:41:43 +03:00 committed by GitHub
commit 025bf9c235
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 12 deletions

View file

@ -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())

View file

@ -138,10 +138,10 @@ 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.Native.Deploy", Func: native.Deploy, 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: 0,
AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowModifyStates},
}

View file

@ -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)

View file

@ -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")),