-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Update contracts to support Solidity 0.8.x #2442
Update contracts to support Solidity 0.8.x #2442
Conversation
Thanks @andrekorol! We in fact want to remove all uses of We have to discuss whether we want to remove These changes will mean that Solidity 0.8 support will happen in a new major version of the library. We plan to release a final version of the current major before that happens, so we will merge the migration to Solidity 0.8 into a separate branch. So I will ask, if you can, to change pragmas to |
@frangio I can make and commit those changes, no problem! I agree with Solidity 0.8 support coming in a new major version of the library, I don't think it makes much sense to have all the changes you mentioned in a new minor version. |
b72352c
to
5079cd1
Compare
4e171e8
to
5079cd1
Compare
5079cd1
to
4ccca4e
Compare
@frangio I've made the necessary changes. Some tests are still not passing because they expect custom error messages instead of just I still didn't make any change to the tests though, I wanted to confirm if the correct approach would be to change the expected custom error messages to the default Also, the Strings utility library seems to be broken now, and I'm still not sure why, the only thing changed was the version pragma. I suppose it's something to do with the new restrictions on type conversions... |
So, apparently the But with 346fbe2, it's working again. |
f82ef07
to
d2ca110
Compare
d2ca110
to
346fbe2
Compare
Great work, @andrekorol! Thanks for your efforts on this. |
The test helpers have an |
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.
Thanks @andrekorol. Most of the changes look good.
I'm now having doubts about what we should do regarding the custom revert reasons on subtraction overflow. Maybe we should keep them. What do other people think about this? Should we keep custom revert reasons such as "insufficient balance"?
Can you also change SafeMath
to remove our manual checks and rely only on the built in checked arithmetic?
contracts/GSN/Context.sol
Outdated
function _msgSender() internal view virtual returns (address payable) { | ||
return msg.sender; | ||
return payable(msg.sender); |
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.
Since Solidity changed the type of msg.sender
we should change the return type of our _msgSender
function accordingly, instead of casting it here.
contracts/drafts/EIP712.sol
Outdated
function _getChainId() private view returns (uint256 chainId) { | ||
chainId = block.chainid; | ||
} |
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.
We can remove this function now and just use the built in.
contracts/mocks/EIP712External.sol
Outdated
function getChainId() external view returns (uint256 chainId) { | ||
chainId = block.chainid; | ||
} |
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.
Same here.
contracts/mocks/ERC20PermitMock.sol
Outdated
function getChainId() external view returns (uint256 chainId) { | ||
chainId = block.chainid; | ||
} |
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.
Same here.
I generally prefer explicit revert messages now that it is convenient to test for them with waffle. |
Would custom messages undo the gas savings from using built in arithmetic checker? This is the best part of 0.8 IMO - we wouldn't want to lose that benefit. |
We have to run some tests and measure the impact. I don't know if there is any special magic in the built in arithmetic checker that would make it more efficient than manual checks. |
msg.sender have the type address instead of address payable since Solidity 0.8.0
cd0dc80
to
38aadc5
Compare
@lephleg Help would be appreciated in fixing tests that are failing under coverage (solidity-coverage/ganache) 😄 |
One way to retain custom revert reasons would be to keep functions with different signatures like |
At first glance it seems there's a memory leak introduced in node. I wouldn't allocate more before ensuring there's nothing sketchy in the changes. Tricky one, I'll give it a shot with clear head tomorrow. |
@frangio does it actually make sense to keep SafeMath as a weird wrapper? It adds no benefit, and the "special error message" versions are removed in this PR. Perhaps it is better biting the bullet by removing it, and that could trigger users to review the new semantics and use them properly (checked vs. unchecked). And also be aware of the gas implications. |
@axic, as I've said in the comment above, it's possible to revert those changes that removed the "special error messages" and have SafeMath overload functions with two different signatures. One would be just that weird wrapper, and the other would perform the manual checks with custom error messages. The actual arithmetic operation would be wrapped in an unchecked block to avoid wasting gas with double-checking. |
Removing SafeMath is tedious but a straightforward refactoring, but its benefit to the ecosystem would worth the effort. I'm against keeping it as a wrapper. Edit: Happy holidays and thank you for the work going on in this PR ✨ |
@@ -208,7 +208,7 @@ function shouldBehaveLikeERC1155 ([minter, firstTokenHolder, secondTokenHolder, | |||
}); | |||
|
|||
it('reverts when transferring more than balance', async function () { | |||
await expectRevert( | |||
await expectRevert.unspecified( |
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.
Should OpenZeppelin/openzeppelin-test-helpers#149 be implemented, tests like these would not lose precision as much as in this current PR.
Just to be clear, I am not part of OpenZeppelin, so my suggestions are only suggestions, not an official review 😃 |
No problem, thanks for the review anyway! |
@frangio is there a consensus on whether SafeMath should be removed? Do you think setting up a poll before making any further changes is a good idea? |
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.
Everything looks good to me.
I was expecting a change of the proxies, using the new fallback (bytes calldata _input) external [payable] returns (bytes memory _output)
signature, but considering the assembly part is in the _delegate
internal function, It might do more harm then good to embrace this change.
My grain of salt: Also, it can be used to force/enable safemath inside
|
Note for the future: Some "low level" functions, such as |
Let's keep We have to take a look at what's causing the coverage job to fail. Otherwise the PR seems good to go. Thanks for working on this @andrekorol! |
It was my pleasure! I think the coverage job failing has something to do with trufflesuite/ganache/issues/515. It should be fixed in ganache@3.0.0-internal.0, but I'll take a closer look at it to see if that's really the case. |
Initially, coverage was failing due to an out of memory error, which could be solved by either updating Node's version here to any version >= 14:
or by increasing the heap memory as I did in 6a30dcc. Now the coverage job is failing because of six different test cases that are not passing. Two of them ( |
I think you have debugged it correctly, it's likely to be the chainId issue. Something else we will have to do afterwards is review all of the Thank you everyone! Please remember this is going in the |
A correction: while doing a last review of the changes in this PR I found that the chain id issue in Ganache already had a workaround and it was being removed here. It fixed the coverage for me locally and hopefully the CI will agree. |
Fixes #2441
Contracts'
solidity
version pragmas were updated to support Solidity 0.8.x.Changes include:
chainid
in inline assembly are nowview
instead ofpure
.Important Note: Some tests are still not passing because since 0.8.0 failing assertions and other internal checks like division by zero or arithmetic overflow do not use the invalid opcode, but instead the revert opcode. And I believe that this is something worth discussing how to handle before making any changes to the current test cases.