Open hats-bug-reporter[bot] opened 2 days ago
The team says that the router doesn't receive funds, but it does consider the contract's funds in the swap logic. Additionally, my PoC basically shows that other possible scenarios are not taken into account in the logic. For example, my PoC demonstrates that the swap shouldn't send more tokens than the user has approved, and it also doesn't verify if the swapped amount matches the amount out.
If the team wants to test my proof, please contact me on Discord so I can provide the full setUp.
@Ghoulouis duplicate of what issue?
But if you read my report is a different, because, my PoC doesn't had the amount to swap exact as the fuction requiere to drain the protocol. Is much more less so the logic still bad to manage the exact amount that the person or user requires. Also de report 22 doesnt add PoC.
Github username: @catellaTech Twitter username: catellatech Submission hash (on-chain): 0xd160e3e72ff8f3ff38dc2097cfdc40f2c21dc1d6e193ff3f0873775321056d49 Severity: high
Description:
Overview
After further analysis and consideration of the test results, we've identified a more fundamental issue in the
exactInputStableSwap
function of the StableSwapRouter contract. The problem is not related to theConstants.CONTRACT_BALANCE
as initially thought, but rather to how the contract manages and attributes funds to individual callers.Root Cause
The core of the vulnerability lies in the contract's failure to properly track and manage funds on a per-user basis. Instead, it incorrectly assumes that the entire balance of the contract belongs to the current caller of the
exactInputStableSwap
function.Key problematic code:
This code sets
amountIn
to the entire balance of the contract for the given token, regardless of how much the caller actually intended to swap or has rights to.Vulnerability Details
Attack Scenario
exactInputStableSwap
with a smallamountIn
.Test Results Analysis
Reviewing the test
testStealFundsAttackOnSwap
:PoC:
Key log output:
This confirms that the contract is using its entire balance for the swap, not just the amount the user specified.
Impact
Recommendations
Implement Strict User Accounting: Keep track of user deposits and only allow users to swap their own funds.
Remove Direct Balance Usage: Eliminate any code that uses the contract's entire balance for operations. Always use specific amounts provided by or accounted for each user.
Comprehensive Testing: Develop and run extensive test suites that cover various scenarios, including potential attack vectors.
Notes
The vulnerability in the StableSwapRouter contract is more fundamental than initially assessed. It stems from a lack of proper fund management and accounting on a per-user basis. This issue allows users to swap more tokens than they should be able to, potentially leading to significant financial losses and market disruptions.
Implementing strict user-based accounting, removing direct contract balance usage, and adding proper deposit and withdrawal functions are crucial steps in addressing this vulnerability. After implementing these changes, a thorough security audit and extensive testing are essential to ensure the contract's integrity and security.
The PoC proves that the attack can be very profitable with a minimal amount of capital, and demonstrates that in scenarios where the function's logic is not properly accounted for, someone could take advantage.