Skip to content
Business logic Audit finding Intermediate

Griefing attack is possible via TrueFi borrowing

A griefing attack is possible because TrueFiStrategy's net asset value depends on TrueFi pool liquidity, which can be reduced by any whitelisted borrower. An attacker can front-run a victim's withdrawal with a short-term loan, causing the victim to incur higher exit penalties.

hyh Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-09-sherlock-judging/tree/main/017-M

Found by

hyh

Summary

As TrueFiStrategy net asset value reported with _balanceOf() depends on the TrueFi liquidity situation, which can be modified by any user eligible for TrueFi loans, a griefing attack of borrowing right ahead of Sherlock requesting NAV figure from the strategy is possible.

Vulnerability Detail

On observing a Sherlock's redeemNFT() or arbRestake() from Bob the target user, Alice the attacker will front run his transaction with borrow() call, reducing the amount of liquid funds a TrueFiPool2 has, immediately repaying her debt right afterwards. I.e. Alice will become a short term debtor for sandwiching Bob's redeemNFT(). Alice needs to be whitelisted as a borrower, which is achievable, and her status will not be affected by this attack and examined alone her actions are legitimate, i.e. she only takes are repays short-term loan, which is valid usage of TrueFi.

As loan term is small the overall cost of the attack (that consists of the loan interest along with gas costs for borrow and repay transactions) isn't substantial for Alice, while Bob can incur big enough slippage as TrueFiStrategy's _balanceOf() will observe low liquidValue() and thus high liquidExitPenalty(totalAmount) of the TrueFiPool2, diminishing the value of the Bob's withdrawal. Alice can repeat this many times over with various Sherlock users.

Impact

Sherlock stakers who unstaked will incur higher fees proportionally to the current TrueFi liquidity situation and the budget Alice have for the attack (with increased budget she can do it more frequently and take bigger loans, moving liquidity more substantially).

Code Snippet

There are two agencies that can be used for borrowing, FixedTermLoanAgency and LineOfCreditAgency, and Alice needs to become an allowed borrower in either of them:

FixedTermLoanAgency:

https://github.com/trusttoken/contracts-pre22/blob/986fefb91fb0619217d17ecf0b4c5b7b921130ed/contracts/truefi2/FixedTermLoanAgency.sol#L288-L291

Solidity
    function allowBorrower(address who) external onlyOwner {
        isBorrowerAllowed[who] = true;
        emit BorrowerAllowed(who);
    }

https://github.com/trusttoken/contracts-pre22/blob/986fefb91fb0619217d17ecf0b4c5b7b921130ed/contracts/truefi2/FixedTermLoanAgency.sol#L327-L351

