6 releases ()

1.0.0-beta.0 Jan 16, 2023
0.6.0 Dec 7, 2023
0.5.4 Jun 14, 2023
0.5.3 May 26, 2023
0.5.0 Jan 17, 2023

#579 in Magic Beans

Download history 632/week @ 2023-12-22 819/week @ 2023-12-29 2041/week @ 2024-01-05 2173/week @ 2024-01-12 2960/week @ 2024-01-19 3039/week @ 2024-01-26 3410/week @ 2024-02-02 2045/week @ 2024-02-09 2654/week @ 2024-02-16 2734/week @ 2024-02-23 2702/week @ 2024-03-01 4181/week @ 2024-03-08 2786/week @ 2024-03-15 3262/week @ 2024-03-22 2648/week @ 2024-03-29 2283/week @ 2024-04-05

11,639 downloads per month
Used in bzb_execution_layer

Apache-2.0

92KB
2K SLoC

ssz_types

List, vector and bitfield types for SSZ.

Maintained by Sigma Prime for use in Lighthouse, with an eye to being useful in the Rust Ethereum ecosystem more broadly. We welcome new contributors!

Please see the docs for more information.


lib.rs:

Provides types with unique properties required for SSZ serialization and Merklization:

  • FixedVector: A heap-allocated list with a size that is fixed at compile time.
  • VariableList: A heap-allocated list that cannot grow past a type-level maximum length.
  • BitList: A heap-allocated bitfield that with a type-level maximum length.
  • BitVector: A heap-allocated bitfield that with a type-level fixed_ length.

These structs are required as SSZ serialization and Merklization rely upon type-level lengths for padding and verification.

Adheres to the Ethereum 2.0 SSZ specification at v0.12.1.

Example

use ssz_types::*;

pub struct Example {
    bit_vector: BitVector<typenum::U8>,
    bit_list: BitList<typenum::U8>,
    variable_list: VariableList<u64, typenum::U8>,
    fixed_vector: FixedVector<u64, typenum::U8>,
}

let mut example = Example {
    bit_vector: Bitfield::new(),
    bit_list: Bitfield::with_capacity(4).unwrap(),
    variable_list: <_>::from(vec![0, 1]),
    fixed_vector: <_>::from(vec![2, 3]),
};

assert_eq!(example.bit_vector.len(), 8);
assert_eq!(example.bit_list.len(), 4);
assert_eq!(&example.variable_list[..], &[0, 1]);
assert_eq!(&example.fixed_vector[..], &[2, 3, 0, 0, 0, 0, 0, 0]);

Dependencies

~11MB
~296K SLoC