Try   HackMD

Subset Sum from Lattice Reduction

Vadim's talk at 2nd BIU gives good intro to why we can use LLL for subset sum in theory, this note focus on "how exactly" in practice for the engineers, as my digest of various related work and why they make sense.

Here's the implementation of this SSP solver in python.

Recall that the goal of lattice reduction algorithms are to find orthonormal bases (i.e. nice, short, and nearly orthogonal) given an arbitrary bases of the lattice. More technically, they obtain a basis whose Gram-Schmidt vectors are not decreasing too quickly (which implies that the basis vectors are somewhat orthogonal to each other).

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

  • Theorm[1]: the vector
    b1
    in a LLL-reduced basis (is short) has length at most
    2(n1)/2λ1(L(B))

For now, we treat lattice reduction algorithm like LLL as an oracle that returns short bases in a lattice, and amazingly even finds the shortest non-zero vector in the lattice with high probability in polynomial time.

Recall the Subset Sum Problem (SSP):

  • [SSP]: Given a multiset
    \setai
    , and a target
    S=i=1naixi
    where
    xi\set0,1
    , find a subset that sums to
    S
    .
    • Brickell and Lagarias & Odlyzko showed that almost all low-density subset sum can be solved in poly time,
      d=n/logmaxai
      ;
      d>1
      generally mean many subset solutions with the same target sum; we are interested in
      d1
      .
    • SSP doesn’t constrain
      |x|
      since it is tasked to find a solution, not “the” solution.

Utilizing LLL to solve SSP is essentially reducing the latter to the former, here’re some attempts that gradually build towards the one reduction that we’ll use. At the center, we need to construct a problem instance

Bt=[b1|b2||bd], given the SSP set
\setai
, to feed into the LLL oracle such that the returned
b1
from the reduced bases correspond to the SSP solutions.

  • note:
    dn
    ,
    d
    is called lattice dimension,
    n
    is called embedding dimension, most cases in cryptography, people consider squared, fully-ranked matrix. When we only use
    n
    subscript, we are implicitly using full-rank
    B
  • notation: by convention (and in python),
    B
    is a row matrix, first row is
    b1
    , but in lattice crypto, the convention is taking column matrix as input, which we denotes
    Bt

First Attempt

B=[Ia0S]=[b1:=(100a1)b2:=(010a2)bn:=(001an)bn+1:=(000S)](n+1)×(n+1)

Now, any lattice point in

L(Bt) can be expressed by a linear combination of the row vectors. Let’s denote the linear combinator
\setci
:

z=[z1,,zn+1]=[c1,c2,,cn,i=1nciaicn+1S]L(Bt)

It’s not hard to verify that actual solution

xL is a short vector in the lattice, thus we can hope that our LLL oracle finds it, and we can check this condition on the reduced
b1
:
zi\set0,1for i[n]zn+1=0
, then output
(zi)i[n]
as the solution. Wola!

Unfortunately, there’s a problem: there could be shorter vectors than

x and lattice oracle might return them instead!

  1. If any one of
    ai
    is small, then that row itself is already a short vector
  2. if any two inputs are close
    aiaj
    , then the difference (i.e.
    rowirowj
    ) is a short vector
    1. more generally, if
      βiaiβjaj
      for any small integer coeffs
      βi,βj
      , then
      z:=(βirowiβjrowj)
      is a short vector

In short, all the above 3 cases presents high probability of our lattice oracle failing to produce the intended solution of SSP, and since we don’t have prior knowledge or constraint on values of

\setai, we need to modify our
B
to avoid these possibilities.

Second Attempts

Both cases above can be solved with one simple trick: scale the last column with some value

N>n (don’t worry about the bound, just think a big number like 1000)!

B=[INa0NS]=[100Na1010Na2001Nan000NS](n+1)×(n+1)

Each row is no longer a short vector, and LLL does need more work to find an actual smaller vector in this lattice. And the second concern is also mitigated since the delta

βiNaiβjNaj is also scaled up, thus unlikely to be a shorter vector than our intended solution
x
anymore.

  • note: if
    ai=aj
    , then the second concern still stands, we will discuss this towards the end.

This version is essentially Lagarias and Odlyzko’s reduction in their work “Solving low-density subset sum problems”.