Solidity
    function borrow(
        ITrueFiPool2 pool,
        uint256 amount,
        uint256 term,
        uint256 _maxApy
    ) external onlyAllowedBorrowers {
        require(poolFactory.isSupportedPool(pool), "FixedTermLoanAgency: Pool not supported by the factory");
        require(poolLoans[pool].length < maxLoans, "FixedTermLoanAgency: Loans number has reached the limit");

        address borrower = msg.sender;
        require(borrowingMutex.isUnlocked(borrower), "FixedTermLoanAgency: There is an ongoing loan or credit line");
        require(
            creditOracle.status(borrower) == ITrueFiCreditOracle.Status.Eligible,
            "FixedTermLoanAgency: Sender is not eligible for loan"
        );

        require(amount > 0, "FixedTermLoanAgency: Loans of amount 0, will not be approved");
        require(
            pool.oracle().tokenToUsd(amount) <= borrowLimit(pool, borrower),
            "FixedTermLoanAgency: Loan amount cannot exceed borrow limit"
        );

        require(term > 0, "FixedTermLoanAgency: Loans cannot have instantaneous term of repay");
        require(isTermBelowMax(term), "FixedTermLoanAgency: Loan's term is too long");
        require(isCredibleForTerm(term), "FixedTermLoanAgency: Credit score is too low for loan's term");

LineOfCreditAgency:

https://github.com/trusttoken/contracts-pre22/blob/986fefb91fb0619217d17ecf0b4c5b7b921130ed/contracts/truefi2/LineOfCreditAgency.sol#L236-L240

Solidity
    /// @dev set borrower `who` to whitelist status `isAllowed`
    function allowBorrower(address who, bool isAllowed) external onlyOwner {
        isBorrowerAllowed[who] = isAllowed;
        emit BorrowerAllowed(who, isAllowed);
    }

https://github.com/trusttoken/contracts-pre22/blob/986fefb91fb0619217d17ecf0b4c5b7b921130ed/contracts/truefi2/LineOfCreditAgency.sol#L380-L395

Solidity
    /**
     * @dev Borrow from `pool` for `amount` using lines of credit
     * Only whitelisted borrowers that meet all requirements can borrow
     * @param pool Pool to borrow from
     * @param amount Amount of tokens to borrow
     */
    function borrow(ITrueFiPool2 pool, uint256 amount) external onlyAllowedBorrowers {
        require(poolFactory.isSupportedPool(pool), "LineOfCreditAgency: The pool is not supported for borrowing");
        require(amount > 0, "LineOfCreditAgency: Borrowed amount has to be greater than 0");
        require(
            creditOracle.status(msg.sender) == ITrueFiCreditOracle.Status.Eligible,
            "LineOfCreditAgency: Sender not eligible to borrow"
        );
        require(!_hasOverdueInterest(pool, msg.sender), "LineOfCreditAgency: Sender has overdue interest in this pool");
        uint8 rawScore = creditOracle.score(msg.sender);
        require(rawScore >= minCreditScore, "LineOfCreditAgency: Borrower has credit score below minimum");

However, this is one time requirement and the attack itself doesn't look malicious, i.e. Alice uses ultra short term borrowing in a flash loan manner, paying the interest, there is no violation in Truefi2 use cases, so becoming an allowed borrower once Alice can perform the attack many times over an extended period of time.

As Alice will seek the easiest path, the FixedTermLoanAgency that doesn't require credit scores for short term borrowing looks the most suitable:

https://github.com/trusttoken/contracts-pre22/blob/986fefb91fb0619217d17ecf0b4c5b7b921130ed/contracts/truefi2/FixedTermLoanAgency.sol#L525-L527

Solidity
    function isCredibleForTerm(uint256 term) internal view returns (bool) {
        return term <= longTermLoanThreshold || creditOracle.score(msg.sender) >= longTermLoanScoreThreshold;
    }

https://github.com/trusttoken/contracts-pre22/blob/986fefb91fb0619217d17ecf0b4c5b7b921130ed/contracts/truefi2/FixedTermLoanAgency.sol#L206

Solidity
        longTermLoanThreshold = 90 days;

Tool used

Manual Review

Recommendation

As this is design specifics only partial remediation looks viable. As an example, some delay can be introduced in the TrueFi between loan request and funds transfer. It will not impact valid use cases, but close this attack surface.

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

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 strategy's net asset value calculation depends on the pool's liquid balance, which can be manipulated by any whitelisted borrower.

Impact

Victims who unstake may incur higher fees proportional to the reduced liquidity and the attacker's budget, and the attack can be repeated.

What the attacker needed

Attacker is whitelisted as a borrower; victim initiates a withdrawal

The fix

A delay should be introduced between loan request and funds transfer to prevent front-running.

How it was found

  1. Attacker becomes a whitelisted borrower in TrueFi.
  2. Attacker observes a victim's redeemNFT() or arbRestake() transaction.
  3. Attacker front-runs with a borrow() call to reduce pool liquidity.
  4. Attacker immediately repays the loan after the victim's transaction.

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 report describes a way to make another user lose money by temporarily borrowing funds from a shared pool. When the victim tries to withdraw, the pool has less money, so they pay a higher fee. The attacker can do this repeatedly because borrowing and repaying quickly is allowed.

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.

More by hyh

View all

137 more disclosed reports, best first.

More from Sherlock

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.