pub struct CoreLibrary(/* private fields */);Expand description
The Miden core library, providing a set of optimized procedures for Miden programs.
This library wraps a Package containing highly-optimized and battle-tested implementations
of commonly-used primitives. When the core library is dynamically linked during assembly time,
procedures can be called from any Miden program and are serialized as 32 bytes, reducing the
amount of code that needs to be shared between parties for proving and verifying program
execution.
§Contents
The core library provides several categories of functionality:
- Cryptographic primitives: Hash functions (Keccak256, SHA-512), digital signature verification (ECDSA, EdDSA-Ed25519, Falcon), and authenticated encryption (AEAD decryption).
- Mathematical operations: Division operations for u64, u128, and u256.
- Data structures: Sparse Merkle Tree operations, Merkle Mountain Range (MMR), and sorted array utilities with lower-bound search capabilities.
- Memory operations: Efficient hashing and “un-hashing” of large amounts of data.
Many of these operations are implemented as precompiles - special procedures that execute outside the Miden VM but are verified as part of the proof. Precompiles allow for efficient execution of complex operations that would be expensive to compute directly in the VM, while maintaining the security guarantees of the Miden proof system. The core library includes precompiles for cryptographic operations like hash functions and signature verification.
§Usage
The core library is typically used with the assembler to enable core library procedures in compiled programs:
use miden_assembly::{Assembler, Linkage};
use miden_core_lib::CoreLibrary;
let core_lib = CoreLibrary::default();
let assembler = Assembler::new(source_manager)
.with_package(core_lib.package(), Linkage::Dynamic)
.unwrap();For program execution, you’ll also need to register the event handlers:
let handlers = core_lib.handlers();
// Register handlers with your host...Stack and memory print-style debug handlers are registered with stdout writers by default. These handlers can print private values if a program moves witness data onto the operand stack or into memory. Privacy-sensitive hosts should replace or unregister these handlers. Advice debug handlers can expose witness data directly, so hosts must opt into those explicitly.
For proof verification, use verifier_registry() to get the
precompile verifiers required to validate core library precompile requests.