EIP-7883 ModExp gas cost increase

Final · Fees & gas · EIP status Final · created 2025-02-11

Changes the gas formula of the ModExp precompile, which computes modular exponentiation, raising the minimum cost from 200 to 500 and the general cost by about 3x.

Why it is needed

Ethereum has "precompiles", complex and frequently used computations that clients implement in advance. Among them, ModExp handles the operation that raises a large number to a power and takes the remainder after dividing by another number. Benchmarks, however, showed that for some inputs the fee (gas) was priced far too low compared with the compute resources a node actually uses. The block gas limit, the cap on the amount of work a single block can hold, must be set safely based on the slowest operation, and cheap but heavy ModExp calls stand in the way of raising it. This EIP proposes adjusting the parameters of the pricing formula defined in EIP-2565 to correct the underpriced cases and make room for raising the block gas limit.

What changes

Today

After EIP-7883

Who is affected

In depth

Increase of the minimum and general cost

The last step of the gas calculation changes from max(200, math.floor(multiplication_complexity * iteration_count / 3)) to max(500, math.floor(multiplication_complexity * iteration_count)). The minimum gas rises from 200 to 500 (a 150% increase), and the division by 3 is removed, so the general cost triples (a 200% increase). The interface and the computation algorithm themselves do not change. Only the pricing formula does.

Double the cost for exponents over 32 bytes

In the iteration_count calculation for an exponent longer than 32 bytes, the factor applied to the excess length rises from 8 to 16. The changed formula is iteration_count = (16 * (exponent_length - 32)) + ((exponent & (2**256 - 1)).bit_length() - 1). The longer the exponent a call uses, the more steeply its cost rises.

Introducing a minimum multiplication complexity and weighting large inputs

calculate_multiplication_complexity changes. It used to return words**2 as is, but the new formula sets the complexity to 16 by default and computes it as 2 * words**2 only when max(base_length, modulus_length) exceeds 32 bytes. In other words, the lengths of the base and the modulus are treated as at least 32 bytes, and the complexity is doubled once they exceed 32 bytes. words is computed as math.ceil(max_length / 8).

Effect on actual calls

As of January 4, 2025, about 99.69% of past ModExp calls see either the 150% increase from 200 to 500 or the 200% increase that triples a cost of about 1360 gas. Edge cases, however, rise much more. Based on the test vectors, modexp_marcin_1_exp_heavy rises from 215 to 16624 gas, an increase of 7632%, and modexp_guido_4_even rises from 1026 to 94448 gas, an increase of 9105%. The existing test vectors can be reused as they are.

Rationale for the adjustment and backward compatibility

Benchmarks identified scenarios in which the gas cost of ModExp was significantly underpriced, and this adjustment corrects that underpricing by changing the parameters of the existing pricing formula. The goal is to ensure that even the heaviest edge case on every execution layer client does not block a block gas limit increase. This change is a price increase that is not backward compatible, but the source explains that similar gas repricings have happened several times on Ethereum and that their effects are well understood. Links to the proposal's empirical analysis and to the analysis by affected party are included in the source.

Security perspective

This EIP neither adds new functionality nor makes existing operations cheaper, so there is no direct security concern from new attack vectors or lower costs. The remaining risk is that some ModExp scenarios could end up overpriced, which the source judges to be smaller than the current underpricing problem. The status of this EIP is set to Final.

Original EIP · ← EIPs