Skip to content

Commit

Permalink
feat: drop SCRIPT_ENABLE_DIP0020_OPCODES, make opcodes available from…
Browse files Browse the repository at this point in the history
… genesis block
  • Loading branch information
knst committed Oct 8, 2024
1 parent 0e55abd commit 61bc300
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 282 deletions.
1 change: 0 additions & 1 deletion src/policy/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS = MANDATORY_SCRIPT_VE
SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY |
SCRIPT_VERIFY_CHECKSEQUENCEVERIFY |
SCRIPT_VERIFY_LOW_S |
SCRIPT_ENABLE_DIP0020_OPCODES |
SCRIPT_VERIFY_CONST_SCRIPTCODE;

/** For convenience, standard but not mandatory verify flags. */
Expand Down
17 changes: 0 additions & 17 deletions src/script/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,23 +409,6 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
if (opcode > OP_16 && ++nOpCount > MAX_OPS_PER_SCRIPT)
return set_error(serror, SCRIPT_ERR_OP_COUNT);

bool fDIP0020OpcodesEnabled = (flags & SCRIPT_ENABLE_DIP0020_OPCODES) != 0;
if (!fDIP0020OpcodesEnabled) {
if (opcode == OP_CAT ||
opcode == OP_SPLIT ||
opcode == OP_AND ||
opcode == OP_OR ||
opcode == OP_XOR ||
opcode == OP_DIV ||
opcode == OP_MOD ||
opcode == OP_NUM2BIN ||
opcode == OP_BIN2NUM ||
opcode == OP_CHECKDATASIG ||
opcode == OP_CHECKDATASIGVERIFY) {
return set_error(serror, SCRIPT_ERR_DISABLED_OPCODE); // Disabled opcodes.
}
}

if (opcode == OP_INVERT ||
opcode == OP_2MUL ||
opcode == OP_2DIV ||
Expand Down
3 changes: 0 additions & 3 deletions src/script/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ enum : uint32_t {
//
SCRIPT_VERIFY_NULLFAIL = (1U << 14),

// Enable the opcodes listed in DIP0020 (OP_CAT, OP_AND, OP_OR, OP_XOR, OP_DIV, OP_MOD, OP_SPLIT, OP_BIN2NUM, OP_NUM2BIN, OP_CHECKDATASIG, OP_CHECKDATASIGVERIFY).
SCRIPT_ENABLE_DIP0020_OPCODES = (1U << 15),

// Making OP_CODESEPARATOR and FindAndDelete fail
//
SCRIPT_VERIFY_CONST_SCRIPTCODE = (1U << 16),
Expand Down
4 changes: 2 additions & 2 deletions src/test/checkdatasig_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void CheckError(uint32_t flags, const stacktype& original_stack,
BaseSignatureChecker sigchecker;
ScriptError err = ScriptError::SCRIPT_ERR_OK;
stacktype stack{original_stack};
bool r = EvalScript(stack, script, flags | SCRIPT_ENABLE_DIP0020_OPCODES, sigchecker, SigVersion::BASE, &err);
bool r = EvalScript(stack, script, flags, sigchecker, SigVersion::BASE, &err);
BOOST_CHECK(!r);
BOOST_CHECK(err == expected);
}
Expand All @@ -53,7 +53,7 @@ static void CheckPass(uint32_t flags, const stacktype& original_stack,
BaseSignatureChecker sigchecker;
ScriptError err = ScriptError::SCRIPT_ERR_OK;
stacktype stack{original_stack};
bool r = EvalScript(stack, script, flags | SCRIPT_ENABLE_DIP0020_OPCODES, sigchecker, SigVersion::BASE, &err);
bool r = EvalScript(stack, script, flags, sigchecker, SigVersion::BASE, &err);
BOOST_CHECK(r);
BOOST_CHECK(err == ScriptError::SCRIPT_ERR_OK);
BOOST_CHECK(stack == expected);
Expand Down
458 changes: 223 additions & 235 deletions src/test/data/script_tests.json

Large diffs are not rendered by default.

10 changes: 2 additions & 8 deletions src/test/dip0020opcodes_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void CheckTestResultForAllFlags(const stacktype& original_stack,
for (uint32_t flags : flagset) {
ScriptError err = ScriptError::SCRIPT_ERR_OK;
stacktype stack{original_stack};
bool r = EvalScript(stack, script, flags | SCRIPT_ENABLE_DIP0020_OPCODES, sigchecker, SigVersion::BASE, &err);
bool r = EvalScript(stack, script, flags, sigchecker, SigVersion::BASE, &err);
BOOST_CHECK(r);
BOOST_CHECK(stack == expected);
}
Expand All @@ -40,7 +40,7 @@ static void CheckError(uint32_t flags, const stacktype& original_stack,
BaseSignatureChecker sigchecker;
ScriptError err = ScriptError::SCRIPT_ERR_OK;
stacktype stack{original_stack};
bool r = EvalScript(stack, script, flags | SCRIPT_ENABLE_DIP0020_OPCODES, sigchecker, SigVersion::BASE, &err);
bool r = EvalScript(stack, script, flags, sigchecker, SigVersion::BASE, &err);
BOOST_CHECK(!r);
BOOST_CHECK(err == expected_error);
}
Expand Down Expand Up @@ -784,10 +784,4 @@ BOOST_AUTO_TEST_CASE(div_and_mod_opcode_tests)
{0xbb, 0xf0, 0x5d, 0x03});
}

BOOST_AUTO_TEST_CASE(check_dip0020_inclusion_in_standard_flags)
{
BOOST_CHECK(STANDARD_SCRIPT_VERIFY_FLAGS &
SCRIPT_ENABLE_DIP0020_OPCODES);
}

BOOST_AUTO_TEST_SUITE_END()
10 changes: 3 additions & 7 deletions src/test/script_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ BOOST_FIXTURE_TEST_SUITE(script_tests, BasicTestingSetup)
void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, uint32_t flags, const std::string& message, int scriptError)
{
bool expect = (scriptError == SCRIPT_ERR_OK);
bool fEnableDIP0020Opcodes = (SCRIPT_ENABLE_DIP0020_OPCODES & flags) != 0;
ScriptError err;
const CTransaction txCredit{BuildCreditingTransaction(scriptPubKey)};
CMutableTransaction tx = BuildSpendingTransaction(scriptSig, txCredit);
Expand All @@ -136,8 +135,6 @@ void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, uint32_t flag
uint32_t combined_flags{expect ? (flags & ~extra_flags) : (flags | extra_flags)};
// Weed out some invalid flag combinations.
if (combined_flags & SCRIPT_VERIFY_CLEANSTACK && ~combined_flags & SCRIPT_VERIFY_P2SH) continue;
// Make sure DIP0020 opcodes flag stays unchanged.
combined_flags = fEnableDIP0020Opcodes ? (combined_flags | SCRIPT_ENABLE_DIP0020_OPCODES) : (combined_flags & ~SCRIPT_ENABLE_DIP0020_OPCODES);
BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, combined_flags, MutableTransactionSignatureChecker(&tx, 0, txCredit.vout[0].nValue), &err) == expect, message + strprintf(" (with flags %x)", combined_flags));
}

