From bc92a4328aec7315604285d0c08c2ad7a0e32f2b Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 20 Oct 2026 22:34:41 +0700 Subject: [PATCH 1/2] feat(dash)!: temporarily expose the unverified coinbase of the newest masternode list diff NOT SECURE, AND TEMPORARY. Nothing authenticates the coinbase payload this exposes, and the dev branch replaces it with a verified version (dashpay/rust-dashcore#1202, which depends on #1200). It exists only because Platform v5.0 ships on this branch and needs the signal before that verified version reaches it. Every MnListDiff carries its block's coinbase transaction, but the masternode list engine dropped it, so an SPV consumer could not read the coinbase payload version. Dash Core requires version 4 once V24 is active, and Platform's wallet needs that to pick the ProUpServTx version Core accepts for an evonode. MasternodeListEngine now keeps the coinbase payload of the diff applied for the highest block, from apply_diff (and so every diff a QRInfo carries) and initialize_with_diff_to_height, and exposes it as latest_coinbase(). DashSpvClient::latest_coinbase() reads it. Both use the names and return types #1202 uses on dev. A diff applied later for a lower block does not replace it, a diff applied again for the same block does, and a payload whose height is not the height the diff was applied at is dropped with a warning. Why it is not secure: the diff's merkle proof of the coinbase and the payload's merkle roots are not checked, so one peer can serve a diff whose quorums verify together with a payload of its choosing. Every doc comment on the new API says so and points to the replacement. The payload is kept in memory only. serde skips it, and the engine's bincode Encode/Decode are now written out with the derived layout minus that field, since the bincode derive cannot skip one. Persisted engines decode unchanged: the engine fixture re-encodes byte for byte, with or without a payload kept. BorrowDecode now goes through Decode, which also makes borrow-decoding the engine fixture work; the derived BorrowDecode read hashes in a different shape and failed on it. Breaking: the new field is pub like the engine's other fields, so struct literals that list every field must add it; `..Default::default()` keeps working. Tests cover a v3 then v4 coinbase, a repeated diff for the same block, a lower diff applied after a higher one, failed applies before and after the base list is found, a coinbase without a payload, payloads naming a lower, higher or u32::MAX height while a payload is already kept, the QRInfo path, bincode and serde persistence, and the client accessor. Each recording rule and both persistence exclusions were mutated in turn, and every mutation failed at least one of these tests. Co-Authored-By: Claude Opus 5.5 --- dash-spv/src/client/mod.rs | 61 +++++ dash-spv/src/client/queries.rs | 15 + dash/src/sml/masternode_list_engine/mod.rs | 305 ++++++++++++++++++++- 3 files changed, 378 insertions(+), 3 deletions(-) diff --git a/dash-spv/src/client/mod.rs b/dash-spv/src/client/mod.rs index 6a7c8bda5..aeceed111 100644 --- a/dash-spv/src/client/mod.rs +++ b/dash-spv/src/client/mod.rs @@ -43,6 +43,12 @@ mod tests { use crate::storage::DiskStorageManager; use crate::test_utils::MockNetworkManager; use crate::Network; + use dashcore::bls_sig_utils::BLSSignature; + use dashcore::hash_types::{ + MerkleRootAssetUnlocks, MerkleRootMasternodeList, MerkleRootQuorums, + }; + use dashcore::hashes::Hash; + use dashcore::transaction::special_transaction::coinbase::CoinbasePayload; use key_wallet::wallet::initialization::WalletAccountCreationOptions; use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo; use key_wallet_manager::WalletManager; @@ -137,4 +143,59 @@ mod tests { let wallet_ref = client.wallet(); let _wallet_guard = wallet_ref.read().await; } + + /// The client reports the coinbase payload the masternode list engine + /// kept, and nothing while masternode sync is off. + #[tokio::test] + async fn latest_coinbase_reports_what_the_masternode_list_engine_kept() { + let make_client = |config: ClientConfig| async move { + let storage = + DiskStorageManager::with_temp_dir().await.expect("Failed to create tmp storage"); + let wallet = + Arc::new(RwLock::new(WalletManager::::new(config.network))); + DashSpvClient::new( + config, + MockNetworkManager::new(), + storage, + wallet, + vec![Arc::new(())], + ) + .await + .expect("client construction must succeed") + }; + let storage_dir = TempDir::new().unwrap(); + + let without_masternodes = make_client( + ClientConfig::mainnet() + .without_filters() + .without_masternodes() + .with_storage_path(storage_dir.path()), + ) + .await; + assert_eq!(without_masternodes.latest_coinbase().await, None); + + let with_masternodes = make_client( + ClientConfig::mainnet().without_filters().with_storage_path(storage_dir.path()), + ) + .await; + assert_eq!(with_masternodes.latest_coinbase().await, None); + + let coinbase = CoinbasePayload { + version: 4, + height: 2_400_000, + merkle_root_masternode_list: MerkleRootMasternodeList::all_zeros(), + merkle_root_quorums: MerkleRootQuorums::all_zeros(), + best_cl_height: Some(0), + best_cl_signature: Some(BLSSignature::from([0; 96])), + asset_locked_amount: Some(0), + merkle_root_asset_unlocks: Some(MerkleRootAssetUnlocks::all_zeros()), + }; + with_masternodes + .masternode_list_engine() + .expect("masternode sync is on") + .write() + .await + .latest_coinbase = Some(coinbase.clone()); + assert_eq!(with_masternodes.latest_coinbase().await, Some(coinbase)); + } } diff --git a/dash-spv/src/client/queries.rs b/dash-spv/src/client/queries.rs index 00836b220..1b4741719 100644 --- a/dash-spv/src/client/queries.rs +++ b/dash-spv/src/client/queries.rs @@ -12,6 +12,7 @@ use crate::storage::StorageManager; use dashcore::sml::llmq_type::LLMQType; use dashcore::sml::masternode_list_engine::MasternodeListEngine; use dashcore::sml::quorum_entry::qualified_quorum_entry::QualifiedQuorumEntry; +use dashcore::transaction::special_transaction::coinbase::CoinbasePayload; use dashcore::QuorumHash; use key_wallet_manager::WalletInterface; use std::sync::Arc; @@ -43,6 +44,20 @@ impl DashSpvClient Option { + let engine = self.masternode_engine.as_ref()?; + engine.read().await.latest_coinbase().cloned() + } + /// Get a quorum entry by type and hash at a specific block height. /// Returns `SpvError::QuorumLookupError` if the quorum is not found. pub async fn get_quorum_at_height( diff --git a/dash/src/sml/masternode_list_engine/mod.rs b/dash/src/sml/masternode_list_engine/mod.rs index 0be111c73..37c992b07 100644 --- a/dash/src/sml/masternode_list_engine/mod.rs +++ b/dash/src/sml/masternode_list_engine/mod.rs @@ -29,6 +29,8 @@ use crate::sml::quorum_entry::qualified_quorum_entry::QualifiedQuorumEntry; #[cfg(feature = "quorum_validation")] use crate::sml::quorum_entry::qualified_quorum_entry::VerifyingChainLockSignaturesType; use crate::sml::quorum_validation_error::QuorumValidationError; +use crate::transaction::special_transaction::TransactionPayload; +use crate::transaction::special_transaction::coinbase::CoinbasePayload; use crate::transaction::special_transaction::quorum_commitment::QuorumEntry; use crate::{BlockHash, QuorumHash}; #[cfg(feature = "bincode")] @@ -238,7 +240,6 @@ impl MasternodeListEngineBlockContainer { #[derive(Clone, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "bincode", derive(Encode, Decode))] pub struct MasternodeListEngine { pub block_container: MasternodeListEngineBlockContainer, pub masternode_lists: BTreeMap, @@ -253,6 +254,12 @@ pub struct MasternodeListEngine { >, >, pub network: Network, + /// Not secure, and temporary: see + /// [`MasternodeListEngine::latest_coinbase`]. Kept in memory only: serde + /// and bincode skip it, so a persisted engine keeps its layout and decodes + /// with `None`. It still takes part in `==`. + #[cfg_attr(feature = "serde", serde(skip))] + pub latest_coinbase: Option, } impl Default for MasternodeListEngine { @@ -264,10 +271,58 @@ impl Default for MasternodeListEngine { rotated_quorums_per_cycle: Default::default(), quorum_statuses: Default::default(), network: Network::Mainnet, + latest_coinbase: None, } } } +// Same layout as a derived impl without `latest_coinbase`, which is not +// persisted, so engines encoded before that field existed keep decoding. +// The field is temporary; once it is gone, the derive can return. +#[cfg(feature = "bincode")] +impl Encode for MasternodeListEngine { + fn encode( + &self, + encoder: &mut E, + ) -> Result<(), bincode::error::EncodeError> { + let Self { + block_container, + masternode_lists, + known_snapshots, + rotated_quorums_per_cycle, + quorum_statuses, + network, + latest_coinbase: _, + } = self; + block_container.encode(encoder)?; + masternode_lists.encode(encoder)?; + known_snapshots.encode(encoder)?; + rotated_quorums_per_cycle.encode(encoder)?; + quorum_statuses.encode(encoder)?; + network.encode(encoder) + } +} + +#[cfg(feature = "bincode")] +impl Decode for MasternodeListEngine { + fn decode>( + decoder: &mut D, + ) -> Result { + Ok(Self { + block_container: Decode::decode(decoder)?, + masternode_lists: Decode::decode(decoder)?, + known_snapshots: Decode::decode(decoder)?, + rotated_quorums_per_cycle: Decode::decode(decoder)?, + quorum_statuses: Decode::decode(decoder)?, + network: Decode::decode(decoder)?, + latest_coinbase: None, + }) + } +} + +#[cfg(feature = "bincode")] +bincode::impl_borrow_decode!(MasternodeListEngine); + /// Builds a per-cycle quorum map keyed by `quorum_index`. /// Rejects missing, negative, out-of-range, or duplicate indices. The map may /// hold fewer entries than the active quorum count: a quorum whose commitment @@ -326,6 +381,15 @@ fn qr_info_diffs(qr_info: &QRInfo) -> Vec<&MnListDiff> { diffs } +/// The coinbase payload (DIP-4) of the block `diff` ends at, if its coinbase +/// carries one. +fn coinbase_payload(diff: &MnListDiff) -> Option { + match &diff.coinbase_tx.special_transaction_payload { + Some(TransactionPayload::CoinbasePayloadType(payload)) => Some(payload.clone()), + _ => None, + } +} + /// Cycle base height, the height of the quorum-index-0 block, for a rotated /// quorum whose commitment sits at `quorum_block_height`. /// @@ -384,9 +448,10 @@ impl MasternodeListEngine { ) -> Result { let block_hash = masternode_list_diff.block_hash; let base_block_hash = masternode_list_diff.base_block_hash; + let coinbase = coinbase_payload(&masternode_list_diff); let masternode_list = masternode_list_diff .try_into_with_block_hash_lookup(|_block_hash| Some(block_height), network)?; - Ok(Self { + let mut engine = Self { block_container: MasternodeListEngineBTreeMapBlockContainer { block_hashes: [(0, base_block_hash), (block_height, block_hash)].into(), block_heights: [(base_block_hash, 0), (block_hash, block_height)].into(), @@ -397,7 +462,10 @@ impl MasternodeListEngine { rotated_quorums_per_cycle: Default::default(), quorum_statuses: Default::default(), network, - }) + latest_coinbase: None, + }; + engine.record_coinbase(coinbase, block_height); + Ok(engine) } /// Gets the most recent masternode list. @@ -408,6 +476,51 @@ impl MasternodeListEngine { self.masternode_lists.last_key_value().map(|(_, list)| list) } + /// The coinbase payload of the highest block a masternode list diff was + /// applied for. + /// + /// **Not secure, and temporary.** Nothing authenticates the payload: the + /// engine checks neither the diff's merkle proof of the coinbase against + /// the block header nor the payload's merkle roots against the lists, so a + /// single peer can serve a diff whose quorums verify together with a + /// payload of its choosing. The `dev` branch replaces this with a version + /// that keeps only coinbases verified against their block + /// (dashpay/rust-dashcore#1202). + /// + /// Every `MnListDiff` carries its block's coinbase transaction. Each diff + /// the engine applies, including those [`Self::feed_qr_info`] and + /// [`Self::initialize_with_diff_to_height`] apply, replaces the kept + /// payload unless a higher block's is kept; a diff applied again for the + /// same block replaces it, as it does that block's list. A payload whose + /// `height` is not the height the diff was applied at is not kept, since + /// Core requires the two to match. `None` until a diff whose coinbase + /// carries a payload is applied, and after decoding, since the payload is + /// not persisted. + pub fn latest_coinbase(&self) -> Option<&CoinbasePayload> { + self.latest_coinbase.as_ref() + } + + /// Keeps `coinbase`, the coinbase payload of a diff applied at `height`, as + /// [`Self::latest_coinbase`] unless it names another height or a higher + /// block's payload is already kept. + fn record_coinbase(&mut self, coinbase: Option, height: CoreBlockHeight) { + let Some(coinbase) = coinbase else { + return; + }; + if coinbase.height != height { + tracing::warn!( + "Ignoring the coinbase payload of the masternode list diff at height {}: it names height {}", + height, + coinbase.height + ); + return; + } + if self.latest_coinbase.as_ref().is_some_and(|latest| latest.height > height) { + return; + } + self.latest_coinbase = Some(coinbase); + } + /// Gets all quorum hashes from the latest masternode list. /// /// # Parameters @@ -1490,6 +1603,7 @@ impl MasternodeListEngine { verify_quorums: bool, previous_chain_lock_sigs: Option<[BLSSignature; 3]>, ) -> Result, SmlError> { + let coinbase = coinbase_payload(&masternode_list_diff); if let Some(known_genesis_block_hash) = self .network .known_genesis_block_hash() @@ -1516,6 +1630,7 @@ impl MasternodeListEngine { } }; self.masternode_lists.insert(diff_end_height, masternode_list); + self.record_coinbase(coinbase, diff_end_height); return Ok(None); } @@ -1639,6 +1754,7 @@ impl MasternodeListEngine { rotation_sig }; + self.record_coinbase(coinbase, diff_end_height); self.block_container.feed_block_height(diff_end_height, block_hash); Ok(rotation_sig) @@ -1799,6 +1915,8 @@ mod tests { }; #[cfg(feature = "quorum_validation")] use crate::sml::quorum_validation_error::QuorumValidationError; + use crate::transaction::special_transaction::TransactionPayload; + use crate::transaction::special_transaction::coinbase::CoinbasePayload; use bincode::{Decode, config, decode_from_slice}; use std::collections::BTreeMap; #[cfg(feature = "quorum_validation")] @@ -3037,4 +3155,185 @@ mod tests { "a smaller verified set must not shrink a larger stored cycle" ); } + + /// Real mainnet diffs from genesis to 2227096 and on to 2241332. Their + /// coinbases carry version-3 payloads. + fn coinbase_fixture_diffs() -> (MnListDiff, MnListDiff) { + let to_2227096: MnListDiff = deserialize(include_bytes!( + "../../../tests/data/test_DML_diffs/mn_list_diff_0_2227096.bin" + )) + .expect("expected to deserialize"); + let to_2241332: MnListDiff = deserialize(include_bytes!( + "../../../tests/data/test_DML_diffs/mn_list_diff_2227096_2241332.bin" + )) + .expect("expected to deserialize"); + (to_2227096, to_2241332) + } + + fn coinbase_payload_mut(diff: &mut MnListDiff) -> &mut CoinbasePayload { + match &mut diff.coinbase_tx.special_transaction_payload { + Some(TransactionPayload::CoinbasePayloadType(payload)) => payload, + other => panic!("the fixture's coinbase must carry a coinbase payload, got {other:?}"), + } + } + + fn latest_coinbase_height_and_version(engine: &MasternodeListEngine) -> Option<(u32, u16)> { + engine.latest_coinbase().map(|coinbase| (coinbase.height, coinbase.version)) + } + + /// Core requires a version-4 coinbase payload once V24 is active, so a + /// consumer reads V24 from the coinbase of the newest diff. The engine + /// must report the version that diff brought, not the first one it saw. + #[test] + fn latest_coinbase_reports_the_payload_of_the_newest_diff() { + let (to_2227096, mut to_2241332) = coinbase_fixture_diffs(); + coinbase_payload_mut(&mut to_2241332).version = 4; + let mut to_2241332_again = to_2241332.clone(); + coinbase_payload_mut(&mut to_2241332_again).version = 5; + + let mut engine = MasternodeListEngine::initialize_with_diff_to_height( + to_2227096, + 2227096, + Network::Mainnet, + ) + .expect("expected to start engine"); + assert_eq!(latest_coinbase_height_and_version(&engine), Some((2227096, 3))); + + engine.apply_diff(to_2241332, Some(2241332), false, None).expect("expected to apply diff"); + assert_eq!(latest_coinbase_height_and_version(&engine), Some((2241332, 4))); + + // A diff applied again for the same block replaces the kept payload, + // as it replaces that block's list. + engine + .apply_diff(to_2241332_again, Some(2241332), false, None) + .expect("expected to apply the diff again"); + assert_eq!(latest_coinbase_height_and_version(&engine), Some((2241332, 5))); + } + + /// Diffs are not applied in height order: every QRInfo after the first + /// applies diffs for work blocks below the previous QRInfo's tip. Those + /// must not hide the coinbase of the highest block. + #[test] + fn latest_coinbase_keeps_the_highest_block_when_a_lower_diff_applies_later() { + let (to_2227096, mut to_2241332) = coinbase_fixture_diffs(); + coinbase_payload_mut(&mut to_2241332).version = 4; + let mut engine = MasternodeListEngine::default_for_network(Network::Mainnet); + + engine + .apply_diff(to_2227096.clone(), Some(2227096), false, None) + .expect("expected to apply diff"); + assert_eq!(latest_coinbase_height_and_version(&engine), Some((2227096, 3))); + engine.apply_diff(to_2241332, Some(2241332), false, None).expect("expected to apply diff"); + engine + .apply_diff(to_2227096, Some(2227096), false, None) + .expect("expected to apply the lower diff again"); + + assert_eq!(latest_coinbase_height_and_version(&engine), Some((2241332, 4))); + } + + /// Only a coinbase the engine can place at a block it applied replaces + /// the kept one: a diff that fails to apply, a coinbase without a + /// coinbase payload, and a payload naming another height than the diff's + /// block leave it in place. A payload kept for a height above its block's + /// would hide every later coinbase. + #[test] + fn latest_coinbase_ignores_a_coinbase_it_cannot_place() { + let (to_2227096, to_2241332) = coinbase_fixture_diffs(); + let mut engine = MasternodeListEngine::default_for_network(Network::Mainnet); + + engine + .apply_diff(to_2241332.clone(), Some(2241332), false, None) + .expect_err("the engine holds no list for the diff's base block"); + assert_eq!(engine.latest_coinbase(), None); + + engine.apply_diff(to_2227096, Some(2227096), false, None).expect("expected to apply diff"); + let kept = Some((2227096, 3)); + assert_eq!(latest_coinbase_height_and_version(&engine), kept); + + let mut unsigned = to_2241332.clone(); + unsigned.quorums_chainlock_signatures.clear(); + coinbase_payload_mut(&mut unsigned).version = 4; + engine + .apply_diff(unsigned, Some(2241332), false, None) + .expect_err("a diff past V20 must carry its new quorums' ChainLock signatures"); + assert_eq!(latest_coinbase_height_and_version(&engine), kept); + + let mut without_payload = to_2241332.clone(); + without_payload.coinbase_tx.special_transaction_payload = None; + engine + .apply_diff(without_payload, Some(2241332), false, None) + .expect("expected to apply diff"); + assert_eq!(latest_coinbase_height_and_version(&engine), kept); + + for claimed_height in [2241331, 2241333, u32::MAX] { + let mut other_height = to_2241332.clone(); + coinbase_payload_mut(&mut other_height).height = claimed_height; + engine + .apply_diff(other_height, Some(2241332), false, None) + .expect("expected to apply diff"); + assert_eq!( + latest_coinbase_height_and_version(&engine), + kept, + "a payload claiming height {claimed_height} must not be kept" + ); + } + + engine.apply_diff(to_2241332, Some(2241332), false, None).expect("expected to apply diff"); + assert_eq!(latest_coinbase_height_and_version(&engine), Some((2241332, 3))); + } + + /// A syncing client gets its first lists from a QRInfo, so the diffs + /// `feed_qr_info` applies must be recorded too. The tip diff ends + /// highest, so its coinbase is the one kept. + #[test] + #[cfg(feature = "quorum_validation")] + fn feed_qr_info_keeps_the_coinbase_of_its_tip_diff() { + let (mut engine, qr_info) = load_qrinfo_2518986_fixture(); + + engine.feed_qr_info(qr_info, false, false).expect("expected to feed the QRInfo"); + + assert_eq!(latest_coinbase_height_and_version(&engine), Some((2518986, 3))); + } + + /// Engines are persisted (the fixture is one), and consumers decode them + /// with code that does not know the kept coinbase. Keeping it must not + /// change what an engine encodes to, and a decoded engine has none. + #[test] + fn latest_coinbase_is_not_persisted() { + let fixture = hex::decode(include_str!( + "../../../tests/data/test_DML_diffs/masternode_list_engine.hex" + )) + .expect("decode hex"); + let mut engine: MasternodeListEngine = decode_fixture(&fixture); + assert_eq!(engine.latest_coinbase(), None); + let encode = |engine: &MasternodeListEngine| { + bincode::encode_to_vec(engine, config::standard()).expect("expected to encode") + }; + assert_eq!(encode(&engine), fixture, "a decoded engine must encode back to the fixture"); + + let (to_2227096, _) = coinbase_fixture_diffs(); + engine.latest_coinbase = super::coinbase_payload(&to_2227096); + assert!(engine.latest_coinbase().is_some()); + assert_eq!(encode(&engine), fixture, "the kept coinbase must not be encoded"); + + #[cfg(feature = "serde")] + { + let serde_encode = |engine: &MasternodeListEngine| { + bincode::serde::encode_to_vec(engine, config::standard()) + .expect("expected to encode with serde") + }; + let with_coinbase = serde_encode(&engine); + let mut without_coinbase = engine.clone(); + without_coinbase.latest_coinbase = None; + assert_eq!( + with_coinbase, + serde_encode(&without_coinbase), + "serde must skip the kept coinbase" + ); + let (decoded, _): (MasternodeListEngine, usize) = + bincode::serde::decode_from_slice(&with_coinbase, config::standard()) + .expect("expected to decode with serde"); + assert!(decoded == without_coinbase, "serde must decode the engine without a coinbase"); + } + } } From 84ea6914f7d012eb12c1022b455262267814fc00 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 21 Oct 2026 01:11:43 +0700 Subject: [PATCH 2/2] docs(dash): lead every doc of the temporary coinbase API with its warning The accessor docs opened with a neutral summary and warned only in their second paragraph, so search results and hovers showed a plain "newest coinbase" accessor. Every doc of the API (engine method, engine field, client method) now opens with "Not secure, and temporary" and names the verified replacement on dev, dashpay/rust-dashcore#1202. The docs also stated the exposure too narrowly. Quorum verification does not gate the payload: any applied diff sets it, including one from a QRInfo the engine then rejects. And the kept payload can belong to a lower block than the highest list when the highest diff's payload is missing or names another height. The client doc now says it is None after a restart until a diff is applied, since the payload is not persisted. Two test helpers get one-line docs. Doc comments only, no behaviour change, so no new test. Co-Authored-By: Claude Opus 5.5 --- dash-spv/src/client/queries.rs | 16 ++++++------- dash/src/sml/masternode_list_engine/mod.rs | 26 +++++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/dash-spv/src/client/queries.rs b/dash-spv/src/client/queries.rs index 1b4741719..ad6357261 100644 --- a/dash-spv/src/client/queries.rs +++ b/dash-spv/src/client/queries.rs @@ -44,15 +44,15 @@ impl DashSpvClient Option { let engine = self.masternode_engine.as_ref()?; engine.read().await.latest_coinbase().cloned() diff --git a/dash/src/sml/masternode_list_engine/mod.rs b/dash/src/sml/masternode_list_engine/mod.rs index 37c992b07..0381fe9e7 100644 --- a/dash/src/sml/masternode_list_engine/mod.rs +++ b/dash/src/sml/masternode_list_engine/mod.rs @@ -254,7 +254,8 @@ pub struct MasternodeListEngine { >, >, pub network: Network, - /// Not secure, and temporary: see + /// **Not secure, and temporary:** replaced on the `dev` branch by a version + /// that keeps only verified coinbases (dashpay/rust-dashcore#1202); see /// [`MasternodeListEngine::latest_coinbase`]. Kept in memory only: serde /// and bincode skip it, so a persisted engine keeps its layout and decodes /// with `None`. It still takes part in `==`. @@ -476,16 +477,16 @@ impl MasternodeListEngine { self.masternode_lists.last_key_value().map(|(_, list)| list) } - /// The coinbase payload of the highest block a masternode list diff was - /// applied for. + /// **Not secure, and temporary:** the unverified coinbase payload of the + /// highest block an applied masternode list diff carried one for, replaced + /// on the `dev` branch by a version that keeps only coinbases verified + /// against their block (dashpay/rust-dashcore#1202). /// - /// **Not secure, and temporary.** Nothing authenticates the payload: the - /// engine checks neither the diff's merkle proof of the coinbase against - /// the block header nor the payload's merkle roots against the lists, so a - /// single peer can serve a diff whose quorums verify together with a - /// payload of its choosing. The `dev` branch replaces this with a version - /// that keeps only coinbases verified against their block - /// (dashpay/rust-dashcore#1202). + /// Nothing authenticates the payload. The engine checks neither the diff's + /// merkle proof of the coinbase against the block header nor the payload's + /// merkle roots against the lists, and quorum verification does not gate + /// it: any diff the engine applies sets it, even one from a QRInfo the + /// engine then rejects. A single peer can serve a payload of its choosing. /// /// Every `MnListDiff` carries its block's coinbase transaction. Each diff /// the engine applies, including those [`Self::feed_qr_info`] and @@ -493,7 +494,8 @@ impl MasternodeListEngine { /// payload unless a higher block's is kept; a diff applied again for the /// same block replaces it, as it does that block's list. A payload whose /// `height` is not the height the diff was applied at is not kept, since - /// Core requires the two to match. `None` until a diff whose coinbase + /// Core requires the two to match, so the kept payload can be a lower + /// block's than the highest list's. `None` until a diff whose coinbase /// carries a payload is applied, and after decoding, since the payload is /// not persisted. pub fn latest_coinbase(&self) -> Option<&CoinbasePayload> { @@ -3170,6 +3172,7 @@ mod tests { (to_2227096, to_2241332) } + /// The coinbase payload of `diff`, for tests that tamper with it. fn coinbase_payload_mut(diff: &mut MnListDiff) -> &mut CoinbasePayload { match &mut diff.coinbase_tx.special_transaction_payload { Some(TransactionPayload::CoinbasePayloadType(payload)) => payload, @@ -3177,6 +3180,7 @@ mod tests { } } + /// The height and version of the payload the engine kept. fn latest_coinbase_height_and_version(engine: &MasternodeListEngine) -> Option<(u32, u16)> { engine.latest_coinbase().map(|coinbase| (coinbase.height, coinbase.version)) }