Skip to main content
Version: 0.16 (unstable)

Miden Core Library

Miden core library provides a set of procedures which can be used by any Miden program. These procedures build on the core instruction set of Miden assembly expanding the functionality immediately available to the user.

The goals of Miden core library are:

  • Provide highly-optimized and battle-tested implementations of commonly-used primitives.
  • Reduce the amount of code that needs to be shared between parties for proving and verifying program execution.

The second goal can be achieved because calls to procedures in the core library can always be serialized as 32 bytes, regardless of how large the procedure is.

Terms and notations

In this document we use the following terms and notations:

  • A field element is an element in a prime field of size p=264232+1p = 2^{64} - 2^{32} + 1.
  • A binary value means a field element which is either 00 or 11.
  • Inequality comparisons are assumed to be performed on integer representations of field elements in the range [0,p)[0, p).

Throughout this document, we use lower-case letters to refer to individual field elements (e.g., aa). Sometimes it is convenient to describe operations over groups of elements. For these purposes we define a word to be a group of four elements. We use upper-case letters to refer to words (e.g., AA). To refer to individual elements within a word, we use numerical subscripts. For example, a0a_0 is the first element of word AA, b3b_3 is the last element of word BB, etc.

Organization and usage

Procedures in the Miden Core Library are organized into modules, each targeting a narrow set of functionality. Modules are grouped under higher-level namespaces, e.g. miden::core::math. These higher-level namespaces are structured to not contain any items directly - instead, procedures and other items are defined in submodules of these high-level namespaces, e.g. miden::core::math::u64 which provides useful 64-bit unsigned integer arithmetic procedures and constants.

For an example of how to invoke procedures from imported modules see this section. Users should load CoreLibrary to access modules under the miden::core namespace. Core wrappers may use bundled precompile-backed verification internally, but users should rely on the stable miden::core::* facades.

Available modules

Currently, Miden core library contains just a few modules, which are listed below. Over time, we plan to add many more modules which will include various cryptographic primitives, additional numeric data types and operations, and many others.

ModuleDescription
miden::core::collections::mmrContains procedures for manipulating Merkle Mountain Ranges.
miden::core::collections::smtContains procedures for manipulating Sparse Merkle Trees with 4-element keys and values.
miden::core::collections::sorted_arrayContains procedures for searching in sorted arrays of words.
miden::core::pcs::fri::frie2f4Contains procedures for verifying FRI proofs (field extension = 2, folding factor = 4).
miden::core::stark::modContains procedures and helpers used when verifying STARK proofs inside the VM.
miden::core::crypto::aeadContains procedures for authenticated encryption with associated data (AEAD) using Poseidon2 hash.
miden::core::crypto::dsa::ecdsa_k256_keccakProves the existence of an ECDSA-valid secp256k1/Keccak256 advice witness; it does not bind a canonical Ethereum signature encoding.
miden::core::crypto::dsa::falcon512_poseidon2Contains procedures for verifying Poseidon2 Falcon512 post-quantum signatures.
miden::core::crypto::hashes::blake3Contains procedures for computing hashes using BLAKE3 hash function.
miden::core::crypto::hashes::keccak256Contains procedures for computing hashes using Keccak256.
miden::core::crypto::hashes::poseidon2Contains procedures for computing hashes using the Poseidon2 hash function.
miden::core::crypto::hashes::sha256Contains procedures for computing hashes using SHA256 hash function.
miden::core::math::u64Contains procedures for working with 64-bit unsigned integers.
miden::core::math::u128Contains procedures for working with 128-bit unsigned integers.
miden::core::math::u256Contains procedures for working with 256-bit unsigned integers.
miden::core::memContains procedures for working with random access memory.
miden::core::sysContains system-level utility procedures.
miden::core::sys::vmContains VM-facing utility procedures needed during Miden VM recursive proof verification.
miden::core::wordContains utilities for working with words.