The swap_exact_out
function uses an incorrect formula to calculate the required amount_in
to receive a specified amount_out
during a token swap. The current formula:
applies the fee incorrectly after computing the base input amount. In constant product AMMs like Uniswap, fees must be factored into the input amount before applying the invariant formula.
Incorrect pricing for swap inputs may result in users overpaying or underpaying for swaps.
Misleading slippage protection, allowing outcomes outside user expectations.
Inconsistent reserves, leading to pool imbalance and potential losses for liquidity providers.
Use the correct formula for constant product AMMs with fees applied upfront. For a 0.3% fee, the effective rate is 0.997 (i.e., 997 / 1000). The corrected calculation should look like this:
This version preserves the invariant and includes the fee during the calculation, not after.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.