mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 20:42:59 +01:00
(partial) Merge bitcoin/bitcoin#22232: refactor: Pass interpreter flags as uint32_t instead of signed int
fa621ededdfe31a200b77a8787de7e3d2e667aec refactor: Pass script verify flags as uint32_t (MarcoFalke) Pull request description: The flags are cast to unsigned in the interpreter anyway, so avoid the confusion (and fuzz crashes) by just passing them as unsigned from the beginning. Also, the flags are often inverted bit-wise with the `~` operator, which also works on signed integers, but might cause confusion as the sign bit is flipped. Fixes #22233 ACKs for top commit: theStack: Concept and code review ACK fa621ededdfe31a200b77a8787de7e3d2e667aec kristapsk: ACK fa621ededdfe31a200b77a8787de7e3d2e667aec jonatack: ACK fa621ededdfe31a200b77a8787de7e3d2e667aec Tree-SHA512: ea0720f32f823fa7f075309978672aa39773c6019d12b6c1c9d611fc1983a76115b7fe2a28d50814673bb6415c311ccc05b99d6e871575fb6900faf75ed17769
This commit is contained in:
parent
f40cb714e5
commit
c338cd69d4
@ -145,7 +145,7 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
|
||||
return nSigOps;
|
||||
}
|
||||
|
||||
unsigned int GetTransactionSigOpCount(const CTransaction& tx, const CCoinsViewCache& inputs, int flags)
|
||||
unsigned int GetTransactionSigOpCount(const CTransaction& tx, const CCoinsViewCache& inputs, uint32_t flags)
|
||||
{
|
||||
unsigned int nSigOps = GetLegacySigOpCount(tx);
|
||||
|
||||
|
@ -52,7 +52,7 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& ma
|
||||
* @param[out] flags Script verification flags
|
||||
* @return Total signature operation count for a tx
|
||||
*/
|
||||
unsigned int GetTransactionSigOpCount(const CTransaction& tx, const CCoinsViewCache& inputs, int flags);
|
||||
unsigned int GetTransactionSigOpCount(const CTransaction& tx, const CCoinsViewCache& inputs, uint32_t flags);
|
||||
|
||||
/**
|
||||
* Check if transaction is final and can be included in a block with the
|
||||
|
@ -32,8 +32,7 @@ enum
|
||||
* All flags are intended to be soft forks: the set of acceptable scripts under
|
||||
* flags (A | B) is a subset of the acceptable scripts under flag (A).
|
||||
*/
|
||||
enum
|
||||
{
|
||||
enum : uint32_t {
|
||||
SCRIPT_VERIFY_NONE = 0,
|
||||
|
||||
// Evaluate P2SH subscripts (BIP16).
|
||||
|
@ -251,7 +251,7 @@ FUZZ_TARGET_INIT(coins_view, initialize_coins_view)
|
||||
// consensus/tx_verify.cpp:130: unsigned int GetP2SHSigOpCount(const CTransaction &, const CCoinsViewCache &): Assertion `!coin.IsSpent()' failed.
|
||||
return;
|
||||
}
|
||||
const int flags = fuzzed_data_provider.ConsumeIntegral<int>();
|
||||
const auto flags{fuzzed_data_provider.ConsumeIntegral<uint32_t>()};
|
||||
if (!transaction.vin.empty() && (flags & SCRIPT_VERIFY_P2SH) == 0) {
|
||||
// Avoid:
|
||||
// script/interpreter.cpp:1705: size_t CountWitnessSigOps(const CScript &, const CScript &, const CScriptWitness *, unsigned int): Assertion `(flags & SCRIPT_VERIFY_P2SH) != 0' failed.
|
||||
|
@ -123,7 +123,7 @@ static ScriptError_t ParseScriptError(const std::string& name)
|
||||
BOOST_FIXTURE_TEST_SUITE(script_tests, BasicTestingSetup)
|
||||
|
||||
|
||||
void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, int flags, const std::string& message, int scriptError)
|
||||
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;
|
||||
@ -136,8 +136,8 @@ void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, int flags, co
|
||||
|
||||
// Verify that removing flags from a passing test or adding flags to a failing test does not change the result.
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
int extra_flags = InsecureRandBits(16);
|
||||
int combined_flags = expect ? (flags & ~extra_flags) : (flags | extra_flags);
|
||||
uint32_t extra_flags(InsecureRandBits(16));
|
||||
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.
|
||||
@ -148,7 +148,7 @@ void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, int flags, co
|
||||
#if defined(HAVE_CONSENSUS_LIB)
|
||||
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
|
||||
stream << tx2;
|
||||
int libconsensus_flags = flags & dashconsensus_SCRIPT_FLAGS_VERIFY_ALL;
|
||||
uint32_t libconsensus_flags{flags & dashconsensus_SCRIPT_FLAGS_VERIFY_ALL};
|
||||
if (libconsensus_flags == flags) {
|
||||
int expectedSuccessCode = expect ? 1 : 0;
|
||||
BOOST_CHECK_MESSAGE(dashconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), (const unsigned char*)&stream[0], stream.size(), 0, libconsensus_flags, nullptr) == expectedSuccessCode, message);
|
||||
@ -240,7 +240,7 @@ private:
|
||||
bool havePush;
|
||||
std::vector<unsigned char> push;
|
||||
std::string comment;
|
||||
int flags;
|
||||
uint32_t flags;
|
||||
int scriptError;
|
||||
|
||||
void DoPush()
|
||||
@ -259,7 +259,7 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
TestBuilder(const CScript& script_, const std::string& comment_, int flags_, bool P2SH = false) : scriptPubKey(script_), havePush(false), comment(comment_), flags(flags_), scriptError(SCRIPT_ERR_OK)
|
||||
TestBuilder(const CScript& script_, const std::string& comment_, uint32_t flags_, bool P2SH = false) : scriptPubKey(script_), havePush(false), comment(comment_), flags(flags_), scriptError(SCRIPT_ERR_OK)
|
||||
{
|
||||
if (P2SH) {
|
||||
creditTx = MakeTransactionRef(BuildCreditingTransaction(CScript() << OP_HASH160 << ToByteVector(CScriptID(script_)) << OP_EQUAL));
|
||||
|
Loading…
Reference in New Issue
Block a user