Repository navigation
Description
🚫 Blocker · Security · Moderate
A peer can fill the pending InstantLock queue with about 880 MB of locks it never has to sign
What goes wrong: A well-formed lock whose cyclehash names no stored cycle passes the structure check and is cloned into pending_instantlocks. Nothing checks its signature first. With up to 48780 inputs (about 1.76 MB each, under the 3 MB message cap) and 500 slots, one peer can hold about 880 MB for PENDING_TTL (one hour).
How to fix it, why, 17 places read, and 1 other check · confirmed with tools
How to fix it
Limit the pending queue by total input count or bytes instead of entry count. Once header sync is done, drop locks whose cyclehash is not a known block header, as Core's ResolveCycleHeight check does. Optionally cap pending entries per peer so one peer cannot evict others' genuine locks.
Why it matters
The FIFO eviction also pushes out genuine locks that are still waiting for quorum data. Pending dedupe is now by lock hash, so the flood can even reuse one txid. Dash Core drops a lock with an unknown cycleHash on receipt and penalizes the sender.
Checked in the code
On the commented line: self.queue_pending(PendingInstantLock::new(instantlock.clone(), hash)); stores the full lock
const MAX_PENDING_INSTANTLOCKS: usize = 500; counts entries, not bytes
rust-dashcore/dash-spv/src/sync/instantsend/manager.rs
Lines 21 to 25 in 3ccc21a
| /// Maximum number of pending InstantLocks awaiting validation. | |
| const MAX_PENDING_INSTANTLOCKS: usize = 500; | |
| /// Maximum number of verified txids to cache. | |
| const MAX_CACHE_SIZE: usize = 5000; |
An unknown cycle returns Ok(None) without any signature check
rust-dashcore/dash-spv/src/validation/instantlock.rs
Lines 90 to 94 in 3ccc21a
| }; | |
| let Some(cycle) = engine.instant_send_cycle(&instant_lock.cyclehash) else { | |
| return Ok(None); | |
| }; | |
| match InstantLockValidator::new(cycle.quorums).validate_signature(instant_lock) { |
MAX_MSG_SIZE: usize = 3 * 1024 * 1024 allows a lock of the maximum input count
rust-dashcore/dash/src/network/message.rs
Lines 44 to 48 in 3ccc21a
| /// 3 MiB. A header announcing a longer payload is refused before the payload is read. | |
| pub const MAX_MSG_SIZE: usize = 3 * 1024 * 1024; | |
| /// Size of a message header: magic, command, payload length and checksum. | |
| const MESSAGE_HEADER_SIZE: usize = 24; |
dash/src/network/message.rs:905:if payload_len > MAX_MSG_SIZE {dash/src/network/message.rs:432:let mut mem_d = io::Cursor::new(payload);dash/src/network/message.rs:573:NetworkMessage::ISLock(Decodable::consensus_decode_from_finite_reader(&mut mem_d)?)dash/src/consensus/encode.rs:395:pub(crate) const MAX_COMPACT_SIZE: u64 = 0x0200_0000;dash/src/consensus/encode.rs:745:let len = read_compact_size_len(r)?;dash-spv/src/network/peer.rs:132:let raw = RawNetworkMessageCodec.decode(src)?;dash-spv/src/sync/instantsend/sync_manager.rs:47:NetworkMessage::ISLock(instantlock) => self.process_instantlock(instantlock).await,dash-spv/src/sync/instantsend/manager.rs:152:if let Err(e) = InstantLockStructureValidator.validate(instantlock) {dash-spv/src/sync/instantsend/manager.rs:158:if self.pending_instantlocks.iter().any(|pending| pending.hash == hash) {dash-spv/src/sync/instantsend/manager.rs:207:if self.pending_instantlocks.len() >= MAX_PENDING_INSTANTLOCKS {dash-spv/src/sync/instantsend/manager.rs:208:let dropped = self.pending_instantlocks.remove(0);dash-spv/src/validation/instantlock.rs:112:const MAX_INSTANT_LOCK_INPUTS: usize = MAX_BLOCK_SIZE as usize / 41;dash-spv/src/validation/instantlock.rs:140:if instant_lock.inputs.len() > MAX_INSTANT_LOCK_INPUTS {- dashpay/dash:src/instantsend/net_instantsend.cpp:269-273 Core rejects a lock whose
cycleHashit cannot resolve and callsPeerMisbehaving
Double-checked
Manki tried to disprove this by reading the code and could not. A lock of at most 48780 inputs whose cyclehash names no stored cycle passes the structure check and gets Ok(None) from verify with no signature check. It is cl…
Found by Manki in #1336 at dash-spv/src/sync/instantsend/manager.rs:189. See the review thread.
Activity