Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions crates/ssz-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,12 +582,7 @@ fn derive_decode_struct(
}
Ok(result)
} else {
// Variable-size: fall back to default
let item_size = <Self as libssz::SszDecode>::fixed_size();
bytes
.chunks_exact(item_size)
.map(Self::from_ssz_bytes)
.collect()
Err(libssz::DecodeError::NotFixedSize)

@MegaRedHand MegaRedHand Mar 31, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the equivalent of ssz_decode_fixed_vec but in the derive macro

}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/ssz/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub trait SszDecode: Sized {
#[cfg(feature = "alloc")]
fn ssz_decode_fixed_vec(bytes: &[u8]) -> Result<Vec<Self>, DecodeError> {
let item_size = Self::fixed_size();
if item_size == 0 {
return Err(DecodeError::NotFixedSize);
}
bytes
.chunks_exact(item_size)
.map(Self::from_ssz_bytes)
Expand Down
2 changes: 2 additions & 0 deletions crates/ssz/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub enum DecodeError {
MissingDelimiterBit,
/// A container has zero variable-length fields but leftover bytes.
AdditionalBytes { expected: usize, got: usize },
/// `ssz_decode_fixed_vec` was called on a variable-size type.
NotFixedSize,
}

#[cfg(feature = "std")]
Expand Down
Loading