The vault hands out LWE samples b = <a,s> + e mod q with a 256-dimensional
secret, and the blurb swears that dimension is enough to kill and BKZ.
That part is a decoy: the actual weakness isn't in the lattice at all, it's
in how the noise is generated.
Hint
The noise isn't noise if you can predict it. What generates e, and how
much entropy does it actually have?
Reading the oracle
challenge.py is short. The secret is FLAG.ljust(256, b'_'), q = 65537,
n = 256, and each sample is:
1a = [secrets.randbelow(q) for _ in range(n)]
2e = self.noise_gen.randint(-100, 100)
3b = (sum(x * y for x, y in zip(a, self.secret)) + e) % q
Two details matter: e is one scalar for the entire 256-long sample,
not one per coordinate, and noise_gen is an XorShift32 seeded with
1self.seed = int.from_bytes(os.urandom(4), 'big') & 0x3FFFFFFF # 30 bits
Every e_i is a deterministic function of that one 30-bit seed.
Pitfall
The obvious LWE move is to subtract two samples and hope the secret
cancels: b_i - b_0 = <a_i - a_0, s> + (e_i - e_0) (mod q). That removes
s, but e_i - e_0 is still there. I spent a while treating that
difference as noise that should just vanish, solved the resulting system
anyway, and got a residual of -16698 on the real data - nowhere near the
+/-100 range the challenge promises. Each sample's noise is independent,
so it never cancels between samples. Wrong instinct, but a useful one to
rule out early: the noise is reproducible, not small, and reproducible
is the real opening.
Killing the noise instead of cancelling it
If the seed is known, every e_i is known, and A s = (b - e) (mod q) is
an exact linear system. The problem is searching 2^30 seeds without
paying for a full linear solve on each one.
Insight
A cheap filter falls out of the matrix shape itself. Take the first 257
samples: A is then 257x256, which has a one-dimensional left null
space - a vector w with w^T A = 0 (mod q). Multiply the samples by
w:
w . b = w . (A s + e) = w . e (mod q)
The secret cancels completely. For a candidate seed, predict
e_0..e_256, compute w . e, and compare against the known w . b. A
wrong seed only passes by coincidence with probability 1/q, so out of
2^30 candidates about 2^30 / 65537 ~ 16368 survive - small enough to
filter further, large enough that this stage alone doesn't nail the
answer.
Running the scan
2^30 seeds, each replaying 257 xorshift steps, is about 2.7x10^11 inner loop iterations - hours in plain Python. Written as a small OpenMP C loop and run on 24 threads, it finishes in about 33 seconds and writes 16368 candidate seeds to disk.
Those survivors are then filtered with the 9-dimensional left null
space of the full 265x256 matrix - nine independent congruences of the
same form. Applied to the candidate list, exactly one seed survives:
801158434.
Recovering the flag
Predict every e_i from the winning seed, solve A s = (b - e) mod q by
Gaussian elimination over F_q, and verify: the recovered secret
reproduces all 265 samples with residual 0, and reads as the flag
followed by 217 trailing underscores (the ljust(256, b'_') padding).
Show the full solve script
1#!/usr/bin/env python3
2# The Oracle's Lattice v2.0
3import json, subprocess
4import numpy as np
5
6Q, N = 65537, 256
7A, b, cur = [], [], None
8for line in open("output.txt"):
9 line = line.strip()
10 if line.startswith("a = "):
11 cur = json.loads(line[4:])
12 elif line.startswith("b = "):
13 A.append(cur); b.append(int(line[4:]))
14A, b = np.array(A, dtype=np.int64), np.array(b, dtype=np.int64)
15
16def null_space(M):
17 """basis of { w : w^T M == 0 mod Q }"""
18 rows, cols = M.shape
19 W = [[int(M[j][i]) % Q for j in range(rows)] for i in range(cols)]
20 piv, r = [], 0
21 for c in range(rows):
22 p = next((x for x in range(r, cols) if W[x][c] % Q), None)
23 if p is None:
24 continue
25 W[r], W[p] = W[p], W[r]
26 inv = pow(W[r][c], Q - 2, Q)
27 W[r] = [(x * inv) % Q for x in W[r]]
28 for x in range(cols):
29 if x != r and W[x][c] % Q:
30 f = W[x][c]
31 W[x] = [(W[x][k] - f * W[r][k]) % Q for k in range(rows)]
32 piv.append(c); r += 1
33 out = []
34 for fc in [c for c in range(rows) if c not in piv]:
35 v = [0] * rows; v[fc] = 1
36 for i, pc in enumerate(piv):
37 v[pc] = (-W[i][fc]) % Q
38 out.append(v)
39 return np.array(out, dtype=np.int64)
40
41def noise(seed, n):
42 st = seed & 0xFFFFFFFF or 1
43 out = []
44 for _ in range(n):
45 st ^= (st << 13) & 0xFFFFFFFF
46 st ^= (st >> 17) & 0xFFFFFFFF
47 st ^= (st << 5) & 0xFFFFFFFF
48 out.append(-100 + st % 201)
49 return out
50
51# stage 1: one parity check on 257 samples -> OpenMP scan of 2^30 seeds
52w1 = null_space(A[:257])[0]
53np.savetxt("w.txt", w1, fmt="%d"); np.savetxt("b.txt", b[:257], fmt="%d")
54open("brute.c", "w").write(r'''
55#include <stdio.h>
56#include <stdint.h>
57#define Q 65537LL
58#define NS 257
59static long long w[NS], bv[NS];
60static inline uint32_t xs(uint32_t s){ s^=s<<13; s^=s>>17; s^=s<<5; return s; }
61int main(void){
62 FILE*f=fopen("w.txt","r"); for(int i=0;i<NS;i++) fscanf(f,"%lld",&w[i]); fclose(f);
63 f=fopen("b.txt","r"); for(int i=0;i<NS;i++) fscanf(f,"%lld",&bv[i]); fclose(f);
64 long long T=0; for(int i=0;i<NS;i++) T=(T+(w[i]%Q)*(bv[i]%Q))%Q;
65 FILE*o=fopen("cand.txt","w");
66 #pragma omp parallel
67 {
68 char buf[1<<16]; size_t bl=0;
69 #pragma omp for schedule(static)
70 for(long seed=0; seed<(1L<<30); seed++){
71 uint32_t s=(uint32_t)seed; if(!s) s=1;
72 long long acc=0;
73 for(int i=0;i<NS;i++){ s=xs(s); acc+=w[i]*(long long)(-100+(int)(s%201)); }
74 if(((acc%Q)+Q)%Q==T){ int n=snprintf(buf+bl,sizeof(buf)-bl,"%ld\n",seed);
75 if(n>0) bl+=n;
76 if(bl>sizeof(buf)-32){
77 #pragma omp critical
78 { fwrite(buf,1,bl,o); bl=0; }
79 } }
80 }
81 #pragma omp critical
82 if(bl) fwrite(buf,1,bl,o);
83 }
84 fclose(o); return 0;
85}
86''')
87subprocess.run(["gcc","-O3","-march=native","-fopenmp","-o","brute","brute.c"], check=True)
88subprocess.run(["./brute"], check=True)
89cands = [int(x) for x in open("cand.txt")]
90print("candidates:", len(cands))
91
92# stage 2: nine more congruences on all 265 samples -> one seed
93W = null_space(A)
94E = np.array([noise(sd, len(b)) for sd in cands])
95hit = np.where((((b[None, :] - E) % Q) @ W.T % Q == 0).all(axis=1))[0]
96seed = cands[hit[0]]
97print("seed:", seed)
98
99# stage 3: exact solve
100e = noise(seed, len(b))
101c = ((b - e) % Q).tolist()
102M = [[int(A[i][j]) % Q for j in range(N)] + [c[i]] for i in range(N)]
103for col in range(N):
104 p = next(r for r in range(col, N) if M[r][col] % Q)
105 M[col], M[p] = M[p], M[col]
106 inv = pow(M[col][col], Q - 2, Q)
107 M[col] = [(x * inv) % Q for x in M[col]]
108 for r in range(N):
109 if r != col and M[r][col] % Q:
110 f = M[r][col]
111 M[r] = [(M[r][k] - f * M[col][k]) % Q for k in range(N + 1)]
112s = [M[i][N] for i in range(N)]
113assert max((sum(int(A[j][i]) * s[i] for i in range(N)) + e[j] - int(b[j])) % Q
114 for j in range(len(b))) == 0
115print(bytes(s).split(b"_")[0].decode())
candidates: 16368
seed: 801158434
L3m0n{2d1bddb899ed4ed5f9ff16bd8038b643}
Note
The 256-dimensional lattice never had to be touched. The giveaway in hindsight: whenever a lattice challenge goes out of its way to mention a "custom" or "lightweight" noise generator, check whether that generator's seed space is small enough to brute-force before reaching for LLL/BKZ.