Skip to content

zkEVM: add modexp attack #1523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 5, 2025
Merged

zkEVM: add modexp attack #1523

merged 10 commits into from
May 5, 2025

Conversation

jsign
Copy link
Collaborator

@jsign jsign commented May 1, 2025

This PR introduces an attack vector for the MODEXP precompile.

We assume 32-byte operands for the base, modulus, and exponent, anticipating the activation of EIP-7883 on mainnet in the near future (TM). Beyond the 32-byte boundary, the cost per unit of work rises, so it is valuable to model that limit from the outset.

The test suite is already parameterised for multiple gas limits (and can easily be extended to cover base/modulo/exp sizes), but for now we target 36M gas-limit since it is the relevant case for zkVMs today.

SP1 cycles: 36M gas limit -> ~27 billion cycles.

cc @kevaundray

@jsign jsign marked this pull request as ready for review May 1, 2025 19:11
@jsign jsign requested a review from marioevz May 1, 2025 19:11
@jsign jsign force-pushed the jsign-zkvm-modexp branch from 743cdfc to 0cb15db Compare May 2, 2025 19:08
Copy link
Member

@marioevz marioevz left a comment

Choose a reason for hiding this comment

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

Some comments but looks good overall 👍

@jsign jsign requested a review from marioevz May 2, 2025 21:41
@jsign
Copy link
Collaborator Author

jsign commented May 2, 2025

Thanks @marioevz. I applied the suggestions, and double-checked again the run and has the same expected cycles.

Copy link
Member

@marioevz marioevz left a comment

Choose a reason for hiding this comment

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

Just a few last comments, thanks!

jsign and others added 10 commits May 5, 2025 19:22
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Co-authored-by: Mario Vega <marioevz@gmail.com>
Co-authored-by: Mario Vega <marioevz@gmail.com>
Co-authored-by: Mario Vega <marioevz@gmail.com>
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
@jsign jsign force-pushed the jsign-zkvm-modexp branch from b8d50b4 to 99f249d Compare May 5, 2025 22:27
@jsign jsign requested a review from marioevz May 5, 2025 22:36
@jsign
Copy link
Collaborator Author

jsign commented May 5, 2025

Thanks @marioevz for the review, I think it is now ready!

Copy link
Member

@marioevz marioevz left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@marioevz marioevz merged commit c91549c into main May 5, 2025
22 checks passed
@marioevz marioevz deleted the jsign-zkvm-modexp branch May 5, 2025 22:38
felix314159 pushed a commit to felix314159/execution-spec-tests that referenced this pull request May 16, 2025
* add modexp tests

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* leave only 36M gas limit

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* adjustments

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* lints

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* lints and cleanup

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* lints

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* Update tests/zkevm/test_worst_compute.py

Co-authored-by: Mario Vega <marioevz@gmail.com>

* Update tests/zkevm/test_worst_compute.py

Co-authored-by: Mario Vega <marioevz@gmail.com>

* Update tests/zkevm/test_worst_compute.py

Co-authored-by: Mario Vega <marioevz@gmail.com>

* feedback

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Co-authored-by: Mario Vega <marioevz@gmail.com>
codeofcarson pushed a commit to codeofcarson/execution-spec-tests that referenced this pull request Jul 1, 2025
* add modexp tests

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* leave only 36M gas limit

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* adjustments

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* lints

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* lints and cleanup

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* lints

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* Update tests/zkevm/test_worst_compute.py

Co-authored-by: Mario Vega <marioevz@gmail.com>

* Update tests/zkevm/test_worst_compute.py

Co-authored-by: Mario Vega <marioevz@gmail.com>

* Update tests/zkevm/test_worst_compute.py

Co-authored-by: Mario Vega <marioevz@gmail.com>

* feedback

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Co-authored-by: Mario Vega <marioevz@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants