Skip to content

Commit

Permalink
fix(levm): for pre Berlin don't use floor cost modexp (#1675)
Browse files Browse the repository at this point in the history
**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.
  • Loading branch information
tomip01 authored Jan 9, 2025
1 parent 8184471 commit 9687e42
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/vm/levm/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit 9687e42

Please sign in to comment.