From 9687e42db45910a2da7035b8288f70001e373ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s?= <112426153+tomip01@users.noreply.github.com> Date: Thu, 9 Jan 2025 16:13:41 -0300 Subject: [PATCH] fix(levm): for pre Berlin don't use floor cost modexp (#1675) **Motivation** This PR is for fixing the Ethereum Foundation Tests on the ModExp precompile. **Description** When the `base_size` and `modulus_size` is Zero, there is an early return to not make all the operations. In the Berlin fork was introduced a floor for the gas cost. We were returning this floor cost also for the previous forks to Berlin. Now is only added after Berlin. --- crates/vm/levm/src/precompiles.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/vm/levm/src/precompiles.rs b/crates/vm/levm/src/precompiles.rs index e9a36c6041..08ab64cd5c 100644 --- a/crates/vm/levm/src/precompiles.rs +++ b/crates/vm/levm/src/precompiles.rs @@ -306,7 +306,11 @@ pub fn modexp( ); if base_size == U256::zero() && modulus_size == U256::zero() { - increase_precompile_consumed_gas(gas_for_call, MODEXP_STATIC_COST, consumed_gas)?; + // On Berlin or newer there is a floor cost for the modexp precompile + // On older versions in this return there is no cost added, see more https://eips.ethereum.org/EIPS/eip-2565 + if spec_id >= SpecId::BERLIN { + increase_precompile_consumed_gas(gas_for_call, MODEXP_STATIC_COST, consumed_gas)?; + } return Ok(Bytes::new()); }