From 82aa1a2da4977f72c9f9998dbba53149cb74e804 Mon Sep 17 00:00:00 2001 From: Vladislav Volosnikov Date: Mon, 28 Oct 2024 10:33:23 +0100 Subject: [PATCH] fix(EVM): Fix TODOs in EvmGasManager (#1038) --- system-contracts/contracts/EvmGasManager.yul | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/system-contracts/contracts/EvmGasManager.yul b/system-contracts/contracts/EvmGasManager.yul index 02fb6c148..151680825 100644 --- a/system-contracts/contracts/EvmGasManager.yul +++ b/system-contracts/contracts/EvmGasManager.yul @@ -23,7 +23,7 @@ object "EvmGasManager" { } function PRECOMPILES_END() -> value { - value := sub(0xffff, 1) // TODO should we exclude system contracts? + value := 0x0a // As in Cancun } function EVM_GAS_SLOT() -> value { @@ -71,7 +71,9 @@ object "EvmGasManager" { let notSystemCall := iszero(and(callFlags, 2)) if notSystemCall { - revert(0, 0) // TODO errors? + // error CallerMustBeEvmContract() + mstore(0, 0xBE4BF9E400000000000000000000000000000000000000000000000000000000) + revert(0, 32) } // SELFDESTRUCT is not supported, so it is ok to cache here @@ -82,7 +84,9 @@ object "EvmGasManager" { isEVM := eq(shr(248, versionedCodeHash), 2) if iszero(isEVM) { - revert(0, 0) + // error CallerMustBeEvmContract() + mstore(0, 0xBE4BF9E400000000000000000000000000000000000000000000000000000000) + revert(0, 32) } // we will not cache contract if it is being constructed @@ -118,7 +122,8 @@ object "EvmGasManager" { let wasWarm := true - if gt(account, PRECOMPILES_END()) { + // precompiles are always warm + if or(iszero(account), gt(account, PRECOMPILES_END())) { let transientSlot := or(IS_ACCOUNT_WARM_PREFIX(), account) wasWarm := tload(transientSlot) @@ -223,6 +228,7 @@ object "EvmGasManager" { } // We should mark the EVM contract as warm too. warmAccount(caller()) + warmAccount(coinbase()) // and the coinbase too return(0x0, 0x0) } default {