From 83a161580865553693bdcf59cc9ef81695f605e1 Mon Sep 17 00:00:00 2001 From: Santiago Sanchez Avalos Date: Fri, 21 Apr 2023 14:37:34 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=BA=20irm:=20add=20max=20config=20valu?= =?UTF-8?q?e=20checks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/healthy-spiders-leave.md | 5 +++++ .gas-snapshot | 8 +++++--- contracts/InterestRateModel.sol | 3 +++ test/solidity/InterestRateModel.t.sol | 10 ++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 .changeset/healthy-spiders-leave.md diff --git a/.changeset/healthy-spiders-leave.md b/.changeset/healthy-spiders-leave.md new file mode 100644 index 000000000..e19fcaf3c --- /dev/null +++ b/.changeset/healthy-spiders-leave.md @@ -0,0 +1,5 @@ +--- +"@exactly-protocol/protocol": patch +--- + +🦺 irm: add max config value checks diff --git a/.gas-snapshot b/.gas-snapshot index ed69f20bf..eb200592f 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -13,6 +13,8 @@ AuditorTest:testExitMarketOwning() (gas: 177445) InterestRateModelTest:testFixedBorrowRate() (gas: 8089) InterestRateModelTest:testFloatingBorrowRate() (gas: 6236) InterestRateModelTest:testMinFixedRate() (gas: 7610) +InterestRateModelTest:testRevertFixedMaxUtilizationLowerThanWad() (gas: 81593) +InterestRateModelTest:testRevertFloatingMaxUtilizationLowerThanWad() (gas: 81681) LeveragerTest:testApproveMaliciousMarket() (gas: 24112) LeveragerTest:testApproveMarket() (gas: 56669) LeveragerTest:testCallReceiveFlashLoanFromAnyAddress() (gas: 11465) @@ -54,7 +56,7 @@ MarketTest:testDepositShouldUpdateFlexibleBorrowVariables() (gas: 443236) MarketTest:testDepositToSmartPool() (gas: 157676) MarketTest:testDistributeMultipleAccumulatedEarnings() (gas: 585361) MarketTest:testDistributionOfLossesShouldReduceFromFloatingBackupBorrowedAccordingly() (gas: 2041192) -MarketTest:testEarlyRepaymentWithExcessiveAmountOfFees() (gas: 1300232) +MarketTest:testEarlyRepaymentWithExcessiveAmountOfFees() (gas: 1300291) MarketTest:testEarlyWithdrawFromFreeLunchShouldNotRevertWithFloatingFullUtilization() (gas: 611090) MarketTest:testFixedBorrowFailingWhenFlexibleBorrowAccruesDebt() (gas: 773534) MarketTest:testFlexibleBorrow() (gas: 329289) @@ -103,8 +105,8 @@ MarketTest:testRoundingUpAllowanceWhenBorrowingAtMaturity() (gas: 489301) MarketTest:testRoundingUpAllowanceWhenWithdrawingAtMaturity() (gas: 501981) MarketTest:testSetDampSpeedFactorShouldUpdateFloatingAssetsAverage() (gas: 240216) MarketTest:testSetEarningsAccumulatorSmoothFactorShouldDistributeEarnings() (gas: 495637) -MarketTest:testSetInterestRateModelShouldUpdateFloatingDebt() (gas: 988294) -MarketTest:testSetInterestRateModelWithAddressZeroShouldNotUpdateFloatingDebt() (gas: 870527) +MarketTest:testSetInterestRateModelShouldUpdateFloatingDebt() (gas: 988353) +MarketTest:testSetInterestRateModelWithAddressZeroShouldNotUpdateFloatingDebt() (gas: 870586) MarketTest:testShareValueNotDecreasingAfterDeposit() (gas: 468612) MarketTest:testShareValueNotDecreasingWhenMintingToTreasury() (gas: 473384) MarketTest:testSingleFloatingBorrow() (gas: 326415) diff --git a/contracts/InterestRateModel.sol b/contracts/InterestRateModel.sol index 70df1db99..90f768474 100644 --- a/contracts/InterestRateModel.sol +++ b/contracts/InterestRateModel.sol @@ -34,6 +34,9 @@ contract InterestRateModel { int256 floatingCurveB_, uint256 floatingMaxUtilization_ ) { + assert(fixedMaxUtilization_ > 1e18); + assert(floatingMaxUtilization_ > 1e18); + fixedCurveA = fixedCurveA_; fixedCurveB = fixedCurveB_; fixedMaxUtilization = fixedMaxUtilization_; diff --git a/test/solidity/InterestRateModel.t.sol b/test/solidity/InterestRateModel.t.sol index efbcb8bb2..a510a9409 100644 --- a/test/solidity/InterestRateModel.t.sol +++ b/test/solidity/InterestRateModel.t.sol @@ -37,6 +37,16 @@ contract InterestRateModelTest is Test { assertEq(rate, 41730769230769230); } + function testRevertFixedMaxUtilizationLowerThanWad() external { + vm.expectRevert(); + new InterestRateModelHarness(0.023e18, -0.0025e18, 1e18 - 1, 0.023e18, -0.0025e18, 1.02e18); + } + + function testRevertFloatingMaxUtilizationLowerThanWad() external { + vm.expectRevert(); + new InterestRateModelHarness(0.023e18, -0.0025e18, 1.02e18, 0.023e18, -0.0025e18, 1e18 - 1); + } + function testFuzzReferenceRate(uint256 v0, uint64 delta) external { (uint256 rate, uint256 refRate) = irm.fixedRate(v0, delta); assertApproxEqAbs(rate, refRate, 3e3);