-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Add Math.modExp
and a Panic
library
#3298
Add Math.modExp
and a Panic
library
#3298
Conversation
…ion-precompile-wrapper-OpenZeppelin#1985
🦋 Changeset detectedLatest commit: f352681 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Added the changeset in next commit |
@frangio had been a while since I worked on this repo, but here's some updated code if it's worth merging in the next update |
…1985' of https://github.com/mw2000/openzeppelin-contracts into modular-exponentiation-precompile-wrapper-OpenZeppelin#1985
Yeah, that's right! I'm fine defaulting to Solidity's behavior if it's a "generic" error. Note that we agreed to add a
Right. I'll try to implement it in that way |
if (m == 0) { | ||
Panic.panic(Panic.DIVISION_BY_ZERO); | ||
} | ||
(bool success, uint256 result) = tryModExp(b, e, m); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A potential threat here is that in chains where this precompile is not available, then the result length will be 0
.
I guess that's the most reliable way to protect against but I don't think it's worth the check.
I added a not specifying that developers need to make sure if the precompile is available.
I couldn't find a way in which calling the precompile returns false. I wonder if that's even possible. In such case the success flag is not even needed. |
Success MUST return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good.
@ernestognw wdyt ?
Note that the coverage issue comes from the
} else {
revert Address.FailedInnerCall();
}
which we don't know how to trigger.
I think its ok for use admin override for that.
Yeah it's good, just added an usage example and natspec to the panic function. Also agree with the coverage drop for this, but I wouldn't remove it in case a weird chain has a contract in that address that does revert. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes #1985
Introduces the wrapper library for EIP 198 that @frangio mentioned in issue #1985. Code was taken from https://ethereum.stackexchange.com/questions/71565/verifying-modular-exponentiation-operation-in-etherum
Looking forward to code review and comments to add docs and Changelog entry.
PR Checklist