From 7cf83c74c7123dad0bb0d4b8926e08849d071a3d Mon Sep 17 00:00:00 2001 From: panukettu Date: Sun, 19 Nov 2023 02:09:03 +0200 Subject: [PATCH] fix: check for negative amount in toWad --- src/contracts/core/common/Errors.sol | 1 + src/contracts/core/common/funcs/Math.sol | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/contracts/core/common/Errors.sol b/src/contracts/core/common/Errors.sol index ac3adee7..659c28ff 100644 --- a/src/contracts/core/common/Errors.sol +++ b/src/contracts/core/common/Errors.sol @@ -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(); diff --git a/src/contracts/core/common/funcs/Math.sol b/src/contracts/core/common/funcs/Math.sol index 5722b8e3..09fd20d4 100644 --- a/src/contracts/core/common/funcs/Math.sol +++ b/src/contracts/core/common/funcs/Math.sol @@ -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; @@ -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); }