-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Closed as not planned
Labels
Description
Description
The division reverts even inside an unchecked block, which is contradictory, what if I already validated that before the unchecked block? or if I rely on the result zero when divide by zero?
Environment
- Compiler version: 0.8.25
- Target EVM version (as per compiler settings): 'shanghai'
- Framework/IDE (e.g. Truffle or Remix): any
- EVM execution environment / backend / blockchain client: Forge
- Operating system: MacOS
Steps to Reproduce
The following code reverts when b is zero, which should not happen inside an unchecked block.
pragma solidity >=0.8.0;
contract Example {
function divide(uint256 a, uint256 b) external pure returns (uint256) {
unchecked {
// Reverts when b = 0
return a / b;
}
}
function asmDivide(uint256 a, uint256 b) external pure returns (uint256 r) {
assembly {
// Works when b = 0
r := div(a, b)
}
}
}Reactions are currently unavailable