forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
test: add special transaction validation fuzz target #7169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
thepastaclaw
wants to merge
6
commits into
dashpay:develop
from
thepastaclaw:fuzz/special-tx-validation
+111
−0
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bbdb7d0
test(fuzz): add special transaction validation fuzz target
thepastaclaw 7640ff5
fix: mine blocks past activation height in special_tx_validation fuzz…
thepastaclaw c252074
fix: add fuzz target to non-backported.txt
thepastaclaw 61df133
fix: add missing newline in non-backported.txt
thepastaclaw 0f4ceaf
style: apply clang-format
thepastaclaw 7e3e61a
fix: add missing newline in non-backported.txt entry
thepastaclaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| // Copyright (c) 2026 The Dash Core developers | ||
| // Distributed under the MIT software license, see the accompanying | ||
| // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
|
||
| #include <coins.h> | ||
| #include <consensus/validation.h> | ||
| #include <evo/chainhelper.h> | ||
| #include <evo/specialtxman.h> | ||
| #include <primitives/transaction.h> | ||
| #include <script/script.h> | ||
| #include <streams.h> | ||
| #include <test/fuzz/FuzzedDataProvider.h> | ||
| #include <test/fuzz/fuzz.h> | ||
| #include <test/util/mining.h> | ||
| #include <test/util/setup_common.h> | ||
| #include <util/check.h> | ||
| #include <validation.h> | ||
| #include <validationinterface.h> | ||
| #include <version.h> | ||
|
|
||
| #include <array> | ||
| #include <cstddef> | ||
| #include <cstdint> | ||
|
|
||
| namespace { | ||
| const TestingSetup* g_setup; | ||
| } // namespace | ||
|
|
||
| void initialize_special_tx_validation() | ||
| { | ||
| static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>( | ||
| CBaseChainParams::REGTEST, {"-dip3params=2:2", "-testactivationheight=v20@2", "-testactivationheight=mn_rr@2"}); | ||
| g_setup = testing_setup.get(); | ||
| // Mine blocks past the activation height so DIP3/v20/mn_rr are active | ||
| for (int i = 0; i < 3; ++i) { | ||
| MineBlock(g_setup->m_node, CScript() << OP_TRUE); | ||
| } | ||
| SyncWithValidationInterfaceQueue(); | ||
| } | ||
|
|
||
| static CMutableTransaction DeserializeCandidateTx(FuzzedDataProvider& fuzzed_data_provider) | ||
| { | ||
| CMutableTransaction tx; | ||
| bool deserialized{false}; | ||
|
|
||
| CDataStream ds(fuzzed_data_provider.ConsumeBytes<uint8_t>(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096)), | ||
| SER_NETWORK, INIT_PROTO_VERSION); | ||
| try { | ||
| int nVersion; | ||
| ds >> nVersion; | ||
| ds.SetVersion(nVersion); | ||
| ds >> tx; | ||
| deserialized = true; | ||
| } catch (const std::ios_base::failure&) { | ||
| } | ||
|
|
||
| if (!deserialized) { | ||
| tx.nVersion = fuzzed_data_provider.ConsumeBool() ? CTransaction::CURRENT_VERSION : CTransaction::SPECIAL_VERSION; | ||
| tx.nType = fuzzed_data_provider.ConsumeIntegral<uint16_t>(); | ||
| tx.nLockTime = fuzzed_data_provider.ConsumeIntegral<uint32_t>(); | ||
| tx.vExtraPayload = fuzzed_data_provider.ConsumeBytes<uint8_t>( | ||
| fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 256)); | ||
| } | ||
|
|
||
| return tx; | ||
| } | ||
|
|
||
| FUZZ_TARGET(special_tx_validation, .init = initialize_special_tx_validation) | ||
| { | ||
| FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); | ||
| const CMutableTransaction base_candidate = DeserializeCandidateTx(fuzzed_data_provider); | ||
|
|
||
| static constexpr std::array<uint16_t, 9> SPECIAL_TYPES{ | ||
| TRANSACTION_PROVIDER_REGISTER, | ||
| TRANSACTION_PROVIDER_UPDATE_SERVICE, | ||
| TRANSACTION_PROVIDER_UPDATE_REGISTRAR, | ||
| TRANSACTION_PROVIDER_UPDATE_REVOKE, | ||
| TRANSACTION_COINBASE, | ||
| TRANSACTION_QUORUM_COMMITMENT, | ||
| TRANSACTION_MNHF_SIGNAL, | ||
| TRANSACTION_ASSET_LOCK, | ||
| TRANSACTION_ASSET_UNLOCK, | ||
| }; | ||
|
|
||
| auto* const special_tx = g_setup->m_node.chain_helper->special_tx.get(); | ||
| Assert(special_tx != nullptr); | ||
|
|
||
| LOCK(::cs_main); | ||
| const CBlockIndex* const pindex_prev = g_setup->m_node.chainman->ActiveChain().Tip(); | ||
| if (pindex_prev == nullptr) return; | ||
| const CCoinsViewCache& coins_view = g_setup->m_node.chainman->ActiveChainstate().CoinsTip(); | ||
|
|
||
| const auto iterations = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, SPECIAL_TYPES.size()); | ||
| for (size_t i = 0; i < iterations; ++i) { | ||
| CMutableTransaction mut_tx{base_candidate}; | ||
| mut_tx.nVersion = CTransaction::SPECIAL_VERSION; | ||
| mut_tx.nType = SPECIAL_TYPES[i]; | ||
|
|
||
| if (fuzzed_data_provider.ConsumeBool()) { | ||
| mut_tx.vExtraPayload = fuzzed_data_provider.ConsumeBytes<uint8_t>( | ||
| fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 512)); | ||
| } | ||
|
|
||
| TxValidationState state; | ||
| const bool accepted{special_tx->CheckSpecialTx(CTransaction{mut_tx}, pindex_prev, coins_view, | ||
| fuzzed_data_provider.ConsumeBool(), state)}; | ||
| Assert(accepted == state.IsValid()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.