Skip to content

Commit

Permalink
Add static bool is_malleable64(txs).
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Apr 11, 2024
1 parent e9e5e61 commit dbdbacc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/bitcoin/system/chain/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class BC_API block
typedef std_vector<size_t> sizes;
typedef std::shared_ptr<const block> cptr;

static bool is_malleable64(const transaction_cptrs& txs) NOEXCEPT;

/// Constructors.
/// -----------------------------------------------------------------------

Expand Down
10 changes: 8 additions & 2 deletions src/chain/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dbdbacc

Please sign in to comment.