There are still some unsatisfactory limitations:

  1. the success probability is bounded, and based on analysis in LO’85, this reduction only works for SSP with density

    d<0.6463 (another detailed analysis is in P.58 of LaMacchia’s “Basis Reduction Algorithms and Subset Sum Problems”)

  2. observe the entry

    zn+1:=N(i=1nciaicn+1S): what if
    c1a1+c2a2=cn+1S
    for some coefficients
    c1,c2,cn+1>1
    ? Then there are more competing short vectors again.

    (e.g.):

    [0,0,2,0,1,0,0] v.s.
    x=[1,1,0,1,1,1,0]
    where
    2a3+a5=5S
    and
    a1+a2+a4+a5+a6=S
    . the former is a shorter vector and more likely to be returned by LLL oracle, but not exactly what we wanted.

In short, the lesson is we want to add even more constraints to the coefficients

\setci that contributes to the term
zn+1
so that constraining
zn+1=0
actually leads to
(zi)i[n]=x
without many competing/alternative short vectors.

Final Reduction

To improve the theoretical bound issue in point 3 above, “An Improved Low-density Subset Sum Algorithm” [CLOS’91] has proposed to use:

B=[INa1/2NS]=[100Na1010Na2001Nan1/21/21/2NS](n+1)×(n+1)

This slightly modified reduction increase the range of SSP instances we can solve to any

d<0.9408. But we skip the analysis, as it’s non-essential to us, and take it as given.

To address concern 4 above, [Schnorr’93] in “Lattice Basis Reduction: Improved Practical Algorithms and Solving Subset Sum Problems” on Sec. 7 build on top of [CLOS’91], added an extra column (second last column below) to control and constrain the equivalent value of

cn+1in our previous attempt.

B=[2I0Na11NS]=[2000Na10200Na20020Nan1111NS](n+1)×(n+2)

The condition to check becomes:

|zn+1|=1zn+2=0z1,,zn\set±1

It’s not hard to verify that the foregoing condition guarantees

(|zizn+1|/2)i[n]=x with overwhelming probability (since we avoid all of the 4 caveats above).

Say

zn+1=1cn+1=1ciai=S, and since
(zi:=2ci+1)i[n]\set±1ci\set0,1|zizn+1|/2\set0,1
, Wola! You can easily double-check the other case when
zn+1=1
.

Higher-dimension SSP

Up until now, we only consider

ai as scalars. What if they are vectors of higher dimension themselves, say
ai=(ai,1,,ai,m),S=(S1,,Sm)Rm
? We could flatten out all the
m
dimensions and use the same argument, inflating the embedding dimension but keeps the same lattice dimension for
Bt
. Concretely:

B=[2I0Na11NS]=[2000Na1,1Na1,2Na1,m0200Na2,1Na2,2Na2,m0020Nan,1Nan,2Nan,m1111NS1NS2NSm](n+1)×(n+m+1)

The condition check becomes:

|zn+1|=1zn+2,,zn+m+1=0z1,,zn\set±1

TODO: add more analysis on the success rate or density bound?

Modular SSP

Sometimes, we are asked to solve the modular variant of SSP where values and summations are carried out in

modq instead of in
R.

TODO: add adaptation here.

One more thing

Recall the edge case of some

ai=aj that goes outside the scope of classical definition of SSP instance, that may cause competing short vectors.

If there aren’t too many (say constant number) of these duplicates, then we can simply remove

aj and feed
(\setaiaj,Saj)
and
(\setaiaj,S)
to the current subset sum solver. Note the two instances corresponds to the original
cj=1
and
cj=0
. Since our reduction in the final attempt gives a poly-time solver, we would end up a poly-time solver here too. Effectively, we are guessing
cj
and trading off run-time with success probability.

This approach also works if there are logarithmic number of duplicates, as guessing all possible combination takes the power set of those duplicates, and logarithmic duplicates leads to

O(n) number of tries, which still end up with poly-time solver.

However, if we go beyond log number of duplicates, then in practice, instead of suffering from super-poly runtime, we might choose to suffer from a slightly higher failure probability from the subset solver instead. Additionally, we can check more than just

b1, but also the first few reduced basis, since there’s likelihood that the first reduced basis is the shortest competing vector while the second shortest basis corresponds to our subset solution. In terms of bound and guarantee, it’s beyond my depth for now but some statistical empirical evaluations might enlighten us.


  1. both the screenshot and the theorem are excerpt from Regev's lecture note. ↩︎