Before transferring `CToken`, the `accrueInterest()` function should be called first
The CToken transfer function calls the comptroller's transferAllowed check without first accruing interest, so the check uses outdated collateral and debt values. This can cause legitimate transfers to be reverted and illegitimate transfers to succeed, potentially leading to liquidation.
Source: https://github.com/sherlock-audit/2024-12-numa-audit-judging/issues/168
Found by
KupiaSec
Summary
Before transferring CToken, the NumaComptroller.transferAllowed() function is called first to prevent any imbalance between the user's collateral and debt value.
However, since accrueInterest() is not called before transferAllowed(), the imbalance check is performed incorrectly, using outdated data.
As a result, legitimate transfers may be reverted, and illegitimate transfers could succeed.
Root Cause
Before transferring CToken, the transferTokens() function is invoked without first calling accrueInterest().
Within the transferTokens() function, transferAllowed() is called.
The NumaComptroller.transferAllowed() function checks for potential imbalances between the user's collateral and debt value. However, this check is inaccurate, as it relies on outdated data because accrueInterest() has not been invoked.
As a result, legitimate transfers may be reverted, and illegitimate transfers could succeed.
The reversal of legitimate transfers is particularly concerning, as it can be time-sensitive, especially in liquidation situations for the receiver. And illegitimate transfers can lead to an imbalance between the sender's collateral and the value of their debt, potentially resulting in the sender facing liquidation after the transfer.
function transfer(
address dst,
uint256 amount
) external override nonReentrant returns (bool) {
149 return transferTokens(msg.sender, msg.sender, dst, amount) == NO_ERROR;
}
--------------------
function transferTokens(
address spender,
address src,
address dst,
uint tokens
) internal returns (uint) {
/* Fail if transfer not allowed */
90 uint allowed = comptroller.transferAllowed(
address(this),
src,
dst,
tokens
);
if (allowed != 0) {
revert TransferComptrollerRejection(allowed);
}
...
}
Internal pre-conditions
External pre-conditions
Attack Path
Impact
Legitimate transfers may be reverted, and illegitimate transfers could succeed.
If the receiver is on the verge of liquidation, the reversal of legitimate transfers to this receiver becomes a time-sensitive issue.
And illegitimate transfers can lead to an imbalance between the sender's collateral and the value of their debt, potentially resulting in the sender facing liquidation after the transfer.
PoC
Mitigation
Invoke accrueInterest() before the transfer.
Discussion
tibthecat
This is coming from compound V2 fork. Is compound V2 vulnerable to that too?
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
Legitimate transfers may be reverted and illegitimate transfers could succeed, potentially causing the sender to face liquidation after the transfer.
What the attacker needed
A lending market using this CToken; user has collateral and debt
The fix
The transfer function should call accrueInterest before checking transferAllowed.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In a lending system, before you move your collateral tokens, the system checks that your remaining collateral still covers your debt. That check uses stored numbers that only update when interest is added. Here, interest was not added first, so the check used old numbers and could wrongly block or allow a transfer.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.