[M04] Missing check for input=output in stableswap math #88
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
insufficient quality report
This report is not of sufficient quality
unsatisfactory
does not satisfy C4 submission criteria; not eligible for awards
Lines of code
https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/pallets/stableswap/src/lib.rs#L787-L842
Vulnerability details
Impact
In curve protocol, there is a check that
idx_in != idx_out
here. This is there to prevent swapping of the same token with itself.The stableswap protocol however is missing this check. This can potentially allow users to swap the same token for itself. This can break the math of the stableswap protocol, and potentially lead to wrong balances.
This check is not present in the
buy
function, and in thecalculate_in_amount
function, the only checks are on the individual tokens.Proof of Concept
The check is missing in the code.
Tools Used
Manual Review
Recommended Mitigation Steps
Add in a check to ensure idx_in != idx_out
Assessed type
Invalid Validation
The text was updated successfully, but these errors were encountered: