Skip to content
DoS Audit finding Intermediate

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 PaprToken and she intends to repay her debt fully:

  • So, she calls the function reduceDebt with the following parameters:

    • account: Alice’s address
    • asset: The NFT which was used as collateral
    • amount: 1000 * 10**18 (decimal of PaprToken is 18).
function reduceDebt(address account, ERC721 asset, uint256 amount) external override {
        _reduceDebt({account: account, asset: asset, burnFrom: msg.sender, amount: amount});
    }

https://github.com/with-backed/papr/blob/9528f2711ff0c1522076b9f93fba13f88d5bd5e6/src/PaprController.sol#L148

  • 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 function reduceDebt with the following parameters:

    • account: Alice’s address
    • asset: The NFT which was used as collateral
    • amount: 1
  • By doing so, Bob repays only 1 PaprToken on behalf of Alice, so Alice’s debt becomes 1000 * 10**18 - 1.

function _reduceDebt(address account, ERC721 asset, address burnFrom, uint256 amount) internal {
        _reduceDebtWithoutBurn(account, asset, amount);
        PaprToken(address(papr)).burn(burnFrom, amount);
    }

https://github.com/with-backed/papr/blob/9528f2711ff0c1522076b9f93fba13f88d5bd5e6/src/PaprController.sol#L481

function _reduceDebtWithoutBurn(address account, ERC721 asset, uint256 amount) internal {
        _vaultInfo[account][asset].debt = uint200(_vaultInfo[account][asset].debt - amount);
        emit ReduceDebt(account, asset, amount);
    }

https://github.com/with-backed/papr/blob/9528f2711ff0c1522076b9f93fba13f88d5bd5e6/src/PaprController.sol#L486

  • Then, when Alice’s transaction is going to be executed, it fails because of Underflow Error. Since Alice’s debt is 1000 * 10**18 - 1 while Alice’s transaction was going to repay 1000 * 10**18.
_vaultInfo[account][asset].debt = uint200(_vaultInfo[account][asset].debt - amount);

https://github.com/with-backed/papr/blob/9528f2711ff0c1522076b9f93fba13f88d5bd5e6/src/PaprController.sol#L487

  • 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(...)

https://github.com/with-backed/papr/blob/9528f2711ff0c1522076b9f93fba13f88d5bd5e6/src/PaprController.sol#L229

  • reduceDebt(...)

https://github.com/with-backed/papr/blob/9528f2711ff0c1522076b9f93fba13f88d5bd5e6/src/PaprController.sol#L149

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);
    }

https://github.com/with-backed/papr/blob/9528f2711ff0c1522076b9f93fba13f88d5bd5e6/src/PaprController.sol#L486

wilsoncusack (Backed) confirmed


The original report as published on Code4rena, by HE1M. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. Alice calls reduceDebt to repay her full debt of 1000 PaprToken.
  2. Bob sees Alice's transaction in the mempool and front-runs by calling reduceDebt for Alice with amount 1.
  3. Bob's transaction reduces Alice's debt to 1000*10**18 - 1.
  4. 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.

More by HE1M

View all

14 more disclosed reports, best first.

More from Papr contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.