Skip to content
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

limit modexp call to 8192 bit inputs #1391

Open
wants to merge 4 commits into
base: zkevm
Choose a base branch
from
Open

Conversation

hexoscott
Copy link
Collaborator

To tackle #1385

@cla-bot cla-bot bot added the cla-signed label Oct 30, 2024
mandrigin
mandrigin previously approved these changes Oct 31, 2024
@hexoscott hexoscott enabled auto-merge (squash) October 31, 2024 11:13
@krlosMata
Copy link

krlosMata commented Oct 31, 2024

The behavior should be slightly different since we tried to mimic ethereum specification and some special cases are handled before checking the lenght.
Some input values, returns directly before checking the input bits: https://github.com/0xPolygonHermez/zkevm-rom/blob/develop-durian/main/precompiled/pre-modexp.zkasm#L197

@krlosMata
Copy link

@hexoscott
Copy link
Collaborator Author

hmmmm

@hexoscott
Copy link
Collaborator Author

The unreachable code is effectively the same so I've combined the statements now

expBitLen = exp.BitLen()
modBitLen = mod.BitLen()
)

Choose a reason for hiding this comment

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

if modulo size is 0, the precompile returns 0 and it consumes GAS. This case is not handled.
if base size is 0 & modsize < 8192, it should also return 0 and consume GAS. This case is not handled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

image These are the revert cases to return a 0 gas so that we don't consume any. Anything else consumes gas as it would normally, unless I'm missing something?

switch {
case mod.BitLen() == 0:

if modBitLen == 0 {
// Modulo 0 is undefined, return zero

Choose a reason for hiding this comment

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

comment is not right

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have removed this comment. It was there from the original erigon implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants