This question is with reference to the python file model_BKZ.py
provided in the GitHub repository https://github.com/pq-crystals/security-estimates/blob/master/model_BKZ.py
In this file, there is function called construct_BKZ_shape
. I am not able to understand what it is doing. I have read BKZ algorithm from this paper and the YouTube lecture by Prof. Damien Stehlé.
I am not able to link the mathematical theory I read through these sources with the code provided here. Can somebody please explain this code from the mathematical point of view? What we are trying to do through this code?
def construct_BKZ_shape(q, nq, n1, b):
""" Simulate the (log) shape of a basis after the reduction of
a [q ... q, 1 ... 1] shape after BKZ-b reduction (nq many q's, n1 many 1's)
This is implemented by constructing a longer shape and looking
for the subshape with the right volume. Also outputs the index of the
first vector <q, and the last >q.
# Note: this implentation takes O(n). It is possible to output
# a compressed description of the shape in time O(1), but it is much
# more prone to making mistakes
"""
d = nq+n1
if b==0:
L = nq*[log(q)] + n1*[0]
return (nq, nq, L)
slope = -2 * log(delta_BKZ(b))
lq = log(q)
B = int(floor(log(q) / - slope)) # Number of vectors in the sloppy region
L = nq*[log(q)] + [lq + i * slope for i in range(1, B+1)] + n1*[0]
x = 0
lv = sum (L[:d])
glv = nq*lq # Goal log volume
while lv > glv: # While the current volume exceeeds goal volume, slide the window to the right
lv -= L[x]
lv += L[x+d]
x += 1
assert x <= B # Sanity check that we have not gone too far
L = L[x:x+d]
a = max(0, nq - x) # The length of the [q, ... q] sequence
B = min(B, d - a) # The length of the GSA sequence
diff = glv - lv
assert abs(diff) < lq # Sanity check the volume, up to the discretness of index error
for i in range(a, a+B): # Small shift of the GSA sequence to equiliBrate volume
L[i] += diff / B
lv = sum(L)
assert abs(lv/glv - 1) < 1e-6 # Sanity check the volume
return (a, a + B, L)