From ab1effc04bd8eb2c73629ad298f6001581101633 Mon Sep 17 00:00:00 2001 From: Bobbin Threadbare Date: Mon, 22 Jul 2024 14:22:46 -0700 Subject: [PATCH] test: add doctests for node hash computations --- core/src/mast/node/call_node.rs | 17 ++++++++++++----- core/src/mast/node/dyn_node.rs | 6 +++++- core/src/mast/node/join_node.rs | 9 +++++++-- core/src/mast/node/loop_node.rs | 8 ++++++-- core/src/mast/node/split_node.rs | 9 +++++++-- 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/core/src/mast/node/call_node.rs b/core/src/mast/node/call_node.rs index 2cb116aeba..ca9c720195 100644 --- a/core/src/mast/node/call_node.rs +++ b/core/src/mast/node/call_node.rs @@ -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 } diff --git a/core/src/mast/node/dyn_node.rs b/core/src/mast/node/dyn_node.rs index 47e5186b59..934a8fec2d 100644 --- a/core/src/mast/node/dyn_node.rs +++ b/core/src/mast/node/dyn_node.rs @@ -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), diff --git a/core/src/mast/node/join_node.rs b/core/src/mast/node/join_node.rs index 797b030fa7..5f802873dd 100644 --- a/core/src/mast/node/join_node.rs +++ b/core/src/mast/node/join_node.rs @@ -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 } diff --git a/core/src/mast/node/loop_node.rs b/core/src/mast/node/loop_node.rs index 125a6c2c02..aec1b0b451 100644 --- a/core/src/mast/node/loop_node.rs +++ b/core/src/mast/node/loop_node.rs @@ -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 } diff --git a/core/src/mast/node/split_node.rs b/core/src/mast/node/split_node.rs index 017e12171f..f754735e35 100644 --- a/core/src/mast/node/split_node.rs +++ b/core/src/mast/node/split_node.rs @@ -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 }