11 breaking releases

new 0.20.0 Feb 4, 2026
0.18.1 Jan 21, 2026
0.17.1 Dec 7, 2025
0.16.0 Oct 24, 2025
0.4.0 Oct 4, 2024

#8 in #nested-struct

Download history 171/week @ 2025-10-15 340/week @ 2025-10-22 76/week @ 2025-10-29 41/week @ 2025-11-05 89/week @ 2025-11-12 143/week @ 2025-11-19 61/week @ 2025-11-26 167/week @ 2025-12-03 184/week @ 2025-12-10 90/week @ 2025-12-17 79/week @ 2025-12-24 103/week @ 2025-12-31 281/week @ 2026-01-07 494/week @ 2026-01-14 194/week @ 2026-01-21 538/week @ 2026-01-28

1,520 downloads per month
Used in 12 crates (3 directly)

Apache-2.0

1.5MB
31K SLoC

Light Protocol SDK Macros

A collection of procedural macros for the Light Protocol SDK.

LightHasher

The LightHasher derive macro implements cryptographic hashing for struct types, providing implementations of the ToByteArray and DataHasher traits.

Attributes

  • #[hash]: Truncates field data to BN254 field size (for large types)
  • #[skip]: Ignores field during hashing

Example

#[derive(LightHasher, Clone)]
pub struct MyNestedStruct {
    pub a: i32,
    pub b: u32,
    #[hash]
    pub c: String,
}

#[derive(LightHasher, Clone)]
pub struct MyAccount {
    pub a: bool,
    pub b: u64,
    pub c: MyNestedStruct,
    #[hash]
    pub d: [u8; 32],
    pub f: Option<usize>,
}

Debug

RUST_BACKTRACE=1 cargo test

Prints DataHasher::hash() inputs.

Testing

This crate includes a comprehensive test suite:

# Run all tests
cargo test

# Run fuzzing tests
cargo test --test hasher_fuzz
cargo test --test fuzz_runner

Fuzzing

For deep, comprehensive fuzzing with cargo-fuzz:

# Install cargo-fuzz (requires nightly Rust)
cargo install cargo-fuzz

# Run the structure generator fuzzer (tests runtime behavior)
cargo +nightly fuzz run struct_generation -- -max_total_time=300

# Run the macro input fuzzer (tests parsing various struct definitions)
cargo +nightly fuzz run macro_input -- -max_total_time=300

For more details, see the fuzzing documentation.

Dependencies

~7–9.5MB
~194K SLoC