Canto - 3docSec's results

A layer-1 EVM powered by free public infrastructure.

General Information

Platform: Code4rena

Start Date: 20/06/2023

Pot Size: $36,500 USDC

Total HM: 2

Participants: 23

Period: 3 days

Judge: 0xean

Id: 252

League: ETH

Canto

Findings Distribution

Researcher Performance

Rank: 3/23

Findings: 2

Award: $3,407.64

QA:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

🌟 Selected for report: sces60107

Also found by: 3docSec, Franfran, Lirios, Team_FliBit, dontonka

Labels

bug
3 (High Risk)
satisfactory
sponsor confirmed
duplicate-36

Awards

3388.2784 USDC - $3,388.28

External Links

Lines of code

https://github.com/code-423n4/2023-06-canto/blob/a4ff2fd2e67e77e36528fad99f9d88149a5e8532/Canto/x/coinswap/types/params.go#L34

Vulnerability details

Impact

In the "coinswap" module a limit is in place for avoiding large swaps and their potential to manipulate the price in a low-liquidity scenario.

The spec says:

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.

The limit as stated in the spec is of $10~15 which is about 1% of the maximum liquidity allowed in CANTO (10,000 canto ~= $1,000). However, the ETH/Canto pool has a 0.1ETH ~= $150 swap limit that is 15x higher. This discrepancy, with the "0.01" mention in the spec, gives high confidence that the value in the code is not the intended one, and is an off-by-one error.

Proof of Concept

The following failing test case would pass if the amounts respected the spec:

package types import ( "github.com/stretchr/testify/assert" "testing" ) func TestDefaultParams(t *testing.T) { // 10 USDC (10 + 6 zeros) assert.Equal(t, 8, len(DefaultMaxSwapAmount.AmountOfNoDenomValidation(UsdcIBCDenom).String())) // 10 USDT (10 + 6 zeros) assert.Equal(t, 8, len(DefaultMaxSwapAmount.AmountOfNoDenomValidation(UsdcIBCDenom).String())) // 0.01 ETH (1 + (18-2=) 16 zeros) assert.Equal(t, 17, len(DefaultMaxSwapAmount.AmountOfNoDenomValidation(EthIBCDenom).String())) }

Tools Used

Visual inspection

Change params.go#L34 line to

sdk.NewCoin(EthIBCDenom, sdk.NewIntWithDecimal(1, 16)),

Assessed type

Decimal

#0 - c4-pre-sort

2023-06-24T12:12:07Z

JeffCX marked the issue as primary issue

#1 - JeffCX

2023-06-24T13:59:58Z

The report highlights a misconfiguration, the setting for ETH limit is 0.01 ETH while the current setting is 0.1 ETH, I believe the report worth sponsor's review

#2 - tkkwon1998

2023-06-28T16:04:26Z

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.

#3 - c4-sponsor

2023-06-28T16:04:32Z

tkkwon1998 marked the issue as sponsor confirmed

#4 - c4-judge

2023-06-30T20:41:57Z

0xean marked the issue as satisfactory

#5 - c4-judge

2023-07-03T21:08:23Z

0xean marked issue #36 as primary and marked this issue as a duplicate of 36

Findings Information

🌟 Selected for report: squeaky_cactus

Also found by: 3docSec, DevABDee, Rolezn, Shogoki, kaveyjoe, nadin, solsaver, vuquang23

Labels

bug
grade-b
QA (Quality Assurance)
Q-12

Awards

19.3584 USDC - $19.36

External Links

  • the swap limit MaxSwapAmount is easily circumvented: one could chain multiple types.MsgSwapOrder in the same transaction and achieve atomically the same result as swapping a larger amount with a single message

  • x/onboarding/keeper/ibc_callbacks.go function OnRecvPacket:

    • the onboarding function moves on with ERC20 conversion even if there are no coins left (transferredCoin - swappedAmount = 0). This can lead to sending 0 coins to the erc20 module for swapping, which is inconsistent with the erc20 module expectations (the MsgConvertCoin.validateBasic() would fail on zero amounts)

#0 - c4-judge

2023-07-02T01:27:41Z

0xean marked the issue as grade-c

#1 - c4-judge

2023-07-02T13:21:44Z

0xean marked the issue as grade-b

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter