coinswap pool can be DoS #6
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-28
🤖_02_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-05-canto/blob/d1d51b2293d4689f467b8b1c82bba84f8f7ea008/canto-main/x/coinswap/keeper/keeper.go#L168
Vulnerability details
Impact
DoS attack makes functions in coinswap unusable
Proof of Concept
In general, if anyone is running in the array and an attacker adds a large number of elements to the array, it will consume a large amount of gas while traversing the array, and the related function will fail to execute due to insufficient gas.
The
AddLiquidity
RemoveLiquidity
calculateWithExactInput
incoinswap
will passk.GetPoolBalances
The banlance of all tokens in the pool.k.GetPoolBalances -> k.bk.GetAllBalances
Let's take a look at
bk.GetAllBalances
, which iterate through the balance(IterateAccountBalances) of all tokens in the pool and then add them to an array and sort them.https://github.com/cosmos/cosmos-sdk/blob/d21620d1280538ddb1129af4979d62878850ff99/x/bank/keeper/view.go#L99
sdk.NewCoins() returns Coins, Coins is an array:
https://github.com/cosmos/cosmos-sdk/blob/d21620d1280538ddb1129af4979d62878850ff99/types/coin.go#L191
When
AddLiquidity
is in the coinswap module,k.CreatePool
is called to create a pool if the pool does not exist,An attacker can create a large number of tokens with
AddLiquidity
(or perhaps in other ways)and then send the balance to the target pool to be attacked.
When other users call functions in
coinswap
, the execution fails because the number of balances arrays returned by GetPoolBalances is too large, consumes too much gas, or the transaction execution failed because of insufficient gas.Tools Used
vscode, manual
Recommended Mitigation Steps
Do not use
bk.GetAllBalances
to obtain the balances of all tokens, but only the balances of one token in the pool at a time.Assessed type
DoS
The text was updated successfully, but these errors were encountered: