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

Proposal: Throw on division by zero #670

Closed
chriseth opened this issue Jun 20, 2016 · 4 comments
Closed

Proposal: Throw on division by zero #670

chriseth opened this issue Jun 20, 2016 · 4 comments
Assignees

Comments

@chriseth
Copy link
Contributor

chriseth commented Jun 20, 2016

Division by zero currently behaves exactly like division by zero on the EVM: It results in zero.

This could be changed into throwing an exception, just like array access out of bounds and other cases.

Do we want to break backwards compatibility to add this feature?

The check will of course be optimized away for division by constants. An improved optimizer (it cannot do it yet) could also optimize it away if the developer checked for zero just prior to the division. The downside of the comparison is also that block-level optimization cannot be done anymore.

@Arachnid
Copy link

Yes, absolutely. Most languages define division by zero as NaN or throw an exception/panic/halt; we should do the same rather than silently returning an incorrect answer. Ideally a hard fork will fix this in the EVM, but in the meantime Solidity should definitely add this check itself, just like it checks array bounds.

@vbuterin
Copy link
Contributor

On the object-level, I support this change. Failing silently is the worst possible thing to do from a safety perspective.

On the meta-level, I am fine with backwards-compatibility breaking changes in Solidity, especially since I think the language will evolve over the next six months as a result of the community discovering incremental changes to make the risk of bugs much smaller. One possible way to make changes like this graceful is to put a hashbang tag into the file, or some similar parameter, specifying a version.

@leonprou
Copy link

Got here from the ethereum wiki. The issue is closed, so this means that division by zero is now "safe"?

@guylando
Copy link
Contributor

@leonprou seems so: #888

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants