Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use block_success in header validation, comments, style. #1475

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/chain/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,10 @@ bool block::is_segregated() const NOEXCEPT
return std::any_of(txs_->begin(), txs_->end(), segregated);
}

// The witness merkle root is obtained from wtxids, subject to malleation just
// as the txs commitment. However, since tx duplicates are precluded by the
// malleable32 (or complete) block check, there is no opportunity for this.
// Similarly the witness commitment cannot be malleable64.
bool block::is_invalid_witness_commitment() const NOEXCEPT
{
if (txs_->empty())
Expand All @@ -528,7 +532,8 @@ bool block::is_invalid_witness_commitment() const NOEXCEPT
return false;

// If there is a valid commitment, return false (valid).
// Last output of commitment pattern holds committed value (bip141).
// Coinbase input witness must be 32 byte witness reserved value (bip141).
// Last output of commitment pattern holds the committed value (bip141).
hash_digest reserved{}, committed{};
if (coinbase.inputs_ptr()->front()->reserved_hash(reserved))
for (const auto& output: views_reverse(*coinbase.outputs_ptr()))
Expand Down Expand Up @@ -724,10 +729,12 @@ code block::check(bool bypass) const NOEXCEPT
{
if (bypass)
{
// type32_malleated is subset of is_internal_double_spend, assuming
// otherwise valid txs, as that will catch any duplicated transaction.
// Transaction commitment is required under checkpoint.
if (is_invalid_merkle_root())
return error::merkle_mismatch;

// type32_malleated is subset of is_internal_double_spend, assuming
// otherwise valid txs, as that will catch any duplicated transaction.
if (is_malleated32())
return error::type32_malleated;

Expand Down Expand Up @@ -766,6 +773,7 @@ code block::check(const context& ctx, bool bypass) const NOEXCEPT
{
const auto bip141 = ctx.is_enabled(bip141_rule);

// Wintness commitment is required under checkpoint.
if (bip141 && is_invalid_witness_commitment())
return error::invalid_witness_commitment;

Expand Down
4 changes: 2 additions & 2 deletions src/chain/header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ code header::check(uint32_t timestamp_limit_seconds,
if (is_invalid_timestamp(timestamp_limit_seconds))
return error::futuristic_timestamp;

return error::success;
return error::block_success;
}

// minimum_block_version
Expand All @@ -349,7 +349,7 @@ code header::accept(const context& ctx) const NOEXCEPT
if (bits_ != ctx.work_required)
return error::incorrect_proof_of_work;

return error::success;
return error::block_success;
}

// JSON value convertors.
Expand Down
Loading