Submitted by t0x1c, also found by DanielArmstrong
Scenario 1:
The following flow of events (one among many) causes a revert:
In case Bob was attempting to make this deposit to rescue his soon-to-become or already bad debt and to avoid liquidation, this revert will delay his attempt which could well be enough for him to be liquidated by any liquidator, causing loss of funds for Bob. Heres a concrete example with numbers:
Scenario 2:
A similar revert occurs when the following flow of events occur:
Bob is not able to withdraw his entire deposit. If he leaves behind 1 ether and withdraws only 9 ether, then he does not face a revert.
In both of the above cases, eventually the revert is caused by the validation failure on L234-L237 due to the check inside _validateParameter():
The reduction by 1 inside _calculateShares() is done by the protocol in its own favour to safeguard itself. The lendingPoolData[_poolToken].pseudoTotalPool; however, is never modified. This mismatch eventually reaches a significant divergence, and is the root cause of these reverts.
See:
Deposit scenario:
Add the following tests inside contracts/WisenLendingShutdown.t.sol and run via forge test --fork-url mainnet -vvvv --mt test_t0x1c_DepositsRevert to see the tests fail.
If you want to check with values which make the test pass, change the following line in both the tests and run again:
There are numerous combinations which will cause such a revert scenario to occur. Just to provide another example:
Four initial deposits are made in either Style1 or Style2:
Now, Emily tries to make a deposit of 2.5 ether. This reverts.
Withdraw scenario:
Add the following test inside contracts/WisenLendingShutdown.t.sol and run via forge test --fork-url mainnet -vvvv --mt test_t0x1c_WithdrawRevert to see the test fail.
If you want to check with values which make the test pass, change the following line of the test case like shown below and run again:
This failure happened because the moment lendingPoolData[_poolToken].pseudoTotalPool and lendingPoolData[_poolToken].totalDepositShares go below 1 ether, their divergence is significant enough to result in lendSharePrice being calculated as greater than 1000000000000000000 or 1 ether:
Which in this case, evaluates to 1000000000000000001. This brings us back to our root cause of failure. Due to the divergence, lendSharePrice of 1000000000000000001 has become greater than currentSharePriceMax of 1000000000000000000 and fails the validation on L234-L237 inside _compareSharePrices().
High likelihood, as its possible for a huge number of value combinations, as shown above.
If user is trying to save his collateral, this is High severity. Otherwise he can try later with modified values making it a Medium severity.
Foundry
Since the reduction by 1 inside _calculateShares() is being done to round-down in favour of the protocol, removing that without a deeper analysis could prove to be risky as it may open up other attack vectors. Still, two points come to mind which can be explored:
Math
vm06007 (Wise Lending) commented:
Trust (judge) decreased severity to Medium and commented:
t0x1c (warden) commented:
Trust (judge) commented:
Wise Lending commented:
For this audit, 7 reports were submitted by wardens detailing low risk and non-critical issues. The report highlighted below by Dup1337 received the top score from the judge.
The following wardens also submitted reports: cheatc0d3, nonseodion, 0x11singh99, serial-coder, shealtielanz, and NentoR.
