Verification checklist

  • On an exact output the fee is not payment minus curve input. It is the curve input times the fee, divided by 1000000 minus the fee, plus 1 when the remainder is greater than 0.
  • At fee 3000 the curve needs 998. The product is 2994000, the quotient is 3, the remainder is 3000, the fee is 4, and the payment is 1002.
  • A payment of 1001, under the exact-input split, lets the curve take 997. Rounding 998 up with the flash-loan divisor of 1000000 writes the fee as 3 and drops 1.
  • When the output is cut down to the amount still requested, the cut replaces amountOut. amountIn is not reduced, and the fee still rounds up from the uncut curve input. The callback must cover the positive return value.

1. An exact output adds the fee outside the curve

Inside SwapMath.computeSwapStep, exactIn is true when the amount still remaining on this step is greater than or equal to 0. That is an exact input. A negative remainder is an exact output: the amountSpecified the caller passed to the pool is negative, and its absolute value is how much the pool should send out. The pool's own exactInput flag is a strict greater-than. An amountSpecified of 0 reverts with AS before the loop, so a real swap never reaches SwapMath carrying 0. The two comparisons disagree at 0, and 0 never arrives at the fee line.

On an exact input that does not reach the price target, the fee is the remaining input minus the amount the curve actually takes. Swap Check: Input 997 Reaches the Curve as 994, and the Fee Is 3 is that branch: the input is multiplied by 997000 and divided by 1000000, truncated, and only then shown to the curve. An exact output cannot enter that branch. When exactIn is false, whether or not the price target is reached, the fee is FullMath.mulDivRoundingUp of the curve input times feePips, divided by 1000000 minus feePips. If the product does not divide evenly and the remainder is greater than 0, the result gains 1.

At fee 3000 that divisor is 997000, not 1000000. The exact-input formula divides by 1000000 because the fee is carved out of the payment and the curve only sees the remaining 997000 parts. An exact output runs the other way: the amount the curve must take is already fixed, and the fee is added outside it, so the divisor is the part that remains after the fee tier is removed. The two divisors differ by the fee tier itself. Using the wrong one can land on the same fee when the division is exact, and it drops 1 as soon as there is a remainder.

2. The curve needs 998, the remainder is 3000, and the payment is 1002

This note starts after the curve has already produced amountIn. 998 is not a token amount converted from a square-root price. It is the input to the fee line. How the price function produced 998 is SqrtPriceMath. The fee line does not look at the output again. It only looks at how much the curve is about to take.

998 times 3000 is 2994000. Divided by 997000, the quotient is 3, because 997000 times 3 is 2991000. The remainder is 3000. A remainder greater than 0 makes mulDivRoundingUp add 1 to the quotient, so the fee is 4. The payment is 998 plus 4, which is 1002. Truncating would leave the fee at 3 and write the payment as 1001. That 1 is the remainder of 3000 being rounded up.

Curve takesTimes 3000QuotientRemainderFeePaymentCurve takes if you pay 1 less
1300003000120
33299600009960001333331
333999000120002335332
99729910003031000996
99829940003300041002997

The product for 332 is 996000, still below 997000, so the quotient is 0 and the remainder is 996000. Rounding up still makes the fee 1, and the payment is 333. The product for 333 is 999000, already past one divisor. The quotient is 1, the remainder is 2000, the fee becomes 2, and the payment is 335. A quotient of 1 does not mean the rounding step can be skipped. Any remainder still adds 1. The product for 1 is only 3000, the quotient is 0, the rounded fee is 1, and the payment is 2. The curve takes 1, and the payment is still 2, not 1.

997 is the only row in the table with remainder 0. 2991000 is exactly 3 times 997000, so truncation and rounding up both give 3, and the payment is 1000. An exact division hides the gap between the two rules. Checking only the 997 row makes the exact-output round-up look identical to truncation. 998 is the row that shows the difference of 1.

3. Paying 1 less lets the curve take 997

