Skip to content
Business logic Audit finding Intermediate

Yield can be unfairly divided because of MEV/Just-in-time stablecoin deposits

An attacker can use MEV to deposit a large amount of stablecoins just before the admin calls distributeYield, receive a disproportionate share of the yield, and then withdraw immediately after. This unfairly divides yield and harms other lenders.

mtz Follow

Originally disclosed on Code4rena

Submitted by mtz, also found by 0x52, hyh, jonah1005, leastwood, and sorrynotsorry

YieldManager.sol#L129-L134 YieldManager.sol#L160-L161

An attacker can use MEV (via gas auction or Flashbots or control of miners) to cause an unfair division of yield. By providing a very large (relative to the size of all other stablecoin deposits combined) stablecoin deposit Just-in-Time before an admin’s call to distributeYield the stablecoin deposited by the attacker will receive a very large amount of the yield and the attacker can immediately withdraw their deposit after yield is distributed. We assume this allows an attacker to get a lot of the yield reward even though they haven’t provided any deposit that has been borrowed. However, the exact mechanism for how yield is distributed to lenders of a particular stablecoin is in LendingPool.sol, which is out of scope. However it is implied in the documentation of this repo that it is based on the balance of that asset the lender has provided. We have confirmed that in LendingPool.sol the yield is distributed based on the proportion of the asset provided. However, even ignoring this, MEV can still be used to unfairly hurt lenders of other stablecoins.

Proof of Concept

  1. An attacker watches the mempool for calls to distributeYield by the admin.
  2. The attacker orders the block’s transactions (most easily using a flashbots bundle) in the following order: i. Attacker deposits stablecoins to lend (ideally the stablecoin will be the one with the least volume). ii. admin’s call to distributeYield happens. iii. Attacker withdraws their deposit.

The attacker has thus made the asset they deposited (and thus themselves) receive much of the yield even though they provide no value to Sturdy since none of their deposit is ever borrowed so the never do anything to earn yield for sturdy. This attack can be done by a whale or by borrowing (even from sturdy) assets and converting them to a stablecoins accepted by sturdy before i. and returning them after iii. This will essentially be cost free for the attacker, none of their capital will ever be tied up by borrowers.

Recommended Mitigation Steps

The simplest way to mitigate this is for the admin to use flashbots or some other means of submitting the distributeYield call that skips the mempool. This is only a partial mitigation since attackers can still withdraw right after yield is distributed and get lucky by depositing soon before the distribution thus still capture more yield than they should have. A better mitigation could use something like snapshotting who has deposited since the last yield distribution and only give these depositers yield based on the size of their deposits the next time yield is distributed.

sforman2000 (Sturdy) confirmed and commented:

We will use flashbots and vary when/how often yield is harvested to mitigate this.

hickuphh3 (judge) decreased severity to Medium and commented:

I take reference to discussions on Discord and in a thread below: https://github.com/code-423n4/2022-03-biconomy-findings/issues/135

To quote from 0xleastwood: “Protocol leaked value in has a broad context but I think most judges can agree that it would pertain to rewards being paid out a lower rate than expected. Or, users can extract small amounts (up to debate on what is considered to be small) from the protocol under certain assumptions.”

Hence, as per the TLDR risk assessment: 2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.

I would downgrade this to a medium severity.


The original report as published on Code4rena, by mtz. 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 yield distribution is based on the current balance of deposits at the moment of distribution, without considering how long the deposit has been held.

Impact

The attacker could receive a large portion of the yield without providing a deposit that is borrowed, and other lenders may receive less yield.

What the attacker needed

Access to mempool; ability to order transactions (e.g., flashbots); large capital or borrowed funds

The fix

The admin should use flashbots or another method to submit the distributeYield call that skips the mempool, and ideally snapshot depositors since the last distribution to calculate yield based on deposit size over time.

How it was found

  1. Watch the mempool for calls to distributeYield by the admin.
  2. Order the block’s transactions (e.g., using a flashbots bundle) so that the attacker deposits stablecoins first.
  3. The admin’s call to distributeYield happens.
  4. The attacker withdraws their deposit.

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.

Yield is like interest paid to people who lend their cryptocurrency. The system pays out yield at certain times. An attacker can quickly add a large deposit just before the payout, collect a big share of the yield, and then take their deposit back right after. This means they get yield without really helping the system.

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 mtz

View all

1 more disclosed report, best first.

More from Sturdy 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.