From 9568095c37a9e24480a9a9fe68940824b1242735 Mon Sep 17 00:00:00 2001 From: Hayden Shively <17186559+haydenshively@users.noreply.github.com> Date: Mon, 18 Sep 2023 00:13:14 -0500 Subject: [PATCH] Fix flakey invariant and add mathematic require in Lender (#162) --- core/src/Lender.sol | 2 +- core/test/invariants/LenderInvariants.t.sol | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/Lender.sol b/core/src/Lender.sol index effdaf47..0b58be51 100644 --- a/core/src/Lender.sol +++ b/core/src/Lender.sol @@ -61,7 +61,7 @@ contract Lender is Ledger { /// @notice Sets the `rateModel` and `reserveFactor`. Only the `FACTORY` can call this. function setRateModelAndReserveFactor(IRateModel rateModel_, uint8 reserveFactor_) external { - require(msg.sender == address(FACTORY)); + require(msg.sender == address(FACTORY) && reserveFactor_ > 0); rateModel = rateModel_; reserveFactor = reserveFactor_; } diff --git a/core/test/invariants/LenderInvariants.t.sol b/core/test/invariants/LenderInvariants.t.sol index e26c5986..f21d9ea9 100644 --- a/core/test/invariants/LenderInvariants.t.sol +++ b/core/test/invariants/LenderInvariants.t.sol @@ -199,9 +199,9 @@ contract LenderInvariantsTest is Test { address user = lenderHarness.holders(i); // NOTE: As price per share increases (i.e., each share converts to more and more underlying assets), - // this assertion may become flakey due to rounding. Allowing for rounding error of 2 seems sufficient + // this assertion may become flakey due to rounding. Allowing for rounding error of 3 seems sufficient // in our testing. Just make sure the contract itself never assumes principle < underlyingBalance - assertLe(lender.principleOf(user), lender.underlyingBalance(user) + 2); + assertLe(lender.principleOf(user), lender.underlyingBalance(user) + 3); } }