Skip to content

fix: reorder UtxoOwners writes to prevent inconsistent persistence (PM-20218)#762

Merged
m2ux merged 9 commits into
mainfrom
fix/PM-20218-utxoowners-inconsistent-persistence
Mar 2, 2026
Merged

fix: reorder UtxoOwners writes to prevent inconsistent persistence (PM-20218)#762
m2ux merged 9 commits into
mainfrom
fix/PM-20218-utxoowners-inconsistent-persistence

Conversation

@m2ux

@m2ux m2ux commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Add test coverage for UtxoOwners persistence guards in the cNight observation pallet, verifying both the event construction failure path and the spend-without-create guard. Addresses audit finding Issue I (PM-20218).

🎫 Ticket 📐 Engineering


Motivation

The Least Authority audit (Issue I, High severity) identified that handle_create wrote to UtxoOwners before event construction, leaving orphaned entries on failure. PR #757 fixed the operation ordering so that UtxoOwners::insert only occurs after successful event construction. However, no tests exercised the failure paths to confirm the fix's correctness or the existing spend guard's behavior.

This PR adds two negative test cases covering:

  1. Event construction failure (invalid DustPublicKey) does not leave orphaned UtxoOwners entries
  2. Spending a UTXO that was never created does not emit a Destroy event

Changes

  • Test: event construction failure guardhandle_create_does_not_write_utxo_owners_on_event_construction_failure registers a wallet with invalid DustPublicKeyBytes ([0xFF; 32]), submits an AssetCreate, and verifies no UtxoOwners entry is written and no SystemTransactionApplied event is emitted
  • Test: spend-without-create guardasset_spend_without_create_should_not_emit_destroy_event registers a valid wallet, submits an AssetSpend for a UTXO that was never created, and verifies no Destroy event is emitted
  • Change filechanges/changed/audit-utxoowners-test-coverage.md

📌 Submission Checklist

  • Changes are backward-compatible (or flagged if breaking)
  • Pull request description explains why the change is needed
  • Self-reviewed the diff
  • I have included a change file, or skipped for this reason: included
  • If the changes introduce a new feature, I have bumped the node minor version
  • Update documentation (if relevant)
  • No new todos introduced

🔱 Fork Strategy

  • Node Runtime Update
  • Node Client Update
  • Other
  • N/A

🗹 TODO before merging

  • Ready for review

@github-actions

github-actions Bot commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

kics-logo

KICS version: v2.1.16

Category Results
CRITICAL CRITICAL 0
HIGH HIGH 0
MEDIUM MEDIUM 99
LOW LOW 12
INFO INFO 83
TRACE TRACE 0
TOTAL TOTAL 194
Metric Values
Files scanned placeholder 31
Files parsed placeholder 31
Files failed to scan placeholder 0
Total executed queries placeholder 73
Queries failed to execute placeholder 0
Execution time placeholder 11

@m2ux m2ux self-assigned this Feb 24, 2026
Audit finding Issue I: UtxoOwners persist inconsistently in
handle_create and handle_redemption_create.

Co-authored-by: Cursor <cursoragent@cursor.com>
@m2ux m2ux force-pushed the fix/PM-20218-utxoowners-inconsistent-persistence branch from f3b30e0 to 7317eed Compare February 27, 2026 12:14
m2ux and others added 6 commits February 27, 2026 12:34
…truction failure

Add negative test for handle_create: when construct_cnight_generates_dust_event
fails due to an invalid DustPublicKey (bytes exceeding Fr field modulus),
UtxoOwners storage must not be written and no SystemTransactionApplied event
should be emitted.

Ref: PM-20218
Made-with: Cursor
…rs-inconsistent-persistence

Made-with: Cursor

# Conflicts:
#	pallets/cnight-observation/tests/tests.rs
…nge file

Add test verifying that AssetSpend for a UTXO without prior AssetCreate
does not emit a Destroy event. Add change file for audit test coverage.

Made-with: Cursor
@m2ux m2ux marked this pull request as ready for review February 28, 2026 12:14
@m2ux m2ux requested a review from a team as a code owner February 28, 2026 12:14
Comment thread pallets/cnight-observation/tests/tests.rs
gilescope and others added 2 commits February 28, 2026 13:18
Signed-off-by: Giles Cope <gilescope@gmail.com>
@gilescope gilescope enabled auto-merge February 28, 2026 13:19
@gilescope gilescope added this pull request to the merge queue Feb 28, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Feb 28, 2026
@m2ux m2ux added this pull request to the merge queue Mar 2, 2026
Merged via the queue into main with commit a8c7733 Mar 2, 2026
36 checks passed
@m2ux m2ux deleted the fix/PM-20218-utxoowners-inconsistent-persistence branch March 2, 2026 10:57
gilescope pushed a commit that referenced this pull request Apr 8, 2026
m2ux added a commit that referenced this pull request Apr 23, 2026
Signed-off-by: Mike Clay <mike.clay@shielded.io>
m2ux added a commit that referenced this pull request Apr 23, 2026
Signed-off-by: Mike Clay <mike.clay@shielded.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants