Skip to content
Audit finding Advanced

OCL_ZVE.sol::forwardYield relies on manipulable Uniswap V2 pool reserves leading to theft of funds

The forwardYield function relies on Uniswap V2 pool reserves to calculate yield, which an attacker can manipulate to set the basis to a very small value. This allows the attacker to later call forwardYield and steal funds by distributing an inflated amount as yield.

0xpiken Follow with 0xvj, AllTooWell and 10 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-03-zivoe-judging/issues/296

The protocol has acknowledged this issue.

Found by

0xpiken, 0xvj, AllTooWell, Audinarey, DPS, Drynooo, JigglypuffAndPikachu, Maniacs, SilverChariot, cergyk, lemonmon, saidam017, t0x1c

Summary

OCL_ZVE.sol::forwardYield is used to forward yield in excess of the basis but it relies on Uniswap V2 pools that can be manipulable by an attacker to set basis to a very small amount and steal funds.

Vulnerability Detail

fetchBasis is a function which returns the amount of pairAsset (USDC) which is claimable by burning the balance of LP tokens of OCL_ZVE

fetchBasis is called first in forwardYield in order to determine the yield to distribute:

OCL_ZVE.sol#L301-L303

Solidity
>>    (uint256 amount, uint256 lp) = fetchBasis();
        if (amount > basis) { _forwardYield(amount, lp); }
        (basis,) = fetchBasis();

If the returned amount is <= basis (negative yield) no yield is forwarded and basis is updated to the low amount value

By manipulating the Uniswap V2 pool with a flashloan, an attacker can get the uint256 amount value to be returned by OCL_ZVE.sol::fetchBasis to be very small and set basis to this very small value:

OCL_ZVE.sol#L301-L303

Solidity
        if (amount > basis) { _forwardYield(amount, lp); }
>>      (basis,) = fetchBasis();

The next call (30 days later) to OCL_ZVE.sol::forwardYield will forward much more yield (in excess of basis) than it should, leading to a loss of funds for the protocol.

Scenario

  1. Attacker buys a very large amount of USDC in the Uniswap V2 pool ZVE/pairAsset (can use a flash-loan if needed)
  2. Attacker calls OCL_ZVE.sol::forwardYield
  • OCL_ZVE.sol::fetchBasis returns an incorrect and very small value for amount:
  • No yield is forwarded since amount < basis
  • OCL_ZVE.sol::forwardYield sets basis to amount
  1. Attacker backruns the calls to OCL_ZVE.sol::forwardYield with the sell of his large buy in the Uniswap V2 pool
  2. 30 days later, Attacker calls OCL_ZVE.sol::forwardYield and steal funds in excess of basis

Impact

Loss of funds for the protocol.

Code Snippet

Tool used

Manual Review

Recommendation

Consider reverting during a call to forwardYield if amount <= basis

Discussion

sherlock-admin2

1 comment(s) were left on this issue during the judging contest.

panprog commented:

medium, allows to distribute almost entire principal as if it's yield, leaving the locker with almost no funds. Since forwardYield will usually be called by keepers, who will use flashbots thus making frontrunning out of scope, this is medium. User can still call forwardYield but only if keeper didn't call it in the 12 hours prior to end of period, so this requires additional conditions.

panprog

Keeping this medium, because forwardYield can still be called by user in some circumstances, thus making the attack possible. Even though the distribution is within the protocol, it still distributes inflated amounts to tranches and/or residual recepients, causing accounting issues for the protocol.

panprog

Sponsor response:

it's protected by keeper calls for 12 hours prior and if not allows public accessibility, obviously mev-mitiation is implemented with front-running in mind and then allows public accessibility, intended functionality

panprog

It is still possible that user calls this with front-running, even though the probability is very low (keeper has to be down for 12 hours, there might be high network congestion for 12+ hours with keeper being unable to submit transaction due to high gas price etc). This is Medium by Sherlock rules (possible, but very low probability of happening).

spacegliderrrr

Escalate

According to Sherlock rules, admins (keepers in this case) are expected to behave properly and not miss their 12hrs window to call this function. Furthermore, this issue would require keepers to miss the 12hrs window 2 months in a row (as if it just happens only once, issue can be mitigated the following month). Issue should be low.

sherlock-admin3

Escalate

According to Sherlock rules, admins (keepers in this case) are expected to behave properly and not miss their 12hrs window to call this function. Furthermore, this issue would require keepers to miss the 12hrs window 2 months in a row (as if it just happens only once, issue can be mitigated the following month). Issue should be low.

You've created a valid escalation!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

ZdravkoHr

Why is it required that keepers don't call it 2 times?

spacegliderrrr

First time, it would simply not distribute yield (and set basis to very low value). Next month if keepers call it, they can adjust it so it distributes just the right amount.

If only 1 attack call is made, biggest impact is rolling over the yield for next month (but it is not lost in any way).

ZdravkoHr

Can't the amount be manipulated in the opposite direction instead to cause distribution on the first call?

panprog

The keeper might be down for factors outside of admin control, so I can't consider "calling within 12 hours" a proper keeper behaviour. The remark about 2 calls is incorrect: only 1 is enough. For example, current basis = 10. User manipulates basis to be 1. During the next distribution user doesn't have to manipulate it, normal distribution will happen with current basis = 10 (or whatever is current basis) and distribute most of the funds as if it's yield.

panprog

Can't the amount be manipulated in the opposite direction instead to cause distribution on the first call?

It's possible, but attacker will lose a lot of funds for such manipulation, so it's very costly to do so, reduction of basis is almost free for attacker, causing the same/bigger impact just later.

WangSecurity

Firstly, I agree that keeper is indeed may be down and miss the call to forwardYield. The probability is low, but as I understand, only one missed call by the keeper is enough for this scenario to occur, leading to a loss of funds for the protocol. Hence, I believe medium is appropriate.

Planning to reject the escalation and leave the issue as it is.

Evert0x

Result: Medium Has Duplicates

sherlock-admin4

Escalations have been resolved successfully!

Escalation status:

The original report as published on Sherlock, by 0xpiken. 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 protocol uses the current Uniswap V2 pool reserves to calculate the basis without any manipulation resistance, allowing an attacker to temporarily distort the reserves and set the basis to an artificially low value.

Impact

The protocol could lose funds because an attacker can cause an inflated yield distribution, but the attack requires the keeper to miss the 12-hour window for calling forwardYield, making it low probability.

What the attacker needed

Keeper misses 12-hour window; attacker can call forwardYield; access to flash loan

The fix

The protocol should revert during a call to forwardYield if amount <= basis.

How it was found

  1. Attacker buys a very large amount of USDC in the Uniswap V2 pool ZVE/pairAsset (can use a flash-loan if needed)
  2. Attacker calls OCL_ZVE.sol::forwardYield
  3. Attacker backruns the calls to OCL_ZVE.sol::forwardYield with the sell of his large buy in the Uniswap V2 pool
  4. 30 days later, Attacker calls OCL_ZVE.sol::forwardYield and steal funds in excess of basis

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.

The protocol uses a Uniswap pool to measure how much yield it has earned. An attacker can temporarily distort the pool's reserves so the measured yield appears tiny, which resets the protocol's baseline. Later, when the pool is normal again, the protocol thinks it has earned a huge profit and pays it out, but the money actually comes from the protocol's own funds.

More by 0xpiken

View all

29 more disclosed reports, best first.

More from Zivoe

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.