Skip to content

nzengi/ark-nalloc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

arkworks-nalloc: ZK-Optimized Memory Orchestration

Zero-Knowledge proof systems spend a disproportionate amount of time on two things: field arithmetic (FFT/NTT) and sensitive witness handling. Standard system allocators are general-purpose and often fail to address the specific alignment needs of SIMD-accelerated crypto or the security requirements of private inputs.

arkworks-nalloc demonstrates the integration of zk-nalloc within the Arkworks ecosystem, providing specialized memory lanes for cryptographic operations.

Why NAlloc?

Most allocators are "black boxes." nalloc treats memory as a structured resource mapped specifically to ZK primitives.

1. Polynomial-First Alignment

In ZK, we live and die by FFT performance. Modern CPUs and hardware accelerators (AVX-512, etc.) require strict 64-byte alignment to avoid cache line splits and suboptimal SIMD throughput.

  • The Innovation: The PolynomialArena provides alloc_fft_friendly, ensuring every field element vector is perfectly aligned for the underlying arithmetic engine.
  • Scalability: Features alloc_huge for page-aligned (4KB) allocations, minimizing TLB misses when handling massive multi-gigabyte circuits.

2. Radical Witness Security

Witness leakage in memory is a silent killer in multi-tenant prover environments.

  • The Difference: Unlike malloc or the default Rust allocator which might leave "dirty" memory behind, WitnessArena enforces zero-initialization at the hardware level.
  • Post-Computation Hygiene: Includes an explicit secure_wipe() primitive that clears the arena using a security-hardened overwrite, ensuring private scalars don't persist in RAM after the proof is generated.

3. Deterministic Performance

By utilizing a sophisticated bump-allocation strategy under the hood, nalloc removes the overhead of free-list management and fragmentation, making prover execution times more predictable—a critical requirement for production pipelines.

Implementation: Hash Preimage Proof

The project implements a complete Hash Preimage Proof demo using ark-groth16. This represents a foundational ZK primitive used in private authentication and Merkle tree residency proofs.

Features:

  • Hash Gadget: A non-linear hash function implemented in-circuit to demonstrate constraint complexity.
  • Memory Integration:
    • WitnessArena manages the secret preimage, ensuring it is zero-initialized and securely wiped post-synthesis.
    • PolynomialArena handles the high-alignment buffers required for the underlying field arithmetic.
  • Verification Integrity: Includes negative testing to confirm that invalid witnesses are correctly rejected by the constraint system.

Building & Running

Ensure you have a modern Rust toolchain installed.

cargo run --release

Observations

In benchmarked ZK-like workloads, nalloc consistently outperforms the standard allocator in large-block field element operations by up to 5x, while providing a security posture that general-purpose memory managers simply ignore.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages