Closed code423n4 closed 2 years ago
The amount is still deterministic. The only thing that can interrupt the determinism is MEV but that's beyond the scope of the audit. The reason UIs exist on top of Ethereum is not just for aesthetic or ease of use but to take care of these sorts of hairy calculations. Making it easier for the user to calculate often involves much more gas consumption. Marking invalid.
Lines of code
https://github.com/code-423n4/2022-08-frax/blob/c4189a3a98b38c8c962c5ea72f1a322fbc2ae45f/src/contracts/FraxlendPairCore.sol#L1209 https://github.com/code-423n4/2022-08-frax/blob/c4189a3a98b38c8c962c5ea72f1a322fbc2ae45f/src/contracts/FraxlendPairCore.sol#L1157-L1162
Vulnerability details
Impact
The
repayAssetWithCollateral()
function is difficult to use in order to pay off a user's entire balance. In an effort to pay off the user's entire debt, they will attempt to calculate the amount of collateral necessary that equivalates to their debt shares. If the amount of asset received via the swap is larger than their debt position, execution will revert due to underflow.Proof of Concept
The
repayAssetWithCollateral()
function takes_collateralToSwap
as a parameter.This amount is used to swap to the asset token. The asset balance is determined via the contract balance difference pre and post swap:
Shares are calculated and a repayment is attempted:
In the
_repayAsset()
function, if too many shares are attempted for repay, execution will revert due to underflow.Tools Used
Manual review.
Recommended Mitigation Steps
This issue also exists in the normal repayment flow, though the user is able to provide the exact
share
value to repay. A fix for this issue would involve refunding the amount of asset that exceeds the debt shares.