Skip to main content

zisklib

ZiskLib is the high-level safe layer over the VM syscalls. Each function dispatches to a dedicated state machine inside the zkVM, covering hash functions and elliptic curve arithmetic for secp256k1, secp256r1, BN254, BLS12-381, and Ed25519.

Signatures and the hints feature

The signatures on these pages are for the ziskos crate, which has no hints feature (Cargo rejects features = ["hints"]). The same source is also built as the ziskos-hints crate, where the hints feature is on by default: there the crypto and big-integer functions each gain a trailing hints: &mut Vec<u64> parameter used to record proving hints.

Every function is re-exported at the crate root, so the canonical path is flat — e.g. ziskos::zisklib::sha256 — regardless of which submodule it lives in.

C-ABI variants

Many functions also have a #[no_mangle] extern "C" form with a _c suffix, such as scalar_mul_bn254_c or checked_add256_c, for C and C++ guests. They take raw *const u64 / *mut u64 limb pointers instead of arrays and slices, and return status codes instead of Result. Only the two added in 1.4.0-alpha, ecdsa_verify_secp256k1_c and pairing_batch_safe_bn254_c, have their own entries. For the rest, see the # Safety comments in ziskos/entrypoint/src/zisklib/lib/.

Standard zkVM C interfaces

zisklib also implements the zkVM standards' C interfaces, for C and C++ guests and for toolchains that target them:

  • zisklib::zkvm_accelerators: the 19 functions of the standard zkvm_accelerators.h interface (zkvm_keccak256, zkvm_sha256, zkvm_modexp, zkvm_bn254_pairing, zkvm_bls12_g1_msm, zkvm_kzg_point_eval, zkvm_secp256k1_ecrecover, and so on).
  • zisklib::zkvm_accelerators_ext: 6 non-standard 256-bit modular arithmetic functions (zkvm_mulmod256, zkvm_add_mod256, zkvm_inv_mod256, ...), declared in zkvm_accelerators_ext.h.
  • zisklib::zkvm_io::{read_input, write_output}: the standard zkvm_io.h interface. read_input returns the first input record and does not advance the io read cursor, so use either it or io::read* for a given input, not both. write_output appends to the same public-output stream as io::commit_slice.

These are not documented function by function here; see the # Safety comments in ziskos/entrypoint/src/zisklib/lib/zkvm_accelerators*.rs and zkvm_io.rs.

Not the zisklib crate in ziskasm

This module is ziskos::zisklib. The ZisK repository also contains an unpublished crate named zisklib in ziskasm/lang/rust, a set of bindings for the hand-written ZisK assembly routines used by examples and test guests. It is unrelated to the API on these pages.