crytic / crytic/building-secure-contracts
Error in learn_evm/arithmetic-checks.md : Arithmetic checks for int256 multiplication
- Dominant language
- Solidity
- Stars
- 2.5k
- Forks
- 391
- PR merge metrics
- No merged PRs in 30d
Description
At this page : https://github.com/crytic/building-secure-contracts/blob/master/learn_evm/arithmetic-checks.md#arithmetic-checks-for-int256-multiplication
The first block of code is :
```solidity
/// @notice versions >=0.8.0 && <0.8.17
function checkedMulInt(int256 a, int256 b) public pure returns (int256 c) {
unchecked {
c = a * b;
if (a > 0 && b > 0 && a > type(int256).max / b) arithmeticError();
if (a > 0 && b < 0 && a < type(int256).min / b) arithmeticError();
if (a < 0 && b > 0 && a < type(int256).min / b) arithmeticError();
if (a < 0 && b < 0 && a < type(int256).max / b) arithmeticError();
}
}
```
There is an issue on the third condition that should be replaced :
```diff
/// @notice versions >=0.8.0 && <0.8.17
function checkedMulInt(int256 a, int256 b) public pure returns (int256 c) {
unchecked {
c = a * b;
if (a > 0 && b > 0 && a > type(int256).max / b) arithmeticError();
if (a > 0 && b < 0 && a < type(int256).min / b) arithmeticError();
- if (a < 0 && b > 0 && a < type(int256).min / b) arithmeticError();
+ if (a < 0 && b > 0 && a > type(int256).min / b) arithmeticError();
if (a < 0 && b < 0 && a < type(int256).max / b) arithmeticError();
}
}
```
I discovered this issue while trying to use the code block for the solution of nodeGuardian's yul assembly quest.
Let me know if you need more details.
Contributor guide
Research direction
Read learn_evm/arithmetic-checks.md at the “Arithmetic checks for int256 multiplication” section and inspect the first Solidity code block. Verify the third condition against the reported replacement, then update the documentation; done means the example contains the corrected condition and renders correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- solidity
- Domain
- documentation, security
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100