Skip to content
Business logic Audit finding Advanced

Potentially depositing at unfavorable rate since anyone can deposit the entire lenderPool to a known strategy at a pre-fixed time

The LenderPool's start function could be called by anyone at a pre-announced time, depositing the entire pool into a yield strategy. An attacker could manipulate the strategy's exchange rate beforehand to cause the deposit to occur at an unfavourable rate, potentially leaking value.

kyliek Follow

Originally disclosed on Code4rena

Submitted by kyliek

LenderPool.sol#L312 LenderPool.sol#L336

An attacker could keep track of the totalSupply of each LenderPool to see if it is more than the minBorrowAmount. If so, at startTime, which is pre-announced, the attacker could call start, which will trigger SAVINGS_ACCOUNT.deposit() of the entire pool assets to mint LP tokens from external strategy, for example, in CompoundYield.

There is potentially a big sum depositing into a known Compound cToken contract at a known fixed time. Thus, the attacker could prepare the pool by depositing a fair sum first to lower the exchange rate before calling start in lenderPool. Hence, the deposit of the entire pool could be at a less favourable rate. This also applies to other potential strategies that are yet to be integrated. For example, in Curve pool, the attacker could prime the pool to be very imbalanced first and trigger the deposit and then harvest the arbitrage bonus by bringing the pool back to balance.

This attack can happen once only when the pooledCreditLine becomes active for each new lenderPool.

Proof of Concept

Step 1: When a new LenderPool started, note the borrowAsset token and its strategy target pool, as well as the collection period (i.e. start time)

Step 2: Closer to the start time block number, if totalSupply of the lenderPool is bigger than the minBorrowAmount, prepare a good sum to manipulate the target strategy pool for unfavorable exchange rate or arbitrage opportunity afterwords.

Step 3: Call start function before others, also put in his own address to _to to pocket the protocol fee.

Step 4: Depending on the strategy pool, harvest arbitrage. Or perhaps just withdraw one’s money from Step 2 for griefing.

Recommended Mitigation Steps

Add access control on start, e.g. only borrower can call through pooledCreditLine.

ritik99 (Sublime) commented:

We’re not sure how this leads to an attack. Fluctuation in yield is known and expected for most yield strategies like Compound. This, however, does not cause a loss of funds. An attacker instantly withdrawing their liquidity doesn’t affect others because interest rates are not “locked in” on the yield strategies. There are no exchanges taking place. Some more info on possible attacks might help.

HardlyDifficult (judge) commented:

Followed up with the warden and there appears to be a way to leak value by debalancing the pool before start and then rebalancing to extract some profit. This could be done with a flashbot for example to limit exposure.

The warden referenced https://github.com/yearn/yearn-security/blob/master/disclosures/2021-02-04.md as an example of something similar.

ritik99 (Sublime) commented:

Had a discussion with the warden and the judge regarding this issue. For Compound in particular we checked that the exchange rate does not change upon deposits or withdrawals. Thus, sandwiching a call to start() couldn’t possibly lead to an attack vector. Additionally, because of another issue related to start fees #19, we decided to restrict start() to be callable only by the borrower.

However, the yield strategies that we whitelist might still be internally susceptible to this attack (for eg, https://github.com/yearn/yearn-security/blob/master/disclosures/2021-02-04.md). We’ll be incorporating checks for this while onboarding strategies. Picking riskier strategies is optional and not enforced at the contract-level.


The original report as published on Code4rena, by kyliek. 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 start function lacks access control, allowing anyone to trigger the deposit at a predictable time, combined with the strategy's exchange rate being manipulable.

Impact

The attacker could cause the pool to deposit at an unfavourable rate, potentially leaking value; however, for Compound the exchange rate does not change upon deposits or withdrawals, so the attack may not work there, but other whitelisted strategies might still be susceptible.

What the attacker needed

A new LenderPool with totalSupply > minBorrowAmount; knowledge of the start time; funds to manipulate the strategy pool

The fix

The start function was restricted to be callable only by the borrower, and checks for strategy susceptibility are being incorporated during onboarding.

How it was found

  1. Note the borrowAsset token, strategy target pool, and collection period (start time) when a new LenderPool starts.
  2. Closer to the start time, if totalSupply is bigger than minBorrowAmount, prepare funds to manipulate the target strategy pool for an unfavourable exchange rate or arbitrage.
  3. Call the start function before others, setting _to to the attacker's address to collect the protocol fee.
  4. Depending on the strategy pool, harvest arbitrage or withdraw the funds from step 2 for griefing.

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 lender pool collects money from many people and invests it in a yield strategy to earn interest. The start function, which moves all the money into that strategy, could be called by anyone at a known time. An attacker could mess with the strategy's price just before that time so the pool's deposit gets a worse deal, and then profit from the difference.

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 kyliek

View all

3 more disclosed reports, best first.

More from Sublime contest

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.