Open hats-bug-reporter[bot] opened 1 month ago
So, basically all the following contracts:
|-- StableSwapLP.sol
|-- StableSwapLPFactory.sol
|-- StableSwapThreePoolDeployer.sol
|-- StableSwapTwoPoolDeployer.sol
No check in the token lenght. So, please add the proper require:
require(token.code.length > 0, "Invalid token");
Github username: @catellaTech Twitter username: catellatech Submission hash (on-chain): 0x51dfd7962bb30986e963847f3a33ba0513a2c950db36b8ca922659b5e5fc6427 Severity: high
Description:
Issue Description
A critical vulnerability has been identified in the StableSwapRouter and StableSwapFactory contracts. These contracts fail to validate whether the addresses provided for token operations correspond to actual token contracts. This oversight allows the creation of swap pairs and the execution of swaps involving invalid token addresses, potentially leading to loss of funds, contract state corruption, or other unexpected behaviors.
Severity: High
Impact: This vulnerability could result in:
Proof of Concept (PoC)
The following test case demonstrates the vulnerability:
--- Starting Invalid Token Address Vulnerability Test --- Valid token deployed at: 0x212224D2F2d262cd093eE13240ca4873fcCBbA3C Invalid token address (EOA): 0x0000000000000000000000000000000000001234 Attempting to create a pool with invalid token... Pool creation attempt completed Approved router to spend 1000 of valid token Attempting swap with invalid token... Swap attempt completed Balance of valid token after attempted swap: 1000000 Attempting to get input swap amount for invalid pair... getInputStableSwap attempt completed Attempting to get output swap amount for invalid pair... getOutputStableSwap attempt completed --- Invalid Token Address Vulnerability Test Completed ---
createSwapPair
,exactInputStableSwap
, and others to use theisValidToken
check:path
array are valid tokens. check the token lenght of the path.By implementing these mitigations, the contracts will be better protected against invalid token addresses, significantly reducing the risk of unexpected behaviors and potential loss of funds.