Submitted by panprog, also found by 0xA5DF and Lambda
Leftover shares in liquidateClean are only subtracted from pair totals, but not from users borrowed shares. This means that after liquidateClean, borrowers shares will be greater than 0 (leftover shares after liquidations), but the user is still insolvent and can be liquidated again and again (with _sharesToLiquidate set to 0). Each subsequent liquidation will write off the bad debt (reduce pair totals by borrower leftover shares/amounts), but doesnt take anything from liquidator nor borrower (since _sharesToLiquidate == 0).
This messes up the whole pair accounting, with total asset amounts reducing and total borrow amounts and shares reducing. This will make it impossible for borrowers to repay debt (or be liquidated), because borrow totals will underflow, and lenders amount to withdraw will reduce a lot (they will share non-existant huge bad debt).
Reducing pair totals scenario:
Copy this to src/test/e2e/LiquidationBugTest.sol
https://gist.github.com/panprog/cbdc1658d63c30c9fe94127a4b4b7e72
After the line
https://github.com/code-423n4/2022-08-frax/blob/c4189a3a98b38c8c962c5ea72f1a322fbc2ae45f/src/contracts/FraxlendPairCore.sol#L1012
add
amirnader-ghazvini (Frax) marked as duplicate and commented:
gititGoro (judge) commented:
DrakeEvans (Frax) confirmed
