Skip to content
wausPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

VDF

Wesolowski RSA-group verifiable delay function in Rust, Dart and Go. Verification requires the original payload, difficulty and public parameters. Proofs contain big-endian y and pi bytes.

Rust

let vdf = optimized_vdf::Wesolowski::with_modulus(modulus, 128)?;
let proof = vdf.prove(b"payload", difficulty, |progress| {
    println!("{:.1}%", progress.fraction() * 100.0);
})?;
let valid = vdf.verify(b"payload", difficulty, &proof)?;

prove blocks the calling thread; pass |_| {} to ignore progress. For scheduling and cancellation, use start_proof, call step(4096) until proof() is available, then into_proof(). Drop the session to cancel. Errors return VdfError; a failed session cannot resume. Supported parameters: odd modulus greater than 2, up to 65,536 bits; 2 <= k <= 4096.

Dart / Flutter

final vdf = Wesolowski.withModulus(modulus, 128);
final cancellation = ProveCancellationToken();
final proof = await vdf.prove(
  payload, difficulty,
  cancellationToken: cancellation,
  onProgress: (progress) => print(progress.completion),
);
final valid = vdf.verify(payload, difficulty, proof);

Computation runs in a worker isolate. Call cancellation.cancel() from your Cancel handler; the future throws ProveCancelledException after cleanup. Cancellation takes effect between chunks, after any current challenge search. Omit cancellationToken if unnecessary; use onProgress: (_) {} to ignore progress.

The package builds and bundles Rust automatically for Android, iOS, macOS, Linux and Windows. Install Rust, the target and the platform SDK/linker. If the native library cannot load, proving falls back to Dart; VdfNativeBackend.loadError exposes the cause. VDFRSA_NATIVE_LIB overrides library loading. For browsers, use the WASM build below.

Go

prover, err := vdf.NewWithModulus(modulus, 128)
if err != nil { return err }
proof, err := prover.Prove(payload, difficulty, func(progress float32) {
    fmt.Printf("%.1f%%\n", progress*100)
})
if err != nil { return err }
valid, err := prover.Verify(payload, difficulty, proof)

Pass nil to ignore progress. ProveAsync runs in a goroutine and returns result/error channels and a concurrency-safe Progress() accessor. Use PublicParams / NewWithPublicParams to share parameters across processes.

C / WASM

Enable the Cargo feature ffi for the C API. The Dart build hook enables it automatically; Rust callers do not need it.

rustup target add wasm32-unknown-unknown
cargo build --release --lib --features ffi --target wasm32-unknown-unknown

Output: target/wasm32-unknown-unknown/release/optimized_vdf.wasm. Call its C API exports through WebAssembly; pass difficulty as JavaScript BigInt. Run computation in a Web Worker. Copy proof bytes before freeing the prover; serialize calls on each handle.

Android ARMv7

The Dart build hook enables vendored OpenSSL for armv7-linux-androideabi. Besides the Android NDK, the build host needs Perl and make. Set ANDROID_NDK_HOME or ANDROID_NDK_ROOT; alternatively the hook discovers the NDK under ANDROID_HOME / ANDROID_SDK_ROOT.

For a direct Cargo build, enable --features openssl-sys explicitly. Other targets, including WASM, use Rust arithmetic by default.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages