fix integer underflow (#374)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
This commit is contained in:
Ignacio Hagopian 2024-02-15 09:47:03 -03:00 committed by Guillaume Ballet
parent 077ad8728f
commit 8ac057090e

View file

@ -401,11 +401,13 @@ func touchCodeChunksRangeOnReadAndChargeGas(contractAddr []byte, startPC, size u
return 0 return 0
} }
// endPC is the last PC that must be touched. endPC := startPC + size
endPC := startPC + size - 1 if endPC > codeLen {
if startPC+size > codeLen {
endPC = codeLen endPC = codeLen
} }
if endPC > 0 {
endPC -= 1 // endPC is the last bytecode that will be touched.
}
var statelessGasCharged uint64 var statelessGasCharged uint64
for chunkNumber := startPC / 31; chunkNumber <= endPC/31; chunkNumber++ { for chunkNumber := startPC / 31; chunkNumber <= endPC/31; chunkNumber++ {