From fc185fdc61ebaaf62a5fcf61d2bd8636ff11283c Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Sun, 14 Apr 2019 09:28:07 -0400 Subject: [PATCH] safemath in calculation of interest owed --- contracts/subscription.sol | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contracts/subscription.sol b/contracts/subscription.sol index 9dcbbd9..d499676 100644 --- a/contracts/subscription.sol +++ b/contracts/subscription.sol @@ -106,7 +106,9 @@ contract Subscription { function getInterestOwed(uint256 amountOwed) view public returns (uint256) { uint256 totalAmount = compound.getSupplyBalance(address(this), daiAddress); uint256 totalInterest = totalAmount - totalBalances; - uint256 interestOwed = totalInterest * amountOwed / totalBalances; + if (amountOwed == totalBalances) return totalInterest; + uint256 totalOwned = totalInterest * amountOwed; + uint256 interestOwed = totalOwned.div(totalBalances); return interestOwed; }