This EIP is modifying the ModExp precompile pricing algorithm introduced in EIP-2565.
Motivation
Currently the ModExp precompile is underpriced in certain scenarios relative to its resource consumption. By adjusting the pricing formula, this EIP aims to address these discrepancies, making ModExp sufficiently efficient to enable potential increases in the block gas limit.
Specification
Upon activation of this EIP, the gas cost of calling the precompile at address 0x0000000000000000000000000000000000000005 will be calculated as follows:
This change introduces a minimal multiplication complexity of 16 and doubles the complexity if the base or modulus length exceeds 32 bytes.
Rationale
Benchmarking the ModExp precompile revealed several scenarios where its gas cost was significantly underestimated. Pricing adjustments are designed to rectify underpriced edge cases by modifying the existing ModExp pricing formula parameters. Specifically, the minimum cost for ModExp will rise from 200 to 500 (a 150% increase), the general cost will triple (a 200% increase), a minimum base/modulus length of 32 bytes will be assumed and the cost will scale more aggressively when the base, modulus, or exponent exceed 32 bytes. These modifications aim to ensure that the ModExp precompile’s performance, even in its most resource-intensive edge cases across all execution layer clients, no longer impedes potential increases to the block gas limit.
Backwards Compatibility
This EIP introduces a backwards-incompatible change. However, similar gas repricings have occurred multiple times in the Ethereum ecosystem, and their effects are well understood.
Test Cases
The most common usages (approximately 99.69% of historical Modexp calls as of January 4th, 2025) will experience either a 150% increase (from 200 to 500 gas) or a 200% increase (tripling from approximately 1360 gas).
No changes are made to the underlying interface or arithmetic algorithms, allowing existing test vectors to be reused. The table below presents the updated gas costs for these test vectors:
This EIP does not introduce any new functionality or make existing operations cheaper, therefore there are no direct security concerns related to new attack vectors or reduced costs. The primary security consideration for this EIP is the potential for ModExp scenarios to be overpriced, though this is deemed a lesser risk compared to the current underpricing issues.