Last time added subgroups, cosets, and roots of unity. This lesson asks a question those tools didn’t answer: inside a finite field, does every number have a square root? In ordinary math, yes, always. In a finite field, no — some numbers have two square roots and some have none at all, and ZK systems need to know which is which. One small example carries the whole lesson: the prime .
Which numbers are squares?
Square every nonzero number from to mod , and a pattern shows up immediately: every result appears exactly twice.
That symmetry isn’t a coincidence: is the same as mod , and is just . A number that is the square of something is called a quadratic residue. Here, exactly six of the twelve nonzero numbers are — half.
Squares are the even powers
Topic 19 built this group from a generator, . Looking at squares through that lens explains why it’s exactly half, not just confirms it.
Squaring any power of the generator doubles its exponent, landing on an even power every time. So every square is an even power of , and every even power is a square — splitting the group’s twelve elements into six even-power squares and six odd-power non-squares.
The square test
Building a full table doesn’t scale to a 254-bit prime. One exponentiation does the same job in a single step.
Write as for the generator . Then , and the last section showed this collapses to when is even and when is odd — exactly the square / non-square split. This quantity is called the Legendre symbol, written .
An easy square root
The test says whether a root exists. Finding the root itself is just as fast — when the prime has the right shape.
Squaring this candidate gives , and the square test says that last factor is whenever is a square — so the square of the candidate really is . This only works when leaves remainder mod ; leaves remainder , so needs a different tool.
When the shortcut fails
For a prime like , the easy formula doesn’t apply. The Tonelli–Shanks algorithm handles every prime, by maintaining a guess and an error term , and fixing the guess until the error disappears.
Split , pick any non-square as a lever, and start from and . Each round measures how many squarings turn into , then multiplies and by a correction built from that cancels exactly that much error. When finally equals , , and is the square root.
One extra bit instead of y
Here’s the first payoff. A curve point has two coordinates, but almost determines on its own — only the sign is missing, and a square root recovers it.
Store and one bit for whether is even or odd. To rebuild the point, compute , take its square root — which gives both and — and use the bit to pick the right one. If isn’t a square at all, no point exists with that . This is exactly how a compressed public key fits a 256-bit plus one bit instead of a full 512-bit pair.
Turning a number into a point
The reverse direction matters too: given an arbitrary number — say, the output of a hash — can it be turned into a point on the curve?
Try a candidate , test whether is a square, and increment if it isn’t. Because exactly half of all numbers are squares — the fact this lesson opened with — about half of all values work, so the odds of failing times in a row fall off as and a few tries are always enough. Real systems use more careful versions of this, since the number of tries taken can leak timing information.
Where these tools show up
Three tools, all built from the same idea: telling squares apart from non-squares, and moving between a number and its root.
The square test gives a fast yes-or-no on whether a root exists at all. Square roots — the easy shortcut or Tonelli–Shanks — actually solve . And compression plus hash-to-curve are where both get used in practice: shrinking a stored point down to and one bit, and turning arbitrary data into a point on the curve. But every one of these tools has a gap: has no square root mod at all. The next lesson builds a bigger field that contains one.
- Exactly half of the nonzero numbers mod a prime are squares (quadratic residues), because and always square to the same value.
- A square is exactly an even power of a generator, since squaring any power doubles its exponent — this is why the split is exactly half and half.
- The square test — raising to — answers “is a square?” in one exponentiation; this quantity is the Legendre symbol.
- When , a square root is a single power, ; otherwise the Tonelli–Shanks algorithm finds it by fixing a guess until its error term reaches .
- Point compression stores a curve point as plus one parity bit and rebuilds with a square root; hash-to-curve runs the idea in reverse, trying values of until is a square.