Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 aPanic
library #3298Add
Math.modExp
and aPanic
library #3298Changes from 57 commits
91e39eb
712a0f3
77f33ea
4683f26
7489ce4
d576641
0d78d29
5d99ed8
acb16f2
d7e81cf
85187dd
d458765
01badeb
a1c1439
d81d69d
6e8cced
fd7b8de
26a036e
4ba0a29
988c950
c08ac50
98f7994
f634aab
66a0c1f
eecd818
1583160
19ead8e
8cf355f
113e85e
4e1cf0d
6d7c154
84b285d
9e73f46
76c9afa
1ff0776
f84b1b6
fe32a38
4accc2e
cfd80e9
526d6b9
3718090
cd2f2e9
104002e
d149ea6
05aa60e
f352681
32ea4bb
2e962c8
275c959
24cd52a
50374a1
ee91836
d13e52d
969e259
e64c3f9
06220be
9137bae
81e8ba0
2b72050
2fc20d4
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
Check failure on line 13 in contracts/utils/Panic.sol
GitHub Actions / lint
Check failure on line 15 in contracts/utils/Panic.sol
GitHub Actions / lint
Check failure on line 17 in contracts/utils/Panic.sol
GitHub Actions / lint
Check failure on line 19 in contracts/utils/Panic.sol
GitHub Actions / lint
Check failure on line 21 in contracts/utils/Panic.sol
GitHub Actions / lint
Check failure on line 23 in contracts/utils/Panic.sol
GitHub Actions / lint
Check failure on line 25 in contracts/utils/Panic.sol
GitHub Actions / lint
Check failure on line 27 in contracts/utils/Panic.sol
GitHub Actions / lint
Check failure on line 29 in contracts/utils/Panic.sol
GitHub Actions / lint
Check failure on line 31 in contracts/utils/Panic.sol
GitHub Actions / lint
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.
Right now anyone can call
Panic.code(0xff)
when0xff
is not in the "official" list (I'm not sure what "official" even means in this context).I'm not sure how frequently Solidity adds (or changes) the panic codes, but imagine the following situation:
Panic
libraryPanic.code(0x420)
0x420
)Wouldn't it be bad that the same revert code has different meanings?
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.
Alternatively we can generate this library procedurally wth the codes, such that users can do:
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'm not too worried about users emitting random panic code ... but I'm not fundamentally opposed to making
panic(uint256)
private and having functions likeWe would have to make them CamelCase though.
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.
The thing, if new panic code are ever added, the current version would allow users to use them without us having to do a release.
I'm also thinking, what if some L2 whant to use specific panic codes for some crosschain stuff. We won't want to add them to the library, but users will want to emit them.
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.
Agree with this syntax.
Right, good point. If the goal is to provide a workaround then I would be fine if we release the
panic(uint256)
function, although I'd suggest naming it_panic(uint256)
and making it internal instead.I know this is kind of the same thing but I feel the design of the library API is more friendly if we keep each panic code function and also the custom
_panic
for the following reasons:_panic
helps signaling that the function is not intended for direct access but as a fallback for custom use cases.Would you agree with this?
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.
The linter rules are not ok with that, and I think we should follow them:
I'm not sure that is a good point. When testing panic code with hardhat you do
you don't to
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 the current version is simple and effective. It's targetting advanced users anyway.
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.
Fair
We should document the function then. Currently it allows panicking with anything it I think it needs some usage instructions in both the contracts NatSpec and the
panic
funciton itselfThere 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.