fix(pm): couple closed-market retention to the commit reveal deadline (validate bound) - #155
Merged
Merged
Conversation
… (validate bound) Defensive hardening for the commit-reveal escrow path. A commit's reveal deadline can fall up to (pm_batch_epoch_blocks + pm_reveal_window_blocks) blocks after the commit, and its escrow is only refunded/forfeited by the reveal-forfeit cron at that deadline. gc_market deletes pm_commit rows unconditionally once a market has been finalized for pm_closed_market_retention_sec, with no status-0 refund. Today this is safe purely by parameter magnitudes (5 d retention vs ~11 min worst-case reveal deadline). Nothing in code enforces the ordering, and pm_closed_market_retention_sec had no lower bound — a misconfigured median (retention below the reveal window) plus a sustained cron cap-starvation could let a still-unrevealed commit be garbage-collected before its escrow is returned, stranding a bettor's stake. Add a validate() assert requiring pm_closed_market_retention_sec > (pm_batch_epoch_blocks + pm_reveal_window_blocks) * CHAIN_BLOCK_INTERVAL so the "a commit is always cleared before its market is GC'd" invariant holds by construction. Both operands are already validated positive just above. Defaults satisfy it with wide margin (432000 > (20 + 200) * 3 = 660); no testnet override changes these. Header syntax-checks clean against the chain build flags. No behavioural change for any valid configuration.
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.
Summary
Defensive hardening for the commit-reveal escrow path, found during a money-path re-audit of the dispute / commit-reveal / lazy-pool subsystems.
The gap
A commit's reveal deadline can fall up to
(pm_batch_epoch_blocks + pm_reveal_window_blocks)blocks after the commit (pm_commit_bet), and its escrow is only refunded/forfeited by the reveal-forfeit cron at that deadline.gc_marketdeletespm_commitrows unconditionally once a market has been finalized forpm_closed_market_retention_sec— with no status-0 refund.Today this is safe purely by parameter magnitudes: the reveal deadline is ~11 min worst case, vs. a 5-day retention default — three orders of magnitude of slack. But:
gc_market's commit drop is an unconditional backstop).pm_closed_market_retention_sechad no lower bound invalidate().So a misconfigured median (retention set below the reveal window) combined with a sustained
pm_processing_cap_per_blockstarvation could let a still-unrevealed commit be garbage-collected before its escrow is returned — stranding a bettor's stake. Not attacker-triggerable and can't happen under sane params, but it's an invariant resting on luck rather than construction.The fix
One
validate()assert:placed right after the existing
pm_batch_epoch_blocks > 0/pm_reveal_window_blocks > 0asserts (both operands already validated positive). This makes "a commit is always cleared before its market is GC'd" hold by construction.Safety
432000 > (20 + 200) * 3 = 660.CHAIN_BLOCK_INTERVAL = 3in both configs.CHAIN_BLOCK_INTERVALis already used elsewhere in this validate body (no new include).Scope note
This is the root-cause fix (bound the parameter). A belt-and-suspenders alternative would be to also make
gc_marketrefund any lingering status-0 commit before dropping it; I left that out deliberately since it adds a balance mutation to the GC path to guard a case this bound already prevents. Happy to add it if you'd prefer defense-in-depth. Full observation is written up on #124.