forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
test: add roundtrip serialize/deserialize fuzz targets for Dash types #7162
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
+186
−0
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e1bae4b
test(fuzz): add roundtrip serialize/deserialize consistency targets f…
thepastaclaw 677f6aa
fix(llmq): clear mnSkipList in CQuorumSnapshot::Unserialize before re…
thepastaclaw e750429
fix: add roundtrip_dash.cpp to non-backported.txt
thepastaclaw dc8fcb2
style: apply clang-format to roundtrip_dash.cpp
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
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,183 @@ | ||
| // 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. | ||
|
|
||
| // Roundtrip (deserialize -> serialize -> deserialize -> serialize) fuzz targets | ||
| // for Dash-specific types. | ||
|
|
||
| #include <test/fuzz/fuzz.h> | ||
| #include <test/util/setup_common.h> | ||
|
|
||
| #include <streams.h> | ||
| #include <version.h> | ||
|
|
||
| // evo/ types | ||
| #include <evo/assetlocktx.h> | ||
| #include <evo/cbtx.h> | ||
| #include <evo/creditpool.h> | ||
| #include <evo/deterministicmns.h> | ||
| #include <evo/dmnstate.h> | ||
| #include <evo/mnauth.h> | ||
| #include <evo/mnhftx.h> | ||
| #include <evo/providertx.h> | ||
| #include <evo/simplifiedmns.h> | ||
| #include <evo/smldiff.h> | ||
|
|
||
| // llmq/ types | ||
| #include <llmq/commitment.h> | ||
| #include <llmq/dkgsession.h> | ||
| #include <llmq/quorums.h> | ||
| #include <llmq/signing.h> | ||
| #include <llmq/signing_shares.h> | ||
| #include <llmq/snapshot.h> | ||
|
|
||
| // governance/ types | ||
| #include <governance/object.h> | ||
|
|
||
| // bls/ types | ||
| #include <bls/bls_ies.h> | ||
|
|
||
| // coinjoin/ types | ||
| #include <coinjoin/coinjoin.h> | ||
|
|
||
| #include <cassert> | ||
| #include <exception> | ||
| #include <stdint.h> | ||
|
|
||
| namespace { | ||
|
|
||
| const BasicTestingSetup* g_setup; | ||
|
|
||
| struct dash_invalid_fuzzing_input_exception : public std::exception { | ||
| }; | ||
|
|
||
| template <typename T> | ||
| void DashRoundtripFromFuzzingInput(FuzzBufferType buffer, T& obj) | ||
| { | ||
| CDataStream ds(buffer, SER_NETWORK, INIT_PROTO_VERSION); | ||
| try { | ||
| int version; | ||
| ds >> version; | ||
| ds.SetVersion(version); | ||
| } catch (const std::ios_base::failure&) { | ||
| throw dash_invalid_fuzzing_input_exception(); | ||
| } | ||
|
|
||
| try { | ||
| ds >> obj; | ||
| } catch (const std::ios_base::failure&) { | ||
| throw dash_invalid_fuzzing_input_exception(); | ||
| } | ||
|
|
||
| CDataStream ds2(SER_NETWORK, ds.GetVersion()); | ||
| ds2 << obj; | ||
|
|
||
| T obj2 = obj; | ||
| CDataStream ds3(Span<const std::byte>{ds2}, SER_NETWORK, ds.GetVersion()); | ||
| try { | ||
| ds3 >> obj2; | ||
| } catch (const std::ios_base::failure&) { | ||
| assert(false); | ||
| } | ||
|
|
||
| CDataStream ds4(SER_NETWORK, ds.GetVersion()); | ||
| ds4 << obj2; | ||
|
|
||
| assert(MakeByteSpan(ds2) == MakeByteSpan(ds4)); | ||
| } | ||
|
|
||
| template <typename T> | ||
| void DashRoundtripFromFuzzingInput(FuzzBufferType buffer) | ||
| { | ||
| T obj; | ||
| DashRoundtripFromFuzzingInput(buffer, obj); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| void initialize_roundtrip_dash() | ||
| { | ||
| static const auto testing_setup = MakeNoLogFileContext<>(); | ||
| g_setup = testing_setup.get(); | ||
| } | ||
|
|
||
| #define FUZZ_TARGET_DASH_ROUNDTRIP(name, code) \ | ||
| FUZZ_TARGET(name, .init = initialize_roundtrip_dash) \ | ||
| { \ | ||
| try { \ | ||
| code \ | ||
| } catch (const dash_invalid_fuzzing_input_exception&) { \ | ||
| } \ | ||
| } | ||
|
|
||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_proreg_tx_roundtrip, { DashRoundtripFromFuzzingInput<CProRegTx>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_proupserv_tx_roundtrip, { DashRoundtripFromFuzzingInput<CProUpServTx>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_proupreg_tx_roundtrip, { DashRoundtripFromFuzzingInput<CProUpRegTx>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_prouprev_tx_roundtrip, { DashRoundtripFromFuzzingInput<CProUpRevTx>(buffer); }) | ||
|
|
||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_asset_lock_payload_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<CAssetLockPayload>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_asset_unlock_payload_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<CAssetUnlockPayload>(buffer); }) | ||
|
|
||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_cbtx_roundtrip, { DashRoundtripFromFuzzingInput<CCbTx>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_credit_pool_roundtrip, { DashRoundtripFromFuzzingInput<CCreditPool>(buffer); }) | ||
|
|
||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_deterministic_mn_roundtrip, { | ||
| CDeterministicMN obj(0 /* internalId, overwritten by deserialization */); | ||
| DashRoundtripFromFuzzingInput(buffer, obj); | ||
| }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_dmn_state_roundtrip, { DashRoundtripFromFuzzingInput<CDeterministicMNState>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_dmn_state_diff_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<CDeterministicMNStateDiff>(buffer); }) | ||
|
|
||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_smn_list_entry_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<CSimplifiedMNListEntry>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_get_smn_list_diff_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<CGetSimplifiedMNListDiff>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_smn_list_diff_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<CSimplifiedMNListDiff>(buffer); }) | ||
|
|
||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_mnauth_roundtrip, { DashRoundtripFromFuzzingInput<CMNAuth>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_mnhf_tx_payload_roundtrip, { DashRoundtripFromFuzzingInput<MNHFTxPayload>(buffer); }) | ||
|
|
||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_final_commitment_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<llmq::CFinalCommitment>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_final_commitment_tx_payload_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<llmq::CFinalCommitmentTxPayload>(buffer); }) | ||
|
|
||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_dkg_complaint_roundtrip, { DashRoundtripFromFuzzingInput<llmq::CDKGComplaint>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_dkg_justification_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<llmq::CDKGJustification>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_dkg_premature_commitment_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<llmq::CDKGPrematureCommitment>(buffer); }) | ||
|
|
||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_recovered_sig_roundtrip, { DashRoundtripFromFuzzingInput<llmq::CRecoveredSig>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_sig_share_roundtrip, { DashRoundtripFromFuzzingInput<llmq::CSigShare>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_sig_ses_ann_roundtrip, { DashRoundtripFromFuzzingInput<llmq::CSigSesAnn>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_sig_shares_inv_roundtrip, { DashRoundtripFromFuzzingInput<llmq::CSigSharesInv>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_batched_sig_shares_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<llmq::CBatchedSigShares>(buffer); }) | ||
|
|
||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_quorum_data_request_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<llmq::CQuorumDataRequest>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_get_quorum_rotation_info_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<llmq::CGetQuorumRotationInfo>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_quorum_snapshot_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<llmq::CQuorumSnapshot>(buffer); }) | ||
|
|
||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_governance_object_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<CGovernanceObject>(buffer); }) | ||
|
|
||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_bls_ies_encrypted_blob_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<CBLSIESEncryptedBlob>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_bls_ies_multi_recipient_blobs_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<CBLSIESMultiRecipientBlobs>(buffer); }) | ||
|
|
||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_coinjoin_status_update_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<CCoinJoinStatusUpdate>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_coinjoin_accept_roundtrip, { DashRoundtripFromFuzzingInput<CCoinJoinAccept>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_coinjoin_entry_roundtrip, { DashRoundtripFromFuzzingInput<CCoinJoinEntry>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_coinjoin_queue_roundtrip, { DashRoundtripFromFuzzingInput<CCoinJoinQueue>(buffer); }) | ||
| FUZZ_TARGET_DASH_ROUNDTRIP(dash_coinjoin_broadcast_tx_roundtrip, | ||
| { DashRoundtripFromFuzzingInput<CCoinJoinBroadcastTx>(buffer); }) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: dashpay/dash
Length of output: 782
🏁 Script executed:
Repository: dashpay/dash
Length of output: 1977
Add
src/test/fuzz/roundtrip_dash.cpptotest/util/data/non-backported.txtThis Dash-specific
.cppfile is not currently listed intest/util/data/non-backported.txt, which is required for clang-format enforcement. Insertsrc/test/fuzz/roundtrip_dash.cppalphabetically aftersrc/test/evo*.cpp(line 57).🤖 Prompt for AI Agents