From 9cad450f2c8c4a42d19bed2b454c21262060cde6 Mon Sep 17 00:00:00 2001 From: itofarina Date: Wed, 13 Dec 2023 17:08:49 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=BA=20irm:=20limit=20parameters=20rang?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/gold-rings-crash.md | 5 +++++ .gas-snapshot | 32 ++++++++++++++++---------------- contracts/InterestRateModel.sol | 13 ++++++++++++- 3 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 .changeset/gold-rings-crash.md diff --git a/.changeset/gold-rings-crash.md b/.changeset/gold-rings-crash.md new file mode 100644 index 000000000..c7b7eabb8 --- /dev/null +++ b/.changeset/gold-rings-crash.md @@ -0,0 +1,5 @@ +--- +"@exactly/protocol": patch +--- + +🦺 irm: limit parameters range diff --git a/.gas-snapshot b/.gas-snapshot index 19e7e1471..a1265ca68 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -130,7 +130,7 @@ EscrowedEXATest:testWithdrawMaxShouldGiveReserveBackWhenDepleted() (gas: 329348) EscrowedEXATest:testWithdrawMaxWithInvalidSender() (gas: 342488) InterestRateModelTest:testFixedBorrowRate() (gas: 16450) InterestRateModelTest:testFloatingBorrowRate() (gas: 10320) -InterestRateModelTest:testRevertMaxUtilizationLowerThanWad() (gas: 38533) +InterestRateModelTest:testRevertMaxUtilizationLowerThanWad() (gas: 38754) MarketTest:testAccountLiquidityAdjustedDebt() (gas: 383831) MarketTest:testAnotherUserRedeemWhenOwnerHasShortfall() (gas: 489509) MarketTest:testAnotherUserWithdrawWhenOwnerHasShortfall() (gas: 477075) @@ -162,7 +162,7 @@ MarketTest:testDepositShouldUpdateFlexibleBorrowVariables() (gas: 448254) MarketTest:testDepositToSmartPool() (gas: 160015) MarketTest:testDistributeMultipleAccumulatedEarnings() (gas: 592925) MarketTest:testDistributionOfLossesShouldReduceFromFloatingBackupBorrowedAccordingly() (gas: 2067235) -MarketTest:testEarlyRepaymentWithExcessiveAmountOfFees() (gas: 2365749) +MarketTest:testEarlyRepaymentWithExcessiveAmountOfFees() (gas: 2366061) MarketTest:testEarlyWithdrawFromFreeLunchShouldNotRevertWithFloatingFullUtilization() (gas: 617061) MarketTest:testFixedBorrowFailingWhenFlexibleBorrowAccruesDebt() (gas: 792249) MarketTest:testFlexibleBorrow() (gas: 331625) @@ -211,8 +211,8 @@ MarketTest:testRoundingUpAllowanceWhenBorrowingAtMaturity() (gas: 503512) MarketTest:testRoundingUpAllowanceWhenWithdrawingAtMaturity() (gas: 526862) MarketTest:testSetDampSpeedFactorShouldUpdateFloatingAssetsAverage() (gas: 243874) MarketTest:testSetEarningsAccumulatorSmoothFactorShouldDistributeEarnings() (gas: 498598) -MarketTest:testSetInterestRateModelShouldUpdateFloatingDebt() (gas: 2024682) -MarketTest:testSetInterestRateModelWithAddressZeroShouldNotUpdateFloatingDebt() (gas: 1887371) +MarketTest:testSetInterestRateModelShouldUpdateFloatingDebt() (gas: 2024994) +MarketTest:testSetInterestRateModelWithAddressZeroShouldNotUpdateFloatingDebt() (gas: 1887683) MarketTest:testShareValueNotDecreasingAfterDeposit() (gas: 474574) MarketTest:testShareValueNotDecreasingWhenMintingToTreasury() (gas: 480569) MarketTest:testSingleFloatingBorrow() (gas: 328751) @@ -247,24 +247,24 @@ PreviewerTest:testAccountsReturningUtilizationForDifferentMaturities() (gas: 341 PreviewerTest:testAccountsWithAccountOnlyDeposit() (gas: 807897) PreviewerTest:testAccountsWithAccountThatHasBalances() (gas: 1689343) PreviewerTest:testAccountsWithEmptyAccount() (gas: 656553) -PreviewerTest:testAccountsWithIntermediateOperationsReturningAccurateAmounts() (gas: 15046830) +PreviewerTest:testAccountsWithIntermediateOperationsReturningAccurateAmounts() (gas: 15047124) PreviewerTest:testActualTimeBeforeStartDistributionRewards() (gas: 7013341) PreviewerTest:testEmptyExactly() (gas: 5225383) PreviewerTest:testExactlyReturningInterestRateModelData() (gas: 651134) -PreviewerTest:testFixedAvailableLiquidityProjectingNewFloatingDebt() (gas: 11156105) -PreviewerTest:testFixedPoolsA() (gas: 16265567) +PreviewerTest:testFixedAvailableLiquidityProjectingNewFloatingDebt() (gas: 11156399) +PreviewerTest:testFixedPoolsA() (gas: 16265861) PreviewerTest:testFixedPoolsChangingMaturityInTime() (gas: 1590533) -PreviewerTest:testFixedPoolsRatesAndUtilizations() (gas: 12635629) -PreviewerTest:testFixedPoolsWithFloatingAssetsAverage() (gas: 13515643) -PreviewerTest:testFlexibleAvailableLiquidity() (gas: 14710040) +PreviewerTest:testFixedPoolsRatesAndUtilizations() (gas: 12635923) +PreviewerTest:testFixedPoolsWithFloatingAssetsAverage() (gas: 13515937) +PreviewerTest:testFlexibleAvailableLiquidity() (gas: 14710334) PreviewerTest:testFlexibleBorrowSharesAndAssets() (gas: 3633520) -PreviewerTest:testFloatingAvailableLiquidityProjectingNewFloatingDebt() (gas: 10746152) +PreviewerTest:testFloatingAvailableLiquidityProjectingNewFloatingDebt() (gas: 10746446) PreviewerTest:testFloatingRateAndUtilization() (gas: 973554) PreviewerTest:testJustUpdatedRewardRatesShouldStillReturnRate() (gas: 6289934) PreviewerTest:testMaxBorrowAssetsCapacity() (gas: 2101880) -PreviewerTest:testMaxBorrowAssetsCapacityForAccountWithShortfall() (gas: 9464882) -PreviewerTest:testMaxBorrowAssetsCapacityPerMarket() (gas: 10945432) -PreviewerTest:testOraclePriceReturningAccurateValues() (gas: 8987296) +PreviewerTest:testMaxBorrowAssetsCapacityForAccountWithShortfall() (gas: 9465176) +PreviewerTest:testMaxBorrowAssetsCapacityPerMarket() (gas: 10945726) +PreviewerTest:testOraclePriceReturningAccurateValues() (gas: 8987590) PreviewerTest:testPreviewBorrowAtAllMaturitiesReturningAccurateAmount() (gas: 3056390) PreviewerTest:testPreviewBorrowAtMaturityReturningAccurateAmount() (gas: 522367) PreviewerTest:testPreviewBorrowAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 1182851) @@ -308,8 +308,8 @@ PreviewerTest:testPreviewWithdrawAtMaturityWithZeroAmount() (gas: 220110) PreviewerTest:testReturnRewardAssetUsdPrice() (gas: 6249941) PreviewerTest:testRewardsRateAfterDistributionEnd() (gas: 6451623) PreviewerTest:testRewardsRateOnlyWithFixedBorrows() (gas: 6204960) -PreviewerTest:testRewardsRateWithDifferentRewardLengths() (gas: 16993794) -PreviewerTest:testRewardsRateWithMarketWithDifferentDecimals() (gas: 16242760) +PreviewerTest:testRewardsRateWithDifferentRewardLengths() (gas: 16994088) +PreviewerTest:testRewardsRateWithMarketWithDifferentDecimals() (gas: 16243054) PreviewerTest:testRewardsRateX() (gas: 7237419) PriceFeedDoubleTest:testPriceFeedDoubleReturningAccurateDecimals() (gas: 433304) PriceFeedDoubleTest:testPriceFeedDoubleReturningPrice() (gas: 26165) diff --git a/contracts/InterestRateModel.sol b/contracts/InterestRateModel.sol index 66a943206..f20464029 100644 --- a/contracts/InterestRateModel.sol +++ b/contracts/InterestRateModel.sol @@ -42,7 +42,18 @@ contract InterestRateModel { int256 timePreference_, uint256 maturitySpeed_ ) { - assert(maxUtilization_ > 1e18); + assert( + curveA_ != 0 && + maxUtilization_ > 1e18 && + floatingNaturalUtilization_ != 0 && + floatingNaturalUtilization_ < 1e18 && + sigmoidSpeed_ != 0 && + growthSpeed_ != 0 && + maxRate_ != 0 && + maxRate_ <= 15_000e16 && + spreadFactor_ != 0 && + maturitySpeed_ != 0 + ); market = market_;