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

Support 'pragma unchecked' in Solidity 0.8.0 #10706

Closed
mudgen opened this issue Dec 31, 2020 · 4 comments
Closed

Support 'pragma unchecked' in Solidity 0.8.0 #10706

mudgen opened this issue Dec 31, 2020 · 4 comments
Labels
closed due inactivity The issue/PR was automatically closed due to inactivity. language design :rage4: Any changes to the language, e.g. new features stale The issue/PR was marked as stale because it has been open for too long.

Comments

@mudgen
Copy link

mudgen commented Dec 31, 2020

I have a style of dealing with over/underflows in Solidity that works like this:

Very often I use large enough variables in contexts where it is impossible to overflow and/or underflow them. Therefore I don't need to use SafeMath or default reverts from Solidity 0.8.0.

In cases where using large enough variables to prevent overflow/underflow is not possible I use explicit require statements or other custom logic to handle. I found that doing this better expresses the algorithm being implemented and can give better error messages.

I have found it important to be aware of and understand each mathematical operation that occurs in a contract and if it can over/underflow and the consequences if that happens and handle accordingly. Reverting on under/overflow is not always the right action and can result in locking funds in contracts forever. So it is important to be aware of and understand each potential over/underflow and handle it correctly.

With this style the default revert on under/overflow from Solidity 0.8.0 is not used and requires me to run all my mathematical operations within unchecked blocks. I would like to request a pragma unchecked or similar directive that turns off default reverts on over/underflow for the whole file.

Besides supporting the style I mention above the pragma could make it easier and faster to port older Solidity code to Solidity 0.8.0.

@ajb
Copy link

ajb commented Jan 18, 2022

Please, please, please implement this feature.

@MerlinEgalite
Copy link

Would be awesome yes!

@github-actions
Copy link

This issue has been marked as stale due to inactivity for the last 90 days.
It will be automatically closed in 7 days.

@github-actions github-actions bot added the stale The issue/PR was marked as stale because it has been open for too long. label Mar 15, 2023
@github-actions
Copy link

Hi everyone! This issue has been automatically closed due to inactivity.
If you think this issue is still relevant in the latest Solidity version and you have something to contribute, feel free to reopen.
However, unless the issue is a concrete proposal that can be implemented, we recommend starting a language discussion on the forum instead.

@github-actions github-actions bot added the closed due inactivity The issue/PR was automatically closed due to inactivity. label Mar 23, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed due inactivity The issue/PR was automatically closed due to inactivity. language design :rage4: Any changes to the language, e.g. new features stale The issue/PR was marked as stale because it has been open for too long.
Projects
None yet
Development

No branches or pull requests

5 participants