Skip to content

[coinselection] Increase SRD target by change_fee - #27846

Merged
achow101 merged 2 commits into
bitcoin:masterfrom
murchandamus:2023-06-fix-srd-target
Jun 23, 2023
Merged

achow101 merged 2 commits into
bitcoin:masterfrom
murchandamus:2023-06-fix-srd-target

Conversation

@murchandamus

@murchandamus murchandamus commented Jun 9, 2023 •

Copy link
Copy Markdown
Member

I discovered via fuzzing of another coin selection approach that at extremely high feerates SRD may find input sets that lead to transactions without change outputs. This is an unintended outcome since SRD is meant to always produce a transaction with a change output—we use other algorithms to specifically search for changeless solutions.

The issue occurs when the flat allowance of 50,000 ṩ for change is insufficient to pay for the creation of a change output with a non-dust amount, at and above 1,613 ṩ/vB. Increasing the change budget by change_fee makes SRD behave as expected at any feerates.

Note: The intermittent failures of test/functional/interface_usdt_mempool.py are a known issue: #27380

@DrahtBot

DrahtBot commented Jun 9, 2023 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK achow101, S3RK

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #27877 (wallet: Add CoinGrinder coin selection algorithm by Xekyo)
  • #27585 (fuzz: improve coinselection by brunoerg)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@achow101

Copy link
Copy Markdown
Member

Could we add a (fuzz) test that checks for this?

@murchandamus

Copy link
Copy Markdown
Member Author

Could we add a (fuzz) test that checks for this?

I added an assert that SRD’s budget for change is always bigger than change_fee plus the dust amount for a P2WPKH output. This assert failed within seconds for the old code, but is fine with the new code.

@murchandamus
murchandamus force-pushed the 2023-06-fix-srd-target branch from c0e40c4 to a92efa9 Compare June 14, 2023 21:03
Comment thread src/wallet/test/fuzz/coinselection.cpp Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why 294?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Answering myself. Dust limit for P2WPKH is 294 = (67 vbytes for input + 31 vbytes for output) * 3sat/vb

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But why use P2WPKH in particular, when change_output_size is a random int for 10 to 1000

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This parameter is the minimum viable change, which for this test, I think makes sense to actually be as high as possible, rather than dependent on the change output itself. The new behavior is that SRD will never make a change output that is smaller than CHANGE_LOWER, so I think it would make sense to set this to CHANGE_LOWER.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@S3RK: Yeah, you got it right.

@achow101: Followed your suggestion and updated the minimum to CHANGE_LOWER.

@S3RK

S3RK commented Jun 19, 2023

Copy link
Copy Markdown
Contributor

Approach ACK.

That's a straightforward fix for the bug.

@murchandamus
murchandamus force-pushed the 2023-06-fix-srd-target branch from a92efa9 to 05b0ce4 Compare June 21, 2023 20:18
I discovered via fuzzing of another coin selection approach that at
extremely high feerates SRD may find input sets that lead to
transactions without change outputs. This is an unintended outcome since
SRD is meant to always produce a transaction with a change output—we use
other algorithms to specifically search for changeless solutions.

The issue occures when the flat allowance of 50,000 ṩ for change is
insufficient to pay for the creation of a change output with a non-dust
amount, at and above 1,613 ṩ/vB. Increasing the change budget by
change_fees makes SRD behave as expected at any feerates.
Adding this assert to the fuzz test without increasing the change target
by the change_fee resulted in a crash within a few seconds.
@murchandamus
murchandamus force-pushed the 2023-06-fix-srd-target branch from 05b0ce4 to 1771daa Compare June 21, 2023 20:19
@murchandamus

Copy link
Copy Markdown
Member Author

Rebase: Increased minimum value of change to CHANGE_LOWER as discussed above, and signed commits.

@achow101

Copy link
Copy Markdown
Member

ACK 1771daa

1 similar comment
@S3RK

S3RK commented Jun 22, 2023

Copy link
Copy Markdown
Contributor

ACK 1771daa

@achow101
achow101 merged commit 8e0cf4f into bitcoin:master Jun 23, 2023
luke-jr pushed a commit to luke-jr/bitcoin that referenced this pull request Aug 16, 2023
I discovered via fuzzing of another coin selection approach that at
extremely high feerates SRD may find input sets that lead to
transactions without change outputs. This is an unintended outcome since
SRD is meant to always produce a transaction with a change output—we use
other algorithms to specifically search for changeless solutions.

The issue occures when the flat allowance of 50,000 ṩ for change is
insufficient to pay for the creation of a change output with a non-dust
amount, at and above 1,613 ṩ/vB. Increasing the change budget by
change_fees makes SRD behave as expected at any feerates.

Github-Pull: bitcoin#27846
Rebased-From: 941b8c6
luke-jr pushed a commit to luke-jr/bitcoin that referenced this pull request Aug 16, 2023
Adding this assert to the fuzz test without increasing the change target
by the change_fee resulted in a crash within a few seconds.

Github-Pull: bitcoin#27846
Rebased-From: 1771daa
@murchandamus
murchandamus deleted the 2023-06-fix-srd-target branch August 25, 2023 18:15
@bitcoin bitcoin locked and limited conversation to collaborators Aug 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants