From a04f17a1882407db09b0a07338e12877ac1d9e92 Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Thu, 8 May 2025 18:37:49 +0200 Subject: [PATCH] doc: warn that CheckBlock() underestimates sigops Counting sigops in the witness and for p2sh requires context that CheckBlock() does not have, so it only counts a subset of sigops. The check here was introduced by Satoshi as a "cleanup" in f1e1fb4bdef878c8fc1564fa418d44e7541a7e83. With the attempted introduction of OP_EVAL, it was replaced by the check in ConnectBlock(). Commit e679ec969c8b22c676ebb10bea1038f6c8f13b33 marked this code as a placeholder for backward compatibility. Then when P2SH replaced OP_EVAL in 922e8e2929a2e78270868385aa46f96002fbcff3 the phrase "compatibility-breaking" was replaced by a simple observation that before v0.6 this is how sigops were counted. It's unclear why the check was kept and there were no review comments about it. --- src/validation.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/validation.cpp b/src/validation.cpp index 3e8a7cf520e..69a4ad449a1 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4094,6 +4094,8 @@ bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensu strprintf("Transaction check failed (tx hash %s) %s", tx->GetHash().ToString(), tx_state.GetDebugMessage())); } } + // This underestimates the number of sigops, because unlike ConnectBlock it + // does not count witness and p2sh sigops. unsigned int nSigOps = 0; for (const auto& tx : block.vtx) {