Skip to content
Business logic Audit finding Intermediate

Witch can’t give back vault after 2x grab

The Witch contract overwrites the stored original vault owner when a second grab occurs, so after the debt is sold the vault cannot be returned to the original owner. An attacker could exploit this to prevent the original owner from recovering their vault.

Yield Witch v2 contest

Originally disclosed on Code4rena

The witch.sol contract gets access to a vault via the grab function in case of liquidation. If the witch.sol contract can’t sell the debt within a certain amount of time, a second grab can occur.

After the second grab, the information of the original owner of the vault is lost, and the vault can’t be returned to the original owner once the debt has been sold.

The grab function stores the previous owner in vaultOwners[vaultId], and then the contract itself is the new owner (via cauldron.grab and cauldron._give). The vaultOwners[vaultId] is overwritten at the second grab

The function buy of Witch.sol tried to give the vault back to the original owner, which won’t succeed after a second grab. See the issue page for proof of concept and referenced code

Assuming it’s useful to give back the vault to the original owner, recommend making a stack/array of previous owners if multiple instances of the witch.sol contract would be used. Or, check if the witch is already the owner (in the grab function) and keep thevaultOwners[vaultId] if that is the case.

albertocuestacanada (Yield) confirmed:

This is a good finding and a vulnerability that we will fix. I anticipate that we will store the original owner in Cauldron.auctions along with the time at which the auction was started.

albertocuestacanada (Yield) commented:

Actually, we might remove some overengineering by taking out the feature of allowing multiple competing liquidation engines.

That would allow us to:

  1. Move the auctions mapping to the Witch.
  2. Remove the auctionInterval setting
  3. Simplify grab
  4. Stop worrying about more than one grab.

Editors note: An alternative submission for this bug was not included in this report but can be found in Issue #30.

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

The grab function overwrites the stored original owner each time it is called, so a second grab loses the first owner's information.

Impact

The original vault owner cannot get their vault back after a second grab, potentially causing permanent loss of the vault.

What the attacker needed

Multiple liquidation engines; second grab occurs

The fix

The project confirmed they will fix it, likely by storing the original owner in Cauldron.auctions along with the auction start time, or by checking if the witch is already the owner and keeping the existing vaultOwners entry.

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 a lending system, if a borrower fails to repay, a liquidator can take over their vault to sell the debt. This report found that if the liquidation process happens twice, the system forgets who originally owned the vault, so it can never be given back. That means the original owner loses their vault permanently, even if they should have been able to recover it.

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 from Yield Witch v2 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.