-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Add Math.modExp and a Panic library
#3298
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
Changes from 1 commit
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
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -283,6 +283,24 @@ library Math { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m) | ||
| * | ||
| * Requirements: | ||
| * - modulus can't be zero | ||
| * - result should be obtained successfully | ||
| */ | ||
| function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) { | ||
| if (m == 0) { | ||
| revert MathModulusEqualsZero(); | ||
| } | ||
|
||
| (bool success, bytes memory result) = (address(5).staticcall(abi.encode(32, 32, 32, b, e, m))); | ||
| if (!success) { | ||
| revert MathModExpCannotBeCalculated(); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't work, I tried different gasLimit values in the following test; It reverts as out of gas but doesn't trigger the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I guess that is because if the precompile has not enough gas, than the 1/64 that remains after that are not enough to check success and revert with a custom error |
||
| return abi.decode(result, (uint256)); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded | ||
| * towards zero. | ||
|
|
@@ -477,26 +495,6 @@ library Math { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * @dev Returns the modular exponentiation of the specified base, | ||
| * exponent and modulus (b ** e % m) | ||
| * | ||
| * Requirements: | ||
| * | ||
| * - modulus can't be zero | ||
| * - result should be obtained successfully | ||
| */ | ||
| function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) { | ||
| if (m == 0) { | ||
| revert MathModulusEqualsZero(); | ||
| } | ||
| (bool success, bytes memory result) = (address(5).staticcall(abi.encode(32, 32, 32, b, e, m))); | ||
| if (!success) { | ||
| revert MathModExpCannotBeCalculated(); | ||
| } | ||
| return abi.decode(result, (uint256)); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers. | ||
| */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.