57036 sc high unconditional debt reduction before protocol fee check in force repayment
Description
Brief/Intro
Vulnerability Details
function _forceRepay(uint256 accountId, uint256 amount) internal returns (uint256) {
if (amount == 0) {
return 0;
}
_checkForValidAccountId(accountId);
Account storage account = _accounts[accountId];
// Query transmuter and earmark global debt
_earmark();
// Sync current user debt before deciding how much is available to be repaid
_sync(accountId);
uint256 debt;
// Burning yieldTokens will pay off all types of debt
_checkState((debt = account.debt) > 0);
uint256 credit = amount > debt ? debt : amount;
uint256 creditToYield = convertDebtTokensToYield(credit);
@> _subDebt(accountId, credit); // Debt reduced here unconditionally
// Repay debt from earmarked amount of debt first
uint256 earmarkToRemove = credit > account.earmarked ? account.earmarked : credit;
account.earmarked -= earmarkToRemove;
creditToYield = creditToYield > account.collateralBalance ? account.collateralBalance : creditToYield;
@> account.collateralBalance -= creditToYield; // <-- Collateral deducted for repayment
@> uint256 protocolFeeTotal = creditToYield * protocolFee / BPS; // <-- Fee computed on full creditToYield
emit ForceRepay(accountId, amount, creditToYield, protocolFeeTotal);
@> if (account.collateralBalance > protocolFeeTotal) {
account.collateralBalance -= protocolFeeTotal; // <-- Fee conditional on *remaining* collateral
// Transfer the protocol fee to the protocol fee receiver
TokenUtils.safeTransfer(myt, protocolFeeReceiver, protocolFeeTotal);
}
if (creditToYield > 0) {
// Transfer the repaid tokens from the account to the transmuter.
TokenUtils.safeTransfer(myt, address(transmuter), creditToYield);
}
return creditToYield;
} Impact Details
Soln
References
Proof of Concept
Proof of Concept
Previous57563 sc insight reward tokens being permanently frozen in tokeautousdstrategyNext58115 sc medium incorrect weth deposit amount prevents deposited eth through receive function to cover strategy loss
Was this helpful?