core: calculate prices of Neo.Crypt.* opcodes correctly

This commit is contained in:
Evgenii Stratonikov 2020-06-19 12:21:37 +03:00
parent ce6bacd51a
commit 540ac23ca8
2 changed files with 10 additions and 3 deletions

View file

@ -8,10 +8,14 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto" "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/hash"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "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"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "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. // ECDSAVerify checks ECDSA signature.
func ECDSAVerify(ic *interop.Context, v *vm.VM) error { func ECDSAVerify(ic *interop.Context, v *vm.VM) error {
msg := getMessage(ic, v.Estack().Pop().Item()) msg := getMessage(ic, v.Estack().Pop().Item())
@ -35,6 +39,9 @@ func ECDSACheckMultisig(ic *interop.Context, v *vm.VM) error {
if err != nil { if err != nil {
return fmt.Errorf("wrong parameters: %s", err.Error()) 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() sigs, err := v.Estack().PopSigElements()
if err != nil { if err != nil {
return fmt.Errorf("wrong parameters: %s", err.Error()) return fmt.Errorf("wrong parameters: %s", err.Error())

View file

@ -138,9 +138,9 @@ var systemInterops = []interop.Function{
} }
var neoInterops = []interop.Function{ var neoInterops = []interop.Function{
{Name: "Neo.Crypto.ECDsaVerify", Func: crypto.ECDSAVerify, Price: 1}, {Name: "Neo.Crypto.ECDsaVerify", Func: crypto.ECDSAVerify, Price: crypto.ECDSAVerifyPrice},
{Name: "Neo.Crypto.ECDsaCheckMultiSig", Func: crypto.ECDSACheckMultisig, Price: 1}, {Name: "Neo.Crypto.ECDsaCheckMultiSig", Func: crypto.ECDSACheckMultisig, Price: 0},
{Name: "Neo.Crypto.SHA256", Func: crypto.Sha256, Price: 1}, {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: 1,
AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowModifyStates}, AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowModifyStates},
} }