Registry Mirror
Skip to content

Conversation

@lklimek

@lklimek lklimek commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Applications restoring transaction history need to authenticate saved InstantSend locks without trusting persisted status flags. Add DashSpvClient::verify_instant_lock, opaque VerifiedInstantLock evidence bound to a network and transaction, and a signed fixture for tests. Live InstantSend events and mempool handling use the same verification path and carry verified evidence.

Depends on #1336; this PR contains the verification API split requested in its review. dashpay/platform#5220 requires both PRs.

API-only changes can be reviewed in the comparison against #1336.

Breaking change: SyncEvent::InstantLockReceived carries a VerifiedInstantLock and no longer has a validated field. Call instant_lock.instant_lock() to access the raw lock. Missing quorum data returns Ok(None); malformed or refuted locks return an error.

🤖 Co-authored by Claudius the Magnificent AI Agent

lklimek and others added 30 commits November 5, 2026 11:06
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.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Claude gpt-6-astra <noreply@anthropic.com>
Classify an absent selected quorum or empty cycle as unavailable evidence,
while retaining errors for malformed locks and invalid BLS signatures.
Cover partial-cycle arrival and retry through the public verification API.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Claude gpt-6-astra <noreply@anthropic.com>
Witness remains available for legacy transaction encoding and does not
contribute to the transaction ID or owner authorization digest.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Claude gpt-6-astra <noreply@anthropic.com>
Retain the verifying engine's network in opaque evidence so wallet replay
can reject proofs from another network without trusting caller metadata.
Exercise public verification with both Mainnet and Testnet clients.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Claude gpt-6-astra <noreply@anthropic.com>
Preserve the InstantLock verification query alongside latest_coinbase,
snapshot v2 and lossless quorum-type bytes from current dev. Resolve
only the overlapping query imports; keep both APIs intact.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Claude gpt-6-astra <noreply@anthropic.com>
…izes a spend

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lock

Fails on the PR head: the forged lock is cached as unvalidated and the
genuine lock for the same txid is then dropped as a duplicate, so the
mempool (which now acts only on validated locks) never sees it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signs a 32-byte digest under the key's scheme, so crates that need BLS signatures (such as the dash-spv InstantLock test fixture) go through the `dashcore-crypto` newtypes instead of depending on `dash-pkc` directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`VerifiedInstantLock::verify` is now the single classifier for both `InstantSendManager` and `DashSpvClient::verify_instant_lock`: verified, deferred while quorum data is missing or incomplete, or rejected when malformed or refuted by a complete, verified cycle. The manager drops rejected locks instead of keeping them pending.

The manager deduplicates only against a verified lock or an identical pending one, so a forged, well-formed lock no longer shadows the genuine lock for the same txid. Once a lock for a txid verifies, the other pending locks for it are dropped and never emit.

Verification also requires every quorum of the cycle to be of the network's InstantSend quorum type (any rotating type on a devnet without an override).

Per-lock signature results log at trace and debug, so re-verifying a wallet's own locks does not write its txids at info or warn.

The test fixture signs through `dashcore-crypto` with the given network's InstantSend quorum type, drops the direct `dash-pkc` dependency, and documents that `install` makes its public test key verify on that client. `InstantLockFixture::new` takes the network.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`should_ignore_unverified_instant_lock` now checks the exact broadcast acceptance event, the removal of the broadcast and the lock handed to the wallet, and reuses the module's transaction and lock helpers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds a round trip through `TransactionSigner::sign_tx` to the `verify_input_authorization` tests, and reads the P2PKH key hash with `Script::p2pkh_public_key_hash_bytes` instead of slicing the script.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
State that an unverified lock is deferred rather than final, may repeat
per txid, that refuted locks emit nothing, and that the mempool acts
only on validated locks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`VerifiedInstantLock::matches_transaction` now takes the receiving
wallet's network and checks it together with the txid and ordered
inputs, so consumers cannot accept cross-network evidence by forgetting
a separate `network()` comparison.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…queue

A lock that verifies on arrival drops the other pending locks of its
txid. When that empties the queue, the manager stayed in `Syncing`
until the next masternode state update, since the tick only resolves
the state for pending work it drained itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fixture signed with the constant secret `[1; 32]`, so a fixture cycle that reached a persisted engine would let anyone forge locks for it. Each fixture now draws its own secret from the thread CSPRNG.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`VerifiedInstantLock::verify` re-derived which stored cycle may sign a lock from three engine internals. `MasternodeListEngine::instant_send_cycle` now owns that policy and `verify` only classifies the signature check over its result.

