-
Notifications
You must be signed in to change notification settings - Fork 4
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
Incorrect integration with UniswapRouter causes all swaps to revert. #42
Comments
0xleastwood marked the issue as primary issue |
0xleastwood marked the issue as selected for report |
Hi @0xleastwood, |
Hey @t0x1cC0de Thanks for pointing out to those reports of the Decent contest. This is why all the reports about not setting deadline were invalidated, including one I reported back then, because I also failed to point out the real problem, and, instead, I just mentioned the possible mev problem (which is totally incorrect)
@0xleastwood This is exactly what I said in my comment on issue #12 |
Thanks @stalinMacias for the explanation. I think code-423n4/2024-01-decent-findings#117 (and the analysis in 172) cite a different reason for invalidation. Thanks |
We are using SwapRouter02 instead of SwapRouter , on new deployments like Base the SwapRouter is not deployed anymore by uniswap team , so we decided to use this contract: to be compatible with all the deployments(Ethereum, Base, Optimism, Arbitrum,... ). We already tested integrations with production chains(Ethereum, Artbitrum) and everything looks to work fine. |
0xleastwood marked the issue as unsatisfactory: |
Lines of code
https://github.com/code-423n4/2024-05-bakerfi/blob/main/contracts/core/hooks/UseSwapper.sol#L67-L76
https://github.com/code-423n4/2024-05-bakerfi/blob/main/contracts/core/hooks/UseSwapper.sol#L84-L93
Vulnerability details
Impact
Core functions on the Strategy contract are impacted because the Strategy won't be able to do swaps caused an incorrect integration with the UniswapRouter.
Proof of Concept
The
UseSwapper._swap() function
makes use of the UniswapRouter when executing swaps. The problem is that the parameters that are passed to the UniswapRouter are missing thedeadline
parameter, on both types of swaps (EXACT_INPUT && EXACT_OUTPUT).EvmError: Revert
, which ultimately ends up reverting the whole tx.If we take a look at the code of the SwapRouter, we can notice that the
deadline
is a parameter that must be sent as part of the params when calling the exactInputSingle() or exactOutputSingle() functions.Coded PoC
I coded a PoC in Foundry to demonstrate the integration error, and show that the missing deadline parameter causes the tx to be reverted.
First of all, help me to create a new folder where we are going to create a couple of test files for this PoC. Create the new folder under the
tests
folderUseSwapper.sol
contract, and we just simply add some functions to allow us setting the address of the UniRouter that will be called when the _swap() is invoked. We also create a new function that executes the call to the SwapRouter in the correct way (without missing the deadline parameter)Before running the PoC, is required to change the visibility of the
uniRouter
variable in theUseSwapper.sol
contract. Update it tointernal
instead of privateOutput of running the PoC
UseSwapper._swap() function
ends up reverting.Tools Used
Manual Audit, Foundry & SwapRouter contract
Recommended Mitigation Steps
The mitigation for this integration error is to pass all the required parameters when calling the functions of the SwapRouter.
Specifically, update the parameters that are sent to the SwapRouter like this: (We are going to use the original ISwapRouter.ExactInputSingleParams to prevent any errors)
Also, make sure that the
UniRouter
variable is of the typeISwapRouter
(the same interface used by the UniswapRouter!), insteaf ofIV3SwapRouter
.Note: Make sure to have imported the correct
ISwapRouter
interfaceAssessed type
Uniswap
The text was updated successfully, but these errors were encountered: