Jittered side-channel trace hypothesis scan
/app/cpu/main.cpp is the source of a multicore CPU program (C++17, OpenMP).
The program takes one input-file path (PROGRAM INPUT_FILE) and writes its result to stdout.
What the program computes
A side-channel analyst has many short, noisy measurements of an unknown byte operation. The program generates G independent campaigns, corrects a drifting baseline in each trace, scores all 256 byte hypotheses at every sample, and reports the strongest peaks plus a checksum of the full score surface. Each campaign contains N traces of T signed samples. Public parameters and a 64-bit seed generate the bulk data deterministically inside the program.
For trace i, plaintext p_i is generated by mix64(seed ^ campaign_tag ^ i_tag) & 255. The campaign's hidden byte is also generated from the seed. A hypothesis h predicts the centered leakage popcount(F(p_i xor h)) - 4, where F(x) = rotl8((77x+29) mod 256,3) xor (13x+5) mod 256. Measurements contain deterministic hash noise, a per-trace offset, a jittered pulse from the hidden byte and a weaker distractor pulse from a second byte. The offset estimate is the integer mean of the first four samples; it is subtracted from every sample.
For each (h,t) with t >= 4, the exact integer score is the absolute centered cross-moment |N sum_i(l_i y_it) - (sum_i l_i)(sum_i y_it)|. The program ranks all pairs by descending score, then smaller hypothesis and earlier sample, and emits the top three plus a mixed checksum over every pair's score. The checksum makes the full scan part of the answer even when the top peak is obvious.
The task tests reuse across a hypothesis-by-time-by-trace computation, irregular leakage values, exact reductions, baseline correction and deterministic ranking. It is distinct from block-cipher avalanche testing, which measures differences between chosen plaintext/ciphertext pairs rather than inferring leakage from noisy traces.
Input format
One line: G N T SEED. 1 <= G <= 64, 1 <= N <= 65536, 4 <= T <= 256, SEED is an unsigned 64-bit decimal integer.
Output format
One line per campaign:
batch B hash=HHHHHHHHHHHHHHHH top=H:T:S,H:T:S,H:T:S
The hash is 16 lowercase hexadecimal digits. When T=4, no score pairs exist and top=none. All scores are unsigned decimal integers. Candidate pairs are unique. This is exact-output grading.
Hidden inputs
Correctness inputs cover N=1, non-power-of-two trace counts, T=4, multiple campaigns, and varied seeds. The timing case is G=64, N=65536, T=256 at scale 1.0. Only the number of independent campaigns scales for smaller timing inputs. CPU and CUDA must reproduce the same 64-bit hash arithmetic, signed integer division truncation, and ranking tie-breaks.
Your task
Port this program to CUDA in /app/gpu/main.cu: same command line (PROGRAM INPUT_FILE),
same output on stdout. Then make it as fast as you can on the GPU while keeping the output correct.
The main computation must execute on the GPU. Renaming CPU code to .cu, running a
CPU fallback, or launching a dummy kernel while computing the answer on the CPU does not satisfy this task.
The CPU source is the specification: when this text and the code disagree, the code wins.
This sandbox is for writing the source only: it has g++ and the CPU program, but no CUDA
compiler and no GPU. Compilation, execution and verification happen later on an H100 in a
separate verifier, and a port that does not compile is rejected, so check your logic against
the CPU program before you finish (for example by emulating your kernels on the host).
How your port is verified
- Only
/app/gpu/main.cuis collected. It is compiled withnvcc -O3 -arch=sm_90 -std=c++17 -o port /app/gpu/main.cu; no extra libraries are linked. The CUDA runtime and the header-only libraries that ship with the CUDA toolkit (CUB, Thrust, libcu++) are allowed. - Your source must not contain any of:
system(,popen(,fork(,exec*,dlopen(,getenv(,#include <filesystem>,/tests/,/proc/. The program may read only the input file it is given. - Verification runs on one H100 in a fresh container without network. Hidden inputs are generated with a fresh random seed at verification time.
- Correctness: every hidden input (small edge cases plus a large timing input) must pass. Your output must be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout is rejected.
- GPU execution is checked: a port that computes its answer on the CPU is rejected even when its output is correct.
- Speed: The scale-1.0 input runs 64 independent campaigns with 65536 traces and 256 samples each; the scan evaluates about 270 billion trace-hypothesis-time contributions.
/app/inputs/timing_example.inhas the shape and size of the hidden timing input. Your port is timed against a reference GPU port on it; the faster your port, the higher its score. /app/inputs/holds public input examples for understanding the input format.