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

Reentrancy risk of the function _handleSwap() #3

Open
shuo-young opened this issue Feb 23, 2024 · 0 comments
Open

Reentrancy risk of the function _handleSwap() #3

shuo-young opened this issue Feb 23, 2024 · 0 comments

Comments

@shuo-young
Copy link

A potential risk lies in the _handleSwap function, which could be reentered by malicious token that implements reentrancy logic to call _handleSwap again. Below shows the possible attack chain.

  1. Attacker initializes a malicious pool with registered malicious tokens. A reentancy logic is implemented in the transfer function, which will be invoked in the _handleSwap function (line 281).
  2. Bind the malicious pool with the pool manager and the TakeProfitsHook.
  3. Attacker prepares the attack by placing order.
  4. Attacker begins to swap for the malicious token in the malicious pool to invoke _handleSwap.
  5. transfer() function of malicious token is invoked to reenter into the _handleSwap again to swap any tokens of the pools existing in the pool manager (line 275).

There are two main issues lie in the _handleSwap function. (1) There is no access control when performing poolManager.swap() by the parameter key and params, which can be inputted by anyone in this external function. (2) The transfer function of currenry0 could be malicious.

So there maybe some problems when uni v4 enables any one register pools and tokens. To avoid potential vulnerabilities, some protection should added, for example, access control and reentrancyguard modifier. Thanks for your watch and happy to stay in touch.

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

No branches or pull requests

1 participant