From 5ca990184f50168722810fb4c7c7d16cd1e9eb81 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Sat, 20 Nov 2021 09:12:57 +0100 Subject: [PATCH] fix boundary check in PUSH --- core/vm/instructions.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 4eec1d3014..27542af176 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -971,7 +971,11 @@ func makePush(size uint64, pushByteSize int) executionFunc { for ; count < 31 && !scope.Contract.IsCode(chunk*31+count); count++ { } value[0] = byte(count) - copy(value[1:], scope.Contract.Code[chunk*31:(chunk+1)*31]) + end := (chunk + 1) * 31 + if end > uint64(len(scope.Contract.Code)) { + end = uint64(len(scope.Contract.Code)) + } + copy(value[1:], scope.Contract.Code[chunk*31:end]) index := trieUtils.GetTreeKeyCodeChunk(scope.Contract.Address().Bytes(), uint256.NewInt(chunk)) interpreter.evm.TxContext.Accesses.TouchAddressAndChargeGas(index, nil)