Open hats-bug-reporter[bot] opened 4 months ago
We had a hard time deciding on this. Here is our reasoning: In general the modification of the virtual supply is by design. Introducing a virtual supply opens up the whole design space for experimenting with the BC, which is what the BCRG wants. This however could introduce unwanted behaviour which is assumed the one pulling the leavers is aware off. The example you brought up is really extreme and quite an edgecase. The virtual Supply you set was 100x the original funds which has quite an impact on the math here. But you are right even if the SetVirtual Amount isnt as high its still highly abusable. In general the addition of the Virtual Supply functionality is seen by us as a feature that should allow for experimentation, but shouldnt be used in a typical BondingCurve usecase. That means we have a High Impact and a Low Recurrence, which would bring this to a Medium find.
Github username: @0xfuje Twitter username: 0xfuje Submission hash (on-chain): 0xbc05ca83aef5a2599fc1c89743a3e255bea8562a89d7a7b6a579cdbd9367cb96 Severity: high
Description:
Impact
Potential total loss of collateral funds in
BondingCurve
FundingManager
.Description
The problem is that the
FundingManager
's balance does not necessarily reflect it's virtualcollateral
andissuance
supply. When these values are changed without organicbuy
andsell
orders viasetVirtualCollateralSupply()
orsetVirtualIssuanceSupply()
, the total amount of change can be sandwiched risk-free by an attacker.FM_BC_Bancor_Redeeming_VirtualSupply_v1
-setVirtualCollateralSupply()
Attack scenario
This is just a specific scenario, the issue affects
setVirtualIssuanceSupply
as well and is meant to be a general submission for sandwich attacks regarding owner set virtual supply changes.issuance
tokens viabuyOrders
up to100e18
ofcollateral
tokens100e18
10000e18
viasetVirtualCollateralSupply
(e.g. plans to manually transfer those tokens after this TX so payment based modules can have enough funds to take fromFM
)setVirtualCollateralSupply
with a minimal amount of1.1e18
buyOrder()
, note that this will be worth substantially more after the new collateral supply has been setissuance
tokens, which will empty theFundingManager
almost completelyFor practical numbers with an example of
BNB
:FundingManager
:100
BNB
-$58000
with current prices1.1
BNB
-$640
101.1
BNB
-$58756
- only the dust amount due to rounding will remain in theFM
contractNote that the final profitability is affected by the measure of virtual supply change but the attacker will always gain back all of their spent capital + change profitability. This is the same scenario as in the coded proof of concept.
Proof of Concept - Coded
FM_BC_Bancor_Redeeming_VirtualSupplyV1Test.t.sol
run with
forge test --mc FM_BC_Bancor_Redeeming_VirtualSupplyV1Test --mt testSupplyChange_Sandwich -vvvv
Recommendation
Recommendation and additional commentary about the issue will be added in comments.