
mini-golfhe: Mini-Golf Physics Under CKKS
November 22, 2026 · 9 min read
mini-golfhe is an 18-hole mini-golf game in which the server simulates every shot without seeing it. The client encrypts the ball’s position and velocity right after the putt, the server returns four encrypted contacts, and the client decrypts them and draws the trajectory. The server knows which hole is being played, but not where the ball is or how it was hit. This article describes the physics model, and how it is evaluated under CKKS.
A trajectory that is an affine map of the shot
The state of the ball is . Each hole has a quadratic terrain, flat, tilted, a bowl or a saddle:
A ball rolling without slipping on gentle slopes follows
where is the fraction of gravity that drives a rolling solid sphere and is a linear drag. Since is affine in , the equation is linear on the augmented state :
Its solution is . On a grid of step ms, over steps ( s),
These 256 affine maps are public. They are computed once per hole in the clear, by scaling and squaring a Taylor series, and match a Runge–Kutta integration to . The server therefore never integrates step by step under encryption: every point of the trajectory is one affine map of the encrypted shot. The model is chosen for this. A drag proportional to the velocity keeps the equation linear, where a constant rolling resistance would not.
Walls and bounces
Every wall is a straight face with a unit normal . Folding the ball radius into the face gives its clearance
the distance from the ball’s centre to the face, minus the radius: the ball overlaps the face when . The boundary of a hole is a convex polygon of rails with inward normals, and each rail face is tested on its own. Blocks are convex polygons with outward normals, and the ball is inside one when it is behind all of its faces. Round bumpers are regular octagons. A hole has at most 32 faces.
A segment starts from a state and looks for its contact: the first step at which the ball is behind a rail face, or inside a block, where it was not at . The bounce off face , with restitution , is
The first term mirrors the penetration across the face, and the second reverses the normal velocity and scales it by , which is for rails and blocks and for bumpers. Once the face is known, the bounce is affine in , and so in . A block bounces the ball off the faces it was in front of three steps (60 ms) earlier. When there are two of them, at a corner, the sum is scaled by over the faces a point can face together, so that a bounce never adds speed. That scale is 1 for blocks whose faces meet at right angles.
A shot has a fixed number of segments: four contacts. A segment that finds no contact within s ends at its last step, flagged as such, and the next one carries on from there. Everything else is decided by the client after decryption, by replaying the public maps between contacts: the cup (the centre within 6 cm of it, slower than m/s), water, and the ball coming to rest. When all four contacts are spent, the ball stops in front of the next obstacle.
The grid in the slots
With , a ciphertext has slots, laid out as four windows of 256 steps by 32 faces. Slot of window 0 is step and face . The client encrypts a single ciphertext: the state, with each component repeated over its own window, over window 0, over window 1, over window 2 and over window 3. Rotating it by slots brings component over window 0, so any per-slot affine function of the state,
is a linear transform with four diagonals and a plaintext offset. The circuit evaluates three of them from the same three rotations of the state:
- the gaps: in slot , divided by a bound on its magnitude over every shot from the hole’s bounding box at up to 6 m/s, so that it lies in . Window 1 holds the gaps of step 0 in every step’s slot, to tell whether the ball was inside at the start;
- the state at every step: over window ;
- the bounces: the components of the bounce off face at step , over the same windows.
None of this multiplies two ciphertexts: the whole trajectory, at every step and against every face, costs a single plaintext product.
One contact in two halves
From gaps to indicators. The indicator is 1 behind a face and 0 in front of it. The sign is a composite minimax approximation: three odd polynomials of degree 31 applied in turn, 15 levels, within of whenever . A smoothstep follows, which keeps 0 and 1 with zero slope and squares what error remains. Once the normalization is undone, is at most mm on any of the 18 holes: a comparison can only be unsure that close to a face. The indicators are then bootstrapped.
From indicators to the contact. The second half reads the indicators of every step and face at once.
- A rail face is inside when its own indicator is 1. A block of faces is inside when the product of its indicators is: products of runs of 1, 2, 4 and 8 consecutive face slots, by rotations, combined along the binary expansion of .
- A detector is newly entered at step when it is inside at and was not at step 0: , with rotated over from window 1.
- Summing over the 32 faces counts the detectors entered at step , and the degree-7 polynomial with and turns the count into a bit : whether any was.
- The ball is still free after step when no detector was entered before: , a prefix product over the 256 steps in 8 rotations and products. It runs at a coarser scale, , since it needs few bits.
- The contact weights are : 1 at the first contact and 0 elsewhere. The sum telescopes to exactly 1, even when the comparisons are unsure over a few steps, in which case the result is a blend of neighbouring steps instead of an arbitrary value.
The state after the contact is then
where marks the faces bounced off at step (scaled at a corner), and keeps only those of the contact. The contact time and the flag come along. Inner sums over the faces, then over the steps, collect everything into the contact’s output ciphertext. Replicated over the four windows, it is also the next segment’s state, which is bootstrapped before the next contact.
The bootstrapping schedule
Each bootstrapping leaves a ciphertext with 776 bits of budget at scale . The gaps, the sign and the smoothstep bring it down to 109 bits, and the detectors, the prefix product and the sums to 147. A shot therefore takes seven bootstrappings: one for the indicators in each contact, and one for the state between two contacts. Since the circuit rounds its own indicators with the sign and the smoothstep, plain bootstrapping is enough. In a run on a CPU, the seven bootstrappings took a little over half of the evaluation time.
What the blur costs
The encrypted shot and the plaintext model find their contacts on the same 20 ms grid. The comparisons are only unsure within a few millimetres of a face, where a contact can come one step late, with its state a few millimetres off. On grazing, corner and slow contacts, the blur can also resolve the contact differently: about 3% of random shots then come to rest between 5 cm and 1 m from where the plaintext model puts them.