aboutsummaryrefslogtreecommitdiff
path: root/src/consensus
diff options
context:
space:
mode:
authorlaanwj <126646+laanwj@users.noreply.github.com>2022-03-25 14:11:12 +0100
committerlaanwj <126646+laanwj@users.noreply.github.com>2022-03-25 14:11:18 +0100
commit7c08d81e119570792648fe95bbacddbb1d5f9ae2 (patch)
treea3efa1f0587829fd63dd7a94bf052d7bb8f309c9 /src/consensus
parentd2615312c1292a0088f162bba1abbeb5f4068b2f (diff)
parentcccc1e70b8a14430cc94143da97936a60d6c83d3 (diff)
downloadbitcoin-7c08d81e119570792648fe95bbacddbb1d5f9ae2.tar.xz
Merge bitcoin/bitcoin#23536: Enforce Taproot script flags whenever WITNESS is set
cccc1e70b8a14430cc94143da97936a60d6c83d3 Enforce Taproot script flags whenever WITNESS is set (MarcoFalke) fa422994116a7a053789304d56159760081479eb Remove nullptr check in GetBlockScriptFlags (MarcoFalke) faadc606c7644f2934de390e261d9d65a81a7592 refactor: Pass const reference instead of pointer to GetBlockScriptFlags (MarcoFalke) Pull request description: Now that Taproot is active, it makes sense to enforce its rules on all blocks, even historic ones, regardless of the deployment status. ### Benefits: (With "script flags" I mean "taproot script verification flags".) * Script flags are known ahead for all blocks (even blocks not yet created) and do not change. This may benefit static analysis, code review, and development of new script features that build on Taproot. * Any future bugs introduced in the deployment code won't have any effect on the script flags, as they are independent of deployment. * Enforcing the taproot rules regardless of the deployment status makes testing easier because invalid blocks after activation are also invalid before activation. So there is no need to differentiate the two cases. * It gives belt-and-suspenders protection against a practically expensive and theoretically impossible IBD reorg attack where the node is eclipsed. While `nMinimumChainWork` already protects against this, the cost for a few months worth of POW might be lowered until a major version release of Bitcoin Core reaches EOL. The needed work for the attack is the difference between `nMinimumChainWork` and the work at block 709632. For reference, previously the same was done for P2SH and WITNESS in commit 0a8b7b4b33c9d78574627fc606267e2d8955cd1c. ### Implementation: I found one block which fails verification with the flags applied, so I added a `TaprootException`, similar to the `BIP16Exception`. For reference, the debug log: ``` ERROR: ConnectBlock(): CheckInputScripts on b10c007c60e14f9d087e0291d4d0c7869697c6681d979c6639dbd960792b4d41 failed with non-mandatory-script-verify-flag (Witness program was passed an empty witness) BlockChecked: block hash=0000000000000000000f14c35b2d841e986ab5441de8c585d5ffe55ea1e395ad state=non-mandatory-script-verify-flag (Witness program was passed an empty witness) InvalidChainFound: invalid block=0000000000000000000f14c35b2d841e986ab5441de8c585d5ffe55ea1e395ad height=692261 log2_work=92.988459 date=2021-07-23T08:24:20Z InvalidChainFound: current best=0000000000000000000067b17a4c0ffd77c29941b15ad356ca8f980af137a25d height=692260 log2_work=92.988450 date=2021-07-23T07:47:31Z ERROR: ConnectTip: ConnectBlock 0000000000000000000f14c35b2d841e986ab5441de8c585d5ffe55ea1e395ad failed, non-mandatory-script-verify-flag (Witness program was passed an empty witness) ``` Hint for testing, make sure to set `-noassumevalid`. ### Considerations Obviously this change can lead to consensus splits on the network in light of massive reorgs. Currently the last block before Taproot activation, that is the last block without the Taproot script flags set, is only buried by a few days of POW. However, when and if this patch is included in the next major release, it will be buried by a few months of POW. BIP90 considerations apply when looking at reorgs this large. ACKs for top commit: Sjors: tACK cccc1e70b8a14430cc94143da97936a60d6c83d3 achow101: ACK cccc1e70b8a14430cc94143da97936a60d6c83d3 laanwj: Code review ACK cccc1e70b8a14430cc94143da97936a60d6c83d3 ajtowns: ACK cccc1e70b8a14430cc94143da97936a60d6c83d3 ; code review; wrote a "getblockscriptflags" rpc to quickly check that blocks just had bit 17 (taproot) added; review of earlier revisions had established non-exception blocks do validate with taproot rules enabled. jamesob: ACK cccc1e70b8a14430cc94143da97936a60d6c83d3 ([`jamesob/ackr/23536.1.MarcoFalke.enforce_taproot_script_f`](https://github.com/jamesob/bitcoin/tree/ackr/23536.1.MarcoFalke.enforce_taproot_script_f)) Tree-SHA512: 00044de68939caef6420ffd588c1291c041a8b397c80a3df1e3e3487fbeae1821d23975c51c95e44e774558db76f943b00b4e27cbd0213f64a9253116dc6edde
Diffstat (limited to 'src/consensus')
-rw-r--r--src/consensus/params.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/consensus/params.h b/src/consensus/params.h
index 1ed5ca469f..0881f2e388 100644
--- a/src/consensus/params.h
+++ b/src/consensus/params.h
@@ -7,7 +7,9 @@
#define BITCOIN_CONSENSUS_PARAMS_H
#include <uint256.h>
+
#include <limits>
+#include <map>
namespace Consensus {
@@ -70,8 +72,13 @@ struct BIP9Deployment {
struct Params {
uint256 hashGenesisBlock;
int nSubsidyHalvingInterval;
- /* Block hash that is excepted from BIP16 enforcement */
- uint256 BIP16Exception;
+ /**
+ * Hashes of blocks that
+ * - are known to be consensus valid, and
+ * - buried in the chain, and
+ * - fail if the default script verify flags are applied.
+ */
+ std::map<uint256, uint32_t> script_flag_exceptions;
/** Block height and hash at which BIP34 becomes active */
int BIP34Height;
uint256 BIP34Hash;