fix(afs)!: preserve input timelock requirements#65
Conversation
d6a0843 to
dc4b147
Compare
evanlinjin
left a comment
There was a problem hiding this comment.
Thanks for working on this.
PR description is misleading - none of these bugs were flagged in the post-merge review. It also says this "fixes two consensus-validity issues", however this PR attempts to close 3 issues?
evanlinjin
left a comment
There was a problem hiding this comment.
There are two versions of the random_probability and random_range methods. The std versions add no meaningful value imo - I would just remove them.
67dcf29 to
8487ab4
Compare
|
Thank you for the review |
f3d7e60 to
3b72e6d
Compare
3b72e6d to
b0b0eb1
Compare
evanlinjin
left a comment
There was a problem hiding this comment.
Make apply_anti_fee_sniping explicitly private!
15943a8 to
adf472f
Compare
adf472f to
8085f45
Compare
|
We are lacking commit messages, PR description has factual errors, missing I'll push it forward! |
b8671c3 to
c83079a
Compare
c83079a to
1211bc3
Compare
|
@aagbotemi I pushed a Claude-generated test commit on top, let me know what you think. |
059752f to
2fcd3c5
Compare
Anti-fee-sniping could produce consensus-invalid transactions when inputs had timelock requirements: - The nLockTime strategy could overwrite `tx.lock_time` with a value lower than the accumulated input CLTV. - The nSequence strategy zeroed `tx.lock_time`, also breaking accumulated CLTV. - The nSequence strategy could select a Taproot input that already had a relative-timelock (CSV) requirement and overwrite its sequence. The locktime path now only updates `tx.lock_time` when the proposed AFS value still satisfies the existing requirement. The sequence path leaves `tx.lock_time` alone and filters CSV-bearing Taproot inputs out of the candidate pool. API changes: - `PsbtParams::enable_anti_fee_sniping: bool` and `fallback_locktime` are replaced with `anti_fee_sniping: Option<absolute::Height>` and `min_locktime`. The tip height is now required when AFS is enabled and time-based tips are unrepresentable. - `apply_anti_fee_sniping` is now `pub(crate)`; the `rbf_enabled` parameter is removed (derived from `tx.is_explicitly_rbf()`). - New `AntiFeeSnipingError` type, wrapped under `CreatePsbtError::AntiFeeSniping`. Closes bitcoindevkit#62 Closes bitcoindevkit#63 Closes bitcoindevkit#64
Three new tests, each verified to fail on the pre-fix algorithm: - `test_anti_fee_sniping_preserves_input_cltv` — input CLTV above tip must not be lowered. - `test_anti_fee_sniping_skips_taproot_csv_input` — a Taproot input carrying a CSV requirement must be excluded from the nSequence candidate pool; a regular Taproot input remains to ensure the sequence path is still reachable. - `test_anti_fee_sniping_rejects_time_based_locktime` — a time-based CLTV must surface `AntiFeeSnipingError::UnsupportedLockTime`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2fcd3c5 to
5df9bb1
Compare
Description
Fixes consensus-validity issues in BIP-326 anti-fee-sniping.
Closes #62
Closes #63
Closes #64
Bugs
tx.lock_timewith a value lower than the accumulated input CLTV.tx.lock_time, also breaking accumulated CLTV.Fixes
tx.lock_timewhen the AFS-proposed value still satisfies the existing requirement.tx.lock_timealone and filters CSV-bearing Taproot inputs out of the candidate pool.Breaking changes
PsbtParams::enable_anti_fee_sniping: bool+fallback_locktime→anti_fee_sniping: Option<absolute::Height>+min_locktime. The tip height is now required when AFS is enabled, and time-based tips are unrepresentable.apply_anti_fee_snipingis nowpub(crate);rbf_enabledparam removed (derived fromtx.is_explicitly_rbf()).AntiFeeSnipingErrortype, wrapped underCreatePsbtError::AntiFeeSniping.