Grieving attack by failing user’s transactions
An attacker can front-run a user's debt repayment transaction by repaying a tiny amount of that user's debt first, causing the user's transaction to fail with an underflow error. This prevents the user from fully repaying their debt.
HE1M Follow with HollaDieWaldfee
Originally disclosed on Code4rena
Submitted by HE1M, also found by HollaDieWaldfee
An attacker can apply grieving attack by preventing users from interacting with some of the protocol functions. In other words whenever a user is going to reduce his debt, or buy and reduce his debt in one tx, it can be failed by the attacker.
Proof of Concept
In the following scenario, I am explaining how it is possible to fail user’s transaction to reduce their debt fully. Failing other transactions (buy and reduce the debt in one tx) can be done similarly.
-
Suppose Alice (an honest user) has debt of 1000
PaprTokenand she intends to repay her debt fully: -
So, she calls the function
reduceDebtwith the following parameters:account: Alice’s addressasset: The NFT which was used as collateralamount: 1000 * 10**18 (decimal ofPaprTokenis 18).
function reduceDebt(address account, ERC721 asset, uint256 amount) external override {
_reduceDebt({account: account, asset: asset, burnFrom: msg.sender, amount: amount});
}
-
Bob (a malicious user who owns a small amount of
PaprToken) notices Alice’s transaction in the Mempool. So, Bob applies front-run attack and calls the functionreduceDebtwith the following parameters:account: Alice’s addressasset: The NFT which was used as collateralamount: 1
-
By doing so, Bob repays only 1
PaprTokenon behalf of Alice, so Alice’s debt becomes1000 * 10**18 - 1.
function _reduceDebt(address account, ERC721 asset, address burnFrom, uint256 amount) internal {
_reduceDebtWithoutBurn(account, asset, amount);
PaprToken(address(papr)).burn(burnFrom, amount);
}
function _reduceDebtWithoutBurn(address account, ERC721 asset, uint256 amount) internal {
_vaultInfo[account][asset].debt = uint200(_vaultInfo[account][asset].debt - amount);
emit ReduceDebt(account, asset, amount);
}
- Then, when Alice’s transaction is going to be executed, it fails because of
Underflow Error. Since Alice’s debt is1000 * 10**18 - 1while Alice’s transaction was going to repay1000 * 10**18.
_vaultInfo[account][asset].debt = uint200(_vaultInfo[account][asset].debt - amount);
- Bob only pays a very small value of 1
PaprToken(consider that the decimal is 18) to apply this grieving attack. - Bob can repeat this attack for Alice, if Alice is going to call this function again with correct parameter.
In summary, Bob could prevent the user from paying her debt fully by just repaying a very small amount of the user’s debt in advance and as a result causing underflow error. Bob can apply this attack for all other users who are going to repay their debt fully. Please note that if a user is going to repay her debt partially, the attack can be expensive and not financially reasonable, but in case of full repayment of debt, it is very cheap to apply this grieving attack.
This attack can be applied on the transactions that are going to interact with the function _reduceDebt. The transactions interacting with this specific function are:
buyAndReduceDebt(...)
reduceDebt(...)
It means that the attacker can prevent users from calling the functions above.
Recommended Mitigation Steps
The following condition should be added to the function _reduceDebtWithoutBurn:
function _reduceDebtWithoutBurn(address account, ERC721 asset, uint256 amount) internal {
if(amount > _vaultInfo[account][asset].debt){
amount = _vaultInfo[account][asset].debt;
}
_vaultInfo[account][asset].debt = uint200(_vaultInfo[account][asset].debt - amount);
emit ReduceDebt(account, asset, amount);
}
wilsoncusack (Backed) confirmed
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 debt reduction function does not cap the repayment amount at the current debt, so an unexpected small repayment causes an underflow when the victim's larger repayment is processed.
Impact
An attacker can cheaply and repeatedly prevent any user from fully repaying their debt, causing a denial of service for the reduceDebt and buyAndReduceDebt functions.
What the attacker needed
Attacker owns a small amount of PaprToken; attacker can front-run transactions
The fix
The function should cap the repayment amount at the current debt before subtracting, so that overpayment does not cause an underflow.
How it was found
- Alice calls reduceDebt to repay her full debt of 1000 PaprToken.
- Bob sees Alice's transaction in the mempool and front-runs by calling reduceDebt for Alice with amount 1.
- Bob's transaction reduces Alice's debt to 1000*10**18 - 1.
- When Alice's transaction executes, it tries to subtract 1000*10**18 from the reduced debt, causing an underflow error and failure.
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 is a smart contract issue where someone can block another person's attempt to pay back a loan. The attacker pays back a tiny part of the victim's loan just before the victim's payment, so the victim's payment tries to subtract more than the remaining debt and fails. The victim cannot fully repay until they adjust the amount.
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.