Skip to content

Commit

Permalink
check digest on deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
plafer committed Jul 3, 2024
1 parent 858582a commit 4e5efd3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions core/src/mast/serialization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,7 @@ fn try_info_to_mast_node(
let mast_node_variant = mast_node_info.ty.variant()?;

// TODOP: Make a faillible version of `MastNode` ctors
// TODOP: Check digest of resulting `MastNode` matches `MastNodeInfo.digest`?
match mast_node_variant {
let mast_node = match mast_node_variant {
MastNodeTypeVariant::Block => {
let num_operations_and_decorators =
EncodedMastNodeType::decode_u32_payload(&mast_node_info.ty);
Expand Down Expand Up @@ -432,6 +431,16 @@ fn try_info_to_mast_node(
}
MastNodeTypeVariant::Dyn => Ok(MastNode::new_dynexec()),
MastNodeTypeVariant::External => Ok(MastNode::new_external(mast_node_info.digest)),
}?;

if mast_node.digest() == mast_node_info.digest {
Ok(mast_node)
} else {
Err(DeserializationError::InvalidValue(format!(
"MastNodeInfo's digest '{}' doesn't match deserialized MastNode's digest '{}'",
mast_node_info.digest,
mast_node.digest()
)))
}
}

Expand Down

0 comments on commit 4e5efd3

Please sign in to comment.