From f5dae8e25496bc80e89ea98cfa4768fb6e095e68 Mon Sep 17 00:00:00 2001 From: IAvecilla Date: Fri, 13 Sep 2024 12:33:51 -0300 Subject: [PATCH] Remove unnecesary memory checks --- system-contracts/contracts/EvmInterpreter.yul | 12 ++++++++---- .../evm-interpreter/EvmInterpreterLoop.template.yul | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index 85a575b02..dca506aab 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -2966,7 +2966,8 @@ object "EVMInterpreter" { evmGasLeft := chargeGas(evmGasLeft,expandMemory(add(offset,size))) returnLen := size - checkOverflow(offset,MEM_OFFSET_INNER(), evmGasLeft) + + // Don't check overflow here since previous checks are enough to ensure this is safe returnOffset := add(MEM_OFFSET_INNER(), offset) break } @@ -3006,7 +3007,8 @@ object "EVMInterpreter" { checkMemOverflowByOffset(add(offset, size), evmGasLeft) evmGasLeft := chargeGas(evmGasLeft,expandMemory(add(offset,size))) - checkOverflow(offset,MEM_OFFSET_INNER(), evmGasLeft) + + // Don't check overflow here since previous checks are enough to ensure this is safe offset := add(offset, MEM_OFFSET_INNER()) offset,size := addGasIfEvmRevert(isCallerEVM,offset,size,evmGasLeft) @@ -5940,7 +5942,8 @@ object "EVMInterpreter" { evmGasLeft := chargeGas(evmGasLeft,expandMemory(add(offset,size))) returnLen := size - checkOverflow(offset,MEM_OFFSET_INNER(), evmGasLeft) + + // Don't check overflow here since previous checks are enough to ensure this is safe returnOffset := add(MEM_OFFSET_INNER(), offset) break } @@ -5980,7 +5983,8 @@ object "EVMInterpreter" { checkMemOverflowByOffset(add(offset, size), evmGasLeft) evmGasLeft := chargeGas(evmGasLeft,expandMemory(add(offset,size))) - checkOverflow(offset,MEM_OFFSET_INNER(), evmGasLeft) + + // Don't check overflow here since previous checks are enough to ensure this is safe offset := add(offset, MEM_OFFSET_INNER()) offset,size := addGasIfEvmRevert(isCallerEVM,offset,size,evmGasLeft) diff --git a/system-contracts/evm-interpreter/EvmInterpreterLoop.template.yul b/system-contracts/evm-interpreter/EvmInterpreterLoop.template.yul index c6fba46c4..eb2cac4ec 100644 --- a/system-contracts/evm-interpreter/EvmInterpreterLoop.template.yul +++ b/system-contracts/evm-interpreter/EvmInterpreterLoop.template.yul @@ -1406,7 +1406,8 @@ for { } true { } { evmGasLeft := chargeGas(evmGasLeft,expandMemory(add(offset,size))) returnLen := size - checkOverflow(offset,MEM_OFFSET_INNER(), evmGasLeft) + + // Don't check overflow here since previous checks are enough to ensure this is safe returnOffset := add(MEM_OFFSET_INNER(), offset) break } @@ -1446,7 +1447,8 @@ for { } true { } { checkMemOverflowByOffset(add(offset, size), evmGasLeft) evmGasLeft := chargeGas(evmGasLeft,expandMemory(add(offset,size))) - checkOverflow(offset,MEM_OFFSET_INNER(), evmGasLeft) + + // Don't check overflow here since previous checks are enough to ensure this is safe offset := add(offset, MEM_OFFSET_INNER()) offset,size := addGasIfEvmRevert(isCallerEVM,offset,size,evmGasLeft)