From 69c1d9e357414f98c303ad673c3b6b5edab2b8c8 Mon Sep 17 00:00:00 2001 From: andri lim Date: Mon, 15 Apr 2019 11:10:40 +0700 Subject: [PATCH] fix block 2.463.413 problem --- nimbus/vm/interpreter/gas_costs.nim | 22 +++++++++++----------- nimbus/vm/interpreter/opcodes_impl.nim | 5 +---- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/nimbus/vm/interpreter/gas_costs.nim b/nimbus/vm/interpreter/gas_costs.nim index a42c7ac90..71270feb4 100644 --- a/nimbus/vm/interpreter/gas_costs.nim +++ b/nimbus/vm/interpreter/gas_costs.nim @@ -8,7 +8,7 @@ import math, eth/common/eth_types, ./utils/[macros_gen_opcodes, utils_numeric], - ./opcode_values, ./vm_forks + ./opcode_values, ./vm_forks, ../../errors # Gas Fee Schedule # Yellow Paper Appendix G - https://ethereum.github.io/yellowpaper/paper.pdf @@ -67,7 +67,7 @@ type of Call, CallCode, DelegateCall, StaticCall: c_isNewAccount*: bool c_gasBalance*: GasInt - c_contractGas*: Gasint + c_contractGas*: Uint256 c_currentMemSize*: Natural c_memOffset*: Natural c_memLength*: Natural @@ -325,16 +325,16 @@ template gasCosts(fork: Fork, prefix, ResultGasCostsName: untyped) = # Cgascap when fork >= FkTangerine: # https://github.com/ethereum/EIPs/blob/master/EIPS/eip-150.md - result.gasRefund = - if gasParams.c_gasBalance >= result.gasCost: - min( - `prefix all_but_one_64th`(gasParams.c_gasBalance - result.gasCost), - gasParams.c_contractGas - ) - else: - gasParams.c_contractGas + let gas = `prefix all_but_one_64th`(gasParams.c_gasBalance - result.gasCost) + if gasParams.c_contractGas > high(GasInt).u256 or + gas < gasParams.c_contractGas.truncate(GasInt): + result.gasRefund = gas + else: + result.gasRefund = gasParams.c_contractGas.truncate(GasInt) else: - result.gasRefund += gasParams.c_contractGas + if gasParams.c_contractGas > high(GasInt).u256: + raise newException(TypeError, "GasInt Overflow (" & $gasParams.kind & ") " & $gasParams.c_contractGas) + result.gasRefund = gasParams.c_contractGas.truncate(GasInt) result.gasCost += result.gasRefund diff --git a/nimbus/vm/interpreter/opcodes_impl.nim b/nimbus/vm/interpreter/opcodes_impl.nim index e468164f8..1e1c6d663 100644 --- a/nimbus/vm/interpreter/opcodes_impl.nim +++ b/nimbus/vm/interpreter/opcodes_impl.nim @@ -710,15 +710,12 @@ template genCall(callName: untyped, opCode: Op): untyped = else: (memOutPos, memOutLen) - if gas > high(GasInt).u256: - raise newException(TypeError, "GasInt Overflow (" & callNameStr & ")") - let (childGasFee, childGasLimit) = computation.gasCosts[opCode].c_handler( value, GasParams(kind: opCode, c_isNewAccount: isNewAccount, c_gasBalance: computation.gasMeter.gasRemaining, - c_contractGas: gas.truncate(GasInt), + c_contractGas: gas, c_currentMemSize: computation.memory.len, c_memOffset: memOffset, c_memLength: memLength