Expand Down Expand Up @@ -680,8 +677,7 @@ BOOST_AUTO_TEST_CASE(script_build)

// Test OP_CHECKDATASIG
const uint32_t checkdatasigflags = SCRIPT_VERIFY_STRICTENC |
SCRIPT_VERIFY_NULLFAIL |
SCRIPT_ENABLE_DIP0020_OPCODES;
SCRIPT_VERIFY_NULLFAIL;

tests.push_back(
TestBuilder(CScript() << ToByteVector(keys.pubkey1C) << OP_CHECKDATASIG,
Expand Down Expand Up @@ -749,7 +745,7 @@ BOOST_AUTO_TEST_CASE(script_build)
TestBuilder(CScript() << ToByteVector(keys.pubkey0H) << OP_CHECKDATASIG
<< OP_NOT,
"CHECKDATASIG with invalid hybrid pubkey but no STRICTENC",
SCRIPT_ENABLE_DIP0020_OPCODES)
0)
.PushDataSig(keys.key0, {})
.DamagePush(10)
.Num(0));
Expand Down Expand Up @@ -839,7 +835,7 @@ BOOST_AUTO_TEST_CASE(script_build)
CScript() << ToByteVector(keys.pubkey0H) << OP_CHECKDATASIGVERIFY
<< OP_TRUE,
"CHECKDATASIGVERIFY with invalid hybrid pubkey but no STRICTENC",
SCRIPT_ENABLE_DIP0020_OPCODES)
0)
.PushDataSig(keys.key0, {})
.DamagePush(10)
.Num(0)
Expand Down
1 change: 0 additions & 1 deletion src/test/transaction_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ static std::map<std::string, unsigned int> mapFlagNames = {
{std::string("NULLFAIL"), (unsigned int) SCRIPT_VERIFY_NULLFAIL},
{std::string("CHECKLOCKTIMEVERIFY"), (unsigned int) SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY},
{std::string("CHECKSEQUENCEVERIFY"), (unsigned int) SCRIPT_VERIFY_CHECKSEQUENCEVERIFY},
{std::string("DIP0020_OPCODES"), (unsigned int) SCRIPT_ENABLE_DIP0020_OPCODES},
{std::string("CONST_SCRIPTCODE"), (unsigned int)SCRIPT_VERIFY_CONST_SCRIPTCODE},
};

Expand Down
10 changes: 2 additions & 8 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1497,9 +1497,8 @@ 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;
const bool hasDIP0020Opcodes = (flags & SCRIPT_ENABLE_DIP0020_OPCODES) != 0;

if (hasNonMandatoryFlags || !hasDIP0020Opcodes) {
if (hasNonMandatoryFlags) {
// 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 @@ -1509,7 +1508,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), 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 @@ -1823,11 +1822,6 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens
flags |= SCRIPT_VERIFY_NULLDUMMY;
}

// Enforce DIP0020
if (DeploymentActiveAt(*pindex, consensusparams, Consensus::DEPLOYMENT_DIP0020)) {
flags |= SCRIPT_ENABLE_DIP0020_OPCODES;
}

return flags;
}

Expand Down

0 comments on commit 61bc300

Please sign in to comment.