From ec159c0da162e091eb479103b15b150837158850 Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Fri, 9 Feb 2024 14:34:25 -0300 Subject: [PATCH] fix integer underflow Signed-off-by: Ignacio Hagopian --- core/vm/instructions.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 7fb340da7b24..3b2b0d33c70b 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++ {