From cc7b73c6e0ce9e30b6b080dced5b51668841441c Mon Sep 17 00:00:00 2001
From: Lukasz Klimek <842586+lklimek@users.noreply.github.com>
Date: Thu, 5 Nov 2026 10:58:49 +0000
Subject: [PATCH 01/38] fix(wallet): authenticate pending spends and
InstantLock evidence
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Move owner authorization policy into key-wallet. Reject unverified SPV
InstantLock events before wallet mutation and expose authenticated,
transaction-bound evidence for safely restoring historical records.
Add signed test fixtures using the public verification query; preserve
unsupported authorization as an error so existing holds remain safe.
🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent
Co-Authored-By: Claude gpt-6-astra
---
dash-spv/Cargo.toml | 2 +
dash-spv/src/client/queries.rs | 20 +-
dash-spv/src/lib.rs | 1 +
dash-spv/src/sml_engine.rs | 9 +
dash-spv/src/sync/mempool/manager.rs | 73 +++++
dash-spv/src/sync/mempool/sync_manager.rs | 2 +-
dash-spv/src/test_utils/instant_lock.rs | 98 ++++++
dash-spv/src/test_utils/mod.rs | 2 +
dash-spv/src/validation/instantlock.rs | 148 +++++++++-
dash-spv/src/validation/mod.rs | 5 +-
dash-spv/tests/instant_lock_evidence.rs | 83 ++++++
key-wallet/Cargo.toml | 1 +
key-wallet/src/transaction_checking/mod.rs | 3 +
.../spend_authorization.rs | 278 ++++++++++++++++++
14 files changed, 721 insertions(+), 4 deletions(-)
create mode 100644 dash-spv/src/test_utils/instant_lock.rs
create mode 100644 dash-spv/tests/instant_lock_evidence.rs
create mode 100644 key-wallet/src/transaction_checking/spend_authorization.rs
diff --git a/dash-spv/Cargo.toml b/dash-spv/Cargo.toml
index 8f32f7b74..316b09ada 100644
--- a/dash-spv/Cargo.toml
+++ b/dash-spv/Cargo.toml
@@ -70,6 +70,7 @@ hex-conservative = { workspace = true }
bincode = { workspace = true }
# Test utilities (optional)
+dash-pkc = { workspace = true, features = ["bls", "std", "portable"], optional = true }
tempfile = { workspace = true, optional = true }
dashcore-rpc = { workspace = true, optional = true }
@@ -127,6 +128,7 @@ test-utils = [
"key-wallet-manager/test-utils",
"dep:tempfile",
"dep:dashcore-rpc",
+ "dep:dash-pkc",
]
[lints]
diff --git a/dash-spv/src/client/queries.rs b/dash-spv/src/client/queries.rs
index 2c2221adc..9b26a10f9 100644
--- a/dash-spv/src/client/queries.rs
+++ b/dash-spv/src/client/queries.rs
@@ -10,10 +10,11 @@ use crate::error::{Result, SpvError};
use crate::network::NetworkManager;
use crate::sml_engine::MasternodeListEngine;
use crate::storage::PersistentBlockHeaderStorage;
+use crate::validation::{InstantLockVerificationError, VerifiedInstantLock};
use dashcore::sml::llmq_type::LLMQType;
use dashcore::sml::masternode_list::MasternodeList;
use dashcore::sml::quorum_entry::qualified_quorum_entry::QualifiedQuorumEntry;
-use dashcore::QuorumHash;
+use dashcore::{InstantLock, QuorumHash};
use key_wallet_manager::WalletInterface;
use std::sync::Arc;
use tokio::sync::RwLock;
@@ -42,6 +43,23 @@ impl DashSpvClient {
}
}
+ /// Authenticates a lock using the client's synchronized quorum state.
+ ///
+ /// Returns `None` while its cycle or the masternode engine is unavailable.
+ /// Malformed locks and invalid signatures return an error. No network request
+ /// or wallet mutation is made; callers may retry after masternode sync advances.
+ /// Fetch this evidence before acquiring wallet or persistence write locks.
+ pub async fn verify_instant_lock(
+ &self,
+ instant_lock: &InstantLock,
+ ) -> std::result::Result