Skip to content

Conversation

@aagbotemi
Copy link
Collaborator

@aagbotemi aagbotemi commented May 6, 2025

This PR implements Anti-Fee-Sniping with randomization as discussed in issue #4

Notes to the reviewers

The implementation adds randomization to anti-fee-sniping behavior:

  1. Uses a 50/50 chance to choose between nLockTime and nSequence (when possible)
  2. Adds a 10% chance to set either value further back in time (by a random value between 0-99)
  3. Detects taproot inputs and their confirmation status
  • I've signed all my commits
  • I ran cargo fmt and cargo clippy before committing
  • I've added docs for the new feature

Closes #4

@aagbotemi aagbotemi force-pushed the feature/anti-fee-sniping branch 2 times, most recently from 6a39ba9 to 94237e8 Compare May 19, 2025 02:58
@ValuedMammal
Copy link
Collaborator

Thanks @aagbotemi I'm still in the process of reviewing. I agree it would be nice to resolve the clippy error - my other suggestion would be to globally allow the lints in lib.rs for now and open an issue to fix them in a future PR, but in general I agree with your approach to simply Box the large enum variants.

@aagbotemi
Copy link
Collaborator Author

Thanks @aagbotemi I'm still in the process of reviewing.

Thank you @ValuedMammal. Clippy error and large enum variant error in the CI build has been fixed. For subsequent ones(if there is), I'll open another for it.

Copy link
Collaborator

@ValuedMammal ValuedMammal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some review notes

  • For imports, prefer alloc over std. This way we can actually support no-std.
  • I want to see a test of some kind that creates a PSBT with enable_anti_fee_sniping and checks the expected values of the locktime and/or sequence.

@notmandatory notmandatory added the enhancement New feature or request label May 28, 2025
@aagbotemi
Copy link
Collaborator Author

I have some review notes

Noted.
alloc is now preferred over std.
adding test to check enable_anti_fee_sniping

@aagbotemi aagbotemi force-pushed the feature/anti-fee-sniping branch 2 times, most recently from 42fe314 to cfe7b5b Compare May 29, 2025 23:21
@aagbotemi aagbotemi force-pushed the feature/anti-fee-sniping branch from cfe7b5b to 9041b2f Compare May 30, 2025 22:33
@ValuedMammal
Copy link
Collaborator

We should also be able to remove the clippy allow attributes in lib.rs.

@aagbotemi
Copy link
Collaborator Author

We should also be able to remove the clippy allow attributes in lib.rs.

Alright, I will remove the clippy allow attributes in lib.rs

@ValuedMammal
Copy link
Collaborator

I'm still in favor of using Box on PlanOrPsbtInput and ScriptSource::Descriptor.

@aagbotemi
Copy link
Collaborator Author

I'm still in favor of using Box on PlanOrPsbtInput and ScriptSource::Descriptor.

Fixed! I've updated the code to use Box.

@aagbotemi aagbotemi force-pushed the feature/anti-fee-sniping branch from 5506018 to 9fde5c1 Compare September 9, 2025 03:39
@aagbotemi aagbotemi force-pushed the feature/anti-fee-sniping branch from ff19f53 to c4dd696 Compare October 20, 2025 14:30
@ValuedMammal
Copy link
Collaborator

In general I think the git history would be cleaner if we didn't merge with merge commits but instead rebase the commits in this PR.

feat: bip326 anti-fee sniping made compatible with new current library
fix(clippy): fixing clippy CI build error with Box due to large enum variant
example to test anti fee snipping, extracted the height from tx
checking expected range of values
- Rename MAX_SEQUENCE_VALUE to MAX_RELATIVE_HEIGHT for clarity
- Use Script::is_p2tr() for more robust taproot input detection
- Replace fallible LockTime::from_height with expect for valid Height
- Remove unnecessary clippy allow attributes in lib.rs
- Remove Box usage from error and enums
- Rename anti_fee_snipping example to anti_fee_sniping
@aagbotemi aagbotemi force-pushed the feature/anti-fee-sniping branch from c4dd696 to cfa9826 Compare October 26, 2025 21:44
@aagbotemi aagbotemi force-pushed the feature/anti-fee-sniping branch from cfa9826 to 4649e8d Compare October 26, 2025 21:56
@aagbotemi
Copy link
Collaborator Author

aagbotemi commented Oct 26, 2025

In general I think the git history would be cleaner if we didn't merge with merge commits but instead rebase the commits in this PR.

Alright, I've done the cleanup

@ValuedMammal
Copy link
Collaborator

Approach ACK.

@ValuedMammal ValuedMammal requested a review from nymius October 28, 2025 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request: Sequence based anti-fee-sniping BIP326

4 participants