4 releases (breaking)

new 0.5.1 Apr 16, 2025
0.5.0 Apr 15, 2025
0.4.0 Oct 4, 2024
0.3.0 Sep 20, 2024
0.1.0 Sep 9, 2024

#149 in #light

Download history 262/week @ 2024-12-24 193/week @ 2024-12-31 82/week @ 2025-01-07 355/week @ 2025-01-14 309/week @ 2025-01-21 584/week @ 2025-01-28 570/week @ 2025-02-04 491/week @ 2025-02-11 327/week @ 2025-02-18 288/week @ 2025-02-25 332/week @ 2025-03-04 271/week @ 2025-03-11 184/week @ 2025-03-18 231/week @ 2025-03-25 109/week @ 2025-04-01 195/week @ 2025-04-08

788 downloads per month
Used in 5 crates (via light-sdk)

Apache-2.0

170KB
3.5K 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

~8.5MB
~164K SLoC