From 9204b95d5be52eceeadda334b17298c66c61edf4 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 6 Feb 2020 18:15:13 +0300 Subject: [PATCH] core: fix GAS price definitions --- pkg/core/gas_price.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/pkg/core/gas_price.go b/pkg/core/gas_price.go index e9ebdeaf0..cbed653ee 100644 --- a/pkg/core/gas_price.go +++ b/pkg/core/gas_price.go @@ -21,20 +21,20 @@ func getPrice(v *vm.VM, op opcode.Opcode, parameter []byte) util.Fixed8 { switch op { case opcode.APPCALL, opcode.TAILCALL: - return util.Fixed8FromInt64(10) + return toFixed8(10) case opcode.SYSCALL: interopID := vm.GetInteropID(parameter) return getSyscallPrice(v, interopID) case opcode.SHA1, opcode.SHA256: - return util.Fixed8FromInt64(10) + return toFixed8(10) case opcode.HASH160, opcode.HASH256: - return util.Fixed8FromInt64(20) + return toFixed8(20) case opcode.CHECKSIG, opcode.VERIFY: - return util.Fixed8FromInt64(100) + return toFixed8(100) case opcode.CHECKMULTISIG: estack := v.Estack() if estack.Len() == 0 { - return util.Fixed8FromInt64(1) + return toFixed8(1) } var cost int @@ -48,21 +48,25 @@ func getPrice(v *vm.VM, op opcode.Opcode, parameter []byte) util.Fixed8 { } if cost < 1 { - return util.Fixed8FromInt64(1) + return toFixed8(1) } - return util.Fixed8FromInt64(int64(100 * cost)) + return toFixed8(int64(100 * cost)) default: - return util.Fixed8FromInt64(1) + return toFixed8(1) } } +func toFixed8(n int64) util.Fixed8 { + return util.Fixed8(n * interopGasRatio) +} + // getSyscallPrice returns cost of executing syscall with provided id. // Is SYSCALL is not found, cost is 1. func getSyscallPrice(v *vm.VM, id uint32) util.Fixed8 { ifunc := v.GetInteropByID(id) if ifunc != nil && ifunc.Price > 0 { - return util.Fixed8(ifunc.Price) * interopGasRatio + return toFixed8(int64(ifunc.Price)) } const (