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

MinTradingLimit check can be bypassed in do_add_liquidity_shares() #138

Open
c4-bot-6 opened this issue Feb 29, 2024 · 9 comments
Open

MinTradingLimit check can be bypassed in do_add_liquidity_shares() #138

c4-bot-6 opened this issue Feb 29, 2024 · 9 comments
Labels
bug Something isn't working disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) downgraded by judge Judge downgraded the risk level of this issue grade-a primary issue Highest quality submission among a set of duplicates QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_23_group AI based duplicate group recommendation sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") sufficient quality report This report is of sufficient quality

Comments

@c4-bot-6
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2024-02-hydradx/blob/main/HydraDX-node/pallets/stableswap/src/lib.rs#L1082-L1135
https://github.com/code-423n4/2024-02-hydradx/blob/main/HydraDX-node/pallets/stableswap/src/lib.rs#L1008-L1011
https://github.com/code-423n4/2024-02-hydradx/blob/main/HydraDX-node/pallets/stableswap/src/lib.rs#L155-L157

Vulnerability details

Impact

An important check(MinTradingLimit) can be bypassed.

Proof of Concept

The function do_add_liquidity_shares() allow a liquidity provider to add liquidity to a selected pool and receive a precise amount of shares in return. The difference between this function and do_add_liquidity() is that do_add_liquidity_shares() user can specify exact amount of shares to receive.

But do_add_liquidity_shares() missing MinTradingLimit check:

        /// Minimum trading amount
        #[pallet::constant]
        type MinTradingLimit: Get<Balance>;

We can see that this check has it in do_add_liquidity():

1008:        ensure!(
1009:           asset.amount >= T::MinTradingLimit::get(), 
1010:           Error::<T>::InsufficientTradingAmount
1011:            );

But this check completely misses in do_add_liquidity_shares(). This allows a user to bypass this important check and add liquidity below the minimum asset amount allowed by the protocol.

Tools Used

Visual Studio Code

Recommended Mitigation Steps

Add a check for MinTradingLimit as you do in do_add_liquidity().

Assessed type

Invalid Validation

@c4-bot-6 c4-bot-6 added 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 labels Feb 29, 2024
c4-bot-8 added a commit that referenced this issue Feb 29, 2024
@c4-bot-12 c4-bot-12 added the 🤖_23_group AI based duplicate group recommendation label Mar 1, 2024
@0xRobocop
Copy link

There is a check for a minimum amount of shares. Leaving for sponsor review.

@c4-pre-sort
Copy link

0xRobocop marked the issue as sufficient quality report

@c4-pre-sort c4-pre-sort added the sufficient quality report This report is of sufficient quality label Mar 3, 2024
@c4-pre-sort
Copy link

0xRobocop marked the issue as primary issue

@c4-pre-sort c4-pre-sort added the primary issue Highest quality submission among a set of duplicates label Mar 3, 2024
@c4-sponsor c4-sponsor added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Mar 6, 2024
@c4-sponsor
Copy link

enthusiastmartin (sponsor) confirmed

@c4-sponsor
Copy link

enthusiastmartin marked the issue as disagree with severity

@c4-sponsor c4-sponsor added the disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) label Mar 6, 2024
@enthusiastmartin
Copy link

MinTradingLimit is there to protect users due to rounding issues..

It is not any risk to protocol. Definitely not Medium.

@OpenCoreCH
Copy link

This would require an active user mistake that would not hurt the protocol in any way. As per the SC verdict "conditional on user mistake", downgrading to QA

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Mar 7, 2024
@c4-judge
Copy link

c4-judge commented Mar 7, 2024

OpenCoreCH changed the severity to QA (Quality Assurance)

@c4-judge
Copy link

c4-judge commented Mar 9, 2024

OpenCoreCH marked the issue as grade-b

@C4-Staff C4-Staff added grade-a and removed grade-b labels Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) downgraded by judge Judge downgraded the risk level of this issue grade-a primary issue Highest quality submission among a set of duplicates QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_23_group AI based duplicate group recommendation sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") sufficient quality report This report is of sufficient quality
Projects
None yet
Development

No branches or pull requests

9 participants