Open hats-bug-reporter[bot] opened 5 months ago
Units have a relationship to asset value that is not linear. However, in your example we can describe it.
Lets assume we have a pool of 2 vaults each with 1 asset each weighted 1. We actually don't have to make more assumptions, not even on the vault balance. We know the maxUnitCapacity for that vault, it will be ln(2)
. What is the value of ln(2)
units?
The equation used is out = balance * (1-exp(-U/W))
.
We know most of the values: out = balance * (1-exp(-ln(2)/1)) = balance * (1-0.5) = balance * 0.5
.
Okay, so when we receive maxUnitCapacity
on the target vault, exactly 50% of the balance will be bought. It doesn't matter how many number of assets are in the vault, 50% will always be bought.
Let do your case, first ln(2)/2 is bought and then ln(2) is bought.
Out1 = balance * (1-exp(-ln(2)/2/1)) = balance * (1-0.7) = balance * 0.3
(1 day later)
Out2 = balance*(1-0.3) * (1-exp(-ln(2)/1)) = balance * 0.7 * (1-0.5) = balance * 0.35
In total, 0,65% of the initial balance was bought, however it was over 2 days. We could actually have bought more since each day 50% of any balance is allowed to be bought.
Asterisk: In your case, the destination vault has 2 tokens. Then the maxUnitCapacity was twice what I used. How can we distribute that:
out = balance * (1-exp(-ln(2)*2/1)) = balance * 0.75
out = balance * (1-exp(-ln(2)*2/2/1)) = balance * 0.5
So you can choose between 75% of any 1 token or 50% of both tokens. In both cases, no more than 50% of the vault is withdraw.
Github username: @nuthan2x Twitter username: nuthan2x Submission hash (on-chain): 0x00c42f4be17fe6e4896942e5f0a7a8cb327133064f0cac094e7ff8aa2f494c9a Severity: high
Description: Description
Attack Scenario
_updateUnitCapacity
is called internally onreceiveAsset
when assets are moved crosschain. And it is called by chainInterface contract to release the liquidity or swap assets.Flow of tx
sendAssetFixedUnit
with 99% of MUC after waiting a day to decayunitCapacityReleased
>= MUC after a day, and now 99% being less than 100% of MUC this tx will pass.newUnitFlow
will be 150% > 100%, so after a day, it can be bypassed.Attachments
test/
folder and runforge t --mt testPOC_MUC -vvv