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

Division by Zero #70

Closed
2 of 4 tasks
0xSandyy opened this issue Jun 5, 2024 · 5 comments · Fixed by #83
Closed
2 of 4 tasks

Division by Zero #70

0xSandyy opened this issue Jun 5, 2024 · 5 comments · Fixed by #83

Comments

@0xSandyy
Copy link
Contributor

0xSandyy commented Jun 5, 2024

Checklist

  • I have searched the existing issues and pull requests for duplicates.

Type of Issue

  • New vulnerability addition
  • Feature request
  • Update existing vulnerability

Description

Division by Zero

In solidity if the contract attempts to perform division when the denominator is zero, the whole transaction reverts. Thus, the denominator should be always checked before division.

function foo(uint num, uint den) public pure returns(uint result) {
  if(den == 0) return 0; // if denominator is 0, return 0 instead of reverting
  result = num / den;
}
@kadenzipfel
Copy link
Owner

Imo this should go under DoS with unexpected revert, would be a great addition

@0xSandyy
Copy link
Contributor Author

0xSandyy commented Jun 6, 2024

or How about a separate Solidity Math Issues listing including all other issues like rounding errors, lack of precision, solidity truncation, etc?

@kadenzipfel
Copy link
Owner

I think division by zero best fits under unexpected revert but I think the others could go together on a listing that specifically encompasses effects of integer math

@0xSandyy
Copy link
Contributor Author

0xSandyy commented Jun 7, 2024

Ok, I will work on the PR for unexpected revert first and then will work on Integer math issues. What should I put the title for integer math issues?

@kadenzipfel
Copy link
Owner

Ok, I will work on the PR for unexpected revert first and then will work on Integer math issues. What should I put the title for integer math issues?

I think we could go with "Integer Rounding" or something like that as I'd say it's probably the root of each of those issues. By the way, I realized we have this vulnerability listed already https://github.com/kadenzipfel/smart-contract-vulnerabilities/blob/master/vulnerabilities/lack-of-precision.md so would be best to update that with the new title and different possible outcomes

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

Successfully merging a pull request may close this issue.

2 participants