From cf48d9af81b2341b2378d40afa80a097ce3276bc Mon Sep 17 00:00:00 2001 From: Philip Paetz Date: Tue, 15 Oct 2024 15:30:39 +0200 Subject: [PATCH] feat: remove reentrancy guards from mint functions they didn't add any value as the mint functions only interact with trusted contracts and tokens --- .../GoodDollarExpansionController.sol | 16 +++++----------- .../GoodDollarExpansionController.t.sol | 18 +++++++++--------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/contracts/goodDollar/GoodDollarExpansionController.sol b/contracts/goodDollar/GoodDollarExpansionController.sol index df105e18..e5db81d9 100644 --- a/contracts/goodDollar/GoodDollarExpansionController.sol +++ b/contracts/goodDollar/GoodDollarExpansionController.sol @@ -8,7 +8,6 @@ import { IERC20 } from "openzeppelin-contracts-next/contracts/token/ERC20/IERC20 import { IGoodDollar } from "contracts/goodDollar/interfaces/IGoodProtocol.sol"; import { IDistributionHelper } from "contracts/goodDollar/interfaces/IGoodProtocol.sol"; -import { ReentrancyGuard } from "openzeppelin-contracts-next/contracts/security/ReentrancyGuard.sol"; import { PausableUpgradeable } from "openzeppelin-contracts-upgradeable/contracts/security/PausableUpgradeable.sol"; import { OwnableUpgradeable } from "openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol"; import { unwrap, wrap, powu } from "prb/math/UD60x18.sol"; @@ -17,12 +16,7 @@ import { unwrap, wrap, powu } from "prb/math/UD60x18.sol"; * @title GoodDollarExpansionController * @notice Provides functionality to expand the supply of GoodDollars. */ -contract GoodDollarExpansionController is - IGoodDollarExpansionController, - PausableUpgradeable, - OwnableUpgradeable, - ReentrancyGuard -{ +contract GoodDollarExpansionController is IGoodDollarExpansionController, PausableUpgradeable, OwnableUpgradeable { /* ==================== State Variables ==================== */ // MAX_WEIGHT is the max rate that can be assigned to an exchange @@ -163,7 +157,7 @@ contract GoodDollarExpansionController is * @param exchangeId The id of the exchange to mint UBI for. * @param reserveInterest The amount of reserve tokens collected from interest. */ - function mintUBIFromInterest(bytes32 exchangeId, uint256 reserveInterest) external nonReentrant { + function mintUBIFromInterest(bytes32 exchangeId, uint256 reserveInterest) external { require(reserveInterest > 0, "reserveInterest must be greater than 0"); IBancorExchangeProvider.PoolExchange memory exchange = IBancorExchangeProvider(address(goodDollarExchangeProvider)) .getPoolExchange(exchangeId); @@ -180,7 +174,7 @@ contract GoodDollarExpansionController is * @param exchangeId The id of the exchange to mint UBI for. * @return amountMinted The amount of UBI tokens minted. */ - function mintUBIFromReserveBalance(bytes32 exchangeId) external nonReentrant returns (uint256 amountMinted) { + function mintUBIFromReserveBalance(bytes32 exchangeId) external returns (uint256 amountMinted) { IBancorExchangeProvider.PoolExchange memory exchange = IBancorExchangeProvider(address(goodDollarExchangeProvider)) .getPoolExchange(exchangeId); @@ -199,7 +193,7 @@ contract GoodDollarExpansionController is * @param exchangeId The id of the exchange to mint UBI for. * @return amountMinted The amount of UBI tokens minted. */ - function mintUBIFromExpansion(bytes32 exchangeId) external nonReentrant returns (uint256 amountMinted) { + function mintUBIFromExpansion(bytes32 exchangeId) external returns (uint256 amountMinted) { ExchangeExpansionConfig memory config = getExpansionConfig(exchangeId); IBancorExchangeProvider.PoolExchange memory exchange = IBancorExchangeProvider(address(goodDollarExchangeProvider)) .getPoolExchange(exchangeId); @@ -233,7 +227,7 @@ contract GoodDollarExpansionController is * @param to The address of the recipient. * @param amount The amount of tokens to mint. */ - function mintRewardFromRR(bytes32 exchangeId, address to, uint256 amount) external onlyAvatar nonReentrant { + function mintRewardFromRR(bytes32 exchangeId, address to, uint256 amount) external onlyAvatar { require(to != address(0), "Invalid to address"); require(amount > 0, "Amount must be greater than 0"); IBancorExchangeProvider.PoolExchange memory exchange = IBancorExchangeProvider(address(goodDollarExchangeProvider)) diff --git a/test/unit/goodDollar/GoodDollarExpansionController.t.sol b/test/unit/goodDollar/GoodDollarExpansionController.t.sol index 0203a6e8..5c019e21 100644 --- a/test/unit/goodDollar/GoodDollarExpansionController.t.sol +++ b/test/unit/goodDollar/GoodDollarExpansionController.t.sol @@ -564,7 +564,7 @@ contract GoodDollarExpansionControllerTest_mintUBIFromExpansion is GoodDollarExp } } -contract GoodDollarExpansionControllerTest_mintRewardFromRR is GoodDollarExpansionControllerTest { +contract GoodDollarExpansionControllerTest_mintRewardFromReserveRatio is GoodDollarExpansionControllerTest { GoodDollarExpansionController expansionController; function setUp() public override { @@ -595,25 +595,25 @@ contract GoodDollarExpansionControllerTest_mintRewardFromRR is GoodDollarExpansi ); } - function test_mintRewardFromRR_whenCallerIsNotAvatar_shouldRevert() public { + function test_mintRewardFromReserveRatio_whenCallerIsNotAvatar_shouldRevert() public { vm.prank(makeAddr("NotAvatar")); vm.expectRevert("Only Avatar can call this function"); - expansionController.mintRewardFromRR(exchangeId, makeAddr("To"), 1000e18); + expansionController.mintRewardFromReserveRatio(exchangeId, makeAddr("To"), 1000e18); } - function test_mintRewardFromRR_whenToIsZero_shouldRevert() public { + function test_mintRewardFromReserveRatio_whenToIsZero_shouldRevert() public { vm.prank(avatarAddress); vm.expectRevert("Invalid to address"); - expansionController.mintRewardFromRR(exchangeId, address(0), 1000e18); + expansionController.mintRewardFromReserveRatio(exchangeId, address(0), 1000e18); } - function test_mintRewardFromRR_whenAmountIs0_shouldRevert() public { + function test_mintRewardFromReserveRatio_whenAmountIs0_shouldRevert() public { vm.prank(avatarAddress); vm.expectRevert("Amount must be greater than 0"); - expansionController.mintRewardFromRR(exchangeId, makeAddr("To"), 0); + expansionController.mintRewardFromReserveRatio(exchangeId, makeAddr("To"), 0); } - function test_mintRewardFromRR_whenCallerIsAvatar_shouldMintAndEmit() public { + function test_mintRewardFromReserveRatio_whenCallerIsAvatar_shouldMintAndEmit() public { uint256 amountToMint = 1000e18; address to = makeAddr("To"); uint256 toBalanceBefore = token.balanceOf(to); @@ -622,7 +622,7 @@ contract GoodDollarExpansionControllerTest_mintRewardFromRR is GoodDollarExpansi emit RewardMinted(exchangeId, to, amountToMint); vm.prank(avatarAddress); - expansionController.mintRewardFromRR(exchangeId, to, amountToMint); + expansionController.mintRewardFromReserveRatio(exchangeId, to, amountToMint); assertEq(token.balanceOf(to), toBalanceBefore + amountToMint); }