Skip to content

Commit

Permalink
Fix flakey invariant and add mathematic require in Lender (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively authored Sep 18, 2023
1 parent 4d7ea7b commit 9568095
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/src/Lender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
}
Expand Down
4 changes: 2 additions & 2 deletions core/test/invariants/LenderInvariants.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 9568095

Please sign in to comment.