From 774991af1130678676c380c2c59c6c697d642c94 Mon Sep 17 00:00:00 2001 From: Alessandro Rezzi Date: Fri, 23 Feb 2024 10:59:45 +0100 Subject: [PATCH] feat: Use DIP0143 flag only when the corresponding EHF is active --- src/policy/policy.h | 3 ++- src/validation.cpp | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/policy/policy.h b/src/policy/policy.h index 8052cebac39706..dd09ca4aa49cc9 100644 --- a/src/policy/policy.h +++ b/src/policy/policy.h @@ -61,7 +61,8 @@ static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS = MANDATORY_SCRIPT_VE SCRIPT_VERIFY_CHECKSEQUENCEVERIFY | SCRIPT_VERIFY_LOW_S | SCRIPT_ENABLE_DIP0020_OPCODES | - SCRIPT_VERIFY_CONST_SCRIPTCODE; + SCRIPT_VERIFY_CONST_SCRIPTCODE | + SCRIPT_ENABLE_DIP0143; /** For convenience, standard but not mandatory verify flags. */ static constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS = STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS; diff --git a/src/validation.cpp b/src/validation.cpp index b56b4e055c156f..b167a2b0669bfa 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1600,9 +1600,11 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState &state, const C check.swap(pvChecks->back()); } else if (!check()) { const bool hasNonMandatoryFlags = (flags & STANDARD_NOT_MANDATORY_VERIFY_FLAGS) != 0; + //TODO: to avoid this flag by flag check, group all ENABLE like flags in a group STANDARD_ENABLE_FLAGS? const bool hasDIP0020Opcodes = (flags & SCRIPT_ENABLE_DIP0020_OPCODES) != 0; + const bool hasDIP0143Flag = (flags & SCRIPT_ENABLE_DIP0143) != 0; - if (hasNonMandatoryFlags || !hasDIP0020Opcodes) { + if (hasNonMandatoryFlags || !hasDIP0020Opcodes || !hasDIP0143Flag) { // Check whether the failure was caused by a // non-mandatory script verification check, such as // non-standard DER encodings or non-null dummy @@ -1612,7 +1614,7 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState &state, const C // non-upgraded nodes by banning CONSENSUS-failing // data providers. CScriptCheck check2(coin.out, tx, i, - (flags & ~STANDARD_NOT_MANDATORY_VERIFY_FLAGS) | SCRIPT_ENABLE_DIP0020_OPCODES, cacheSigStore, &txdata); + (flags & ~STANDARD_NOT_MANDATORY_VERIFY_FLAGS) | SCRIPT_ENABLE_DIP0020_OPCODES | SCRIPT_ENABLE_DIP0143, cacheSigStore, &txdata); if (check2()) return state.Invalid(TxValidationResult::TX_NOT_STANDARD, strprintf("non-mandatory-script-verify-flag (%s)", ScriptErrorString(check.GetScriptError()))); } @@ -2036,6 +2038,11 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens flags |= SCRIPT_ENABLE_DIP0020_OPCODES; } + // Enforce DIP0143 + if (DeploymentActiveAt(*pindex, consensusparams, Consensus::DEPLOYMENT_DIP0143)){ + flags |= SCRIPT_ENABLE_DIP0143; + } + return flags; }