Duplication of Balance
The Cauldron contract's stir function caches balances before updating them, so a transfer to self incorrectly adds the transferred amount instead of leaving the balance unchanged. An attacker could duplicate any amount of ink or art, breaking the accounting system.
Yield Witch v2 contest
Originally disclosed on Code4rena
It is possible to duplicate currently held ink or art within a Cauldron, thereby breaking the contract’s accounting system and minting units out of thin air.
The stir function of the Cauldron, which can be invoked via a Ladle operation, caches balances in memory before decrementing and incrementing. As a result, if a transfer to self is performed, the assignment balances[to] = balancesTo will contain the added-to balance instead of the neutral balance.
This allows one to duplicate any number of ink or art units at will, thereby severely affecting the protocol’s integrity. A similar attack was exploited in the third bZx hack resulting in a roughly 8 million loss.
Recommend that a require check should be imposed prohibiting the from and to variables to be equivalent.
albertocuestacanada (Yield) confirmed:
It is a good finding and a scary one. It will be fixed. Duplicated with #7.
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 stir function caches balances in memory before decrementing and incrementing, causing a self-transfer to use the added-to balance instead of the neutral balance.
Impact
An attacker could duplicate any number of ink or art units, severely affecting the protocol's integrity.
What the attacker needed
Ability to call stir via Ladle
The fix
A require check should be added to prohibit the from and to variables from being equivalent.
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 smart contract keeps track of who owns what. When you transfer tokens to yourself, the balance should stay the same. But here, the code accidentally adds the amount again, so you end up with more tokens than you started with.
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.