Repository navigation
Judge PRISM ledger-confirmation on settlement balances, not identity labels - #87
Merged
Merged
Conversation
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 reportledger-confirmation-failedeven 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 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:prior_balances_match_currentaccepts a relabel and still rejects changed amountsAll 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
Need help on this PR? Tag
@codesmith-botwith 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 lowercasedp2mr_program_hexand 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 ofnormalized_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_currentbehavior.Reviewed by Cursor Bugbot for commit db1a72a. Bugbot is set up for automated code reviews on this repo. Configure here.