Skip to content

Commit 5b6dd17

Browse files
authored
Dynamic bitfield length for lighthouse issue #6757 (#46)
* add dynamic bitvector module * add dynamic module * make dynamic submodule to preserve private fields * comment * add tests, clean up files * comment cleanup * tests proving from_bytes equivalence and max_length usage * clippy * fix potential out of bounds and remove unwraps in union and intersection * add serde test * clippy (not mine) * fix failing test * test serialize and deserialise * serde testing * deserialize serde test * remove test unwraps * tidy error message in tests * Use iter_mut().enumerate() in bitvector_dynamic * cargo fmt
1 parent 7168af7 commit 5b6dd17

File tree

4 files changed

+516
-1
lines changed

4 files changed

+516
-1
lines changed

ssz/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ name = "ssz"
1616
[dev-dependencies]
1717
alloy-primitives = { version = "1.0", features = ["getrandom"] }
1818
ethereum_ssz_derive = { version = "0.9.0", path = "../ssz_derive" }
19+
serde_json = "1.0.0"
1920

2021
[dependencies]
2122
alloy-primitives = "1.0"

ssz/src/bitfield.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use serde::ser::{Serialize, Serializer};
55
use serde_utils::hex::{encode as hex_encode, PrefixedHexVisitor};
66
use smallvec::{smallvec, SmallVec, ToSmallVec};
77
use typenum::Unsigned;
8+
pub mod bitvector_dynamic;
89

910
/// Returned when an item encounters an error.
1011
#[derive(PartialEq, Debug, Clone)]
@@ -406,7 +407,7 @@ impl<T: BitfieldBehaviour> Bitfield<T> {
406407
.get(i / 8)
407408
.ok_or(Error::OutOfBounds { i, len: self.len })?;
408409

409-
Ok(*byte & 1 << (i % 8) > 0)
410+
Ok(*byte & (1 << (i % 8)) > 0)
410411
} else {
411412
Err(Error::OutOfBounds { i, len: self.len })
412413
}

0 commit comments

Comments
 (0)