A Gröbner basis is a canonical generating set for a polynomial ideal with powerful computational properties. Given a system of polynomial equations, computing a Gröbner basis with respect to a lexicographic monomial order reduces it to a sequence of univariate polynomials that can be solved by standard root-finding.
This is Part 1 of a two-part article that develops a Gröbner basis attack on arithmetization-oriented ciphers, a class of hash functions designed for use inside zero-knowledge proof systems. Part 1 builds the necessary algebraic machinery: what a Gröbner basis is, how it is computed, and why it solves polynomial systems. Part 2 will show how a hash function becomes a polynomial system and how that machinery breaks it.
The definitions and theorems in this post follow Cox, Little, and O'Shea, Ideals, Varieties, and Algorithms (4th ed., Springer, 2015). Chapters 1 and 2 cover all the material in this post.
Polynomial Rings and Affine Varieties
The starting point is to make precise what we mean by a system of polynomial equations and its solution set.
Definition. Let k be a field and x1,…,xn indeterminates. A monomial in x1,…,xn is a product of the form
xα=x1α1x2α2⋯xnαn,α=(α1,…,αn)∈Z≥0n.
The total degree of xα is ∣α∣=α1+⋯+αn. A polynomialf in x1,…,xn with coefficients in k is a finite k-linear combination of monomials:
f=α∑cαxα,cα∈k.
The set of all such polynomials, equipped with the usual addition and multiplication, forms a commutative ring denoted k[x1,…,xn], called the polynomial ring in n variables over k.
The solution set of a system of polynomial equations is the fundamental geometric object we need.
Definition. Let f1,…,fs∈k[x1,…,xn]. The affine variety defined by f1,…,fs is the set of all common zeros:
V(f1,…,fs)={(a1,…,an)∈kn∣fi(a1,…,an)=0 for all i=1,…,s}.
Example. In R2, the variety V(x12+x22−1) is the unit circle. The variety V(x1−x2,x12−1) is the finite set {(1,1),(−1,−1)}.
Ideals
A system of polynomial equations can be described by many different collections of polynomials. Multiplying any fi by an arbitrary polynomial h, or replacing f1 with f1+h⋅f2, does not change the solution set. This suggests that the solution set depends not on the particular generators chosen, but on a larger algebraic object they generate. That object is an ideal.
Definition. A subset I⊆k[x1,…,xn] is an ideal if:
0∈I,
f,g∈I⇒f+g∈I,
f∈I, h∈k[x1,…,xn]⇒hf∈I.
Definition. Given f1,…,fs∈k[x1,…,xn], the ideal generated by f1,…,fs is
⟨f1,…,fs⟩={i=1∑shifihi∈k[x1,…,xn]}.
This is the smallest ideal containing f1,…,fs.
The key observation is that different generating sets for the same ideal define the same variety. This is not obvious from the definition of a variety, but it follows immediately from the ideal structure.
Lemma.If ⟨f1,…,fs⟩=⟨g1,…,gt⟩, then V(f1,…,fs)=V(g1,…,gt).
This lemma means we are free to replace any generating set for an ideal with any other generating set, including a Gröbner basis, without changing the variety. Solving the system with a convenient generating set is equivalent to solving it with the original one.
We also record the ideal associated to a given variety, which will appear in the construction of the field equations.
Definition. Given an affine variety V⊆kn, the ideal of V is
I(V)={f∈k[x1,…,xn]∣f(a)=0 for all a∈V}.
The ideal I(V) captures every polynomial relation that vanishes on V and is in general strictly larger than any particular generating set ⟨f1,…,fs⟩ used to define V.
Monomial Orderings
To compute with polynomials in k[x1,…,xn], we need a notion of leading term: the term we try to cancel first when performing polynomial division. In the univariate case, the leading term is simply the one of highest degree. In the multivariate case, there is no single natural choice, and different choices lead to Gröbner bases with different properties.
Definition. A monomial ordering on k[x1,…,xn] is a total ordering > on the set of monomials satisfying:
if xα>xβ then xα⋅xγ>xβ⋅xγ for all γ∈Z≥0n,
> is a well-ordering: every nonempty set of monomials has a least element.
Condition 2 implies that 1=x(0,…,0) is the smallest monomial under any monomial ordering, and together with condition 1 it guarantees that any sequence of reductions eventually terminates.
There are three orderings used in practice. Their computational and structural properties differ significantly, and the choice of ordering is central to the efficiency of the attack.
Definition (Lexicographic Order, lex).xα>lexxβ if the leftmost nonzero entry of α−β∈Zn is positive.
Example. In k[x1,x2,x3]: x12x3>lexx1x25>lexx24x32. The variable x1 dominates unconditionally, regardless of the degrees of x2 and x3. This makes lex order behave like a dictionary, and it is precisely this property that makes it suitable for elimination: a lex Gröbner basis will contain elements involving only x2,x3, then only x3, allowing us to solve the system one variable at a time.
Definition (Graded Lexicographic Order, grlex).xα>grlexxβ if ∣α∣>∣β∣, or if ∣α∣=∣β∣ and xα>lexxβ.
Example. In k[x1,x2,x3]: x1x2x3>grlexx12x3 since ∣α∣=3>2=∣β∣. Total degree is compared first; lex breaks ties.
Definition (Graded Reverse Lexicographic Order, grevlex).xα>grevlexxβ if ∣α∣>∣β∣, or if ∣α∣=∣β∣ and the rightmost nonzero entry of α−β is negative.
Example. In k[x1,x2,x3], among degree-2 monomials: x12>grevlexx1x2>grevlexx1x3>grevlexx22>grevlexx2x3>grevlexx32.
With a monomial ordering fixed, we can designate the distinguished term of each polynomial.
Definition. Fix a monomial ordering > and let f=∑αcαxα=0.
The multidegree of f is multdeg(f)=max>{α∣cα=0}.
The leading monomial is LM(f)=xmultdeg(f).
The leading coefficient is LC(f)=cmultdeg(f)∈k.
The leading term is LT(f)=LC(f)⋅LM(f).
Example. For f=4x12x2+3x23−x1∈Q[x1,x2] under >lex: multdeg(f)=(2,1), LM(f)=x12x2, LC(f)=4, LT(f)=4x12x2.
The Multivariate Division Algorithm
With a notion of leading term in hand, we can generalise polynomial long division to the multivariate setting.
Theorem.Fix a monomial ordering > and an ordered s-tuple F=(f1,…,fs). Then every f∈k[x1,…,xn] can be written as
f=a1f1+⋯+asfs+r
where ai,r∈k[x1,…,xn], no monomial of r is divisible by any LT(fi), and multdeg(f)≥multdeg(aifi) whenever aifi=0. The polynomial r is the remainder on division of f by F, written fF.
The algorithm proceeds greedily: at each step, if the current leading term is divisible by some LT(fi), it is cancelled; otherwise it is moved to the remainder.
This generalisation, however, has two serious defects that do not appear in the univariate case.
First, the remainder fF need not be unique: reordering f1,…,fs can produce a different remainder for the same f. Second, and more critically, fF=0 does not imply f∈⟨f1,…,fs⟩. A polynomial can be a member of an ideal yet fail to reduce to zero when divided by a generating set, simply because the right cancellations do not happen in the right order.
These two defects are not minor inconveniences. They mean that arbitrary generating sets are computationally useless for ideal membership testing and system solving. Gröbner bases are defined as exactly the generating sets for which both defects disappear.
Gröbner Bases
Before defining a Gröbner basis, we need to know that every ideal has a finite generating set to begin with, without this, the notion of a "basis" would be ill-defined. This is the content of the Hilbert Basis Theorem.
Theorem (Hilbert Basis Theorem).Every ideal I⊆k[x1,…,xn] has a finite generating set.
The proof uses the ascending chain condition: any chain I1⊆I2⊆⋯ of ideals must eventually stabilise. This will also guarantee that Buchberger's algorithm, which enlarges a generating set step by step, always terminates.
Definition. For an ideal I⊆k[x1,…,xn], the leading term ideal is
LT(I)=⟨LT(f)∣f∈I,f=0⟩.
The leading term ideal collects the leading terms of every element of I, not just those of a generating set. The gap between ⟨LT(f1),…,LT(fs)⟩ and LT(I) is precisely what causes the division algorithm to fail. A Gröbner basis closes this gap.
Definition. A finite set G={g1,…,gt}⊂I is a Gröbner basis for I if
⟨LT(g1),…,LT(gt)⟩=LT(I).
Equivalently, for every nonzero f∈I, there exists gi∈G such that LT(gi) divides LT(f).
Every nonzero ideal has a Gröbner basis, and every Gröbner basis is a generating set for I. The following two lemmas confirm that Gröbner bases fix both defects identified previously.
Lemma.Let G be a Gröbner basis for I. Then every f∈k[x1,…,xn] has a unique remainder fG, independent of the ordering of elements of G in the division algorithm. This remainder is called the normal form of f with respect to G, written NF(f,G).
Lemma.Let G be a Gröbner basis for I. Then
f∈I⟺fG=0.
Together, these lemmas say that once we have a Gröbner basis, ideal membership becomes a deterministic single computation. Since we know that V(G)=V(I), we can replace any generating set with a Gröbner basis and solve the resulting system instead.
The S-Polynomial and Buchberger's Algorithm
To compute a Gröbner basis, we need a criterion that detects whether a given generating set is already one. The key observation is that the only way a generating set can fail to be a Gröbner basis is if some combination of its elements produces a polynomial whose leading term is not divisible by any of the generators' leading terms. The S-polynomial is designed to expose exactly these combinations.
Definition. Let f,g∈k[x1,…,xn] be nonzero, with α=multdeg(f) and β=multdeg(g). Set xγ=lcm(LM(f),LM(g)), where γi=max(αi,βi). The S-polynomial of f and g is
S(f,g)=LT(f)xγ⋅f−LT(g)xγ⋅g.
The leading terms of f and g cancel by construction, producing a polynomial of strictly lower degree. If this polynomial reduces to zero modulo the current generating set, it contributes nothing new to the ideal and no new generator is needed. If it does not reduce to zero, its remainder is a new ideal element whose leading term is missing from ⟨LT(G)⟩, witnessing that G is not yet a Gröbner basis.
Example. Let f=x13−2x1x2 and g=x12x2−2x22+x1 in Q[x1,x2] under >lex. Then lcm(LM(f),LM(g))=x13x2, and
S(f,g)=x2⋅f−x1⋅g=−2x1x22−x12+2x23.
Theorem (Buchberger's Criterion).A generating set G={g1,…,gt} for an ideal I is a Gröbner basis if and only if
S(gi,gj)G=0for all i=j.
This criterion directly yields an algorithm: start with the given generators, compute all pairwise S-polynomials, add any nonzero remainder as a new generator, and repeat until no new generators appear.
Buchberger's Algorithm.
Input:F={f1,…,fs} Output: A Gröbner basis G⊇F
Set G:=F
Repeat: Set G′:=G For each pair {p,q}⊆G′: Compute r:=S(p,q)G′ If r=0, set G:=G∪{r}
Until G=G′
Return G
Termination follows from the ascending chain condition: each nonzero remainder strictly enlarges ⟨LT(G)⟩, and this chain must stabilise.
Minimal and Reduced Gröbner Bases
Buchberger's algorithm terminates with a Gröbner basis, but typically one containing redundant elements. We shrink it in two steps.
Definition. A Gröbner basis G is minimal if every p∈G is monic and LT(p)∈/⟨LT(G∖{p})⟩.
Definition. A Gröbner basis G is reduced if every p∈G is monic and no monomial of p is divisible by LT(q) for any other q∈G.
A reduced Gröbner basis is obtained from any Gröbner basis by first removing redundant elements to make it minimal, then fully reducing each remaining element modulo the others. The result is unique.
Theorem.Fix a monomial ordering. Every nonzero ideal I⊆k[x1,…,xn] has a unique reduced Gröbner basis.
This uniqueness means the reduced Gröbner basis is a canonical invariant of the ideal and the chosen ordering. Two polynomial systems generate the same ideal if and only if their reduced Gröbner bases coincide. For our purposes, it guarantees that the computation is deterministic: no matter how Buchberger's algorithm processes the S-polynomials, the final reduced basis is always the same.
Solving a Polynomial System with a Gröbner Basis
We now have all the pieces. The following procedure solves a system of polynomial equations f1=⋯=fs=0 over a field k.
Step 1: Form the ideal. Collect the system into I=⟨f1,…,fs⟩⊂k[x1,…,xn]. Finding V(I) is equivalent to finding V(f1,…,fs).
Step 2: Add field equations. If k=Fp, every element of Fp satisfies ap−a=0. Adding the field equations xip−xi for each variable to the generating set restricts the variety to Fpn and ensures the ideal is zero-dimensional, meaning V(I) is a finite set.
Step 3: Choose a monomial ordering and compute a Gröbner basis. Apply Buchberger's algorithm with lex order, placing the variable of primary interest first. The resulting basis G generates the same ideal and satisfies V(G)=V(f1,…,fs).
Step 4: Read off the univariate polynomial. Because lex order forces earlier variables to be eliminated as aggressively as possible, the Gröbner basis G will contain an element g∈k[xn] involving only the last variable. Its roots over k are the only possible values of xn in any solution.
Step 5: Back-substitute. For each root an of g, substitute xn=an into the remaining elements of G and repeat: find the univariate polynomial in xn−1, extract its roots, substitute, and continue until all variables are determined. The full solution set V(I) is recovered.
Example
Consider the following system over Q in variables x>y>z:
⎩⎨⎧f1=x+y+z−6=0f2=x+2y−z−3=0f3=x2+y2+z2−14=0
Computing the Gröbner basis. We apply Buchberger's algorithm, processing S-polynomials until all reduce to zero.
S-polynomial of f1 and f2. Both have leading term x, so lcm(LM(f1),LM(f2))=x and:
S(f1,f2)=f1−f2=(x+y+z−6)−(x+2y−z−3)=−y+2z−3.
This does not reduce to zero modulo {f1,f2,f3}, so we add g1=y−2z+3 to the basis.
S-polynomial of f1 and f3. Here LM(f1)=x and LM(f3)=x2, so lcm=x2 and:
S(f1,f3)=x⋅f1−f3=xy+xz−6x−y2−z2+14.
We reduce this modulo the current basis {f1,f2,f3,g1}. The leading term xy is divisible by LT(f1)=x, so we subtract y⋅f1:
Dividing through by −2 gives y2+yz−6y+z2−6z+11. The leading term is now y2, divisible by LT(g1)=y. Subtracting y⋅g1:
y2+yz−6y+z2−6z+11−y(y−2z+3)=3yz−9y+z2−6z+11.
Subtracting 3z⋅g1:
3yz−9y+z2−6z+11−3z(y−2z+3)=−9y+7z2−15z+11.
Subtracting −9⋅g1:
−9y+7z2−15z+11−(−9)(y−2z+3)=7z2−33z+38.
No element of the current basis has a leading term dividing z2, so this remainder is a new generator: g2=7z2−33z+38.
Verifying the remaining S-polynomials. At this point the basis is G={f1,f2,f3,g1,g2}. We must check all remaining pairs. Seven of them can be dismissed immediately by the coprimality criterion: if the leading monomials of two polynomials are coprime, their S-polynomial always reduces to zero.
The only non-trivial remaining pair is (f2,f3). We have lcm(LM(f2),LM(f3))=x2, so:
All S-polynomials reduce to zero, confirming the basis is a Gröbner basis.
Reducing to minimal form. The current basis is {f1,f2,f3,g1,g2} with leading terms x,x,x2,y,7z2. Since LT(f2)=x is divisible by LT(f1)=x, and LT(f3)=x2 is also divisible by LT(f1)=x, both f2 and f3 are redundant and are removed. Making g2 monic by dividing by 7 gives z2−733z+738. The minimal basis is:
{x+y+z−6,y−2z+3,z2−733z+738}.
Reducing to reduced form. We fully reduce each element modulo the others, ensuring no monomial in any element is divisible by the leading term of another.
For f1=x+y+z−6: the monomial y is divisible by LT(g1)=y, so we subtract g1:
f1−g1=(x+y+z−6)−(y−2z+3)=x+3z−9.
No remaining monomial is divisible by y or z2, so this is fully reduced.
For g1=y−2z+3: no monomial is divisible by LT(f1)=x or LT(g2)=z2. No change.
For z2−733z+738: no monomial is divisible by x or y. No change.
The reduced Gröbner basis in lex order is:
⎩⎨⎧x+3z−9=0y−2z+3=0z2−733z+738=0
The triangular structure is the polynomial analogue of row echelon form. The variable x has been eliminated from the second and third equations, and y has been eliminated from the third. This is the Elimination Theorem in action.
Step 4: Solve the univariate polynomial. The third equation involves only z:
z2−733z+738=0⟹7z2−33z+38=(7z−19)(z−2)=0
giving z=2 or z=719.
Step 5: Back-substitute. For each value of z, substitute into the second equation to find y, then into the first to find x.
Case z=2:
y−2(2)+3=0⟹y=1.
x+3(2)−9=0⟹x=3.
Solution: (x,y,z)=(3,1,2).
Case z=719:
y−2(719)+3=0⟹y=717.
x+3(719)−9=0⟹x=76.
Solution: (x,y,z)=(76,717,719).
The theory developed in this part will be applied directly in Part 2 to a problem in cryptanalysis. A class of cryptographic hash functions called arithmetization-oriented ciphers is designed to have a compact algebraic description, which makes their internal computation expressible as a low-degree polynomial system over a prime field. The variety of that system is the set of inputs consistent with a known output. Part 2 will show how to construct that system, compute its Gröbner basis, and recover the input, with a working implementation in SageMath.