BasePool.swap() Is Callable By Anyone
The BasePool.swap() function lacks an onlyRouter modifier, allowing anyone to call it directly and bypass the input validation performed by VaderRouter._swap(). An attacker could potentially exploit this to perform swaps without the necessary checks.
Submitted by leastwood
Impact
The BasePool.swap() function differs from its implementation in BasePoolV2.swap() in which it lacks an onlyRouter modifier. This ensures that users cannot call this function directly as VaderRouter._swap() performs some necessary input validation which can be bypassed by directly calling BasePool.swap().
Proof of Concept
- https://github.com/code-423n4/2021-11-vader/blob/main/contracts/dex/router/VaderRouter.sol#L304-L351
- https://github.com/code-423n4/2021-11-vader/blob/main/contracts/dex/pool/BasePool.sol#L289-L379
- https://github.com/code-423n4/2021-11-vader/blob/main/contracts/dex/pool/BasePool.sol#L261-L268
Tools Used
Manual code review.
Recommended Mitigation Steps
Consider adding an onlyRouter modifier to the BasePool.swap() functions to ensure users cannot directly call these functions.
The pool contracts, similarly to Uniswap V2, are never meant to be interacted with directly.
That’s what the modifier would do.
@alcueca They are never meant however it should still be possible to do so. With Uniswap V2, it is possible to interact with the contracts directly however doing so (without using a smart contract) will result in the same vulnerabilities as described in the issue. This is not intended usage and as such does not constitute an issue unless it is implied that the Uniswap V2 implementation is incorrect.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the BasePool.swap() function was not protected with an onlyRouter modifier, unlike BasePoolV2.swap(), so it can be called by any address.
Impact
An attacker could call BasePool.swap() directly, bypassing the router's input validation, though the project disputed that this constitutes a vulnerability because direct interaction is possible in Uniswap V2 as well.
What the attacker needed
None
The fix
The function should be fixed by adding an onlyRouter modifier to BasePool.swap() to prevent direct calls.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In a decentralised exchange, a router contract normally checks that a swap request is valid before passing it to a pool contract. Here, the pool contract can be called directly, skipping those checks. This means someone could interact with the pool in ways the developers did not intend.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.