Pre-defined limit is different from the spec
The smart contract's swap limit for ETH was set to 0.1 ETH instead of the specified 0.01 ETH, allowing swaps up to ten times larger than intended. An attacker could exploit this to manipulate pools and cause larger losses than the risk management intended.
sces60107 Follow with Franfran, Team_FliBit and 3 others
Originally disclosed on Code4rena
Submitted by sces60107, also found by Franfran, Team_FliBit, dontonka, Lirios, and 3docSec
https://github.com/code-423n4/2023-06-canto/blob/main/Canto/x/coinswap/keeper/swap.go#L212 https://github.com/code-423n4/2023-06-canto/blob/main/Canto/x/coinswap/types/params.go#L34
Impact
In the spec, the pre-defined limit of ETH is 0.01 ETHs. But the actual limit in the code is not 0.01 ETH which could result in misleading.
Proof of Concept
In the spec, it said that the pre-defined limit of ETH is 0.01 ETHs. https://github.com/code-423n4/2023-06-canto/blob/main/README.md#swap
For risk management purposes, a swap will fail if the input coin amount exceeds a pre-defined limit (10 USDC, 10 USDT, 0.01 ETH) or if the swap amount limit is not defined.
But in x/coinswap/types/params.go, the actual limit of ETH is 1*10e17 which is 0.1 ETH.
// Parameter store keys
var (
KeyFee = []byte("Fee") // fee key
KeyPoolCreationFee = []byte("PoolCreationFee") // fee key
KeyTaxRate = []byte("TaxRate") // fee key
KeyStandardDenom = []byte("StandardDenom") // standard token denom key
KeyMaxStandardCoinPerPool = []byte("MaxStandardCoinPerPool") // max standard coin amount per pool
KeyMaxSwapAmount = []byte("MaxSwapAmount") // whitelisted denoms
DefaultFee = sdk.NewDecWithPrec(0, 0)
DefaultPoolCreationFee = sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)
DefaultTaxRate = sdk.NewDecWithPrec(0, 0)
DefaultMaxStandardCoinPerPool = sdk.NewIntWithDecimal(10000, 18)
DefaultMaxSwapAmount = sdk.NewCoins(
sdk.NewCoin(UsdcIBCDenom, sdk.NewIntWithDecimal(10, 6)),
sdk.NewCoin(UsdtIBCDenom, sdk.NewIntWithDecimal(10, 6)),
sdk.NewCoin(EthIBCDenom, sdk.NewIntWithDecimal(1, 17)),
)
)
The limit is used in swap.GetMaximumSwapAmount. Wrong could harm the risk management.
https://github.com/code-423n4/2023-06-canto/blob/main/Canto/x/coinswap/keeper/swap.go#L212
func (k Keeper) GetMaximumSwapAmount(ctx sdk.Context, denom string) (sdk.Coin, error) {
params := k.GetParams(ctx)
for _, coin := range params.MaxSwapAmount {
if coin.Denom == denom {
return coin, nil
}
}
return sdk.Coin{}, sdkerrors.Wrap(types.ErrInvalidDenom, fmt.Sprintf("invalid denom: %s, denom is not whitelisted", denom))
}
Recommended Mitigation Steps
0.01 ETH should be sdk.NewIntWithDecimal(1, 16).
Assessed type
Error
0xean (judge) increased severity to High
tkkwon1998 (Canto) confirmed and commented on duplicate issue 8:
Agreed, this issue is valid as limit is 10x higher than it should be. Although losses are still minimal (0.1 eth at most), I agree with high risk since funds can be lost if pools are manipulated.
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 parameter for the maximum swap amount of ETH was set to 1×10^17 (0.1 ETH) instead of the intended 1×10^16 (0.01 ETH).
Impact
The higher limit could allow an attacker to manipulate pools and cause losses up to 0.1 ETH, which is ten times the intended maximum.
What the attacker needed
None
The fix
The limit should be changed to 1×10^16 (0.01 ETH) to match the specification.
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.
This is a smart contract for swapping tokens. The developers said that swaps larger than 0.01 ETH should be blocked to limit risk, but the code actually allowed swaps up to 0.1 ETH. That means someone could swap a larger amount than intended, potentially causing more damage if they manipulate the pool.
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.