Reading an exact output as the inverse of an exact input means estimating a truncated fee and adding it to the 998 the curve needs. 998 times 3000 divided by 997000 truncates to 3, so the payment is written as 1001. The exact-input split checks that 1001 the other way: 1001 times 997000 is 997997000, and dividing by 1000000 truncates to 997. The curve takes 997, and the fee is 1001 minus 997, which is 4. The amount taken is 1 below 998. The payment was short by 1, and the curve is also short by 1, but the missing 1 was not removed from the fee. It was cut when the whole payment was truncated into 997000 parts.

Paying the full 1002 gives 1002 times 997000, which is 998994000. Divided by 1000000 and truncated, that is 998, and the remaining 4 is the rounded-up fee. An exact input of 1002 that does not hit the price target lets the curve take 998 with a fee of 4. An exact output that needs the curve to take 998 also requires a payment of 1002. The two sides meet when the payment includes the rounded-up fee. They do not meet one unit lower, because the exact-input truncation reduces the curve input as well when the payment drops by 1.

The 333 row does the same thing. After rounding up, the payment is 335. 335 times 997000 divided by 1000000 truncates to 333. The short payment of 334 produces 332: 334 times 997000 is 332998000, and dividing by 1000000 leaves 332, with a fraction below 1 cut off. Reading the quotient of 1 as a fee of 1, and paying 334, stops the curve at 332, one short of the 333 it needed. A remainder of 2000 is far below 997000, and the round-up still costs that full 1.

The other undercount borrows the flash-loan divisor. A flash fee is the borrowed amount times the fee, divided by 1000000, rounded up when there is a remainder. In Flash Check: Borrow 997, and the Repayment Must Be at Least 1000, 997 times 3000 is 2991000. Divided by 1000000 the quotient is 2 and the remainder is 991000, so the fee rounds up to 3. Using that same division by 1000000 on a curve input of 998 gives 2994000 divided by 1000000, quotient 2 and remainder 994000, which rounds up to a fee of 3 and a payment of 1001. The exact-output divisor is 997000, and the fee on that same 998 is 4. Dropping the fee tier of 3000 out of the divisor drops 1 from the fee. 998 is the next integer after the two divisors still agree. 997 divides 997000 evenly, and dividing by 1000000 still rounds up to 3, so both formulas land on a fee of 3 and the split stays hidden.

4. An exact 997 costs 1000, and that is not an exact input of 997

When the curve needs 997, 2991000 divided by 997000 has no remainder, the fee is 3, and the payment is 1000. An exact input whose payment is 997 is a different trade: 997 times 997000 divided by 1000000 truncates to 994, and the fee is 997 minus 994, which is 3. You pay 997 and the curve takes 994. The exact output pays 1000 and the curve takes 997. Both fees of 3 are right, and the amounts taken differ by 3, because one 3 is carved out of the payment and the other 3 is added outside the amount the curve needs.

The flash loan's 1000 is a third trade. After borrowing 997, the pool requires the balance to rise by at least the fee of 3 above the pre-borrow balance, so at least 1000 comes back. Those 1000 include the 997 that was just sent out. The exact output's 1000 contains 997 that the curve is newly taking and 3 added outside it. The pool did not first lend 997 on this swap. All three sit next to fee 3000 with a 997 and a 1000. They cannot be added together, and one formula cannot be used to check another.

Paying 999, under the exact-input split, lets the curve take 996: 999 times 997000 is 996003000, and dividing by 1000000 truncates to 996. That is neither the 997 an exact output needed nor the 994 an exact input of 997 lets the curve take. Around 997, each step of 1 cuts the exact-input formula in a different place. A check has to name exact input, exact output, or flash loan before it picks the divisor.

5. Cutting the output does not shrink the fee

