Incorrect Struct Field and Hardcoded sqrtPriceLimitX96 in _getQuoteAndDirection
The _getQuoteAndDirection function uses an incorrect struct field name (amountIn instead of amount) and hardcodes sqrtPriceLimitX96 to zero, which could cause runtime failure and allow swaps at prices beyond expected limits.
Submitted by Daniel526
The absence of a properly set sqrtPriceLimitX96 allows swaps to execute at prices far beyond expected limits, exposing the contract to unfavorable trade outcomes. The function is also likely to fail at runtime due to a mismatch in struct field names (amountIn instead of amount).
Proof of Concept
In the _getQuoteAndDirection function, the amountIn parameter is incorrectly used for constructing the QuoteExactInputSingleWithPoolParams struct. Additionally, the sqrtPriceLimitX96 parameter is hardcoded to 0, potentially leading to unintended behavior in price-constrained swaps.
IQuoter.QuoteExactInputSingleWithPoolParams({
tokenIn: tokenIn,
tokenOut: tokenOut,
amountIn: amountIn, // Incorrect struct field usage
fee: fee,
pool: uniswapPool,
sqrtPriceLimitX96: 0 // No price constraint is applied
})
The QuoteExactOutputSingleWithPoolParams struct implementation:
struct QuoteExactOutputSingleWithPoolParams {
address tokenIn;
address tokenOut;
uint256 amount;
uint24 fee;
address pool;
uint160 sqrtPriceLimitX96;
}
Recommended mitigation steps
Update _getQuoteAndDirection to correctly reference the struct fields and provide configurable sqrtPriceLimitX96 if needed:
(amountOut, , , ) = IQuoter(quoter).quoteExactInputSingleWithPool(
IQuoter.QuoteExactInputSingleWithPoolParams({
tokenIn: tokenIn,
tokenOut: tokenOut,
amount: amountIn, // Correct field usage
fee: fee,
pool: uniswapPool,
sqrtPriceLimitX96: sqrtPriceLimitX96 // Example of allowing no limit
})
);
Shaneson (Lambo.win) confirmed and commented:
Good suggestion.
Accept.
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
Impact
Swaps could execute at prices far beyond expected limits, leading to unfavorable trade outcomes, and the function is likely to fail at runtime due to the struct field mismatch.
What the attacker needed
None
The fix
The function should be updated to use the correct struct field name (amount) and to accept a configurable sqrtPriceLimitX96 parameter.
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.
This is a smart contract bug where a function builds a data structure with the wrong field name, so it would likely crash. Also, a price limit is set to zero, meaning trades could happen at any price, which is risky.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.