Skip to content

Commit

Permalink
add new error variant + semicolon fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rista404 committed Apr 26, 2024
1 parent 1ad3fbc commit 3fc1440
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 1 addition & 3 deletions ssz-rs/src/merkleization/compact_multiproofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ fn compute_bits_from_proof_descriptor(descriptor: &[u8]) -> Result<Vec<bool>, Er

// Check mismatch condition at the last index
if (count_0_vs_1 < 0) != (i == last_one_index) {
return Err(Error::InvalidDescriptor(
"Mismatch in count of '0's vs '1's at the last index".to_string(),
));
return Err(Error::InvalidIndexBalanceInDescriptor);
}
}

Expand Down
3 changes: 3 additions & 0 deletions ssz-rs/src/merkleization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub enum MerkleizationError {
InvalidPathElement(PathElement),
/// Signals an invalid path when walking a `GeneralizedIndexable` type
InvalidPath(Vec<PathElement>),
/// Signals an invalid balance in a descriptor
InvalidIndexBalanceInDescriptor,
/// Signals an invalid descriptor was provided or calculated
InvalidDescriptor(String),
/// Attempt to prove an inner element outside the bounds of what the implementing type
Expand Down Expand Up @@ -59,6 +61,7 @@ impl Display for MerkleizationError {
Self::InvalidPathElement(element) => write!(f, "invalid path element {element:?}"),
Self::InvalidPath(path) => write!(f, "invalid path {path:?}"),
Self::InvalidDescriptor(err) => write!(f, "invalid descriptor {err:?}"),
Self::InvalidIndexBalanceInDescriptor => write!(f, "mismatch in count of '0's vs '1's at the last index in proof descriptor"),
Self::InvalidInnerIndex => write!(f, "requested to compute proof for an inner element outside the bounds of what this type supports"),
Self::NoInnerElement => write!(
f,
Expand Down
4 changes: 2 additions & 2 deletions ssz-rs/src/merkleization/multiproofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ pub fn calculate_multi_merkle_root(
indices: &[GeneralizedIndex],
) -> Result<Node, Error> {
if leaves.len() != indices.len() {
return Err(Error::InvalidProof);
return Err(Error::InvalidProof)
}
let helper_indices = get_helper_indices(indices);
if proof.len() != helper_indices.len() {
return Err(Error::InvalidProof);
return Err(Error::InvalidProof)
}

let mut objects = HashMap::new();
Expand Down

0 comments on commit 3fc1440

Please sign in to comment.