From fb888645d8f2c07b64554fe7d84c5d169c578856 Mon Sep 17 00:00:00 2001 From: Gianbelinche Date: Fri, 17 May 2024 15:15:15 -0300 Subject: [PATCH] Optimize sload --- .../contracts/EvmInterpreterLoop.template.yul | 6 ++++-- .../contracts/EvmInterpreterPreprocessed.yul | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/system-contracts/contracts/EvmInterpreterLoop.template.yul b/system-contracts/contracts/EvmInterpreterLoop.template.yul index 2bd8d7b7a..a6b067811 100644 --- a/system-contracts/contracts/EvmInterpreterLoop.template.yul +++ b/system-contracts/contracts/EvmInterpreterLoop.template.yul @@ -578,13 +578,15 @@ for { } true { } { key, sp := popStackItem(sp) - if iszero(isSlotWarm(key)) { + let wasWarm := isSlotWarm(key) + + if iszero(wasWarm) { evmGasLeft := chargeGas(evmGasLeft, 2000) } value := sload(key) - if iszero(isSlotWarm(key)) { + if iszero(wasWarm) { let _wasW, _orgV := warmSlot(key, value) } diff --git a/system-contracts/contracts/EvmInterpreterPreprocessed.yul b/system-contracts/contracts/EvmInterpreterPreprocessed.yul index e037e09ac..1b3701804 100644 --- a/system-contracts/contracts/EvmInterpreterPreprocessed.yul +++ b/system-contracts/contracts/EvmInterpreterPreprocessed.yul @@ -1870,13 +1870,15 @@ object "EVMInterpreter" { key, sp := popStackItem(sp) - if iszero(isSlotWarm(key)) { + let wasWarm := isSlotWarm(key) + + if iszero(wasWarm) { evmGasLeft := chargeGas(evmGasLeft, 2000) } value := sload(key) - if iszero(isSlotWarm(key)) { + if iszero(wasWarm) { let _wasW, _orgV := warmSlot(key, value) } @@ -4457,13 +4459,15 @@ object "EVMInterpreter" { key, sp := popStackItem(sp) - if iszero(isSlotWarm(key)) { + let wasWarm := isSlotWarm(key) + + if iszero(wasWarm) { evmGasLeft := chargeGas(evmGasLeft, 2000) } value := sload(key) - if iszero(isSlotWarm(key)) { + if iszero(wasWarm) { let _wasW, _orgV := warmSlot(key, value) }