Skip to content

Commit 7d22a13

Browse files
authored
fix(mpt): Empty root node case (op-rs#705)
1 parent 6b6a881 commit 7d22a13

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Diff for: crates/mpt/src/node.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,15 @@ impl TrieNode {
109109
}
110110

111111
/// Returns the commitment of a [TrieNode::Blinded] node, if `self` is of the
112-
/// [TrieNode::Blinded] variant.
112+
/// [TrieNode::Blinded] or [TrieNode::Empty] variants.
113113
///
114114
/// ## Returns
115115
/// - `Some(B256)` - The commitment of the blinded node
116116
/// - `None` - `self` is not a [TrieNode::Blinded] node
117117
pub const fn blinded_commitment(&self) -> Option<B256> {
118118
match self {
119119
Self::Blinded { commitment } => Some(*commitment),
120+
Self::Empty => Some(EMPTY_ROOT_HASH),
120121
_ => None,
121122
}
122123
}
@@ -681,6 +682,12 @@ mod test {
681682
use alloy_trie::{HashBuilder, Nibbles};
682683
use rand::prelude::SliceRandom;
683684

685+
#[test]
686+
fn test_empty_blinded() {
687+
let trie_node = TrieNode::Empty;
688+
assert_eq!(trie_node.blinded_commitment().unwrap(), EMPTY_ROOT_HASH);
689+
}
690+
684691
#[test]
685692
fn test_decode_branch() {
686693
const BRANCH_RLP: [u8; 83] = hex!("f851a0eb08a66a94882454bec899d3e82952dcc918ba4b35a09a84acd98019aef4345080808080808080a05d87a81d9bbf5aee61a6bfeab3a5643347e2c751b36789d988a5b6b163d496518080808080808080");

0 commit comments

Comments
 (0)