Skip to content

Judge PRISM ledger-confirmation on settlement balances, not identity labels - #87

Merged
djh58 merged 1 commit into
1.x.xfrom
fix-prism-preview-balance-comparison
Jul 23, 2026
Merged

djh58 merged 1 commit into
1.x.xfrom
fix-prism-preview-balance-comparison

Conversation

@djh58

@djh58 djh58 commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

Problem

Bech32 defines all-lowercase and all-uppercase as equally valid encodings of the same payout address, and miner firmware/proxies commonly emit the uppercase (QR) form. PRISM canonicalizes the decoded P2MR program but derives the account identity strings (miner_id, payout_order_key) from the raw authorized username. A miner who re-authorizes the same address in a different spelling therefore mints a second identity for a program that may already carry a nonzero owed balance.

The accepted-block ledger-confirmation gates compared full normalized rows — identity strings included. The durable recompute (prior_balances_after_pool_block / qbit_current_carry_forward_balances()) picks one historical identity per program, while the published preview carries the re-authorized spelling, so after a relabel the gates report ledger-confirmation-failed even though every settled amount matches. The check re-runs identically on replay, so the coordinator enters a deterministic fail-closed loop: start, replay the retained candidate, re-detect the label mismatch, shut down cleanly — taking both Stratum listeners and the public API down with it.

Fix

Add settlement_balances_by_program(), which aggregates owed balances into a (p2mr_program_hex -> balance_sats) map (program hex case-normalized; zero totals dropped, matching both the ledger reader's nonzero filter and the preview builder's zero-skip), and judge the confirmation gates on those maps:

  • prior_balances_match_current() (used by the pre-submit stale-balance gate and the pre-publication gate)
  • the live-vs-expected prior-balance gate before preview publication
  • the post-confirm published-preview comparison

The P2MR program is what the coinbase/covenant actually commits to; identity strings remain display metadata everywhere else (publication, artifacts, dashboards are unchanged). A genuine amount or membership divergence still fails closed exactly as before.

Tests

tests/test_prism_settlement_balance_comparison.py:

  • case-variant identity relabel compares settlement-equal (the regression)
  • program hex case is normalized
  • amount divergence still detected
  • membership divergence still detected
  • zero totals dropped on either side
  • split identities aggregate per program
  • prior_balances_match_current accepts a relabel and still rejects changed amounts

All 8 pass; tests/test_prism_coordinator_shutdown.py (17 tests) passes unchanged.

Recovery behavior

On restart with this fix, a coordinator wedged on a relabel-poisoned retained candidate replays it, the settlement comparison passes, and finalization/publication complete normally — no ledger surgery required.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Changes settlement equality logic on ledger-confirmation shutdown paths; semantics are intentionally relaxed only for identity relabels while real amount or membership drift still fails closed.

Overview
Fixes a fail-closed loop where miners re-authorizing the same payout address in a different bech32 casing (lower vs upper) changed identity strings but not the committed program, so ledger confirmation compared full normalized rows and rejected matching settlements.

Adds settlement_balances_by_program(), which sums owed sats per lowercased p2mr_program_hex and omits zero totals. prior_balances_match_current() and the accepted-block confirmation paths (live vs expected prior balances before preview publication, and confirmed balances vs published preview) now compare these maps instead of normalized_prior_balances() row equality. Amount or program-set mismatches still shut down as before; display identity strings are unchanged elsewhere.

New unit tests cover relabel equality, hex case normalization, amount/membership divergence, zero dropping, per-program aggregation, and prior_balances_match_current behavior.

Reviewed by Cursor Bugbot for commit db1a72a. Bugbot is set up for automated code reviews on this repo. Configure here.

…labels

A miner can re-authorize the same payout address under a different valid
bech32 spelling (all-uppercase and all-lowercase encode the same P2MR
program). The share ledger then carries two identity strings for one
program, and the accepted-block confirmation gates - which compared full
identity rows - could report a mismatch between the durable recompute and
the published preview even though every settled amount was identical. The
mismatch is deterministic on replay, so the coordinator entered a
fail-closed shutdown loop with the retained candidate re-failing on every
restart.

Aggregate owed balances by P2MR program (case-normalized, zero totals
dropped to match both the ledger reader and the preview builder) and judge
the confirmation gates on those settlement maps. Identity strings remain
display metadata everywhere else; a genuine amount or membership
divergence still fails closed.

Co-Authored-By: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant