Skip to content

Commit

Permalink
Merge pull request #113 from kreskohq/oak-38
Browse files Browse the repository at this point in the history
fix: check for negative amount in toWad
  • Loading branch information
panukettu authored Nov 19, 2023
2 parents 2058a0e + 7cf83c7 commit 15e9bd8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/contracts/core/common/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ library Errors {

error ADDRESS_HAS_NO_CODE(address);
error NOT_INITIALIZING();
error TO_WAD_AMOUNT_IS_NEGATIVE(int256);
error COMMON_ALREADY_INITIALIZED();
error MINTER_ALREADY_INITIALIZED();
error SCDP_ALREADY_INITIALIZED();
Expand Down
4 changes: 4 additions & 0 deletions src/contracts/core/common/funcs/Math.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.21;

import {WadRay} from "libs/WadRay.sol";
import {PercentageMath} from "libs/PercentageMath.sol";
import {Errors} from "common/Errors.sol";

using WadRay for uint256;
using PercentageMath for uint256;
Expand Down Expand Up @@ -47,6 +48,9 @@ function toWad(uint256 _amount, uint8 _decimals) pure returns (uint256) {
}

function toWad(int256 _amount, uint8 _decimals) pure returns (uint256) {
if (_amount < 0) {
revert Errors.TO_WAD_AMOUNT_IS_NEGATIVE(_amount);
}
return toWad(uint256(_amount), _decimals);
}

Expand Down

0 comments on commit 15e9bd8

Please sign in to comment.