Skip to content

Commit

Permalink
feat: Use DIP0143 flag only when the corresponding EHF is active
Browse files Browse the repository at this point in the history
  • Loading branch information
panleone committed Feb 23, 2024
1 parent c66b3a2 commit 774991a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/policy/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())));
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 774991a

Please sign in to comment.