diff --git a/src/Synths/EulerSavingsRate.sol b/src/Synths/EulerSavingsRate.sol index efc701b8..01dbb00c 100644 --- a/src/Synths/EulerSavingsRate.sol +++ b/src/Synths/EulerSavingsRate.sol @@ -29,7 +29,6 @@ contract EulerSavingsRate is EVCUtil, ERC4626 { uint256 totalAssetsDeposited; error Reentrancy(); - error E_GulpTooMuch(); /// @notice Modifier to require an account status check on the EVC. /// @dev Calls `requireAccountStatusCheck` function from EVC for the specified account after the function body. @@ -133,10 +132,12 @@ contract EulerSavingsRate is EVCUtil, ERC4626 { uint256 assetBalance = IERC20(asset()).balanceOf(address(this)); uint256 toGulp = assetBalance - totalAssetsDeposited - esrSlotCache.interestLeft; - if (toGulp > type(uint168).max - esrSlotCache.interestLeft) revert E_GulpTooMuch(); + uint256 maxGulp = type(uint168).max - esrSlotCache.interestLeft; + if (toGulp > maxGulp) toGulp = maxGulp; // cap interest, allowing the vault to function esrSlotCache.interestSmearEnd = uint40(block.timestamp + INTEREST_SMEAR); - esrSlotCache.interestLeft += uint168(toGulp); + esrSlotCache.interestLeft += uint168(toGulp); // toGulp <= maxGulp <= max uint168 + // write esrSlotCache back to storage in a single SSTORE esrSlot = esrSlotCache; } diff --git a/test/unit/esr/ESR.Fuzz.t.sol b/test/unit/esr/ESR.Fuzz.t.sol index 688dc5ef..3012e63f 100644 --- a/test/unit/esr/ESR.Fuzz.t.sol +++ b/test/unit/esr/ESR.Fuzz.t.sol @@ -35,7 +35,7 @@ contract ESRFuzzTest is ESRTest { // this tests shows that when you have a very small deposit and a very large interestAmount minted to the contract function testFuzz_gulp_under_uint168(uint256 interestAmount, uint256 depositAmount, uint256 timePassed) public { depositAmount = bound(depositAmount, 0, type(uint112).max); - interestAmount = bound(interestAmount, 0, type(uint112).max - depositAmount); // this makes sure that the mint won't cause overflow + interestAmount = bound(interestAmount, 0, type(uint256).max - depositAmount); // this makes sure that the mint won't cause overflow timePassed = bound(timePassed, block.timestamp, type(uint40).max); asset.mint(address(esr), interestAmount); @@ -43,7 +43,11 @@ contract ESRFuzzTest is ESRTest { esr.gulp(); EulerSavingsRate.ESRSlot memory esrSlot = esr.updateInterestAndReturnESRSlotCache(); - assertEq(esrSlot.interestLeft, interestAmount); + if (interestAmount <= type(uint168).max - depositAmount) { + assertEq(esrSlot.interestLeft, interestAmount); + } else { + assertEq(esrSlot.interestLeft, type(uint168).max); + } } // fuzz test that any deposits added are added to the totalAssetsDeposited