Open code423n4 opened 1 year ago
An attacker may trick a user into calling exactInput with a malicious contract as a pool and steal user's funds
I wonder if this is the protocol's concern.
@hansfriese Protocols may have different concerns. This project submitted their code for audit, and our goal is to discover as many attack vectors as possible.
Btw, Uniswap is not exposed to this attack.
@Jeiwan Agree with you. At least the mitigation is clear. I was just curious.
@hansfriese In this specific case users have to trust a front end to build the path argument for them. Users never fill it manually or verify it before sending a transaction. And it's not realistic to ask them to do so because the path is a byte array containing pool addresses: it's not readable and users usually don't know which pools are legit and which ones are not (the contract must check this for them). So, yeah, it might seem like an attack vector that's outside of the protocol (like, forcing users to send their tokens to an attacker), but this subtle difference changes everything.
This is a dup of #97
Disagree. For this to be a problem, a user has to choose to call this function with a malicious pool as one of the inputs. There are many ways for a user to misuse a smart contract. This is analogous to inputing more tokens than the user intended to swap; ie, it is equivalent to a user error.
There are even use cases where a user values this feature because it lets them include a path that has a pool address from another protocol that implements the pool interface that the router expects.
If a frontend is compromised, this is the least of your worries. With a compromised frontend, the attacker can route a user to any contract.
gte620v marked the issue as sponsor disputed
With a compromised frontend, the attacker can route a user to any contract.
As long as contracts allow that. If we take Uniswap V3 as a reference, the Router contract won't allow to route a user through pools not created via the official Factory contract. So, the Stealth Project is vulnerable to this attack vector, while Uniswap V3 isn't.
The design choice to allow third parties to create and use their own Pool
in conjunction with Stealth Project Pools is a genuine use case which may make the mitigation invalid.
A malicious pool included in the path would allow for for draining funds for a user.
I consider this a valid Medium as there is an attack vector in the code however it should be protected against by the front-end only selecting the path from factory created pools.
kirk-baird changed the severity to 2 (Med Risk)
kirk-baird marked the issue as satisfactory
kirk-baird marked the issue as primary issue
kirk-baird marked the issue as selected for report
Lines of code
https://github.com/code-423n4/2022-12-Stealth-Project/blob/fc8589d7d8c1d8488fd97ccc46e1ff11c8426ac2/router-v1/contracts/Router.sol#L151 https://github.com/code-423n4/2022-12-Stealth-Project/blob/fc8589d7d8c1d8488fd97ccc46e1ff11c8426ac2/router-v1/contracts/Router.sol#L128
Vulnerability details
Impact
Users can lose funds during swapping.
Proof of Concept
The Router contract is a higher level contract that will be used by the majority of the users. The contract implements the
exactInput
functions that users call to perform multiple swaps in a single transaction. The key argument of the function is the path: an encoded list of "input token, pool address, output token" tuples that defines the series of swaps to be made by the function. On every iteration, theexactInput
function extracts next tuple from the path and calls the extracted pool address to perform a swap (Router.sol#L149-L154, Router.sol#L128):However, the pool address is not verified before being called. An attacker may trick a user into calling
exactInput
with a malicious contract as a pool and steal user's funds. Despite the requirement to force a user to sign a transaction, the difficulty of this attack is low for several reasons:An example of a malicious pool contract:
A coded proof of concept that demonstrates an attack using the above contract:
Tools Used
Manual review
Recommended Mitigation Steps
Consider always checking that pools being called in the Router were created through the Factory: