Bridging ANF and CNF Solvers with BOSPHORUS
Bridging ANF and CNF Solvers with BOSPHORUS
Davin Choo* , Mate Soos† , Kian Ming A. Chai* , and Kuldeep S. Meel†
*
Information Division, DSO National Laboratories, Singapore
† School of Computing, National University of Singapore
Abstract—Algebraic Normal Form (ANF) and Conjunctive ANF and CNF solving algorithms exploit different prop-
Normal Form (CNF) are commonly used to encode problems erties of the problem encoding. For instance, Gauss-Jordan
in Boolean algebra. ANFs are typically solved via Gröbner elimination (GJE) is a natural procedure in ANF, but not in
basis algorithms, often using more memory than is feasible;
while CNFs are solved using SAT solvers, which cannot exploit CNF; while conflict learning prunes the search tree in SAT
the algebra of polynomials naturally. We propose a paradigm solvers, but we are unaware of such learning for ANF. Despite
that bridges between ANF and CNF solving techniques: the the recent successes of GJE-enabled SAT solvers in counting
techniques are applied in an iterative manner to learn facts problems [19], [20], the use of GJE-enabled solvers is not
to augment the original problems. Experiments on over 1,100 prevalent. In this context, we ask: is there an alternative and
benchmarks arising from four different applications domains
demonstrate that learnt facts can significantly improve runtime easier way to combine ANF and CNF solving?
and enable more benchmarks to be solved. The primary contribution of this paper is an affirmative
answer to the above question. We demonstrate a paradigm
I. I NTRODUCTION that bridges between ANF and CNF solving techniques. The
Algebraic Normal Form (ANF) and Conjunctive Normal techniques are applied in an iterative manner to learn facts
Form (CNF) are two commonly used normal forms in Boolean to augment the original problems. This approach is attractive
algebra. Both ANF and CNF reason about Boolean variables when the conversion time between ANF and CNF encodings is
x1 , . . . , xn but with different Boolean operators. negligible relative to the overall solving time. Our experiments
demonstrate that our iterative approach can help us to solve
ANF is a system of polynomial equations in GF(2), i.e.,
more instances while spending less time.
the Galois field of two elements, or Z2 . Each polynomial is a
As a consequence of this bridge, problems can be encoded
sum of monomials, where a monomial is a product of zero or
in their most natural and comprehensible manner, either in
more variables. Cryptologists prefer ANF because it naturally
ANF or CNF, and yet draws from solving techniques in both to
encodes definitions such as AES [1] and hash functions [2].
achieve reasonable solving performance — this is our second
One approach to solving ANF is to compute the Gröbner
contribution. We call our tool B OSPHORUS, the namesake of
basis of the system using the Buchberger’s algorithm [3] or
the Bosphorus bridge connecting Europe and Asia.
its variants [4], [5]. Efficient implementations include M4GB
In the next section, we describe the various techniques for
[6], FGb [7] and Magma [8]. In certain systems, methods
solving ANFs and CNFs. Section III describes how B OSPHO -
such as XL/XSL [9], [10] and ElimLin [11], [12] have also
RUS uses these techniques. Results on three classes of ANF
been shown to be effective. Unfortunately, ANF solvers on
problems and the SAT Competition 2017 benchmarks are in
huge polynomial systems tend to require more memory than
section IV. For notation, we use ⊕ for exclusive-OR (XOR)
is feasible on most computing platforms [13].
and addition in GF(2), ¬ for negation, ∧ for conjunction
In comparison, CNF is a conjunction of clauses. Each clause
and ∨ for disjunction. We use the term polynomial to mean
is a disjunction of literals, where a literal is either a Boolean
polynomial equation equated to zero, and we will also write
variable or its negation. As Boolean circuits are naturally de-
such equations by just stating the polynomial.
scribed in logical connectives, hardware verification problems
are often described in CNFs [14]. Some other domains using II. L EARNING FACTS
CNFs are software verification, industrial planning, scheduling
Our approach iteratively extracts two types of learnt facts:
and recreational mathematical puzzle solving.
(1) linear equations xi1 + xi2 + · · · + xip + c where c is either
CNFs are typically solved by SAT solvers, which use
zero or one; and (2) polynomials of the form xi1 xi2 . . . xip ⊕1.
significantly less memory than the methods for ANF. This is
The former keeps the degree of the system low while the latter
primarily due to the depth-first search nature of CDCL [15]
allows immediate deduction that xi1 = xi2 = · · · = xip = 1.
that most modern SAT solvers are based on. Many solvers
The rest of this section explains how B OSPHORUS obtains and
build upon the small code base of MiniSat [16], which includes
uses these facts in various phases.
the standard CDCL, variable and clause elimination [17],
watched literals data structures [18] and the like. A. ANF propagation
The open-source tool is available at [Link] For each variable, we attempt to assign a value (0 or 1) or an
bosphorus equivalent literal by examining the polynomials involving the
978-3-9819263-2-3/DATE19/2019
c EDAA 468
variable. A value assignment can occur in two cases. First, x1 x2 ⊕x2 x3 ⊕1 becomes x1 ⊕x3 ⊕1, and the ANF propagation
for polynomial x or x ⊕ 1, we set x to the constants 0 or can deduce the equivalence x1 = ¬x3 .
1 respectively. Second, for polynomial xi1 xi2 . . . xip ⊕ 1, we Similar to XL, we apply ElimLin on a random subset of
set xi1 = xi2 = · · · = xip = 1. An equivalence assignment polynomials that has linearized size of approximately 2M .
happens if the polynomial is x ⊕ y or x ⊕ y ⊕ 1, in which case
we set x = y or x = ¬y respectively. These assignments are D. Conflict-bounded SAT solving
applied iteratively until a fixed point is reached. With a CNF equivalent of the ANF, we call a SAT solver
that has conflict-driven clause learning [15]. The solver is
B. eXtended Linearization (XL) allowed up to a pre-determined number C of conflicts to solve
the system. We bound the solver using use a conflict budget
Gauss-Jordan elimination (GJE) solves a system of linear
instead of a time budget for replicability of experiments.
equations by elementary row operations. For polynomials, one
Due to this budget, the solver will surely terminate with one
can apply GJE by treating each monomial as an indepen-
of these three cases: (1) unsatisfiable; (2) satisfiable, giving an
dent variable — this is known as linearization. Dependence
assignment; or (3) undecidable within the limit. In case (1),
between the monomials can be re-introduced by generating
B OSPHORUS appends the contradictory equation 1 = 0 to the
more polynomial equations, a process known as eXtended
system — this is the learnt fact by the SAT solver. In cases
Linearization (XL) [9]. We describe XL and how it is used.
(2) and (3), B OSPHORUS extracts linear equations from learnt
Given a polynomial system S with n variables and m
clauses — of particular interest are linear equations from the
equations, we expand S incrementally to obtain an expanded
unit and binary clauses because they immediately yield value
system S . The expansion process selects each equation in S
and equivalence assignments.
in ascending degree order and multiplies the equation with
all possible monomials up to a chosen degree D. In the case E. Example
where we manage to expand S fully, the expanded system will
D Consider the ANF
have m j=0 nj polynomials. GJE is then applied on S .
x1 x2 ⊕ x3 ⊕ x4 ⊕ 1, x1 x2 x3 ⊕ x1 ⊕ x3 ⊕ 1,
Table I shows an example of applying XL on the ANF
{x1 x2 ⊕ x1 ⊕ 1, x2 x3 ⊕ x3 }, expanding up to degree D = 1 x1 x3 ⊕ x3 x4 x5 ⊕ x3 , x2 x3 ⊕ x3 x5 ⊕ 1, (1)
monomials. The last three rows of Table Ib are the facts {x1 ⊕ x2 x3 ⊕ x5 ⊕ 1.
1, x2 , x3 } that B OSPHORUS will retain.
XL with D = 1 on this system learns the facts x2 x3 x4 ⊕ 1,
Applying XL on the entire ANF often requires considerable
x1 x3 x4 ⊕ 1, x1 ⊕ x5 ⊕ 1, x1 ⊕ x4 , x3 ⊕ 1, and x1 ⊕ x2 . For
memory and time. To avoid this, we uniformly subsample the
ElimLin, its initial GJE — step (1) in section II-C — gives
polynomials from the ANF to obtain an m -by-n linearized
four distinct linear equations: x1 ⊕x5 ⊕1; x1 ⊕x4 ; x3 ⊕1; and
system S such that m n 2M , for a fixed parameter M .
x1 ⊕x2 . After substituting x5 by x1 ⊕1, x4 by x1 , x3 by 1 and
Moreover, S is incrementally expanded only until the system
x2 by x1 , ElimLin learns x1 ⊕ 1. Converting to CNF using
size is approximately 2M +δM , for a parameter δM .
Karnaugh map (section III-C) creates one auxiliary variable
We employ XL in this manner because our primary purpose for x1 x2 . Boolean constraint propagation in the SAT solver
is not to solve the system but to learn facts to augment it. We then gives x2 ⊕ 1, x4 ⊕ 1, x5 , and x1 x2 ⊕ 1.
also employ ElimLin and SAT solver in the same spirit. ANF propagation using the above facts obtained from XL,
ElimLin and SAT solver simplifies the system into
C. ElimLin
ElimLin [11] is an algorithm that iterates through the x1 ⊕ 1, x2 ⊕ 1, x3 ⊕ 1, x4 ⊕ 1, x5 . (2)
following three steps until fixed point: (1) apply GJE on the This effectively solves the system to its unique satisfying
linearization of the polynomial system S; (2) gather linear assignment x1 = x2 = x3 = x4 = 1 and x5 = 0.
equations and remove them from S, yielding S ; and (3) for Observe that ANF propagation after the XL step would
each linear equation , pick, say, a variable from that occurs have led to (2) without the need for either ElimLin or SAT
in the least number equations in S , and eliminate that variable solver. Nevertheless, the above example illustrates that each
from S using . The resultant system S is free of linear can derive different learnt facts: XL gives the value assign-
equations. The process is repeated from step (1) using S as ment for x3 , ElimLin gives that for x1 , and the SAT solver
S until there are no more linear equations after applying GJE. learns the remaining assignments. To make full use of these
Consider the ANF {x1 ⊕x2 ⊕x3 , x1 x2 ⊕x2 x3 ⊕1}. As step different learnt facts, B OSPHORUS is designed to perform ANF
(1) does not affect the system, x1 ⊕ x2 ⊕ x3 remains the only propagation when learnt facts are produced after every step.
linear equation in step (2). If we choose to substitute x1 by
x2 ⊕x3 in step (3), the ANF becomes the single equation (x2 ⊕ III. B OSPHORUS
x3 )x2 ⊕ x2 x3 ⊕ 1. By right-distributing the first conjunction This section details the workflow and the data structures of
over the first XOR and then replacing the XOR of x2 x3 with B OSPHORUS, and the approaches to convert between ANFs
itself by zero, this equation simplifies to x2 ⊕ 1. Assigning and CNFs. The source code is available at [Link]
x2 = 1 and performing ANF propagation on the original ANF, meelgroup/bosphorus.
Problem Convert x1 in (1) do not involve processing the last two equations. The
description to ANF time saved can be significant for large polynomial systems.
C. ANF to CNF conversion
yes Processed
SAT Solver Fixed Point
ANF and CNF
CNF is used by the SAT solver within B OSPHORUS, and it
is also an output. To convert ANF to CNF, we introduce an
no
auxiliary CNF variable on-the-fly for each ANF monomial,
ElimLin XL and we maintain a bi-directional map for such variables.
B OSPHORUS handles determined variables, equivalences,
Fig. 1: B OSPHORUS’s flow. A dashed arrow means ANF and polynomials differently in the conversion. Determined
propagation is applied. variables are added as unit clauses, while an equivalence such
as xi = ¬xj is represented in CNF by (xi ∨xj )∧(¬xi ∨¬xj ).
For a polynomial, it is first re-expressed as shorter ones
A. Workflow by introducing auxiliary variables. The number of terms in
B OSPHORUS takes a problem encoded in ANF and pro- the shorter polynomials is parameterized by an XOR-cutting
duces a processed ANF and CNF after performing an XL– length L, Then, each of these shorter polynomials is converted
ElimLin–SAT-solver fact-learning loop until the fixed point to CNF using either of the following two approaches:
when no further learnt facts are produced. ANF propagation 1) If the polynomial is K-variate, we use the Karnaugh
is performed on the input ANF and whenever learnt facts are map to yield the minimal clause representation while re-
produced. Fig. 1 shows the overall workflow. ducing the number of auxiliary variables used. Because
Internally within B OSPHORUS, the problem is represented computing the Karnaugh map scales exponentially with
as an ANF polynomial system, and only ANF propagation the number of variables, the Karnaugh parameter K is
modifies and replaces this master copy. Each of the other kept low to ensure reasonable conversion time.
techniques — XL, ElimLin and SAT solver — operates on 2) If the polynomial involves more than K variables, we
a copy of the ANF, and learnt facts are extracted and then apply a transformation à la Tseitin encoding [22]. Each
added onto the master copy if not already there. polynomial of length l ≤ L is treated as an XOR clause
If the equation 1 = 0 is detected, B OSPHORUS terminates of independent terms and converted to CNF clauses by
and returns UNSAT. If the SAT solver finds a satisfying enumerating through all possible 2l terms.
solution, B OSPHORUS stores the solution. This solution is not Although the Karnaugh map approach is less flexi-
used to simplify the ANF because it may not be unique. ble, it can yield a more compact conversion than the
B. Data structures Tseitin-based approach. Consider the polynomial equation
x1 x3 ⊕ x1 ⊕ x2 ⊕ x4 ⊕ 1 = 0. Fig. 2 shows possible CNF
B OSPHORUS stores the system of equations in the ANF representations via both approaches. Using the Karnaugh map
description as a list of Boolean polynomials. For each variable, shown in Fig. 3, one can derive a more compact CNF system
we track (i) its value, as either 0, 1, or undetermined; (ii) its that directly deals with the variables involved. In comparison,
equivalence literal; and (iii) its occurrence list. the Tseitin-based approach creates a new CNF variable x5 and
The default equivalence literal for each variable is the encode x5 = x1 x3 using three CNF clauses.
variable itself and may change as B OSPHORUS proceeds. For At present, any auxiliary variable introduced in the conver-
example, the equivalence literal of xi may be switched to ¬xj sion process does not participate in the learnt facts.
to encode xi = ¬xj .
Occurrence list is an optimization technique from the SAT D. CNF to ANF conversion
literature [18], [21]. Here, B OSPHORUS tracks the list of poly- B OSPHORUS can be used as a CNF preprocessor, though its
nomials that each variable occurs in. For example, updates to main use-case is that of solving problems represented in ANF.
Computation, 2009.
xi+2 xi+1
[26] M. Albrecht and G. Bard, The M4RI Library – Version 20121224, The
M4RI Team, 2012. [Online]. Available: [Link]
[27] M. Albrecht, G. Bard, and C. Pernet, “Efficient dense Gaus- Fig. 4: One Fiestel round of Simon cipher. Diagram from [36].
sian elimination over the finite field with two elements,” 2011,
arXiv:1111.6549v1[[Link]]. 448 bits 64 bits
[28] M. Soos, “The CryptoMiniSat 5 set of solvers at SAT competition 2016,”
in SAT Competition 2016 – Solver and Benchmark Descriptions, 2016. Message M Nonce 1 |M |
[29] R. K. Brayton, G. D. Hachtel, C. McMullen, and A. Sangiovanni-
Vincentelli, Logic minimization algorithms for VLSI synthesis, 1984. Randomly fixed 415 bits 32-bit Size of M
[30] M. Karnaugh, “The map method for synthesis of combinational logic nonce in binary
circuits,” Transactions of the American Institute of Electrical Engineers,
Part I: Communication and Electronics, 1953. Fig. 5: Our nonce-finding setup.
[31] T. Balyo, M. Heule, and M. Järvisalo, Eds., SAT Competition 2017 –
Solver and Benchmark Descriptions. University of Helsinki, 2017, vol.
B-2017-1.
[32] A. Biere, “CaDiCaL, Lingeling, Plingeling, Treengeling, YalSAT Enter- we toggle the ith in the right-half of P1 , for i ∈ {2, . . . , n}.
ing the SAT Competition 2017,” in SAT Competition 2017 – Solver and This set of problems is parameterized by (n, r), where n is
Benchmark Descriptions, 2017.
[33] A. Biere, A. Biere, M. Heule, H. van Maaren, and T. Walsh, Handbook the number of plaintexts, and r is the number of rounds.
of Satisfiability: Volume 185 Frontiers in Artificial Intelligence and
Applications, 2009. C. Cryptographic hash functions — 50 instances per k
[34] C. Cid, S. Murphy, and M. J. Robshaw, “Small scale variants of the Recently, Cryptographically secure hash functions have
AES,” in Proceedings of FSE, 2005.
[35] The Sage Developers, SageMath, the Sage Mathematics Software System been used to serve as proof-of-work in blockchains and
(Version 8.1), 2017, [Link] cryptocurrencies, of which Bitcoin is an example. Bitcoin [38]
[36] R. Beaulieu, S. Treatman-Clark, D. Shors, B. Weeks, J. Smith, and uses SHA256, a hash function in the SHA-2 hash family [2].
L. Wingers, “The Simon and Speck lightweight block ciphers,” in
Proceedings of DAC, 2015.
We consider a weakened version of the Bitcoin block
[37] N. Courtois, T. Mourouzis, G. Song, P. Sepehrdad, and P. Susil, “Com- hashing algorithm. Let M be a 512-bit input message, and
bined algebraic and truncated differential cryptanalysis on reduced-round H be a 256-bit hash output. We randomly set the first 415
Simon,” in Proceedings of SECRYPT, 2014.
[38] S. Nakamoto, “Bitcoin: A peer-to-peer electronic cash system,” Tech.
bits of M , allow the next 32-bit nonce to be free (but to
Rep., 2008. be determined), and pad according to SHA padding (add
‘1’, then encode |M | = 448 in the next 64 bits). Given k,
A PPENDIX the challenge is then to solve for a suitable 32-bit nonce
A. Round-reduced AES cipher — 500 instances of M that results in a hash H with the first k bits being
We obtain a parameterized ANF encoding of AES [34] from 0. We construct challenges in this manner because Bitcoin
SageMath [35]. Using parameters (n, r, c, e) = (1, 4, 4, 8), uses 32-bit nonces to solve for hashes starting with varying k
we generate 500 ANF instances for 1-round AES. First, 500 zeroes. See Fig. 5 for an illustration. We generate instances for
random pairs of plaintext (P ) and key (K) bits are generated k = {10, 15, 20} using the generic ANF encoding available at
and simulated to yield the corresponding ciphertext (C) bits. [Link]
The resultant ANF has 800 variables and 1120 equations — D. Instances from SAT 2017 Competition
864 equations and 256 bit assignments from (P, C).
We preprocess g2-hwmcc15deep-beemfwt4b1-k48 and
B. Round-reduced Simon cipher — 50 instances per (n, r) g2-hwmcc15deep-beemlifts3b1-k29 using CryptoMin-
Simon [36] is a family of lightweight Feistel-based block iSat5 to reduce the number of variables to less than 1,048,574
ciphers. The round functions are described in conjunction variables, which is the maximum number of variables that
and exclusive-OR of bits, allowing a straightforward ANF the P OLY B O R I data structure can handle on our platforms.
encoding; see Fig. 4. This set of benchmarks are reduced We omit the 40 CNFs with names of the pattern g2-T∗
rounds Simon32/64 with multiple plaintext-ciphertext pairs because they each have too many variables even after the
encoded under the same randomly generated secret key. preprocessing. We also omit mp1-bsat222-777 because it
Simon32/64 takes a 32-bit plaintext (P ) and a 64-bit key is not a well-formed DIMACS file. Hence, we experiment
to return a 32-bit ciphertext. For each instance, we generate on 310 instances altogether. From these, we select difficult
n ≤ 17 plaintexts with low hamming distance as per the Sim- instances: using the runtime of MiniSat (without B OSPHORUS)
ilar Plaintexts/Random Ciphertexts (SP/RC) setting in [37]. as a proxy difficulty measure, we select the 219 that requires
Concretely, the first plaintext P1 is uniformly sampled while more than 2,500 seconds.