Verification checklist
- The fee is computed before the transfer, but the check is how far the balance sits above the pre-transfer snapshot. The fee is not removed from the amount received.
- Fee tier 3000 and a flash of 997. 997 times 3000 divided by 1000000 has quotient 2 and remainder 991000, so the fee rounds up to 3. Repay at least 1000. A repayment of 999 leaves an increase of 2 and fails F0.
- A flash of 1 and a flash of 100 both floor to 0 and both round up to 1, so the repayments are at least 2 and 101. A flash of 0 has a fee of 0. Liquidity of 0 reverts with L.
- With protocol denominator 4 and a paid increase of 3, the protocol fee is 0 and LPs receive 3. A paid increase of 4 gives the protocol 1, and LPs still receive 3. Growth divides by the liquidity recorded before the transfer.
1. The full amount leaves, and the fee is added to the increase on the way back
UniswapV3Pool.sol v1.0.0 reads current liquidity at the start of flash. If liquidity is not greater than 0, the function reverts with L and the fee is never computed. After that check, the token0 fee and the token1 fee are each FullMath.mulDivRoundingUp of the borrowed amount times the pool fee, divided by 1000000, with 1 added whenever the remainder is not 0. At fee tier 3000 the denominator stays 1000000. It is not the 997000 used on the swap path.
The balance snapshot is taken before the transfer. The pool then sends the full borrowed amount to the recipient, and the callback sends tokens back. The check after the callback is not "did the balance return to the snapshot." The check is whether the snapshot plus the precomputed fee is less than or equal to the balance after the callback. A shortfall reverts with F0 or F1. The paid increase is the balance after the callback minus the snapshot, so it measures how far the balance sits above the pre-transfer balance, not the gross amount the caller transferred back.
Put the two steps together and the repayment is not the borrowed amount. The outgoing transfer has already reduced the balance by what was borrowed. To finish at least one fee above the snapshot, the callback must send back the borrowed amount plus the fee. The fee is not deducted from the amount that arrives. An account that receives 997 is up by 997, not by 994.
The function is declared with lock. A callback that enters swap, mint, or another flash on the same pool hits that lock. The repayment has to be in hand before the callback, or it has to come from another pool or another contract. The same pool cannot turn the borrowed tokens into the repayment inside this callback.
2. Borrow 997, the fee is 3, and the repayment is at least 1000
The teaching pool uses fee tier 3000 and borrows only token0, amount 997, with token1 amount 0. 997 times 3000 is 2991000. Divided by 1000000, the quotient is 2 and the remainder is 991000. The remainder is not 0, so the fee moves from 2 to 3. The token1 fee is 0, and the pool does not transfer token1.
The callback must lift the token0 balance at least 3 above the snapshot. The 997 has already left, so at least 1000 must come back. Returning 1000 changes the balance by minus 997 plus 1000, the paid increase is exactly 3, and the check passes on equality. Returning only 997 restores the snapshot, the increase is 0, and F0 reverts. Writing the fee as the floored 2 prepares a repayment of 999. Minus 997 plus 999 is an increase of 2, still below 3, and the call reverts as well. The missing token is the one produced by remainder 991000. It is not a second protocol cut.
The same round-up is easier to see on small amounts. A flash of 1: 1 times 3000 is 3000, the quotient is 0, the remainder is 3000, and the fee is 1. The account receives 1 and must repay at least 2. A flash of 100: 100 times 3000 is 300000, the quotient is 0, the remainder is 300000, the fee is still 1, and the repayment is at least 101. Both amounts times 3000 divided by 1000000, rounded down, are 0. Repaying only principal from that 0 leaves an increase of 0 and reverts with F0. On a small flash the fee can be a full token above "0.3 percent, rounded down," and that one token is the entire fee.
| Borrowed | Remainder | Rounded down | Fee | Repay at least |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 1 | 3000 | 0 | 1 | 2 |
| 100 | 300000 | 0 | 1 | 101 |
| 997 | 991000 | 2 | 3 | 1000 |
| 333333 | 999000 | 999 | 1000 | 334333 |
| 1000000 | 0 | 3000 | 3000 | 1003000 |
3. A flash of 333333 barely misses a clean division, and 1000000 hits one
333333 times 3000 is 999999000. Divided by 1000000, the quotient is 999 and the remainder is 999000. The remainder is 1000 short of another whole token, but any nonzero remainder moves the round-up from 999 to 1000. The repayment is at least 334333, not 333333 plus 999. Preparing 334332 from the floor leaves the balance only 999 above the snapshot, and F0 reverts. This row is there for the rule "it almost divides, so repay the quotient." The missing 1000 stays in the remainder, and the fee has already stepped up.
A flash of 1000000 makes 1000000 times 3000 divided by 1000000 exactly 3000. The remainder is 0, so rounding up and rounding down agree. The repayment is at least 1003000. This row makes the two formulas look identical. It uses the same mulDivRoundingUp as 997, 1, and 333333. A report that only includes 1000000 leaves the extra token on 997 outside the table. A divisible sample can be a control. It cannot be the formula.
A flash of 0 uses the same path. Zero times any fee divided by 1000000 is 0, there is no remainder, the fee is 0, and the pool transfers nothing. The callback still runs. An unchanged balance satisfies snapshot plus 0. So "every flash costs at least 1" is false. The premise is that liquidity is already greater than 0. If liquidity is 0, even this zero-amount call never reaches the callback. The function reverts with L first.
4. The 997 on a swap already contains the fee, and the 997 on a flash does not
In Swap Check: Input 997 Reaches the Curve as 994, and the Fee Is 3, an exact input of 997 is the total the user pays the pool. When the price limit is missed, the curve takes 994 and the fee of 3 is already inside that 997. The user does not pay another 3 on top. Carrying that arithmetic onto a flash produces "the fee is 3, so returning 997 is enough." On a flash, the 3 is the extra height the balance must have above the pre-transfer snapshot. Returning 997 only puts the borrowed tokens back, and the increase is 0.
The denominators differ as well. Exact input first divides by 997000 and rounds down. The round-up after a step reaches the limit divides by 997000 again. A flash divides by 1000000 and rounds up from the start, and the full borrowed amount arrives first. On a swap, 997 splits into 994 and 3. On a flash, 997 is still the 997 received, and the repayment is at least 1000. The same 3 sits inside one payment and outside the other.
When both tokens are borrowed, each side is checked on its own. Borrowing 1 extra token1 sets the token1 fee to 1, so at least 2 token1 must come back, while token0 still requires at least 1000. Stacking both fees into token0 and returning only principal of token1 can pass the token0 check and still fail F1, because the token1 increase is 0. There is no branch that pays one token's fee in the other token.
5. The extra token can go to the protocol, while LPs still receive 3
After the check passes, the amount written into fees is the paid increase, not the precomputed minimum fee. Returning exactly 1000 makes the paid increase 3. Returning 1001 makes it 4. The extra token stays in the pool and is treated as a fee. It is not refunded.
The protocol fee uses the teaching value from Fee Check: The Pool Fee Tier Is Not the Cut LPs Keep. When slot0.feeProtocol is 100, token0 takes the low 4 bits and the denominator is 4, and token1 takes the high 4 bits and the denominator is 6. The token0 protocol fee is the paid increase divided by 4, rounded down. A paid increase of 3 gives 3 divided by 4, which is 0. The protocol-fee balance is not increased, and LPs receive 3 minus 0, which is 3. A paid increase of 4 gives 4 divided by 4, which is 1. The protocol receives 1, and LPs receive 4 minus 1, which is still 3. The extra token did not give LPs one more token. It crossed the next step of integer division and went entirely to the protocol.
One more token makes the paid increase 5. 5 divided by 4 is still 1, and LPs receive 4. The fourth token goes to the protocol. The fifth token is the one that reaches LPs. Reading "anything extra is shared in proportion" assigns the fourth token to the wrong balance. When the flash of 1000000 is repaid with exactly 1003000, the paid increase is 3000, 3000 divided by 4 is 750, and LPs receive 2250. Those integers match the 750 and 2250 split of a 3000 fee in the fee-tier note, and the source is different. There, 3000 is a swap fee that already exists. Here, 3000 is the paid increase on this flash.
| Paid increase | Protocol fee | LPs |
|---|---|---|
| 3 | 0 | 3 |
| 4 | 1 | 3 |
| 5 | 1 | 4 |
| 3000 | 750 | 2250 |
6. Those 3 tokens enter growth, and the denominator is the liquidity from before the transfer
The LP portion is multiplied by 2^128, divided by liquidity, rounded down, and added to feeGrowthGlobal. The denominator is the liquidity recorded at the start of the function, not the liquidity at the end of the callback. The teaching value sets that liquidity to 1000000. When the paid increase is 3 and the protocol fee is 0, the amount entering growth is 3. 3 times 2^128 divided by 1000000, rounded down, is 1020847100762815390390123822295304, and the remainder is 634368.
When the paid increase moves from 3 to 4, the LP portion is still 3, so the integer added to global growth does not change either. The extra token shows up in the protocol fee and does not show up in feeGrowthGlobal. Reconstructing "how much the caller repaid" from the growth value misses that token.
On the same liquidity, a paid amount of 3000 rather than 3 stores 1020847100762815390390123822295304634. That is the growth recorded in Fee Check: Growth Records 3000, and tokensOwed Is Still 0 Before the Poke. Multiplying this note's growth for 3 by 1000 produces 1020847100762815390390123822295304000, which is 634 short of the growth for 3000. 634 is the quotient of 1000 times remainder 634368, divided by 1000000. Growth scales with the paid amount, but the remainder dropped by each floor does not scale by the same factor. Scaling a small flash's growth up to a large one is short by the units that were dropped and then carried back in at the larger multiple.
If the callback mints more liquidity, the new liquidity does not enter this flash's denominator. The fee is spread across the liquidity that was already in range before the transfer. The new position starts earning on the next fee, which is the same order of time as the growth note's point that a position minted after a fee is written cannot claim that fee. This time the fee comes from a repayment, not from a swap.
This is an analytical framework. Sending the full amount, rounding the fee up, requiring the balance to finish at least one fee above the pre-transfer snapshot, splitting the paid increase by the protocol denominator, and writing growth against the liquidity recorded before the transfer, come from flash in UniswapV3Pool.sol v1.0.0. Remainder 991000 on 997, a fee of 3, a repayment of at least 1000, a protocol fee of 1 when the paid increase is 4, growth of 1020847100762815390390123822295304, and the missing 634 are teaching results of that integer arithmetic. They are not a pool reading from 11 November 2026, and they are not investment advice.
7. Common misreadings
If the flash sends 997, is returning 997 enough?
No. At fee tier 3000, 997 times 3000 divided by 1000000 has quotient 2 and remainder 991000, so the fee rounds up to 3. The pool snapshots the balance before the transfer, and after the callback the balance must be at least 3 above that snapshot. The 997 has already left, so the repayment is at least 1000. Returning 997 restores the snapshot and the increase is 0, which fails F0. Returning 999 from the floored fee of 2 produces an increase of 2, which also fails.
A flash of 1 floors to a fee of 0. Is the fee waived?
No. 1 times 3000 divided by 1000000 floors to 0, the remainder is 3000, and the fee rounds up to 1. Borrow 1 and repay at least 2. A flash of 100 also floors to 0 and rounds up to 1, so the repayment is at least 101. The fee is 0 only when the borrowed amount is 0. If pool liquidity is 0, the function reverts with L before the fee is computed, and a zero-amount flash does not run either.
If the caller repays one extra token, do LPs receive one extra token?
Not in this teaching series. Repaying exactly 1000 makes the paid increase 3. With a protocol-fee denominator of 4, 3 divided by 4 is 0 and LPs receive 3. One extra token makes the paid increase 4. 4 divided by 4 is 1, and LPs still receive 4 minus 1, which is 3. The extra token goes to the protocol fee. Growth uses the paid amount after that cut, and the denominator is the liquidity recorded before the transfer. Liquidity minted inside the callback does not enlarge it.