Skip to content
Business logic Audit finding Intermediate

Innocent borrower could incur losses caused by a malicious lender

The lender can change the interest rate at the trading pool level at any time, and the borrower cannot specify a maximum acceptable rate. A malicious lender could front-run a borrowing transaction by raising the rate to the maximum, causing the borrower to incur losses even if they repay immediately because interest is charged for at least one day.

Koolex Follow

Originally disclosed on Code4rena

Submitted by Koolex

The protocol allows the lender to change the interest rate anytime. However, since the new interest rate is stored on trading pool level, the lender could front-run a borrowing transaction that’s yet to be processed, updating the interest rate too high (up to 99). This is harmful to the borrower even if the borrower repays the SOL immediately. That’s because the minimum elapsed days on repay is set to be one

  let days_elapsed = ((current_timestamp - timestamp) as u64 / 86400) + 1; // +1 to ensure interest is charged from day 0

src/processor/swapback.rs#L145

Proof of Concept

Update interest rate on pool level:

src/processor/lending.rs#L38-L51

Minimum elapsed days is 1:

```rust
  let days_elapsed = ((current_timestamp - timestamp) as u64 / 86400) + 1; // +1 to ensure interest is charged from day 0
```

src/processor/swapback.rs#L145

Recommended Mitigation Steps

Allow the borrower to pass maximum interest rate, this protects the borrower from any change of the interest rate that occur after they send their TX.

Another suggestion: store the interest rate on position level instead.

piske-alex (Lavarage) confirmed and commented:

Another suggestion: store the interest rate on position level instead.

Will implement max interest rate param. How do I store the interest rate on position before the position is created?

Koolex (warden) commented:

@piske-alex - That’s a very good point, as it can still be front-run.

However, if you still would like to avoid passing the interest rate as a param, interest rate should be stored in trading pool with updated_time, then on borrowing, check if there is not enough timespan between current timestamp and updated_time, revert accordingly. Otherwise, proceed and store the interest rate (for records only).

This should be a sufficient protection without requiring the user to pass max interest rate as a param due to the fact that, a Solana TX has an expiration time. So, if it is not processed within a certain time, it will never be.

During transaction processing, Solana Validators will check if each transaction’s recent blockhash is recorded within the most recent 151 stored hashes (aka “max processing age”). If the transaction’s recent blockhash is older than this max processing age, the transaction is not processed.

Check this for more info.

alcueca (judge) commented:

Front-running by validators is possible in Solana, and after a brief analysis of the current situation, concerning to some users. This issue can cause mild losses to users. Nothing major, but a headache for the protocol that will have to deal with the complaints and possibly refunds. Affected users would have to close their positions immediately if they notice the issue. All in all, a medium is a fair severity rating.

Note: For full discussion, see here.


The original report as published on Code4rena, by Koolex. 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

Likely the interest rate is stored at the trading pool level and can be updated by the lender at any time, while the borrower has no way to specify a maximum acceptable rate, allowing front-running.

Impact

The borrower could incur losses due to the high interest rate, even if they repay immediately, because interest is charged for at least one day; the judge noted this can cause mild losses and is a medium severity issue.

What the attacker needed

Malicious lender; borrower submits a borrow transaction; lender can front-run the transaction

The fix

The fix should allow the borrower to pass a maximum interest rate parameter, or store the interest rate on the position level, or implement a time delay check on rate updates.

How it was found

  1. Lender updates the interest rate on the pool to a very high value (up to 99).
  2. Borrower submits a borrowing transaction without a maximum rate parameter.
  3. Lender front-runs the borrowing transaction, so the high rate is applied.
  4. Borrower repays immediately but is charged interest for at least one day.

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.

In this lending system, the lender sets the interest rate, and the borrower has no say in it. A malicious lender can watch for a borrower's transaction and quickly change the rate to a very high value before the borrower's transaction is processed. Even if the borrower repays right away, they still owe at least one day of interest at that high rate, so they lose money.

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 Koolex

View all

10 more disclosed reports, best first.

More from Lavarage Invitational

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.