primitives: enable batched merkle root computation for x86
What changed, and why it matters
This commit simply turns on an existing, faster way to calculate Merkle roots for Intel/AMD (x86 and x86_64) processors. It was already enabled for ARM64 (aarch64). There is no security bug here; it is a small performance portability change.
No security action needed. Treat as a normal performance/portability commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch widens the conditional compilation (cfg) guard on the batched Merkle-root helper from target_arch = "aarch64" to also include x86 and x86_64. The same calculate_root_batched code path is reused unchanged. No cryptographic logic, input validation, or memory-safety code was modified.
Changed components
primitives/src/merkle_tree.rsInspect captured patch +3 / −3
diff --git a/primitives/src/merkle_tree.rs b/primitives/src/merkle_tree.rs
index 49ed1f0a..2b4253fb 100644
--- a/primitives/src/merkle_tree.rs
+++ b/primitives/src/merkle_tree.rs
@@ -115,7 +115,7 @@ pub(crate) trait MerkleNode: Copy + PartialEq {
}
#[cfg(feature = "std")]
-#[cfg(target_arch = "aarch64")]
+#[cfg(any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64"))]
fn calculate_root_batched(mut nodes: Vec<[u8; 32]>) -> Option<[u8; 32]> {
if nodes.is_empty() {
return None;
@@ -169,7 +169,7 @@ impl MerkleNode for TxMerkleNode {
}
#[cfg(feature = "std")]
- #[cfg(target_arch = "aarch64")]
+ #[cfg(any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64"))]
fn calculate_root<I: Iterator<Item = Self::Leaf>>(iter: I) -> Option<Self> {
let nodes: Vec<[u8; 32]> = iter.map(Txid::to_byte_array).collect();
calculate_root_batched(nodes).map(Self::from_byte_array)
@@ -187,7 +187,7 @@ impl MerkleNode for WitnessMerkleNode {
}
#[cfg(feature = "std")]
- #[cfg(target_arch = "aarch64")]
+ #[cfg(any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64"))]
fn calculate_root<I: Iterator<Item = Self::Leaf>>(iter: I) -> Option<Self> {
let nodes: Vec<[u8; 32]> = iter.map(Wtxid::to_byte_array).collect();
calculate_root_batched(nodes).map(Self::from_byte_array)
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.