From b14b3e6f0e429d727cde6ae1321bfeeadac561e5 Mon Sep 17 00:00:00 2001 From: Ryan Noble Date: Mon, 25 Nov 2024 16:33:13 +0100 Subject: [PATCH] fix: $GD resolved large reward issue (#544) --- contracts/goodDollar/GoodDollarExchangeProvider.sol | 2 ++ test/unit/goodDollar/GoodDollarExchangeProvider.t.sol | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/contracts/goodDollar/GoodDollarExchangeProvider.sol b/contracts/goodDollar/GoodDollarExchangeProvider.sol index b744fcc..af6b3e0 100644 --- a/contracts/goodDollar/GoodDollarExchangeProvider.sol +++ b/contracts/goodDollar/GoodDollarExchangeProvider.sol @@ -203,6 +203,8 @@ contract GoodDollarExchangeProvider is IGoodDollarExchangeProvider, BancorExchan uint256 newRatioScaled = unwrap(numerator.div(denominator)); uint32 newRatioUint = uint32(newRatioScaled / 1e10); + require(newRatioUint > 0, "New ratio must be greater than 0"); + exchanges[exchangeId].reserveRatio = newRatioUint; exchanges[exchangeId].tokenSupply += rewardScaled; diff --git a/test/unit/goodDollar/GoodDollarExchangeProvider.t.sol b/test/unit/goodDollar/GoodDollarExchangeProvider.t.sol index 96eb978..eb075ca 100644 --- a/test/unit/goodDollar/GoodDollarExchangeProvider.t.sol +++ b/test/unit/goodDollar/GoodDollarExchangeProvider.t.sol @@ -683,6 +683,15 @@ contract GoodDollarExchangeProviderTest_updateRatioForReward is GoodDollarExchan exchangeId = exchangeProvider.createExchange(poolExchange); } + function test_updateRatioForReward_whenNewRatioIsZero_shouldRevert() public { + // Use a very large reward that will make the denominator massive compared to numerator + uint256 veryLargeReward = type(uint256).max / 1e20; // Large but not large enough to overflow + + vm.expectRevert("New ratio must be greater than 0"); + vm.prank(expansionControllerAddress); + exchangeProvider.updateRatioForReward(exchangeId, veryLargeReward); + } + function test_updateRatioForReward_whenCallerIsNotExpansionController_shouldRevert() public { vm.prank(makeAddr("NotExpansionController")); vm.expectRevert("Only ExpansionController can call this function");