AccountantDelegate: The sweepInterest function sweeps an incorrect number of cnote
The sweepInterest function transfers amtToSweep (a Note-denominated amount) instead of cNoteToSweep (the corresponding cNote amount) to the treasury. Since amtToSweep is normally larger than cNoteToSweep, the transfer often fails or reverts, leaving interest locked in the contract.
Submitted by cccz, also found by Critical
In the sweepInterest function of the AccountantDelegate contract, the number of cnote sent to treasury should be cNoteToSweep instead of amtToSweep, as amtToSweep will normally be smaller than cNoteToSweep, which will cause the interest to be locked in the in the contract.
uint amtToSweep = sub_(cNoteAmt, noteDiff); // amount to sweep in Note,
uint cNoteToSweep = div_(amtToSweep, exRate); // amount of cNote to sweep = amtToSweep(Note) / exRate
cNoteToSweep = (cNoteToSweep > cNoteBal) ? cNoteBal : cNoteToSweep;
bool success = cnote.transfer(treasury, amtToSweep);
if (!success) {
revert SweepError(treasury , amtToSweep); //handles if transfer of tokens is not successful
}
TreasuryInterface Treas = TreasuryInterface(treasury);
Treas.redeem(address(cnote),amtToSweep);
Proof of Concept
Recommended Mitigation Steps
uint amtToSweep = sub_(cNoteAmt, noteDiff); // amount to sweep in Note,
uint cNoteToSweep = div_(amtToSweep, exRate); // amount of cNote to sweep = amtToSweep(Note) / exRate
cNoteToSweep = (cNoteToSweep > cNoteBal) ? cNoteBal : cNoteToSweep;
- bool success = cnote.transfer(treasury, amtToSweep);
+ bool success = cnote.transfer(treasury, cNoteToSweep);
if (!success) {
- revert SweepError(treasury , amtToSweep); //handles if transfer of tokens is not successful
+ revert SweepError(treasury , cNoteToSweep); //handles if transfer of tokens is not successful
}
TreasuryInterface Treas = TreasuryInterface(treasury);
- Treas.redeem(address(cnote),amtToSweep);
+ Treas.redeem(address(cnote),cNoteToSweep);
Alex the Entreprenerd (judge) commented:
The warden has shown that the wrong variable is being used as the transferAmount.
Because
cNoteToSweep<<amtToSweepthere will be many instances in which the function will revert.Because the finding shows incorrect functionality, which can leave the tokens stuck indefinitely, I agree with High Severity.
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
Root cause
Likely the code uses the wrong variable (amtToSweep) as the transfer amount instead of the correctly calculated cNoteToSweep.
Impact
Interest can be locked in the contract indefinitely because the transfer may revert when the Note amount exceeds the cNote balance.
What the attacker needed
Contract holds interest to sweep
The fix
The transfer, revert, and redeem calls should use cNoteToSweep instead of amtToSweep.
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.
This contract holds two kinds of tokens: Note and cNote. When it sweeps interest, it calculates how many cNote to send but then accidentally sends the Note amount instead. Because the Note amount is usually bigger than the cNote amount, the transfer often fails and the interest gets stuck.
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.