-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'openzeppelin-solidity': minor | ||
--- | ||
|
||
`Math`: Make `ceilDiv` to revert on 0 division even if the numerator is 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.19; | ||
|
||
import "../../token/ERC20/extensions/ERC4626.sol"; | ||
|
||
abstract contract ERC4626LimitsMock is ERC4626 { | ||
uint256 _maxDeposit; | ||
uint256 _maxMint; | ||
|
||
constructor() { | ||
_maxDeposit = 100 ether; | ||
_maxMint = 100 ether; | ||
} | ||
|
||
function maxDeposit(address) public view override returns (uint256) { | ||
return _maxDeposit; | ||
} | ||
|
||
function maxMint(address) public view override returns (uint256) { | ||
return _maxMint; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,11 @@ library Math { | |
* of rounding down. | ||
*/ | ||
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { | ||
if (b == 0) { | ||
// Guarantee the same behavior as in a regular Solidity division. | ||
return a / b; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Amxx
Collaborator
|
||
} | ||
|
||
// (a + b - 1) / b can overflow on addition, so we distribute. | ||
return a == 0 ? 0 : (a - 1) / b + 1; | ||
} | ||
|
I have a quick question here: This will revert with the error
Panic(0x12)
. As long as you have an environment that knows how to decode what this error means (i.e. "If you divide or modulo by zero") or you're native enough to know what it means it's not an issue. But what if you have a sequence of complex interactions and maybe need some further information to understand where the panic comes from. Don't you think the following would make more sense?