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 and Modulo by Zero does not produce Compiler Error when using shorthand notation /= and %= #14702

Closed
rafaelmohr opened this issue Nov 26, 2023 · 3 comments · Fixed by #15074
Assignees
Labels
bug 🐛 low effort There is not much implementation work to be done. The task is very easy or tiny. low impact Changes are not very noticeable or potential benefits are limited. should have We like the idea but it’s not important enough to be a part of the roadmap.

Comments

@rafaelmohr
Copy link

rafaelmohr commented Nov 26, 2023

Description

When performing a Division or Modulo by Zero using the long notation, the compiler reports the 'Division by Zero' or 'Modulo zero' error. When performing the same operations using the shorthand '/=' or '%=' operators, the compiler does not raise any errors, and instead the operation will cause a revert at runtime.
As the shorthand notation is semantically equivalent to the longer syntax, both should produce the same behaviour.

Environment

  • Compiler version: 0.8.23
  • Target EVM version (as per compiler settings): Shanghai
  • Framework/IDE (e.g. Truffle or Remix): Remix
  • EVM execution environment / backend / blockchain client: Remix VM
  • Operating system: macOS 14.1

Steps to Reproduce

The following two contracts will produce an error on compilation:

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.23;
contract DivisionByZero {
    function test() public pure returns (uint8) {
        uint8 num = 1;
        num = num / 0;
        return num;
    }
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.23;
contract ModuloByZero {
    function test() public pure returns (uint8) {
        uint8 num = 1;
        num = num % 0;
        return num;
    }
}

The following two contracts will compile successfully, and instead revert when calling the function test()

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.23;
contract DivisionByZeroShorthand {
    function test() public pure returns (uint8) {
        uint8 num = 1;
        num /= 0;
        return num;
    }
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.23;
contract ModuloByZeroShorthand {
    function test() public pure returns (uint8) {
        uint8 num = 1;
        num %= 0;
        return num;
    }
}
@cameel cameel added low effort There is not much implementation work to be done. The task is very easy or tiny. low impact Changes are not very noticeable or potential benefits are limited. should have We like the idea but it’s not important enough to be a part of the roadmap. labels Nov 30, 2023
@AkhilKamath
Copy link

hello, is anyone working on this? if not could you please assign it to me? i would like to work on this, thank you!

@nikola-matic
Copy link
Collaborator

hello, is anyone working on this? if not could you please assign it to me? i would like to work on this, thank you!

Hi @AkhilKamath, this one is still under discussion, so please don't start work on this until further notice.

@gsalzer
Copy link

gsalzer commented Apr 11, 2024

@nikola-matic @cameel What is the final verdict on this issue? I'd be interested in the pros and cons of treating /=0 and %=0 the same as or different from /0 and %0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 low effort There is not much implementation work to be done. The task is very easy or tiny. low impact Changes are not very noticeable or potential benefits are limited. should have We like the idea but it’s not important enough to be a part of the roadmap.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants