Skip to content

Conversation

@chfast
Copy link
Member

@chfast chfast commented Jun 3, 2025

From the performance analysis of the modexp precompile after EIP-7883, the increase minimal cost of 500 don't fully cover the worst case of small base/modulus. E.g. the case of the smallest base/modulus of 8 bytes the maximum exponent within the 500 gas cost budget has 880 bits. This case performs significantly worst than the average case (modulus 32 bytes).

We propose to eliminate the pathological cases of base/modulus smaller than 32 bytes by computing the gas cost as if they had 32 byte length. By the Mainnet usage data of the modexp, a modulus smaller than 32 bytes had never been used.

Additional context in the EIP discussion: https://ethereum-magicians.org/t/eip-7883-modexp-gas-cost-increase/22841/6.

The below graphs (of different zoom levels) visualize the proposed changes. They show:

  • EIP-2565 common (modulus 32 bytes) gas curve,
  • EIP-7883 gas curves for modulus 8, 16, 24, 32 bytes long,
  • The proposed gas cost collapsing moduli <= 32 bytes into single curve.

You can notice how slowly rises the EIP-7883 mod=8b curve.

EIP-7883 gas cost analysis 500

EIP-7883 gas cost analysis 1500

@chfast chfast requested a review from eth-bot as a code owner June 3, 2025 15:11
@github-actions github-actions bot added c-update Modifies an existing proposal s-draft This EIP is a Draft t-core labels Jun 3, 2025
@eth-bot
Copy link
Collaborator

eth-bot commented Jun 3, 2025

✅ All reviewers have approved.

@eth-bot eth-bot added the a-review Waiting on author to review label Jun 3, 2025
@chfast
Copy link
Member Author

chfast commented Jun 4, 2025

The benchmarks are available in ethereum/execution-spec-tests#1701.

This change moves the worst case: from mod_even_8b_exp_896 to mod_even_32b_exp_96.

  • Geth: 31 → 47 Mgps
  • Besu: 40 → 90 Mgps
  • evmone: 79 → 190 Mgps

@marcindsobczak
Copy link
Contributor

Assuming minimal base/mod length of 32 is a great idea and worth to update an EIP and add it. It is covering some edge-case scenarios while having zero impact on common cases. Win-win.
On the other hand, with min price at 200 there are some cases that are performing significantly worse than EcRecover precompile. I would stick to increasing min price to 500.

@marcindsobczak
Copy link
Contributor

With minimal base/mod length of 32 and min price at 500, our worst case should be mod_even_32b_exp_96.

@chfast
Copy link
Member Author

chfast commented Jun 6, 2025

With minimal base/mod length of 32 and min price at 500, our worst case should be mod_even_32b_exp_96.

I restored the minimal cost of 500. The description and benchmark results are also updated.

Copy link
Contributor

@MarekM25 MarekM25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we approve this we need to adjust test cases
https://eips.ethereum.org/EIPS/eip-7883#test-cases

@chfast
Copy link
Member Author

chfast commented Jun 9, 2025

If we approve this we need to adjust test cases https://eips.ethereum.org/EIPS/eip-7883#test-cases

Correct. But these test cases are not attached so I cannot do so.

@spencer-tb
Copy link
Contributor

spencer-tb commented Jun 9, 2025

If we approve this we need to adjust test cases https://eips.ethereum.org/EIPS/eip-7883#test-cases

Correct. But these test cases are not attached so I cannot do so.

Here is the pricing changes from our side in EEST if that helps.
https://github.com/ethereum/execution-spec-tests/pull/1729/files#diff-439a8fdd72de2d7e306ccff66f38ba0ae4ee4dba077de1dd90571eee3374d336

Copy link
Contributor

@gakonst gakonst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK from Reth side.

@rakita
Copy link
Contributor

rakita commented Jun 10, 2025

Makes sense to do it

@barnabasbusa
Copy link
Member

Can we get this PR merged in?

@chfast chfast marked this pull request as ready for review June 11, 2025 08:38
Copy link
Contributor

@lu-pinto lu-pinto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@eth-bot eth-bot enabled auto-merge (squash) June 11, 2025 08:59
Copy link
Collaborator

@eth-bot eth-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All Reviewers Have Approved; Performing Automatic Merge...

@eth-bot eth-bot merged commit 5cdd751 into ethereum:master Jun 11, 2025
30 checks passed
VBulikov pushed a commit to erigontech/erigon that referenced this pull request Jun 18, 2025
chfast added a commit to ipsilon/evmone that referenced this pull request Jul 19, 2025
Update the [EIP-7883 "ModExp Gas Cost Increase"](https://eips.ethereum.org/EIPS/eip-7883)
to the latest revision:
- ethereum/EIPs#9855
- ethereum/EIPs#9969
chfast added a commit to ipsilon/evmone that referenced this pull request Jul 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a-review Waiting on author to review c-update Modifies an existing proposal s-draft This EIP is a Draft t-core

Projects

None yet

Development

Successfully merging this pull request may close these issues.