Assessment reports>Initia>High findings>Stablepool swap can be called, repeating the same asset
Category: Coding Mistakes

Stablepool swap can be called, repeating the same asset

High Severity
Informational Impact
Low Likelihood

Description

The stableswap.move module implements an AMM based on the Curve StableSwap price function.

The swap function can be used to perform a swap between assets contained in the pool:

public fun swap(
    pair: Object<Pool>,
    offer_coin: FungibleAsset, 
    return_coin_metadata: Object<Metadata>, 
    min_return_amount: Option<u64>
): FungibleAsset acquires Pool

The function reverts if offer_coin or return_coin_metadata are not assets contained in the pool. However, it does not require offer_coin and return_coin_metadata to refer to two different assets.

Impact

This issue is reported as informational as we were unable to circumvent an unintentional revert due to an underflow in one of the helper functions called to perform the swap calculations, get_y. However, other third-party modules that rely on the AMM may be impacted to a greater extent, even by a denial-of-service condition. Considering the importance of the AMM modules on the ecosystem and the potential — even if undetermined — impact on third-party modules, we classify this issue as high severity.

Recommendations

Require the input and output assets in a swap to differ from each other.

Remediation

Zellic © 2024Back to top ↑