-
Notifications
You must be signed in to change notification settings - Fork 0
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
Donating 1 Unit of Tokens to a New Pool Could Block Users from Adding Liquidity #148
Comments
0xRobocop marked the issue as primary issue |
0xRobocop marked the issue as sufficient quality report |
0xRobocop marked the issue as high quality report |
enthusiastmartin (sponsor) confirmed |
enthusiastmartin marked the issue as disagree with severity |
This might be an issue but we disagree with severity. The creation of pool is not permissionless and it is always batched together with add_liquidity to provide initial liquidity. |
While the creation is not permissionless and should be batched together with |
OpenCoreCH marked the issue as selected for report |
this DoS state can simply be mitigated by donating a minimum non-zero amount of the assets that have zero reserves , because the condition of this attack is to have at least one reserve to be zero ,and the rest of reserves of the other assets in the pool are non-zero reserves , this action will allow liquidity addition again , with almost tiny cost and without any permissioned calls . |
After reconsideration of the issue, the impact in the worst case is indeed only a DoS that is very easily recoverable (and is very improbable). So this is comparable with e.g. frontrunning of initializers (where redeployment is the solution), which historically have been considered QA. |
OpenCoreCH changed the severity to QA (Quality Assurance) |
OpenCoreCH marked the issue as grade-b |
OpenCoreCH marked the issue as not selected for report |
Lines of code
https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/pallets/stableswap/src/lib.rs#L1053-L1059
Vulnerability details
Impact
When adding a new pool, an attacker could donate 1_u128 tokens to the pool account (this attack would work also by donating 1 token to a max of (n-1) Token in a pool of n tokens)
after having this condition met, each subsequent
add_liquidity()
call for this new created pool would revert with an arithmetic overflow error.The attacker could use this bug to block users from adding liquidity to the pool, and costing them transactions fees.
Proof of Concept
By donating at least 1 unit of a token to the pool account and leaving at least a token uninitialized, in
do_add_liquidity()
the arrayinitial_reserves
would contain at least a zero amount. For a new pool of asset_a and asset_b after donating 1 unit to asset_b theinitial_reserves
would look like thisThis array would be supplied to
hydra_dx_math::stableswap::calculate_shares()
(source)The inital_reserves array would then be handled in the function
calculate_d()
(source)
Which would then throw an error, because the initial_reserves contain a zero amount.
To run the Proof of Concept add the following code to
pallets/stableswap/src/tests/add_liquidity.rs
Tools Used
Manual Review, Substrate
Recommended Mitigation Steps
To prevent this attack vector, it is recomended to either donate a small amount of each tokens to the newly created pool, to make sure that the transaction wouldn't revert, or to adjust the logic in
do_add_liquidity
to remove zero amounts from theinitial_reserves
array.Assessed type
DoS
The text was updated successfully, but these errors were encountered: