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

Lack of protection on swaps #9

Open
robertleifke opened this issue Jun 29, 2024 · 1 comment
Open

Lack of protection on swaps #9

robertleifke opened this issue Jun 29, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@robertleifke
Copy link
Member

Description:

The swap method of the SwapHelper library does not accept user-provided limits or query an external oracle to prevent front-running sandwich attacks. The SwapRouter contract uses the SwapHelper library to facilitate pre-deposit and post-withdrawal asset exchanges. The function signature and data types associated with this library’s swap method, shown in figure 8.1, indicate that this method accepts a signed integer amount parameter that is either the exact input or exact output, depending on whether this value is positive or negative.

However, this function does not accept user-specified maximum amounts. To safely execute an exact-in or exact-out swap, the minimum amount out or maximum amount in should be enforced, respectively.
Furthermore, no uncorrelated oracle is consulted to enforce such limits.

The Uniswap market itself is queried to determine the expected input or output amounts, but this query is not sufficient to detect whether the market was manipulated during a preceding transaction. Outside information is required to detect such market manipulation.

@robertleifke robertleifke added the enhancement New feature or request label Jun 29, 2024
@robertleifke robertleifke added this to the Review #2 milestone Jun 29, 2024
@robertleifke robertleifke self-assigned this Jun 29, 2024
@robertleifke
Copy link
Member Author

Recommendations:

Short term, modify the code to either consult user-provided input or an uncorrelated oracle to detect market manipulation and revert if the user would receive an unacceptable exchange rate.

Long term, exercise caution when implementing low-level third-party protocol interactions. If Numo2 intends to bypass high-level routers, ensure all safety mechanisms implemented by such routers are fully understood, and address these risks in the Numo2 implementation. Consider using a higher-level interface if possible. Regardless, always consult the documentation for third-party protocol integrations to ensure that best practices are being followed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant