Skip to content
Business logic Audit finding Intermediate

unsponsor, claimYield and withdraw might fail unexpectedly

The vault's totalUnderlying() figure counts assets that have been invested and are not held in the contract balance, so withdrawals, yield claims and unsponsoring can try to transfer more than the contract actually holds. A forced unsponsor would always fail for this reason, and in stressed conditions users could be unable to retrieve funds.

danb Follow

Originally disclosed on Code4rena

Submitted by danb, also found by ACai, cmichel, harleythedog, leastwood, palina, pedroais, and WatchPug

totalUnderlying() includes the invested assets, they are not in the contract balance.

when a user calls withdraw, claimYield or unsponsor, the system might not have enough assets in the balance and the transfer would fail.

especially, force unsponsor will always fail, because it tries to transfer the entire totalUnderlying(), which the system doesn’t have:

https://github.com/code-423n4/2022-01-sandclock/blob/main/sandclock/contracts/Vault.sol#L391

Recommended Mitigation Steps

when the system doesn’t have enough balance to make the transfer, withdraw from the strategy.

gabrielpoca (Sandclock) confirmed:

I’m not sure this is an issue. We are aware of it, and redeeming from the strategy won’t fix it because it is asynchronous. This is why we have an investment percentage.

dmvt (judge) changed severity and commented:

This one is a hard issue to size, but I’m going to go with the medium risk rating provided by other wardens reporting this issue. This seems to amount to a bank run like issue similar to what can happen with DeFi lending protocols.

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.

If the invested assets are compromised or locked, this could result in a loss of funds. Users of the protocol should be made aware of the risk. This risk exists with many DeFi protocols and probably shouldn’t be a surprise to most users.

The original report as published on Code4rena, by danb. 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 contract treats the total of held plus invested assets as spendable balance, without first pulling funds back from the strategy before transferring.

Impact

Withdrawals, yield claims and unsponsoring could fail when invested assets are not in the contract balance, and a forced unsponsor would always fail; the judge rated this a medium-risk availability issue resembling a bank run, with possible loss of funds if invested assets are locked or compromised.

What the attacker needed

Assets invested in the strategy; contract balance below amount owed

The fix

The reporter suggested withdrawing from the strategy when the balance is short, but the project said redeeming from the strategy is asynchronous and would not fix it, pointing to the investment percentage instead.

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 vault is a contract that holds other people's money. This one lends part of that money out to earn interest, so the contract's own balance is smaller than the total it reports. When someone asks to take money out, the contract may try to send more than it currently has, and the transfer simply fails.

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 danb

View all

12 more disclosed reports, best first.

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