From dbdbacc07e9fc21283159f1d57399bb575e78614 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Thu, 11 Apr 2024 18:52:45 -0400 Subject: [PATCH] Add static bool is_malleable64(txs). --- include/bitcoin/system/chain/block.hpp | 2 ++ src/chain/block.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/bitcoin/system/chain/block.hpp b/include/bitcoin/system/chain/block.hpp index 696846fff4..0a8e865e48 100644 --- a/include/bitcoin/system/chain/block.hpp +++ b/include/bitcoin/system/chain/block.hpp @@ -44,6 +44,8 @@ class BC_API block typedef std_vector sizes; typedef std::shared_ptr cptr; + static bool is_malleable64(const transaction_cptrs& txs) NOEXCEPT; + /// Constructors. /// ----------------------------------------------------------------------- diff --git a/src/chain/block.cpp b/src/chain/block.cpp index 153ae07017..8627c620a8 100644 --- a/src/chain/block.cpp +++ b/src/chain/block.cpp @@ -488,16 +488,22 @@ bool block::is_malleated32(size_t width) const NOEXCEPT return true; } +bool block::is_malleable64() const NOEXCEPT +{ + return is_malleable64(*txs_); +} + +// static // If all non-witness tx serializations are 64 bytes the id is malleable. // This form of malleability does not imply current block instance is invalid. -bool block::is_malleable64() const NOEXCEPT +bool block::is_malleable64(const transaction_cptrs& txs) NOEXCEPT { const auto two_leaves = [](const transaction::cptr& tx) NOEXCEPT { return tx->serialized_size(false) == two * hash_size; }; - return !is_empty() && std::all_of(txs_->begin(), txs_->end(), two_leaves); + return !txs.empty() && std::all_of(txs.begin(), txs.end(), two_leaves); } bool block::is_segregated() const NOEXCEPT