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

Throw DivisionByZero exception #41

Closed
cburgdorf opened this issue Sep 22, 2020 · 2 comments
Closed

Throw DivisionByZero exception #41

cburgdorf opened this issue Sep 22, 2020 · 2 comments

Comments

@cburgdorf
Copy link
Collaborator

What is wrong

After #36 lands support for basic arithmetic operations including division will be implemented. However, division by zero will return 0 as that is the EVM default behavior. We should throw an exception instead.

How can it be fixed

Need to investigate. Solidity fixed that a long time ago. Related threads ethereum/solidity#888, ethereum/solidity#670

@cburgdorf
Copy link
Collaborator Author

Citing @g-r-a-n-t from #36 (comment)

My thinking right now is that we will introduce safe math functions to the runtime, where we check for things like overflow and div-by-zero. Then instead of mapping a / b to div(a', b'), we map to safe_div(a', b'), where safe_div is a function that we've defined that reverts on a zero denominator.

I think the semantic analysis pass should be responsible for determining what functions are needed during runtime and then we'll include them in the Yul contract when mapping from the Fe contract. This approach would be extended to things like maps where we have generic type params. For example, defining the contract field pub guest_book: map<address, bytes[100]> would result in two function being added to the runtime named something like map_get_address_bytes100 and map_insert_address_bytes100, which would be used in place of the expression self.guest_book[0x00] and statement self.guest_book[0x00] = some_bytes.

@cburgdorf
Copy link
Collaborator Author

This landed with the recent checks for arithmetic operations

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

No branches or pull requests

1 participant