mini-golfhe: Mini-Golf Physics Under CKKS

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 s=(x,y,vx,vy)s = (x, y, v_x, v_y). Each hole has a quadratic terrain, flat, tilted, a bowl or a saddle:

h(q)=12 (q−c)⊤H (q−c)+σ⊤(q−c).h(q) = \tfrac{1}{2}\,(q - c)^\top H\,(q - c) + \sigma^\top (q - c).

A ball rolling without slipping on gentle slopes follows

q¨=−κ ∇h(q)−λ q˙,κ=57 g,\ddot q = -\kappa\, \nabla h(q) - \lambda\, \dot q, \qquad \kappa = \tfrac{5}{7}\, g,

where 5/75/7 is the fraction of gravity that drives a rolling solid sphere and λ=0.9 s−1\lambda = 0.9\ \mathrm{s}^{-1} is a linear drag. Since ∇h(q)=H(q−c)+σ\nabla h(q) = H(q - c) + \sigma is affine in qq, the equation is linear on the augmented state z=(x,y,vx,vy,1)z = (x, y, v_x, v_y, 1):

z˙=Mz,M=(0I20−κH−λI2−κ (σ−Hc)000).\dot z = M z, \qquad M = \begin{pmatrix} 0 & I_2 & 0 \\ -\kappa H & -\lambda I_2 & -\kappa\,(\sigma - Hc) \\ 0 & 0 & 0 \end{pmatrix}.

Its solution is z(t)=eMtz(0)z(t) = e^{Mt} z(0). On a grid of step Δt=20\Delta t = 20 ms, over 256256 steps (5.125.12 s),

s(kΔt)=Ak s0+ck,(Akck)=the first four rows of ekMΔt.s(k\Delta t) = A_k\, s_0 + c_k, \qquad \begin{pmatrix} A_k & c_k \end{pmatrix} = \text{the first four rows of } e^{kM\Delta t}.

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 10−610^{-6}. 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 −μ v/∥v∥-\mu\, v/\lVert v \rVert would not.

Walls and bounces

Every wall is a straight face with a unit normal nfn_f. Folding the ball radius into the face gives its clearance

gf(q)=nf⋅q−bf,g_f(q) = n_f \cdot q - b_f,

the distance from the ball’s centre to the face, minus the radius: the ball overlaps the face when gf<0g_f < 0. 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 s0s_0 and looks for its contact: the first step k≥1k \ge 1 at which the ball is behind a rail face, or inside a block, where it was not at k=0k = 0. The bounce off face ff, with restitution ee, is

Δq=−(1+e) gf(q) nf,Δv=−(1+e) (nf⋅v) nf.\Delta q = -(1 + e)\, g_f(q)\, n_f, \qquad \Delta v = -(1 + e)\, (n_f \cdot v)\, n_f.

The first term mirrors the penetration across the face, and the second reverses the normal velocity and scales it by ee, which is 0.750.75 for rails and blocks and 0.90.9 for bumpers. Once the face is known, the bounce is affine in s(kΔt)s(k\Delta t), and so in s0s_0. 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 1/λmax⁡ ⁣(∑nfnf⊤)1/\lambda_{\max}\!\left(\sum n_f n_f^\top\right) 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.

railg = 0ns₀, encrypteds(kΔt) = Aₖ s₀ + cₖall 256 grid points at oncefirst step with g < 0Δq = −(1+e) g nΔv = −(1+e) (n·v) nthen a new segment from the bounced state
One segment against a rail. The dots are ball centres on the 20 ms grid, all computed from the encrypted start state by public affine maps. The contact is the first one behind the face (g < 0, the ball radius folded into the face); later grid points are discarded and the next segment starts from the bounced state.

A shot has a fixed number of segments: four contacts. A segment that finds no contact within 5.125.12 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 1.31.3 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 N=216N = 2^{16}, a ciphertext has 2152^{15} slots, laid out as four windows of 256 steps by 32 faces. Slot 32k+f32k + f of window 0 is step kk and face ff. The client encrypts a single ciphertext: the state, with each component repeated over its own window, xx over window 0, yy over window 1, vxv_x over window 2 and vyv_y over window 3. Rotating it by j⋅8192j \cdot 8192 slots brings component jj over window 0, so any per-slot affine function of the state,

∑jaj[slot] sj+c[slot],\sum_{j} a_j[\text{slot}]\, s_j + c[\text{slot}],

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: gf(s(kΔt))g_f(s(k\Delta t)) in slot (k,f)(k, f), 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 [−1,1][-1, 1]. 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: sj(kΔt)s_j(k\Delta t) over window jj;
  • the bounces: the components of the bounce off face ff at step kk, 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 β=(1−sign⁡(g))/2\beta = (1 - \operatorname{sign}(g))/2 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 2−122^{-12} of ±1\pm 1 whenever ∣g∣≥2−11\lvert g \rvert \ge 2^{-11}. A smoothstep 3β2−2β33\beta^2 - 2\beta^3 follows, which keeps 0 and 1 with zero slope and squares what error remains. Once the normalization is undone, 2−112^{-11} is at most 7.37.3 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.

  1. A rail face is inside when its own indicator is 1. A block of mm faces is inside when the product of its mm indicators is: products of runs of 1, 2, 4 and 8 consecutive face slots, by rotations, combined along the binary expansion of mm.
  2. A detector is newly entered at step kk when it is inside at kk and was not at step 0: dk−dkd0d_k - d_k d_0, with d0d_0 rotated over from window 1.
  3. Summing over the 32 faces counts the detectors entered at step kk, and the degree-7 polynomial with p(0)=0p(0) = 0 and p(1)=⋯=p(7)=1p(1) = \dots = p(7) = 1 turns the count into a bit aka_k: whether any was.
  4. The ball is still free after step kk when no detector was entered before: φk=∏j≤k(1−aj)\varphi_k = \prod_{j \le k} (1 - a_j), a prefix product over the 256 steps in 8 rotations and products. It runs at a coarser scale, 2302^{30}, since it needs few bits.
  5. The contact weights are wk=φk−1−φkw_k = \varphi_{k-1} - \varphi_k: 1 at the first contact and 0 elsewhere. The sum ∑kwk+φ255\sum_k w_k + \varphi_{255} 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

s′=∑kwk s(kΔt)+φ255 s(255 Δt)+∑kφk−1∑fβk,f′ Δf(kΔt),s' = \sum_{k} w_k\, s(k\Delta t) + \varphi_{255}\, s(255\,\Delta t) + \sum_{k} \varphi_{k-1} \sum_{f} \beta'_{k,f}\, \Delta_f(k\Delta t),

where βk,f′\beta'_{k,f} marks the faces bounced off at step kk (scaled at a corner), and φk−1\varphi_{k-1} keeps only those of the contact. The contact time ∑kwk kΔt\sum_k w_k\, k\Delta t and the flag ∑kwk\sum_k w_k 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

contact 1contact 2contact 3contact 4gapssign, 0/1Bdetectorsfirst contactBgapssign, 0/1Bdetectorsfirst contactBgapssign, 0/1Bdetectorsfirst contactBgapssign, 0/1Bdetectorsfirst contact7760109147bitsbootstrapping of the face indicatorsbootstrapping of the next state
The server's side of a shot. Each contact runs in two halves of 630 to 670 bits: the first turns the gaps into 0/1 face indicators, the second finds the first contact and sums the state after it. Seven bootstrappings per shot: one for the indicators in every contact, one for the state between contacts.

Each bootstrapping leaves a ciphertext with 776 bits of budget at scale 2352^{35}. 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.