GitHub - ovasylenko/g6k-rs

3 min read Original article ↗

g6k-rs is a research-oriented Rust library for lattice reduction, enumeration, and sieving on CPUs, Apple Metal, and NVIDIA CUDA.

The crate includes floating-point and arbitrary-precision reduction, exact invariant checks, deterministic examples, and optional GPU backends. It is an experimental implementation: APIs may change, and it has not been audited for use in production cryptographic systems.

Try it

The quickest path uses only the portable floating-point feature set:

git clone https://github.com/ovasylenko/g6k-rs.git
cd g6k-rs
./scripts/quickstart.sh

The script runs a deterministic LLL/BKZ example and verifies its determinant invariant. The first build compiles dependencies and therefore takes longer than subsequent runs.

Add the crate to a Rust project with:

[dependencies]
g6k-rs = "0.1"
use g6k_rs::{LLLParams, LatticeBasis, lll_reduce};

let mut basis = LatticeBasis::from_rows(vec![
    vec![1.0, 1.0],
    vec![-1.0, 2.0],
]);
lll_reduce(&mut basis, &LLLParams::default()).unwrap();

The default build enables arbitrary-precision support through the mpz feature. Set default-features = false for the floating-point API only.

What is implemented

  • Floating-point LLL, BKZ, deep insertion, slide reduction, and self-dual reduction.
  • Babai-style CVP, pruned enumeration, rerandomized enumeration, and pruning profile optimization.
  • BDGL, BGJ1, and HK3-style lattice sieves with deterministic CPU and parallel paths.
  • Arbitrary-precision lattice arithmetic and reduction through rug/GMP/MPFR.
  • Optional Metal and CUDA sieve, enumeration, and Seysen-conditioning paths.
  • Exact or independently recomputed checks for determinant preservation, coordinate reconstruction, integral output, and returned candidate norms.

See the examples guide for task-oriented snippets and project status for maturity and limitations.

Relationship to G6K and fplll

The name describes the project's goal: exploring a Rust implementation of the lattice-reduction and sieving problem space associated with the General Sieve Kernel. It is not an official port, release, or drop-in replacement for fplll/G6K.

Project Primary interface Focus
g6k-rs Rust library Rust APIs, exact checks, CPU/Metal/CUDA experiments
G6K Python + C++ Established General Sieve Kernel research implementation
fplll C++ library + CLI Mature lattice reduction and enumeration tooling

No claim is made that g6k-rs is faster, more complete, or a compatible replacement. Read PROVENANCE.md before redistributing or relicensing the project.

Verification

# Portable floating-point build and tests
cargo test --no-default-features

# Default build, including arbitrary precision
cargo test

# Formatting and linting
cargo fmt --check
cargo clippy --all-targets -- -D warnings

The last locally observed default-platform run completed 1,813 tests with no failures; ignored tests include slow probes and hardware-dependent paths. That number is a development reference, not a substitute for the current CI result. GPU tests require the corresponding feature, toolchain, and device.

GPU features

  • metal-gpu (macOS): Metal sieve kernels, GPU Seysen conditioning, and Metal-backed reduction entry points.
  • metal-fp16: experimental half-precision database storage on top of metal-gpu.
  • cuda-gpu (Linux/NVIDIA): CUDA sieve, enumeration, and Seysen kernels. The build requires nvcc; set G6K_CUDA_ARCH to the target architecture, such as sm_89.

Use the GPU testing guide for build and validation commands. Hardware measurements and the rules for making performance claims live in BENCHMARKING.md.

Documentation

License

Licensed under either the Apache License 2.0 or the MIT License, at your option.

Maintainer: Oleksii Vasylenko (hello@ovasylenko.com).