1Notation and state
In shortWe follow the paper's notation. Every later formula lives in one plane, , and the whole state fits in four storage words. In the text, a symbol shows its definition when you hover or tap it.
| Symbol | Meaning |
|---|---|
| , | Virtual reserves, one per asset; assets. The contract fixes . |
| , the direction of equal reserves. | |
| , | and . With , and . |
| , | and , exact integers recomputed from the stored reserves. |
| , | A tick's radius and plane constant, and its boundary circle radius . |
| , a tick's normalized plane. | |
| over interior ticks: the radius of the consolidated sphere. | |
| , | and over boundary ticks. |
| over all ticks, the total radius. | |
| A tick's lowest reserve on its cap. Their sum is the pool's floor. | |
| partition | The set of boundary ticks: always a prefix of the initialized ticks, selected by alone (section 4). |
Split the reserves into their component along , , and the rest, . The consolidated invariant only sees and :
highlighted boundary sums · plain interior radius
In the plane, this is a circle of radius centred at . Turned around the line of , it sweeps a torus. A tick's plane becomes a vertical line, at the where the interior point reaches it; when the reserves cross it, the tick changes class and the circle changes with it.
The state the invariant needs fits in four storage words: the three real reserves , from which the pool recomputes and exactly; the interior radius , the boundary sums and , the total radius and the floor ; and one integer for the current partition. A one-word bitmap marks initialized ticks (bits 40 to 238). A swap touches two reserves and reads one tick record per partition it walks: the paper's constant cost in holds in practice.
2The boundary radius is a sum, not a root
In shortThe paper consolidates boundary ticks in two places, and the two forms disagree. The sum is the right one: with it, the surface stays smooth and the marginal price continuous when a tick crosses.
Paper · Tick Consolidation, case 2
Two boundary ticks combine into one sphere in the subspace orthogonal to , with radius .
Paper · Global Trade Invariant
All boundary ticks are treated as a single tick , with .
Where they differ
The two forms agree for a single boundary tick, or for several on the same normalized plane. Otherwise they differ, and always in the same direction: the root form is larger.
What we use
The case-2 argument is the right one: boundary reserves add along a common direction orthogonal to . So , with over interior ticks and summed over boundary ticks.
Why the root form overstates
As a function of , the boundary radius is concave and homogeneous of degree one, hence superadditive. The root of the sums is therefore at least the sum of the roots, with equality only when all boundary ticks share the same .
Proof
- , a product of two linear forms in that are both positive on every valid tick.
- So is their geometric mean: concave and homogeneous of degree one, hence superadditive.
- The root of the sums is therefore at least the sum of the roots. Equality holds only when all boundary ticks share the same .
What the sum buys
With the sum, the invariant is a circle in the plane. When tick crosses, moves between and the boundary sums, and its moves with it. The circles of the two partitions are then internally tangent at the crossing point: their radii are and , and their normals there are parallel. With the root form, the new partition's circle generally misses the crossing point, and the invariant jumps.
Result 1provedtested
With , the surface is not only continuous across a crossing, it is smooth. The marginal price does not jump when a tick flips. In exact arithmetic, a fee-free round trip through a crossing returns exactly to its start.
We checked the consolidated model against an independent convex program, which maximizes output under per-tick sphere and plane constraints. The two agreed to about on swaps that cross ticks, including swaps that pass the point where the two traded reserves are equal.
3Why the path breaks in integers
In shortThe paper's trade segmentation does not survive integer rounding: near a crossing, several independently rounded conditions can leave no valid integer at all.
The paper computes the trade in the current torus. If the common interior point has crossed the nearest plane, it solves a quadratic for the exact crossover, flips that tick, and repeats with the remaining input. Inside a segment, it solves the quartic by Newton's method.
Our first engine followed this procedure. In integers, every event must satisfy several independently rounded computations at once: the classification of the reserve sum against the plane, the closed-form crossover, the segment solver's root, and a tolerance on both sides of the flip. Near an event, sometimes no integer satisfies all of them, and a fail-closed engine reverts a swap that should succeed.
Two rounds of fixes closed specific configurations, and others stayed open. Bands of input 607 wei wide reverted, and isolated inputs failed while their neighbours passed. The case space (event type × direction × regime × rounding side) is combinatorial. Separately, an unbounded Newton on the quartic could converge to the mirror root on the other side of the pair diagonal.
4The endpoint search
In shortAdd the whole input, cut the line of outcomes at integer thresholds, and solve once in the piece that holds the endpoint. The geometry is the paper's; the algorithm is not.
Add the whole net input first. The input reserve and the untouched reserve are then fixed, and only the output reserve is free. Along that line, grows with , and every tick plane becomes an integer threshold on . In partition , the next tick is a boundary tick exactly when
where is the tick's normalized plane. These thresholds cut the line into pieces, each with one fixed torus. Neighbouring partitions compute the same integer, so pieces share their seams exactly.
The engine finds the piece that holds the endpoint and solves once there. On a sphere, when every tick is interior, it uses a closed form. On a torus, it runs Newton, then bisection, inside a certified bracket. A state's partition is a function of its reserve sum alone: no event history is needed. Inside a piece, the offset to the surface falls at a guaranteed rate, and at a seam it can rise by at most half a unit; the endpoint is the first point certified on the pool side. How it works draws this line.
- Take the feeon the gross input
- Locate the piecethresholds on
- Solve onceclosed form or Newton
- Certifyon or inside the surface
- Commitreserves, partition, flips
- Credit feesfrom the two ends
Exact output
An exact-output swap runs the same search on the inverse line. The output reserve falls by exactly the requested amount and the untouched reserve stays fixed; only the input reserve is free. One solve gives the smallest certified input reserve, within the same bound of its integer optimum, and the pool commits that endpoint. It charges the smallest gross input whose net input reaches that endpoint, rounded up to raw units.
The state follows from the output, not from the input, so the swap emits its own event. The exact input of the amount charged certifies a different point and, near a seam, can pay a few wei less than the requested output.
5What we proved
For the stored integers and the pinned constant :
Theorem 1 · Up-setproved
Every piece lies on the near side of its circle's center, where the arc is steeper than any output line can climb. Inside a piece, the pool side of the line is therefore an up-set of integers. Root selection disappears, and the mirror root with it.
Theorem 2 · Seamsproved
Consecutive stored circles are internally tangent to within half a unit.
Theorem 3 · Boundproved
The search terminates and reverts only for capacity. It returns an output at most 50 wei below the exact integer optimum, or 77 wei at the largest supported radius.
6Rounding, everywhere
In shortTwo rules replace every tolerance of the first engine, and they set the rounding of every operation in the pool.
Rule 1
Certified inside
Every stored state is proven on or inside the surface of the partition its sum selects. The proof uses the exact integers and , one square root and outward rounding.
Rule 2
Doubt favours the pool
When a sign is uncertain, the engine takes the pool-favourable integer: a few wei less output. It reverts only for capacity, slippage or zero output.
| Operation | Rounded | Toward the pool | § |
|---|---|---|---|
| Exact-input swap | output | down: at most 50 wei below the integer optimum, 77 at the largest radius | 5 |
| Exact-output swap | gross input | up, to raw units | 4 |
| Deposit | deposit | up: a few wei more when a repair is needed | 7 |
| Withdrawal | withdrawal | down: a few wei less when a repair is needed | 7 |
| Fee split | each share | down; the interior class takes the remainder | 8 |
7Deposits keep the depth
In shortThe paper assumes “each tick has only a single LP” and does not describe deposits or withdrawals once some ticks sit on their boundary. Homogeneity gives the rules; integer states need one more step, or the next trader collects the difference.
The invariant is homogeneous of degree 2 in , which gives two rules:
Interior tick
Adding scales the consolidated interior circle by about its offset .
Boundary tick
Adding liquidity translates the point and the circle together, by the tick's own along the axis and orthogonally.
In both cases, no tick changes class. The virtual reserves become dynamic and move with every deposit and withdrawal.
The trap
An integer state sits slightly inside the surface, and a plain homothety of the reserve point scales that depth too. After a large mint, the point sits far inside every output line, and the next swap captures the surplus. Our 1,000-run fuzz campaign found exactly this: a minimal round trip returned 390 wei more than its input.
The fix applies the homothety to the point's radial projection on the circle and keeps the depth unchanged.
Rounding
Each new state goes through the same certification as a swap endpoint. If rounding leaves it outside, the scarcest reserve is raised along its own line, with the same search a swap uses. The LP pays the difference: the minter deposits a few wei more, the burner receives a few wei less.
8Fees from two states
In shortThe paper does not discuss fees. Ours are charged on the gross input. The net input enters the reserves, and the fee stays outside the invariant, owed to LPs. There is no protocol fee. Each tick's share is read from the swap's start and end states.
A tick's holding is a function of the state
The paper shows that is parallel to . So a boundary tick holds of asset , where . The interior ticks share the rest,
in proportion to their radii. The holdings of all ticks sum to at every state. What each tick absorbs of the input is therefore read from the swap's start and endpoint alone, with no event path and no crossing point.
A holding is continuous where its tick flips: on the tick's plane, the interior ticks' common point is the tick's own point, so its interior and boundary holdings coincide.
Three classes of ticks
The boundary ticks are a prefix of the initialized ticks, so a swap flips one run of consecutive ticks and keeps the class of the others. Each class is paid in proportion to what it absorbs.
| Class | What each tick absorbs | How it is paid |
|---|---|---|
| Boundary at both ends | Its own times | One boundary stream, per unit of , pays them all. |
| Flipped | Its own gain | Credited per unit of its own , and nothing from either stream for that swap. |
| Interior at both ends | In proportion to its radius | One interior stream, per unit of , pays them the rest of the fee. |
Each tick keeps a fee history that is updated at every flip. Fees survive flips, full burns and the re-creation of a tick, without granting old growth to a new position.
Result 2provedtested
The total fee is exact, and the split is exact up to a few wei: every gain is a lower bound, every share rounds down, and the interior class takes the remainder. LPs are never paid more than the fee taken.
A separate oracle, which evaluates every tick's holding at both ends, gives the same class fees on 13 swaps, 7 of them with flips. Vectors computed to 90 digits are met to the wei.
Attribution pays net absorption. Input that a tick absorbs and gives back within one swap, as on a path that turns at pair parity, earns it nothing, and a class whose holding falls is paid nothing for that swap. Question 1 asks whether that is the right choice.
ABeyond three assets
In shortThe contract fixes . The proof's numeric premises, however, can be recomputed for any with the same 199-price catalog. The endpoint bound grows slowly with , and gas limits before the proof does.
The up-set property holds for every . For a tick at depeg price , the premise that the arc is steeper than any output line reduces to .
The endpoint bound has a closed form. Along an output line, the offset to the surface falls at a rate of at least
where is the widest tick's price. The endpoint bound is about wei.
| Bound, | Bound, | ||
|---|---|---|---|
| 3 · deployed | 0.0705 | 50 wei | 77 wei |
| 4 | 0.0576 | 61 wei | 94 wei |
| 5 | 0.0499 | 71 wei | 109 wei |
| 10 | 0.0333 | 107 wei | 163 wei |
| 20 | 0.0229 | 157 wei | 239 wei |
What tightens is precision at the tightest tick. There, , which shrinks like . From , one constant in the liquidity-repair bound has to be re-derived.
These results cover the premises only. Other steps of the proof use identities specific to and would have to be redone. In practice, gas limits before the proof does: each tick a swap flips updates two fee words per asset.
Next · [3]