From 8ac057090e965d52ef7cd5fd0a6130bdc8eed3e6 Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Thu, 15 Feb 2024 09:47:03 -0300 Subject: [PATCH] fix integer underflow (#374) 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 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++ {