diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 35d9ccc62197..372d4a900248 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -401,11 +401,13 @@ func touchCodeChunksRangeOnReadAndChargeGas(contractAddr []byte, startPC, size u return 0 } - // endPC is the last PC that must be touched. - endPC := startPC + size - 1 - if startPC+size > codeLen { + endPC := startPC + size + if endPC > codeLen { endPC = codeLen } + if endPC > 0 { + endPC -= 1 // endPC is the last bytecode that will be touched. + } var statelessGasCharged uint64 for chunkNumber := startPC / 31; chunkNumber <= endPC/31; chunkNumber++ {