From 540ac23ca82facc028433275aa4cd88dad103be4 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 19 Jun 2020 12:21:37 +0300 Subject: [PATCH] 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}, }