A cycle counts as complete only when storage has stopped merging into it: every slot of the configured InstantSend type, all of that type. Mainnet, testnet and regtest behave as before. On a devnet whose cycle has another rotating type, a lock the cycle does not verify is deferred instead of refuted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A peer could send locks of up to ~111k inputs, and each new lock was compared input by input against every pending lock before verification.

`InstantLockStructureValidator` now rejects locks with more than `MAX_BLOCK_SIZE / 41` inputs, the cap Dash Core applies in `InstantSendLock::MAX_INPUTS`: a transaction fits in a block and each input takes at least 41 bytes, so no valid lock is rejected. Pending locks are deduplicated by the hash of the serialized lock instead of a deep comparison.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ved`

The live InstantSend path discarded the `VerifiedInstantLock` it obtained and sent `validated: bool` to the mempool, whose gate was a literal `validated: true` pattern. A `{ .. }` match or a hand-built event could feed an unverified lock into acceptance.

`SyncEvent::InstantLockReceived` now carries `instant_lock: VerifiedInstantLock` and is emitted only for verified locks. Locks awaiting quorum data are queued without an event; no in-repo consumer used that notification. `MempoolManager::process_instant_send` and its pending locks take only `VerifiedInstantLock`, which cannot be built outside the crate, so the mempool and wallet act on verified locks by type.

The mempool event test moves next to its siblings in `sync_manager.rs`; its unverified-lock half is no longer expressible.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`impl Validator<&InstantLock> for InstantLockValidator` was only reached by a test since `VerifiedInstantLock::verify` became the single entry point. Its doc now points there, and the disconnect comments describe the current deduplication.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eing it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…erride

The devnet test returned early whenever another test in the same binary
had set the process-wide devnet override, so under `cargo test` it
rarely asserted anything. The completeness rule now lives in a pure
function taking the InstantSend type explicitly, and the test drives it
directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The pending-queue dedupe hashed every incoming lock first, so an
oversized lock was serialized in full before the input bound dropped it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The InstantSend path reads cycles through `instant_send_cycle`, which left
the raw query to tests only and failed the release clippy build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Covers `verify_input_authorization` on a two-input transaction signed by two owners: each input verifies only against its own prevout, a change to one input revokes the other input's SIGHASH_ALL authorization, and a signature does not follow its input to another position. The existing tests only exercised input 0 of single-input transactions.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Fails on this branch. `InstantSendManager` still caches an entry for every lock awaiting quorum data, although only verified entries deduplicate. `MAX_CACHE_SIZE` such locks evict the oldest verified entry, so the next announcement of that lock is verified and emitted as `InstantLockReceived` a second time.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Only a verified entry settles a txid, yet `InstantSendManager` still cached an entry for every lock awaiting quorum data. `MAX_CACHE_SIZE` such locks evicted the oldest verified entry, so the next announcement of that lock was verified again and emitted as a second `InstantLockReceived`. `validate_pending` also lost the verified txid when its unverified entry had been evicted.

The cache now holds only verified txids, recorded both on direct verification and when a pending lock verifies. Disconnect clears just the pending queue. The manager tests import `Network` and `MAX_BLOCK_SIZE` instead of writing full paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replaces full paths with imports in the code this branch adds, and makes `InstantLockValidator` private, since only `VerifiedInstantLock::verify` uses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lklimek and others added 14 commits November 18, 2026 12:27
…horization

`dev` carries the final #1419: InstantLocks verify against the held quorums of their stored cycle, and a held quorum refutes a lock whether or not the cycle is complete. `VerifiedInstantLock::verify` now builds on that classifier, `rotated_quorums_of_cycle` and `InstantLockValidator`, in place of the removed `instant_send_cycle` and `verify_against_cycle`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
The merged classifier refutes a lock whose selected quorum is held, even when its cycle is partial. The evidence test now expects a deferral only when that quorum is missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
The engine stores only quorums of the network's rotation type, so `VerifiedInstantLock::verify` no longer checks the type itself. The test installed a cycle of another type through the test hook, a state production never reaches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
The version 2 snapshot assertion and the cycle accessor swap belonged to #1419. The broadcast acceptance test covered mempool behavior this PR does not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
Every fixture used one cycle hash, so installing a second fixture replaced the first one's cycle and its lock no longer verified. The cycle hash now derives from the fixture's key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
`InstantSendManager` checks a lock's structure before hashing and queueing it, so it verifies the signature with `VerifiedInstantLock::verify_well_formed` instead of repeating the check on every replay. The manager tests are named after the held-quorum contract, and tests with the same setup are merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
The evidence test also checks through the public client that a held quorum refutes a valid BLS signature of another key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep the nonbreaking producer fix and its regression tests here. Move opaque evidence, public revalidation, typed events and signed fixtures to a separate feature PR.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Codex GPT-6 <noreply@openai.com>
Authenticate saved locks against the client quorum state and return opaque evidence bound to a network and transaction. Use the same classifier and evidence token for live InstantSend events and mempool handling, with signed fixtures for tests.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Codex GPT-6 <noreply@openai.com>
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.57806% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.78%. Comparing base (da0373b) to head (2b81ffd).
⚠️ Report is 6 commits behind head on dev.

Files with missing lines Patch % Lines
dash-spv/src/sync/instantsend/manager.rs 98.48% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1499      +/-   ##
==========================================
+ Coverage   86.77%   86.78%   +0.01%     
==========================================
  Files         270      270              
  Lines       71309    71430     +121     
==========================================
+ Hits        61876    61993     +117     
- Misses       9433     9437       +4     
Flag Coverage Δ
core 82.21% <ø> (ø)
rpc 82.21% <ø> (ø)
spv 94.96% <99.57%> (+<0.01%) ⬆️
wallet 82.21% <ø> (ø)
Files with missing lines Coverage Δ
dash-spv/src/client/queries.rs 54.00% <100.00%> (+10.09%) ⬆️
dash-spv/src/lib.rs 46.66% <ø> (ø)
dash-spv/src/sml_engine.rs 97.72% <100.00%> (+<0.01%) ⬆️
dash-spv/src/sync/events.rs 94.44% <100.00%> (-0.20%) ⬇️
dash-spv/src/sync/instantsend/sync_manager.rs 100.00% <ø> (ø)
dash-spv/src/sync/mempool/manager.rs 98.18% <100.00%> (+0.06%) ⬆️
dash-spv/src/sync/mempool/sync_manager.rs 99.53% <100.00%> (-0.01%) ⬇️
dash-spv/src/validation/instantlock.rs 99.64% <100.00%> (+0.24%) ⬆️
dash-spv/src/sync/instantsend/manager.rs 96.02% <98.48%> (-1.69%) ⬇️

... and 4 files with indirect coverage changes

lklimek and others added 6 commits November 24, 2026 07:48
Keep pending deduplication bounded by comparing cached full-lock hashes after structure validation. Keep the producer fix small and cover deferred replay through real dashd quorum synchronization.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Codex GPT-6 <noreply@openai.com>
Merge the smaller producer fix and its real dashd replay regression while preserving typed evidence and the shared verification classifier.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Codex GPT-6 <noreply@openai.com>
Remove queued variants when their transaction receives a verified InstantLock, including variants requeued earlier in the same replay. Cover direct receipt and replay with real quorum synchronization. Keep the unit test focused on queuing and correct stale cache comments.

Co-Authored-By: Codex GPT-6 <noreply@openai.com>

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
Co-Authored-By: Codex GPT-6 <noreply@openai.com>

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
Merge the InstantLock fix and its real-quorum regression coverage. Preserve the verified event payload while removing the obsolete unit replay fixture.

Co-Authored-By: Codex GPT-6 <noreply@openai.com>

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
Co-Authored-By: Codex GPT-6 <noreply@openai.com>

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
@github-actions github-actions Bot added the merge-conflict The PR conflicts with the target branch. label Nov 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them.

@lklimek
lklimek changed the base branch from dev to fix/wallet-restore-authorization November 24, 2026 11:46
@github-actions github-actions Bot removed the merge-conflict The PR conflicts with the target branch. label Nov 24, 2026
Base automatically changed from fix/wallet-restore-authorization to dev November 25, 2026 03:20
@github-actions github-actions Bot added the merge-conflict The PR conflicts with the target branch. label Nov 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-conflict The PR conflicts with the target branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant