Transparency-log audit: SHA-256 Merkle trees and inclusion proofs
/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 transparency-log auditor run (Certificate-Transparency / blockchain light-client style) over
L append-only logs of very different sizes, with SHA-256 (FIPS 180-4) as the hash:
- Leaf hashing. Log
thasn_trecords. Recordkof logthas the per-record seedls = gen64(gen64(SEED, t), k), lengthlen = LMIN + ls mod (LMAX - LMIN + 1)bytes and data bytej= bytej mod 8(little-endian) ofgen64(ls, j / 8). Its leaf hash isSHA256(0x00 || t as u32 little-endian || k as u64 little-endian || data). - Tree building. Each log's tree is built bottom-up: level
l + 1nodeiisSHA256(0x01 || (l+1) as one byte || node(l, 2i) || node(l, 2i+1))(66-byte message); when a level has an odd number of nodes, its last node is promoted to the next level unchanged. The root of an empty log isSHA256(""), of a one-record log its leaf hash. All logs are processed level by level (interiorcounts the hashed nodes). - Proof audit.
QPinclusion-proof queries are answered by a partly faulty mirror (only if at least one log is nonempty). Queryqusesh0, h1, h2 = gen64(gen64(SEED, 2^48 - 1), 4q + 0/1/2): log = the(h0 mod #nonempty)-th nonempty log, leafk = h1 mod n, fault class from(h0 >> 32) mod 100:< 70honest,< 80tampered record (data bith2 mod 8 lenflipped),< 90tampered sibling (path entryh2 mod pathlen, bit(h2 >> 32) mod 256of the big-endian-word digest, honest if the path is empty), else wrong claimed index (k xor 2^(h2 mod bitlen(n - 1)), or(k + 1) mod nif that is out of range; honest ifn < 2). The audit path holds the existing siblings from the leaf level up. The client recomputes the leaf hash for the claimed index and folds the path (left/right from the index bits, no path entry where the node is a promoted last node); the proof is valid if the path is used up exactly and the result equals the log's root. If the path runs out early the proof is invalid and the partial hash is used in the checksum. - Report. Every tree head, counts, and per fault class the number of proofs and of valid
proofs, plus
rootsum= sum over queries ofmix64(q ^ (w0 << 32 | w1))of the recomputed digest words.
Input format
L LMIN LMAX QP SEED
n_0
...
n_{L-1}
1 <= L <= 64, 1 <= LMIN <= LMAX <= 1024, 0 <= n_t <= 2^23, total records <= 3*10^7,
0 <= QP <= 1.2*10^7, SEED unsigned 64-bit.
Output format
L lines log t n=.. levels=.. root=<64 hex digits>, then leaves=.. interior=..,
proofs=.. pathlen_sum=.. rootsum=<16 hex digits>, and four lines
honest|bad_leaf|bad_sibling|bad_index count=.. valid=...
Hidden inputs
Correctness inputs (11 files) include empty logs, logs of 1, 2, 3, 4, 5, 7, 8, 9 records,
sizes 2^k - 1, 2^k, 2^k + 1, 2^17 + 3, 64 logs, one-byte and 1024-byte records, QP = 0,
inputs where all logs are empty, seeds 0 and 2^64 - 1, and random inputs with
n_t <= 60000, QP <= 50000. The timing input has the shape and size of /app/inputs/timing_example.in.
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:
/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.