Skip to content

Commit

Permalink
sealable-tire: verify expected error when hashing Extension nodes
Browse files Browse the repository at this point in the history
Addresses a left-over `XXX` comment which slipped in previous commit.
Extension nodes never have empty keys.  Panic if that’s not held when
calculating node’s hash.

This mirrors code in SetContext::handle_extension where the opposite
invariant is held and code panics if the key is too long.
  • Loading branch information
mina86 committed Sep 13, 2023
1 parent 6682e8a commit 1359d80
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions sealable-trie/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,16 @@ impl<'a, P, S> Node<'a, P, S> {
// tag = 0b100v_0000 where v indicates whether the child is
// a value reference.
let tag = 0x80 | (u8::from(child.is_value()) << 4);
// XXX
if let Ok(len) = key.encode_into(key_buf, tag) {
buf[len..len + 32].copy_from_slice(child.hash().as_slice());
len + 32
} else {
return hash_extension_slow_path(*key, child);
match key.encode_into(key_buf, tag) {
Ok(len) => {
buf[len..len + 32]
.copy_from_slice(child.hash().as_slice());
len + 32
}
Err(bits::EncodeError::EmptySlice) => {
return hash_extension_slow_path(*key, child);
}
Err(bits::EncodeError::SliceTooLong) => unreachable!(),
}
}
};
Expand Down

0 comments on commit 1359d80

Please sign in to comment.