Skip to content

Commit

Permalink
test: add doctests for node hash computations
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbinth committed Jul 22, 2024
1 parent 9e59aec commit ab1effc
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
17 changes: 12 additions & 5 deletions core/src/mast/node/call_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,19 @@ impl CallNode {
/// The commitment is computed as a hash of the callee and an empty word ([ZERO; 4]) in the
/// domain defined by either [Self::CALL_DOMAIN] or [Self::SYSCALL_DOMAIN], depending on
/// whether the node represents a simple call or a syscall - i.e.,:
///
/// hasher::merge_in_domain(&[callee_digest, Digest::default()], CallNode::CALL_DOMAIN)
///
/// ```
/// # use miden_core::mast::CallNode;
/// # use miden_crypto::{hash::rpo::{RpoDigest as Digest, Rpo256 as Hasher}};
/// # let callee_digest = Digest::default();
/// Hasher::merge_in_domain(&[callee_digest, Digest::default()], CallNode::CALL_DOMAIN);
/// ```
/// or
///
/// hasher::merge_in_domain(&[callee_digest, Digest::default()], CallNode::SYSCALL_DOMAIN)
/// ```
/// # use miden_core::mast::CallNode;
/// # use miden_crypto::{hash::rpo::{RpoDigest as Digest, Rpo256 as Hasher}};
/// # let callee_digest = Digest::default();
/// Hasher::merge_in_domain(&[callee_digest, Digest::default()], CallNode::SYSCALL_DOMAIN);
/// ```
pub fn digest(&self) -> RpoDigest {
self.digest
}
Expand Down
6 changes: 5 additions & 1 deletion core/src/mast/node/dyn_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ impl DynNode {
/// The commitment is computed by hashing two empty words ([ZERO; 4]) in the domain defined
/// by [Self::DOMAIN], i.e.:
///
/// hasher::merge_in_domain(&[Digest::default(), Digest::default()], DynNode::DOMAIN)
/// ```
/// # use miden_core::mast::DynNode;
/// # use miden_crypto::{hash::rpo::{RpoDigest as Digest, Rpo256 as Hasher}};
/// Hasher::merge_in_domain(&[Digest::default(), Digest::default()], DynNode::DOMAIN);
/// ```
pub fn digest(&self) -> RpoDigest {
RpoDigest::new([
Felt::new(8115106948140260551),
Expand Down
9 changes: 7 additions & 2 deletions core/src/mast/node/join_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ impl JoinNode {
///
/// The commitment is computed as a hash of the `first` and `second` child node in the domain
/// defined by [Self::DOMAIN] - i.e.,:
///
/// hasher::merge_in_domain(&[first_child_digest, second_child_digest], JoinNode::DOMAIN)
/// ```
/// # use miden_core::mast::JoinNode;
/// # use miden_crypto::{hash::rpo::{RpoDigest as Digest, Rpo256 as Hasher}};
/// # let first_child_digest = Digest::default();
/// # let second_child_digest = Digest::default();
/// Hasher::merge_in_domain(&[first_child_digest, second_child_digest], JoinNode::DOMAIN);
/// ```
pub fn digest(&self) -> RpoDigest {
self.digest
}
Expand Down
8 changes: 6 additions & 2 deletions core/src/mast/node/loop_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ impl LoopNode {
///
/// The commitment is computed as a hash of the loop body and an empty word ([ZERO; 4]) in
/// the domain defined by [Self::DOMAIN] - i..e,:
///
/// hasher::merge_in_domain(&[on_true_digest, Digest::default()], LoopNode::DOMAIN)
/// ```
/// # use miden_core::mast::LoopNode;
/// # use miden_crypto::{hash::rpo::{RpoDigest as Digest, Rpo256 as Hasher}};
/// # let body_digest = Digest::default();
/// Hasher::merge_in_domain(&[body_digest, Digest::default()], LoopNode::DOMAIN);
/// ```
pub fn digest(&self) -> RpoDigest {
self.digest
}
Expand Down
9 changes: 7 additions & 2 deletions core/src/mast/node/split_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ impl SplitNode {
///
/// The commitment is computed as a hash of the `on_true` and `on_false` child nodes in the
/// domain defined by [Self::DOMAIN] - i..e,:
///
/// hasher::merge_in_domain(&[on_true_digest, on_false_digest], SplitNode::DOMAIN)
/// ```
/// # use miden_core::mast::SplitNode;
/// # use miden_crypto::{hash::rpo::{RpoDigest as Digest, Rpo256 as Hasher}};
/// # let on_true_digest = Digest::default();
/// # let on_false_digest = Digest::default();
/// Hasher::merge_in_domain(&[on_true_digest, on_false_digest], SplitNode::DOMAIN);
/// ```
pub fn digest(&self) -> RpoDigest {
self.digest
}
Expand Down

0 comments on commit ab1effc

Please sign in to comment.