EIP-7883: ModExp Gas Cost Increase

Increases cost of ModExp precompile


Metadata
Status: DraftStandards Track: CoreCreated: 2025-02-11
Authors
Marcin Sobczak (@marcindsobczak), Marek Moraczyński (@MarekM25), Marcos Maceo (@stdevMac)
Requires

Abstract


This EIP is modifying the ModExp precompile pricing algorithm introduced in EIP-2565.

Motivation


There are cases where the ModExp precompile is underpriced for it's resource consumption. By modifying the ModExp pricing formula these scenarios would be covered with minimal impact on real world applications. The target is to make ModExp at least as fast as EcRecover precompile in all cases.

Specification


Upon activation of this EIP, the gas cost of calling the precompile at address 0x0000000000000000000000000000000000000005 will be calculated as follows:


Changes (with algorithm from EIP-2565):

1. Increase minimal price from 200 to 500

This part of equation:


Is replaced by this:


2. Increase cost when exponent is larger than 32 bytes

This part of equation:


Is replaced by this:


Multiplier 8 is replaced by 16.

3. Increase cost when base or modulus is larger than 32 bytes

This part of equation:


Is replaced by this:


Multiplication complexity is doubled if base or modulus is bigger than 32 bytes.

Rationale


After benchmarking the ModExp precompile, we identified certain scenarios that are underpriced and require repricing to ensure appropriate costs. Further research revealed that all underpriced edge cases can be addressed by adjusting the parameters in the current ModExp pricing formula. With these changes, the minimum cost for using the ModExp precompile will increase from 200 to 500 (a 150% increase), and the cost will scale higher when the base, modulus, or exponent exceed 32 bytes. These adjustments will ensure that the worst-performing edge cases of the ModExp precompile perform no worse than the EcRecover precompile.

Backwards Compatibility


This change is backwards incompatible. However, similar gas repricings have occurred multiple times in the Ethereum ecosystem, and their effects are well understood.

Test Cases


There are no changes to the underlying interface or arithmetic algorithms, so the existing test vectors can be reused. Below is a table with the updated test vectors:

Test CaseEIP-2565 PricingEIP-7883 PricingIncrease
modexp_nagydani_1_square200500150%
modexp_nagydani_1_qube200500150%
modexp_nagydani_1_pow0x10001341682100%
modexp_nagydani_2_square200500150%
modexp_nagydani_2_qube200500150%
modexp_nagydani_2_pow0x1000113652730100%
modexp_nagydani_3_square341682100%
modexp_nagydani_3_qube341682100%
modexp_nagydani_3_pow0x10001546110922100%
modexp_nagydani_4_square13652730100%
modexp_nagydani_4_qube13652730100%
modexp_nagydani_4_pow0x100012184543690100%
modexp_nagydani_5_square546110922100%
modexp_nagydani_5_qube546110922100%
modexp_nagydani_5_pow0x1000187381174762100%
modexp_marius_1_even2057377483%
modexp_guido_1_even2298426185%
modexp_guido_2_even2300426285%
modexp_guido_3_even540010800100%
modexp_guido_4_even1026196792%
modexp_marcin_1_base_heavy200500150%
modexp_marcin_1_exp_heavy215500133%
modexp_marcin_1_balanced200500150%
modexp_marcin_2_base_heavy8671734100%
modexp_marcin_2_exp_heavy852136460%
modexp_marcin_2_balanced9961992100%
modexp_marcin_3_base_heavy6776770%
modexp_marcin_3_exp_heavy7657650%
modexp_marcin_3_balanced136013600%

Reference Implementation


[None]

Security Considerations


There are no security concerns since no new functionality is introduced or made cheaper. The primary consideration for this EIP is the risk of potentially overpriced ModExp scenarios.

Copyright


Copyright and related rights waived via CC0.