Before the fee, computeSwapStep has one line that applies only to an exact output. If the amountOut implied by the price move is larger than the output still requested, amountOut is replaced by that remainder. The line changes the output. It does not change amountIn. The fee branch that follows still uses the original amountIn. The output that was cut off cannot be subtracted from the curve input and used to recompute the fee. The 998, 4, and 1002 in this table assume that line was not taken. If it is taken, the output gets smaller, and the fee is still not recomputed from the smaller output.

When the pool folds the step back into the swap, an exact output adds the output to the remaining amount, which moves toward 0. amountCalculated adds the curve input plus the fee, the positive amount that has to be paid. The loop stops when the remainder returns to 0 or the price hits the limit. If the remainder hits 0 first, the negative side equals the original amountSpecified and the positive side is the sum of the payments from the steps that ran. If the price limit hits first, the negative side is only the output actually sent and the positive side only adds the steps that already ran. This note does not invent an unfinished output amount.

Which return value is positive depends on whether zeroForOne and exactInput are the same boolean. On an exact output, exactInput is false. When zeroForOne is true the two flags differ, amount0 is amountCalculated and is the positive payment, and amount1 is the negative value computed from the remainder. The pool transfers token1 to the recipient first, then the callback must increase the token0 balance by at least amount0 or the call reverts with IIA. When zeroForOne is false the two flags match, the positive value is amount1, the pool transfers token0 first, and the callback must bring token1. When the curve takes 998 and the fee is 4, that positive value is 1002. A payment of 1001 fails IIA. The transfer happens before the callback, and a short payment reverts the whole transaction, so the transfer does not remain.

This 4 has not yet been split into a protocol fee. The protocol fee is an integer division of the step fee, using the denominator stored in slot0, and the remainder stays with liquidity providers. Fee Check: The Pool Fee Tier Is Not the Cut LPs Keep is that later cut. The 4 in this note is the whole step fee before the split. It should not be written down as liquidity-provider income, and it should not be added to that note's example of a 3000 fee splitting into 2250 or 2500.

To check an exact output, read in this order. Confirm that amountSpecified is negative and is not 0. Read the step's amountIn, multiply by the pool fee, and divide by 1000000 minus the fee. A remainder of 0 keeps the quotient. A remainder greater than 0 takes the quotient plus 1. The payment is amountIn plus that fee. Run the payment minus 1 through the exact-input split, and the curve input should come out lower than amountIn. Last, after the callback, the balance increase must be at least the positive return value. At fee 3000 with amountIn of 998, the fee must be 4 and the positive value must be 1002. A figure of 1001 has dropped the remainder of 3000.

This is an analytical framework. The exact-output round-up, the divisor of 1000000 minus the fee, and the output being cut on its own come from SwapMath.sol and FullMath.sol v1.0.0. The positive value that the callback must cover, and the transfer that happens before payment, come from UniswapV3Pool.sol v1.0.0. 998, 4, 1002, 997, and 1000 are results of that integer arithmetic, not a pool quote from 16 November 2026, and they are not investment advice.

6. Common misreadings

The curve needs 998. Is a payment of 1001 enough?

No. 998 times 3000 is 2994000. Divided by 997000, the quotient is 3 and the remainder is 3000, so the fee rounds up to 4 and the payment is 1002. A payment of 1001, under the exact-input split, is 1001 times 997000 divided by 1000000 and truncated, which is 997. The curve takes 997, not 998.

The curve needs 997 and the payment is 1000. Is that the same trade as an exact input of 997?

No. 997 times 3000 is 2991000, which divides evenly by 997000, so the fee is exactly 3. The exact output pays 1000 and the curve takes 997. An exact input pays 997, the curve takes 994, and the fee is the remaining 3. A flash loan that borrows 997 and must repay at least 1000 compares balances with the pre-borrow balance. It does not mean the curve took 997.

If this step cuts the output down to the amount still requested, does the fee get smaller?

No. The cut replaces amountOut, and it happens before the fee is computed. The curve's amountIn is not reduced. The fee is still amountIn times 3000 divided by 997000, plus 1 when the remainder is greater than 0.